From: Dave Chinner <david@fromorbit.com>
To: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, khlebnikov@openvz.org
Subject: [PATCH 12/13] dcache: remove dentries from LRU before putting on dispose list
Date: Tue, 23 Aug 2011 18:56:25 +1000 [thread overview]
Message-ID: <1314089786-20535-13-git-send-email-david@fromorbit.com> (raw)
In-Reply-To: <1314089786-20535-1-git-send-email-david@fromorbit.com>
From: Dave Chinner <dchinner@redhat.com>
One of the big problems with modifying the way the dcache shrinker
and LRU implementation works is that the LRU is abused in several
ways. One of these is shrinker_dentry_list().
Basically, we can move a dentry off the LRU onto a different list
without doing any accounting changes, and then use dentry_lru_del()
to remove it from what-ever list it is now on to do the LRU
accounting at that point.
This makes it -really hard- to change the LRU implementation. The
use of the per-sb LRU lock serialises movement of the dentries
between the different lists and the removal of them, and this is the
only reason that it works. If we want to break up the dentry LRU
lock and lists into, say, per-node lists, we remove the only
serialisation that allows this lru list/dispose list abuse to work.
To make this work effectively, the dispose list has to be isolated
from the LRU list - dentries have to be removed from the LRU
*before* being placed on the dispose list. This means that the LRU
accounting and isolation is completed before disposal is started,
and that means we can change the LRU implementation freely in
future..
Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
fs/dcache.c | 25 ++++++++++++++++++++-----
1 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index b931415..79bf47c 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -269,10 +269,10 @@ static void dentry_lru_move_list(struct dentry *dentry, struct list_head *list)
spin_lock(&dentry->d_sb->s_dentry_lru_lock);
if (list_empty(&dentry->d_lru)) {
list_add_tail(&dentry->d_lru, list);
- dentry->d_sb->s_nr_dentry_unused++;
- this_cpu_inc(nr_dentry_unused);
} else {
list_move_tail(&dentry->d_lru, list);
+ dentry->d_sb->s_nr_dentry_unused--;
+ this_cpu_dec(nr_dentry_unused);
}
spin_unlock(&dentry->d_sb->s_dentry_lru_lock);
}
@@ -732,12 +732,17 @@ static void shrink_dentry_list(struct list_head *list)
}
/*
+ * The dispose list is isolated and dentries are not accounted
+ * to the LRU here, so we can simply remove it from the list
+ * here regardless of whether it is referenced or not.
+ */
+ list_del_init(&dentry->d_lru);
+
+ /*
* We found an inuse dentry which was not removed from
- * the LRU because of laziness during lookup. Do not free
- * it - just keep it off the LRU list.
+ * the LRU because of laziness during lookup. Do not free it.
*/
if (dentry->d_count) {
- dentry_lru_del(dentry);
spin_unlock(&dentry->d_lock);
continue;
}
@@ -789,6 +794,8 @@ relock:
spin_unlock(&dentry->d_lock);
} else {
list_move_tail(&dentry->d_lru, &tmp);
+ this_cpu_dec(nr_dentry_unused);
+ sb->s_nr_dentry_unused--;
spin_unlock(&dentry->d_lock);
freed++;
if (!--nr_to_scan)
@@ -818,6 +825,14 @@ void shrink_dcache_sb(struct super_block *sb)
spin_lock(&sb->s_dentry_lru_lock);
while (!list_empty(&sb->s_dentry_lru)) {
list_splice_init(&sb->s_dentry_lru, &tmp);
+
+ /*
+ * account for removal here so we don't need to handle it later
+ * even though the dentry is no longer on the lru list.
+ */
+ this_cpu_sub(nr_dentry_unused, sb->s_nr_dentry_unused);
+ sb->s_nr_dentry_unused = 0;
+
spin_unlock(&sb->s_dentry_lru_lock);
shrink_dentry_list(&tmp);
spin_lock(&sb->s_dentry_lru_lock);
--
1.7.5.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2011-08-23 8:56 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-23 8:56 [PATCH 00/12] RFC: shrinker APi rework and generic LRU lists Dave Chinner
2011-08-23 8:56 ` [PATCH 01/13] fs: Use a common define for inode slab caches Dave Chinner
2011-08-23 9:13 ` Christoph Hellwig
2011-08-23 9:20 ` Dave Chinner
2011-08-24 6:16 ` Christoph Hellwig
2011-08-23 8:56 ` [PATCH 02/13] dcache: convert dentry_stat.nr_unused to per-cpu counters Dave Chinner
2011-08-23 9:13 ` Christoph Hellwig
2011-08-24 14:12 ` Christoph Lameter
2011-08-23 8:56 ` [PATCH 03/13] dentry: move to per-sb LRU locks Dave Chinner
2011-08-24 6:16 ` Christoph Hellwig
2011-08-23 8:56 ` [PATCH 04/13] mm: new shrinker API Dave Chinner
2011-08-23 9:15 ` Christoph Hellwig
2011-08-23 9:23 ` Dave Chinner
2011-08-24 6:17 ` Christoph Hellwig
2011-08-23 8:56 ` [PATCH 05/13] mm: convert shrinkers to use new API Dave Chinner
2011-08-23 9:17 ` Christoph Hellwig
2011-08-23 9:35 ` Steven Whitehouse
2011-08-26 17:09 ` Wanlong Gao
2011-08-23 8:56 ` [PATCH 06/13] shrinker: remove old API now it is unused Dave Chinner
2011-08-23 8:56 ` [PATCH 07/13] Use atomic-long operations instead of looping around cmpxchg() Dave Chinner
2011-08-23 8:56 ` [PATCH 08/13] list: add a new LRU list type Dave Chinner
2011-08-23 9:20 ` Christoph Hellwig
2011-08-23 9:32 ` Dave Chinner
2011-08-23 9:58 ` Konstantin Khlebnikov
2011-08-24 14:24 ` Christoph Lameter
2011-08-23 8:56 ` [PATCH 09/13] inode: convert inode lru list to generic lru list code Dave Chinner
2011-08-24 6:38 ` Christoph Hellwig
2011-08-23 8:56 ` [PATCH 10/13] xfs: convert buftarg LRU to generic code Dave Chinner
2011-08-24 6:27 ` Christoph Hellwig
2011-08-23 8:56 ` [PATCH 11/13] dcache: use a dispose list in select_parent Dave Chinner
2011-08-23 9:37 ` Christoph Hellwig
2011-09-05 9:42 ` Christoph Hellwig
2011-08-23 8:56 ` Dave Chinner [this message]
2011-08-23 9:35 ` [PATCH 12/13] dcache: remove dentries from LRU before putting on dispose list Christoph Hellwig
2011-08-23 9:57 ` Dave Chinner
2011-08-23 8:56 ` [PATCH 13/13] dcache: convert to use new lru list infrastructure Dave Chinner
2011-08-24 6:32 ` Christoph Hellwig
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=1314089786-20535-13-git-send-email-david@fromorbit.com \
--to=david@fromorbit.com \
--cc=khlebnikov@openvz.org \
--cc=linux-fsdevel@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).