lkml.org 
[lkml]   [2003]   [Aug]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] dcache statistics race in 2.4
 Hello,

In fs/dcache.c, dentry_stat.nr_dentry is not protected by anything
and on a busy SMP machine, after a while, the count goes wild. I'm
attaching a patch which puts nr_dentry accounting inside dcache_lock.
One spin_lock/unlock pair is added to d_alloc on NULL parent path but
I think NULL parent is used only occasionally when allocating root
dentry so this patch shouldn't cause any performance impact.

If anything is wrong, please point out. If there's no comment in a
few days, I'll submit this to Marcelo.

TIA.

--
tejun

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.1085 -> 1.1086
# fs/dcache.c 1.24 -> 1.25
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/08/28 tj@atj.dyndns.org 1.1086
# - dentry_stat.nr_dentry race fix.
# --------------------------------------------
#
diff -Nru a/fs/dcache.c b/fs/dcache.c
--- a/fs/dcache.c Thu Aug 28 11:07:51 2003
+++ b/fs/dcache.c Thu Aug 28 11:07:51 2003
@@ -63,7 +63,6 @@
if (dname_external(dentry))
kfree(dentry->d_name.name);
kmem_cache_free(dentry_cache, dentry);
- dentry_stat.nr_dentry--;
}

/*
@@ -148,6 +147,7 @@
kill_it: {
struct dentry *parent;
list_del(&dentry->d_child);
+ dentry_stat.nr_dentry--;
/* drops the lock, at that point nobody can reach this dentry */
dentry_iput(dentry);
parent = dentry->d_parent;
@@ -297,6 +297,7 @@

list_del_init(&dentry->d_hash);
list_del(&dentry->d_child);
+ dentry_stat.nr_dentry--;
dentry_iput(dentry);
parent = dentry->d_parent;
d_free(dentry);
@@ -625,11 +626,15 @@
dentry->d_sb = parent->d_sb;
spin_lock(&dcache_lock);
list_add(&dentry->d_child, &parent->d_subdirs);
+ dentry_stat.nr_dentry++;
spin_unlock(&dcache_lock);
- } else
+ } else {
INIT_LIST_HEAD(&dentry->d_child);
+ spin_lock(&dcache_lock);
+ dentry_stat.nr_dentry++;
+ spin_unlock(&dcache_lock);
+ }

- dentry_stat.nr_dentry++;
return dentry;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 13:48    [W:0.103 / U:0.520 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site