Skip to contentSkip to conversation

Per-container dcache size limitation

PATCH Superseded Glauber Costa 4 participants 18 messages Aug 5, 2011 – Aug 12, 2011 3 messages not in the archive

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Per-container dcache size limitation

Hi,

Since v1, there is not too much new here.
I'm incorporating David's suggestion of calling the sb shrinker, which will, in effect, prune the icache and other sb related objects as well.

I am also keeping the mount based interface, since I still believe it is the way to go. But I'm obviously still open for suggestions. Some small corrections were also made to it since v1. Specifically, bind mounts are not allowed to alter the original sb dcache size.

Glauber Costa (4):
factor out single-shrinker code
Keep nr_dentry per super block
limit nr_dentries per superblock
parse options in the vfs level

 fs/dcache.c              |   44 +++++++++++-
 fs/namespace.c           |  105 ++++++++++++++++++++++++++
 fs/super.c               |   16 ++++-
 include/linux/dcache.h   |    4 +
 include/linux/fs.h       |    3 +
 include/linux/shrinker.h |    6 ++
 mm/vmscan.c              |  185 ++++++++++++++++++++++++----------------------
 7 files changed, 274 insertions(+), 89 deletions(-)
Signature · 1 line
1.7.6
#1 lore raw

PATCH v2 1/4 factor out single-shrinker code

While shrinking our caches, vmscan.c passes through all registered shrinkers, trying to free objects as it goes.

We would like to do that individually for some caches, like the dcache, when certain conditions apply (for example, when we reach a soon-to-exist maximum allowed size)

To avoid re-writing the same logic at more than one place, this patch factors out the shrink logic at shrink_one_shrinker(), that we can call from other places of the kernel.

---
 include/linux/shrinker.h |    6 ++
 mm/vmscan.c              |  185 ++++++++++++++++++++++++----------------------
 2 files changed, 104 insertions(+), 87 deletions(-)
include/linux/shrinker.h +6 -0
index 790651b..c5db650 100644
@@ -39,4 +39,10 @@ struct shrinker {
 #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
 extern void register_shrinker(struct shrinker *);
 extern void unregister_shrinker(struct shrinker *);
+
+unsigned long shrink_one_shrinker(struct shrinker *shrinker,
+				  struct shrink_control *shrink,
+				  unsigned long nr_pages_scanned,                      
+				  unsigned long lru_pages);
+
 #endif
mm/vmscan.c +98 -87

197 lines not on this page · raw message

Signature · 1 line
1.7.6
#3 lore raw

PATCH v2 1/4 factor out single-shrinker code

In reply to a message not in the archive

While shrinking our caches, vmscan.c passes through all registered shrinkers, trying to free objects as it goes.

We would like to do that individually for some caches, like the dcache, when certain conditions apply (for example, when we reach a soon-to-exist maximum allowed size)

To avoid re-writing the same logic at more than one place, this patch factors out the shrink logic at shrink_one_shrinker(), that we can call from other places of the kernel.

---
 include/linux/shrinker.h |    6 ++
 mm/vmscan.c              |  185 ++++++++++++++++++++++++----------------------
 2 files changed, 104 insertions(+), 87 deletions(-)
include/linux/shrinker.h +6 -0
index 790651b..c5db650 100644
@@ -39,4 +39,10 @@ struct shrinker {
 #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
 extern void register_shrinker(struct shrinker *);
 extern void unregister_shrinker(struct shrinker *);
+
+unsigned long shrink_one_shrinker(struct shrinker *shrinker,
+				  struct shrink_control *shrink,
+				  unsigned long nr_pages_scanned,                      
+				  unsigned long lru_pages);
+
 #endif
mm/vmscan.c +98 -87

197 lines not on this page · raw message

Signature · 1 line
1.7.6
#7 lore raw

PATCH v2 2/4 Keep nr_dentry per super block

In reply to Glauber Costa

Now that we have per-sb shrinkers, it makes sense to have nr_dentries stored per sb as well. We turn them into per-cpu counters so we can keep acessing them without locking.

---
 fs/dcache.c        |   12 +++++++++++-
 fs/super.c         |   15 ++++++++++++++-
 include/linux/fs.h |    2 ++
 3 files changed, 27 insertions(+), 2 deletions(-)
fs/dcache.c +11 -1
index b05aac3..ac19d24 100644
@@ -151,7 +151,13 @@ static void __d_free(struct rcu_head *head)
 static void d_free(struct dentry *dentry)
 {
 	BUG_ON(dentry->d_count);
+	/*
+	 * It is cheaper to keep a global counter separate
+	 * then to scan through all superblocks when needed
+	 */
 	this_cpu_dec(nr_dentry);
+	this_cpu_dec(*dentry->d_sb->s_nr_dentry);
+
 	if (dentry->d_op && dentry->d_op->d_release)
 		dentry->d_op->d_release(dentry);
 
@@ -1224,7 +1230,11 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
 	INIT_LIST_HEAD(&dentry->d_alias);
 	INIT_LIST_HEAD(&dentry->d_u.d_child);
 	d_set_d_op(dentry, dentry->d_sb->s_d_op);
-
+	/*
+	 * It is cheaper to keep a global counter separate
+	 * then to scan through all superblocks when needed
+	 */
+	this_cpu_inc(*dentry->d_sb->s_nr_dentry);
 	this_cpu_inc(nr_dentry);
 
 	return dentry;
fs/super.c +14 -1
index 3f56a26..9345385 100644
@@ -112,6 +112,7 @@ static struct super_block *alloc_super(struct file_system_type *type)
 {
 	struct super_block *s = kzalloc(sizeof(struct super_block),  GFP_USER);
 	static const struct super_operations default_op;
+	int i;
 
 	if (s) {
 		if (security_sb_alloc(s)) {
@@ -119,15 +120,26 @@ static struct super_block *alloc_super(struct file_system_type *type)
 			s = NULL;
 			goto out;
 		}
+
+		s->s_nr_dentry = alloc_percpu(int);
+		if (!s->s_nr_dentry) {
+			security_sb_free(s);
+			kfree(s);
+			s = NULL;
+			goto out;
+		}
+		for_each_possible_cpu(i)
+			*per_cpu_ptr(s->s_nr_dentry, i) = 0;
+
 #ifdef CONFIG_SMP
 		s->s_files = alloc_percpu(struct list_head);
 		if (!s->s_files) {
+			free_percpu(s->s_nr_dentry);
 			security_sb_free(s);
 			kfree(s);
 			s = NULL;
 			goto out;
 		} else {
-			int i;
 
 			for_each_possible_cpu(i)
 				INIT_LIST_HEAD(per_cpu_ptr(s->s_files, i));
@@ -198,6 +210,7 @@ static inline void destroy_super(struct super_block *s)
 {
 #ifdef CONFIG_SMP
 	free_percpu(s->s_files);
+	free_percpu(s->s_nr_dentry);
 #endif
 	security_sb_free(s);
 	kfree(s->s_subtype);
include/linux/fs.h +2 -0
index f23bcb7..35113fd 100644
@@ -1399,6 +1399,8 @@ struct super_block {
 	struct list_head	s_dentry_lru;	/* unused dentry lru */
 	int			s_nr_dentry_unused;	/* # of dentry on lru */
 
+	int __percpu 		*s_nr_dentry;		/* # of dentry on this sb */
+
 	/* s_inode_lru_lock protects s_inode_lru and s_nr_inodes_unused */
 	spinlock_t		s_inode_lru_lock ____cacheline_aligned_in_smp;
 	struct list_head	s_inode_lru;		/* unused inode lru */
Signature · 1 line
1.7.6
#4 lore raw

PATCH v2 3/4 limit nr_dentries per superblock

In reply to a message not in the archive

This patch lays the foundation for us to limit the dcache size. Each super block can have only a maximum amount of dentries under its sub-tree. Allocation fails if we we're over limit and the cache can't be pruned to free up space for the newcomers.

---
 fs/dcache.c        |   25 +++++++++++++++++++++++++
 fs/super.c         |    1 +
 include/linux/fs.h |    1 +
 3 files changed, 27 insertions(+), 0 deletions(-)
fs/dcache.c +25 -0
index ac19d24..52a0faf 100644
@@ -1180,6 +1180,28 @@ void shrink_dcache_parent(struct dentry * parent)
 }
 EXPORT_SYMBOL(shrink_dcache_parent);
 
+static int dcache_mem_check(struct super_block *sb)
+{
+	int i;
+	int nr_dentry;
+	struct shrink_control sc = {
+		.gfp_mask = GFP_KERNEL,
+	};
+
+	do {
+		nr_dentry = 0;
+		for_each_possible_cpu(i)
+			nr_dentry += per_cpu(*sb->s_nr_dentry, i);
+
+		if (nr_dentry < sb->s_nr_dentry_max)
+			return 0;
+
+	/* nr_pages = 1, lru_pages = 0 should get delta ~ 2 */
+	} while (shrink_one_shrinker(&sb->s_shrink, &sc, 1, 0));
+
+	return -ENOMEM;
+}
+
 /**
  * __d_alloc	-	allocate a dcache entry
  * @sb: filesystem it will belong to
@@ -1195,6 +1217,9 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
 	struct dentry *dentry;
 	char *dname;
 
+	if (dcache_mem_check(sb))
+		return NULL;
+
 	dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
 	if (!dentry)
 		return NULL;
fs/super.c +1 -0
index 9345385..d9bcae8 100644
@@ -130,6 +130,7 @@ static struct super_block *alloc_super(struct file_system_type *type)
 		}
 		for_each_possible_cpu(i)
 			*per_cpu_ptr(s->s_nr_dentry, i) = 0;
+		s->s_nr_dentry_max = INT_MAX;
 
 #ifdef CONFIG_SMP
 		s->s_files = alloc_percpu(struct list_head);
include/linux/fs.h +1 -0
index 35113fd..e90dcb4 100644
@@ -1399,6 +1399,7 @@ struct super_block {
 	struct list_head	s_dentry_lru;	/* unused dentry lru */
 	int			s_nr_dentry_unused;	/* # of dentry on lru */
 
+	int 			s_nr_dentry_max;	/* max # of dentry on this sb*/
 	int __percpu 		*s_nr_dentry;		/* # of dentry on this sb */
 
 	/* s_inode_lru_lock protects s_inode_lru and s_nr_inodes_unused */
Signature · 1 line
1.7.6
#5 lore raw

PATCH v2 4/4 parse options in the vfs level

In reply to a message not in the archive

This patch introduces a simple generic vfs option parser. Right now, the only option we have is to limit the size of the dcache.

So any user that wants to have a dcache entries limit, can specify:

mount -o whatever_options,vfs_dcache_size=XXX <dev> <mntpoint>

It is supposed to work well with remounts, allowing it to change multiple over the course of the filesystem's lifecycle.

I find mount a natural interface for handling filesystem options, so that's what I've choosen. Feel free to yell at it at will if you disagree.

---
 fs/dcache.c            |    7 +++
 fs/namespace.c         |  105 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/dcache.h |    4 ++
 3 files changed, 116 insertions(+), 0 deletions(-)
fs/dcache.c +7 -0
index 52a0faf..ace5670 100644
@@ -1202,6 +1202,13 @@ static int dcache_mem_check(struct super_block *sb)
 	return -ENOMEM;
 }
 
+int vfs_set_dcache_size(struct super_block *sb, int size)
+{
+	sb->s_nr_dentry_max = size;
+
+	return dcache_mem_check(sb);
+}
+
 /**
  * __d_alloc	-	allocate a dcache entry
  * @sb: filesystem it will belong to
fs/namespace.c +105 -0

141 lines not on this page · raw message

include/linux/dcache.h +4 -0
index d37d2a7..1a309f3 100644
@@ -251,6 +251,10 @@ 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);
+
+#define DCACHE_MIN_SIZE 1024
+extern int vfs_set_dcache_size(struct super_block *sb, int size);
 
 /* <clickety>-<click> the ramfs-type tree */
 extern void d_genocide(struct dentry *);
Signature · 1 line
1.7.6
#11 lore raw

PATCH v2 3/4 limit nr_dentries per superblock

In reply to Glauber Costa

This patch lays the foundation for us to limit the dcache size. Each super block can have only a maximum amount of dentries under its sub-tree. Allocation fails if we we're over limit and the cache can't be pruned to free up space for the newcomers.

---
 fs/dcache.c        |   25 +++++++++++++++++++++++++
 fs/super.c         |    1 +
 include/linux/fs.h |    1 +
 3 files changed, 27 insertions(+), 0 deletions(-)
fs/dcache.c +25 -0
index ac19d24..52a0faf 100644
@@ -1180,6 +1180,28 @@ void shrink_dcache_parent(struct dentry * parent)
 }
 EXPORT_SYMBOL(shrink_dcache_parent);
 
+static int dcache_mem_check(struct super_block *sb)
+{
+	int i;
+	int nr_dentry;
+	struct shrink_control sc = {
+		.gfp_mask = GFP_KERNEL,
+	};
+
+	do {
+		nr_dentry = 0;
+		for_each_possible_cpu(i)
+			nr_dentry += per_cpu(*sb->s_nr_dentry, i);
+
+		if (nr_dentry < sb->s_nr_dentry_max)
+			return 0;
+
+	/* nr_pages = 1, lru_pages = 0 should get delta ~ 2 */
+	} while (shrink_one_shrinker(&sb->s_shrink, &sc, 1, 0));
+
+	return -ENOMEM;
+}
+
 /**
  * __d_alloc	-	allocate a dcache entry
  * @sb: filesystem it will belong to
@@ -1195,6 +1217,9 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
 	struct dentry *dentry;
 	char *dname;
 
+	if (dcache_mem_check(sb))
+		return NULL;
+
 	dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
 	if (!dentry)
 		return NULL;
fs/super.c +1 -0
index 9345385..d9bcae8 100644
@@ -130,6 +130,7 @@ static struct super_block *alloc_super(struct file_system_type *type)
 		}
 		for_each_possible_cpu(i)
 			*per_cpu_ptr(s->s_nr_dentry, i) = 0;
+		s->s_nr_dentry_max = INT_MAX;
 
 #ifdef CONFIG_SMP
 		s->s_files = alloc_percpu(struct list_head);
include/linux/fs.h +1 -0
index 35113fd..e90dcb4 100644
@@ -1399,6 +1399,7 @@ struct super_block {
 	struct list_head	s_dentry_lru;	/* unused dentry lru */
 	int			s_nr_dentry_unused;	/* # of dentry on lru */
 
+	int 			s_nr_dentry_max;	/* max # of dentry on this sb*/
 	int __percpu 		*s_nr_dentry;		/* # of dentry on this sb */
 
 	/* s_inode_lru_lock protects s_inode_lru and s_nr_inodes_unused */
Signature · 1 line
1.7.6
#19 lore raw

PATCH v2 4/4 parse options in the vfs level

In reply to Glauber Costa

This patch introduces a simple generic vfs option parser. Right now, the only option we have is to limit the size of the dcache.

So any user that wants to have a dcache entries limit, can specify:

mount -o whatever_options,vfs_dcache_size=XXX <dev> <mntpoint>

It is supposed to work well with remounts, allowing it to change multiple over the course of the filesystem's lifecycle.

I find mount a natural interface for handling filesystem options, so that's what I've choosen. Feel free to yell at it at will if you disagree.

---
 fs/dcache.c            |    7 +++
 fs/namespace.c         |  105 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/dcache.h |    4 ++
 3 files changed, 116 insertions(+), 0 deletions(-)
fs/dcache.c +7 -0
index 52a0faf..ace5670 100644
@@ -1202,6 +1202,13 @@ static int dcache_mem_check(struct super_block *sb)
 	return -ENOMEM;
 }
 
+int vfs_set_dcache_size(struct super_block *sb, int size)
+{
+	sb->s_nr_dentry_max = size;
+
+	return dcache_mem_check(sb);
+}
+
 /**
  * __d_alloc	-	allocate a dcache entry
  * @sb: filesystem it will belong to
fs/namespace.c +105 -0

141 lines not on this page · raw message

include/linux/dcache.h +4 -0
index d37d2a7..1a309f3 100644
@@ -251,6 +251,10 @@ 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);
+
+#define DCACHE_MIN_SIZE 1024
+extern int vfs_set_dcache_size(struct super_block *sb, int size);
 
 /* <clickety>-<click> the ramfs-type tree */
 extern void d_genocide(struct dentry *);
Signature · 1 line
1.7.6
#6 lore raw
In reply to a message not in the archive
Quoted 20 lines · Glauber Costa

Hi,

Since v1, there is not too much new here.
I'm incorporating David's suggestion of calling the sb shrinker, which will, in effect, prune the icache and other sb related objects as well.

I am also keeping the mount based interface, since I still believe it is the way to go. But I'm obviously still open for suggestions. Some small corrections were also made to it since v1. Specifically, bind mounts are not allowed to alter the original sb dcache size.

Glauber Costa (4):
factor out single-shrinker code
Keep nr_dentry per super block
limit nr_dentries per superblock
parse options in the vfs level

Quoted 9 lines
  fs/dcache.c              |   44 +++++++++++-
  fs/namespace.c           |  105 ++++++++++++++++++++++++++
  fs/super.c               |   16 ++++-
  include/linux/dcache.h   |    4 +
  include/linux/fs.h       |    3 +
  include/linux/shrinker.h |    6 ++
  mm/vmscan.c              |  185 ++++++++++++++++++++++++----------------------
  7 files changed, 274 insertions(+), 89 deletions(-)

People,

Any comments on this? I think I addressed all the comments previously made, and if there are no further requests, I think this is ready for getting in. In case there are issues, please let me know so I can address them.

#20 lore raw
In reply to Glauber Costa
Quoted 20 lines · Glauber Costa

Hi,

Since v1, there is not too much new here.
I'm incorporating David's suggestion of calling the sb shrinker, which will, in effect, prune the icache and other sb related objects as well.

I am also keeping the mount based interface, since I still believe it is the way to go. But I'm obviously still open for suggestions. Some small corrections were also made to it since v1. Specifically, bind mounts are not allowed to alter the original sb dcache size.

Glauber Costa (4):
factor out single-shrinker code
Keep nr_dentry per super block
limit nr_dentries per superblock
parse options in the vfs level

Quoted 9 lines
  fs/dcache.c              |   44 +++++++++++-
  fs/namespace.c           |  105 ++++++++++++++++++++++++++
  fs/super.c               |   16 ++++-
  include/linux/dcache.h   |    4 +
  include/linux/fs.h       |    3 +
  include/linux/shrinker.h |    6 ++
  mm/vmscan.c              |  185 ++++++++++++++++++++++++----------------------
  7 files changed, 274 insertions(+), 89 deletions(-)

People,

Any comments on this? I think I addressed all the comments previously made, and if there are no further requests, I think this is ready for getting in. In case there are issues, please let me know so I can address them.

#9 lore raw

Re: [PATCH v2 2/4] Keep nr_dentry per super block

In reply to a message not in the archive
Quoted 17 lines · Glauber Costa

Now that we have per-sb shrinkers, it makes sense to have nr_dentries stored per sb as well. We turn them into per-cpu counters so we can keep acessing them without locking.

---
 fs/dcache.c        |   12 +++++++++++-
 fs/super.c         |   15 ++++++++++++++-
 include/linux/fs.h |    2 ++
 3 files changed, 27 insertions(+), 2 deletions(-)
fs/dcache.c +0 -0
index b05aac3..ac19d24 100644

fs/dcache.c static void __d_free(struct rcu_head *head) · line 156

Quoted 6 lines
fs/dcache.c +3 -0
@@ -151,7 +151,13 @@ static void __d_free(struct rcu_head *head)
 static void d_free(struct dentry *dentry)
 {
 	BUG_ON(dentry->d_count);
+	/*
+	 * It is cheaper to keep a global counter separate
+	 * then to scan through all superblocks when needed

"then to scan" or "than scanning" ?

Quoted 39 lines
fs/dcache.c +8 -1
+	 */
 	this_cpu_dec(nr_dentry);
+	this_cpu_dec(*dentry->d_sb->s_nr_dentry);
+
 	if (dentry->d_op && dentry->d_op->d_release)
 		dentry->d_op->d_release(dentry);
 
@@ -1224,7 +1230,11 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
 	INIT_LIST_HEAD(&dentry->d_alias);
 	INIT_LIST_HEAD(&dentry->d_u.d_child);
 	d_set_d_op(dentry, dentry->d_sb->s_d_op);
-
+	/*
+	 * It is cheaper to keep a global counter separate
+	 * then to scan through all superblocks when needed
+	 */
+	this_cpu_inc(*dentry->d_sb->s_nr_dentry);
 	this_cpu_inc(nr_dentry);
 
 	return dentry;
fs/super.c +4 -0
index 3f56a26..9345385 100644
@@ -112,6 +112,7 @@ static struct super_block *alloc_super(struct file_system_type *type)
 {
 	struct super_block *s = kzalloc(sizeof(struct super_block),  GFP_USER);
 	static const struct super_operations default_op;
+	int i;
 
 	if (s) {
 		if (security_sb_alloc(s)) {
@@ -119,15 +120,26 @@ static struct super_block *alloc_super(struct file_system_type *type)
 			s = NULL;
 			goto out;
 		}
+
+		s->s_nr_dentry = alloc_percpu(int);
+		if (!s->s_nr_dentry) {

fs/super.c static struct super_block *alloc_super(struct file_system_type *type) · line 135

Quoted 10 lines
fs/super.c +7 -0
+			security_sb_free(s);
+			kfree(s);
+			s = NULL;
+			goto out;
+		}
 
 
 
+		for_each_possible_cpu(i)
+			*per_cpu_ptr(s->s_nr_dentry, i) = 0;

This loop is not needed, alloc_percpu() gives zeroed data

Why dont you use a percpu_counter ?

_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers

#10 lore raw

Re: [PATCH v2 2/4] Keep nr_dentry per super block

In reply to Glauber Costa
Quoted 17 lines · Glauber Costa

Now that we have per-sb shrinkers, it makes sense to have nr_dentries stored per sb as well. We turn them into per-cpu counters so we can keep acessing them without locking.

---
 fs/dcache.c        |   12 +++++++++++-
 fs/super.c         |   15 ++++++++++++++-
 include/linux/fs.h |    2 ++
 3 files changed, 27 insertions(+), 2 deletions(-)
fs/dcache.c +0 -0
index b05aac3..ac19d24 100644

fs/dcache.c static void __d_free(struct rcu_head *head) · line 156

Quoted 6 lines
fs/dcache.c +3 -0
@@ -151,7 +151,13 @@ static void __d_free(struct rcu_head *head)
 static void d_free(struct dentry *dentry)
 {
 	BUG_ON(dentry->d_count);
+	/*
+	 * It is cheaper to keep a global counter separate
+	 * then to scan through all superblocks when needed

"then to scan" or "than scanning" ?

Quoted 39 lines
fs/dcache.c +8 -1
+	 */
 	this_cpu_dec(nr_dentry);
+	this_cpu_dec(*dentry->d_sb->s_nr_dentry);
+
 	if (dentry->d_op && dentry->d_op->d_release)
 		dentry->d_op->d_release(dentry);
 
@@ -1224,7 +1230,11 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
 	INIT_LIST_HEAD(&dentry->d_alias);
 	INIT_LIST_HEAD(&dentry->d_u.d_child);
 	d_set_d_op(dentry, dentry->d_sb->s_d_op);
-
+	/*
+	 * It is cheaper to keep a global counter separate
+	 * then to scan through all superblocks when needed
+	 */
+	this_cpu_inc(*dentry->d_sb->s_nr_dentry);
 	this_cpu_inc(nr_dentry);
 
 	return dentry;
fs/super.c +4 -0
index 3f56a26..9345385 100644
@@ -112,6 +112,7 @@ static struct super_block *alloc_super(struct file_system_type *type)
 {
 	struct super_block *s = kzalloc(sizeof(struct super_block),  GFP_USER);
 	static const struct super_operations default_op;
+	int i;
 
 	if (s) {
 		if (security_sb_alloc(s)) {
@@ -119,15 +120,26 @@ static struct super_block *alloc_super(struct file_system_type *type)
 			s = NULL;
 			goto out;
 		}
+
+		s->s_nr_dentry = alloc_percpu(int);
+		if (!s->s_nr_dentry) {

fs/super.c static struct super_block *alloc_super(struct file_system_type *type) · line 135

Quoted 10 lines
fs/super.c +7 -0
+			security_sb_free(s);
+			kfree(s);
+			s = NULL;
+			goto out;
+		}
 
 
 
+		for_each_possible_cpu(i)
+			*per_cpu_ptr(s->s_nr_dentry, i) = 0;

This loop is not needed, alloc_percpu() gives zeroed data

Why dont you use a percpu_counter ?

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

Re: [PATCH v2 3/4] limit nr_dentries per superblock

In reply to Glauber Costa
Quoted 23 lines · Glauber Costa

This patch lays the foundation for us to limit the dcache size. Each super block can have only a maximum amount of dentries under its sub-tree. Allocation fails if we we're over limit and the cache can't be pruned to free up space for the newcomers.

---
 fs/dcache.c        |   25 +++++++++++++++++++++++++
 fs/super.c         |    1 +
 include/linux/fs.h |    1 +
 3 files changed, 27 insertions(+), 0 deletions(-)
fs/dcache.c +2 -0
index ac19d24..52a0faf 100644
@@ -1180,6 +1180,28 @@ void shrink_dcache_parent(struct dentry * parent)
 }
 EXPORT_SYMBOL(shrink_dcache_parent);
 
+static int dcache_mem_check(struct super_block *sb)
+{

fs/dcache.c void shrink_dcache_parent(struct dentry * parent) · line 1194

Quoted 10 lines
fs/dcache.c +10 -0
+	int i;
+	int nr_dentry;
+	struct shrink_control sc = {
+		.gfp_mask = GFP_KERNEL,
+	};
+
+	do {
+		nr_dentry = 0;
+		for_each_possible_cpu(i)
+			nr_dentry += per_cpu(*sb->s_nr_dentry, i);

You seriously want to call this for every __d_alloc() invocation, even if s_nr_dentry_max is the default value (INT_MAX) ?

On a 4096 cpu machine, it will be _very_ slow.

A percpu_counter would be the thing to consider, since you can avoid the for_each_possible_cpu(i) loop if percpu_counter_read() is smaller than sb->s_nr_dentry_max.

Check how its done in include/net/tcp.h, tcp_too_many_orphans()

#18 lore raw

Re: [PATCH v2 3/4] limit nr_dentries per superblock

In reply to a message not in the archive
Quoted 23 lines · Glauber Costa

This patch lays the foundation for us to limit the dcache size. Each super block can have only a maximum amount of dentries under its sub-tree. Allocation fails if we we're over limit and the cache can't be pruned to free up space for the newcomers.

---
 fs/dcache.c        |   25 +++++++++++++++++++++++++
 fs/super.c         |    1 +
 include/linux/fs.h |    1 +
 3 files changed, 27 insertions(+), 0 deletions(-)
fs/dcache.c +2 -0
index ac19d24..52a0faf 100644
@@ -1180,6 +1180,28 @@ void shrink_dcache_parent(struct dentry * parent)
 }
 EXPORT_SYMBOL(shrink_dcache_parent);
 
+static int dcache_mem_check(struct super_block *sb)
+{

fs/dcache.c void shrink_dcache_parent(struct dentry * parent) · line 1194

Quoted 10 lines
fs/dcache.c +10 -0
+	int i;
+	int nr_dentry;
+	struct shrink_control sc = {
+		.gfp_mask = GFP_KERNEL,
+	};
+
+	do {
+		nr_dentry = 0;
+		for_each_possible_cpu(i)
+			nr_dentry += per_cpu(*sb->s_nr_dentry, i);

You seriously want to call this for every __d_alloc() invocation, even if s_nr_dentry_max is the default value (INT_MAX) ?

On a 4096 cpu machine, it will be _very_ slow.

A percpu_counter would be the thing to consider, since you can avoid the for_each_possible_cpu(i) loop if percpu_counter_read() is smaller than sb->s_nr_dentry_max.

Check how its done in include/net/tcp.h, tcp_too_many_orphans()

_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers

#13 lore raw

Re: [PATCH v2 3/4] limit nr_dentries per superblock

In reply to Eric Dumazet
Quoted 22 lines · Eric Dumazet
Quoted 21 lines · Glauber Costa

This patch lays the foundation for us to limit the dcache size. Each super block can have only a maximum amount of dentries under its sub-tree. Allocation fails if we we're over limit and the cache can't be pruned to free up space for the newcomers.

---
  fs/dcache.c        |   25 +++++++++++++++++++++++++
  fs/super.c         |    1 +
  include/linux/fs.h |    1 +
  3 files changed, 27 insertions(+), 0 deletions(-)
fs/dcache.c +0 -0
index ac19d24..52a0faf 100644
@@ -1180,6 +1180,28 @@ void shrink_dcache_parent(struct dentry * parent)
  }
  EXPORT_SYMBOL(shrink_dcache_parent);
 
Quoted 15 lines

fs/dcache.c void shrink_dcache_parent(struct dentry * parent) · line 1194

Quoted 12 lines
fs/dcache.c +12 -0
+static int dcache_mem_check(struct super_block *sb)
+{
+	int i;
+	int nr_dentry;
+	struct shrink_control sc = {
+		.gfp_mask = GFP_KERNEL,
+	};
+
+	do {
+		nr_dentry = 0;
+		for_each_possible_cpu(i)
+			nr_dentry += per_cpu(*sb->s_nr_dentry, i);

You seriously want to call this for every __d_alloc() invocation, even if s_nr_dentry_max is the default value (INT_MAX) ?

Well, I guess that special-casing INT_MAX is a good thing. I can include it in the next submission, I like it. Thanks.

Quoted 7 lines

On a 4096 cpu machine, it will be _very_ slow.

A percpu_counter would be the thing to consider, since you can avoid the for_each_possible_cpu(i) loop if percpu_counter_read() is smaller than sb->s_nr_dentry_max.

Check how its done in include/net/tcp.h, tcp_too_many_orphans()

Yeah, I guess I could do that. In fact, my first series used percpu_counters, and then I switched. But looking back, percpu_counters are indeed more suitable. The goal back then was trying to avoid percpu_counter_add, but as it is right now, we trade it for an even worse thing.

Thank you for your comments.
_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers

#14 lore raw

Re: [PATCH v2 3/4] limit nr_dentries per superblock

In reply to Eric Dumazet
Quoted 22 lines · Eric Dumazet
Quoted 21 lines · Glauber Costa

This patch lays the foundation for us to limit the dcache size. Each super block can have only a maximum amount of dentries under its sub-tree. Allocation fails if we we're over limit and the cache can't be pruned to free up space for the newcomers.

---
  fs/dcache.c        |   25 +++++++++++++++++++++++++
  fs/super.c         |    1 +
  include/linux/fs.h |    1 +
  3 files changed, 27 insertions(+), 0 deletions(-)
fs/dcache.c +0 -0
index ac19d24..52a0faf 100644
@@ -1180,6 +1180,28 @@ void shrink_dcache_parent(struct dentry * parent)
  }
  EXPORT_SYMBOL(shrink_dcache_parent);
 
Quoted 15 lines

fs/dcache.c void shrink_dcache_parent(struct dentry * parent) · line 1194

Quoted 12 lines
fs/dcache.c +12 -0
+static int dcache_mem_check(struct super_block *sb)
+{
+	int i;
+	int nr_dentry;
+	struct shrink_control sc = {
+		.gfp_mask = GFP_KERNEL,
+	};
+
+	do {
+		nr_dentry = 0;
+		for_each_possible_cpu(i)
+			nr_dentry += per_cpu(*sb->s_nr_dentry, i);

You seriously want to call this for every __d_alloc() invocation, even if s_nr_dentry_max is the default value (INT_MAX) ?

Well, I guess that special-casing INT_MAX is a good thing. I can include it in the next submission, I like it. Thanks.

Quoted 7 lines

On a 4096 cpu machine, it will be _very_ slow.

A percpu_counter would be the thing to consider, since you can avoid the for_each_possible_cpu(i) loop if percpu_counter_read() is smaller than sb->s_nr_dentry_max.

Check how its done in include/net/tcp.h, tcp_too_many_orphans()

Yeah, I guess I could do that. In fact, my first series used percpu_counters, and then I switched. But looking back, percpu_counters are indeed more suitable. The goal back then was trying to avoid percpu_counter_add, but as it is right now, we trade it for an even worse thing.

Thank you for your comments.
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#15 lore raw

Re: [PATCH v2 3/4] limit nr_dentries per superblock

In reply to Eric Dumazet
Quoted 22 lines · Eric Dumazet
Quoted 21 lines · Glauber Costa

This patch lays the foundation for us to limit the dcache size. Each super block can have only a maximum amount of dentries under its sub-tree. Allocation fails if we we're over limit and the cache can't be pruned to free up space for the newcomers.

---
  fs/dcache.c        |   25 +++++++++++++++++++++++++
  fs/super.c         |    1 +
  include/linux/fs.h |    1 +
  3 files changed, 27 insertions(+), 0 deletions(-)
fs/dcache.c +0 -0
index ac19d24..52a0faf 100644
@@ -1180,6 +1180,28 @@ void shrink_dcache_parent(struct dentry * parent)
  }
  EXPORT_SYMBOL(shrink_dcache_parent);
 
Quoted 15 lines

fs/dcache.c void shrink_dcache_parent(struct dentry * parent) · line 1194

Quoted 12 lines
fs/dcache.c +12 -0
+static int dcache_mem_check(struct super_block *sb)
+{
+	int i;
+	int nr_dentry;
+	struct shrink_control sc = {
+		.gfp_mask = GFP_KERNEL,
+	};
+
+	do {
+		nr_dentry = 0;
+		for_each_possible_cpu(i)
+			nr_dentry += per_cpu(*sb->s_nr_dentry, i);

You seriously want to call this for every __d_alloc() invocation, even if s_nr_dentry_max is the default value (INT_MAX) ?

Well, I guess that special-casing INT_MAX is a good thing. I can include it in the next submission, I like it. Thanks.

Quoted 7 lines

On a 4096 cpu machine, it will be _very_ slow.

A percpu_counter would be the thing to consider, since you can avoid the for_each_possible_cpu(i) loop if percpu_counter_read() is smaller than sb->s_nr_dentry_max.

Check how its done in include/net/tcp.h, tcp_too_many_orphans()

Yeah, I guess I could do that. In fact, my first series used percpu_counters, and then I switched. But looking back, percpu_counters are indeed more suitable. The goal back then was trying to avoid percpu_counter_add, but as it is right now, we trade it for an even worse thing.

Thank you for your comments.

#16 lore raw

Re: [PATCH v2 3/4] limit nr_dentries per superblock

In reply to Eric Dumazet
Quoted 22 lines · Eric Dumazet
Quoted 21 lines · Glauber Costa

This patch lays the foundation for us to limit the dcache size. Each super block can have only a maximum amount of dentries under its sub-tree. Allocation fails if we we're over limit and the cache can't be pruned to free up space for the newcomers.

---
  fs/dcache.c        |   25 +++++++++++++++++++++++++
  fs/super.c         |    1 +
  include/linux/fs.h |    1 +
  3 files changed, 27 insertions(+), 0 deletions(-)
fs/dcache.c +0 -0
index ac19d24..52a0faf 100644
@@ -1180,6 +1180,28 @@ void shrink_dcache_parent(struct dentry * parent)
  }
  EXPORT_SYMBOL(shrink_dcache_parent);
 
Quoted 15 lines

fs/dcache.c void shrink_dcache_parent(struct dentry * parent) · line 1194

Quoted 12 lines
fs/dcache.c +12 -0
+static int dcache_mem_check(struct super_block *sb)
+{
+	int i;
+	int nr_dentry;
+	struct shrink_control sc = {
+		.gfp_mask = GFP_KERNEL,
+	};
+
+	do {
+		nr_dentry = 0;
+		for_each_possible_cpu(i)
+			nr_dentry += per_cpu(*sb->s_nr_dentry, i);

You seriously want to call this for every __d_alloc() invocation, even if s_nr_dentry_max is the default value (INT_MAX) ?

Well, I guess that special-casing INT_MAX is a good thing. I can include it in the next submission, I like it. Thanks.

Quoted 7 lines

On a 4096 cpu machine, it will be _very_ slow.

A percpu_counter would be the thing to consider, since you can avoid the for_each_possible_cpu(i) loop if percpu_counter_read() is smaller than sb->s_nr_dentry_max.

Check how its done in include/net/tcp.h, tcp_too_many_orphans()

Yeah, I guess I could do that. In fact, my first series used percpu_counters, and then I switched. But looking back, percpu_counters are indeed more suitable. The goal back then was trying to avoid percpu_counter_add, but as it is right now, we trade it for an even worse thing.

Thank you for your comments.
_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers