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

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 25 Jul 2024 06:39:02 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
72278: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=72278
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#72278: 29.4; Proced reports incorrect results with 16KB page size
From: Paul Eggert <[email-masked]>
To: Eli Zaretskii <[email-masked]>
Cc: Rahguzar <[email-masked]>, [email-masked]
Date: Wed, 24 Jul 2024 23:38:34 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

On 2024-07-24 22:06, Eli Zaretskii wrote:
> Paul, it sounds like we need to multiply by getpagesize() instead of
> by a fixed value of 4?

Yes, that sounds right. I installed the attached patch into Emacs master 
on Savannah, and am boldly closing the bug as fixed. We can reopen it if 
I'm wrong.

Thanks, Rahguzar, for reporting the bug.

From 42cdfe7f60ef7ae3bccb5b1e43349c3a6b54ac4a Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
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=UTF-8
Content-Transfer-Encoding: 8bit

Problem reported by Rahguzar <https://bugs.gnu.org/72278>.
* 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.
---
 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.43.0

Subject: 29.4; Proced reports incorrect results with 16KB page size
From: Rahguzar <[email-masked]>
To: [email-masked]
Date: Wed, 24 Jul 2024 19:22:08 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

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

In GNU Emacs 29.4 (build 1, aarch64-redhat-linux-gnu, GTK+ Version
 3.24.42, cairo version 1.18.0) of 2024-07-08 built on
 c7db9ae0ee0641de8f7c6190b678dcb8
System Description: Fedora Linux Asahi Remix 40 (Forty)

Configured using:
 'configure --build=aarch64-redhat-linux-gnu
 --host=aarch64-redhat-linux-gnu --program-prefix=
 --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr
 --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc
 --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64
 --libexecdir=/usr/libexec --localstatedir=/var --runstatedir=/run
 --sharedstatedir=/var/lib --mandir=/usr/share/man
 --infodir=/usr/share/info --with-cairo --with-dbus --with-gif
 --with-gpm=no --with-harfbuzz --with-jpeg --with-json --with-modules
 --with-native-compilation=aot --with-pgtk --with-png --with-rsvg
 --with-sqlite3 --with-tiff --with-tree-sitter --with-webp --with-xpm
 --with-xwidgets build_alias=aarch64-redhat-linux-gnu
 host_alias=aarch64-redhat-linux-gnu CC=gcc 'CFLAGS=-DMAIL_USE_LOCKF -O2
 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches
 -pipe -Wall -Werror=format-security
 -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS
 -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong
 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1
 -mbranch-protection=standard -fasynchronous-unwind-tables
 -fstack-clash-protection -fno-omit-frame-pointer
 -mno-omit-leaf-frame-pointer ' LDFLAGS=-Wl,-z,relro
 PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig CXX=g++
 'CXXFLAGS=-O2 -flto=auto -ffat-lto-objects -fexceptions -g
 -grecord-gcc-switches -pipe -Wall -Werror=format-security
 -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS
 -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong
 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1
 -mbranch-protection=standard -fasynchronous-unwind-tables
 -fstack-clash-protection -fno-omit-frame-pointer
 -mno-omit-leaf-frame-pointer ''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY
PDUMPER PGTK PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM XWIDGETS GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: ELisp/l

Minor modes in effect:
  pdf-occur-global-minor-mode: t
  shell-dirtrack-mode: t
  undo-fu-session-mode: t
  highlight-quoted-mode: t
  corfu-history-mode: t
  corfu-popupinfo-mode: t
  corfu-mode: t
  evil-surround-mode: t
  server-mode: t
  outline-minor-mode: t
  dirvish-override-dired-mode: t
  satchel-mode: t
  nerd-icons-completion-mode: t
  marginalia-mode: t
  vertico-multiform-mode: t
  vertico-mode: t
  evil-goggles-mode: t
  anzu-mode: t
  evil-mode: t
  evil-local-mode: t
  recentf-mode: t
  savehist-mode: t
  electric-pair-mode: t
  save-place-mode: t
  override-global-mode: t
  flymake-mode: t
  pixel-scroll-precision-mode: t
  repeat-mode: t
  midnight-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  buffer-read-only: t
  size-indication-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  abbrev-mode: t
  view-mode: t

Load-path shadows:
/home/azeem/.local/state/emacs/elpaca/builds/transient/transient hides /usr/share/emacs/29.4/lisp/transient
/home/azeem/.local/state/emacs/elpaca/builds/ef-themes/theme-loaddefs hides /usr/share/emacs/29.4/lisp/theme-loaddefs
/home/azeem/.local/state/emacs/elpaca/builds/eww-hacks/shr hides /usr/share/emacs/29.4/lisp/net/shr
/home/azeem/.local/state/emacs/elpaca/builds/eww-hacks/eww hides /usr/share/emacs/29.4/lisp/net/eww

Features:
(shadow files-x emacsbug evil-nerd-commenter html-mode-expansions
sgml-mode evil-nerd-commenter-operator evil-nerd-commenter-sdk misearch
multi-isearch pdf-roll crm consult-info gnus-fun embark-org
embark-consult embark inspirehep-pdf companion-mode inspirehep reftex
reftex-loaddefs reftex-vars pdf-sync pdf-annot pdf-outline pdf-links
pdf-history pdf-occur tablist tablist-filter semantic/wisent/comp
semantic/wisent semantic/wisent/wisent semantic/util-modes semantic/util
semantic semantic/tag semantic/lex semantic/fw mode-local cedet
pdf-isearch pdf-misc pdf-tools pdf-view pdf-cache pdf-info tq pdf-util
pdf-macs password-store auth-source-pass with-editor shell consult-imenu
checkdoc vc-git vc-dispatcher package-lint-flymake package-lint
let-alist finder finder-inf lisp-mnt package url-handlers
vertico-directory oc-basic url-queue mm-url ol-rmail ol-mhe ol-irc
ol-info ol-gnus nnselect ol-docview doc-view ol-bibtex bibtex ol-bbdb
ol-w3m ol-doi org-link-doi descr-text mastodon-notifications smerge-mode
diff diff-mode link-hint ffap goto-addr avy jka-compr view helpful
cc-langs cc-vars cc-defs imenu trace edebug debug backtrace info-look
info f help-fns radix-tree elisp-refs s dash undo-fu-session
nerd-icons-corfu dabbrev delsel jit-spell ispell cape face-remap
mastodon-media image-mode exif mastodon-profile mastodon-tl url-http
url-gw url-cache url-auth mastodon-auth mastodon-client plstore mastodon
mastodon-search mastodon-toot facemenu mastodon-iso persist
mastodon-http request adaptive-wrap shr-color highlight-quoted
corfu-history corfu-popupinfo corfu evil-embrace embrace expand-region
text-mode-expansions the-org-mode-expansions org-element org-persist xdg
org-id org-refile avl-tree generator er-basic-expansions
expand-region-core expand-region-custom evil-surround qp sort smiley
gnus-cite mm-archive mail-extr textsec uni-scripts idna-mapping
ucs-normalize uni-confusable textsec-check gnus-async gnus-bcklg gnus-ml
disp-table nndraft nnmh vertico-repeat epa-file network-stream nsm
gnus-agent gnus-srvr gnus-score score-mode nnvirtual gnus-msg nntp
gnus-cache fabs consult server mu4e mu4e-org org ob ob-tangle ob-ref
ob-lob ob-table ob-exp org-macro org-src ob-comint org-pcomplete
pcomplete org-list org-footnote org-faces org-entities noutline outline
ob-emacs-lisp ob-core ob-eval org-cycle org-table ol org-fold
org-fold-core org-keys oc org-loaddefs find-func org-version org-compat
org-macs mu4e-notification notifications mu4e-main smtpmail mu4e-view
mu4e-mime-parts gnus-art mm-uu mml2015 mm-view mml-smime smime gnutls
dig gnus-sum gnus-group gnus-undo gnus-start gnus-dbus dbus gnus-cloud
nnimap nnmail mail-source utf7 nnoo parse-time iso8601 gnus-spec
gnus-int gnus-range gnus-win gnus cal-menu calendar cal-loaddefs
mu4e-headers mu4e-thread mu4e-actions mu4e-compose nnheader range
mu4e-search mu4e-lists mu4e-bookmarks mu4e-mark mu4e-message shr
pixel-fill kinsoku url-file svg xml dom browse-url flow-fill mule-util
hl-line mu4e-contacts mu4e-update mu4e-folders mu4e-context
mu4e-query-items mu4e-server mu4e-modeline mu4e-vars mu4e-helpers
mu4e-config mu4e-window ido message sendmail yank-media puny cus-start
dirvish transient format-spec autorevert filenotify dired dired-loaddefs
rfc822 mml mml-sec epa derived epg rfc6068 epg-config gnus-util
time-date mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047
rfc2045 mm-util ietf-drums mail-prsvr mailabbrev mail-utils gmm-utils
mailheader mu4e-obsolete usher satchel ibuf-ext ibuffer ibuffer-loaddefs
bookmark nerd-icons-completion nerd-icons nerd-icons-faces
nerd-icons-data nerd-icons-data-mdicon nerd-icons-data-flicon
nerd-icons-data-codicon nerd-icons-data-devicon nerd-icons-data-sucicon
nerd-icons-data-wicon nerd-icons-data-faicon nerd-icons-data-powerline
nerd-icons-data-octicon nerd-icons-data-pomicon nerd-icons-data-ipsicon
marginalia vertico-multiform vertico compat compat-30 evil-goggles pulse
color ef-spring-theme ef-themes pdf-loader evil-anzu anzu evil
evil-integration evil-maps evil-commands reveal evil-jumps
evil-command-window evil-types evil-search evil-ex evil-macros
evil-repeat evil-states evil-core comp comp-cstr cl-extra help-mode
advice evil-common rect evil-vars edmacro kmacro orderless
mastodon-autoloads request-autoloads persist-autoloads yeetube-autoloads
filechooser-autoloads wile-autoloads adaptive-wrap-autoloads
usher-autoloads undo-fu-session-autoloads ef-themes-autoloads
jit-spell-autoloads satchel-autoloads pdf-tools-autoloads
tablist-autoloads xr-autoloads link-hint-autoloads avy-autoloads
yaml-mode-autoloads markdown-mode-autoloads magit-autoloads
git-commit-autoloads magit-section-autoloads inspirehep-autoloads
consult-hoogle-autoloads haskell-mode-autoloads geiser-guile-autoloads
geiser-autoloads fabs-autoloads companion-mode-autoloads
eww-hacks-autoloads evil-embrace-autoloads embrace-autoloads
expand-region-autoloads evil-surround-autoloads
evil-nerd-commenter-autoloads evil-goggles-autoloads evil-anzu-autoloads
anzu-autoloads evil-autoloads goto-chg-autoloads
eshell-syntax-highlighting-autoloads eat-autoloads
package-lint-flymake-autoloads package-lint-autoloads
elisp-def-autoloads macrostep-autoloads helpful-autoloads f-autoloads
elisp-refs-autoloads dash-autoloads s-autoloads
highlight-quoted-autoloads dirvish-autoloads transient-autoloads
diredfl-autoloads trashed-autoloads vertico-autoloads
orderless-autoloads nerd-icons-completion-autoloads marginalia-autoloads
embark-consult-autoloads embark-autoloads nerd-icons-corfu-autoloads
nerd-icons-autoloads cape-autoloads corfu-autoloads consult-autoloads
password-store-autoloads with-editor-autoloads compat-autoloads
elpaca-log elpaca-ui url url-proxy url-privacy url-expand url-methods
url-history url-cookie generate-lisp-file url-domsuf url-util mailcap
recentf tree-widget savehist elec-pair saveplace bind-key url-parse
auth-source eieio eieio-core password-cache json map url-vars easy-mmode
cus-edit pp cus-load wid-edit pcase ibuf-macs flymake-proc flymake
project byte-opt bytecomp byte-compile compile text-property-search
comint ansi-osc ansi-color warnings icons thingatpt cl-macs pixel-scroll
cua-base ring subr-x repeat rx midnight gv cl-seq elpaca elpaca-process
cl-loaddefs cl-lib elpaca-autoloads rmc iso-transl tooltip cconv eldoc
paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode
mwheel term/pgtk-win pgtk-win term/common-win pgtk-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads xwidget-internal dbusbind
inotify dynamic-setting system-font-setting font-render-setting cairo
gtk pgtk multi-tty make-network-process native-compile emacs)

Memory information:
((conses 16 1976204 1127031)
 (symbols 48 94384 7)
 (strings 32 478350 81603)
 (string-bytes 1 31638678)
 (vectors 16 149464)
 (vector-slots 8 3721744 648039)
 (floats 8 2069 5420)
 (intervals 56 197274 14128)
 (buffers 984 162))