mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] tools/mm/thpmaps: fix THP statistics and mapping names
@ 2026-10-27  7:49 Weilin Tong
  2026-10-27  7:49 ` [PATCH 1/3] tools/mm/thpmaps: fix partial THP anon/file accounting Weilin Tong
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Weilin Tong @ 2026-10-27  7:49 UTC (permalink / raw)
  To: Andrew Morton, Ryan Roberts
  Cc: David Hildenbrand, Baolin Wang, linux-mm, linux-kernel

This series fixes three issues in thpmaps.

Patch 1 corrects anon/file accounting for trailing partial THPs.
Patch 2 includes order-1 file THPs in the per-size statistics.
Patch 3 preserves mapping names containing whitespace, including
paths with a (deleted) suffix.

The three fixes are independent.

Weilin Tong (3):
  tools/mm/thpmaps: fix partial THP anon/file accounting
  tools/mm/thpmaps: fix missing order-1 file THP statistics
  tools/mm/thpmaps: fix missing mapping names

 tools/mm/thpmaps | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


base-commit: 39274b454e9993cea319f4ac342a8082a9ee1730
-- 
2.43.7


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] tools/mm/thpmaps: fix partial THP anon/file accounting
  2026-10-27  7:49 [PATCH 0/3] tools/mm/thpmaps: fix THP statistics and mapping names Weilin Tong
@ 2026-10-27  7:49 ` Weilin Tong
  2026-10-27  7:49 ` [PATCH 2/3] tools/mm/thpmaps: fix missing order-1 file THP statistics Weilin Tong
  2026-10-27  7:49 ` [PATCH 3/3] tools/mm/thpmaps: fix missing mapping names Weilin Tong
  2 siblings, 0 replies; 4+ messages in thread
From: Weilin Tong @ 2026-10-27  7:49 UTC (permalink / raw)
  To: Andrew Morton, Ryan Roberts
  Cc: David Hildenbrand, Baolin Wang, linux-mm, linux-kernel

thp_parse() reduces index_end before looking up the type of the
trailing partially mapped THP. The lookup then uses the preceding
page, or anons[-1] if the THP starts at index zero, so its pages can
be charged to the wrong anon/file counter.

Account the partial THP before reducing index_end.

Fixes: 2444172cfde4 ("tools/mm: add thpmaps script to dump THP usage info")
Assisted-by: LLM
Signed-off-by: Weilin Tong <tongweilin@linux.alibaba.com>
---
 tools/mm/thpmaps | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/mm/thpmaps b/tools/mm/thpmaps
index 803e0318f2fe..d92aace005c1 100644
--- a/tools/mm/thpmaps
+++ b/tools/mm/thpmaps
@@ -263,8 +263,8 @@ def thp_parse(vma, kpageflags, ranges, indexes, vfns, pfns, anons, heads):
             if flags & KPF_COMPOUND_TAIL:
                 nr = index_end - int(folios[-1])
                 folios = folios[:-1]
-                index_end -= nr
                 stats['anon' if anons[index_end - 1] else 'file']['partial'] += nr
+                index_end -= nr
 
         # Account fully mapped THPs in the middle of the range.
         if len(folios):
-- 
2.43.7


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] tools/mm/thpmaps: fix missing order-1 file THP statistics
  2026-10-27  7:49 [PATCH 0/3] tools/mm/thpmaps: fix THP statistics and mapping names Weilin Tong
  2026-10-27  7:49 ` [PATCH 1/3] tools/mm/thpmaps: fix partial THP anon/file accounting Weilin Tong
@ 2026-10-27  7:49 ` Weilin Tong
  2026-10-27  7:49 ` [PATCH 3/3] tools/mm/thpmaps: fix missing mapping names Weilin Tong
  2 siblings, 0 replies; 4+ messages in thread
From: Weilin Tong @ 2026-10-27  7:49 UTC (permalink / raw)
  To: Andrew Morton, Ryan Roberts
  Cc: David Hildenbrand, Baolin Wang, linux-mm, linux-kernel

File-backed THPs can have order 1, but the per-size counters are only
emitted for order 2 and above. Fully and contiguously mapped order-1
file THPs are therefore missing from the output.

Start emitting the per-size counters at order 1.

Fixes: 2444172cfde4 ("tools/mm: add thpmaps script to dump THP usage info")
Assisted-by: LLM
Signed-off-by: Weilin Tong <tongweilin@linux.alibaba.com>
---
 tools/mm/thpmaps | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/mm/thpmaps b/tools/mm/thpmaps
index d92aace005c1..30a8e915d677 100644
--- a/tools/mm/thpmaps
+++ b/tools/mm/thpmaps
@@ -295,7 +295,7 @@ def thp_parse(vma, kpageflags, ranges, indexes, vfns, pfns, anons, heads):
 
     def flatten_sub(type, subtype, stats):
         param = f"{type}-thp-pte-{subtype}-{{}}kB"
-        for od, nr in enumerate(stats[2:], 2):
+        for od, nr in enumerate(stats[1:], 1):
             rstats[param.format(odkb(od))] = {'type': type, 'value': nrkb(nr)}
 
     def flatten_type(type, stats):
-- 
2.43.7


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] tools/mm/thpmaps: fix missing mapping names
  2026-10-27  7:49 [PATCH 0/3] tools/mm/thpmaps: fix THP statistics and mapping names Weilin Tong
  2026-10-27  7:49 ` [PATCH 1/3] tools/mm/thpmaps: fix partial THP anon/file accounting Weilin Tong
  2026-10-27  7:49 ` [PATCH 2/3] tools/mm/thpmaps: fix missing order-1 file THP statistics Weilin Tong
@ 2026-10-27  7:49 ` Weilin Tong
  2 siblings, 0 replies; 4+ messages in thread
From: Weilin Tong @ 2026-10-27  7:49 UTC (permalink / raw)
  To: Andrew Morton, Ryan Roberts
  Cc: David Hildenbrand, Baolin Wang, linux-mm, linux-kernel

VMAList splits smaps lines on whitespace and only keeps the mapping
name when there are exactly six fields. Names containing whitespace,
including paths with a (deleted) suffix, are therefore lost.

Limit splitting to the five fixed fields and preserve the remaining
name.

Fixes: 2444172cfde4 ("tools/mm: add thpmaps script to dump THP usage info")
Assisted-by: LLM
Signed-off-by: Weilin Tong <tongweilin@linux.alibaba.com>
---
 tools/mm/thpmaps | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/mm/thpmaps b/tools/mm/thpmaps
index 30a8e915d677..a1a9bc30514f 100644
--- a/tools/mm/thpmaps
+++ b/tools/mm/thpmaps
@@ -198,7 +198,7 @@ class VMAList:
         self.vmas = []
         with open(f'/proc/{pid}/smaps', 'r') as file:
             for line in file:
-                elements = line.split()
+                elements = line.rstrip('\n').split(maxsplit=5)
                 if '-' in elements[0]:
                     start, end = map(lambda x: int(x, 16), elements[0].split('-'))
                     major, minor = map(lambda x: int(x, 16), elements[3].split(':'))
-- 
2.43.7


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-27  7:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-27  7:49 [PATCH 0/3] tools/mm/thpmaps: fix THP statistics and mapping names Weilin Tong
2026-10-27  7:49 ` [PATCH 1/3] tools/mm/thpmaps: fix partial THP anon/file accounting Weilin Tong
2026-10-27  7:49 ` [PATCH 2/3] tools/mm/thpmaps: fix missing order-1 file THP statistics Weilin Tong
2026-10-27  7:49 ` [PATCH 3/3] tools/mm/thpmaps: fix missing mapping names Weilin Tong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®