This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

memory reported in /proc/pid/status is wrongly scaled

While playing with reading process memory usage in Linux and cygwin, I
found that cygwin reports too large values in /proc/self/status (in 2.10.0
and earlier).
Whenever I was allocating a few kB in my test program, the VmSize line in
/proc/self/status was growing several times faster.

Small bash script to show the issue:
vmsizesplit=($(grep VmSize /proc/$pid/status))
echo Initial memory reported in status: $vmsize1 kB
echo Allocating a 1000 kB string (bash can use more memory)
eat=$(printf '%1024000s')
vmsizesplit=($(grep VmSize /proc/$pid/status))
echo Current memory reported in status: $vmsize2 kB
echo Difference is $[$vmsize2-$vmsize1] kB

Running this in cygwin on my laptop I get:
Initial memory reported in status: 84928 kB
Allocating a 1000 kB string (bash can use more memory)
Current memory reported in status: 106880 kB
Difference is 21952 kB

While bash may use quite more than 1000 kb in this case, 22x times larger
doesn't seem right.

Checking source file, the
function format_process_status which writes the "status" proc file
retrieves memory usage via get_mem_values. Get_mem_values obtains that info
from NtQueryInformationProcess/PagefileUsage which is in bytes, then it
scales it to pages dividing by wincap.page_size:
1515: *vmsize = vmc.PagefileUsage / wincap.page_size ();

Then format_process_status scales it back, in theory to bytes, and shifts
it by 10 bits in order to print it out in kB:
1219:  unsigned page_size = wincap.allocation_granularity ();
1220:  vmsize *= page_size;

The first observation is that scaling and unscaling are using different
factors, causing the issue. Same for the other memory amounts reported in
the "status" file (VmLck, VmRSS, etc....). Memory reported in the "stat"
file seems ok, and regarding the "statm" file, I'm not really sure (since
I'm not sure about what the correct page size should be in cygwin).
A second observation is that the same struct that contains PagefileUsage
also contains PeakPagefileUsage, so it would be very easy to also add the
VmPeak line to the "status" file (as in Linux).


Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]