Commit 4a0962ab authored by Christoph Lameter's avatar Christoph Lameter Committed by Linus Torvalds

dentries: Extract common code to remove dentry from lru

Extract the common code to remove a dentry from the lru into a new function
dentry_lru_remove().

Two call sites used list_del() instead of list_del_init().  AFAIK the
performance of both is the same.  dentry_lru_remove() does a list_del_init().

As a result dentry->d_lru is now always empty when a dentry is freed.
Signed-off-by: default avatarChristoph Lameter <clameter@sgi.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent cf28b486
...@@ -95,6 +95,14 @@ static void d_free(struct dentry *dentry) ...@@ -95,6 +95,14 @@ static void d_free(struct dentry *dentry)
call_rcu(&dentry->d_u.d_rcu, d_callback); call_rcu(&dentry->d_u.d_rcu, d_callback);
} }
static void dentry_lru_remove(struct dentry *dentry)
{
if (!list_empty(&dentry->d_lru)) {
list_del_init(&dentry->d_lru);
dentry_stat.nr_unused--;
}
}
/* /*
* Release the dentry's inode, using the filesystem * Release the dentry's inode, using the filesystem
* d_iput() operation if defined. * d_iput() operation if defined.
...@@ -211,13 +219,7 @@ void dput(struct dentry *dentry) ...@@ -211,13 +219,7 @@ void dput(struct dentry *dentry)
unhash_it: unhash_it:
__d_drop(dentry); __d_drop(dentry);
kill_it: kill_it:
/* If dentry was on d_lru list dentry_lru_remove(dentry);
* delete it from there
*/
if (!list_empty(&dentry->d_lru)) {
list_del(&dentry->d_lru);
dentry_stat.nr_unused--;
}
dentry = d_kill(dentry); dentry = d_kill(dentry);
if (dentry) if (dentry)
goto repeat; goto repeat;
...@@ -285,10 +287,7 @@ int d_invalidate(struct dentry * dentry) ...@@ -285,10 +287,7 @@ int d_invalidate(struct dentry * dentry)
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);
if (!list_empty(&dentry->d_lru)) { dentry_lru_remove(dentry);
dentry_stat.nr_unused--;
list_del_init(&dentry->d_lru);
}
return dentry; return dentry;
} }
...@@ -404,10 +403,7 @@ static void prune_one_dentry(struct dentry * dentry) ...@@ -404,10 +403,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);
if (!list_empty(&dentry->d_lru)) { dentry_lru_remove(dentry);
list_del(&dentry->d_lru);
dentry_stat.nr_unused--;
}
__d_drop(dentry); __d_drop(dentry);
dentry = d_kill(dentry); dentry = d_kill(dentry);
spin_lock(&dcache_lock); spin_lock(&dcache_lock);
...@@ -596,10 +592,7 @@ static void shrink_dcache_for_umount_subtree(struct dentry *dentry) ...@@ -596,10 +592,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);
if (!list_empty(&dentry->d_lru)) { dentry_lru_remove(dentry);
dentry_stat.nr_unused--;
list_del_init(&dentry->d_lru);
}
__d_drop(dentry); __d_drop(dentry);
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
...@@ -613,11 +606,7 @@ static void shrink_dcache_for_umount_subtree(struct dentry *dentry) ...@@ -613,11 +606,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) {
if (!list_empty(&loop->d_lru)) { dentry_lru_remove(loop);
dentry_stat.nr_unused--;
list_del_init(&loop->d_lru);
}
__d_drop(loop); __d_drop(loop);
cond_resched_lock(&dcache_lock); cond_resched_lock(&dcache_lock);
} }
...@@ -799,10 +788,7 @@ static int select_parent(struct dentry * parent) ...@@ -799,10 +788,7 @@ static int select_parent(struct dentry * parent)
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;
if (!list_empty(&dentry->d_lru)) { dentry_lru_remove(dentry);
dentry_stat.nr_unused--;
list_del_init(&dentry->d_lru);
}
/* /*
* 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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment