From: clameter@sgi.com
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, dgc@sgi.com,
Hugh Dickins <hugh@veritas.com>
Subject: [patch 03/10] Dentry defragmentation
Date: Fri, 18 May 2007 11:10:43 -0700 [thread overview]
Message-ID: <20070518181119.327980685@sgi.com> (raw)
In-Reply-To: <20070518181040.465335396@sgi.com>
[-- Attachment #1: dentry_targeted_reclaim --]
[-- Type: text/plain, Size: 4720 bytes --]
This patch allows the removal of unused or negative dentry entries in a
partially populated slab page.
get() uses the dcache lock and then works with dget_locked to obtain a
reference to the dentry. An additional complication is that the dentry
may be in process of being freed or it may just have been allocated.
We add an additional flag to d_flags to be able to determined the
status of an object.
kick() is called after get() has been used and after the slab has dropped
all of its own locks. The dentry pruning for unused entries works in a
straighforward way.
Signed-off-by: Christoph Lameter <clameter@sgi.com>
---
fs/dcache.c | 100 +++++++++++++++++++++++++++++++++++++++++++++----
include/linux/dcache.h | 4 +
2 files changed, 96 insertions(+), 8 deletions(-)
Index: slub/fs/dcache.c
===================================================================
--- slub.orig/fs/dcache.c 2007-05-18 10:53:01.000000000 -0700
+++ slub/fs/dcache.c 2007-05-18 10:58:38.000000000 -0700
@@ -136,6 +136,7 @@ static struct dentry *d_kill(struct dent
list_del(&dentry->d_u.d_child);
dentry_stat.nr_dentry--; /* For d_free, below */
+ dentry->d_flags &= ~DCACHE_ENTRY_VALID;
/*drops the locks, at that point nobody can reach this dentry */
dentry_iput(dentry);
parent = dentry->d_parent;
@@ -952,6 +953,7 @@ struct dentry *d_alloc(struct dentry * p
if (parent)
list_add(&dentry->d_u.d_child, &parent->d_subdirs);
dentry_stat.nr_dentry++;
+ dentry->d_flags |= DCACHE_ENTRY_VALID;
spin_unlock(&dcache_lock);
return dentry;
@@ -2114,18 +2116,100 @@ static void __init dcache_init_early(voi
INIT_HLIST_HEAD(&dentry_hashtable[loop]);
}
+/*
+ * The slab is holding off frees. Thus we can safely examine
+ * the object without the danger of it vanishing from under us.
+ */
+static void *get_dentries(struct kmem_cache *s, int nr, void **v)
+{
+ struct dentry *dentry;
+ unsigned long abort = 0;
+ int i;
+
+ spin_lock(&dcache_lock);
+ for (i = 0; i < nr; i++) {
+ dentry = v[i];
+ /*
+ * if DCACHE_ENTRY_VALID is not set then the dentry
+ * may be already in the process of being freed.
+ */
+ if (abort || !(dentry->d_flags & DCACHE_ENTRY_VALID))
+ v[i] = NULL;
+ else {
+ dget_locked(dentry);
+ abort = atomic_read(&dentry->d_count) > 1;
+ }
+ }
+ spin_unlock(&dcache_lock);
+ return (void *)abort;
+}
+
+/*
+ * Slab has dropped all the locks. Get rid of the
+ * refcount we obtained earlier and also rid of the
+ * object.
+ */
+static void kick_dentries(struct kmem_cache *s, int nr, void **v, void *private)
+{
+ struct dentry *dentry;
+ unsigned long abort = (unsigned long)private;
+ int i;
+
+ spin_lock(&dcache_lock);
+ for (i = 0; i < nr; i++) {
+ dentry = v[i];
+ if (!dentry)
+ continue;
+
+ if (abort)
+ goto put_dentry;
+
+ spin_lock(&dentry->d_lock);
+ if (atomic_read(&dentry->d_count) > 1) {
+ /*
+ * Reference count was increased.
+ * We need to abandon the freeing of
+ * objects.
+ */
+ abort = 1;
+ spin_unlock(&dentry->d_lock);
+put_dentry:
+ spin_unlock(&dcache_lock);
+ dput(dentry);
+ spin_lock(&dcache_lock);
+ continue;
+ }
+
+ /* Remove from LRU */
+ if (!list_empty(&dentry->d_lru)) {
+ dentry_stat.nr_unused--;
+ list_del_init(&dentry->d_lru);
+ }
+ /* Drop the entry */
+ prune_one_dentry(dentry, 1);
+ }
+ spin_unlock(&dcache_lock);
+ /*
+ * dentries are freed using RCU so we need to wait until RCU
+ * operations arei complete
+ */
+ if (!abort)
+ synchronize_rcu();
+}
+
+static struct kmem_cache_ops dentry_kmem_cache_ops = {
+ .get = get_dentries,
+ .kick = kick_dentries,
+};
+
static void __init dcache_init(unsigned long mempages)
{
int loop;
- /*
- * A constructor could be added for stable state like the lists,
- * but it is probably not worth it because of the cache nature
- * of the dcache.
- */
- dentry_cache = KMEM_CACHE(dentry,
- SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD);
-
+ dentry_cache = KMEM_CACHE_OPS(dentry,
+ SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD,
+ &dentry_kmem_cache_ops);
+
register_shrinker(&dcache_shrinker);
/* Hash may have been set up in dcache_init_early */
Index: slub/include/linux/dcache.h
===================================================================
--- slub.orig/include/linux/dcache.h 2007-05-18 10:53:01.000000000 -0700
+++ slub/include/linux/dcache.h 2007-05-18 10:58:07.000000000 -0700
@@ -177,6 +177,10 @@ d_iput: no no no yes
#define DCACHE_INOTIFY_PARENT_WATCHED 0x0020 /* Parent inode is watched */
+#define DCACHE_ENTRY_VALID 0x0040 /*
+ * Entry is valid and not in the process of
+ * being created or destroyed
+ */
extern spinlock_t dcache_lock;
/**
--
next prev parent reply other threads:[~2007-05-18 18:10 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-18 18:10 [patch 00/10] Slab defragmentation V2 clameter
2007-05-18 18:10 ` [patch 01/10] SLUB: add support for kmem_cache_ops clameter
2007-05-19 12:53 ` Pekka Enberg
2007-05-19 18:19 ` Christoph Lameter
2007-05-20 21:16 ` Pekka Enberg
2007-05-18 18:10 ` [patch 02/10] SLUB: slab defragmentation and kmem_cache_vacate clameter
2007-05-21 14:10 ` Mel Gorman
2007-05-21 17:01 ` Christoph Lameter
2007-05-18 18:10 ` clameter [this message]
2007-05-18 18:10 ` [patch 04/10] Generic inode defragmentation clameter
2007-05-18 18:10 ` [patch 05/10] reiserfs: inode defragmentation support clameter
2007-05-18 18:10 ` [patch 06/10] xfs: " clameter
2007-05-18 18:26 ` Christoph Lameter
2007-05-18 18:10 ` [patch 07/10] procfs: " clameter
2007-05-18 18:10 ` [patch 08/10] shmem: " clameter
2007-05-18 20:34 ` Jan Engelhardt
2007-05-18 21:04 ` Christoph Lameter
2007-05-18 18:10 ` [patch 09/10] sockets: " clameter
2007-05-18 18:10 ` [patch 10/10] ext2 ext3 ext4: support inode slab defragmentation clameter
2007-05-18 20:32 ` Jan Engelhardt
2007-05-18 21:03 ` Christoph Lameter
2007-05-18 18:29 ` [patch 00/10] Slab defragmentation V2 Christoph Lameter
2007-05-18 18:54 ` Michal Piotrowski
2007-05-21 12:52 ` Hugh Dickins
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=20070518181119.327980685@sgi.com \
--to=clameter@sgi.com \
--cc=akpm@linux-foundation.org \
--cc=dgc@sgi.com \
--cc=hugh@veritas.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/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