From patchwork Tue Dec 26 20:02:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13505036 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 09BCCC46CD3 for ; Tue, 26 Dec 2023 20:02:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57BC06B0087; Tue, 26 Dec 2023 15:02:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 502C66B0088; Tue, 26 Dec 2023 15:02:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32DFC6B0089; Tue, 26 Dec 2023 15:02:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1B1456B0087 for ; Tue, 26 Dec 2023 15:02:20 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EA938A0684 for ; Tue, 26 Dec 2023 20:02:19 +0000 (UTC) X-FDA: 81610041198.10.44B6E90 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) by imf24.hostedemail.com (Postfix) with ESMTP id 258D118001F for ; Tue, 26 Dec 2023 20:02:17 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=gQRpXMdj; dmarc=none; spf=pass (imf24.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.43 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703620938; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BtxKf3FqZi0ydpudkf0bXoEdqlC2cPc9JiSI0VbRHzc=; b=Mj6vFoFDThg9Z9btc3yh5SIc88eQq0pp3owjob+VLEkn+pyE6Zrew9XS54n8gjXgs1Dd+F CFbj7brwgMpbtG59ZP836mAo3ZRE+gNr5P+hhdZrhC4JReawiKGsqxbwPm6C/WleGasyk/ 4cAsgHVt8/+zGo8sbD1Z+NrOhP4mdMo= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=gQRpXMdj; dmarc=none; spf=pass (imf24.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.43 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703620938; a=rsa-sha256; cv=none; b=QXBb8B3ybJ79QIcAyEsPBegvRh2aAgaFD/Jn5K1AoiKVmjsd2RG6pST/+5FOMSR6YUDOpL zUIjS+ynAXTgqyLNcefeBAS+O7zC/NYthtfnyfXyq4vYZEOWUKWuub2TnszrGaE203nYrQ 2XuHU8W5Xwf68cd4SzqPOWYNGZdmJdY= Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-67f6272e7c6so42218576d6.1 for ; Tue, 26 Dec 2023 12:02:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1703620937; x=1704225737; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=BtxKf3FqZi0ydpudkf0bXoEdqlC2cPc9JiSI0VbRHzc=; b=gQRpXMdjeO01uIFvbTsngROmXackuvSGSuM+ACRnHiUm5yF8LrTNShJkyNq3JVIv+2 wXcF8b9nPADk49YmCZeainS5IUZ6dFz4DtPFgCiOJ/Gw4laKIZ804tAV+qUOkb7DbAy/ WtY0zdfyDS1ZL/KZpSt/N3tD6hSoVf/YHFw04f6PV6Pl9ZtGxcmq1VDzY93w7YoG+E0/ S00VKYsUDC90VlgqtiysovM10kjVi0Xo8l2tkae7dxmg4oJYYIWK7X4GH5nfob1COH0l pWU4Getk+bPLDSNKCO/ihbgnuECEkHeARc2fiMQBUiawHOTs0nyehm2xvVgRf78uA0tE sK/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703620937; x=1704225737; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BtxKf3FqZi0ydpudkf0bXoEdqlC2cPc9JiSI0VbRHzc=; b=in4mAsBy6stBmxhDvXQjL6+Iu8AUr35PsLhfO/HaNp3BZuyGyYT0N8Jqy3h9rOh9GI D4H4swHgvFaBM2wRuqob7trxXsPR3HhjkrllB9LylmwpE+qazAIcKMhgcL8p3O1DqsRr XPrYb8VHTYo3g85k+G3T+SX/9zEqlL6hIYC/HipTmjObAxFxiEluOf3kVhNvHaRHNGZW aJ6uDkI5AMBMyLSpyw+NfFJPOMVBDrE93tSydX/5zcMAsT3QEvnfA0VOvPpsEJr3b3vj CxqAtVPxjccByVIK1jbUui+YU7e8NY/8TBeQIKlMYb8C81ZV1M+d9lBAu80xoP8FX4ni u0Xw== X-Gm-Message-State: AOJu0YygwC4AN6NWBmrZbVNgVjHN06hawcFlIAaRCwou+YzfbLCYvN+h aqHvg0KrDJzfWSkIDf01ULLLT1Tc+SFGOw== X-Google-Smtp-Source: AGHT+IF6SHRllSaxJq4UXQlu+eJlDbGhCpDAe3qqJtRfc6g3mN6rB4PyhEEN8AN1FQVjUmVdCTe1Ag== X-Received: by 2002:a0c:e90e:0:b0:67f:d69e:9c45 with SMTP id a14-20020a0ce90e000000b0067fd69e9c45mr6794763qvo.11.1703620937325; Tue, 26 Dec 2023 12:02:17 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id t5-20020a0cf985000000b0067f696f412esm4894539qvn.112.2023.12.26.12.02.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 12:02:17 -0800 (PST) From: Pasha Tatashin To: 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, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, 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 Subject: [PATCH v3 10/10] iommu: account IOMMU allocated memory Date: Tue, 26 Dec 2023 20:02:05 +0000 Message-ID: <20231226200205.562565-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231226200205.562565-1-pasha.tatashin@soleen.com> References: <20231226200205.562565-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-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8IYojndfB8n i9XQJE78 0I0FWa/b5TiFZpXsI2oe2Po3ffh+2sO/nVL2hVtyrv8VQextAxxRVoW86GHrE/yGcZReCtAT6ajt8TGeGjM5yD90BBq8zqYxI8Kp4LIhOR++UbDx40ZygZDWL2Z5sd+EmZu+hK/MkOGE3HdqOPgeXf9wsCMn8GoMj4CUFKrepxxF/hRPfOwV/A0vvBhRQGnO1YwVfibCXAcga6wqFysKZCkSljw/HhEgNupX8wTEURRE5bx1VV4iUXRcsIe226D06L+EwZSgozEzh47DGWen3bTAzT8mNUA/CQ2hnH2OG0UVH0DMxlfo+9gqY6kF8xqAuZrXDdmCcyV1ea29FuKQ8nhlKVjfDx7kRM/uE9QsxjbIn6FhbFTuTjMzLDFJeurkaleYefQIbcpL7Car5N/lf35JU44EHKW03TX4vGowrunWltJstCG1opVUOBEkFEUe8ZPBK 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: In order to be able to limit the amount of memory that is allocated by IOMMU subsystem, the memory must be accounted. Account IOMMU as part of the secondary pagetables as it was discussed at LPC. The value of SecPageTables now contains mmeory allocation by IOMMU and KVM. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes --- Documentation/admin-guide/cgroup-v2.rst | 2 +- Documentation/filesystems/proc.rst | 4 ++-- drivers/iommu/iommu-pages.h | 2 ++ include/linux/mmzone.h | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 3f85254f3cef..e004e05a7cde 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1418,7 +1418,7 @@ PAGE_SIZE multiple when read back. sec_pagetables Amount of memory allocated for secondary page tables, this currently includes KVM mmu allocations on x86 - and arm64. + and arm64 and IOMMU page tables. percpu (npn) Amount of memory used for storing per-cpu kernel diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 49ef12df631b..86f137a9b66b 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -1110,8 +1110,8 @@ KernelStack PageTables Memory consumed by userspace page tables SecPageTables - Memory consumed by secondary page tables, this currently - currently includes KVM mmu allocations on x86 and arm64. + Memory consumed by secondary page tables, this currently includes + KVM mmu and IOMMU allocations on x86 and arm64. NFS_Unstable Always zero. Previous counted pages which had been written to the server, but has not been committed to stable storage. diff --git a/drivers/iommu/iommu-pages.h b/drivers/iommu/iommu-pages.h index 4e70cdf7acac..b4289d577e2c 100644 --- a/drivers/iommu/iommu-pages.h +++ b/drivers/iommu/iommu-pages.h @@ -27,6 +27,7 @@ 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); + mod_lruvec_page_state(page, NR_SECONDARY_PAGETABLE, pgcnt); } /** @@ -39,6 +40,7 @@ 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); + mod_lruvec_page_state(page, NR_SECONDARY_PAGETABLE, -pgcnt); } /** diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index f0b54c752e22..da68f9977206 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -199,7 +199,7 @@ enum node_stat_item { NR_KERNEL_SCS_KB, /* measured in KiB */ #endif NR_PAGETABLE, /* used for pagetables */ - NR_SECONDARY_PAGETABLE, /* secondary pagetables, e.g. KVM pagetables */ + NR_SECONDARY_PAGETABLE, /* secondary pagetables, KVM & IOMMU */ #ifdef CONFIG_IOMMU_SUPPORT NR_IOMMU_PAGES, /* # of pages allocated by IOMMU */ #endif