Per-container dcache size limitation
Subsystems (5)
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
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
@@ -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
A message that is not in the archive (sent off-list or not yet received): 1312504544-1108-1-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org
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
@@ -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
PATCH v2 3/4 limit nr_dentries per superblock
In reply to a message not in the archiveThis 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
@@ -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
@@ -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
@@ -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
PATCH v2 4/4 parse options in the vfs level
In reply to a message not in the archiveThis 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
@@ -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
@@ -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
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
Keepnr_dentryper super block
limitnr_dentriesper 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.
PATCH v2 2/4 Keep nr_dentry per super block
In reply to Glauber CostaNow 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
@@ -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
@@ -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
@@ -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
A message that is not in the archive (sent off-list or not yet received): 1312504544-1108-3-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org
Re: [PATCH v2 2/4] Keep nr_dentry per super block
Quoted 17 lines · Glauber Costa
Now that we have per-sb shrinkers, it makes sense to have
nr_dentriesstored per sb as well. We turn them into per-cpu counters so we can keep acessing them without locking.Signed-off-by Glauber Costa <[email protected]>CC Dave Chinner <[email protected]>--- 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
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@@ -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
Re: [PATCH v2 2/4] Keep nr_dentry per super block
In reply to Glauber CostaQuoted 17 lines · Glauber Costa
Now that we have per-sb shrinkers, it makes sense to have
nr_dentriesstored per sb as well. We turn them into per-cpu counters so we can keep acessing them without locking.Signed-off-by Glauber Costa <[email protected]>CC Dave Chinner <[email protected]>--- 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
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@@ -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
PATCH v2 3/4 limit nr_dentries per superblock
In reply to Glauber CostaThis 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
@@ -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
@@ -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
@@ -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
Re: [PATCH v2 3/4] limit nr_dentries per superblock
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.
Signed-off-by Glauber Costa <[email protected]>CC Dave Chinner <[email protected]>--- 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@@ -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()
Re: [PATCH v2 3/4] limit nr_dentries per superblock
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.
Signed-off-by Glauber Costa<[email protected]>CC Dave Chinner<[email protected]>--- 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@@ -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 ifs_nr_dentry_maxis 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_counterwould be the thing to consider, since you can avoid thefor_each_possible_cpu(i)loop ifpercpu_counter_read()is smaller thansb->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
Re: [PATCH v2 3/4] limit nr_dentries per superblock
In reply to Eric DumazetQuoted 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.
Signed-off-by Glauber Costa<[email protected]>CC Dave Chinner<[email protected]>--- 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@@ -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 ifs_nr_dentry_maxis 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_counterwould be the thing to consider, since you can avoid thefor_each_possible_cpu(i)loop ifpercpu_counter_read()is smaller thansb->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
Re: [PATCH v2 3/4] limit nr_dentries per superblock
In reply to Eric DumazetQuoted 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.
Signed-off-by Glauber Costa<[email protected]>CC Dave Chinner<[email protected]>--- 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@@ -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 ifs_nr_dentry_maxis 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_counterwould be the thing to consider, since you can avoid thefor_each_possible_cpu(i)loop ifpercpu_counter_read()is smaller thansb->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.
Re: [PATCH v2 3/4] limit nr_dentries per superblock
In reply to Eric DumazetQuoted 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.
Signed-off-by Glauber Costa<[email protected]>CC Dave Chinner<[email protected]>--- 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@@ -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 ifs_nr_dentry_maxis 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_counterwould be the thing to consider, since you can avoid thefor_each_possible_cpu(i)loop ifpercpu_counter_read()is smaller thansb->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
A message that is not in the archive (sent off-list or not yet received): 1312504544-1108-4-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org
Re: [PATCH v2 3/4] limit nr_dentries per superblock
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.
Signed-off-by Glauber Costa <[email protected]>CC Dave Chinner <[email protected]>--- 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@@ -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
PATCH v2 4/4 parse options in the vfs level
In reply to Glauber CostaThis 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
@@ -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
@@ -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
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
Keepnr_dentryper super block
limitnr_dentriesper 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.