fix: mm/tracing: add 'accounted' entry into output of allocation tracepoints (v6.0)
authorMichael Jeanson <mjeanson@efficios.com>
Mon, 15 Aug 2022 21:22:47 +0000 (17:22 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 18 Aug 2022 18:35:07 +0000 (14:35 -0400)
See upstream commit :

  commit b347aa7b57477f71c740e2bbc6d1078a7109ba23
  Author: Vasily Averin <vasily.averin@linux.dev>
  Date:   Fri Jun 3 06:21:49 2022 +0300

    mm/tracing: add 'accounted' entry into output of allocation tracepoints

    Slab caches marked with SLAB_ACCOUNT force accounting for every
    allocation from this cache even if __GFP_ACCOUNT flag is not passed.
    Unfortunately, at the moment this flag is not visible in ftrace output,
    and this makes it difficult to analyze the accounted allocations.

    This patch adds boolean "accounted" entry into trace output,
    and set it to 'true' for calls used __GFP_ACCOUNT flag and
    for allocations from caches marked with SLAB_ACCOUNT.
    Set it to 'false' if accounting is disabled in configs.

Change-Id: I023a355b94e79931499e1a1f648e2649d6dd3c89
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/instrumentation/events/kmem.h
src/probes/Kbuild

index 8c19e9624a2f13502b08a7142e43e8fbf8c35d61..219533a1ed12e74e9441137044b3dda3a2181239 100644 (file)
@@ -9,6 +9,96 @@
 #include <linux/types.h>
 #include <lttng/kernel-version.h>
 
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,0,0))
+
+#include <../../mm/slab.h>
+
+LTTNG_TRACEPOINT_EVENT_CLASS(kmem_alloc,
+
+       TP_PROTO(unsigned long call_site,
+                const void *ptr,
+                struct kmem_cache *s,
+                size_t bytes_req,
+                size_t bytes_alloc,
+                gfp_t gfp_flags),
+
+       TP_ARGS(call_site, ptr, s, bytes_req, bytes_alloc, gfp_flags),
+
+       TP_FIELDS(
+               ctf_integer_hex(unsigned long, call_site, call_site)
+               ctf_integer_hex(const void *, ptr, ptr)
+               ctf_integer(size_t, bytes_req, bytes_req)
+               ctf_integer(size_t, bytes_alloc, bytes_alloc)
+               ctf_integer(gfp_t, gfp_flags, gfp_flags)
+               ctf_integer(bool, accounted, IS_ENABLED(CONFIG_MEMCG_KMEM) ?
+                       ((gfp_flags & __GFP_ACCOUNT) ||
+                       (s && s->flags & SLAB_ACCOUNT)) : false)
+       )
+)
+
+LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(kmem_alloc, kmalloc,
+
+       kmem_kmalloc,
+
+       TP_PROTO(unsigned long call_site, const void *ptr, struct kmem_cache *s,
+                size_t bytes_req, size_t bytes_alloc, gfp_t gfp_flags),
+
+       TP_ARGS(call_site, ptr, s, bytes_req, bytes_alloc, gfp_flags)
+)
+
+LTTNG_TRACEPOINT_EVENT_INSTANCE(kmem_alloc, kmem_cache_alloc,
+
+       TP_PROTO(unsigned long call_site, const void *ptr, struct kmem_cache *s,
+                size_t bytes_req, size_t bytes_alloc, gfp_t gfp_flags),
+
+       TP_ARGS(call_site, ptr, s, bytes_req, bytes_alloc, gfp_flags)
+)
+
+LTTNG_TRACEPOINT_EVENT_CLASS(kmem_alloc_node,
+
+       TP_PROTO(unsigned long call_site,
+                const void *ptr,
+                struct kmem_cache *s,
+                size_t bytes_req,
+                size_t bytes_alloc,
+                gfp_t gfp_flags,
+                int node),
+
+       TP_ARGS(call_site, ptr, s, bytes_req, bytes_alloc, gfp_flags, node),
+
+       TP_FIELDS(
+               ctf_integer_hex(unsigned long, call_site, call_site)
+               ctf_integer_hex(const void *, ptr, ptr)
+               ctf_integer(size_t, bytes_req, bytes_req)
+               ctf_integer(size_t, bytes_alloc, bytes_alloc)
+               ctf_integer(gfp_t, gfp_flags, gfp_flags)
+               ctf_integer(int, node, node)
+               ctf_integer(bool, accounted, IS_ENABLED(CONFIG_MEMCG_KMEM) ?
+                       ((gfp_flags & __GFP_ACCOUNT) ||
+                       (s && s->flags & SLAB_ACCOUNT)) : false)
+       )
+)
+
+LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(kmem_alloc_node, kmalloc_node,
+
+       kmem_kmalloc_node,
+
+       TP_PROTO(unsigned long call_site, const void *ptr,
+                struct kmem_cache *s, size_t bytes_req, size_t bytes_alloc,
+                gfp_t gfp_flags, int node),
+
+       TP_ARGS(call_site, ptr, s, bytes_req, bytes_alloc, gfp_flags, node)
+)
+
+LTTNG_TRACEPOINT_EVENT_INSTANCE(kmem_alloc_node, kmem_cache_alloc_node,
+
+       TP_PROTO(unsigned long call_site, const void *ptr,
+                struct kmem_cache *s, size_t bytes_req, size_t bytes_alloc,
+                gfp_t gfp_flags, int node),
+
+       TP_ARGS(call_site, ptr, s, bytes_req, bytes_alloc, gfp_flags, node)
+)
+#else
 LTTNG_TRACEPOINT_EVENT_CLASS(kmem_alloc,
 
        TP_PROTO(unsigned long call_site,
@@ -86,6 +176,7 @@ LTTNG_TRACEPOINT_EVENT_INSTANCE(kmem_alloc_node, kmem_cache_alloc_node,
 
        TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags, node)
 )
+#endif
 
 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,12,0))
 LTTNG_TRACEPOINT_EVENT_MAP(kfree,
index 3e556b8e1d72c7225e768baac8ee06930e27f62b..aa002534ab5424e59318f8c6b86715f935a807e6 100644 (file)
@@ -9,7 +9,24 @@ ccflags-y += -I$(TOP_LTTNG_MODULES_DIR)/include
 obj-$(CONFIG_LTTNG) += lttng-probe-sched.o
 obj-$(CONFIG_LTTNG) += lttng-probe-irq.o
 obj-$(CONFIG_LTTNG) += lttng-probe-timer.o
-obj-$(CONFIG_LTTNG) += lttng-probe-kmem.o
+
+# A dependency on internal header 'mm/slab.h' was introduced in v6.0
+kmem_dep = $(srctree)/mm/slab.h
+kmem_dep_wildcard = $(wildcard $(kmem_dep))
+kmem_dep_check = $(shell \
+if [ \( $(VERSION) -ge 7 \
+   -o \( $(VERSION) -eq 6 -a $(PATCHLEVEL) -ge 0 \) \) -a \
+   -z "$(kmem_dep_wildcard)" ] ; then \
+  echo "warn" ; \
+else \
+  echo "ok" ; \
+fi ;)
+ifeq ($(kmem_dep_check),ok)
+  obj-$(CONFIG_LTTNG) += lttng-probe-kmem.o
+else
+  $(warning File $(kmem_dep) not found. Probe "kmem" is disabled. Use full kernel source tree to enable it.)
+endif
+
 obj-$(CONFIG_LTTNG) += lttng-probe-module.o
 obj-$(CONFIG_LTTNG) += lttng-probe-power.o
 obj-$(CONFIG_LTTNG) += lttng-probe-statedump.o
This page took 0.030051 seconds and 4 git commands to generate.