linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hyeonggon Yoo <42.hyeyoo@gmail.com>
To: Feng Tang <feng.tang@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	Christoph Lameter <cl@linux.com>,
	Pekka Enberg <penberg@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Dmitry Vyukov <dvyukov@google.com>,
	"Hansen, Dave" <dave.hansen@intel.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	John Garry <john.garry@huawei.com>,
	Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: Re: [PATCH v4 1/4] mm/slub: enable debugging memory wasting of kmalloc
Date: Thu, 1 Sep 2022 20:14:40 +0900	[thread overview]
Message-ID: <YxCUIM4BWVZD6fnk@hyeyoo> (raw)
In-Reply-To: <YxA9etTqGsaogfZ6@feng-clx>

On Thu, Sep 01, 2022 at 01:04:58PM +0800, Feng Tang wrote:
> 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/

Ah, I missed that :) Thanks!

Considering the added cost (should be low) and races with validation,
I think this approach will cost more than it get. Sorry for the noise.

p.s. I think I can review this series in few days.
Thanks for your efforts!

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

> Thanks,
> Feng
> 
> > Thanks!

-- 
Thanks,
Hyeonggon


  reply	other threads:[~2022-09-01 11:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-29  7:56 [PATCH v4 0/4] mm/slub: some debug enhancements for kmalloc objects Feng Tang
2022-08-29  7:56 ` [PATCH v4 1/4] mm/slub: enable debugging memory wasting of kmalloc Feng Tang
2022-08-31 14:52   ` Hyeonggon Yoo
2022-09-01  5:04     ` Feng Tang
2022-09-01 11:14       ` Hyeonggon Yoo [this message]
2022-09-01 14:01   ` Hyeonggon Yoo
2022-09-02  6:15     ` Feng Tang
2022-09-04  9:03       ` Hyeonggon Yoo
2022-09-04  9:42         ` Feng Tang
2022-09-04 10:58           ` Hyeonggon Yoo
2022-09-05  2:55             ` Feng Tang
2022-09-05  6:29               ` Vlastimil Babka
2022-09-05  7:06                 ` Feng Tang
2022-09-05  7:33                   ` Vlastimil Babka
2022-09-05  8:37                     ` Feng Tang
2022-09-06 13:39                       ` Hyeonggon Yoo
2022-08-29  7:56 ` [PATCH v4 2/4] mm/slub: only zero the requested size of buffer for kzalloc Feng Tang
2022-08-29  7:56 ` [PATCH v4 3/4] mm: kasan: Add free_meta size info in struct kasan_cache Feng Tang
2022-08-29  7:56 ` [PATCH v4 4/4] mm/slub: extend redzone check to cover extra allocated kmalloc space than requested Feng Tang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YxCUIM4BWVZD6fnk@hyeyoo \
    --to=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=dave.hansen@intel.com \
    --cc=dvyukov@google.com \
    --cc=feng.tang@intel.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=john.garry@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=robin.murphy@arm.com \
    --cc=roman.gushchin@linux.dev \
    --cc=vbabka@suse.cz \
    --cc=wangkefeng.wang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).