From patchwork Thu Nov 30 20:15:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13475022 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 8F0B9C07CA9 for ; Thu, 30 Nov 2023 20:15:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B7A56B04A3; Thu, 30 Nov 2023 15:15:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CAD66B04A5; Thu, 30 Nov 2023 15:15:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE69A6B04A6; Thu, 30 Nov 2023 15:15:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CAFC86B04A3 for ; Thu, 30 Nov 2023 15:15:19 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A653480282 for ; Thu, 30 Nov 2023 20:15:19 +0000 (UTC) X-FDA: 81515725158.17.E285F2A Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf16.hostedemail.com (Postfix) with ESMTP id DF279180029 for ; Thu, 30 Nov 2023 20:15:17 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=QVao737I; spf=pass (imf16.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.48 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701375317; 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=Nk58INbxx30xLOHUnMGn9OdPuZubp6H+G9gT2CVk01Q=; b=24j5kIdaAB+ToMbJOhRIiObRBGHGobMR2SoVKE5qm+QDCmMBucyeVTaKsgN7/xF8x7TPmD T4ZgRCehG3reg+mq6DJOwcRsA/ZFec1MWdwBzYYUY6e/u4pdgX6uO3jcTEFF4omIDZSZk5 i6vic/WnRgyj786MRgrTrpHbmJHiGkU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701375317; a=rsa-sha256; cv=none; b=NQOWgb/VrR3fMJjkOBSzKZXcH6nmP8f8CAgYbqXFcJ7aPMWhzKF1vU3Ot7t5VXEjOlJGs9 9XRGwqES4DSs3dY3YB0Drl51cFQozud/c2wjdhRvRbd7akCR7VcpIjFM9/0xdQrJo4VXqX iyBx71WlPJSIMoo9YbkFXnnhuQwW9LA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=QVao737I; spf=pass (imf16.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.48 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-67a35b68c34so7512116d6.3 for ; Thu, 30 Nov 2023 12:15:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375317; x=1701980117; 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=Nk58INbxx30xLOHUnMGn9OdPuZubp6H+G9gT2CVk01Q=; b=QVao737I5t123cE5y/4CMhjze2EqyIQ2jun2q0RTEKyi0guA1VHKTn6P/okVZrIzNh 6ExHXZccNMd0JX0+AfH9m3QWk7/m7QFp7P6ewPZK6/jJfeDXoolt52fiNgqtbH4Wt1FQ PFE0PSS3A/U6SVgDsjaQAgO42SPZOmgq5iI6HwKROljuvoqEdaUcgLPHuAACMScv9owe J0Tr0bL3F6cf1Wb5pxMB58kcBMhi9U1uKe2kUqrMYIWz21wfzMCZhnqZ9/t/aZ2CIzRZ 5DGQDuvQtpKKoTlLdN18Yjv7Z0WLwnrYND1k5yaHnSs41o4aSNvSBNJCbSSmn5xK7VUz QWCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375317; x=1701980117; 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=Nk58INbxx30xLOHUnMGn9OdPuZubp6H+G9gT2CVk01Q=; b=Xe6f3MR73x12YLSVJ+fS6gA/t5g/evZwJOdcW0otBDY2NIE7wquVUJhk8FB86gsVff 6ASaglfNujepnMuZXP/G1OcevXYds3J6luNtKQOUnzQztU52MSI9vKtDbFET88kXQNh6 5nQirx6XG2ziLk9abRtb9XygWxybIBblkosJVqctzHr2Zb550PNBQ+1s85JMcYtPBeV6 IFrEAKc6PGo5i/Yj/PMgOZvdSyyg+LBBxDALCI+fN+omocJG2E5qZstwy60gZP9j0VPE PZ3iCnrMIePreqaJsacQWbO9uGi/X0MwoMlJKi1/OCn9g2kUjqD4UxXo9AnKpcWzdlOo KBkg== X-Gm-Message-State: AOJu0Yy5eqvR0ELo4EFGzLblr4HY4NvUA4vhBeaAaxkny8cf+YktmpAs hV/mHKUQ3rq22OVB2niW9qlfAQ== X-Google-Smtp-Source: AGHT+IGvd2g71GGje9dR/iX9F2NrVDVxx6CHTrqO1K3GZh4lvqRPIVhnZdc8oub8jQLvnHQLKAhyCg== X-Received: by 2002:a05:6214:16d:b0:67a:2942:988 with SMTP id y13-20020a056214016d00b0067a29420988mr18670319qvs.21.1701375317117; Thu, 30 Nov 2023 12:15: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 e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:16 -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 Subject: [PATCH v2 10/10] iommu: account IOMMU allocated memory Date: Thu, 30 Nov 2023 20:15:04 +0000 Message-ID: <20231130201504.2322355-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Stat-Signature: ym4gbup5oxu1wch6qykb3hkoyr4fd8k1 X-Rspamd-Server: r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LCxXsK9isaIa3riKjY3ES98OPoeVaLcECiEYPTWfa3rknCLmoLZtGfv61TN+TBrn+uRtYucioXDpZbaysypTkq/SCjYNE3GPWqQ30itJwp94D66+wiee8xGS3XMN3KxDei6NX8aFFiIleb9N6CY46ezukrqcQuDxw0oFOF2YjPZHLrfr2l8BCX2Mi6+aOthdlzeUxInSfMOK4DkiraEEgeNItG8UHycWp2VrEM+FLhE/VXU+YsXHWDDUH9q1ShSaFyjEiq1kBnkK7hOpu92rYkxSV/gThG7we+Ywwl+QAwqDarFj61tyq79L8F300+yJNlvG7TGnPPEDgQCvGhXSc8QL5Lxk7THByMAXSX9ujWfoC3LCukjs4fvC+c/N4+Dbpsw0bd9Nz6Z5AAc6d+CJtz1ghVA== 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 69895a355c0c..cdd257585284 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 *pages, int order) const long pgcnt = 1l << order; mod_node_page_state(page_pgdat(pages), NR_IOMMU_PAGES, pgcnt); + mod_lruvec_page_state(pages, NR_SECONDARY_PAGETABLE, pgcnt); } /** @@ -39,6 +40,7 @@ static inline void __iommu_free_account(struct page *pages, int order) const long pgcnt = 1l << order; mod_node_page_state(page_pgdat(pages), NR_IOMMU_PAGES, -pgcnt); + mod_lruvec_page_state(pages, NR_SECONDARY_PAGETABLE, -pgcnt); } /** diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 1a4d0bba3e8b..aaabb385663c 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