https://github.com/python/cpython/commit/751db4e64993b5af98aa1c12cc9d7c7c5882961b
commit: 751db4e64993b5af98aa1c12cc9d7c7c5882961b
branch: main
author: Neil Schemenauer <[email protected]>
committer: nascheme <[email protected]>
date: 2025-05-08T04:32:23Z
summary:
gh-132917: Use /proc/self/status for mem usage info. (#133544)
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.
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 -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]