Skip to contentSkip to conversation

smaps: Report correct page sizes with THP

PATCH Superseded Andi Kleen 3 participants 5 messages Feb 9 – Feb 21

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 smaps: Report correct page sizes with THP

Recently I wasted quite some time debugging why THP didn't work, when it was just smaps always reporting the base page size. It has separate counts for (non m) THP, but using them is not always obvious. For standard THP the page sizes can be actually derived from the existing counts, so do just do that. I left KernelPageSize alone.
The mixed page size case is reported with a new MMUPageSize2 item. This doesn't do anything about mTHP reporting, but even the basic smaps is not aware of it so far.

---
 Documentation/filesystems/proc.rst |  2 +-
 fs/proc/task_mmu.c                 | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
Documentation/filesystems/proc.rst +1 -1
index 8256e857e2d7..7c776046d15a 100644
@@ -483,7 +483,7 @@ entries; the page size used by the MMU when backing a VMA (in most cases,
 the same as KernelPageSize); the amount of the mapping that is currently
 resident in RAM (RSS); the process's proportional share of this mapping
 (PSS); and the number of clean and dirty shared and private pages in the
-mapping.
+mapping. If the mapping has multiple page size there might be a MMUPageSize2.
 
 The "proportional set size" (PSS) of a process is the count of pages it has
 in memory, where each page is divided by the number of processes sharing it.
fs/proc/task_mmu.c +13 -1
index 26188a4ad1ab..9123e59dcf4c 100644
@@ -1377,7 +1377,19 @@ static int show_smap(struct seq_file *m, void *v)
 
 	SEQ_PUT_DEC("Size:           ", vma->vm_end - vma->vm_start);
 	SEQ_PUT_DEC(" kB\nKernelPageSize: ", vma_kernel_pagesize(vma));
-	SEQ_PUT_DEC(" kB\nMMUPageSize:    ", vma_mmu_pagesize(vma));
+
+	/* Only THP? */
+	if (mss.shmem_thp + mss.file_thp + mss.anonymous_thp == mss.resident &&
+	    mss.resident > 0) {
+		SEQ_PUT_DEC(" kB\nMMUPageSize:    ", HPAGE_PMD_SIZE);
+	} else {
+		unsigned ps = vma_mmu_pagesize(vma);
+		/* Will need adjustments when more THP page sizes are added. */
+		SEQ_PUT_DEC(" kB\nMMUPageSize:    ", ps);
+		if (mss.shmem_thp + mss.file_thp + mss.anonymous_thp > 0 &&
+		    ps != HPAGE_PMD_SIZE)
+			SEQ_PUT_DEC(" kB\nMMUPageSize2:   ", HPAGE_PMD_SIZE);
+	}
 	seq_puts(m, " kB\n");
 
 	__show_smap(m, &mss, false);
Signature · 1 line
2.52.0
#1 lore raw
Quoted 43 lines · Andi Kleen

Recently I wasted quite some time debugging why THP didn't work, when it was just smaps always reporting the base page size. It has separate counts for (non m) THP, but using them is not always obvious. For standard THP the page sizes can be actually derived from the existing counts, so do just do that. I left KernelPageSize alone.
The mixed page size case is reported with a new MMUPageSize2 item. This doesn't do anything about mTHP reporting, but even the basic smaps is not aware of it so far.

---
  Documentation/filesystems/proc.rst |  2 +-
  fs/proc/task_mmu.c                 | 14 +++++++++++++-
  2 files changed, 14 insertions(+), 2 deletions(-)
Documentation/filesystems/proc.rst +1 -1
index 8256e857e2d7..7c776046d15a 100644
@@ -483,7 +483,7 @@ entries; the page size used by the MMU when backing a VMA (in most cases,
  the same as KernelPageSize); the amount of the mapping that is currently
  resident in RAM (RSS); the process's proportional share of this mapping
  (PSS); and the number of clean and dirty shared and private pages in the
-mapping.
+mapping. If the mapping has multiple page size there might be a MMUPageSize2.
 
  The "proportional set size" (PSS) of a process is the count of pages it has
  in memory, where each page is divided by the number of processes sharing it.
fs/proc/task_mmu.c +6 -1
index 26188a4ad1ab..9123e59dcf4c 100644
@@ -1377,7 +1377,19 @@ static int show_smap(struct seq_file *m, void *v)
 
  	SEQ_PUT_DEC("Size:           ", vma->vm_end - vma->vm_start);
  	SEQ_PUT_DEC(" kB\nKernelPageSize: ", vma_kernel_pagesize(vma));
-	SEQ_PUT_DEC(" kB\nMMUPageSize:    ", vma_mmu_pagesize(vma));
+
+	/* Only THP? */
+	if (mss.shmem_thp + mss.file_thp + mss.anonymous_thp == mss.resident &&
+	    mss.resident > 0) {
+		SEQ_PUT_DEC(" kB\nMMUPageSize:    ", HPAGE_PMD_SIZE);
+	} else {

fs/proc/task_mmu.c static int show_smap(struct seq_file *m, void *v) · line 1395

Quoted 10 lines
fs/proc/task_mmu.c +7 -0
+		unsigned ps = vma_mmu_pagesize(vma);
+		/* Will need adjustments when more THP page sizes are added. */
+		SEQ_PUT_DEC(" kB\nMMUPageSize:    ", ps);
+		if (mss.shmem_thp + mss.file_thp + mss.anonymous_thp > 0 &&
+		    ps != HPAGE_PMD_SIZE)
+			SEQ_PUT_DEC(" kB\nMMUPageSize2:   ", HPAGE_PMD_SIZE);
+	}
  	seq_puts(m, " kB\n");
 
  	__show_smap(m, &mss, false);

We have AnonHugePages:, ShmemPmdMapped: and FilePmdMapped: that tell you exactly what you want to know.

Especially the mixed thing is just nasty.

Once we go into cont-pte territory (or automatic pte coalescing by hardware) it all gets confusing.

Sorry, NAK.

Signature · 3 lines
Cheers,

David
author
#2 lore raw
Quoted 2 lines

We have AnonHugePages:, ShmemPmdMapped: and FilePmdMapped: that tell you exactly what you want to know.

.... if you know about it. I personally wasted a lot of time on it because we trusted a lie.

Quoted 5 lines

Especially the mixed thing is just nasty.

Once we go into cont-pte territory (or automatic pte coalescing by hardware) it all gets confusing.

In this case it can be extended to more.

Quoted 2 lines

Sorry, NAK.

Okay then just remove the page size if it's fictional outside hugetlb anyways?

I can send that patch too, but it would seem inferior.

-Andi

#3 lore raw
Quoted 5 lines · Andi Kleen
Quoted 2 lines

We have AnonHugePages:, ShmemPmdMapped: and FilePmdMapped: that tell you exactly what you want to know.

.... if you know about it. I personally wasted a lot of time on it because we trusted a lie.

It is confusing, I agree. I don't know why we added it in the first place.

Quoted 7 lines
Quoted 6 lines

Especially the mixed thing is just nasty.

Once we go into cont-pte territory (or automatic pte coalescing by hardware) it all gets confusing.

Quoted 6 lines

In this case it can be extended to more.

Quoted 2 lines

Sorry, NAK.

Okay then just remove the page size if it's fictional outside hugetlb anyways?

I'm sure that would break some tooling.

Signature · 3 lines
Cheers,

David
Reviewed-by on v1 1/1
#4 lore raw
In reply to Andi Kleen
Quoted 43 lines · Andi Kleen

Recently I wasted quite some time debugging why THP didn't work, when it was just smaps always reporting the base page size. It has separate counts for (non m) THP, but using them is not always obvious. For standard THP the page sizes can be actually derived from the existing counts, so do just do that. I left KernelPageSize alone.
The mixed page size case is reported with a new MMUPageSize2 item. This doesn't do anything about mTHP reporting, but even the basic smaps is not aware of it so far.

---
  Documentation/filesystems/proc.rst |  2 +-
  fs/proc/task_mmu.c                 | 14 +++++++++++++-
  2 files changed, 14 insertions(+), 2 deletions(-)
Documentation/filesystems/proc.rst +1 -1
index 8256e857e2d7..7c776046d15a 100644
@@ -483,7 +483,7 @@ entries; the page size used by the MMU when backing a VMA (in most cases,
  the same as KernelPageSize); the amount of the mapping that is currently
  resident in RAM (RSS); the process's proportional share of this mapping
  (PSS); and the number of clean and dirty shared and private pages in the
-mapping.
+mapping. If the mapping has multiple page size there might be a MMUPageSize2.
 
  The "proportional set size" (PSS) of a process is the count of pages it has
  in memory, where each page is divided by the number of processes sharing it.
fs/proc/task_mmu.c +6 -1
index 26188a4ad1ab..9123e59dcf4c 100644
@@ -1377,7 +1377,19 @@ static int show_smap(struct seq_file *m, void *v)
 
  	SEQ_PUT_DEC("Size:           ", vma->vm_end - vma->vm_start);
  	SEQ_PUT_DEC(" kB\nKernelPageSize: ", vma_kernel_pagesize(vma));
-	SEQ_PUT_DEC(" kB\nMMUPageSize:    ", vma_mmu_pagesize(vma));
+
+	/* Only THP? */
+	if (mss.shmem_thp + mss.file_thp + mss.anonymous_thp == mss.resident &&
+	    mss.resident > 0) {
+		SEQ_PUT_DEC(" kB\nMMUPageSize:    ", HPAGE_PMD_SIZE);
+	} else {

fs/proc/task_mmu.c static int show_smap(struct seq_file *m, void *v) · line 1395

Quoted 10 lines
fs/proc/task_mmu.c +7 -0
+		unsigned ps = vma_mmu_pagesize(vma);
+		/* Will need adjustments when more THP page sizes are added. */
+		SEQ_PUT_DEC(" kB\nMMUPageSize:    ", ps);
+		if (mss.shmem_thp + mss.file_thp + mss.anonymous_thp > 0 &&
+		    ps != HPAGE_PMD_SIZE)
+			SEQ_PUT_DEC(" kB\nMMUPageSize2:   ", HPAGE_PMD_SIZE);
+	}
  	seq_puts(m, " kB\n");
 
  	__show_smap(m, &mss, false);

Looks good to me.
While you're at this, maybe you could remove the redundant entries in the documentation?

    452     Size:               1084 kB
    453     KernelPageSize:        4 kB
    454     MMUPageSize:           4 kB
    455     Rss:                 892 kB
    456     Pss:                 374 kB
[..]
    472     KernelPageSize:        4 kB	<--
    473     MMUPageSize:           4 kB	<--

thanks,
-jane