https://github.com/python/cpython/commit/8e86f9c3ccbe8955ea5b28b07bb3d37197eef841
commit: 8e86f9c3ccbe8955ea5b28b07bb3d37197eef841
branch: 3.14
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: nascheme <nas-git...@arctrix.com>
date: 2025-05-08T16:37:59-07:00
summary:

[3.14] gh-132917: Use /proc/self/status for mem usage info. (GH-133544) 
(gh-133718)

On Linux, use /proc/self/status for mem usage info.  Using smaps_rollup is 
quite a lot slower and
we can get the similar info from /proc/self/status.
(cherry picked from commit 751db4e64993b5af98aa1c12cc9d7c7c5882961b)

Co-authored-by: Neil Schemenauer <nas-git...@arctrix.com>

files:
M Python/gc_free_threading.c

diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c
index 757e9cb3227e26..d2ea5b5e06ba43 100644
--- a/Python/gc_free_threading.c
+++ b/Python/gc_free_threading.c
@@ -1927,8 +1927,7 @@ get_process_mem_usage(void)
     }
 
 #elif __linux__
-    // Linux, use smaps_rollup (Kernel >= 4.4) for RSS + Swap
-    FILE* fp = fopen("/proc/self/smaps_rollup", "r");
+    FILE* fp = fopen("/proc/self/status", "r");
     if (fp == NULL) {
         return -1;
     }
@@ -1938,11 +1937,11 @@ get_process_mem_usage(void)
     long long swap_kb = -1;
 
     while (fgets(line_buffer, sizeof(line_buffer), fp) != NULL) {
-        if (rss_kb == -1 && strncmp(line_buffer, "Rss:", 4) == 0) {
-            sscanf(line_buffer + 4, "%lld", &rss_kb);
+        if (rss_kb == -1 && strncmp(line_buffer, "VmRSS:", 6) == 0) {
+            sscanf(line_buffer + 6, "%lld", &rss_kb);
         }
-        else if (swap_kb == -1 && strncmp(line_buffer, "Swap:", 5) == 0) {
-            sscanf(line_buffer + 5, "%lld", &swap_kb);
+        else if (swap_kb == -1 && strncmp(line_buffer, "VmSwap:", 7) == 0) {
+            sscanf(line_buffer + 7, "%lld", &swap_kb);
         }
         if (rss_kb != -1 && swap_kb != -1) {
             break; // Found both

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to