Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp499527rdb; Thu, 22 Feb 2024 10:00:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWtapIGU3QNA8Kqj1I57tuUnkoqAigzhyMnk07FXZHmXrrUxxqjMUlHSWhSpYpBd/9i4XI+DJVl0e1R2UeNBwzqUcb/1ohXrtARZR4fdQ== X-Google-Smtp-Source: AGHT+IHoRRoGXTftn0xg8JpZhHuANIQOOMwlNN+yy9+91vuPBbL10LfkRzRoGAuvxGBiFhr7Icls X-Received: by 2002:a05:6e02:105:b0:365:2390:931f with SMTP id t5-20020a056e02010500b003652390931fmr14965898ilm.4.1708624851343; Thu, 22 Feb 2024 10:00:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708624851; cv=pass; d=google.com; s=arc-20160816; b=aWTBYbr6TxgbpCtvN7hiEHaYNVgScCHSrMBV9NiHf4+j2sdasTl+nre/+v7wXACeST 7JYVk/txpy1HTVBrZgv1NH/z884D83AtwFyQ0V0zAQGEGBA0Y4J9AMAzgbIDaHdcjHwQ i9rJM8RjMdIQkK2aRdvIbQhFU4afpkhMpxwqC+ZhUlUr0F1X9EJIhfr9K6HUf8FYj5nH 4ZJ4Upmta0/6MQLHdUyUx6f+ei0mhtjCgOEGMmIu2yrr6dsw1XRt+EZL2IF1vt5fsI4B x7subeaSpN88tIA32QfuwBJT3ulwq47Q6qsimxWomcWR6h3oaSYJhX8ssZ4HWoElbafP GL+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=SZ2pQJ9+dxF//EaiCt/uq+OdRpwnCyd+9hrUk8R734o=; fh=3MygRo5nHVt8uagvVOsfTpSfv1wWYWiB1c89fTqhpXI=; b=pokKYPhL7RU15KaYyQc0uPHg3UjwNgOGnmJebQ9PSO9RHprPpCm3/WZTOl+Y9h0VLX InNPMUuqwmpywtBLuGkBhxuSnglbviuH+vl49R39RvyJd9u6gdbB314QXS4zyQBeHjCH +45rwLf+ot7+1yX+W4DL+LbxDhKO1ewwDoMGpyYBQ+OEvGy/0L2yMfV1AmDV4WGOAK3M qmA0MjXI/5tTyMXxjUD/uYuEEAqMR3LgHizVOYX5du/kOQltAp2ucyTzZocr5fHmvE+F RxnkFVbsKaXZ89xkRSNBoUpZIYBz04ail96FusLG4g+TrPXjqiSUwA0UiLLbeUFKa3IS 5Fwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=yewvBuHl; arc=pass (i=1 spf=pass spfdomain=soleen.com dkim=pass dkdomain=soleen-com.20230601.gappssmtp.com dmarc=pass fromdomain=soleen.com); spf=pass (google.com: domain of linux-kernel+bounces-76999-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=soleen.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z25-20020a6b5c19000000b007c788bf49a7si336129ioh.31.2024.02.22.10.00.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:00:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76999-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=yewvBuHl; arc=pass (i=1 spf=pass spfdomain=soleen.com dkim=pass dkdomain=soleen-com.20230601.gappssmtp.com dmarc=pass fromdomain=soleen.com); spf=pass (google.com: domain of linux-kernel+bounces-76999-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=soleen.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 586B3289CE8 for ; Thu, 22 Feb 2024 17:42:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A78415B11C; Thu, 22 Feb 2024 17:40:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="yewvBuHl" Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD1111552E9 for ; Thu, 22 Feb 2024 17:40:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708623606; cv=none; b=RPf+BshkTq0Hulq7pAPBGJOpYMAFisTmVtwdWe0ucsaBGVvGp27xxS6SXaC2SK10H/3/tYrjGp5na5UCNzkumKNab2qURogVjBKFpOpntkuOT3WarmPQnYnhOcsrPO2OMJrXRDS0TkuZ7HE/W1hlbqnwvzs8rMNh35xqjbqbtWE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708623606; c=relaxed/simple; bh=s2nvM2JSjpFzXc4jGY+I9yEyb0A/qzUAKQj+oJecsuI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pW1nwE+PXl10IjUcFsS2GAO0H0gH71W4sDo7EuGxqSqyGRubnod9ybtWQ2AJ/c/LnZOwgMmqyaZE3a2AdHbEsj7cR2ot5kP8m9pno/L32v0h8BAuPd1F9ORY16+L4g3TufILGile9mTdoimSpozEEZaeY7TuJ6eIkXROIYTvT9U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=yewvBuHl; arc=none smtp.client-ip=209.85.128.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-607c5679842so20926107b3.2 for ; Thu, 22 Feb 2024 09:39:58 -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=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=SZ2pQJ9+dxF//EaiCt/uq+OdRpwnCyd+9hrUk8R734o=; b=yewvBuHle/gJwA+itjyFD/ybSsLiCIVR4xaJxgr0GB+wC2676n9F9XZ+/oMyjm1icz 1TJwrAZI1jAv43V4OtZbsV3mJCAbh2urs3n+gUB42mgT5Gc/tD2jJ2+RCoRoq1l3Ct2x jobWQ8AtkC5O7anBaEvifFHAdNfbh9MnCZpm40s46wqiMmIx7g1Hda4hl7D2LBzmRy/g Yar7fao1ojokoqySRKMvg1Z71ZRvzD5rNQwcb0tAiPxwVN0UI9R8vPotL1pwzcetufwB 2Hp9Atw50NLLmq3mMlpQ7KIDbC7Xnth5tKXg6G4uZnBPyB7t+/Wm0rqL46Se2cGZ61oI /+pA== 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=Wf1rUhdMQO3YAD++7hW+qswkBMZCo6dTE19idItr6nisjUVb0czZuLxKMORamRozje u/pkkJFOSppi9v3MfFEJkSDhxFcXNZJvi97Y3JJWgnkai/kyE2xfqyEuhWVafTHq9IZh dWOCcKIkWvKDt0QsOTGv2eLG+YHlxBTNbuR16UsPdcX4x2xlxS2BaeusQvcwO1uEggXS eQdjJ/tmgHO2qKjEXGdD1uCvuLIv9Riz/liihGwbdWPeu4vBY5h7uHYKDI6aC+F4AkjJ JF2M1xtu2uZCGIzO1lffxFCiiO1+s0r31OSE2MJfgwtgFFqUF8gSOImY10qNJk01DzGx SIfg== X-Forwarded-Encrypted: i=1; AJvYcCXSjrFiJ9JPNTHiBBDrMvXz8Vyy4VbXqeCypt1XsPX4Vd/kMitovy7Sp6vqu2PoX7vQVoeOzh6BaN+HGtjCspbELxVXarExMiil0J0y X-Gm-Message-State: AOJu0Yyzm+Mk5p8mx8O9BecpJv9XEIGqI8eW1dKJCgYR2UuHpoEMWbFR 8dHeHdsBenRod8oNqTPFlnaeSFBkiuPdZOG6+jGXb+KDVjY5EoGDPVP+LGumgpQ= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 -- 2.44.0.rc0.258.g7320e95886-goog