[PATCH 3/4] dcache set size

From: Glauber Costa
Date: Fri Jul 29 2011 - 09:45:37 EST


Simple patch that provides a function allowing its caller to set
the maximum number of dentries that can exist at the same time
at a given super block. Will be used in a later patch.

Signed-off-by: Glauber Costa <glommer@xxxxxxxxxxxxx>
CC: Dave Chinner <david@xxxxxxxxxxxxx>
---
fs/dcache.c | 12 ++++++++++++
include/linux/dcache.h | 1 +
2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index 3bdb106..4369aa2 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1202,6 +1202,18 @@ static int dcache_mem_check(struct super_block *sb)
return -ENOMEM;
}

+int vfs_set_dcache_size(struct super_block *sb, int size)
+{
+ unsigned long dr = percpu_counter_sum_positive(&sb->s_nr_dentry);
+
+ if (size != sb->s_nr_dentry_max)
+ prune_dcache_sb(sb, dr - size);
+
+ sb->s_nr_dentry_max = size;
+
+ return 0;
+}
+
/**
* __d_alloc - allocate a dcache entry
* @sb: filesystem it will belong to
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index d37d2a7..cd1ab71 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -251,6 +251,7 @@ extern int d_invalidate(struct dentry *);

/* only used at mount-time */
extern struct dentry * d_alloc_root(struct inode *);
+extern int vfs_set_dcache_size(struct super_block *sb, int size);

/* <clickety>-<click> the ramfs-type tree */
extern void d_genocide(struct dentry *);
--
1.7.6

--
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/