[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <edfc9b39-52d8-4c4c-8c81-53dd5b35ba6e@gmail.com>
Date: Tue, 17 Dec 2024 00:03:03 +0800
From: Wenchao Hao <haowenchao22@...il.com>
To: Barry Song <21cnbao@...il.com>, Lance Yang <ioworker0@...il.com>
Cc: David Hildenbrand <david@...hat.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Matthew Wilcox <willy@...radead.org>, Oscar Salvador <osalvador@...e.de>,
Muhammad Usama Anjum <usama.anjum@...labora.com>,
Andrii Nakryiko <andrii@...nel.org>, Ryan Roberts <ryan.roberts@....com>,
Peter Xu <peterx@...hat.com>, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH] smaps: count large pages smaller than PMD size to
anonymous_thp
On 2024/12/8 14:06, Barry Song wrote:
> On Fri, Dec 6, 2024 at 7:16 PM Lance Yang <ioworker0@...il.com> wrote:
>>
>> On Tue, Dec 3, 2024 at 10:17 PM David Hildenbrand <david@...hat.com> 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@...il.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).
>>
>> Yeah, I think we need to keep AnonHugePages unchanged within these interfaces
>> due to historical reasons ;)
>>
>> Perhaps, there might be another way to count all THP allocated for each process.
>
> My point is that counting the THP allocations per process doesn't seem
> as important
> when compared to the overall system's status. We already have
> interfaces to track
> the following:
>
> * The number of mTHPs allocated or fallback events;
> * The total number of anonymous mTHP folios in the system.
> * The total number of partially unmapped mTHP folios in the system.
>
> To me, knowing the details for each process doesn’t seem particularly
> critical for
> profiling. To be honest, I don't see a need for this at all, except perhaps for
> debugging to verify if mTHP is present.
>
> If feasible, we could explore converting Ryan's Python script into a native
> C program. I believe this would be more than sufficient for embedded systems
> and Android.
>
Hi Barry,
Yes, the reason I want to use smap to collect this data is that I wasn’t familiar
with this tool before. When analyzing the performance impact of enabling mTHP, I want
to understand the actual memory usage of the process being analyzed, including the
proportions of anonymous pages, swap pages, large pages and so on.
This helps determine whether the test results align with expectations.
Indeed, the main purpose of adding this is to make debugging more convenient.
For now, I’ll perform the analysis and testing on the Fedora distribution, so I
can use the pyrhon tool directly.
If it becomes unavoidable to run this tool on embedded devices in the future, I may
take the time to create a simplified version of the analysis tool in C based on this
script.
>>
>> Thanks,
>> Lance
>>
>>
>>>
>>>
>>>
>>> --
>>> Cheers,
>>>
>>> David / dhildenb
>
> Thanks
> Barry
Powered by blists - more mailing lists