[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240704043132.28501-12-osalvador@suse.de>
Date: Thu, 4 Jul 2024 06:30:58 +0200
From: Oscar Salvador <osalvador@...e.de>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: linux-kernel@...r.kernel.org,
linux-mm@...ck.org,
Peter Xu <peterx@...hat.com>,
Muchun Song <muchun.song@...ux.dev>,
David Hildenbrand <david@...hat.com>,
SeongJae Park <sj@...nel.org>,
Miaohe Lin <linmiaohe@...wei.com>,
Michal Hocko <mhocko@...e.com>,
Matthew Wilcox <willy@...radead.org>,
Christophe Leroy <christophe.leroy@...roup.eu>,
Oscar Salvador <osalvador@...e.de>
Subject: [PATCH 11/45] fs/proc: Enable smaps_pte_entry to handle cont-pte mapped hugetlb vmas
HugeTLB pages can be cont-pte mapped, so teach smaps_pte_entry to handle
them.
Signed-off-by: Oscar Salvador <osalvador@...e.de>
---
fs/proc/task_mmu.c | 19 +++++++++++++------
include/linux/pgtable.h | 12 ++++++++++++
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 3f3460ff03b0..4d94b6ce58dd 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -825,6 +825,7 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr,
struct page *page = NULL;
bool present = false, young = false, dirty = false;
pte_t ptent = ptep_get(pte);
+ unsigned long size = pte_cont(ptent) ? PAGE_SIZE * CONT_PTES : PAGE_SIZE;
if (pte_present(ptent)) {
page = vm_normal_page(vma, addr, ptent);
@@ -834,18 +835,18 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr,
} else if (is_swap_pte(ptent)) {
swp_entry_t swpent = pte_to_swp_entry(ptent);
- if (!non_swap_entry(swpent)) {
+ if (!is_vm_hugetlb_page(vma) && !non_swap_entry(swpent)) {
int mapcount;
- mss->swap += PAGE_SIZE;
+ mss->swap += size;
mapcount = swp_swapcount(swpent);
if (mapcount >= 2) {
- u64 pss_delta = (u64)PAGE_SIZE << PSS_SHIFT;
+ u64 pss_delta = (u64)size << PSS_SHIFT;
do_div(pss_delta, mapcount);
mss->swap_pss += pss_delta;
} else {
- mss->swap_pss += (u64)PAGE_SIZE << PSS_SHIFT;
+ mss->swap_pss += (u64)size << PSS_SHIFT;
}
} else if (is_pfn_swap_entry(swpent)) {
if (is_device_private_entry(swpent))
@@ -860,7 +861,10 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr,
if (!page)
return;
- smaps_account(mss, page, false, young, dirty, locked, present);
+ if (is_vm_hugetlb_page(vma))
+ mss_hugetlb_update(mss, page_folio(page), vma, pte);
+ else
+ smaps_account(mss, page, false, young, dirty, locked, present);
}
#ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES
@@ -952,6 +956,7 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
struct vm_area_struct *vma = walk->vma;
pte_t *pte;
spinlock_t *ptl;
+ unsigned long size, cont_ptes;
ptl = pmd_huge_lock(pmd, vma);
if (ptl) {
@@ -965,7 +970,9 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
walk->action = ACTION_AGAIN;
return 0;
}
- for (; addr != end; pte++, addr += PAGE_SIZE)
+ size = pte_cont(ptep_get(pte)) ? PAGE_SIZE * CONT_PTES : PAGE_SIZE;
+ cont_ptes = pte_cont(ptep_get(pte)) ? CONT_PTES : 1;
+ for (; addr != end; pte += cont_ptes, addr += size)
smaps_pte_entry(pte, addr, walk);
pte_unmap_unlock(pte - 1, ptl);
out:
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index a9edeb86b7fe..991137dab87e 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -1926,6 +1926,18 @@ typedef unsigned int pgtbl_mod_mask;
#define CONT_PMDS 0
#endif
+#ifndef pte_cont
+#define pte_cont(x) false
+#endif
+
+#ifndef CONT_PTE_SIZE
+#define CONT_PTE_SIZE 0
+#endif
+
+#ifndef CONT_PTES
+#define CONT_PTES 0
+#endif
+
/*
* We always define pmd_pfn for all archs as it's used in lots of generic
* code. Now it happens too for pud_pfn (and can happen for larger
--
2.26.2
Powered by blists - more mailing lists