[PATCH] simple fs stop -ve dentries

From: Hugh Dickins
Date: Thu Aug 05 2004 - 15:38:48 EST


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 <hugh@xxxxxxxxxxx>

--- 2.6.8-rc3-mm1/fs/libfs.c 2004-04-04 03:38:40.000000000 +0100
+++ linux/fs/libfs.c 2004-08-05 20:25:50.054872096 +0100
@@ -26,14 +26,27 @@ int simple_statfs(struct super_block *sb
}

/*
- * 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;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/