fs: clean up dentry lru modification

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>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Christoph Hellwig 2010-10-10 05:36:26 -04:00 committed by Al Viro
parent 3049cfe24e
commit a4633357ac

View file

@ -133,37 +133,34 @@ static void dentry_iput(struct dentry * 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) static void dentry_lru_add(struct dentry *dentry)
{ {
if (list_empty(&dentry->d_lru)) {
list_add(&dentry->d_lru, &dentry->d_sb->s_dentry_lru); list_add(&dentry->d_lru, &dentry->d_sb->s_dentry_lru);
dentry->d_sb->s_nr_dentry_unused++; dentry->d_sb->s_nr_dentry_unused++;
percpu_counter_inc(&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);
} }
static void dentry_lru_del(struct dentry *dentry) static void dentry_lru_del(struct dentry *dentry)
{ {
if (!list_empty(&dentry->d_lru)) { if (!list_empty(&dentry->d_lru)) {
list_del(&dentry->d_lru); list_del_init(&dentry->d_lru);
dentry->d_sb->s_nr_dentry_unused--; dentry->d_sb->s_nr_dentry_unused--;
percpu_counter_dec(&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))) { if (list_empty(&dentry->d_lru)) {
list_del_init(&dentry->d_lru); list_add_tail(&dentry->d_lru, &dentry->d_sb->s_dentry_lru);
dentry->d_sb->s_nr_dentry_unused--; dentry->d_sb->s_nr_dentry_unused++;
percpu_counter_dec(&nr_dentry_unused); percpu_counter_inc(&nr_dentry_unused);
} else {
list_move_tail(&dentry->d_lru, &dentry->d_sb->s_dentry_lru);
} }
} }
@ -253,7 +250,6 @@ repeat:
/* Otherwise leave it cached and ensure it's on the LRU */ /* Otherwise leave it cached and ensure it's on the LRU */
dentry->d_flags |= DCACHE_REFERENCED; 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(&dentry->d_lock);
@ -333,7 +329,7 @@ EXPORT_SYMBOL(d_invalidate);
static inline struct dentry * __dget_locked(struct dentry *dentry) static inline struct dentry * __dget_locked(struct dentry *dentry)
{ {
atomic_inc(&dentry->d_count); atomic_inc(&dentry->d_count);
dentry_lru_del_init(dentry); dentry_lru_del(dentry);
return dentry; return dentry;
} }
@ -452,7 +448,7 @@ static void prune_one_dentry(struct dentry * dentry)
if (dentry->d_op && dentry->d_op->d_delete) if (dentry->d_op && dentry->d_op->d_delete)
dentry->d_op->d_delete(dentry); dentry->d_op->d_delete(dentry);
dentry_lru_del_init(dentry); dentry_lru_del(dentry);
__d_drop(dentry); __d_drop(dentry);
dentry = d_kill(dentry); dentry = d_kill(dentry);
spin_lock(&dcache_lock); spin_lock(&dcache_lock);
@ -465,7 +461,7 @@ static void shrink_dentry_list(struct list_head *list)
while (!list_empty(list)) { while (!list_empty(list)) {
dentry = list_entry(list->prev, struct dentry, d_lru); 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 * We found an inuse dentry which was not removed from
@ -650,7 +646,7 @@ static void shrink_dcache_for_umount_subtree(struct dentry *dentry)
/* detach this root from the system */ /* detach this root from the system */
spin_lock(&dcache_lock); spin_lock(&dcache_lock);
dentry_lru_del_init(dentry); dentry_lru_del(dentry);
__d_drop(dentry); __d_drop(dentry);
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
@ -664,7 +660,7 @@ static void shrink_dcache_for_umount_subtree(struct dentry *dentry)
spin_lock(&dcache_lock); spin_lock(&dcache_lock);
list_for_each_entry(loop, &dentry->d_subdirs, list_for_each_entry(loop, &dentry->d_subdirs,
d_u.d_child) { d_u.d_child) {
dentry_lru_del_init(loop); dentry_lru_del(loop);
__d_drop(loop); __d_drop(loop);
cond_resched_lock(&dcache_lock); cond_resched_lock(&dcache_lock);
} }
@ -841,14 +837,15 @@ resume:
struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child); struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child);
next = tmp->next; next = tmp->next;
dentry_lru_del_init(dentry);
/* /*
* move only zero ref count dentries to the end * move only zero ref count dentries to the end
* of the unused list for prune_dcache * of the unused list for prune_dcache
*/ */
if (!atomic_read(&dentry->d_count)) { if (!atomic_read(&dentry->d_count)) {
dentry_lru_add_tail(dentry); dentry_lru_move_tail(dentry);
found++; found++;
} else {
dentry_lru_del(dentry);
} }
/* /*