slab: add a check for the first kmem_cache not to be destroyed
Subsystems (2)
PATCH 1/1 slab: add a check for the first kmem_cache not to be destroyed
The first kmem_cache created at booting up is supposed neither mergeable nor destroyable but was possible to destroy. So prevent it.
--- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slab_common.c +1 -1
@@ -744,7 +744,7 @@ void kmem_cache_destroy(struct kmem_cache *s)bool need_rcu_barrier = false;int err; -if (unlikely (!s)) +if (unlikely (!s) || s->refcount ==-1 )return ;get_online_cpus ();
Signature · 1 line
2.9.3 (Apple Git-75)
Quoted 13 lines · Kyunghwan Kwon
The first
kmem_cachecreated at booting up is supposed neither mergeable nor destroyable but was possible to destroy. So prevent it.Signed-off-by Kyunghwan Kwon <[email protected]>--- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slab_common.c +0
-0
mm/slab_common.c void kmem_cache_destroy(struct kmem_cache *s) · line 748
Quoted 6 lines
mm/slab_common.c +1
-1@@ -744,7 +744,7 @@ void kmem_cache_destroy(struct kmem_cache *s)bool need_rcu_barrier = false;int err; -if (unlikely (!s)) +if (unlikely (!s) || s->refcount ==-1 )return ;
Hello, Kyunghwan.
Few lines below, s->refcount is checked.
if (s->refcount)
goto unlock;
Am I missing something?
Thanks.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 26 lines · Joonsoo Kim
Quoted 13 lines · Kyunghwan Kwon
The first
kmem_cachecreated at booting up is supposed neither mergeable nor destroyable but was possible to destroy. So prevent it.Signed-off-by Kyunghwan Kwon <[email protected]>---
mm/slab_common.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)mm/slab_common.c +0
-0mm/slab_common.c void kmem_cache_destroy(struct kmem_cache *s) · line 748
Quoted 6 lines
mm/slab_common.c +1
-1@@ -744,7 +744,7 @@ void kmem_cache_destroy(struct kmem_cache *s)bool need_rcu_barrier = false;int err; -if (unlikely (!s)) +if (unlikely (!s) || s->refcount ==-1 )return ;Hello, Kyunghwan.
Quoted 8 lines
Few lines below,
s->refcountis checked.if (
s->refcount)goto unlock;Am I missing something?
Thanks.
Hello, Joonsoo.
In case it is called the number of int size times. refcount would finally reach to 0 since decreased every time the function called.
When refcount is -1, the count will not change in the patch so no lock would be need to be taken prior, I believe.
Thanks.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
David Rientjes
reviewerQuoted 19 lines · kwon
Quoted 19 lines
mm/slab_common.c void kmem_cache_destroy(struct kmem_cache *s) · line 748
Quoted 11 lines
mm/slab_common.c +1
-1@@ -744,7 +744,7 @@ void kmem_cache_destroy(struct kmem_cache *s)bool need_rcu_barrier = false;int err; -if (unlikely (!s)) +if (unlikely (!s) || s->refcount ==-1 )return ;Hello, Kyunghwan.
Few lines below,
s->refcountis checked.if (
s->refcount)goto unlock;
Quoted 9 lines
Quoted 3 lines
Am I missing something?
Thanks.
Hello, Joonsoo.
In case it is called the number of int size times. refcount would finally reach to 0 since decreased every time the function called.
The only thing using create_boot_cache() should be the slab implementation itself, so I don't think we need to protect ourselves from doing something like kmem_cache_destroy(kmem_cache) or kmem_cache_destroy(kmem_cache_node) even a single time.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 30 lines · David Rientjes
Quoted 25 lines · kwon
Quoted 14 lines
mm/slab_common.c void kmem_cache_destroy(struct kmem_cache *s) · line 748
Quoted 11 lines
mm/slab_common.c +1
-1@@ -744,7 +744,7 @@ void kmem_cache_destroy(struct kmem_cache *s)bool need_rcu_barrier = false;int err; -if (unlikely (!s)) +if (unlikely (!s) || s->refcount ==-1 )return ;Hello, Kyunghwan.
Quoted 8 lines
Few lines below,
s->refcountis checked.if (
s->refcount)goto unlock;Am I missing something?
Thanks.
Hello, Joonsoo.
Quoted 8 lines
Quoted 3 lines
In case it is called the number of int size times. refcount would finally reach to 0 since decreased every time the function called.
The only thing using
create_boot_cache()should be the slab implementation itself, so I don't think we need to protect ourselves from doing something likekmem_cache_destroy(kmem_cache)orkmem_cache_destroy(kmem_cache_node)even a single time.
Agreed. I was aware of that though, I thought it would make its logic firm not giving performance disadvantages. Sorry for distraction.