Re: [RFC PATCH v1] tools/mm: Add thpmaps script to dump THP usage info

Ryan Roberts
2024-01-03T09:35:32Z

On 03/01/2024 09:16, Barry Song wrote:
> On Wed, Jan 3, 2024 at 9:25 PM Ryan Roberts <ryan.roberts@arm.com> wrote:
>>
>> On 03/01/2024 08:07, William Kucharski wrote:
>>>
>>>> On Jan 2, 2024, at 23:44, Barry Song <21cnbao@gmail.com> wrote:
>>>>
>>>> Hi Ryan,
>>>>
>>>> I ran a couple of test cases with different parameters, it seems to
>>>> work correctly.
>>>> just i don't understand the below, what is the meaning of 000000ce at
>>>> the beginning of
>>>> each line?
>>>
>>> It's the pid; 0xce is the specified pid, 206.
>>
>> Yes indeed. I added the pid to the front for the case where you are using
>> --cgroup without --summary; in that case, each vma will be printed for each pid
>> in the cgroup and it seemed sensible to be able to see which pid each vma
>> belonged to.
>
> I don't understand why we have to add the pid before each line as this tool
> already has pid in the parameter :-)

The reason is that it is also possible to invoke the tool with --cgroup instead
of --pid. In this case, the tool will iterate over all the pids in the cgroup so
(when --summary is not specified) having the pid associated with each vma is useful.

I could change it to conditionally output the pid only when --cgroup is specified?

> this seems like duplicated information
> to me. but it doesn't matter too much as this tool is really nice though it is
> not so easy to deploy on Android.

Hmm. I've seen tutorials where people have Python running under Android, but I
agree its not zero effort. Perhaps it would be better in C. Unfortuantely, I
can't commit to doing a port at this point.

>
> Please feel free to add,
>
> Tested-by: Barry Song <v-songbaohua@oppo.com>

Thanks!

>
>>
>>>
>>> Perhaps the pid should be printed in decimal?
>>
>> I thought about printing in decimal, but every other value in the vma is in hex
>> without a leading "0x" (I'm trying to follow the smaps convention). So I thought
>> it could be more confusing in decimal.
>>
>> I'm happy to change it to decimal if that's the preference though? Although I'd
>> like to continue to present it in a fixed width field, padded with 0s on the
>> left so that everything lines up.
>>
>>>
>>> -- William Kucharski
>>>
>>>> /thpmaps --pid 206 --cont 64K
>>>> 000000ce 0000aaaadbb20000-0000aaaadbb21000 r-xp 00000000 fe:00
>>>> 00426969 /root/a.out
>>>> 000000ce 0000aaaadbb3f000-0000aaaadbb40000 r--p 0000f000 fe:00
>>>> 00426969 /root/a.out
>>>> 000000ce 0000aaaadbb40000-0000aaaadbb41000 rw-p 00010000 fe:00
>>>> 00426969 /root/a.out
>>>> 000000ce 0000ffff702c0000-0000ffffb02c0000 rw-p 00000000 00:00 00000000
>>>> anon-thp-aligned-64kB: 473920 kB (100%)
>>>> anon-cont-aligned-64kB: 473920 kB (100%)
>>>> 000000ce 0000ffffb02c0000-0000ffffb044c000 r-xp 00000000 fe:00
>>>> 00395429 /usr/lib/aarch64-linux-gnu/libc.so.6
>>>> 000000ce 0000ffffb044c000-0000ffffb045d000 ---p 0018c000 fe:00
>>>> 00395429 /usr/lib/aarch64-linux-gnu/libc.so.6
>>>> 000000ce 0000ffffb045d000-0000ffffb0460000 r--p 0018d000 fe:00
>>>> 00395429 /usr/lib/aarch64-linux-gnu/libc.so.6
>>>> 000000ce 0000ffffb0460000-0000ffffb0462000 rw-p 00190000 fe:00
>>>> 00395429 /usr/lib/aarch64-linux-gnu/libc.so.6
>>>> 000000ce 0000ffffb0462000-0000ffffb046f000 rw-p 00000000 00:00 00000000
>>>> 000000ce 0000ffffb0477000-0000ffffb049d000 r-xp 00000000 fe:00
>>>> 00393893 /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
>>>> 000000ce 0000ffffb04b0000-0000ffffb04b2000 rw-p 00000000 00:00 00000000
>>>> 000000ce 0000ffffb04b2000-0000ffffb04b4000 r--p 00000000 00:00 00000000 [vvar]
>>>> 000000ce 0000ffffb04b4000-0000ffffb04b5000 r-xp 00000000 00:00 00000000 [vdso]
>>>> 000000ce 0000ffffb04b5000-0000ffffb04b7000 r--p 0002e000 fe:00
>>>> 00393893 /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
>>>> 000000ce 0000ffffb04b7000-0000ffffb04b9000 rw-p 00030000 fe:00
>>>> 00393893 /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
>>>> 000000ce 0000ffffdaba4000-0000ffffdabc5000 rw-p 00000000 00:00 00000000 [stack]
>>>
>
> Thanks
> Barry