From 8a34e562b3613ff2d68308c69ea8842caf9c0df7 Mon Sep 17 00:00:00 2001 From: Hugh Dickins Date: Mon, 23 Aug 2004 21:25:21 -0700 Subject: [PATCH] [PATCH] simple fs stop -ve dentries A tmpfs user reported increasingly slow directory reads when repeatedly creating and unlinking in a mkstemp-like way. The negative dentries accumulate alarmingly (until memory pressure finally frees them), and are just a hindrance to any in-memory filesystem. simple_lookup set d_op to arrange for negative dentries to be deleted immediately. (But I failed to discover how it is that on-disk filesystems seem to keep their negative dentries within manageable bounds: this effect was gross with tmpfs or ramfs, but no problem at all with extN or reiser.) Signed-off-by: Hugh Dickins Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/libfs.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 205cfdbe2bc11..eac69c91b1a0f 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -27,14 +27,27 @@ int simple_statfs(struct super_block *sb, struct kstatfs *buf) } /* - * Lookup the data. This is trivial - if the dentry didn't already - * exist, we know it is negative. + * Retaining negative dentries for an in-memory filesystem just wastes + * memory and lookup time: arrange for them to be deleted immediately. */ +static int simple_delete_dentry(struct dentry *dentry) +{ + return 1; +} +/* + * Lookup the data. This is trivial - if the dentry didn't already + * exist, we know it is negative. Set d_op to delete negative dentries. + */ struct dentry *simple_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) { + static struct dentry_operations simple_dentry_operations = { + .d_delete = simple_delete_dentry, + }; + if (dentry->d_name.len > NAME_MAX) return ERR_PTR(-ENAMETOOLONG); + dentry->d_op = &simple_dentry_operations; d_add(dentry, NULL); return NULL; } -- 2.53.0