Received: by 2002:ac0:de83:0:0:0:0:0 with SMTP id b3csp745949imk; Sun, 3 Jul 2022 07:54:39 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sCZGUO+47chJU0DyZ40jC9kf8ifejbYr+pmcO9zBqJJquIEBKL5He4SMieHaCQlZcdhfno X-Received: by 2002:a05:6402:1cc8:b0:437:a61a:5713 with SMTP id ds8-20020a0564021cc800b00437a61a5713mr32643920edb.340.1656860079542; Sun, 03 Jul 2022 07:54:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656860079; cv=none; d=google.com; s=arc-20160816; b=dFHeZklY67bh58oTDdbplYRa8MPpJqVNnJM8eb0oe87P1AQfUs/3sd3RSOAkqaAyZh WS13vLgcbfr7hJvzAN14n4LrDT9KRpOZhiVke8J9FO3RMxqCHJ0QxsEaBju60qCVKsak NTfhU95tVlbQywVNpGp9586UrL+ul8xmbFpI0p9Jt3ZRxI2KyPwywOzG99xoPr7TzQ5C 38uIydhy5crJVOIfGNKIxOz1Zo5W7dNlK56fT7xHhIxZJWkrpwCeHV96n5yH4nUeGEpl 9TbvxinZcrNPfJUpfXqSdGqaahuugYhOUux7tJYSSk4al/ZqFZZzxkzx7oajY1fYyX47 Kepg== 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=AiyMYj7nYwpq/c8VwgRl9hvpQQsaNas9abyoIGc2aT4=; b=FGZb4483rArz6wjkr7Shd5dEuaOa7SpYcwR7horW5/lZAlXCdfWtJdGzJ/PxR5CO6j 8FI24nhXvp1LpN73wA5emE+KQnUVWzJCN6HmKv+NH6ymZSBODYkOr/+cSCPuxjfppIs/ ghBVPbnctMgMvMdIkUptxb8eol2yvQFr39mfmZ98nvE1zNmG4Fo+FBoA4wjMdZ9+1SXg W7h2AjRqnepJlQyepHvmg3uEnCrkP47oFmWfgB2+NWsfMr76KihHqMvVh+pB9pyJBGVT zaE3BMyDnKs27AsK0fEtUikFU7YIc4wcgHVL7HXbXu+gpXeOx96Az0G2829VEWBxMeVH z9NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AQs99Xvi; 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 k21-20020a17090646d500b00722e82edf14si32667296ejs.14.2022.07.03.07.54.14; Sun, 03 Jul 2022 07:54:39 -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=AQs99Xvi; 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 S232748AbiGCORt (ORCPT + 99 others); Sun, 3 Jul 2022 10:17:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231658AbiGCORo (ORCPT ); Sun, 3 Jul 2022 10:17:44 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7C4CCC1 for ; Sun, 3 Jul 2022 07:17:43 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id g7so1995525pfb.10 for ; Sun, 03 Jul 2022 07:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=AiyMYj7nYwpq/c8VwgRl9hvpQQsaNas9abyoIGc2aT4=; b=AQs99Xvix22RcsCaca5aUgkEFvzLyOaBefzzekPwS44rxFXIwUVysG0T9DFqxEZqOi /IgFyVoQGNdMjwLPmgx4lenwfGoUJDBH59G6sKBvpqOP5uts3ZnGpmcF9N0d7QnfOmou awXh0cItJzcMWESmTsirGnOLTFkF5dl50kCmA0ks4FYJ+OVV5sRCu7Hg6QNdAGow2spE 44e+R5fye/fRzlT1rHcZhxQZrvbByJfbxzkJ0TAOIWharek0FjhGHI/tXlxdajw+KapM JrlpahNvhvA1+DjRU9EOnKUlOi+qKU7acnekeeEd7BN3hXsKF2okyefdKPlJyAvReRW+ YL+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=AiyMYj7nYwpq/c8VwgRl9hvpQQsaNas9abyoIGc2aT4=; b=P0thsJE2GR2wB5C3zHf2QUHIugIHTFsJ1a73HNjcuStXYnhK9bUXmD0GVBCX3M1P/F 8Sm4PIsRJT7vlgIYQAEMfefGNDQAhzOM5nh0/+5EiQ97n9j/pd+quPrdlshnKuNJkvB/ xJf+O6n60Pio1+Ho1jmXYO6G5xuDNVzKmbZmgQDnxtxf79snM/MRhkOrICDbWyURZdwk EyKxd+Qk2REn534XWRlGkZIA972pEv7KX28GxryAIhn5hRflKHgCBa3Nsn8DqauNq1Qq VdTtR3VWek9WTzR+gVjTm92cTuT4e8AmnOLNpZNOJbDTKO2d4oNKNELaWigEtJBeliGS YAtw== X-Gm-Message-State: AJIora9sm76UehlvMppnHfoyo/nStxX63Wr35ePNzovkvGfKsiMuwaym 1+IsU9LQvs0lwcAL206kIfM= X-Received: by 2002:a63:6bc1:0:b0:40d:ffa7:9dc3 with SMTP id g184-20020a636bc1000000b0040dffa79dc3mr21365831pgc.111.1656857863297; Sun, 03 Jul 2022 07:17:43 -0700 (PDT) Received: from ip-172-31-24-42.ap-northeast-1.compute.internal (ec2-35-73-226-155.ap-northeast-1.compute.amazonaws.com. [35.73.226.155]) by smtp.gmail.com with ESMTPSA id x5-20020a1709029a4500b001678e9670d8sm19197078plv.2.2022.07.03.07.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Jul 2022 07:17:42 -0700 (PDT) Date: Sun, 3 Jul 2022 14:17:37 +0000 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Feng Tang Cc: Christoph Lameter , Andrew Morton , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, Robin Murphy , John Garry Subject: Re: [PATCH v1] mm/slub: enable debugging memory wasting of kmalloc Message-ID: References: <20220701135954.45045-1-feng.tang@intel.com> <20220701150451.GA62281@shbuild999.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220701150451.GA62281@shbuild999.sh.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 Fri, Jul 01, 2022 at 11:04:51PM +0800, Feng Tang wrote: > Hi Christoph, > > On Fri, Jul 01, 2022 at 04:37:00PM +0200, Christoph Lameter wrote: > > On Fri, 1 Jul 2022, Feng Tang wrote: > > > > > 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) > > > { > > > > It would be good to avoid expanding the basic slab handling functions for > > kmalloc. Can we restrict the mods to the kmalloc related functions? > > Yes, this is the part that concerned me. I tried but haven't figured > a way. > > I started implemting it several month ago, and stuck with several > kmalloc APIs in a hacky way like dump_stack() when there is a waste > over 1/4 of the object_size of the kmalloc_caches[][]. > > Then I found one central API which has all the needed info (object_size & > orig_size) that we can yell about the waste : > > static __always_inline void *slab_alloc_node(struct kmem_cache *s, struct list_lru *lru, > gfp_t gfpflags, int node, unsigned long addr, size_t orig_size) > > which I thought could be still hacky, as the existing 'alloc_traces' > can't be resued which already has the count/call-stack info. Current > solution leverage it at the cost of adding 'orig_size' parameters, but > I don't know how to pass the 'waste' info through as track/location is > in the lowest level. If adding cost of orig_size parameter for non-debugging case is concern, what about doing this in userspace script that makes use of kmalloc tracepoints? kmalloc: call_site=tty_buffer_alloc+0x43/0x90 ptr=00000000b78761e1 bytes_req=1056 bytes_alloc=2048 gfp_flags=GFP_ATOMIC|__GFP_NOWARN accounted=false calculating sum of (bytes_alloc - bytes_req) for each call_site may be an alternative solution. Thanks, Hyeonggon > Thanks, > Feng > > >