From: Christoph Hellwig <hch@infradead.org>
To: viro@zeniv.linux.org.uk
Cc: eparis@redhat.com, linux-fsdevel@vger.kernel.org
Subject: [PATCH 06/10] fs: clean up dentry lru modification
Date: Sun, 10 Oct 2010 05:36:26 -0400 [thread overview]
Message-ID: <20101010093721.657372574@canuck.infradead.org> (raw)
In-Reply-To: 20101010093620.416498597@canuck.infradead.org
[-- Attachment #1: dcache-simplify-lru --]
[-- Type: text/plain, Size: 4379 bytes --]
Always do a list_del_init on the LRU to make sure the list_empty invariant for
not beeing on the LRU always holds true, and fold dentry_lru_del_init into
dentry_lru_del. Replace the dentry_lru_add_tail primitive with a
dentry_lru_move_tail operations that simpler when the dentry already is one
the list, which is always is. Move the list_empty into dentry_lru_add to
fit the scheme of the other lru helpers, and simplify locking once we
move to a separate LRU lock.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Index: linux-2.6/fs/dcache.c
===================================================================
--- linux-2.6.orig/fs/dcache.c 2010-10-09 23:02:16.223005663 +0200
+++ linux-2.6/fs/dcache.c 2010-10-10 09:35:59.292254021 +0200
@@ -133,37 +133,34 @@ static void dentry_iput(struct dentry *
}
/*
- * dentry_lru_(add|add_tail|del|del_init) must be called with dcache_lock held.
+ * dentry_lru_(add|del|move_tail) must be called with dcache_lock held.
*/
static void dentry_lru_add(struct dentry *dentry)
{
- list_add(&dentry->d_lru, &dentry->d_sb->s_dentry_lru);
- dentry->d_sb->s_nr_dentry_unused++;
- percpu_counter_inc(&nr_dentry_unused);
-}
-
-static void dentry_lru_add_tail(struct dentry *dentry)
-{
- list_add_tail(&dentry->d_lru, &dentry->d_sb->s_dentry_lru);
- dentry->d_sb->s_nr_dentry_unused++;
- percpu_counter_inc(&nr_dentry_unused);
+ if (list_empty(&dentry->d_lru)) {
+ list_add(&dentry->d_lru, &dentry->d_sb->s_dentry_lru);
+ dentry->d_sb->s_nr_dentry_unused++;
+ percpu_counter_inc(&nr_dentry_unused);
+ }
}
static void dentry_lru_del(struct dentry *dentry)
{
if (!list_empty(&dentry->d_lru)) {
- list_del(&dentry->d_lru);
+ list_del_init(&dentry->d_lru);
dentry->d_sb->s_nr_dentry_unused--;
percpu_counter_dec(&nr_dentry_unused);
}
}
-static void dentry_lru_del_init(struct dentry *dentry)
+static void dentry_lru_move_tail(struct dentry *dentry)
{
- if (likely(!list_empty(&dentry->d_lru))) {
- list_del_init(&dentry->d_lru);
- dentry->d_sb->s_nr_dentry_unused--;
- percpu_counter_dec(&nr_dentry_unused);
+ if (list_empty(&dentry->d_lru)) {
+ list_add_tail(&dentry->d_lru, &dentry->d_sb->s_dentry_lru);
+ dentry->d_sb->s_nr_dentry_unused++;
+ percpu_counter_inc(&nr_dentry_unused);
+ } else {
+ list_move_tail(&dentry->d_lru, &dentry->d_sb->s_dentry_lru);
}
}
@@ -253,8 +250,7 @@ repeat:
/* Otherwise leave it cached and ensure it's on the LRU */
dentry->d_flags |= DCACHE_REFERENCED;
- if (list_empty(&dentry->d_lru))
- dentry_lru_add(dentry);
+ dentry_lru_add(dentry);
spin_unlock(&dentry->d_lock);
spin_unlock(&dcache_lock);
@@ -333,7 +329,7 @@ EXPORT_SYMBOL(d_invalidate);
static inline struct dentry * __dget_locked(struct dentry *dentry)
{
atomic_inc(&dentry->d_count);
- dentry_lru_del_init(dentry);
+ dentry_lru_del(dentry);
return dentry;
}
@@ -452,7 +448,7 @@ static void prune_one_dentry(struct dent
if (dentry->d_op && dentry->d_op->d_delete)
dentry->d_op->d_delete(dentry);
- dentry_lru_del_init(dentry);
+ dentry_lru_del(dentry);
__d_drop(dentry);
dentry = d_kill(dentry);
spin_lock(&dcache_lock);
@@ -465,7 +461,7 @@ static void shrink_dentry_list(struct li
while (!list_empty(list)) {
dentry = list_entry(list->prev, struct dentry, d_lru);
- dentry_lru_del_init(dentry);
+ dentry_lru_del(dentry);
/*
* We found an inuse dentry which was not removed from
@@ -650,7 +646,7 @@ static void shrink_dcache_for_umount_sub
/* detach this root from the system */
spin_lock(&dcache_lock);
- dentry_lru_del_init(dentry);
+ dentry_lru_del(dentry);
__d_drop(dentry);
spin_unlock(&dcache_lock);
@@ -664,7 +660,7 @@ static void shrink_dcache_for_umount_sub
spin_lock(&dcache_lock);
list_for_each_entry(loop, &dentry->d_subdirs,
d_u.d_child) {
- dentry_lru_del_init(loop);
+ dentry_lru_del(loop);
__d_drop(loop);
cond_resched_lock(&dcache_lock);
}
@@ -841,14 +837,15 @@ resume:
struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child);
next = tmp->next;
- dentry_lru_del_init(dentry);
/*
* move only zero ref count dentries to the end
* of the unused list for prune_dcache
*/
if (!atomic_read(&dentry->d_count)) {
- dentry_lru_add_tail(dentry);
+ dentry_lru_move_tail(dentry);
found++;
+ } else {
+ dentry_lru_del(dentry);
}
/*
next prev parent reply other threads:[~2010-10-10 9:37 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-10 9:36 [PATCH 00/10] dcache cleanups Christoph Hellwig
2010-10-10 9:36 ` [PATCH 01/10] [PATCH] fs: take dcache_lock inside __d_path Christoph Hellwig
2010-10-10 9:36 ` [PATCH 02/10] fs: simplify __d_free Christoph Hellwig
2010-10-10 9:36 ` [PATCH 03/10] fs: use percpu counter for nr_dentry and nr_dentry_unused Christoph Hellwig
2010-10-10 9:36 ` [PATCH 04/10] fs: improve DCACHE_REFERENCED usage Christoph Hellwig
2010-10-10 9:36 ` [PATCH 05/10] fs: split __shrink_dcache_sb Christoph Hellwig
2010-10-10 9:36 ` Christoph Hellwig [this message]
2010-10-10 9:36 ` [PATCH 07/10] fs: use RCU read side protection in d_validate Christoph Hellwig
2010-10-10 9:36 ` [PATCH 08/10] exportfs: use dget_parent Christoph Hellwig
2010-10-10 9:36 ` [PATCH 09/10] smbfs: " Christoph Hellwig
2010-10-10 9:36 ` [PATCH 10/10] fsnotify: " Christoph Hellwig
2010-10-11 13:59 ` Eric Paris
2010-10-13 1:04 ` [PATCH 00/10] dcache cleanups Dave Chinner
2010-10-13 11:21 ` Christoph Hellwig
2010-10-13 1:46 ` Dave Chinner
2010-10-13 11:22 ` Christoph Hellwig
2010-10-13 15:56 ` Christoph Hellwig
2010-10-16 8:17 ` Nick Piggin
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=20101010093721.657372574@canuck.infradead.org \
--to=hch@infradead.org \
--cc=eparis@redhat.com \
--cc=linux-fsdevel@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).