Skip to content

Instantly share code, notes, and snippets.

@agentzh
Created March 3, 2020 23:41
Show Gist options
  • Save agentzh/011404ec048b1a4d209aebc730da3ad6 to your computer and use it in GitHub Desktop.
Save agentzh/011404ec048b1a4d209aebc730da3ad6 to your computer and use it in GitHub Desktop.
From 100d5e81de0f34ebba38472e373dece4c3449ea4 Mon Sep 17 00:00:00 2001
From: "Yichun Zhang (agentzh)" <yichun@openresty.com>
Date: Tue, 3 Mar 2020 15:15:30 -0800
Subject: [PATCH] Bug: proc_mem_rss() broken on older kernels lacking
MM_SHMEMPAGES.
This is a regression introduced in commit de253786000.
---
buildrun.cxx | 3 +++
runtime/linux/autoconf-mm-shmempages.c | 5 +++++
tapset/linux/proc_mem.stp | 11 ++++++++---
3 files changed, 16 insertions(+), 3 deletions(-)
create mode 100644 runtime/linux/autoconf-mm-shmempages.c
diff --git a/buildrun.cxx b/buildrun.cxx
index 0870af946..040132277 100644
--- a/buildrun.cxx
+++ b/buildrun.cxx
@@ -440,6 +440,9 @@ compile_pass (systemtap_session& s)
output_autoconf(s, o, cs, "autoconf-cpu-clock.c", "STAPCONF_CPU_CLOCK", NULL);
output_autoconf(s, o, cs, "autoconf-local-clock.c", "STAPCONF_LOCAL_CLOCK", NULL);
+ // used by tapset/linux/proc_mem.stp
+ output_autoconf(s, o, cs, "autoconf-mm-shmempages.c", "STAPCONF_MM_SHMEMPAGES", NULL);
+
// used by runtime/uprobe-inode.c
output_either_exportconf(s, o2, "uprobe_register", "register_uprobe",
"STAPCONF_UPROBE_REGISTER_EXPORTED");
diff --git a/runtime/linux/autoconf-mm-shmempages.c b/runtime/linux/autoconf-mm-shmempages.c
new file mode 100644
index 000000000..2ce742be7
--- /dev/null
+++ b/runtime/linux/autoconf-mm-shmempages.c
@@ -0,0 +1,5 @@
+#include <linux/sched.h>
+
+void foo (void) {
+ (void) MM_SHMEMPAGES;
+}
diff --git a/tapset/linux/proc_mem.stp b/tapset/linux/proc_mem.stp
index 1208a2287..87f349bf8 100644
--- a/tapset/linux/proc_mem.stp
+++ b/tapset/linux/proc_mem.stp
@@ -73,9 +73,14 @@ enum {
%(systemtap_v > "4.2" %?
@__private30 function _MM_SHMEMPAGES:long()
-{
- return @const("MM_SHMEMPAGES")
-}
+%{ /* pure */
+ STAP_RETVALUE =
+#ifdef STAPCONF_MM_SHMEMPAGES
+ MM_SHMEMPAGES;
+#else
+ 0;
+#endif
+%}
%)
@__private30 function _stp_get_mm_counter:long(mm_ptr:long, member:long)
--
2.17.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment