diff options
author | Eric Dumazet <dada1@cosmosbay.com> | 2006-01-08 04:03:32 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-08 23:13:58 -0500 |
commit | 5160ee6fc891a9ca114be0e90fa6655647bb64b2 (patch) | |
tree | 35d3740a777935582af1b78238f20d2c2971ed55 /fs/libfs.c | |
parent | 21b6bf143d05d77c350d9c6764ae090a877b66ea (diff) |
[PATCH] shrink dentry struct
Some long time ago, dentry struct was carefully tuned so that on 32 bits
UP, sizeof(struct dentry) was exactly 128, ie a power of 2, and a multiple
of memory cache lines.
Then RCU was added and dentry struct enlarged by two pointers, with nice
results for SMP, but not so good on UP, because breaking the above tuning
(128 + 8 = 136 bytes)
This patch reverts this unwanted side effect, by using an union (d_u),
where d_rcu and d_child are placed so that these two fields can share their
memory needs.
At the time d_free() is called (and d_rcu is really used), d_child is known
to be empty and not touched by the dentry freeing.
Lockless lookups only access d_name, d_parent, d_lock, d_op, d_flags (so
the previous content of d_child is not needed if said dentry was unhashed
but still accessed by a CPU because of RCU constraints)
As dentry cache easily contains millions of entries, a size reduction is
worth the extra complexity of the ugly C union.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Cc: Dipankar Sarma <dipankar@in.ibm.com>
Cc: Maneesh Soni <maneesh@in.ibm.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: "Paul E. McKenney" <paulmck@us.ibm.com>
Cc: Ian Kent <raven@themaw.net>
Cc: Paul Jackson <pj@sgi.com>
Cc: Al Viro <viro@ftp.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: Neil Brown <neilb@cse.unsw.edu.au>
Cc: James Morris <jmorris@namei.org>
Cc: Stephen Smalley <sds@epoch.ncsc.mil>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/libfs.c')
-rw-r--r-- | fs/libfs.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/fs/libfs.c b/fs/libfs.c index 58101dff2c66..9c50523382e7 100644 --- a/fs/libfs.c +++ b/fs/libfs.c | |||
@@ -93,16 +93,16 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int origin) | |||
93 | loff_t n = file->f_pos - 2; | 93 | loff_t n = file->f_pos - 2; |
94 | 94 | ||
95 | spin_lock(&dcache_lock); | 95 | spin_lock(&dcache_lock); |
96 | list_del(&cursor->d_child); | 96 | list_del(&cursor->d_u.d_child); |
97 | p = file->f_dentry->d_subdirs.next; | 97 | p = file->f_dentry->d_subdirs.next; |
98 | while (n && p != &file->f_dentry->d_subdirs) { | 98 | while (n && p != &file->f_dentry->d_subdirs) { |
99 | struct dentry *next; | 99 | struct dentry *next; |
100 | next = list_entry(p, struct dentry, d_child); | 100 | next = list_entry(p, struct dentry, d_u.d_child); |
101 | if (!d_unhashed(next) && next->d_inode) | 101 | if (!d_unhashed(next) && next->d_inode) |
102 | n--; | 102 | n--; |
103 | p = p->next; | 103 | p = p->next; |
104 | } | 104 | } |
105 | list_add_tail(&cursor->d_child, p); | 105 | list_add_tail(&cursor->d_u.d_child, p); |
106 | spin_unlock(&dcache_lock); | 106 | spin_unlock(&dcache_lock); |
107 | } | 107 | } |
108 | } | 108 | } |
@@ -126,7 +126,7 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir) | |||
126 | { | 126 | { |
127 | struct dentry *dentry = filp->f_dentry; | 127 | struct dentry *dentry = filp->f_dentry; |
128 | struct dentry *cursor = filp->private_data; | 128 | struct dentry *cursor = filp->private_data; |
129 | struct list_head *p, *q = &cursor->d_child; | 129 | struct list_head *p, *q = &cursor->d_u.d_child; |
130 | ino_t ino; | 130 | ino_t ino; |
131 | int i = filp->f_pos; | 131 | int i = filp->f_pos; |
132 | 132 | ||
@@ -153,7 +153,7 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir) | |||
153 | } | 153 | } |
154 | for (p=q->next; p != &dentry->d_subdirs; p=p->next) { | 154 | for (p=q->next; p != &dentry->d_subdirs; p=p->next) { |
155 | struct dentry *next; | 155 | struct dentry *next; |
156 | next = list_entry(p, struct dentry, d_child); | 156 | next = list_entry(p, struct dentry, d_u.d_child); |
157 | if (d_unhashed(next) || !next->d_inode) | 157 | if (d_unhashed(next) || !next->d_inode) |
158 | continue; | 158 | continue; |
159 | 159 | ||
@@ -261,7 +261,7 @@ int simple_empty(struct dentry *dentry) | |||
261 | int ret = 0; | 261 | int ret = 0; |
262 | 262 | ||
263 | spin_lock(&dcache_lock); | 263 | spin_lock(&dcache_lock); |
264 | list_for_each_entry(child, &dentry->d_subdirs, d_child) | 264 | list_for_each_entry(child, &dentry->d_subdirs, d_u.d_child) |
265 | if (simple_positive(child)) | 265 | if (simple_positive(child)) |
266 | goto out; | 266 | goto out; |
267 | ret = 1; | 267 | ret = 1; |