Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp577453rdb; Thu, 30 Nov 2023 12:16:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHjZe/CfX8z3wPzjWqM7Aoe5x68m1YWIDQBWfrGvFyNylGyA0wVif/HOBw0q90JOSKplBU X-Received: by 2002:a17:902:76cc:b0:1cc:bf6b:f3b1 with SMTP id j12-20020a17090276cc00b001ccbf6bf3b1mr21774984plt.37.1701375377744; Thu, 30 Nov 2023 12:16:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701375377; cv=none; d=google.com; s=arc-20160816; b=nRVwFgYJx7b2SXj1Z19uqePF/6eTk5wkUYD8484308kvTf+JLsHJIyzfUvQpGfqi/+ LS6XuT5G8FNoJfZV7EeolkczkBHf4/BMvX178uUK6z/OmilaB3kplArqSK1lawnb2tj6 R5B956lFbnUH5JP3DU8eipPAYc1NbDxmkV0rJ2xZxesava+GczB3Z60pIK1k/PG6RRvB zjwfJE5HqSLdwNCu8eyumoWg7se4k8pgZye48j7zyVRiZ9Ujvx7hs5lwcv4LN5Vhn8rU oIQmiLJii5o5tzA5CPlcpX11Vx31uNceIFK+zVfTJPzLFHKh8jLFSlpaqfrX1WSmGiXk czwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Nk58INbxx30xLOHUnMGn9OdPuZubp6H+G9gT2CVk01Q=; fh=EWgL8IBvHPGC0Y7opUuF57pNES+TiFvURSlxmGDMOzg=; b=BGg585sq5bXub7UP4heEQxMF6dCttSd+0hZjBhzY0XzbUpEfphAVaZ/rzjFxFnr9m4 l/PDbqA03N5I5Ii622DKvud0sSHiSc4INc3H/yxyAuAvtnbMvmmrhMS3lhETKMPDRe+I bJAFjJ20kNTv/uWafoyWDSf5FHbgc/vOp1MKQ7G6QIqeqCuiO0XOP0jLJgLi79NPUeFE Ai+Rvom1zSqWHBm6f5cTX2wTV3eYUmtaBjiq0Shm0lCj4V8SIkdYyM8E6s2EMa33Qw5O 1wPaXdlWXMokjQav+uEYlXq2RO0rEw2CgGaBSDvk76nj1+Qi7/2uibkbIyM65eIaM2X5 zzVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=DG3KIdcP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id v11-20020a1709028d8b00b001d00ed1185bsi1794217plo.506.2023.11.30.12.16.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:16:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=DG3KIdcP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 19EFA8072A13; Thu, 30 Nov 2023 12:16:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376829AbjK3UPk (ORCPT + 99 others); Thu, 30 Nov 2023 15:15:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376678AbjK3UPM (ORCPT ); Thu, 30 Nov 2023 15:15:12 -0500 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 070C71708 for ; Thu, 30 Nov 2023 12:15:18 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-77d6b28aa9aso70182585a.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=vger.kernel.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=DG3KIdcPWSPhvrI24R2yPywnWd22F+iBx3WlRdOltvRY0Sii72Lc1kKHEDP6+GWAzC a1YyCvr851G96f6nsxNcxKrEv2IojfTTwq4F9oyqTuWkCMSCU4BXK0rJUeDjrR1Cmbgx Ftlrexb+4koXwddoNm8+26IdW25lYphdEMRwtYEOPE+EN/DZ0hR7fzyrXZG1oHrVQjpz 9U96cwYZuZZ6zW+Nfi20znE5cxiKfH0nimxd+1QGK/3Rt/QwiycSA/v94nME74OWxfsk lVV3xtnzoRur7J8d3eLocUUi6tciH5+UWjYGLQKbDe9ovY8/kDfRdhGH82VaDQq03vVN B9nw== 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=m5TeQ/VAJwefhM3IR0GvBrWd51/0WdUVCJRyFDcRiEqCtx2XayU7VXV5DjO6qBmETN g/Bl96yzwfbhTAALZPz6WsSyHWohnWiJc5Tj+NjNePZRdL54E0VXfuvjM3bjvt10bw58 9wpEPnuHINWfqbY3RUgKIakeaDK398cKNXUIaTJWLL5mQcqFuoxYiB/0digMwEPCfwZy s20RWFxyV+FZi2skkdqzEYfxQMC5iwcLVhcjpstd9ZDxcgiL2R+T6+p0gLzcj4ErNdR+ u2BldRBuW/s/5JLULm0KrcK+gZOlThrdZNAnisbNB5Qrzh2maWfhB8vbFtsrbuAIrgY0 RcQQ== X-Gm-Message-State: AOJu0YymhNDpNOsrUEo3ZqesTMPjcdrqIuZrLxfhvoODSUw/gKdmpYWJ vLfoP48plh5V81mpPfNaauWUDA== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 30 Nov 2023 12:16:13 -0800 (PST) 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 --- 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 -- 2.43.0.rc2.451.g8631bc7472-goog