diff mbox series

smaps: count large pages smaller than PMD size to anonymous_thp

Message ID 20241203134949.2588947-1-haowenchao22@gmail.com (mailing list archive)
State New
Headers show
Series smaps: count large pages smaller than PMD size to anonymous_thp | expand

Commit Message

Wenchao Hao Dec. 3, 2024, 1:49 p.m. UTC
Currently, /proc/xxx/smaps reports the size of anonymous huge pages for
each VMA, but it does not include large pages smaller than PMD size.

This patch adds the statistics of anonymous huge pages allocated by
mTHP which is smaller than PMD size to AnonHugePages field in smaps.

Signed-off-by: Wenchao Hao <haowenchao22@gmail.com>
---
 fs/proc/task_mmu.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

David Hildenbrand Dec. 3, 2024, 2:17 p.m. UTC | #1
On 03.12.24 14:49, Wenchao Hao wrote:
> Currently, /proc/xxx/smaps reports the size of anonymous huge pages for
> each VMA, but it does not include large pages smaller than PMD size.
> 
> This patch adds the statistics of anonymous huge pages allocated by
> mTHP which is smaller than PMD size to AnonHugePages field in smaps.
> 
> Signed-off-by: Wenchao Hao <haowenchao22@gmail.com>
> ---
>   fs/proc/task_mmu.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index 38a5a3e9cba2..b655011627d8 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -717,6 +717,12 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
>   		if (!folio_test_swapbacked(folio) && !dirty &&
>   		    !folio_test_dirty(folio))
>   			mss->lazyfree += size;
> +
> +		/*
> +		 * Count large pages smaller than PMD size to anonymous_thp
> +		 */
> +		if (!compound && PageHead(page) && folio_order(folio))
> +			mss->anonymous_thp += folio_size(folio);
>   	}
>   
>   	if (folio_test_ksm(folio))


I think we decided to leave this (and /proc/meminfo) be one of the last
interfaces where this is only concerned with PMD-sized ones:

Documentation/admin-guide/mm/transhuge.rst:

The number of PMD-sized anonymous transparent huge pages currently used by the
system is available by reading the AnonHugePages field in ``/proc/meminfo``.
To identify what applications are using PMD-sized anonymous transparent huge
pages, it is necessary to read ``/proc/PID/smaps`` and count the AnonHugePages
fields for each mapping. (Note that AnonHugePages only applies to traditional
PMD-sized THP for historical reasons and should have been called
AnonHugePmdMapped).
Ryan Roberts Dec. 3, 2024, 2:42 p.m. UTC | #2
On 03/12/2024 14:17, David Hildenbrand wrote:
> On 03.12.24 14:49, Wenchao Hao wrote:
>> Currently, /proc/xxx/smaps reports the size of anonymous huge pages for
>> each VMA, but it does not include large pages smaller than PMD size.
>>
>> This patch adds the statistics of anonymous huge pages allocated by
>> mTHP which is smaller than PMD size to AnonHugePages field in smaps.
>>
>> Signed-off-by: Wenchao Hao <haowenchao22@gmail.com>
>> ---
>>   fs/proc/task_mmu.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
>> index 38a5a3e9cba2..b655011627d8 100644
>> --- a/fs/proc/task_mmu.c
>> +++ b/fs/proc/task_mmu.c
>> @@ -717,6 +717,12 @@ static void smaps_account(struct mem_size_stats *mss,
>> struct page *page,
>>           if (!folio_test_swapbacked(folio) && !dirty &&
>>               !folio_test_dirty(folio))
>>               mss->lazyfree += size;
>> +
>> +        /*
>> +         * Count large pages smaller than PMD size to anonymous_thp
>> +         */
>> +        if (!compound && PageHead(page) && folio_order(folio))
>> +            mss->anonymous_thp += folio_size(folio);
>>       }
>>         if (folio_test_ksm(folio))
> 
> 
> I think we decided to leave this (and /proc/meminfo) be one of the last
> interfaces where this is only concerned with PMD-sized ones:
> 
> Documentation/admin-guide/mm/transhuge.rst:
> 
> The number of PMD-sized anonymous transparent huge pages currently used by the
> system is available by reading the AnonHugePages field in ``/proc/meminfo``.
> To identify what applications are using PMD-sized anonymous transparent huge
> pages, it is necessary to read ``/proc/PID/smaps`` and count the AnonHugePages
> fields for each mapping. (Note that AnonHugePages only applies to traditional
> PMD-sized THP for historical reasons and should have been called
> AnonHugePmdMapped).
> 

Agreed. If you need per-process metrics for mTHP, we have a python script at
tools/mm/thpmaps which does a fairly good job of parsing pagemap. --help gives
you all the options.
diff mbox series

Patch

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 38a5a3e9cba2..b655011627d8 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -717,6 +717,12 @@  static void smaps_account(struct mem_size_stats *mss, struct page *page,
 		if (!folio_test_swapbacked(folio) && !dirty &&
 		    !folio_test_dirty(folio))
 			mss->lazyfree += size;
+
+		/*
+		 * Count large pages smaller than PMD size to anonymous_thp
+		 */
+		if (!compound && PageHead(page) && folio_order(folio))
+			mss->anonymous_thp += folio_size(folio);
 	}
 
 	if (folio_test_ksm(folio))