From: Christoph Lameter <cl@linux-foundation.org>
To: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: akpm@linux-foundation.org, Alexander Viro <viro@ftp.linux.org.uk>,
Christoph Hellwig <hch@infradead.org>,
Christoph Lameter <clameter@sgi.com>,
Christoph Lameter <cl@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Cc: Mel Gorman <mel@skynet.ie>
Cc: andi@firstfloor.org
Cc: Rik van Riel <riel@redhat.com>
Cc: mpm@selenic.com
Cc: Dave Chinner <david@fromorbit.com>
Subject: [patch 11/19] inodes: Support generic defragmentation
Date: Fri, 09 May 2008 19:21:12 -0700 [thread overview]
Message-ID: <20080801182346.481748122@lameter.com> (raw)
In-Reply-To: 20080801182324.572058187@lameter.com
[-- Attachment #1: 0025-inodes-Support-generic-defragmentation.patch --]
[-- Type: text/plain, Size: 5124 bytes --]
This implements the ability to remove inodes in a particular slab
from inode caches. In order to remove an inode we may have to write out
the pages of an inode, the inode itself and remove the dentries referring
to the node.
Provide generic functionality that can be used by filesystems that have
their own inode caches to also tie into the defragmentation functions
that are made available here.
Cc: Alexander Viro <viro@ftp.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>
Reviewed-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Christoph Lameter <clameter@sgi.com>
Signed-off-by: Christoph Lameter <cl@linux-foundation.org>
---
fs/inode.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/fs.h | 6 ++
2 files changed, 129 insertions(+)
Index: linux-2.6/fs/inode.c
===================================================================
--- linux-2.6.orig/fs/inode.c 2008-07-31 12:18:12.000000000 -0500
+++ linux-2.6/fs/inode.c 2008-07-31 12:18:15.000000000 -0500
@@ -1363,6 +1363,128 @@
__setup("ihash_entries=", set_ihash_entries);
/*
+ * Obtain a refcount on a list of struct inodes pointed to by v. If the
+ * inode is in the process of being freed then zap the v[] entry so that
+ * we skip the freeing attempts later.
+ *
+ * This is a generic function for the ->get slab defrag callback.
+ */
+void *get_inodes(struct kmem_cache *s, int nr, void **v)
+{
+ int i;
+
+ spin_lock(&inode_lock);
+ for (i = 0; i < nr; i++) {
+ struct inode *inode = v[i];
+
+ if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE))
+ v[i] = NULL;
+ else
+ __iget(inode);
+ }
+ spin_unlock(&inode_lock);
+ return NULL;
+}
+EXPORT_SYMBOL(get_inodes);
+
+/*
+ * Function for filesystems that embedd struct inode into their own
+ * fs inode. The offset is the offset of the struct inode in the fs inode.
+ *
+ * The function adds to the pointers in v[] in order to make them point to
+ * struct inode. Then get_inodes() is used to get the refcount.
+ * The converted v[] pointers can then also be passed to the kick() callback
+ * without further processing.
+ */
+void *fs_get_inodes(struct kmem_cache *s, int nr, void **v,
+ unsigned long offset)
+{
+ int i;
+
+ for (i = 0; i < nr; i++)
+ v[i] += offset;
+
+ return get_inodes(s, nr, v);
+}
+EXPORT_SYMBOL(fs_get_inodes);
+
+/*
+ * Generic callback function slab defrag ->kick methods. Takes the
+ * array with inodes where we obtained refcounts using fs_get_inodes()
+ * or get_inodes() and tries to free them.
+ */
+void kick_inodes(struct kmem_cache *s, int nr, void **v, void *private)
+{
+ struct inode *inode;
+ int i;
+ int abort = 0;
+ LIST_HEAD(freeable);
+ int active;
+
+ for (i = 0; i < nr; i++) {
+ inode = v[i];
+ if (!inode)
+ continue;
+
+ if (inode_has_buffers(inode) || inode->i_data.nrpages) {
+ if (remove_inode_buffers(inode))
+ /*
+ * Should we really be doing this? Or
+ * limit the writeback here to only a few pages?
+ *
+ * Possibly an expensive operation but we
+ * cannot reclaim the inode if the pages
+ * are still present.
+ */
+ invalidate_mapping_pages(&inode->i_data,
+ 0, -1);
+ }
+
+ /* Invalidate children and dentry */
+ if (S_ISDIR(inode->i_mode)) {
+ struct dentry *d = d_find_alias(inode);
+
+ if (d) {
+ d_invalidate(d);
+ dput(d);
+ }
+ }
+
+ if (inode->i_state & I_DIRTY)
+ write_inode_now(inode, 1);
+
+ d_prune_aliases(inode);
+ }
+
+ mutex_lock(&iprune_mutex);
+ for (i = 0; i < nr; i++) {
+ inode = v[i];
+
+ if (!inode)
+ /* inode is alrady being freed */
+ continue;
+
+ active = inode->i_sb->s_flags & MS_ACTIVE;
+ iput(inode);
+ if (abort || !active)
+ continue;
+
+ spin_lock(&inode_lock);
+ abort = !can_unuse(inode);
+
+ if (!abort) {
+ list_move(&inode->i_list, &freeable);
+ inode->i_state |= I_FREEING;
+ inodes_stat.nr_unused--;
+ }
+ spin_unlock(&inode_lock);
+ }
+ dispose_list(&freeable);
+ mutex_unlock(&iprune_mutex);
+}
+EXPORT_SYMBOL(kick_inodes);
+
+/*
* Initialize the waitqueues and inode hash table.
*/
void __init inode_init_early(void)
@@ -1401,6 +1523,7 @@
SLAB_MEM_SPREAD),
init_once);
register_shrinker(&icache_shrinker);
+ kmem_cache_setup_defrag(inode_cachep, get_inodes, kick_inodes);
/* Hash may have been set up in inode_init_early */
if (!hashdist)
Index: linux-2.6/include/linux/fs.h
===================================================================
--- linux-2.6.orig/include/linux/fs.h 2008-07-31 12:18:12.000000000 -0500
+++ linux-2.6/include/linux/fs.h 2008-07-31 12:18:15.000000000 -0500
@@ -1844,6 +1844,12 @@
__insert_inode_hash(inode, inode->i_ino);
}
+/* Helper functions for inode defragmentation support in filesystems */
+extern void kick_inodes(struct kmem_cache *, int, void **, void *);
+extern void *get_inodes(struct kmem_cache *, int nr, void **);
+extern void *fs_get_inodes(struct kmem_cache *, int nr, void **,
+ unsigned long offset);
+
extern struct file * get_empty_filp(void);
extern void file_move(struct file *f, struct list_head *list);
extern void file_kill(struct file *f);
--
next prev parent reply other threads:[~2008-05-10 2:21 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-10 2:21 [patch 00/19] Slab Fragmentation Reduction V13 Christoph Lameter
2008-05-10 2:21 ` [patch 01/19] slub: Add defrag_ratio field and sysfs support Christoph Lameter
2008-05-10 2:21 ` [patch 02/19] slub: Replace ctor field with ops field in /sys/slab/* Christoph Lameter
2008-05-10 2:21 ` [patch 03/19] slub: Add get() and kick() methods Christoph Lameter
2008-05-10 2:21 ` [patch 04/19] slub: Sort slab cache list and establish maximum objects for defrag slabs Christoph Lameter
2008-05-10 2:21 ` [patch 05/19] slub: Slab defrag core Christoph Lameter
2008-05-10 2:21 ` [patch 06/19] slub: Add KICKABLE to avoid repeated kick() attempts Christoph Lameter
2008-05-10 2:21 ` [patch 07/19] slub: Extend slabinfo to support -D and -F options Christoph Lameter
2008-05-10 2:21 ` [patch 08/19] slub/slabinfo: add defrag statistics Christoph Lameter
2008-05-10 2:21 ` [patch 09/19] slub: Trigger defragmentation from memory reclaim Christoph Lameter
2008-05-10 2:21 ` [patch 10/19] buffer heads: Support slab defrag Christoph Lameter
2008-05-10 2:21 ` Christoph Lameter [this message]
2008-05-10 2:21 ` [patch 12/19] Filesystem: Ext2 filesystem defrag Christoph Lameter
2008-05-10 2:21 ` [patch 13/19] Filesystem: Ext3 " Christoph Lameter
2008-05-10 2:21 ` [patch 14/19] Filesystem: Ext4 " Christoph Lameter
2008-08-03 1:54 ` Theodore Tso
2008-08-13 7:26 ` Pekka Enberg
2008-05-10 2:21 ` [patch 15/19] Filesystem: XFS slab defragmentation Christoph Lameter
2008-08-03 1:42 ` Dave Chinner
2008-08-04 13:36 ` Christoph Lameter
2008-05-10 2:21 ` [patch 16/19] Filesystem: /proc filesystem support for slab defrag Christoph Lameter
2008-05-10 2:21 ` [patch 17/19] Filesystem: Slab defrag: Reiserfs support Christoph Lameter
2008-05-10 2:21 ` [patch 18/19] dentries: Add constructor Christoph Lameter
2008-05-10 2:21 ` [patch 19/19] dentries: dentry defragmentation Christoph Lameter
2008-08-03 1:58 ` No, really, stop trying to delete slab until you've finished making slub perform as well Matthew Wilcox
2008-08-03 21:25 ` Pekka Enberg
2008-08-04 2:37 ` Rene Herman
2008-08-04 21:22 ` Pekka Enberg
2008-08-04 21:41 ` Christoph Lameter
2008-08-04 23:09 ` Rene Herman
2008-08-04 13:43 ` Christoph Lameter
2008-08-04 14:48 ` Jamie Lokier
2008-08-04 15:21 ` Jamie Lokier
2008-08-04 16:35 ` Christoph Lameter
2008-08-04 15:11 ` Rik van Riel
2008-08-04 16:02 ` Christoph Lameter
2008-08-04 16:47 ` KOSAKI Motohiro
2008-08-04 17:13 ` Christoph Lameter
2008-08-04 17:20 ` Pekka Enberg
2008-08-05 12:06 ` KOSAKI Motohiro
2008-08-05 14:59 ` Christoph Lameter
2008-08-06 12:36 ` KOSAKI Motohiro
2008-08-06 14:24 ` Christoph Lameter
2008-08-13 10:46 ` KOSAKI Motohiro
2008-08-13 13:10 ` Christoph Lameter
2008-08-13 14:14 ` KOSAKI Motohiro
2008-08-13 14:16 ` Pekka Enberg
2008-08-13 14:31 ` Christoph Lameter
2008-08-13 15:05 ` KOSAKI Motohiro
2008-08-14 19:44 ` Christoph Lameter
2008-08-15 16:44 ` KOSAKI Motohiro
2008-08-15 18:24 ` Christoph Lameter
2008-08-15 19:42 ` Christoph Lameter
2008-08-18 10:08 ` KOSAKI Motohiro
2008-08-18 10:34 ` KOSAKI Motohiro
2008-08-18 14:08 ` Christoph Lameter
2008-08-19 10:34 ` KOSAKI Motohiro
2008-08-19 13:51 ` Christoph Lameter
2008-08-20 11:46 ` KOSAKI Motohiro
2008-08-14 7:15 ` Pekka Enberg
2008-08-14 14:45 ` Christoph Lameter
2008-08-14 15:06 ` Christoph Lameter
2008-08-04 17:19 ` Christoph Lameter
-- strict thread matches above, loose matches on Subject: below --
2008-08-11 15:06 [patch 00/19] Slab Fragmentation Reduction V14 Christoph Lameter
2008-08-11 15:06 ` [patch 11/19] inodes: Support generic defragmentation Christoph Lameter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080801182346.481748122@lameter.com \
--to=cl@linux-foundation.org \
--cc=akpm@linux-foundation.org \
--cc=clameter@sgi.com \
--cc=hch@infradead.org \
--cc=penberg@cs.helsinki.fi \
--cc=viro@ftp.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).