Re: dentry bloat.

From: Linus Torvalds
Date: Sat May 08 2004 - 21:58:16 EST

while we're discussing the other things, how about for now
just having this fairly minimal patch to get rid of the most egregious
memory mis-use.

This removes the SLAB_HWCACHE_ALIGN and the cache line alignment on
"struct dentry", and to compensate for the fact that the inline name
length will shrink quite a bit it changes DNAME_INLINE_LEN_MIN from 16 to

It also re-orders the first few fields of the dentry, since the "count"
and "d_lock" should be 32-bit on most 64-bit architectures, so to avoid
having unnecessary unused space, we should just put them together
(everything else there is goign to be comprised of 64-bit entities, I

So this should bring the size of a dentry down to 160 bytes on x86, from
either 192 of 256 bytes (depending on cacheline size). And 24 bytes of
inline name (it can be a bit more on some architectures, due to longword
alignment or similar) should still capture most of the dentries by far.

Let's see what Andrew's more complex patches can do to bring the size of
"struct dentry" down further.


--- 1.71/fs/dcache.c Mon Apr 26 22:07:34 2004
+++ edited/fs/dcache.c Sat May 8 17:41:30 2004
@@ -1558,14 +1558,11 @@
* A constructor could be added for stable state like the lists,
* but it is probably not worth it because of the cache nature
* of the dcache.
- * If fragmentation is too bad then the SLAB_HWCACHE_ALIGN
- * flag could be removed here, to hint to the allocator that
- * it should not try to get multiple page regions.
dentry_cache = kmem_cache_create("dentry_cache",
sizeof(struct dentry),
if (!dentry_cache)
panic("Cannot create dentry cache");
===== include/linux/dcache.h 1.36 vs edited =====
--- 1.36/include/linux/dcache.h Mon Jan 19 15:38:11 2004
+++ edited/include/linux/dcache.h Sat May 8 19:39:47 2004
@@ -74,14 +74,14 @@
return end_name_hash(hash);


struct dcookie_struct;

struct dentry {
atomic_t d_count;
- unsigned long d_vfs_flags; /* moved here to be on same cacheline */
spinlock_t d_lock; /* per dentry lock */
+ unsigned long d_vfs_flags; /* moved here to be on same cacheline */
struct inode * d_inode; /* Where the name belongs to - NULL is negative */
struct list_head d_lru; /* LRU list */
struct list_head d_child; /* child of parent list */
@@ -102,7 +102,7 @@
struct hlist_node d_hash; /* lookup hash list */
struct hlist_head * d_bucket; /* lookup hash bucket */
unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
-} ____cacheline_aligned;

#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at