Subject: bug#72278: 29.4; Proced reports incorrect results with 16KB page size

From: Rahguzar <[email-masked]>
Date: Wed, 24 Jul 2024 22:40:53 +0200

Hi Stefan,

Stefan Kangas <[email-masked]> writes:

> Rahguzar via "Bug reports for GNU Emacs, the Swiss army knife of text
> editors" <[email-masked]> writes:
>
>> Dear Emacs Maintainers,
>>
>> I am using GNU/Linux on an Apple M2 processor using the Asahi Linux
>> project [1]. They provide a kernel with 16KB page size [2]. This causes proced
>> to show incorrect values for percentage memory (other memory related
>> attributes might also be affected). E.g. comparing with top I see that
>> value reported by proced is a quarter of that related by top.
>>
>> [1] https://asahilinux.org
>> [2] https://discussion.fedoraproject.org/t/switch-to-the-kernel-16k-variant/87711
>
> 1. What is the output of running this command?
>
>        grep MemTotal /proc/meminfo
>
>    Does that value seem right?  Does that file make sense in general?

The value and the file generally look correct to me.

> 2. Copy this to a buffer somewhere, put point after the last
>    parenthesis, and press `C-u C-x C-e':
>
>         (pp (mapcar #'process-attributes
>              (seq-take (list-system-processes) 5)))
>
>     Please post the result back here.
>
>     Could you also tell us which values in the resulting list are wrong
>     (a.k.a. "different from top")?

The processes that end up in that list have memory footprint so small
that top ends up showing percentage memory as 0. I modified the snippet
to obtain 5 processes started by firefox:

(((args . "/usr/lib64/firefox/firefox")
  (pmem . 3.018895533065192)
  (rss . 727876)
  (vsize . 17513856)
  (thcount . 105)
  (nice . 0)
  (pri . 20)
  (pcpu . 1.0718871382569872)
  (etime 12 34487 450000 0)
  (start 26260 56544 260000 0)
  (ctime 0 8651 310000 0)
  (cstime 0 393 900000 0)
  (cutime 0 8257 410000 0)
  (time 0 8799 330000 0)
  (stime 0 2500 340000 0)
  (utime 0 6298 990000 0)
  (cmajflt . 83)
  (cminflt . 10288762)
  (majflt . 1571)
  (minflt . 20999882)
  (tpgid . -1)
  (ttname . "")
  (sess . 1239)
  (pgrp . 1239)
  (ppid . 1)
  (state . "S")
  (comm . "firefox")
  (group . "azeem")
  (egid . 1000)
  (user . "azeem")
  (euid . 1000))
 ((args . "/usr/lib64/firefox/firefox -contentproc -parentBuildID 20240712194222 -prefsLen 42067 -prefMapSize 262227 -appDir /usr/lib64/firefox/browser {6dc0e492-94e8-413e-83e0-ac2b970bde23} 1241 socket")
  (pmem . 0.05839737689600688)
  (rss . 14080)
  (vsize . 576016)
  (thcount . 6)
  (nice . 0)
  (pri . 20)
  (pcpu . 5.359847034838214e-05)
  (etime 12 34486 950000 0)
  (start 26260 56544 770000 0)
  (ctime 0 0 0 0)
  (cstime 0 0 0 0)
  (cutime 0 0 0 0)
  (time 0 0 440000 0)
  (stime 0 0 180000 0)
  (utime 0 0 260000 0)
  (cmajflt . 0)
  (cminflt . 0)
  (majflt . 9)
  (minflt . 1669)
  (tpgid . -1)
  (ttname . "")
  (sess . 1239)
  (pgrp . 1239)
  (ppid . 1241)
  (state . "S")
  (comm . "Socket Process")
  (group . "azeem")
  (egid . 1000)
  (user . "azeem")
  (euid . 1000))
 ((args . "/usr/lib64/firefox/firefox -contentproc -childID 1 -isForBrowser -prefsLen 42067 -prefMapSize 262227 -jsInitLen 234780 -parentBuildID 20240712194222 -greomni /usr/lib64/firefox/omni.ja -appomni /usr/lib64/firefox/browser/omni.ja -appDir /usr/lib64/firefox/browser {2280679f-70cf-4f2d-887a-33665cc52830} 1241 tab")
  (pmem . 0.9880603908509892)
  (rss . 238228)
  (vsize . 22750640)
  (thcount . 27)
  (nice . 0)
  (pri . 20)
  (pcpu . 0.13563582493620777)
  (etime 12 34486 810000 0)
  (start 26260 56544 920000 0)
  (ctime 0 0 0 0)
  (cstime 0 0 0 0)
  (cutime 0 0 0 0)
  (time 0 1113 460000 0)
  (stime 0 75 970000 0)
  (utime 0 1037 490000 0)
  (cmajflt . 0)
  (cminflt . 0)
  (majflt . 0)
  (minflt . 1710810)
  (tpgid . -1)
  (ttname . "")
  (sess . 1239)
  (pgrp . 1239)
  (ppid . 1241)
  (state . "R")
  (comm . "WebExtensions")
  (group . "azeem")
  (egid . 1000)
  (user . "azeem")
  (euid . 1000))
 ((args . "/usr/lib64/firefox/firefox -contentproc -childID 2 -isForBrowser -prefsLen 43016 -prefMapSize 262227 -jsInitLen 234780 -parentBuildID 20240712194222 -greomni /usr/lib64/firefox/omni.ja -appomni /usr/lib64/firefox/browser/omni.ja -appDir /usr/lib64/firefox/browser {c7fd5dcc-7f18-4677-8cd3-ff49efab3e75} 1241 tab")
  (pmem . 0.10299173743477577)
  (rss . 24832)
  (vsize . 4366000)
  (thcount . 28)
  (nice . 0)
  (pri . 20)
  (pcpu . 0.0032487989036966473)
  (etime 12 34486 770000 0)
  (start 26260 56544 960000 0)
  (ctime 0 0 0 0)
  (cstime 0 0 0 0)
  (cutime 0 0 0 0)
  (time 0 26 670000 0)
  (stime 0 6 580000 0)
  (utime 0 20 90000 0)
  (cmajflt . 0)
  (cminflt . 0)
  (majflt . 0)
  (minflt . 2708)
  (tpgid . -1)
  (ttname . "")
  (sess . 1239)
  (pgrp . 1239)
  (ppid . 1241)
  (state . "S")
  (comm . "Privileged Cont")
  (group . "azeem")
  (egid . 1000)
  (user . "azeem")
  (euid . 1000))
 ((args . "/usr/lib64/firefox/firefox -contentproc -childID 3 -isForBrowser -prefsLen 29688 -prefMapSize 262227 -jsInitLen 234780 -parentBuildID 20240712194222 -greomni /usr/lib64/firefox/omni.ja -appomni /usr/lib64/firefox/browser/omni.ja -appDir /usr/lib64/firefox/browser {77722f8d-f95f-4796-9765-00d7017c5796} 1241 tab")
  (pmem . 1.0487306202000508)
  (rss . 252856)
  (vsize . 6381408)
  (thcount . 31)
  (nice . 0)
  (pri . 20)
  (pcpu . 0.48562684148940605)
  (etime 12 34486 380000 0)
  (start 26260 56545 350000 0)
  (ctime 0 0 0 0)
  (cstime 0 0 0 0)
  (cutime 0 0 0 0)
  (time 0 3986 600000 0)
  (stime 0 651 720000 0)
  (utime 0 3334 880000 0)
  (cmajflt . 0)
  (cminflt . 0)
  (majflt . 5)
  (minflt . 1335797)
  (tpgid . -1)
  (ttname . "")
  (sess . 1239)
  (pgrp . 1239)
  (ppid . 1241)
  (state . "S")
  (comm . "Isolated Web Co")
  (group . "azeem")
  (egid . 1000)
  (user . "azeem")
  (euid . 1000)))

The percentage memory values in top for these processes are 12.1 0.2 4.0
0.4 and 4.2 so 4 times those returned by proced.

> Thanks in advance.

>From discussion with Eli at the help-gnu-emacs thread I think there is
some hard coded assumption about 4KB page size in sysdep.c. E.g. here at
line 3741 

	  pmem = 4.0 * 100 * rss / procfs_get_total_memory ();

Thanks,
Rahguzar