Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp648447rwe; Wed, 31 Aug 2022 08:40:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR7yWcagU4DvRs4g/RjC7YHhOiwBFocZ21OPSasfvYUeIIzT9pzXB26M+S+INa3B7mSuu7CR X-Received: by 2002:a17:906:8462:b0:741:6003:71e4 with SMTP id hx2-20020a170906846200b00741600371e4mr12977926ejc.170.1661960415757; Wed, 31 Aug 2022 08:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661960415; cv=none; d=google.com; s=arc-20160816; b=S1qzocxE1Y4JQxYVwLDGaPS9KfcJpUNq/zumDTQ8Gn7Ys67xwDq580CYPqDv49RM06 eOKCQd37zbQN+0ZuF8A5XFm8aI6rzPV64ByM8iLeP9QW2MuffZU305+PiH+sz+Qe+vz0 P71ejAvlbmL6EZydQpL8pkcRaYSYkVQ3uESYrV4VU7fQYgsF7kc2HAxYhYa3D8UnT6X3 qOEPiqB/9bxZi8A2tUsG1F6GbVHObqeIEgZ70laYl/O+Npu8r2drUncMVp+37iibzggp 2lo4DdVwOa7dfT6xM0IzeNDG/VvRTiqu6o2T5xOoZ30RzT5ZrpAnfkWjg+vE+QVm+/R0 D0jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Gf8tbj4RpGeuppvSON/HSM0Glqk0yYviXDuhJFMb/GU=; b=hIRujIvsCoKFkmFBgG+iSXvss5Np6Yr4VHPVWG2IpZCDiJoxOZfJj4R2EUdID2E6Ob sMWej63lje/GiNpWwnRumMFV22kYTOt3bK8OHwneMvJFic7Mkfi4ir1ZQdLEQzyIu67l rTl8kvdySQjGQHP1T7FtKkeBAsUlMgx7peFc1KHimBFBvmEwT5dYWF4CqDusSZzOnv+B 4uVCSIwKWCPsidJwtS6vUeEUc4CrSmvYIQHaKHgGW/Mpyd1lMaStXacqeCcZ0dY4l4Nn J+WsQV+X0kb0DOhEyyi1GTS0SZzNdxeA84+NKnd0LUA/5s2TD7aqhW7AbfQsEFeIC3AO hD8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cQxyBMvv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs38-20020a1709072d2600b0073136f95cccsi12780517ejc.582.2022.08.31.08.39.42; Wed, 31 Aug 2022 08:40:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cQxyBMvv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229692AbiHaOw1 (ORCPT + 99 others); Wed, 31 Aug 2022 10:52:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiHaOwZ (ORCPT ); Wed, 31 Aug 2022 10:52:25 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C616CC325 for ; Wed, 31 Aug 2022 07:52:24 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id y127so14668417pfy.5 for ; Wed, 31 Aug 2022 07:52:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=Gf8tbj4RpGeuppvSON/HSM0Glqk0yYviXDuhJFMb/GU=; b=cQxyBMvvozNYynus3zxZ3j6RzXSBCpn5FoAJ+nxKz3VHiS1lPZzxADwXlYRuG0lI3B iubXtay3v5e612hUHNMRi9pO3BoM7+V6nua4ccIirdwdAWV5GDmbXNB3aaP0GSgTpuWP nHW/4r7u39B3y081Hzdd0igqeAx9v0A/y+Tn0jf9CDsHJTsjTTvOjhaKnfYTW5kkLBrn KNgAj1LflkiZ/CvLjcjVtD6gnblQiNy2KksOanc3Da332hYVeyFKkr7EDZqsgSRqLj4T /auCOgZbeBvfyH8YPAadjtSdky6NohdNqcDfIs6cFywfY1K96K97eYQ7qGIxabWIC7/8 VmNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=Gf8tbj4RpGeuppvSON/HSM0Glqk0yYviXDuhJFMb/GU=; b=XKduJq2LcyXfak4c9mTFRIii7O52EntkErP+Pr9CFP75DEHc4op6aGfXvDGdHOJYsq uOrb2D74D0l33L6EEwgSKcHwcCPgR+Y82OQmcI+yb1UObIyncItfHYgkpAwuSnza2loH 50UkcY0U/G5oKb1ezdxx6eJ4nKiIt39ZjKDEN2FkC8mh1FwisqdA04Rt6d3boS0k/+c+ I25r7Veir2K9/WZmlzaIhegSxOn4CAxK4tCQcakSkjfDZh3drR4U0XmS6B3HmkfW4tr8 3ZfdsMZILyD0YQCOaExSXLZQ99F+rWB5bUwEf42gsS1FdHLVonjK+2Chr3cqGMqUyBjT cqGQ== X-Gm-Message-State: ACgBeo2cFc7YpCrUvh7iA9IGORrQWHy2em0zVdgrly+4KL+QUMehPVWV lUPYQIuyxVycPn457Uvpo5Q= X-Received: by 2002:a65:408b:0:b0:42a:55fb:60b0 with SMTP id t11-20020a65408b000000b0042a55fb60b0mr22418817pgp.431.1661957543649; Wed, 31 Aug 2022 07:52:23 -0700 (PDT) Received: from hyeyoo ([114.29.91.56]) by smtp.gmail.com with ESMTPSA id i63-20020a626d42000000b00537b8aa0a46sm11571093pfc.96.2022.08.31.07.52.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 07:52:22 -0700 (PDT) Date: Wed, 31 Aug 2022 23:52:15 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Feng Tang Cc: Andrew Morton , Vlastimil Babka , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Dmitry Vyukov , Dave Hansen , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Robin Murphy , John Garry , Kefeng Wang Subject: Re: [PATCH v4 1/4] mm/slub: enable debugging memory wasting of kmalloc Message-ID: References: <20220829075618.69069-1-feng.tang@intel.com> <20220829075618.69069-2-feng.tang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220829075618.69069-2-feng.tang@intel.com> X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.) Thanks! > > @@ -3182,7 +3228,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, > * pointer. > */ > 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 *p; -- Thanks, Hyeonggon