lkml.org 
[lkml]   [2022]   [Sep]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4 1/4] mm/slub: enable debugging memory wasting of kmalloc
On Wed, Aug 31, 2022 at 10:52:15PM +0800, Hyeonggon Yoo wrote:
> On Mon, Aug 29, 2022 at 03:56:15PM +0800, Feng Tang wrote:
> > kmalloc's API family is critical for mm, with one nature that it will
> > round up the request size to a fixed one (mostly power of 2). Say
> > when user requests memory for '2^n + 1' bytes, actually 2^(n+1) bytes
> > could be allocated, so in worst case, there is around 50% memory
> > space waste.
> >
>
> [...]
>
> > static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
> > - unsigned long addr, struct kmem_cache_cpu *c)
> > + unsigned long addr, struct kmem_cache_cpu *c, unsigned int orig_size)
> > {
> > void *freelist;
> > struct slab *slab;
> > @@ -3115,6 +3158,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
> >
> > if (s->flags & SLAB_STORE_USER)
> > set_track(s, freelist, TRACK_ALLOC, addr);
> > + set_orig_size(s, freelist, orig_size);
> >
> > return freelist;
> > }
> > @@ -3140,6 +3184,8 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
> > */
> > if (s->flags & SLAB_STORE_USER)
> > set_track(s, freelist, TRACK_ALLOC, addr);
> > + set_orig_size(s, freelist, orig_size);
> > +
> > return freelist;
> > }
>
> Maybe we can move set_track() and set_orig_size() to after slab_post_alloc_hook().
> something like alloc/free hooks for debugging caches? (and drop orig_size parameter.)

Yep, we discussed this during v3 review
https://lore.kernel.org/lkml/442d2b9c-9f07-8954-b90e-b4a9f8b64303@intel.com/

Will revisit this considering recent refactoring and the following
kmalloc data redzone patches.

Thanks,
Feng

> Thanks!

\
 
 \ /
  Last update: 2022-09-01 07:06    [W:0.085 / U:0.088 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site