From patchwork Wed Feb 7 17:41:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13548810 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 F00C4C4829F for ; Wed, 7 Feb 2024 17:41:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBC436B0088; Wed, 7 Feb 2024 12:41:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D944A6B008A; Wed, 7 Feb 2024 12:41:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0D706B008C; Wed, 7 Feb 2024 12:41:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AE7046B0088 for ; Wed, 7 Feb 2024 12:41:22 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 869801403F2 for ; Wed, 7 Feb 2024 17:41:22 +0000 (UTC) X-FDA: 81765724404.06.7106F3D Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf04.hostedemail.com (Postfix) with ESMTP id BCFD74000C for ; Wed, 7 Feb 2024 17:41:20 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=Uh1jK89E; spf=none (imf04.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.178) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707327680; a=rsa-sha256; cv=none; b=nHapokAsBtLDxwgQlXFMq8kb46P9m8OPm8IxDelPgKt8pBk01iNyeub+d/nyrQwunz/uYy ih3bHlyzPzi3HtjKiwnkXjLwBsyDdhOxWgPBtOpsqKVFoDwgQOpEKuJqlFwmmfDdVWesUb Tkbj3/DbrfmYP61C5GLubonJzg9cumM= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=Uh1jK89E; spf=none (imf04.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.178) 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=1707327680; 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=HrRTSlkta7nD8c1SJPx3AxPn1tn9y9LkFmhcOlF4lks=; b=oHsMAviuDZVKIjx/fFpjANVNk3rH9WlMi++04PJuUNekGwVN076CbxSm+tKF2GPgzS2HED akCC+pEaIFcFWDHOX/CZD0ywqdjpL7XePFTzAIhxHevrr2DLXAA/NozHZCGRBEiUOEQdPt xirC4XBLDfGgw+tkPVuq/PzEWE4Wx3A= Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7853a9eb5daso33241685a.2 for ; Wed, 07 Feb 2024 09:41:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327680; x=1707932480; 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=HrRTSlkta7nD8c1SJPx3AxPn1tn9y9LkFmhcOlF4lks=; b=Uh1jK89EMRQfOMjgO3181uHl4xGWtdi0TFRf79u6h+x91vUrrKDljar3MLAHL3/xa2 NaEzgEG6Ow2a9UxTY9feZdRElLg9TptnzzWozd0VKuJhU8kk/mSjJuZQ6ExEy4WMe3Fs pMv4Yhu6cNwDBJY9wmVwHuUo8x00MkTZ8W12cchbPPoOLPLCJaJvrJjc1lmZL7w9vIaq 1jq5ulw8cpMjZ8C/prK31DmbU3CxTFzeg22c7o/kIw21a0O/MbxPeuq0Zj3VQAAUgnGP w4AmcZpXNMQB2PvQkFlbmAgwayOfOLFUGirlyMEr+TS/Tbgy6OozFryXnoOr9O7ZeXjC JXww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327680; x=1707932480; 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=HrRTSlkta7nD8c1SJPx3AxPn1tn9y9LkFmhcOlF4lks=; b=IKkcLMNuPOwB7Jr4yXNHHKNC4uTE7XSbeVsLY6ce9yHs40kiZxmxOAOZYcj1yUE8ll 1tFhGqVN/KaXlckhnSejFvME8jlqdsUVMrOOjnpyKIN60IMJzEZS64IGeH2kAz7MC4fM WeksrgCJY7kzGqPIDJT70OdhxjwLu1zMxt3ZT0IU1Kx7PzSnRtXnhNYOmDyv1qHFqhyE kBtB1emzXTQMWhndJdBsQXAtHeT6ryUmeEe90lj6Tj2eIiLb42dUvxRNMCgyB+QlFRGy LKiqTlfRUYXupdwT9owsP2S6NqZdoLURx/JnKbk/maQEHrGHls7+PCCl7qjJHgOQENWa puCg== X-Gm-Message-State: AOJu0YxlDBj+CTwYS46lLDunTL+coUKBuzriVbgu0MMGZIlXfagqo8mD O9bkaKCGBzrfmrIde7wPmcmGtg3mwJJbIbGJ19iNQBMcIRu2gqeYJR4pj5Siu3I= X-Google-Smtp-Source: AGHT+IHhb+pueaISZV6Y8tJp2t2CFo0mWlpmACo7IYuyoV1N2oy7KZrIG0XVhtVG+SmB5cwuhpqy+Q== X-Received: by 2002:a05:620a:12c8:b0:785:3887:de18 with SMTP id e8-20020a05620a12c800b007853887de18mr6401324qkl.65.1707327679899; Wed, 07 Feb 2024 09:41:19 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUCDfKWFIl6QUubNKHOK+J/TQZfBk6GOATQV7+UROelHHizxj2bMScNb5yjy+7wEKvrKAVO938EhFK3MDp4QvVuIEMns3aJNEfZ4lLhVczSUx4hYdn3X7Qx8HTpAiobpDi+dY9UU0JFYWP3sxFQVS1xxl7fcBVSx0blttAqIQWkGbtG/8OFxy5YJX+xNhtsJb3t9pvZsef+YcrlQh+9z7K1HEh5YIvRBqpPod3dD8oKW9DDybH9+3HAaHHBY8iiIHdHyvvhg/Qqh/tY8U66rdo6r4QvsxgmBFMyxznrxlOPKUwMUFVhM2YvFghVr6hKgb6KzPzIvg28q6LrAw8lD7weD0eI2MrfirCmooqnAA/zgK7D0KurMOIDpabn9VkUHuhE88OEKQ8h62/Wa2gdcl4YDdMkJY4DDjELGulQmsDVBCrUtil9loYc5aX8Gh2jq/ztHo3kv5ymJnfZ/h7e7WZdfaZvxSbUL64wc23AYR/EczgayCdZpmGXX2jQE3/KPfSIPAL6DXV6qvHIwUWL4vG18mc7tiVYDE//uM4hJo7eMbISiBgH4sundju5RQWqxyjeA3VcVHj+VPU4vBDpsrZVdnHRZeaGTV3rwC8oZXb19D/7KR1Wm7euJ76N5bgFnA7vjZhfsEp+F03DZsEUpCkkLYMsxrQWrLbAZIy488QP+Zdz41QqcwwktLByJIdIxAeRSxHxin8RRSgrxaqXRKius9NFl4oDbRCD6svZoHMd4UnX0vfYrQ0s8umvFi83/7gbRVCzXY4TP8NJFByhRuhTVTALB1EBu6ny+PtNXEQLdFexeijpQwT5/ahI+mpZ9ajMM7oM3At8FGk5pnU/BL1Nonz5Y8fjdV6tPG/C5Zk6RhURg9qAf+9R8Omad1eFWXxT9K6yqaix3pq9xGAZ8o3pF+xFI149xhPQNCmvLnHRgEmJUeIIm7boC4Kgdr C5bBoaux c6ozrLySOAxoy5JAAUBKnlhPctpWnwmvtfHeBXAM+mRt1+c/cu3MhP0MSUMt9WZHns3r/985c1KNIPq0blR6t+yh5SOQk7YDqh0wPxUpt4Kax6NjryE1iCgR1+E5QeDElNdAVf+hiKcPe5+DO4dGivJK8C2DQW1E5U+dX94X2hiWwHcHd0IHOFqpQBMw3MYyXVibLuxNZq6E5ml+47r+bMOyL/Bqfi3ViLUhztHQ6nikGjlZcsJYY7JUssc0W5vg58IiiHspK92+rwN2jGd4sH3ALx4bgyCF0SF9flcBEtXUjRUNSmob4ETrVkz7HKMS7If6nnJcyM0Vbo0UMoOZmd5knYt1xz+hu+YULQesXnetGwV4BBbVo0WA5dRc2eIzIsQXmdql1aXqiSjGCn5mug3+d3TEVV9PvmDpKEou6WN731U4KQNAZjHoQUf6UFZNlFysQJQPL4NE73c76duMdmUXiGxzZFehKgNvB7y4Wu+1/j 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 e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:19 -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 v4 10/10] iommu: account IOMMU allocated memory Date: Wed, 7 Feb 2024 17:41:02 +0000 Message-ID: <20240207174102.1486130-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240207174102.1486130-1-pasha.tatashin@soleen.com> References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: BCFD74000C X-Stat-Signature: nijcy869iim15b9oqzchcduiypwr815n X-Rspam-User: X-HE-Tag: 1707327680-804622 X-HE-Meta: U2FsdGVkX1+efKno/E7bMFXu1vDx4eg4ePFxaWLjStJtf+t+wczeb0RK0uCa0d4liRYdAMfCTGvF0CP7a/kjeYTjkuluKCb0mArYjOFYsRGvANEe4SCY4tX0fZIdprdWpIJ77hUpfsSI6XbBOfoSNa7emk5Arn5Vi6ocz3SeDTdUYI7NlkBcvWgwLsUe6hys0Xe8e0w26LcADppjWFcOJ1VqyIox58oONbMAMOtRvxGmIA5aBCd7G0KDCe6F00pSErRuLy2khlHD2waYVuIjiKGOVyLRC9hrXVHguw251zVxlO+kWMr/2s4CKecFHiBX/52uaVeRL06jEP598oa4BlQX+g8NhRCVVkMGMfqCXkNGvpw5ccSvopl0kM812dsZEh9HKZ6QaTbP7BRWhYY2s+rvAhqVGjifUAlb38PdqA9e6xOhi7Q+1lEmiuzRVpaQrdMspEwIO2PgZGMNypZ6Ql4kZeP+JuQIno/xn5NRbR3f/I2xvVy1oYUtw9u6EWgJDl4vY3S27gNLRc78eUpKVwBfaFMPFWk9a0E0p/L2YQPXsIK/ZpyKHcEcqwwFZWb/PupSt6J/7W6/r1pk4mk1DWJGatFMQO9+pIHzvi0jbYROFpJQdzzJ77/rJU4rMhvKRxuvjKHIXpObbA7I4Iqi5Q2iuDSokFZlY4chW8E4O+MzUC5yiMw3qmXeSV30xLnpvgjsOV+25yy7IDeei01mE2FCqQscV8cuNmkIIYgMCMT0+zivMDnzgtDumLDB7jQIVEtbdMcYjtLxMxb8+R+2jESJ5UJ9cQeUvq2IAQ73/TK50POZhgIq97uOZ4BJAK9dfvuRUW4MFcOlNTLs8I3Q2xQOV6Voph+us3JmDMdhmFyjFJRvRWQ513j/p9vzPeLPs0EvHUxYdIZgjwNsYlhmfEIDZquQfBFGyXTa45kiczH3+bgOlVefeB1reSGHS+O+ziXoWvW4WTXGNMR5WNC 6fVWbv6c R39+r0VDHRPQWbN49Chjs0hr2NkqvJz3HEyotN4EGPPuuChV6HRnoIct/3FQkeIiz3z7KrvCKlRnQbSeIy8WvRblsJEmP7BQiwUeX+nKDuQG71+H5DlxpnjjTwiOJDrpw3VmgMERVRpT5nVNia44jHztfzR94nqfMFyv+7PN5aq7GWjCcrup0NHX/pZi/G4fmlHWjuVcF3vIJmomkLe5k82tqW6YYCQniL7hoVDUf15t3b7cNHbFQ8UzbFRMqSklcpaxWHyeV8FsOloAWNWGWLqFAnK8LQpn6fYzzsaNbHdNvnOT018xlJ5oLdX+hMBuY2T18XGmFfPWW8VogRGbatTW3AsgO2rG9iRIa6vGBOZj03A5bFxFC/VPPA/PRoHNymclkSX3altJlkBvAN6HnyKdqUm/TQtK0H+RXaaDAeaMyBjX39bKmVOmz/xQh8+tmSGVH 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 7336f976b641..e3eb93857a73 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 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