[pve-devel] [PATCH qemu-server v4 2/4] vmstatus: add memhost for host view of vm mem consumption

Lukas Wagner l.wagner at proxmox.com
Thu Jul 31 08:51:14 CEST 2025


On Thu Jul 31, 2025 at 5:37 AM CEST, Thomas Lamprecht wrote:
> Am 29.07.25 um 14:50 schrieb Lukas Wagner:
>> On Sat Jul 26, 2025 at 3:06 AM CEST, Aaron Lauterer wrote:
>>> +        my $fh = IO::File->new("/sys/fs/cgroup/qemu.slice/${vmid}.scope/cgroup.procs", "r");
>>> +        if ($fh) {
>>> +            while (my $childPid = <$fh>) {
>>> +                chomp($childPid);
>> 
>> nit: should be snake_case
>
> +1 and go into it's own method, I moved it in a follow-up
>
>> 
>>> +                open(my $SMAPS_FH, '<', "/proc/$childPid/smaps_rollup")
>>> +                    or die "failed to open PSS memory-stat from process - $!\n";
>>> +
>>> +                while (my $line = <$SMAPS_FH>) {
>>> +                    if ($line =~ m/^Pss:\s+([0-9]+) kB$/) {
>>> +                        $d->{memhost} = $d->{memhost} + int($1) * 1024;
>> 
>> Why do you sum up $d->{memhost} with the thing you just read from /proc?
>> As far as I can tell memhost should always be zero at this point....
>
> it's a += and there are two loops, basically it sums up all Pss stats for
> every process in a cgroup to get a somewhat correct total memory consumption
> of that cgroup.

I guess I must have missed that second loop, my bad. Thanks for the
clarification!
>
>> 
>> 
>>> +                        last;
>> 
>> ... and also you break here from the loop, so even if there were two Pss
>> lines, you wouldn't add them up.
>> 
>> Am I missing something? :)
>
> This is smaps_rollup, not smaps, i.e. the former is a a summed up variant
> of all separate mappings from the latter, so there is always only one Pss
> entry in there.
>
> See (need to search twice for "smaps_rollup", there is no better link anchor
> in the vicinity):
>
> https://docs.kernel.org/filesystems/proc.html#process-specific-subdirectories
>

Thanks, I'll have a look!





More information about the pve-devel mailing list