check for mem in slab
Hi list,
in file mm/slab.c and routine kmem_cache_init() I found there is no checking for allocated memory on line:
/* 4) Replace the bootstrap head arrays */
{
struct array_cache *ptr;
ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);--> no check for ptr == NULL <--
local_irq_disable(); BUG_ON(cpu_cache_get(&cache_cache) != &initarray_cache.cache); memcpy(ptr, cpu_cache_get(&cache_cache), sizeof(struct arraycache_init)); ...
is that OK? or it's a bug?
Cyrill
Quoted 10 lines
in file
mm/slab.cand routinekmem_cache_init()I found there is no checking for allocated memory on line:/* 4) Replace the bootstrap head arrays */ { struct array_cache *ptr; ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);--> no check for ptr == NULL <--
[...]
Quoted 1 line
is that OK? or it's a bug?
It's ok. If that allocation fails your machine won't come up anyway.
Quoted 7 lines · Heiko Carstens
Quoted 7 lines
in file
mm/slab.cand routinekmem_cache_init()I found there is no checking for allocated memory on line:/* 4) Replace the bootstrap head arrays */ { struct array_cache *ptr;
Quoted 7 lines
Quoted 3 lines
ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);--> no check for ptr == NULL <--
[...]
Quoted 1 line
is that OK? or it's a bug?
It's ok. If that allocation fails your machine won't come up anyway.
We ought to add a BUG_ON or comment at least there as this keeps popping up again and again.
[Pekka Enberg - Fri, Mar 30, 2007 at 02:55:26PM +0300]
| On 3/30/07, Heiko Carstens <[email protected]> wrote: | >> in file mm/slab.c and routine kmem_cache_init() I found there | >> is no checking for allocated memory on line: | >> | >> /* 4) Replace the bootstrap head arrays */ | >> { | >> struct array_cache *ptr; | >> | >> ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL); | >> | >> --> no check for ptr == NULL <-- | >[...] | >> is that OK? or it's a bug? | > | >It's ok. If that allocation fails your machine won't come up anyway. | | We ought to add a BUG_ON or comment at least there as this keeps | popping up again and again. |
Thanks for answer
Cyrill
PATCH 1/1 Catch kmalloc failure in kmem_cache_init() (was: [QUESTION] check for mem in slab)
In reply to Pekka EnbergHi,
Quoted 10 lines · Heiko Carstens
Quoted 9 lines
Quoted 9 lines
in file
mm/slab.cand routinekmem_cache_init()I found there is no checking for allocated memory on line:/* 4) Replace the bootstrap head arrays */ { struct array_cache *ptr; ptr = kmalloc(sizeof(struct arraycache_init), GFP_KERNEL);
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
--> no check for ptr == NULL <--
[...]
Quoted 1 line
is that OK? or it's a bug?
It's ok. If that allocation fails your machine won't come up anyway.
We ought to add a
BUG_ONor comment at least there as this keeps popping up again and again.
Done. Patch attached.
mm/slab.c +2 -0
@@ -1512,6 +1512,7 @@ void __init kmem_cache_init(void)struct array_cache *ptr; ptr =kmalloc (sizeof (struct arraycache_init ),GFP_KERNEL ); +BUG_ON (!ptr);local_irq_disable ();BUG_ON (cpu_cache_get (&cache_cache) != &initarray_cache.cache);
@@ -1526,6 +1527,7 @@ void __init kmem_cache_init(void)local_irq_enable (); ptr =kmalloc (sizeof (struct arraycache_init ),GFP_KERNEL ); +BUG_ON (!ptr);local_irq_disable (); BUG_ON(cpu_cache_get(malloc_sizes[INDEX_AC].cs_cachep)
PATCH 1/1 Catch kmalloc() failure in kmem_cache_init()
In reply to Cyrill GorcunovHi,
This patch makes kmem_cache_init() trigger a BUG when the calls to kmalloc() fail. Altough the kernel would not boot anyway on failure, this adds some clarity to the code.
mm/slab.c +2 -0
@@ -1512,6 +1512,7 @@ void __init kmem_cache_init(void)struct array_cache *ptr; ptr =kmalloc (sizeof (struct arraycache_init ),GFP_KERNEL ); +BUG_ON (!ptr);local_irq_disable ();BUG_ON (cpu_cache_get (&cache_cache) != &initarray_cache.cache);
@@ -1526,6 +1527,7 @@ void __init kmem_cache_init(void)local_irq_enable (); ptr =kmalloc (sizeof (struct arraycache_init ),GFP_KERNEL ); +BUG_ON (!ptr);local_irq_disable (); BUG_ON(cpu_cache_get(malloc_sizes[INDEX_AC].cs_cachep)
Re: [PATCH] Catch kmalloc() failure in kmem_cache_init()
Quoted 3 lines · Johannes Weiner
This patch makes
kmem_cache_init()trigger a BUG when the calls tokmalloc()fail. Altough the kernel would not boot anyway on failure, this adds some clarity to the code.
Indeed. This keeps popping up again and again, so