From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0BA9C43334 for ; Sun, 3 Jul 2022 14:17:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F21E6B0072; Sun, 3 Jul 2022 10:17:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 352806B0073; Sun, 3 Jul 2022 10:17:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F2A08E0001; Sun, 3 Jul 2022 10:17:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 088696B0072 for ; Sun, 3 Jul 2022 10:17:45 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id D59C9120974 for ; Sun, 3 Jul 2022 14:17:44 +0000 (UTC) X-FDA: 79645992048.09.081F156 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf05.hostedemail.com (Postfix) with ESMTP id 7AC8F10005E for ; Sun, 3 Jul 2022 14:17:44 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id w185so3069059pfb.4 for ; Sun, 03 Jul 2022 07:17:44 -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=5ty/3/caiXn5x+aD3+XdyHABfDQVUMQAmrNR23q0qpFqIZf0fGAaVht9letamoHPlz kGb0twlx6Vzi6nJKeGnjevYmsfeQeGYEfZXDrIOAapQZd/jB96mFNi5Z9MdW7Azm5uNe epLPKyA9eC54beC4UBHt9Qw+1jF0u0lWFMUpWqVDCftIBSOqgjn2ktLiZ2+kzbIm9Ap7 frX2mMINSW3sd4wK3uSEr3ag2MYo4YQYb+lSTusIgzvJdAO01koTcwTpKZJ3NyaAXtgL LIEJLKzD3cRRLXg1iDfB29YnzqLLxeQv7o0qmbi04KqgelBf96yWvASHja5sfrwlMjUL GO1g== X-Gm-Message-State: AJIora95wYHtGkoOe/u/XGMxARdLBtqTAs0npsoUADNmc2yavd1MtiG/ kOK0No1eo5/4wA9F6siFenE= X-Google-Smtp-Source: AGRyM1uYXWzyHPGKcFPOzsJMOBubqKzUQCmu9f2M5naimbwsMlpk4L8Ey2ZM/JM4dNYI1i2/9GIETA== 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> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656857864; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AiyMYj7nYwpq/c8VwgRl9hvpQQsaNas9abyoIGc2aT4=; b=eRzdnwE//YIXaHkhHD4Dor3SmoPUHYmRSGLrpArSYQRf/ehBqxBfCi/L01qQmNlR+0DdeJ fF1eUNcO6kJsI3fTfzgMvQAvUXVtXt9gyua21kFmYtHyWFkEeWk8eLfR9oJ1Sb8xE+Y1Ue KAPqYIgwvnRGGCszb/9lYmff9FxPeXk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656857864; a=rsa-sha256; cv=none; b=uFiB3AeSP8G0ImDMzXV4W3efnYcOs4wKz71tjDg2BhQFd0KAESSSTL3S3+jLdHcenU/fB1 xoeFZVMW1RqlU7uJdixqJMFjuWlwdRvgTK2U0JqEt158WJ4eYh8IYD9oQhVJRd/ccheQpf GOd4ayni2d1tgeKGsaA9JyF2LfPaAMQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AQs99Xvi; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AQs99Xvi; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com X-Rspamd-Server: rspam03 X-Rspam-User: X-Stat-Signature: pginrbd48wjwbqq5j86zdpnu9umu4rmj X-Rspamd-Queue-Id: 7AC8F10005E X-HE-Tag: 1656857864-307962 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 > > >