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 05135C48297 for ; Fri, 9 Feb 2024 11:17:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A8426B0083; Fri, 9 Feb 2024 06:17:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 530116B0087; Fri, 9 Feb 2024 06:17:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D1766B0089; Fri, 9 Feb 2024 06:17:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 257646B0083 for ; Fri, 9 Feb 2024 06:17:55 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C975BA271C for ; Fri, 9 Feb 2024 11:17:54 +0000 (UTC) X-FDA: 81772015668.02.22F476A Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf11.hostedemail.com (Postfix) with ESMTP id B8A1140011 for ; Fri, 9 Feb 2024 11:17:52 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of robin.murphy@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=robin.murphy@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707477473; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XaTw8xL8WNl2WdM/1to8cDMSu3LfQv74hmXKJsuSGzE=; b=UEY2sU9SJBd5LDITsU6i3Wt+fTvVXPc2XgRk+Lmkwvq7omlGwfbvWh9Lw6Ax629eWq+VaG UJGFs6XRD4ykqbHQTwJY+G0K0Mxd7vQJRyyioXVegYgb6i/ohfiKMO+z+5bSm/bKkNSfN0 IQgy8zq2e82mmwEqk7Gx+UD9EMfyA10= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707477473; a=rsa-sha256; cv=none; b=b5xQcpmJtX6A+Bn/1pKNObpuuWbAY5BGJ0TFf/o8yxhZPQyTHedLMBo/9q0qguoCyxlGnt ABSoiySwAGhcYpHisBW46e9RTOtPF7fa1I8+2pPwZukvRuuKCYNSg1LKVYuDNj/egIRrBf hkt1jCABF/utDK3THnv3zCn06Z3aADI= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of robin.murphy@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=robin.murphy@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BF7CFDA7; Fri, 9 Feb 2024 03:18:33 -0800 (PST) Received: from [10.57.47.119] (unknown [10.57.47.119]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7511A3F762; Fri, 9 Feb 2024 03:17:45 -0800 (PST) Message-ID: <14e55a48-4439-47c7-a74f-126eaa998968@arm.com> Date: Fri, 9 Feb 2024 11:17:44 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 09/10] iommu: observability of the IOMMU allocations Content-Language: en-GB To: Pasha Tatashin , akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, paulmck@kernel.org, rdunlap@infradead.org, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> <20240207174102.1486130-10-pasha.tatashin@soleen.com> From: Robin Murphy In-Reply-To: <20240207174102.1486130-10-pasha.tatashin@soleen.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Stat-Signature: ieezm3pgzsizn4k7qnwopdfzmd1jxriz X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B8A1140011 X-Rspam-User: X-HE-Tag: 1707477472-156932 X-HE-Meta: U2FsdGVkX199lmSzlm9RCbe4jUwwQr1XoXDeN0B3cRgTA1jTiJUOahmO+Trda9/wTl+7HmQvJZoFe78BCrNyxZWRvHvR8U5ggL+W0qCcfSH1f4eAGxZ4v22MhnOHWsUiX4dLBh/JGuSXQCsJiDT0SswQdcH9EGFqBO6QldKI98xiKC5iRSTFsV6XpMCeKYkEf0hQD8wzvE3Dmyh8FIoxF5sAFGa6HBTWnLuAajeGDbiihV7yMy/nl6+46wfMktbB9FTVV+dqx3LAT6r0tIWWG8C6mHCaYq5Vc2iV/a46QiLw6EA//qOAW/1+U1AiHjvo+sQu7Q8WUYNwmON3TJdcddlXlzM9BjU6f6juHj7jwSpiNryxMF1BOE1RmqLT3r6DPC8+8PKkf2xM7sOXDcR/FCyjQ6DGKzs0kg7pR4et8vBvoMcTH80B9pcC32pBfC9JV6jZH0nucxXfbSWg9m1MsZWqWl5m37v8X3G/ZFkKD7iGYjRroJA3E/yhPW5IStHgPQGTFLP8DVs6bQvHWiOr9SPFmcukheEHtuim9j/LxKItzYbPJbc9JHExpZunT5J3Ofk92RCZKfJ7bq5ka/QqXr+XZSVHvANYfmfiopXbTCNXcaGMhYK+7tzoaGaTjO4NS6qO8jHZT2wAviC8WzgbWeoTa6+3NaWspTHebZ57gCkErIKLy8JxtwGPg0Inc43nH9L8Tbp72AnOZm9ouvAsnfNhxJ/XbaEvEfQIE/fJW5U574w+/p+Txzr+GbnCOtYb5oFT88O+lDPP5+AmwFNLMXwktsM6ipaGJe2w0zoZPcwzpzDbgbzrAGMumyIrVRBKNr1T80gzpI6ZGM095iJgYgYtB+4FSYcMPUvhe1cJhvGEUQbAv5mMobbA+GrUgHdrMsroEq3GprslZ/plhoN2tKtPEyWno4IBvTowNpFP5MgN1eT/g4Gvv1HrnPqDQedeiKMTuJZp7+Ed7BAPmGX ROpRiowZ N7W1ITNqCT7R/ephTNyusA07RE5xHuVom4VtrVLOTh775I41ym1f92n+RgBPR3Nt/i96cLoba4V4+pXyJx0zbzrRvfpg1yZmMfJdNlNYsH1BHMuq5JUPg4mkB82zubQf3INHej/KoQd2lCAQvaFxjjrQAgU/eRoJ1L9N2qzkx/8U+s0tqfq/7Mp0fMnyl2tCguijuGK7vnyDa642q/rWGxEbEVdftvCwE9ap7QwwLUGI3lCbtrRQi2U1uzda77Gc8Pk9K56xbqUdLqJpmg9+PwQeAOwiQRM+kg9Dno+5ZvcmEQNTznxtuXh9dwQnrbQO1skghGrv0u8u/rYo= 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: List-Subscribe: List-Unsubscribe: On 2024-02-07 5:41 pm, Pasha Tatashin wrote: > Add NR_IOMMU_PAGES into node_stat_item that counts number of pages > that are allocated by the IOMMU subsystem. > > The allocations can be view per-node via: > /sys/devices/system/node/nodeN/vmstat. > > For example: > > $ grep iommu /sys/devices/system/node/node*/vmstat > /sys/devices/system/node/node0/vmstat:nr_iommu_pages 106025 > /sys/devices/system/node/node1/vmstat:nr_iommu_pages 3464 > > The value is in page-count, therefore, in the above example > the iommu allocations amount to ~428M. > > Signed-off-by: Pasha Tatashin > Acked-by: David Rientjes > Tested-by: Bagas Sanjaya > --- > drivers/iommu/iommu-pages.h | 30 ++++++++++++++++++++++++++++++ > include/linux/mmzone.h | 3 +++ > mm/vmstat.c | 3 +++ > 3 files changed, 36 insertions(+) > > diff --git a/drivers/iommu/iommu-pages.h b/drivers/iommu/iommu-pages.h > index c412d0aaa399..7336f976b641 100644 > --- a/drivers/iommu/iommu-pages.h > +++ b/drivers/iommu/iommu-pages.h > @@ -17,6 +17,30 @@ > * state can be rather large, i.e. multiple gigabytes in size. > */ > > +/** > + * __iommu_alloc_account - account for newly allocated page. > + * @page: head struct page of the page. > + * @order: order of the page > + */ > +static inline void __iommu_alloc_account(struct page *page, int order) > +{ > + const long pgcnt = 1l << order; > + > + mod_node_page_state(page_pgdat(page), NR_IOMMU_PAGES, pgcnt); > +} > + > +/** > + * __iommu_free_account - account a page that is about to be freed. > + * @page: head struct page of the page. > + * @order: order of the page > + */ > +static inline void __iommu_free_account(struct page *page, int order) > +{ > + const long pgcnt = 1l << order; > + > + mod_node_page_state(page_pgdat(page), NR_IOMMU_PAGES, -pgcnt); > +} > + > /** > * __iommu_alloc_pages_node - allocate a zeroed page of a given order from > * specific NUMA node. > @@ -35,6 +59,8 @@ static inline struct page *__iommu_alloc_pages_node(int nid, gfp_t gfp, > if (unlikely(!page)) > return NULL; > > + __iommu_alloc_account(page, order); > + > return page; > } > > @@ -53,6 +79,8 @@ static inline struct page *__iommu_alloc_pages(gfp_t gfp, int order) > if (unlikely(!page)) > return NULL; > > + __iommu_alloc_account(page, order); > + > return page; > } > > @@ -89,6 +117,7 @@ static inline void __iommu_free_pages(struct page *page, int order) > if (!page) > return; > > + __iommu_free_account(page, order); > __free_pages(page, order); > } > > @@ -197,6 +226,7 @@ static inline void iommu_free_pages_list(struct list_head *page) > struct page *p = list_entry(page->prev, struct page, lru); > > list_del(&p->lru); > + __iommu_free_account(p, 0); I'm keen to revive my patches to hook up freelist support in io-pgtable-arm, which would then mean a chance of higher-order GFP_COMP allocations coming back though this path - do you have any pointers for what I'd have to do here to make it work properly? Thanks, Robin. > put_page(p); > } > } > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index a497f189d988..bb6bc504915a 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -203,6 +203,9 @@ enum node_stat_item { > #endif > NR_PAGETABLE, /* used for pagetables */ > NR_SECONDARY_PAGETABLE, /* secondary pagetables, e.g. KVM pagetables */ > +#ifdef CONFIG_IOMMU_SUPPORT > + NR_IOMMU_PAGES, /* # of pages allocated by IOMMU */ > +#endif > #ifdef CONFIG_SWAP > NR_SWAPCACHE, > #endif > diff --git a/mm/vmstat.c b/mm/vmstat.c > index db79935e4a54..8507c497218b 100644 > --- a/mm/vmstat.c > +++ b/mm/vmstat.c > @@ -1242,6 +1242,9 @@ const char * const vmstat_text[] = { > #endif > "nr_page_table_pages", > "nr_sec_page_table_pages", > +#ifdef CONFIG_IOMMU_SUPPORT > + "nr_iommu_pages", > +#endif > #ifdef CONFIG_SWAP > "nr_swapcached", > #endif