Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp804727rwe; Wed, 31 Aug 2022 11:16:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR5zJX55uT38Va2PgCBoWx54aQ/DH7qEKFzGr5JsECvRvRntULu5VYapT4AFjPrq9V3eWXmQ X-Received: by 2002:a17:90b:1a88:b0:1fd:6a42:3eb9 with SMTP id ng8-20020a17090b1a8800b001fd6a423eb9mr4569400pjb.154.1661969797059; Wed, 31 Aug 2022 11:16:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661969797; cv=none; d=google.com; s=arc-20160816; b=qZJVPkglKdu9Wu8eD91ablj9daDQfMISzLPPWUv5EBX8XeX9KOV+OLcqMMaospp8Ii 32b3RJoWvbUyczOE8qIRbzuxkJ+j+Z+c4Bi2CFntTiDpx6ogl1QK37hVewuN740PuFEy ItkZcs1hfR/OFQwkHK+9RCJFzJWRXostXTBpcHnHQ/hIjFmMrKUJ6MxoErUKDoP/mwKo tpx9fw9FVnUzb9DCp4u9H95UTdsoChnL/AQRSgqQ/b+I16/GxZW4FhUHdQ+8lQoUlzkw 7uGW7Nm8LiXCd2XRRqla8iieQOPyVrwz/DBTAp4Uf5VTHaoe4yPvlBL0+7CXUpRwLgE/ KpiA== 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:dkim-signature:date; bh=cNGQu2INYppvwn/vrI+H9fLNjZAQ9LEc2ZMlyG9+b7I=; b=WzGPG6tS23k9tEzyzH5nX2o1HnaqMU6/jsC0Hx8t0Byegti++Yw5lysljZ20R/gL1K eJuUG2Qx6ClqJFno63Nsp64KCn9dSH84ZwvmLUvEhB6gkFYxCwe3FUAqXyxNSbScY2mY tvzcVM6TEk3/nSGs186vkllM4Ih1kePlx5Tb9RkWnjuFt/RgMwaMprsbPEQe+wsffP1b D5PF5fgcFMXjx586uTGwMh27G6olhXQWCZ4ScggPZXbcgKdoOslu44ulPXZurEMBgdD5 ANi1TlHbTGSvTIE2RixvL0zWjweexT10aNGQwFNU9+uxdH+OVftyjJtp+jp0jYJ5GOP3 BRDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=UvGgvRFF; 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=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x190-20020a6386c7000000b0041bc27c45b9si5431554pgd.811.2022.08.31.11.16.21; Wed, 31 Aug 2022 11:16:37 -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=@linux.dev header.s=key1 header.b=UvGgvRFF; 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=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229481AbiHaRqm (ORCPT + 99 others); Wed, 31 Aug 2022 13:46:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbiHaRqj (ORCPT ); Wed, 31 Aug 2022 13:46:39 -0400 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2643FB941B; Wed, 31 Aug 2022 10:46:38 -0700 (PDT) Date: Wed, 31 Aug 2022 13:46:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1661967996; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=cNGQu2INYppvwn/vrI+H9fLNjZAQ9LEc2ZMlyG9+b7I=; b=UvGgvRFFFCjI/MJ+R56HoYOSRVpisoRSFrlM+Tnr28bYpzjswOUst1RZvoLN2iOla1UOYk AhrqjPYHyPNC9OtSTSv8bCcogGpeWso0AVnHwUd3AWn+b9IVre9e619KvqRphXZ15fsktW AqO9MlFcMAgNkcSNSSA7HGEzQFUhYiE= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Mel Gorman Cc: Suren Baghdasaryan , akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, ldufour@linux.ibm.com, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, changbin.du@intel.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, arnd@arndb.de, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, kernel-team@android.com, linux-mm@kvack.org, iommu@lists.linux.dev, kasan-dev@googlegroups.com, io-uring@vger.kernel.org, linux-arch@vger.kernel.org, xen-devel@lists.xenproject.org, linux-bcache@vger.kernel.org, linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 10/30] mm: enable page allocation tagging for __get_free_pages and alloc_pages Message-ID: <20220831174629.zpa2pu6hpxmytqya@moria.home.lan> References: <20220830214919.53220-1-surenb@google.com> <20220830214919.53220-11-surenb@google.com> <20220831101103.fj5hjgy3dbb44fit@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220831101103.fj5hjgy3dbb44fit@suse.de> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 Wed, Aug 31, 2022 at 11:11:03AM +0100, Mel Gorman wrote: > On Tue, Aug 30, 2022 at 02:48:59PM -0700, Suren Baghdasaryan wrote: > > Redefine alloc_pages, __get_free_pages to record allocations done by > > these functions. Instrument deallocation hooks to record object freeing. > > > > Signed-off-by: Suren Baghdasaryan > > +#ifdef CONFIG_PAGE_ALLOC_TAGGING > > + > > #include > > #include > > > > @@ -25,4 +27,37 @@ static inline void pgalloc_tag_dec(struct page *page, unsigned int order) > > alloc_tag_sub(get_page_tag_ref(page), PAGE_SIZE << order); > > } > > > > +/* > > + * Redefinitions of the common page allocators/destructors > > + */ > > +#define pgtag_alloc_pages(gfp, order) \ > > +({ \ > > + struct page *_page = _alloc_pages((gfp), (order)); \ > > + \ > > + if (_page) \ > > + alloc_tag_add(get_page_tag_ref(_page), PAGE_SIZE << (order));\ > > + _page; \ > > +}) > > + > > Instead of renaming alloc_pages, why is the tagging not done in > __alloc_pages()? At least __alloc_pages_bulk() is also missed. The branch > can be guarded with IS_ENABLED. It can't be in a function, it has to be in a wrapper macro. alloc_tag_add() is a macro that defines a static struct in a special elf section. That struct holds the allocation counters, and putting it in a special elf section is how the code to list it in debugfs finds it. Look at the dynamic debug code for prior precedence for this trick in the kernel - that's how it makes pr_debug() calls dynamically controllable at runtime, from debugfs. We're taking that method and turning it into a proper library. Because all the counters are statically allocated, without even a pointer deref to get to them in the allocation path (one pointer deref to get to them in the deallocate path), that makes this _much, much_ cheaper than anything that could be done with tracing - cheap enough that I expect many users will want to enable it in production.