[PATCH 3/4] alloc_tag: extend allocinfo_filter to support tracing queries

From: Abhishek Bapat

Date: Mon Sep 21 2026 - 17:27:15 EST


Extend the allocinfo filtering mechanism to allow users to filter tags
based on their trace state.

Signed-off-by: Abhishek Bapat <abhishekbapat@xxxxxxxxxx>
---
include/uapi/linux/alloc_tag.h | 8 ++++++--
mm/alloc_tag.c | 8 ++++++++
2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/alloc_tag.h b/include/uapi/linux/alloc_tag.h
index 069ab8341e87..e65c32afceee 100644
--- a/include/uapi/linux/alloc_tag.h
+++ b/include/uapi/linux/alloc_tag.h
@@ -38,7 +38,8 @@ struct allocinfo_counter {
__u64 bytes;
__u64 calls;
__u8 accurate;
- __u8 pad[7];
+ __u8 trace_on;
+ __u8 pad[6];
} __attribute__((aligned(8)));

struct allocinfo_tag_data {
@@ -54,7 +55,8 @@ enum {
ALLOCINFO_FILTER_INACCURATE,
ALLOCINFO_FILTER_MIN_SIZE,
ALLOCINFO_FILTER_MAX_SIZE,
- __ALLOCINFO_FILTER_LAST = ALLOCINFO_FILTER_MAX_SIZE
+ ALLOCINFO_FILTER_TRACE_ON,
+ __ALLOCINFO_FILTER_LAST = ALLOCINFO_FILTER_TRACE_ON
};

#define ALLOCINFO_FILTER_MASK_MODNAME (1 << ALLOCINFO_FILTER_MODNAME)
@@ -64,6 +66,7 @@ enum {
#define ALLOCINFO_FILTER_MASK_INACCURATE (1 << ALLOCINFO_FILTER_INACCURATE)
#define ALLOCINFO_FILTER_MASK_MIN_SIZE (1 << ALLOCINFO_FILTER_MIN_SIZE)
#define ALLOCINFO_FILTER_MASK_MAX_SIZE (1 << ALLOCINFO_FILTER_MAX_SIZE)
+#define ALLOCINFO_FILTER_MASK_TRACE_ON (1 << ALLOCINFO_FILTER_TRACE_ON)

#define ALLOCINFO_FILTER_MASKS \
((1 << (__ALLOCINFO_FILTER_LAST + 1)) - 1)
@@ -75,6 +78,7 @@ struct allocinfo_filter {
__u64 max_size;
/* filter criteria only; see allocinfo_counter.accurate for actual accuracy */
__u64 inaccurate;
+ __u64 tracing;
};

struct allocinfo_get_at {
diff --git a/mm/alloc_tag.c b/mm/alloc_tag.c
index fb179321a2a1..50632b627d92 100644
--- a/mm/alloc_tag.c
+++ b/mm/alloc_tag.c
@@ -251,6 +251,7 @@ static void allocinfo_to_params(struct codetag *ct,
data->counter.bytes = counters->bytes;
data->counter.calls = counters->calls;
data->counter.accurate = !alloc_tag_is_inaccurate(ct_to_alloc_tag(ct));
+ data->counter.trace_on = alloc_tag_is_traced(ct_to_alloc_tag(ct));
}

/*
@@ -324,6 +325,13 @@ static bool matches_filter(struct codetag *ct, struct allocinfo_filter *filter,
return false;
}

+ if (filter->mask & ALLOCINFO_FILTER_MASK_TRACE_ON) {
+ bool tracing = alloc_tag_is_traced(ct_to_alloc_tag(ct));
+
+ if (tracing != !!(filter->tracing))
+ return false;
+ }
+
return true;
}

--
2.55.0.1082.g2b9226bbc0-goog