From: Neil Brown <neilb@suse.de>
To: David Chinner <dgc@sgi.com>
Cc: Jan Blunck <jblunck@suse.de>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
akpm@osdl.org, viro@zeniv.linux.org.uk, balbir@in.ibm.com
Subject: Re: [patch 0/5] [PATCH,RFC] vfs: per-superblock unused dentries list (2nd version)
Date: Mon, 19 Jun 2006 11:21:04 +1000 [thread overview]
Message-ID: <17557.64512.496195.714144@cse.unsw.edu.au> (raw)
In-Reply-To: message from David Chinner on Monday June 19
On Monday June 19, dgc@sgi.com wrote:
>
> Ok. Send me the patch and I'll try to get some tests done on it...
>
Below, thanks.
NeilBrown
-------------------------------------
Reduce contention in dentry_unused when unmounting.
When we unmount a filesystem we need to release all dentries.
We currently
- move a collection of dentries to the end of the dentry_unused list
- call prune_dcache to prune that number of dentries.
If lots of other dentries are added to the end of the list while
the prune_dcache proceeds (e.g. another filesystem is unmounted),
this can involve a lot of wasted time wandering through the
list looking for dentries that we had previously found.
This patch allows the dentry_unused list to temporarily be multiple
lists.
When unmounting, dentries that are found to require pruning are moved
to a temporary list, but accounted as though they were on dentry_unused.
Then this list is passed to prune_dcache for freeing. Any entries
that are not pruned for whatever reason are added to the end of
dentry_unused.
Also change shrink_dcache_sb to simply call shrink_dcache_parent and
shrink_dcache_anon. This avoids a long walk of the LRU.
Signed-off-by: Neil Brown <neilb@suse.de>
### Diffstat output
./fs/dcache.c | 111 ++++++++++++++++++----------------------------------------
1 file changed, 35 insertions(+), 76 deletions(-)
diff .prev/fs/dcache.c ./fs/dcache.c
--- .prev/fs/dcache.c 2006-06-19 11:14:02.000000000 +1000
+++ ./fs/dcache.c 2006-06-19 11:19:29.000000000 +1000
@@ -383,8 +383,8 @@ static void prune_one_dentry(struct dent
/**
* prune_dcache - shrink the dcache
* @count: number of entries to try and free
- * @sb: if given, ignore dentries for other superblocks
- * which are being unmounted.
+ * @list: If given, remove from this list instead of
+ * from dentry_unused.
*
* Shrink the dcache. This is done when we need
* more memory, or simply when we need to unmount
@@ -393,11 +393,23 @@ static void prune_one_dentry(struct dent
*
* This function may fail to free any resources if
* all the dentries are in use.
+ *
+ * Any dentries that were not removed due to the @count
+ * limit will be splice on to the end of dentry_unused,
+ * so they should already be founded in dentry_stat.nr_unused.
*/
-static void prune_dcache(int count, struct super_block *sb)
+static void prune_dcache(int count, struct list_head *list)
{
+ int have_list = list != NULL;
+ struct list_head alt_head;
spin_lock(&dcache_lock);
+ if (list == NULL) {
+ /* use the dentry_unused list */
+ list_add(&alt_head, &dentry_unused);
+ list_del_init(&dentry_unused);
+ list = &alt_head;
+ }
for (; count ; count--) {
struct dentry *dentry;
struct list_head *tmp;
@@ -405,23 +417,11 @@ static void prune_dcache(int count, stru
cond_resched_lock(&dcache_lock);
- tmp = dentry_unused.prev;
- if (unlikely(sb)) {
- /* Try to find a dentry for this sb, but don't try
- * too hard, if they aren't near the tail they will
- * be moved down again soon
- */
- int skip = count;
- while (skip && tmp != &dentry_unused &&
- list_entry(tmp, struct dentry, d_lru)->d_sb != sb) {
- skip--;
- tmp = tmp->prev;
- }
- }
- if (tmp == &dentry_unused)
+ tmp = list->prev;
+ if (tmp == list)
break;
list_del_init(tmp);
- prefetch(dentry_unused.prev);
+ prefetch(list->prev);
dentry_stat.nr_unused--;
dentry = list_entry(tmp, struct dentry, d_lru);
@@ -454,7 +454,7 @@ static void prune_dcache(int count, stru
* If this dentry is for "my" filesystem, then I can prune it
* without taking the s_umount lock (I already hold it).
*/
- if (sb && dentry->d_sb == sb) {
+ if (have_list) {
prune_one_dentry(dentry);
continue;
}
@@ -489,68 +489,25 @@ static void prune_dcache(int count, stru
*/
break;
}
+ /* split any remaining entries back onto dentry_unused */
+ list_splice(list, dentry_unused.prev);
spin_unlock(&dcache_lock);
}
-/*
- * Shrink the dcache for the specified super block.
- * This allows us to unmount a device without disturbing
- * the dcache for the other devices.
- *
- * This implementation makes just two traversals of the
- * unused list. On the first pass we move the selected
- * dentries to the most recent end, and on the second
- * pass we free them. The second pass must restart after
- * each dput(), but since the target dentries are all at
- * the end, it's really just a single traversal.
- */
-
/**
* shrink_dcache_sb - shrink dcache for a superblock
* @sb: superblock
*
* Shrink the dcache for the specified super block. This
- * is used to free the dcache before unmounting a file
- * system
+ * is used to reduce the dcache presence of a file system
+ * before re-mounting, and when invalidating the device
+ * holding a file system.
*/
void shrink_dcache_sb(struct super_block * sb)
{
- struct list_head *tmp, *next;
- struct dentry *dentry;
-
- /*
- * Pass one ... move the dentries for the specified
- * superblock to the most recent end of the unused list.
- */
- spin_lock(&dcache_lock);
- list_for_each_safe(tmp, next, &dentry_unused) {
- dentry = list_entry(tmp, struct dentry, d_lru);
- if (dentry->d_sb != sb)
- continue;
- list_move(tmp, &dentry_unused);
- }
-
- /*
- * Pass two ... free the dentries for this superblock.
- */
-repeat:
- list_for_each_safe(tmp, next, &dentry_unused) {
- dentry = list_entry(tmp, struct dentry, d_lru);
- if (dentry->d_sb != sb)
- continue;
- dentry_stat.nr_unused--;
- list_del_init(tmp);
- spin_lock(&dentry->d_lock);
- if (atomic_read(&dentry->d_count)) {
- spin_unlock(&dentry->d_lock);
- continue;
- }
- prune_one_dentry(dentry);
- cond_resched_lock(&dcache_lock);
- goto repeat;
- }
- spin_unlock(&dcache_lock);
+ shrink_dcache_parent(sb->s_root);
+ shrink_dcache_anon(sb);
}
/*
@@ -607,7 +564,7 @@ positive:
/*
* Search the dentry child list for the specified parent,
- * and move any unused dentries to the end of the unused
+ * and move any unused dentries to the end of a new unused
* list for prune_dcache(). We descend to the next level
* whenever the d_subdirs list is non-empty and continue
* searching.
@@ -619,7 +576,7 @@ positive:
* drop the lock and return early due to latency
* constraints.
*/
-static int select_parent(struct dentry * parent)
+static int select_parent(struct dentry * parent, struct list_head *new)
{
struct dentry *this_parent = parent;
struct list_head *next;
@@ -643,7 +600,7 @@ resume:
* of the unused list for prune_dcache
*/
if (!atomic_read(&dentry->d_count)) {
- list_add_tail(&dentry->d_lru, &dentry_unused);
+ list_add_tail(&dentry->d_lru, new);
dentry_stat.nr_unused++;
found++;
}
@@ -687,9 +644,10 @@ out:
void shrink_dcache_parent(struct dentry * parent)
{
int found;
+ LIST_HEAD(list);
- while ((found = select_parent(parent)) != 0)
- prune_dcache(found, parent->d_sb);
+ while ((found = select_parent(parent, &list)) != 0)
+ prune_dcache(found, &list);
}
/**
@@ -708,6 +666,7 @@ void shrink_dcache_anon(struct super_blo
struct hlist_head *head = &sb->s_anon;
int found;
do {
+ LIST_HEAD(list);
found = 0;
spin_lock(&dcache_lock);
hlist_for_each(lp, head) {
@@ -722,13 +681,13 @@ void shrink_dcache_anon(struct super_blo
* of the unused list for prune_dcache
*/
if (!atomic_read(&this->d_count)) {
- list_add_tail(&this->d_lru, &dentry_unused);
+ list_add_tail(&this->d_lru, &list);
dentry_stat.nr_unused++;
found++;
}
}
spin_unlock(&dcache_lock);
- prune_dcache(found, sb);
+ prune_dcache(found, &list);
} while(found);
}
next prev parent reply other threads:[~2006-06-19 1:21 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-01 9:51 [patch 0/5] [PATCH,RFC] vfs: per-superblock unused dentries list (2nd version) jblunck
2006-06-01 9:51 ` [patch 1/5] vfs: remove whitespace noise from fs/dcache.c jblunck
2006-06-01 9:51 ` [patch 2/5] vfs: d_genocide() doesnt add dentries to unused list jblunck
2006-06-01 9:51 ` [patch 3/5] vfs: remove shrink_dcache_anon() jblunck
2006-06-01 9:51 ` [patch 4/5] vfs: per superblock dentry stats jblunck
2006-06-01 9:51 ` [patch 5/5] vfs: per superblock dentry unused list jblunck
2006-06-02 1:06 ` [patch 0/5] [PATCH,RFC] vfs: per-superblock unused dentries list (2nd version) Andrew Morton
2006-06-02 2:23 ` David Chinner
2006-06-02 2:49 ` Andrew Morton
2006-06-02 4:17 ` David Chinner
2006-06-02 15:33 ` Jan Blunck
2006-06-05 1:30 ` Neil Brown
2006-06-16 15:51 ` Jan Blunck
2006-06-16 22:25 ` Neil Brown
2006-06-18 23:56 ` David Chinner
2006-06-19 0:27 ` Neil Brown
2006-06-19 1:00 ` David Chinner
2006-06-19 1:21 ` Neil Brown [this message]
2006-06-19 2:04 ` Andrew Morton
2006-06-19 2:25 ` Neil Brown
2006-06-19 5:55 ` David Chinner
2006-06-19 6:33 ` Andrew Morton
2006-06-19 8:30 ` David Chinner
2006-06-19 10:48 ` Thomas Gleixner
2006-06-19 11:01 ` Andrew Morton
2006-06-19 17:34 ` Ravinandan Arakali
2006-06-20 0:37 ` Andrew Morton
2006-06-20 21:34 ` Ravinandan Arakali
2006-06-20 22:10 ` Andrew Morton
2006-06-20 23:56 ` Ravinandan Arakali
2006-06-21 0:18 ` Andrew Morton
2006-06-21 0:31 ` Ravinandan Arakali
2006-06-19 9:34 ` Jan Blunck
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=17557.64512.496195.714144@cse.unsw.edu.au \
--to=neilb@suse.de \
--cc=akpm@osdl.org \
--cc=balbir@in.ibm.com \
--cc=dgc@sgi.com \
--cc=jblunck@suse.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.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).