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 1921DECAAD5 for ; Thu, 1 Sep 2022 01:08:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232154AbiIABH6 (ORCPT ); Wed, 31 Aug 2022 21:07:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231743AbiIABH5 (ORCPT ); Wed, 31 Aug 2022 21:07:57 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94066EEF1E for ; Wed, 31 Aug 2022 18:07:55 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id y197so6591507yby.13 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=ie/SAlfQ2J1eWYPKNbmeLeN4CkAt27cHBOry0fogAC3ucevLOQCYIx2i//zwdSlEAt 4Poc+oRum7erPSJwPBF0Xzp9oxQzI30lBvb9Smy1B1b2Q0sXmtP9c/uh8T1Kpv9GeQLF WsIAUyGf/eW8tGru33bokehtqASsWeJs8kEZYQvdoHnU+JTyZPqK6KlgY4uJmffWFajN qUAvHovHOo1vaUH7xSP5Fr7hRuD51s1S6m9eLMaSziw3LTOyPJx6/QBONtEX5WlEBpfj yo+dkf/KtWC4+w9kt+3N3HozeW7rhzbdt5IAB8Y60tcgmy9XBY8QlExlxcSdbIYvnzrG fgog== X-Gm-Message-State: ACgBeo1UZVTSj2fw7euJmtDA9j9HJt/Rn/tzbhzBcbrQIWvjuRx3MPH4 GWXv1PgiaMJlmS6YV10HeB1+ZmjbW5VyBn9xoEXgww== 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: io-uring@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. >