From: Paul Eggert Date: Thu, 25 Jul 2024 06:32:24 +0000 (-0700) Subject: Fix process-attributes rss and pmem on GNU/Linux X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f333ea59de68fb8781b01b7ae28df96306ca74b5;p=emacs.git Fix process-attributes rss and pmem on GNU/Linux Problem reported by Rahguzar . * src/sysdep.c (system_process_attributes): [GNU_LINUX || CYGWIN || __ANDROID__]: When computing rss and pmem, don’t assume pagesize is 4096; it could be greater. (cherry picked from commit 42cdfe7f60ef7ae3bccb5b1e43349c3a6b54ac4a) --- diff --git a/src/sysdep.c b/src/sysdep.c index d916a695155..3955d796ca5 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -3548,6 +3548,7 @@ procfs_ttyname (int rdev) } # endif /* GNU_LINUX || __ANDROID__ */ +/* Total usable RAM in KiB. */ static uintmax_t procfs_get_total_memory (void) { @@ -3737,8 +3738,13 @@ system_process_attributes (Lisp_Object pid) attrs = Fcons (Fcons (Qnice, make_fixnum (niceness)), attrs); attrs = Fcons (Fcons (Qthcount, INT_TO_INTEGER (thcount)), attrs); attrs = Fcons (Fcons (Qvsize, INT_TO_INTEGER (vsize / 1024)), attrs); - attrs = Fcons (Fcons (Qrss, INT_TO_INTEGER (4 * rss)), attrs); - pmem = 4.0 * 100 * rss / procfs_get_total_memory (); + + /* RSS in KiB. */ + uintmax_t rssk = rss; + rssk *= getpagesize () >> 10; + + attrs = Fcons (Fcons (Qrss, INT_TO_INTEGER (rssk)), attrs); + pmem = 100.0 * rssk / procfs_get_total_memory (); if (pmem > 100) pmem = 100; attrs = Fcons (Fcons (Qpmem, make_float (pmem)), attrs);