Possible working method to get actual process size on Linux

Stefan Reich stefan.reich.maker.of.eye at googlemail.com
Thu Oct 3 17:01:58 UTC 2019


So basically, I need to port ps_mem.py to Java. I really can't ship Python
code.

On Thu, Oct 3, 2019, 16:20 Stefan Reich <
stefan.reich.maker.of.eye at googlemail.com> wrote:

> Yes, that sounds like a cleaner way. I do see these fields even on my
> oldest kernel.
>
> Let me guess, smem probably reads from /smaps too...
>
> On Thu, 3 Oct 2019 at 16:15, Florian Weimer <fw at deneb.enyo.de> wrote:
>
>> * Stefan Reich:
>>
>> > OK, here is the code:
>> > https://github.com/stefan-reich/LinuxProcessSizeDetector
>> >
>> > Can this be linked somewhere? I believe it to be useful. Seems to work
>> on
>> > the machines I tested it on, even though there is mild guesswork
>> involved.
>>
>> With a recent-enough kernel, you will see this:
>>
>> $ grep ^[^A-Z] /proc/21679/smaps | grep memfd | sort -k3
>> 40000000000-40001000000 rw-s 00000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> 80000000000-80001000000 rw-s 00000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> 100000000000-100001000000 rw-s 00000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> 7fffe000000-80000000000 rw-s 01000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> bfffe000000-c0000000000 rw-s 01000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> 13fffe000000-140000000000 rw-s 01000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> 40001000000-40002000000 rw-s 03000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> 80001000000-80002000000 rw-s 03000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> 100001000000-100002000000 rw-s 03000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> 7fffc000000-7fffe000000 rw-s 04000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> bfffc000000-bfffe000000 rw-s 04000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> 13fffc000000-13fffe000000 rw-s 04000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> 40002000000-4000ec00000 rw-s 06000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> 80002000000-8000ec00000 rw-s 06000000 00:05 253242
>>  /memfd:java_heap (deleted)
>> 100002000000-10000ec00000 rw-s 06000000 00:05 253242
>>  /memfd:java_heap (deleted)
>>
>> That is, you can recover the information which mapping aliases which
>> other mapping by looking at device/inode combination (column 4 and 5)
>> and the mapping offset (column 3).
>>
>> I believe there is a tool called smem which does exactly that.
>>
>
>
> --
> Stefan Reich
> BotCompany.de // Java-based operating systems
>


More information about the zgc-dev mailing list