Blob Blame History Raw
From fe1f2189326a54e3496b2fcfdc1b08839f3165b4 Mon Sep 17 00:00:00 2001
From: Daniel Rank <dwrank@gmail.com>
Date: Sun, 27 Sep 2020 16:55:22 -0700
Subject: [PATCH] slabratetop: Add memcg_cache_params struct def

struct memcg_cache_params moved from include/linux/slab.h to
mm/slab.h in kernel v5.4, causing a compiler error when including
slub_def.h or slab_def.h in slabratetop's bpf program.

It has been removed completely from kernel version 5.9.

Add an empty memcg_cache_params struct in slabratetop's bpf
program so it will compile with kernel versions 5.4 to 5.8.
---
 tools/slabratetop.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/slabratetop.py b/tools/slabratetop.py
index 066f79d6..182dbd1d 100755
--- a/tools/slabratetop.py
+++ b/tools/slabratetop.py
@@ -62,7 +62,13 @@ loadavg = "/proc/loadavg"
 bpf_text = """
 #include <uapi/linux/ptrace.h>
 #include <linux/mm.h>
-#include <linux/slab.h>
+
+// memcg_cache_params is a part of kmem_cache, but is not publicly exposed in
+// kernel versions 5.4 to 5.8.  Define an empty struct for it here to allow the
+// bpf program to compile.  It has been completely removed in kernel version
+// 5.9, but it does not hurt to have it here for versions 5.4 to 5.8.
+struct memcg_cache_params {};
+
 #ifdef CONFIG_SLUB
 #include <linux/slub_def.h>
 #else
-- 
2.29.2