Re: [PATCH 9/9] mm: kmemleak: fix undetected leaks for page aligned objects

Christoph Lameter
2023-01-26T11:21:19Z

On Mon, 23 Jan 2023, George Prekas wrote:

> If kmalloc returns a page aligned object, then the object has 2
> references: the pointer returned by kmalloc and page->s_mem of the first
> page of the object. Account for this extra reference, so that kmemleak
> can correctly detect leaks for page aligned objects.

s_mem is a reference to the array of slab objects in a SLAB page. It is
not referring to a particular object. s_mem allows access to the Nth
object in a slab page.

See the function index_to_obj() in slab.c

static inline void *index_to_obj(struct kmem_cache *cache,
const struct slab *slab, unsigned int idx)
{

return slab->s_mem + cache->size * idx;
}