From f333ea59de68fb8781b01b7ae28df96306ca74b5 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 24 Jul 2024 23:32:24 -0700 Subject: [PATCH] Fix process-attributes rss and pmem on GNU/Linux MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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) --- src/sysdep.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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); -- 2.39.2