[RFC PATCH 13/27] mm/damon/core: introduce damon_report_exist()
From: SJ Park
Date: Sun Nov 15 2026 - 15:30:01 EST
Implement and expose a new DAMON API function for searching data
attribute reports from the report queue. The purpose is to let
operation sets use it for supporting the REPORT_MADE type probe filters.
The caller can specify the type, associated memory address range, and
the creation time range of reports to search.
The function uses CAS-based try-locking for the mutual-exclusive
synchronization. If any parallel access to the queue is detected, it
forgives searching.
Signed-off-by: SJ Park <sj@xxxxxxxxxx>
---
include/linux/damon.h | 3 +++
mm/damon/core.c | 46 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index cce7d344c585b..0e43b669dfc49 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -1193,6 +1193,9 @@ int damon_call(struct damon_ctx *ctx, struct damon_call_control *control);
int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control);
int damon_submit_report(struct damon_report *report);
+bool damon_report_exist(enum damon_report_type report_type,
+ struct damon_addr_range *addr_range,
+ unsigned long jiffies_old);
int damon_set_region_system_rams_default(struct damon_target *t,
unsigned long *start, unsigned long *end,
diff --git a/mm/damon/core.c b/mm/damon/core.c
index c02c7fbc1d864..c60a6504d0a15 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2386,6 +2386,52 @@ int damon_submit_report(struct damon_report *report)
return 0;
}
+/**
+ * damon_report_exist() - Find if a report of a given condition exists.
+ *
+ * @report_type: Type of the report.
+ * @addr_range: Address range of the report.
+ * @jiffies_old: Oldest jiffies to find the report for.
+ *
+ * Returns true if the report is found, false otherwise.
+ */
+bool damon_report_exist(enum damon_report_type report_type,
+ struct damon_addr_range *addr_range, unsigned long jiffies_old)
+{
+ struct damon_report_queue *queue;
+ int lock_old_val;
+ unsigned int idx, nr_read;
+ struct damon_report *report;
+ bool found = false;
+
+ queue = &damon_report_queue;
+ lock_old_val = atomic_cmpxchg(&queue->lock, 0, 1);
+
+ if (lock_old_val)
+ return false;
+ idx = queue->tail;
+ for (nr_read = 0; nr_read < queue->nr_reports; nr_read++) {
+ report = &queue->reports[idx];
+ if (idx)
+ idx--;
+ else
+ idx = queue->size - 1;
+
+ if (time_before(report->jiffies, jiffies_old))
+ break;
+ if (report->type != report_type)
+ continue;
+ if (addr_range->end <= report->addr_range.start ||
+ report->addr_range.end <= addr_range->start)
+ continue;
+ found = true;
+ break;
+ }
+
+ atomic_cmpxchg(&queue->lock, 1, 0);
+ return found;
+}
+
/*
* Reset the aggregated monitoring results ('nr_accesses' of each region).
*/
--
2.47.3