public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Possible memory leak via slub kmem_cache_create
@ 2008-11-19 16:25 Catalin Marinas
  2008-11-19 19:22 ` Christoph Lameter
  0 siblings, 1 reply; 6+ messages in thread
From: Catalin Marinas @ 2008-11-19 16:25 UTC (permalink / raw)
  To: Christoph Lameter; +Cc: linux-kernel

Hi Cristoph,

I've recently worked on reviving kmemleak (to be posted on LKML this
week) and tried the slub allocator. I got the following report of orphan
objects:

unreferenced object 0xdf80f180 (size 32):                                       
  comm "swapper", pid 1, jiffies 4294937343                                     
  backtrace:                                                                    
    [<c0082f44>] memleak_alloc                                                  
    [<c0080ff0>] __kmalloc                                                      
    [<c019edac>] proto_register                                                 
    [<c001640c>] inet_init                                                      
    [<c001e30c>] do_one_initcall                                                
    [<c0008400>] kernel_init                                                    
    [<c0035aa8>] do_exit                                                        
    [<ffffffff>]                                                                
unreferenced object 0xdf800840 (size 16):                                       
  comm "swapper", pid 1, jiffies 4294937343                                     
  backtrace:                                                                    
    [<c0082f44>] memleak_alloc                                                  
    [<c0080ff0>] __kmalloc                                                      
    [<c019ee3c>] proto_register                                                 
    [<c001640c>] inet_init                                                      
    [<c001e30c>] do_one_initcall                                                
    [<c0008400>] kernel_init                                                    
    [<c0035aa8>] do_exit                                                        
    [<ffffffff>]                                                                

The proto_register() function in net/core/sock.c allocates
request_sock_slab_name and timewait_sock_slab_name to generate the cache
names passed to kmem_cache_create(). However, this function in mm/slub.c
goes on the find_mergeable() route and doesn't update s->name to the
previously allocated pointers. Therefore, kmemleak reports them as
orphan.

It could be worse since proto_unregister() tries to free these pointers
but they don't actually point to the allocated blocks because of the
merging.

A solution could be to pass one of the SLUB_NEVER_MERGE bits to
kmem_cache_create in proto_register(), though none of them has any
meaning for this situation. Otherwise, maybe defining another bit like
SLAB_ALLOCATED_NAME to ensure that kmem_cache_name() returns the same
value.

Or just simplify proto_register() to no longer allocate memory for these
names and it should be stated somewhere that kmem_cache_create() doesn't
necessarily saves the pointer to the name.

Thanks.

-- 
Catalin


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-11-20 18:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-19 16:25 Possible memory leak via slub kmem_cache_create Catalin Marinas
2008-11-19 19:22 ` Christoph Lameter
2008-11-20  9:51   ` Catalin Marinas
2008-11-20 11:04     ` Arnaldo Carvalho de Melo
2008-11-20 18:14     ` Christoph Lameter
2008-11-20 18:45     ` Pekka Enberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox