]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu: account IOMMU allocated memory
authorPasha Tatashin <pasha.tatashin@soleen.com>
Sat, 13 Apr 2024 00:25:22 +0000 (00:25 +0000)
committerJoerg Roedel <jroedel@suse.de>
Mon, 15 Apr 2024 12:31:48 +0000 (14:31 +0200)
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 <pasha.tatashin@soleen.com>
Acked-by: David Rientjes <rientjes@google.com>
Tested-by: Bagas Sanjaya <bagasdotme@gmail.com>
Link: https://lore.kernel.org/r/20240413002522.1101315-12-pasha.tatashin@soleen.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Documentation/admin-guide/cgroup-v2.rst
Documentation/filesystems/proc.rst
drivers/iommu/iommu-pages.h
include/linux/mmzone.h

index 17e6e9565156404e1adec007b20a31f097b20294..15f80fea8df76491d5909bf0884ce51a8190bf87 100644 (file)
@@ -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
index c6a6b9df210497de6f2ad8e8a7dffc1bd974016a..707e39280a9a7b6fbdd8231968438e3879ee7d48 100644 (file)
@@ -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.
index 1264b0f6b6c3cb568c2cc078926b36a08b3bdb8c..82ebf00330811c19d3b8f3f5a05c44e58e6e353d 100644 (file)
@@ -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);
 }
 
 /**
index be17195f6f868ccbd7f431112b588275918a5a7c..8f9c9590a42cfd646e4394d220a9da4d3559aa70 100644 (file)
@@ -205,7 +205,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