From patchwork Tue Nov 28 20:49:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13471796 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 033BAC46CA0 for ; Tue, 28 Nov 2023 20:50:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 749896B0363; Tue, 28 Nov 2023 15:49:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F74D6B0364; Tue, 28 Nov 2023 15:49:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FCA86B0365; Tue, 28 Nov 2023 15:49:57 -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 3BFDD6B0363 for ; Tue, 28 Nov 2023 15:49:57 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 040158034D for ; Tue, 28 Nov 2023 20:49:56 +0000 (UTC) X-FDA: 81508554834.21.08CA12B Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) by imf08.hostedemail.com (Postfix) with ESMTP id 43386160013 for ; Tue, 28 Nov 2023 20:49:55 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="mvDvr/M1"; spf=pass (imf08.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.128.169 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=1701204595; 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=phIWLgEuDxv92AIZhGfw+EGW167LF5JCtkcwTmMEADLEMOOwKME/J7J9ojLPcTWl6kWqtv 8sYzW6gRw76xjzEEKlYUJ2CU3/sb9o9x3ydQNy7dA+AeAlXw+GRaycYtbpn7H1AbbiMpS5 CSlraTrWX9EN/zQk/3y4wFhCTmqdqic= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701204595; a=rsa-sha256; cv=none; b=M7YtTDx2G43Qg9bwZQ3mFnfXyY+NmZP3Y5qYxz28rRn4ynEKIW6AewFYgQD61z8uK7JTr+ yOaAA1HosBIwHOKh3LAYOodbQr/MtxkBA5afEw1kv+GHJl1N/eMh1fZZg+q+yhQXja623I YdMzylIfyZhI6Ed+EhM2g7QK7eeJzdQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="mvDvr/M1"; spf=pass (imf08.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.128.169 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-5ce8eff71e1so41753707b3.0 for ; Tue, 28 Nov 2023 12:49:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701204594; x=1701809394; 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=mvDvr/M1DsuICzjWl3ECvd4/wGd+aDwmV/H6CIyz6fBrPBiEMXTcq5pgDnf1KXeYzz JplNw6pi7F+xLHlpAEOfcD6/JkluZ2Bpqk59YnRrr+7FJiFXbDKpoUhyxARktMMyr8xA BxXr8x5HUhwYIbONfOWqpcctpR1MfHZ8cK6yQ1wiL5jZ8XPM/xwBOy5pgQ18HJBwGKm9 puWgV528vpnLA6DLRGhQbxzvjylGqRueSlJlI1xKUQUmaPF6Iw/+bkFQOIwFhcV/J6Zi g5nDxXP/sfSP9WQOKSTngYws2+tmOvwrhbDBhpahzmfznRQRiH7hO/I0alJ6fjDK1tLa J+gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701204594; x=1701809394; 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=TJskc468cDjsvBJE//koZSMhjfkH65E9w0dAULihkmmUZlF6qFCi5lcstt6i44haid tQ3Pxp2JR1NhJdCxtmSLrwk0I3k3EFnhNM/KHAUp8RmDk8yL3ML8mZGT9U19szo/HKY8 SKyZOKuKvLI/+TokI1JbansL40fyNPM/FNfjn3jABU6RIyJsHe/yYbRgE4Jl14OxLZYd qyuzHhRP00N4367zG5SfQhMJd2in8zyBrSdd7UBINefCnumrKysbznR9IMNgLmVhBueV eQo5ybYHs6xcSeQQQ1rkhdseo1mMVgciWe+76VVKkGF88eKug2QTUzVqRZ3BWbo4eQJv siaQ== X-Gm-Message-State: AOJu0YzVFCL6TQbo12mMI7B6DjjWwRSxru/wfE/BtX983qdj0jnwJK9T 7/zBk+fN9X0b9OB/hKPmZIxOpg== X-Google-Smtp-Source: AGHT+IFeRft5lu3DnWQgWnRJh58TGHHoSR4IZRyS1wE4nkLKveRfays9X3IHaY/+Xezkx1Q2h+wp9Q== X-Received: by 2002:a81:a507:0:b0:5cb:d645:8cdf with SMTP id u7-20020a81a507000000b005cbd6458cdfmr16849996ywg.48.1701204594372; Tue, 28 Nov 2023 12:49:54 -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 d11-20020a0cfe8b000000b0067a56b6adfesm1056863qvs.71.2023.11.28.12.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 12:49:54 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alex.williamson@redhat.com, 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, jasowang@redhat.com, jernej.skrabec@gmail.com, jgg@ziepe.ca, jonathanh@nvidia.com, joro@8bytes.org, kevin.tian@intel.com, krzysztof.kozlowski@linaro.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.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, mst@redhat.com, m.szyprowski@samsung.com, netdev@vger.kernel.org, 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, virtualization@lists.linux.dev, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com Subject: [PATCH 14/16] iommu: account IOMMU allocated memory Date: Tue, 28 Nov 2023 20:49:36 +0000 Message-ID: <20231128204938.1453583-15-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231128204938.1453583-1-pasha.tatashin@soleen.com> References: <20231128204938.1453583-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 43386160013 X-Rspam-User: X-Stat-Signature: wp84wzftu8tqnm5hk65zqj6kky7z4y48 X-Rspamd-Server: rspam03 X-HE-Tag: 1701204595-470387 X-HE-Meta: U2FsdGVkX1955hdCsRVLf0neuy5Dy92i1vVNa7zGGOe9nDr5gj5rCg5+4t0Xw9JxyaAMeEbfrD31Spi5sNSmAHJuoda3/hvcVK4GP1Jfs5HTJm3D1+PvQGAE3tCp8Vghezenu6+VCwpM+N75sveLpMI3vbnqBeRdaSWxPu9plwgxRrLMlhjyGUTO1/5eqY8R52PmUT7NWtYReA2f6nf+aTJ5/aSCQ/DQWdxQE3/D4/2ivRkt0PjPdj2UVThzhpJGS2SG1yW4yQkwlHzPgUwXeYp5DOv05fskLLYJtX6E/3VVn45l2j7R/MUq6p54WtHiDsZjoOIEiKDDT+zm48jTAacx8EStOmZ1H3js8q5MRVD94Fyvwic1oVvvFOwIWzSmYV1ZJw4nL+c8BrueFu+S0US1kgAzqVta5pfFq0pHE+arygctkZePQZZQ3YYIx9/nH9dp0HYmUm6lCQ14ZJcVtT5gjQMdvSVq4Ukjpk2odk408703ZH+o/Jie7TI/WVzer06vPIIDT6V3hT2h/KTr/KT0YM3M5BxOW2lNHOsI4hhbIahxbljaF5fzpQ4n4C811Bw4OhrnYxZJpAZ29MbRx7osisnn1HhG+17td9mJ7OMjIgBs1Gf4n+unkB+w7FBpz5FXfxi07yKB71fuk5TUdUKDEZ9+3pYoXMJAzI8pMysHF+UtHY7PRAXoQbkAIPWr9r3DY0Z1FYW18uxGlcGbjmdgC5uMM34nvOYPqEfOnaxYMqe9NEt7AfFSCkjlXxmLc4J8FkLURI69bDDxVKUD5F/VG8ux8INTcgNiHCTBvWRC5ZrqUR7T1O30r94l+nfgkquRGgscoanEzZSPhzpGoROGM+FKNsmGPhbWhZ/DCPOD9Pxz1jhMNu0UbEb8AcbII8VJK5FV3Uc666chO2JyI84W7407ebneOLvp+j1viZVx+kTgTlCkewWj/zGkjIjuv+h0RkyyrTdIVfgAcpU xIq1G44J qUOSnTytIBK3A8zNWn1uF3xX6/SogoB0rtKZkWNDRo5E0gq2MAZA8ODm/hlesSR2roPim9g1rB6rm0BNd/4nj3ldSwq3TaARnD5QLDo8nU9XNkhxL1ZnsIhWy+7kSG8adtE/RwqWvVc3AL0ow1FjzhH0GdObwHREYB7ofm7zuYi44SfI5wVv09os7mJ4X+1ERdDb4npYERVRnxN5kIK/JwWBi+F1DaRayJA3I4IINj0wqz99vPcO2MJ+FvTCLFaXxqGlDk9yKSk4V0Ggu0vxJgo1tYyWhv73EA5tY3ACi9uoio47EyJXNNrVffTsTYmkR/C2zaY0R8HIlUDSQWJDMFzXXEvXLO4bbUUa3/y7y4/0y2D/2cZgDOCRzSJ2MIGl2JJI8w7lFQ+Bms3VsK4PzrXGWAhlXxIOkNLQegGB8DMGBrdhiQ5VutrnLmKWGN45/ohma 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 --- 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