From patchwork Thu Feb 22 17:39:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13567708 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 78BCEC48BF8 for ; Thu, 22 Feb 2024 17:40:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0BBCD6B0098; Thu, 22 Feb 2024 12:39:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0935B6B0099; Thu, 22 Feb 2024 12:39:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD7206B009A; Thu, 22 Feb 2024 12:39:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C8DB66B0098 for ; Thu, 22 Feb 2024 12:39:58 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9AEA740EF8 for ; Thu, 22 Feb 2024 17:39:58 +0000 (UTC) X-FDA: 81820152876.25.5CA909F Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by imf20.hostedemail.com (Postfix) with ESMTP id CE2BA1C0017 for ; Thu, 22 Feb 2024 17:39:56 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=wXZUL2zG; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf20.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.128.173 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=1708623596; 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=SZ2pQJ9+dxF//EaiCt/uq+OdRpwnCyd+9hrUk8R734o=; b=a3wqCA8/q5RVUFehabMYFE97crUAaN2lQ/rLoZ0K8PjMIkPSL7Tjn2vhOaGMae8OZYpusI NLN3KUoMSj5ZHqJui2U7Nnt/W4sdf/LfY2dfZmNIBVT7fZqHv6zTJ3HCJi1pKplWuPmAea jtbuguHS2Hk9nK/nd7sM96OxDpKMyN4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=wXZUL2zG; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf20.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.128.173 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708623596; a=rsa-sha256; cv=none; b=soZSDMIlrksKBxVadwkjK7xu6w9lB+F87J+axe4yikzHrJJksciLGabCJJEHx+FvaEMggI SaeXyJXkZJudj57bodn0lRh9nzlVrP8D3TEr07R0n5M1GoKvG/FLZaz4bMcFfWuElmoEok FioKxg7x5KZIkkAE/70xk2+jJUlBLxk= Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-607c5679842so20926137b3.2 for ; Thu, 22 Feb 2024 09:39:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1708623596; x=1709228396; 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=SZ2pQJ9+dxF//EaiCt/uq+OdRpwnCyd+9hrUk8R734o=; b=wXZUL2zG9xn+FsCe/oxYRnTeMNlJHYVRHjQEzwOGvk79wlhBmk3tw0C/bEuNfQHgTr mXcEYhKaG7S2b9WsQGNEXiwJjawjeqA/sys2X29VsMG2LZ89csXTDb2kQaNpiHKSnlt/ qX/0r0BWGBPiZaqw/WP6fCaWUK7tdN6Gd1NoCzXMdNuwxmeJPUDhDGFmg2b5/y7wJvu6 P4DXR1VxfgsHG6hUOUOJuUYRt1Z5v6n1fhD4esyumB0Mrst0yww8dvxBcPsQWBir5BRY ry+zpij9yKEekElkSpA4/dJUovZi1HIK9WMdElqQKx8Av1ZSK/kcetX/jZiUq95Gpb4Q 2ovw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708623596; x=1709228396; 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=SZ2pQJ9+dxF//EaiCt/uq+OdRpwnCyd+9hrUk8R734o=; b=I4DhJ+CkQ4H8BUMksW7Q2UgEcp7IOHM3Xk0KRv3jpIk0s16NRE84VkVI0sxruKmbO1 vW+N445voDYDD74bungXzt2Fgz5w8fl47Egr5wVtrvO7YL7WWQWp/MKmypeb6SH77rqk /A/vS8nFJy2fjawGgz0Tvl4IMY/tZDsKeKqohA4q0R0q74jP45YWOhh+SZWb2HoJQscU fxVmPf2QvpFo4+PnikRovuGLLXX/TB2Odxo3G+NnoTGQD2gF7MPbJdsUbL7BfhX5R49J ymj5O6y44kuri5o3aqTJQ391SSNecWhpj9dICPkT9gi+nUybIdcRTfzuH82vlHDW55lF WeGw== X-Forwarded-Encrypted: i=1; AJvYcCUcXTKaS6Vqt300qE8W1PsHTj9KwPDgnRMO55t6nE1Bo0mDnI4mea46hauLWABGoQs4UvfOcAyEGFUWbsdK3vuxhLs= X-Gm-Message-State: AOJu0YzP5w4LDDRGTZRBiFbiMjnxE/cTmSp1MrxiZiPstc7dHKqEJ3YQ 7ioiy/abN5aacCVHj1+njiV0T1l4ZL125aNWg7dOtHYzo/f4V7zpWzyYlAIBvU0= X-Google-Smtp-Source: AGHT+IEtAUUqy5uqw2b6AFNUjnG1318TVskHRq83YxSHDfvItzdqlBQeiT8forYQaEVyJnoFBVJVWg== X-Received: by 2002:a81:431a:0:b0:607:ef06:eb8 with SMTP id q26-20020a81431a000000b00607ef060eb8mr20801514ywa.40.1708623595945; Thu, 22 Feb 2024 09:39:55 -0800 (PST) Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id f17-20020ac86ed1000000b0042e5ab6f24fsm259682qtv.7.2024.02.22.09.39.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 09:39:55 -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, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v5 11/11] iommu: account IOMMU allocated memory Date: Thu, 22 Feb 2024 17:39:37 +0000 Message-ID: <20240222173942.1481394-12-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240222173942.1481394-1-pasha.tatashin@soleen.com> References: <20240222173942.1481394-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: CE2BA1C0017 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: afaon5ai1xujqyutuo7p9uzc75gs9pg1 X-HE-Tag: 1708623596-641882 X-HE-Meta: U2FsdGVkX1+pG/vKC9597drVCLNakKkErMnokY6Rf2LxGGkdVyNuoJaIYUsNUiiIeZp8Km5meCWWHBEXIKiwYXTXyWv2bXILFpd1a3n9FEXeZQ57uqKhJrsumTcPDKyW9LIZcDsILoWM/JEQwAt/kP1CN1lnxxdySkttOH7OfYsnTxlUtotWkdJFj/yCs3h+Wj4wbX8r/QpofN8Rz67IaAzjVE3txTjh5ohy6HS5bsLXF4o0hMTbG8YKKTUHl8gZI2u3MGFg0mGwsH1hnTbh0Tp3lN2b1zgp+6u2cjIQ7vUXJta9AU3AhTfcqlLc2Ky0LiDYGx5gBpYadwPaqnV8SRd+jH5neJcpT5guv7DeudCZk5rkkE46wY4uurF4sPmvMhvj5Zyeqvu99GUE77oj+r2Gu+vTPzRPHFmsvZsa3q3d/gEWiZUhpX4ogtHX/Vd8863nqvHrZ68JaJhnkACi6sNhM/dfTe4TvrJglZr1o109ZQ+AWWRAe/CWFhjXcZN2Ep71vwqbPJfNGN24NDCJwQF82b9uFgrnQyo8sI1P8zgUe2T4TRx/EewzDoDv4KvRPzr0fXFh4ZlN0EAsbWwZZD8OxVaJM7H+pt8hkgJnzh+95cdJms7B9GdPjwFgMqcfrkUzksDZxLhaK6gX+3Xlj2FbaDDA7+b5SBmbSspX07K8eH9GU4a7ilMpqbpo4tJ0eyEdx2crah8a+7zmsZohvZf2MREdftsfpAeAS0oCYcLWFZnmoDgw6lektydjqroeqT9geB4fzDBsJStx80lYBntuUJ0Q500y2n0ofrHO39iBQ9UiZglB2EY/EbJ7fDxUxn7PxTfpQzhuZNXmfem0FCxp7orvLa+HqT0jSeDlbaqv14MSTUMCSz5r8+74Q4Sl5fl55zhGviKron8z8xllYOh4Rnhmx1PbHq432SONMdCuGPsjPgqvpmgOie5DkbMhiErCnDog+fqUzEOwH2G OhOP8CFP /WbFhPD+QvamJ/cx6+rayIRT8h604NlVLrdNuzFef+/tafH+EbZKCaPoWAIXfVLQNkdIw0pWbS0RF0HpmmjVfCstPk1deYTkJi1XkVlerIlsn03pFZl3zDw/GvlFvWjG2WH7IIJ0WVu2Wp9AjPi144NAMSKqQhRD3JmiPEO9p2SKUdm7xQHQvtLLt9ZnRtBi57wrRVoD3pRVTQKUv6E8Pjm1fnt4UB2oT73hAb5EECga/BIpNTfFbnbep8CAxD0OnGNd/tImTCs5kAlobMX6yWHvBR62PkxqX+pwhDWD2KcrSy+0F1/99j3Pm70sFNHan2bo8l6nDYM1i0xXR1qGjDe34R1v7isZyLVyh7AJN6STsDSA63Skp/0p0JgqooWHgzq7XkxiSu+2l3tkLgPpr8A0FIFrdXOS4bl/YOlDj8ak+V1lUkHPEa1YRTny94QPyVJj1vvz/qYUcpwibWtxbc83KTOmePx0klIgAPV4FZDa5+ncGr2tL2ZjFPUDS3thehs8exMTPveqLoB6IBHC1r8nzSZW5Hu0xOmCXwkdzr2AU0hYmMTWY6Jk+Pblm/gkfKGR4 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. There is a difference between GFP_ACCOUNT and what NR_IOMMU_PAGES shows. GFP_ACCOUNT is set only where it makes sense to charge to user processes, i.e. IOMMU Page Tables, but there more IOMMU shared data that should not really be charged to a specific process. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes Tested-by: Bagas Sanjaya --- 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 17e6e9565156..15f80fea8df7 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1432,7 +1432,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 104c6d047d9b..604b2dccdc5a 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 daac2da00e40..6df286931907 100644 --- a/drivers/iommu/iommu-pages.h +++ b/drivers/iommu/iommu-pages.h @@ -30,6 +30,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); } /** @@ -42,6 +43,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 bb6bc504915a..a18edcf12d53 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -202,7 +202,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