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 69B94ECAAD1 for ; Wed, 31 Aug 2022 17:46:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C91838D0001; Wed, 31 Aug 2022 13:46:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C40916B0072; Wed, 31 Aug 2022 13:46:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B079B8D0001; Wed, 31 Aug 2022 13:46:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9E8166B0071 for ; Wed, 31 Aug 2022 13:46:39 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6C340120108 for ; Wed, 31 Aug 2022 17:46:39 +0000 (UTC) X-FDA: 79860617718.13.03DE3FE Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf08.hostedemail.com (Postfix) with ESMTP id 9F2E9160058 for ; Wed, 31 Aug 2022 17:46:38 +0000 (UTC) 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661967999; a=rsa-sha256; cv=none; b=FEnktRaJYgEQGUFUrdElWbutXrTymtLC99paj+keJ01blEdmdwXUektA15+ldyFmOoGIV1 33Ab69LBW2jCxQgXeyRDgaukEI91g9sHDELQlMU/UYvJdPg7lFC/tEyTyfwGcCCNC1r4Q9 Ehmnyqg0Lv5CvNH81gC1UQUhfUlLYkE= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UvGgvRFF; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of kent.overstreet@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661967999; 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=cNGQu2INYppvwn/vrI+H9fLNjZAQ9LEc2ZMlyG9+b7I=; b=hGUdzPGMqoxLwMaGlNQvo85zPMYJZg9By0JtQ2OQMgCRxITYCs80KlY6PEKz3Ejyl4PPbI Di8VwvLliXMPXxPSkQXuU5evilqMIgUfARcP3pEzwFYjbANsGOOR6S2EksE/2Jh80yVbgj BvGldnv7KZVQ1FOCviUidsXMh+sE8tE= Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UvGgvRFF; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of kent.overstreet@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: m6hgbtfuwjaqs9usnpxrh7zg9hujgssa X-Rspamd-Queue-Id: 9F2E9160058 X-HE-Tag: 1661967998-513213 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 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.