From: Michael Jeanson Date: Mon, 15 Aug 2022 21:22:47 +0000 (-0400) Subject: fix: mm/tracing: add 'accounted' entry into output of allocation tracepoints (v6.0) X-Git-Url: https://git.liburcu.org/?p=lttng-modules.git;a=commitdiff_plain;h=c02d67bcbfbbbd0d82b338da1eddfec015a96b8a fix: mm/tracing: add 'accounted' entry into output of allocation tracepoints (v6.0) See upstream commit : commit b347aa7b57477f71c740e2bbc6d1078a7109ba23 Author: Vasily Averin 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 Signed-off-by: Mathieu Desnoyers --- diff --git a/include/instrumentation/events/kmem.h b/include/instrumentation/events/kmem.h index 8c19e962..219533a1 100644 --- a/include/instrumentation/events/kmem.h +++ b/include/instrumentation/events/kmem.h @@ -9,6 +9,96 @@ #include #include +#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, diff --git a/src/probes/Kbuild b/src/probes/Kbuild index 3e556b8e..aa002534 100644 --- a/src/probes/Kbuild +++ b/src/probes/Kbuild @@ -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