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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAD60ECAAD1 for ; Thu, 1 Sep 2022 01:07:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231941AbiIABH6 (ORCPT ); Wed, 31 Aug 2022 21:07:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiIABH5 (ORCPT ); Wed, 31 Aug 2022 21:07:57 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F2E5D86C8 for ; Wed, 31 Aug 2022 18:07:55 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id 130so6582652ybw.8 for ; Wed, 31 Aug 2022 18:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=MRPzoJhQ6jRX3IlC8DX7IgvLpQbZlMnsgnvZKuuei8w=; b=FN6oNUdWK/epLWx1TsL9yA3judc8GEWbPUlFBZx3N+obm1zvmXwKLTgA0C+din1hae QL+aeoxudtTxFElhfOjbFrb5XsjBAilaB08Ldofl1XN7K/KLlXYDWHTq4s13vSXmuj5f DKOIAo7JDYtLr+88kw7IWfUfQEtwzvbREYO0F51ITJHJcS5BlsMkaJFVMWN04WfbWge0 QaMLxE28PQcRoEcCdCRT5hYYcc5qJq1t6S50Lj3dBP+TXgyTlXN6pUj2nAiR7uqNJFnz LBjn/+WoYkZm8EFAaPai3sk01dRp3NFnU9eS/Pc/JsqSX+SuHO7G2QXvivbbuPpvEXP7 8nRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=MRPzoJhQ6jRX3IlC8DX7IgvLpQbZlMnsgnvZKuuei8w=; b=ene5E3QzvjhPfLNSClME3HxqsE2T50nuF6SDHGe0jcWGKVnbshpq1ZFcA+s/caY4nz /iRbVTF0c6sYiXoMcW4DobI5UjhR/F06igxgRfTdUV0MSJt6yCFuhjiFn0/AfwkmRSFR mUinCoZkGkLUdwPv6IYnAPuRAfot6Aunp7r7on+mm2srqux9BDDNiNPPO82Y8r/mQ31U FQHk3GvIgPHjhGBhJbsmaUrJIO/fQK7v5Ns8xtVRlOsdmJjn/8jVGnE6xRlSVTnRTGMp XRRWoeKibbXuZNyeWZy2QuzEbsXe3iwgMzIA52hDUaXWw7U/8/cBljOA5GpmBqxDQXDN GXKQ== X-Gm-Message-State: ACgBeo3snJRjJlPpwC5X2JTjU4zbK/RLNIYR6KBMq8NAttwoMEpxmDgK ORg+LLS6ptx34aqBGLrnuORhD/ZhqwPeZ31wVqtFmQ== X-Google-Smtp-Source: AA6agR7ANRZu1y3V5ec1pN1knn4GFpXcEWezad8yEa+jyRtwuxFDik/95LNfhWenWi2n9p8vw7Ebn9CJDR6Mcs4MSyE= X-Received: by 2002:a05:6902:4c7:b0:69a:9e36:debe with SMTP id v7-20020a05690204c700b0069a9e36debemr14531815ybs.543.1661994474639; Wed, 31 Aug 2022 18:07:54 -0700 (PDT) MIME-Version: 1.0 References: <20220830214919.53220-1-surenb@google.com> <20220830214919.53220-11-surenb@google.com> <20220831101103.fj5hjgy3dbb44fit@suse.de> <20220831174629.zpa2pu6hpxmytqya@moria.home.lan> In-Reply-To: <20220831174629.zpa2pu6hpxmytqya@moria.home.lan> From: Suren Baghdasaryan Date: Wed, 31 Aug 2022 18:07:43 -0700 Message-ID: Subject: Re: [RFC PATCH 10/30] mm: enable page allocation tagging for __get_free_pages and alloc_pages To: Kent Overstreet Cc: Mel Gorman , Andrew Morton , Michal Hocko , Vlastimil Babka , Johannes Weiner , Roman Gushchin , Davidlohr Bueso , Matthew Wilcox , "Liam R. Howlett" , David Vernet , Peter Zijlstra , Juri Lelli , Laurent Dufour , Peter Xu , David Hildenbrand , Jens Axboe , mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, changbin.du@intel.com, ytcoode@gmail.com, Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Benjamin Segall , Daniel Bristot de Oliveira , Valentin Schneider , Christopher Lameter , Pekka Enberg , Joonsoo Kim , 42.hyeyoo@gmail.com, Alexander Potapenko , Marco Elver , dvyukov@google.com, Shakeel Butt , Muchun Song , arnd@arndb.de, jbaron@akamai.com, David Rientjes , Minchan Kim , Kalesh Singh , kernel-team , linux-mm , 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, LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bcache@vger.kernel.org On Wed, Aug 31, 2022 at 10:46 AM Kent Overstreet wrote: > > 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. Ah, right. __FILE__, __LINE__ and others we use to record the call location would point to include/linux/gfp.h instead of the location allocation is performed at. > > 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. > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >