mm/damon: hardware-sampled access reports
Subsystems (5)
cover mm/damon: hardware-sampled access reports
This series introduces a vendor and PMU-agnostic substrate inside DAMON that consumes hardware-sampled access reports through the standard perf-event interface. Userspace selects the PMU through sysfs (raw type/config knobs), driving either Intel PEBS L3-miss sampling or AMD IBS Op sampling.
Why a unified perf-event substrate
Earlier hardware-sampled access-monitoring proposal [1] took an AMD IBS specific module path backend, owning its own probe configuration, sysfs knobs, and lifecycle.
SeongJae Park has previously highlighted the advantage of Akinobu Mita's perf-event proposal [2]: let DAMON register kernel-counter perf events and consume samples from any sampling PMU that perf core knows about. This series builds on that direction with the changes we needed to run it cross-vendor:
- a per-CPU lockless ring between the NMI sample handler and the kdamond drain,
- per-CPU events that follow CPU hotplug cleanly,
- events fire only while the monitor is running -- created disabled, armed when kdamond starts, disarmed and drained when it stops,
- all-or-nothing init across CPUs: a partial-CPU create failure rolls the whole event back rather than leaving silent gaps,
- safe handling of vendor sample-validity flags so a stale or unpopulated address is never mistaken for a valid sample.
What the series adds
Patch 1 introduces the substrate's data types: a per-event configuration struct and a per-context list to hang them on. A CONFIG_PERF_EVENTS=n build folds to no-op stubs.
Patch 2 exposes those types through sysfs. Each entry maps to one perf event and lets userspace pick the PMU and how to sample it: the raw PMU type/config, addressing flags, and period or frequency. The defaults are tuned for Intel PEBS; userspace overrides them for other PMUs.
Patch 3 wires the sysfs apply path so configured events get attached to the running monitoring context.
Patch 4 is the core of the series. It replaces the mutex-protected report queue with a per-CPU lockless ring fed from NMI by the perf overflow handler and drained once per sample tick by the kdamond. Drained reports are matched to monitored regions by binary search over a per-tick snapshot. The patch also wires the per-event lifecycle into kdamond: events arm when the monitor starts, disarm and drain when it stops, roll back cleanly when per-CPU init fails on some CPUs, and a second context that asks for the substrate while it is in use is rejected with -EBUSY.
Patch 5 is the perf-event backend. Two stateless overflow handlers (one vaddr-keyed, one paddr-keyed) are picked at event creation time and submit samples into the per-CPU ring. Vendor-specific sample validity is honored at this layer.
Patch 6 adds a tracepoint at every node_eligible_mem_bp quota-goal evaluation so userspace can watch goal convergence without polling sysfs.
Userspace setup model
Userspace selects the sampling PMU by pointing the perf event's type / config at it, and chooses the scheme topology that suits the address space the PMU reports on. No module load or unload step is involved; echo on > state arms the substrate, echo off > state disarms it.
Two configurations were used for validation.
Configuration A: AMD IBS Op, paddr ops, system-wide PULL+PUSH tiering
IBS Op stamps samples with physical addresses, so DAMON reasons over every backing page in the system regardless of which task or guest touched it -- the substrate becomes a system-wide tiering controller.
Setup (abridged; D=/sys/kernel/mm/damon/admin/kdamonds/0):
echo 1 > /sys/kernel/mm/damon/admin/kdamonds/nr_kdamonds
echo 1 > $D/contexts/nr_contexts
echo paddr > $D/contexts/0/operations
# Two regions, one per NUMA node (DRAM + CXL). PA ranges # are derived per host from /proc/iomem; omitted here. echo 1 > $D/contexts/0/targets/nr_targets
echo 2 > $D/contexts/0/targets/0/regions/nr_regions echo <DRAM_LO> > $D/contexts/0/targets/0/regions/0/start echo <DRAM_HI> > $D/contexts/0/targets/0/regions/0/end echo <CXL_LO> > $D/contexts/0/targets/0/regions/1/start echo <CXL_HI> > $D/contexts/0/targets/0/regions/1/end
# IBS Op event, period-based, paddr-stamped:
PE=$D/contexts/0/monitoring_attrs/sample/perf_events echo 1 > $PE/nr_perf_events
echo $(cat /sys/bus/event_source/devices/ibs_op/type) > $PE/0/type
echo 0 > $PE/0/config
echo 1 > $PE/0/sample_phys_addr
echo 0 > $PE/0/freq
echo 262144 > $PE/0/sample_period
echo 0 > $PE/0/exclude_kernel
echo 0 > $PE/0/exclude_hv
# PULL scheme: migrate_hot toward DRAM, gated on
# node_eligible_mem_bp(nid=DRAM) goal target_value=TARGET_BP. # addr filter restricts source to the CXL range.
# PUSH scheme: migrate_hot toward CXL, gated on
# node_eligible_mem_bp(nid=CXL) target_value=10000-TARGET_BP. # addr filter restricts source to the DRAM range.
# Both schemes are migrate_hot; they converge from opposite # directions on the same hot working set.
echo on > $D/state
Userspace tunes the steady-state DRAM:CXL split by writing the goal target_values; DAMON's quota autotuner drives migration intensity to match.
Workload: a QEMU/KVM guest pinned to one NUMA node, running 32 multichase multiload threads each touching a 4 GiB working set (~128 GiB aggregate) with the memcpy-libc kernel. The guest sees a flat single-NUMA layout and has no direct view of the host's tiering topology, yet its hot pages are migrated to DRAM and cold pages pushed to CXL by host-side DAMON acting on IBS-stamped physical addresses -- the application inside the guest benefits from tiering it never had to be aware of. Validated on AMD Turin (132-CPU EPYC). The configuration converged to its target ratio in seconds and remained stable for 7+ hours continuously, with no perf core auto-throttle and no measurable drift in the achieved interleave ratio.
Configuration B: Intel PEBS L3-miss, vaddr ops, per-PID weighted-dest
PEBS reports vaddr samples in the context of the running task. DAMON's vaddr ops monitors a specific PID.
Setup (abridged):
echo 1 > /sys/kernel/mm/damon/admin/kdamonds/nr_kdamonds
echo 1 > $D/contexts/nr_contexts
echo vaddr > $D/contexts/0/operations
echo 1 > $D/contexts/0/targets/nr_targets
echo $PID > $D/contexts/0/targets/0/pid_target
echo 0 > $D/contexts/0/targets/0/regions/nr_regions
# PEBS MEM_LOAD_RETIRED.L3_MISS, frequency-based, vaddr-stamped:
echo 1 > $PE/nr_perf_events
echo 4 > $PE/0/type # PERF_TYPE_RAW
echo 0x20d1 > $PE/0/config # umask=0x20 event=0xd1
echo 0 > $PE/0/sample_phys_addr
echo 1 > $PE/0/freq
echo 5003 > $PE/0/sample_freq
echo 2 > $PE/0/precise_ip
echo 1 > $PE/0/wakeup_events
# Single migrate_hot scheme with two weighted destinations # (DRAM + CXL). Userspace tunes the steady-state interleave by # writing dests/{0,1}/weight.
echo on > $D/state
Workload: 32 multichase multiload threads with a 4 GiB working set each (~128 GiB aggregate) running directly on the host, monitored by DAMON via the multiload PID. Validated on Intel Granite Rapids (144-CPU). Convergence is fast and the system is stable.
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/[email protected]
Ravi Jonnalagadda (6):
mm/damon: add struct damon_perf_event{,_attr} and per-ctx perf_events
list
mm/damon/sysfs-sample: expose perf_events configuration via sysfs mm/damon/sysfs: install perf_events on apply mm/damon/core: per-CPU SPSC ring drain and damon_perf_event lifecycle mm/damon/vaddr: implement perf-event access check mm/damon: add damos_node_eligible_mem_bp tracepoint
include/linux/damon.h | 80 +++++ include/trace/events/damon.h | 49 +++ mm/damon/core.c | 403 ++++++++++++++++++++---- mm/damon/ops-common.h | 39 +++ mm/damon/sysfs-common.h | 6 + mm/damon/sysfs-sample.c | 579 +++++++++++++++++++++++++++++++++++ mm/damon/sysfs.c | 3 + mm/damon/vaddr.c | 267 ++++++++++++++++ 8 files changed, 1370 insertions(+), 56 deletions(-)
base-commit: 4c8ad15abf15eb480d3ad85f902001e35465ef18
Signature · 1 line
2.43.0
RFC PATCH 1/6 mm/damon: add struct damon_perf_event{,_attr} and per-ctx perf_events list
Introduce the substrate types for using perf events as DAMON access check sources. struct damon_perf_event_attr carries the raw PMU attr configurable from userspace; struct damon_perf_event is the per-event entry on a new damon_ctx::perf_events list.
Declare damon_perf_init() and damon_perf_cleanup() in mm/damon/ops-common.h. When CONFIG_PERF_EVENTS=n they fold to a no-op returning -ENOSYS.
--- include/linux/damon.h | 80 +++++++++++++++++++++++++++++++++++++++++ mm/damon/ops-common.h | 39 ++++++++++++++++++++ mm/damon/sysfs-common.h | 6 ++++ 3 files changed, 125 insertions(+)
include/linux/damon.h +80 -0
@@ -123,6 +123,7 @@ struct damon_target {* @size: The size of the accessed address range. * @cpu: The id of the CPU that made the access. * @tid: The task id of the task that made the access. +* @tgid: Thread group id of the task that made the access. * @is_write: Whether the access is write. * * Any DAMON API callers that notified access events can report the information
@@ -135,6 +136,7 @@ struct damon_access_report {unsigned long size;unsigned int cpu;pid_t tid; +pid_t tgid;bool is_write;/* private: */ unsigned long report_jiffies;/* when this report is made */
@@ -501,6 +503,7 @@ struct damos_filter { };struct damon_ctx ; +struct damon_target_lookup ;struct damos ;/**
@@ -966,6 +969,67 @@ struct damon_sample_control {struct list_head sample_filters; }; +/** +* struct damon_perf_event_attr - raw PMU event attr for access check. +* +* @type: raw PMU event type. +* @config: raw PMU event config. +* @config1: raw PMU event config1. +* @config2: raw PMU event config2. +* @sample_phys_addr: whether to set PERF_SAMPLE_PHYS_ADDR in sample_type. +* @sample_weight_struct: whether to set PERF_SAMPLE_WEIGHT_STRUCT in +* sample_type. PMUs that do not advertise +* weight (e.g. AMD IBS Op) reject events with +* this flag set, so it must be opt-in. +* @exclude_kernel: exclude kernel-mode samples. +* @exclude_hv: exclude hypervisor samples. +* @freq: when true use @sample_freq, otherwise @sample_period. +* @sample_freq: target sample rate when @freq is true. +* @sample_period: period (samples-between-overflows) when @freq is false. +* @wakeup_events: perf_event_attr.wakeup_events. +* @precise_ip: precise sampling skid bound (PEBS-style PMUs). +*/ +struct damon_perf_event_attr { +u32 type; +u64 config; +u64 config1; +u64 config2; +bool sample_phys_addr; +bool sample_weight_struct; +bool exclude_kernel; +bool exclude_hv; +bool freq; +u64 sample_freq; +u64 sample_period; +u32 wakeup_events; +u32 precise_ip; +}; + +/** +* struct damon_perf_event - perf event for access check. +* +* @attr: Per-event PMU attribute (configured via sysfs). +* @priv: Monitoring operations-specific data. +* @list: List head for &damon_ctx->perf_events siblings. +* @hlist_node: Tracks this event among cpuhp multi-instance entries. +* @init_complete: Set after the synchronous online sweep finishes; gates +* @any_cpu_failed writes from late hotplug callbacks. +* @any_cpu_failed: Set by the cpuhp online callback if perf_event creation +* fails on any CPU during the synchronous initial install. +* @ctx: Back-pointer to the owning damon_ctx; the cpu_online callback +* reads ctx->perf_events_active to decide whether to enable a +* late-onlining CPU's event immediately after create. +*/ +struct damon_perf_event { +struct damon_perf_event_attr attr; +void *priv; +struct list_head list; +struct hlist_node hlist_node; +bool init_complete; +bool any_cpu_failed; +struct damon_ctx *ctx; +}; +/** * struct damon_ctx - Represents a context for each monitoring. This is the * main interface that allows users to set the attributes and get the results
@@ -991,6 +1055,11 @@ struct damon_sample_control {* @addr_unit: Scale factor for core to ops address conversion. * @min_region_sz: Minimum region size. * @pause: Pause kdamond main loop. +* @perf_events: Head of perf events (&damon_perf_event) list. +* @perf_events_active: Set while kdamond_fn has the perf events armed. +* Cleared in the kdamond_fn done path before the events are +* disabled; serves as the gate for damon_commit_perf_events() +* and the kdamond_fn drain dispatch. */ struct damon_ctx {struct damon_attrs attrs;
@@ -1046,6 +1115,9 @@ struct damon_ctx {unsigned long min_region_sz;bool pause; +struct list_head perf_events; +bool perf_events_active; +/* private: */ /* Head of monitoring targets (&damon_target) list. */ struct list_head adaptive_targets;
@@ -1054,6 +1126,14 @@ struct damon_ctx {/* Per-ctx PRNG state for damon_rand(); kdamond is the sole consumer. */ struct rnd_state rnd_state; + +/* Reusable drain-loop snapshot buffer (avoids per-tick kmalloc). */ +struct { +struct damon_target_lookup *lookups; +unsigned int nr_lookups; +struct damon_region **region_buf; +unsigned int region_buf_cap; + } drain_snapshot; };/* Get a random number in [@l, @r) using @ctx's lockless PRNG. */
mm/damon/ops-common.h +39 -0
@@ -23,3 +23,42 @@ bool damos_folio_filter_match(struct damos_filter *filter, struct folio *folio);unsigned long damon_migrate_pages (struct list_head *folio_list,int target_nid);bool damos_ops_has_filter (struct damos *s); + +#ifdef CONFIG_PERF_EVENTS + +/* +* Per-event opaque allocated by damon_perf_init(). The NMI overflow +* handler does NOT touch this struct; submission goes through the +* shared per-CPU SPSC ring via damon_report_access(). +*/ +struct damon_perf { +struct perf_event *__percpu *event; +}; + +int damon_perf_init (struct damon_ctx *ctx,struct damon_perf_event *event); +void damon_perf_cleanup (struct damon_ctx *ctx,struct damon_perf_event *event); +void damon_perf_event_arm (struct damon_perf_event *event); +void damon_perf_event_disarm (struct damon_perf_event *event); + +#else /* !CONFIG_PERF_EVENTS */ + +static inline int damon_perf_init (struct damon_ctx *ctx, +struct damon_perf_event *event) +{ +return -ENOSYS ; +} + +static inline void damon_perf_cleanup (struct damon_ctx *ctx, +struct damon_perf_event *event) +{ +} + +static inline void damon_perf_event_arm (struct damon_perf_event *event) +{ +} + +static inline void damon_perf_event_disarm (struct damon_perf_event *event) +{ +} + +#endif /* CONFIG_PERF_EVENTS */
mm/damon/sysfs-common.h +6 -0
@@ -66,10 +66,13 @@ int damon_sysfs_memcg_path_to_id(char *memcg_path, u64 *id);* sample directory */ +struct damon_sysfs_perf_events ; +struct damon_sysfs_sample {struct kobject kobj;struct damon_sysfs_primitives *primitives;struct damon_sysfs_sample_filters *filters; +struct damon_sysfs_perf_events *perf_events; };struct damon_sysfs_sample *damon_sysfs_sample_alloc (void );
@@ -82,3 +85,6 @@ extern const struct kobj_type damon_sysfs_sample_ktype;int damon_sysfs_set_sample_control (struct damon_sample_control *control,struct damon_sysfs_sample *sysfs_sample); + +int damon_sysfs_add_perf_events (struct damon_ctx *ctx, +struct damon_sysfs_sample *sysfs_sample);
Signature · 1 line
2.43.0
RFC PATCH 2/6 mm/damon/sysfs-sample: expose perf_events configuration via sysfs
In reply to Ravi JonnalagaddaAdd a perf_events/ subdirectory under each context's sample/ directory. Each numbered entry maps to one damon_perf_event and exposes its raw PMU attr, addressing flags, and period/delivery knobs.
Defaults match Intel PEBS L3-miss; userspace overrides them for other PMUs. sample_weight_struct defaults off because PMUs that do not advertise PERF_SAMPLE_WEIGHT_STRUCT (e.g. AMD IBS Op) reject events that request it with -EOPNOTSUPP.
--- mm/damon/sysfs-sample.c | 579 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 579 insertions(+)
mm/damon/sysfs-sample.c +579 -0
@@ -452,6 +452,520 @@ static const struct kobj_type damon_sysfs_primitives_ktype = { .default_groups = damon_sysfs_primitives_groups, }; +/* +* perf_event_attr directory +*/ + +struct damon_sysfs_perf_event_attr { +struct kobject kobj; +u32 type; +u64 config; +u64 config1; +u64 config2; +bool sample_phys_addr; +bool sample_weight_struct; +bool exclude_kernel; +bool exclude_hv; +bool freq; +u64 sample_freq; +u64 sample_period; +u32 wakeup_events; +u32 precise_ip; +}; + +static struct damon_sysfs_perf_event_attr * +damon_sysfs_perf_event_attr_alloc (void ) +{ +struct damon_sysfs_perf_event_attr *attr = +kzalloc (sizeof (*attr),GFP_KERNEL ); + +if (!attr) +return NULL ; + attr->wakeup_events =1 ; + attr->precise_ip =2 ; + attr->freq = true; + attr->exclude_kernel = true; + attr->exclude_hv = true; +return attr; +} + +static ssize_t attr_type_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"0x%x\n" , perf_event_attr->type); +} + +static ssize_t attr_type_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +int err =kstrtou32 (buf,0 , &perf_event_attr->type); + +if (err) +return -EINVAL ; +return count; +} + +static ssize_t config_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"0x%llx\n" , perf_event_attr->config); +} + +static ssize_t config_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +int err =kstrtou64 (buf,0 , &perf_event_attr->config); + +if (err) +return -EINVAL ; +return count; +} + +static ssize_t config1_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"0x%llx\n" , perf_event_attr->config1); +} + +static ssize_t config1_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +int err =kstrtou64 (buf,0 , &perf_event_attr->config1); + +if (err) +return -EINVAL ; +return count; +} + +static ssize_t config2_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"0x%llx\n" , perf_event_attr->config2); +} + +static ssize_t config2_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +int err =kstrtou64 (buf,0 , &perf_event_attr->config2); + +if (err) +return -EINVAL ; +return count; +} + +static ssize_t sample_phys_addr_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"%d\n" , perf_event_attr->sample_phys_addr); +} + +static ssize_t sample_phys_addr_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +bool sample_phys_addr; +int err =kstrtobool (buf, &sample_phys_addr); + +if (err) +return -EINVAL ; + + perf_event_attr->sample_phys_addr = sample_phys_addr; +return count; +} + +static ssize_t sample_weight_struct_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"%d\n" , perf_event_attr->sample_weight_struct); +} + +static ssize_t sample_weight_struct_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +bool sample_weight_struct; +int err =kstrtobool (buf, &sample_weight_struct); + +if (err) +return -EINVAL ; + + perf_event_attr->sample_weight_struct = sample_weight_struct; +return count; +} + +static ssize_t sample_freq_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"%llu\n" , perf_event_attr->sample_freq); +} + +static ssize_t sample_freq_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +int err =kstrtou64 (buf,0 , &perf_event_attr->sample_freq); + +if (err) +return -EINVAL ; +return count; +} + +static ssize_t wakeup_events_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"%u\n" , perf_event_attr->wakeup_events); +} + +static ssize_t wakeup_events_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +int err =kstrtou32 (buf,0 , &perf_event_attr->wakeup_events); + +if (err) +return -EINVAL ; +return count; +} + +static ssize_t precise_ip_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"%u\n" , perf_event_attr->precise_ip); +} + +static ssize_t precise_ip_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +int err =kstrtou32 (buf,0 , &perf_event_attr->precise_ip); + +if (err) +return -EINVAL ; +return count; +} + +static ssize_t freq_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"%d\n" , perf_event_attr->freq); +} + +static ssize_t freq_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +bool freq; +int err =kstrtobool (buf, &freq); + +if (err) +return -EINVAL ; + perf_event_attr->freq = freq; +return count; +} + +static ssize_t sample_period_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"%llu\n" , perf_event_attr->sample_period); +} + +static ssize_t sample_period_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +int err =kstrtou64 (buf,0 , &perf_event_attr->sample_period); + +if (err) +return -EINVAL ; +return count; +} + +static ssize_t exclude_kernel_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"%d\n" , perf_event_attr->exclude_kernel); +} + +static ssize_t exclude_kernel_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +bool v; +int err =kstrtobool (buf, &v); + +if (err) +return -EINVAL ; + perf_event_attr->exclude_kernel = v; +return count; +} + +static ssize_t exclude_hv_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); + +return sysfs_emit (buf,"%d\n" , perf_event_attr->exclude_hv); +} + +static ssize_t exclude_hv_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_event_attr *perf_event_attr =container_of (kobj, + struct damon_sysfs_perf_event_attr, kobj); +bool v; +int err =kstrtobool (buf, &v); + +if (err) +return -EINVAL ; + perf_event_attr->exclude_hv = v; +return count; +} + +static void damon_sysfs_perf_event_attr_release (struct kobject *kobj) +{ +kfree (container_of(kobj ,struct damon_sysfs_perf_event_attr ,kobj )); +} + +static struct kobj_attribute damon_sysfs_perf_event_attr_type_attr = +__ATTR (type,0600 , attr_type_show, attr_type_store); + +static struct kobj_attribute damon_sysfs_perf_event_attr_config_attr = +__ATTR_RW_MODE (config,0600 ); + +static struct kobj_attribute damon_sysfs_perf_event_attr_config1_attr = +__ATTR_RW_MODE (config1,0600 ); + +static struct kobj_attribute damon_sysfs_perf_event_attr_config2_attr = +__ATTR_RW_MODE (config2,0600 ); + +static struct kobj_attribute damon_sysfs_perf_event_attr_sample_phys_addr_attr = +__ATTR_RW_MODE (sample_phys_addr,0600 ); + +static struct kobj_attribute + damon_sysfs_perf_event_attr_sample_weight_struct_attr = +__ATTR_RW_MODE (sample_weight_struct,0600 ); + +static struct kobj_attribute damon_sysfs_perf_event_attr_sample_freq_attr = +__ATTR_RW_MODE (sample_freq,0600 ); + +static struct kobj_attribute damon_sysfs_perf_event_attr_wakeup_events_attr = +__ATTR_RW_MODE (wakeup_events,0600 ); + +static struct kobj_attribute damon_sysfs_perf_event_attr_precise_ip_attr = +__ATTR_RW_MODE (precise_ip,0600 ); + +static struct kobj_attribute damon_sysfs_perf_event_attr_freq_attr = +__ATTR_RW_MODE (freq,0600 ); + +static struct kobj_attribute damon_sysfs_perf_event_attr_sample_period_attr = +__ATTR_RW_MODE (sample_period,0600 ); + +static struct kobj_attribute damon_sysfs_perf_event_attr_exclude_kernel_attr = +__ATTR_RW_MODE (exclude_kernel,0600 ); + +static struct kobj_attribute damon_sysfs_perf_event_attr_exclude_hv_attr = +__ATTR_RW_MODE (exclude_hv,0600 ); + +static struct attribute *damon_sysfs_perf_event_attr_attrs[] = { + &damon_sysfs_perf_event_attr_type_attr.attr, + &damon_sysfs_perf_event_attr_config_attr.attr, + &damon_sysfs_perf_event_attr_config1_attr.attr, + &damon_sysfs_perf_event_attr_config2_attr.attr, + &damon_sysfs_perf_event_attr_sample_phys_addr_attr.attr, + &damon_sysfs_perf_event_attr_sample_weight_struct_attr.attr, + &damon_sysfs_perf_event_attr_freq_attr.attr, + &damon_sysfs_perf_event_attr_sample_freq_attr.attr, + &damon_sysfs_perf_event_attr_sample_period_attr.attr, + &damon_sysfs_perf_event_attr_wakeup_events_attr.attr, + &damon_sysfs_perf_event_attr_precise_ip_attr.attr, + &damon_sysfs_perf_event_attr_exclude_kernel_attr.attr, + &damon_sysfs_perf_event_attr_exclude_hv_attr.attr, +NULL , +}; +ATTRIBUTE_GROUPS (damon_sysfs_perf_event_attr); + +static const struct kobj_type damon_sysfs_perf_event_attr_ktype = { + .release = damon_sysfs_perf_event_attr_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damon_sysfs_perf_event_attr_groups, +}; + +/* +* perf_events directory +*/ + +/* +* Cap on the number of perf events per damon_ctx, to bound the sysfs +* kobject footprint and prevent unbounded allocations from a careless +* write to nr_perf_events. +*/ +#define DAMON_SYSFS_PERF_EVENTS_MAX 64 + +struct damon_sysfs_perf_events { +struct kobject kobj; +struct damon_sysfs_perf_event_attr **attrs_arr; +int nr; +}; + +static struct damon_sysfs_perf_events *damon_sysfs_perf_events_alloc (void ) +{ +return kzalloc (sizeof (struct damon_sysfs_perf_events ),GFP_KERNEL ); +} + +static void damon_sysfs_perf_events_rm_dirs ( +struct damon_sysfs_perf_events *events) +{ +struct damon_sysfs_perf_event_attr **attrs_arr = events->attrs_arr; +int i; + +for (i =0 ; i < events->nr; i++) +kobject_put (&attrs_arr[i]->kobj); + events->nr =0 ; +kfree (attrs_arr); + events->attrs_arr =NULL ; +} + +static int damon_sysfs_perf_events_add_dirs ( +struct damon_sysfs_perf_events *events,int nr_events) +{ +struct damon_sysfs_perf_event_attr **attrs_arr, *attr; +int err, i; + +damon_sysfs_perf_events_rm_dirs (events); +if (!nr_events) +return 0 ; + + attrs_arr =kmalloc_array (nr_events,sizeof (*attrs_arr),GFP_KERNEL ); +if (!attrs_arr) +return -ENOMEM ; + events->attrs_arr = attrs_arr; + +for (i =0 ; i < nr_events; i++) { + attr =damon_sysfs_perf_event_attr_alloc (); +if (!attr) { +damon_sysfs_perf_events_rm_dirs (events); +return -ENOMEM ; + } + + err =kobject_init_and_add (&attr->kobj, + &damon_sysfs_perf_event_attr_ktype, &events->kobj, +"%d" , i); +if (err) { +kobject_put (&attr->kobj); +damon_sysfs_perf_events_rm_dirs (events); +return err; + } + attrs_arr[i] = attr; + events->nr++; + } +return 0 ; +} + +static ssize_t nr_perf_events_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct damon_sysfs_perf_events *events =container_of (kobj, + struct damon_sysfs_perf_events, kobj); + +return sysfs_emit (buf,"%d\n" , events->nr); +} + +static ssize_t nr_perf_events_store (struct kobject *kobj, +struct kobj_attribute *attr,const char *buf,size_t count) +{ +struct damon_sysfs_perf_events *events; +int nr, err =kstrtoint (buf,0 , &nr); + +if (err) +return err; +if (nr <0 || nr >DAMON_SYSFS_PERF_EVENTS_MAX ) +return -EINVAL ; + + events = container_of(kobj, struct damon_sysfs_perf_events, kobj); + +if (!mutex_trylock (&damon_sysfs_lock)) +return -EBUSY ; + err =damon_sysfs_perf_events_add_dirs (events, nr); +mutex_unlock (&damon_sysfs_lock); +if (err) +return err; + +return count; +} + +static void damon_sysfs_perf_events_release (struct kobject *kobj) +{ +kfree (container_of(kobj ,struct damon_sysfs_perf_events ,kobj )); +} + +static struct kobj_attribute damon_sysfs_perf_events_nr_attr = +__ATTR_RW_MODE (nr_perf_events,0600 ); + +static struct attribute *damon_sysfs_perf_events_attrs[] = { + &damon_sysfs_perf_events_nr_attr.attr, +NULL , +}; +ATTRIBUTE_GROUPS (damon_sysfs_perf_events); + +static const struct kobj_type damon_sysfs_perf_events_ktype = { + .release = damon_sysfs_perf_events_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damon_sysfs_perf_events_groups, +}; +/* * sample directory */
@@ -471,6 +985,7 @@ int damon_sysfs_sample_add_dirs(struct damon_sysfs_sample *sample) {struct damon_sysfs_primitives *primitives;struct damon_sysfs_sample_filters *filters; +struct damon_sysfs_perf_events *perf_events;int err; primitives =damon_sysfs_primitives_alloc (true, false);
@@ -494,7 +1009,23 @@ int damon_sysfs_sample_add_dirs(struct damon_sysfs_sample *sample)if (err) goto put_filters_out; sample->filters = filters; + + perf_events =damon_sysfs_perf_events_alloc (); +if (!perf_events) { + err = -ENOMEM ; + goto put_filters_out; + } + err =kobject_init_and_add (&perf_events->kobj, + &damon_sysfs_perf_events_ktype, &sample->kobj, +"perf_events" ); +if (err) + goto put_perf_events_out; + sample->perf_events = perf_events; +return 0 ; +put_perf_events_out: +kobject_put (&perf_events->kobj); + sample->perf_events =NULL ; put_filters_out:kobject_put (&filters->kobj); sample->filters =NULL ;
@@ -512,6 +1043,10 @@ void damon_sysfs_sample_rm_dirs(struct damon_sysfs_sample *sample)damon_sysfs_sample_filters_rm_dirs (sample->filters);kobject_put (&sample->filters->kobj); } +if (sample->perf_events) { +damon_sysfs_perf_events_rm_dirs (sample->perf_events); +kobject_put (&sample->perf_events->kobj); + } }void damon_sysfs_sample_release (struct kobject *kobj)
@@ -596,3 +1131,47 @@ int damon_sysfs_set_sample_control(return damon_sysfs_set_sample_filters (control, sysfs_sample->filters); } + +static int damon_sysfs_add_perf_event ( +struct damon_sysfs_perf_event_attr *sys_attr, +struct damon_ctx *ctx) +{ +struct damon_perf_event *event =kzalloc (sizeof (*event),GFP_KERNEL ); + +if (!event) +return -ENOMEM ; + + event->attr.type = sys_attr->type; + event->attr.config = sys_attr->config; + event->attr.config1 = sys_attr->config1; + event->attr.config2 = sys_attr->config2; + event->attr.sample_phys_addr = sys_attr->sample_phys_addr; + event->attr.sample_weight_struct = sys_attr->sample_weight_struct; + event->attr.freq = sys_attr->freq; + event->attr.sample_freq = sys_attr->sample_freq; + event->attr.sample_period = sys_attr->sample_period; + event->attr.wakeup_events = sys_attr->wakeup_events; + event->attr.precise_ip = sys_attr->precise_ip; + event->attr.exclude_kernel = sys_attr->exclude_kernel; + event->attr.exclude_hv = sys_attr->exclude_hv; + +list_add_tail (&event->list, &ctx->perf_events); +return 0 ; +} + +int damon_sysfs_add_perf_events (struct damon_ctx *ctx, +struct damon_sysfs_sample *sysfs_sample) +{ +struct damon_sysfs_perf_events *events = sysfs_sample->perf_events; +int i, err; + +if (!events) +return 0 ; + +for (i =0 ; i < events->nr; i++) { + err =damon_sysfs_add_perf_event (events->attrs_arr[i], ctx); +if (err) +return err; + } +return 0 ; +}
Signature · 1 line
2.43.0
RFC PATCH 3/6 mm/damon/sysfs: install perf_events on apply
In reply to Ravi JonnalagaddaCall damon_sysfs_add_perf_events() from damon_sysfs_apply_inputs() so events configured under sample/perf_events/ get attached to the damon_ctx when the kdamond starts.
--- mm/damon/sysfs.c | 3 +++ 1 file changed, 3 insertions(+)
mm/damon/sysfs.c +3 -0
@@ -2092,6 +2092,9 @@ static int damon_sysfs_apply_inputs(struct damon_ctx *ctx,return err; err =damon_sysfs_set_sample_control (&ctx->sample_control, sys_ctx->attrs->sample); +if (err) +return err; + err =damon_sysfs_add_perf_events (ctx, sys_ctx->attrs->sample);if (err)return err; err =damon_sysfs_add_targets (ctx, sys_ctx->targets);
Signature · 1 line
2.43.0
RFC PATCH 4/6 mm/damon/core: per-CPU SPSC ring drain and damon_perf_event lifecycle
In reply to Ravi JonnalagaddaReplace the mutex-protected damon_access_reports[] single-buffer with a per-CPU SPSC ring. The producer (damon_report_access) is called from NMI by perf overflow handlers; the consumer (kdamond_check_reported_accesses) runs once per sample tick.
- 256-entry ring per CPU with cache-line-aligned head/tail
- per-CPU damon_report_ring_busy guards against NMI nesting on top of a process-context producer on the same CPU
- per-CPU damon_ring_pending bit so the consumer iterates only CPUs that produced samples this tick
- smp_mb between flag clear and head read on the consumer side pairs with the producer's head-publish ordering
Replace the O(N) per-region scan in kdamond_apply_access_report() with bsearch over a per-tick per-target snapshot built into a reusable damon_ctx::drain_snapshot buffer. The pid-based ctx early-reject is no longer needed: kdamond_apply_access_report() already discriminates report->vaddr vs report->paddr per ctx.
Wire the damon_perf_event lifecycle: init per attached event when kdamond starts, teardown when the ctx is destroyed, replayed across damon_commit_ctx. Add the matching forward decl + drain_snapshot field on struct damon_ctx.
--- include/trace/events/damon.h | 17 ++ mm/damon/core.c | 383 ++++++++++++++++++++++++++++++----- 2 files changed, 344 insertions(+), 56 deletions(-)
include/trace/events/damon.h +17 -0
@@ -74,6 +74,23 @@ TRACE_EVENT(damos_esz, __entry->esz) ); +TRACE_EVENT (damon_perf_ring_overflow, + + TP_PROTO(int cpu), + +TP_ARGS (cpu), + +TP_STRUCT__entry ( +__field (int, cpu) + ), + +TP_fast_assign ( + __entry->cpu = cpu; + ), + +TP_printk ("cpu=%d" , __entry->cpu) +); + TRACE_EVENT_CONDITION(damos_before_apply, TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
mm/damon/core.c +327 -56
530 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC PATCH 5/6 mm/damon/vaddr: implement perf-event access check
In reply to Ravi JonnalagaddaAdd the perf-event backend used by the substrate. Two stateless NMI overflow handlers are picked at perf_event_create_kernel_counter() time (paddr- vs vaddr-keyed) and called with context = NULL, so the NMI fast path never dereferences the per-event struct. Each submits a damon_access_report into the per-CPU ring.
The vaddr handler drops samples with addr == 0 or addr >= TASK_SIZE. The paddr handler gates on data->sample_flags & PERF_SAMPLE_PHYS_ADDR rather than testing data->phys_addr for zero (which would also drop legitimate page 0). AMD IBS Op only populates phys_addr when IBS_OP_DATA3.dc_phy_addr_valid is set; gating on sample_flags is the documented way to detect that. is_write is derived from data->data_src.mem_op.
cpuhp_setup_state_multi() registers one global state at subsys_initcall; each damon_perf_event is added as an instance in damon_perf_init() so cpuhp drives per-CPU event creation and offline-time release. Events are created with disabled=1 and armed by kdamond_fn() when the substrate is ready; per-CPU init failures are surfaced via init_complete / any_cpu_failed so damon_perf_init() rolls back the cpuhp instance instead of leaving a half-armed event behind.
--- mm/damon/vaddr.c | 267 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 267 insertions(+)
mm/damon/vaddr.c +267 -0
@@ -7,11 +7,13 @@#define pr_fmt (fmt) "damon-va: " fmt +#include <linux/cpuhotplug.h> #include <linux/highmem.h> #include <linux/hugetlb.h> #include <linux/mman.h> #include <linux/mmu_notifier.h> #include <linux/page_idle.h> +#include <linux/perf_event.h> #include <linux/pagewalk.h> #include <linux/sched/mm.h>
@@ -957,6 +959,263 @@ static int damon_va_scheme_score(struct damon_ctx *context,return DAMOS_MAX_SCORE ; } +#ifdef CONFIG_PERF_EVENTS + +#define DAMON_PERF_MAX_RECORDS (1UL << 20) +#define DAMON_PERF_INIT_RECORDS (1UL << 15) + +/* +* NMI hot-path: avoid every heap dereference. These handlers carry no +* pointer back to the per-event struct -- perf_event_create_kernel_counter +* is called with context = NULL. Submission flows into the global +* per-CPU SPSC ring (damon_report_access -> kdamond_check_reported_accesses +* drains). +*/ +static void damon_perf_overflow_vaddr (struct perf_event *perf_event, +struct perf_sample_data *data,struct pt_regs *regs) +{ +struct damon_access_report report; + +if (!data || !data->addr) +return ; + +/* Drop kernel-VA hits -- only user-space VAs land in damon vaddr regions. */ +if (data->addr >=TASK_SIZE ) +return ; + + report = (struct damon_access_report ){ + .vaddr = data->addr &PAGE_MASK , + .size =PAGE_SIZE , + .cpu =smp_processor_id (), + .tid = current->pid, + .tgid = current->tgid, + .is_write = !!(data->data_src.mem_op &PERF_MEM_OP_STORE ), + }; +damon_report_access (&report); +} + +static void damon_perf_overflow_paddr (struct perf_event *perf_event, +struct perf_sample_data *data,struct pt_regs *regs) +{ +struct damon_access_report report; + +if (!data) +return ; + +/* +* AMD IBS Op only populates data->phys_addr when +* IBS_OP_DATA3.dc_phy_addr_valid is set; otherwise the field +* carries a stale value. Gate on sample_flags rather than testing +* phys_addr for zero (which would also drop legitimate page 0). +*/ +if (!(data->sample_flags &PERF_SAMPLE_PHYS_ADDR )) +return ; + + report = (struct damon_access_report ){ + .paddr = data->phys_addr &PAGE_MASK , + .size =PAGE_SIZE , + .cpu =smp_processor_id (), + .is_write = !!(data->data_src.mem_op &PERF_MEM_OP_STORE ), + }; +damon_report_access (&report); +} + +static enum cpuhp_state damon_perf_cpuhp_state; + +static void damon_perf_event_init_attr (struct damon_perf_event *event, +struct perf_event_attr *attr) +{ + *attr = (struct perf_event_attr ) { + .size =sizeof (*attr), + .type = event->attr.type, + .config = event->attr.config, + .config1 = event->attr.config1, + .config2 = event->attr.config2, + .freq = event->attr.freq, + .sample_type =PERF_SAMPLE_TIME |PERF_SAMPLE_ADDR | +PERF_SAMPLE_PERIOD |PERF_SAMPLE_DATA_SRC | + (event->attr.sample_phys_addr ? +PERF_SAMPLE_PHYS_ADDR :0 ) | + (event->attr.sample_weight_struct ? +PERF_SAMPLE_WEIGHT_STRUCT :0 ), + .precise_ip = event->attr.precise_ip, + .pinned =1 , + .disabled =1 , + .wakeup_events = event->attr.wakeup_events, + .exclude_kernel = event->attr.exclude_kernel, + .exclude_hv = event->attr.exclude_hv, + }; + +/* +* sample_period and sample_freq share storage in the kernel +* perf_event_attr (union). Select based on the freq toggle so +* frequency-based callers (PEBS) and period-based callers +* (AMD IBS Op MaxCnt) both work correctly. +*/ +if (event->attr.freq) + attr->sample_freq = event->attr.sample_freq; +else + attr->sample_period = event->attr.sample_period; +} + +static int damon_perf_cpu_online (unsigned int cpu,struct hlist_node *node) +{ +struct damon_perf_event *event =hlist_entry (node, + struct damon_perf_event, hlist_node); +struct damon_perf *perf = event->priv; +struct perf_event_attr attr; +struct perf_event *perf_event; +perf_overflow_handler_t handler; + +if (!perf) +return 0 ; + +damon_perf_event_init_attr (event, &attr); + +/* +* Pick a paddr- or vaddr-specific handler at create time so the +* NMI fast path is statically branched. Pass NULL as context -- +* handlers are stateless wrt the per-event struct, so the NMI +* fast path performs no per-event heap dereference. Submission +* flows into the global per-CPU SPSC ring via damon_report_access(). +*/ + handler = event->attr.sample_phys_addr ? + damon_perf_overflow_paddr : damon_perf_overflow_vaddr; + + perf_event =perf_event_create_kernel_counter (&attr, cpu,NULL , + handler,NULL ); +if (IS_ERR (perf_event)) { +pr_warn_ratelimited ("damon-perf: cpu %u event create failed: %ld\n" , + cpu,PTR_ERR (perf_event)); +if (!event->init_complete) + event->any_cpu_failed = true; +return 0 ;/* never block CPU online */ + } + *per_cpu_ptr (perf->event, cpu) = perf_event; +/* +* Late-online CPU after the substrate is armed: events are created +* with attr.disabled = 1 and would otherwise stay quiescent on this +* CPU until the next arm walk. Enable here so coverage matches the +* already-online CPUs. +*/ +if (event->ctx &&READ_ONCE (event->ctx->perf_events_active)) +perf_event_enable (perf_event); +return 0 ; +} + +static int damon_perf_cpu_offline (unsigned int cpu,struct hlist_node *node) +{ +struct damon_perf_event *event =hlist_entry (node, + struct damon_perf_event, hlist_node); +struct damon_perf *perf = event->priv; +struct perf_event *perf_event; + +if (!perf) +return 0 ; + + perf_event =per_cpu (*perf->event, cpu); +if (perf_event) { +perf_event_disable (perf_event); +perf_event_release_kernel (perf_event); + *per_cpu_ptr (perf->event, cpu) =NULL ; + } +return 0 ; +} + +void damon_perf_event_arm (struct damon_perf_event *event) +{ +struct damon_perf *perf = event->priv; +struct perf_event *perf_event; +int cpu; + +if (!perf) +return ; + +for_each_online_cpu (cpu) { + perf_event = *per_cpu_ptr (perf->event, cpu); +if (perf_event) +perf_event_enable (perf_event); + } +} + +void damon_perf_event_disarm (struct damon_perf_event *event) +{ +struct damon_perf *perf = event->priv; +struct perf_event *perf_event; +int cpu; + +if (!perf) +return ; + +for_each_online_cpu (cpu) { + perf_event = *per_cpu_ptr (perf->event, cpu); +if (perf_event) +perf_event_disable (perf_event); + } +} + +int damon_perf_init (struct damon_ctx *ctx,struct damon_perf_event *event) +{ +struct damon_perf *perf; +int err = -ENOMEM ; + + perf =kzalloc (sizeof (*perf),GFP_KERNEL ); +if (!perf) +return -ENOMEM ; + + perf->event =alloc_percpu (typeof (*perf->event)); +if (!perf->event) + goto free_perf; + + event->priv = perf; + event->ctx = ctx; +INIT_HLIST_NODE (&event->hlist_node); + +/* +* cpuhp_state_add_instance() invokes the online callback synchronously +* for every currently-online CPU; late-online CPUs subsequently get +* an event automatically and offline CPUs release theirs cleanly. +*/ + err =cpuhp_state_add_instance (damon_perf_cpuhp_state, + &event->hlist_node); +if (err) + goto free_event; + + event->init_complete = true; +if (event->any_cpu_failed) { +cpuhp_state_remove_instance (damon_perf_cpuhp_state, + &event->hlist_node); + err = -ENODEV ; + goto free_event; + } + +return 0 ; + +free_event: +free_percpu (perf->event); +free_perf: +kfree (perf); + event->priv =NULL ; +return err; +} + +void damon_perf_cleanup (struct damon_ctx *ctx,struct damon_perf_event *event) +{ +struct damon_perf *perf = event->priv; + +if (!perf) +return ; + +cpuhp_state_remove_instance (damon_perf_cpuhp_state, + &event->hlist_node); + +free_percpu (perf->event); +kfree (perf); + event->priv =NULL ; +} + +#endif /* CONFIG_PERF_EVENTS */ +static int __init damon_va_initcall (void ) {struct damon_operations ops = {
@@ -979,6 +1238,14 @@ static int __init damon_va_initcall(void) ops_fvaddr.init =NULL ; ops_fvaddr.update =NULL ; +#ifdef CONFIG_PERF_EVENTS + err =cpuhp_setup_state_multi (CPUHP_AP_ONLINE_DYN ,"damon/perf:online" , + damon_perf_cpu_online, damon_perf_cpu_offline); +if (err <0 ) +return err; + damon_perf_cpuhp_state = err; +#endif + err =damon_register_ops (&ops);if (err)return err;
Signature · 1 line
2.43.0
RFC PATCH 6/6 mm/damon: add damos_node_eligible_mem_bp tracepoint
In reply to Ravi JonnalagaddaFire a tracepoint at every DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP goal evaluation, exposing (context, scheme, nid, target_value, current_value). This gives userspace observability into goal-tracking without polling sysfs.
The trace_..._enabled() guard avoids the damon_for_each_scheme() iteration cost when nothing is listening.
--- include/trace/events/damon.h | 32 ++++++++++++++++++++++++++++++++ mm/damon/core.c | 20 ++++++++++++++++++++ 2 files changed, 52 insertions(+)
include/trace/events/damon.h +32 -0
@@ -91,6 +91,38 @@ TRACE_EVENT(damon_perf_ring_overflow,TP_printk ("cpu=%d" , __entry->cpu) ); +/* Per-tick DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP goal evaluation. */ +TRACE_EVENT (damos_node_eligible_mem_bp, + + TP_PROTO(unsigned int context_idx, unsigned int scheme_idx, + int nid, + unsigned long target_value, unsigned long current_value), + +TP_ARGS (context_idx, scheme_idx, nid, target_value, current_value), + +TP_STRUCT__entry ( + __field(unsigned int, context_idx) + __field(unsigned int, scheme_idx) + __field(int, nid) + __field(unsigned long, target_value) + __field(unsigned long, current_value) + ), + +TP_fast_assign ( + __entry->context_idx = context_idx; + __entry->scheme_idx = scheme_idx; + __entry->nid = nid; + __entry->target_value = target_value; + __entry->current_value = current_value; + ), + +TP_printk ("ctx_idx=%u scheme_idx=%u nid=%d " +"target_value=%lu current_value=%lu" , + __entry->context_idx, __entry->scheme_idx, + __entry->nid, + __entry->target_value, __entry->current_value) +); + TRACE_EVENT_CONDITION(damos_before_apply, TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
mm/damon/core.c +20 -0
@@ -3203,6 +3203,26 @@ static unsigned long damos_quota_score(struct damon_ctx *c, struct damos *s) highest_score =max (highest_score,mult_frac (goal->current_value,10000 , goal->target_value)); + +/* +* Per-tick visibility of NODE_ELIGIBLE_MEM_BP goal evaluation +* for userspace convergence-detection. +*/ +if (goal->metric ==DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP && +trace_damos_node_eligible_mem_bp_enabled ()) { +unsigned int cidx =0 , sidx =0 ; +struct damos *siter; + +damon_for_each_scheme (siter, c) { +if (siter == s) +break ; + sidx++; + } +trace_damos_node_eligible_mem_bp (cidx, sidx, + goal->nid, + goal->target_value, + goal->current_value); + } }return highest_score;
Signature · 1 line
2.43.0
SeongJae Park
maintainerQuoted 8 lines · On Fri, 29 May 2026 09:56:34 -0700 Ravi Jonnalagadda <[email protected]>…
This series introduces a vendor and PMU-agnostic substrate inside DAMON that consumes hardware-sampled access reports through the standard perf-event interface. Userspace selects the PMU through sysfs (raw type/config knobs), driving either Intel PEBS L3-miss sampling or AMD IBS Op sampling.
Why a unified perf-event substrate
Quoted 8 lines
Earlier hardware-sampled access-monitoring proposal [1] took an AMD IBS specific module path backend, owning its own probe configuration, sysfs knobs, and lifecycle.
SeongJae Park has previously highlighted the advantage of Akinobu Mita's perf-event proposal [2]: let DAMON register kernel-counter perf events and consume samples from any sampling PMU that perf core knows about. This series builds on that direction
Ah great, so we have no unclear challenge (additional loadable module support and conflicts with other IBS modules) on our road for now! That is, we can reuse the stable perf event interface and achieve all our goals! As I previously shared [1], it would take time, but I'm very optimistic about the success of this project. I don't like promising too much, but this project looks like something that we can "consider it done".
We can also say that the current candidate of the first damon_report_access()-based data attributes monitoring (milestone 2 [1] final deliverable) is the perf event based monitoring.
Quoted 78 lines
with the changes we
needed to run it cross-vendor:- a per-CPU lockless ring between the NMI sample handler and the kdamond drain,
- per-CPU events that follow CPU hotplug cleanly,
- events fire only while the monitor is running -- created disabled, armed when kdamond starts, disarmed and drained when it stops,
- all-or-nothing init across CPUs: a partial-CPU create failure rolls the whole event back rather than leaving silent gaps,
- safe handling of vendor sample-validity flags so a stale or unpopulated address is never mistaken for a valid sample.What the series adds
Patch 1 introduces the substrate's data types: a per-event configuration struct and a per-context list to hang them on. A
CONFIG_PERF_EVENTS=nbuild folds to no-op stubs.Patch 2 exposes those types through sysfs. Each entry maps to one perf event and lets userspace pick the PMU and how to sample it: the raw PMU type/config, addressing flags, and period or frequency. The defaults are tuned for Intel PEBS; userspace overrides them for other PMUs.
Patch 3 wires the sysfs apply path so configured events get attached to the running monitoring context.
Patch 4 is the core of the series. It replaces the mutex-protected report queue with a per-CPU lockless ring fed from NMI by the perf overflow handler and drained once per sample tick by the kdamond. Drained reports are matched to monitored regions by binary search over a per-tick snapshot. The patch also wires the per-event lifecycle into kdamond: events arm when the monitor starts, disarm and drain when it stops, roll back cleanly when per-CPU init fails on some CPUs, and a second context that asks for the substrate while it is in use is rejected with
-EBUSY.Patch 5 is the perf-event backend. Two stateless overflow handlers (one vaddr-keyed, one paddr-keyed) are picked at event creation time and submit samples into the per-CPU ring. Vendor-specific sample validity is honored at this layer.
Patch 6 adds a tracepoint at every
node_eligible_mem_bpquota-goal evaluation so userspace can watch goal convergence without polling sysfs.Userspace setup model
Userspace selects the sampling PMU by pointing the perf event's
type/configat it, and chooses the scheme topology that suits the address space the PMU reports on. No module load or unload step is involved;echo on > statearms the substrate,echo off > statedisarms it.Two configurations were used for validation.
Configuration A: AMD IBS Op, paddr ops, system-wide PULL+PUSH tiering
IBS Op stamps samples with physical addresses, so DAMON reasons over every backing page in the system regardless of which task or guest touched it -- the substrate becomes a system-wide tiering controller.
Setup (abridged;
D=/sys/kernel/mm/damon/admin/kdamonds/0):echo 1 >
/sys/kernel/mm/damon/admin/kdamonds/nr_kdamonds
echo 1 > $D/contexts/nr_contexts
echo paddr > $D/contexts/0/operations# Two regions, one per NUMA node (DRAM + CXL). PA ranges # are derived per host from
/proc/iomem; omitted here. echo 1 > $D/contexts/0/targets/nr_targets
echo 2 > $D/contexts/0/targets/0/regions/nr_regions echo <DRAM_LO> > $D/contexts/0/targets/0/regions/0/start echo <DRAM_HI> > $D/contexts/0/targets/0/regions/0/end echo <CXL_LO> > $D/contexts/0/targets/0/regions/1/start echo <CXL_HI> > $D/contexts/0/targets/0/regions/1/end
Quoted 10 lines
# IBS Op event, period-based, paddr-stamped:
PE=$D/contexts/0/monitoring_attrs/sample/perf_events echo 1 > $PE/nr_perf_events
echo $(cat/sys/bus/event_source/devices/ibs_op/type) > $PE/0/type
echo 0 > $PE/0/config
echo 1 > $PE/0/sample_phys_addr
echo 0 > $PE/0/freq
echo 262144 > $PE/0/sample_period
echo 0 > $PE/0/exclude_kernel
echo 0 > $PE/0/exclude_hv
FYI, and as you may already know, the current plan [1] is to use the attributes probe interface. With it, the above IBS Op event setup part would look like,
mon_attr=/sys/kernel/mm/damon/admin/kdamonds/0/contexts/0/monitoring_attrs echo 1 > $mon_attr/probes/nr_probes
probe=$mon_attr/probes/0
echo 1 > $probe/filters/nr_filters
filter=$probe/filters/0
echo perf_event > $filter/type
echo ibs_op > $filter/perf_event_type
echo Y > $filter/allow
Of course, more details could change later.
Quoted 58 lines
# PULL scheme:
migrate_hottoward DRAM, gated on
#node_eligible_mem_bp(nid=DRAM)goal target_value=TARGET_BP. # addr filter restricts source to the CXL range.
# PUSH scheme:migrate_hottoward CXL, gated on
#node_eligible_mem_bp(nid=CXL)target_value=10000-TARGET_BP. # addr filter restricts source to the DRAM range.
# Both schemes aremigrate_hot; they converge from opposite # directions on the same hot working set.echo on > $D/state
Userspace tunes the steady-state DRAM:CXL split by writing the goal
target_values; DAMON's quota autotuner drives migration intensity to match.Workload: a QEMU/KVM guest pinned to one NUMA node, running 32 multichase multiload threads each touching a 4 GiB working set (~128 GiB aggregate) with the memcpy-libc kernel. The guest sees a flat single-NUMA layout and has no direct view of the host's tiering topology, yet its hot pages are migrated to DRAM and cold pages pushed to CXL by host-side DAMON acting on IBS-stamped physical addresses -- the application inside the guest benefits from tiering it never had to be aware of. Validated on AMD Turin (132-CPU EPYC). The configuration converged to its target ratio in seconds and remained stable for 7+ hours continuously, with no perf core auto-throttle and no measurable drift in the achieved interleave ratio.
Configuration B: Intel PEBS L3-miss, vaddr ops, per-PID weighted-dest
PEBS reports vaddr samples in the context of the running task. DAMON's vaddr ops monitors a specific PID.
Setup (abridged):
echo 1 >
/sys/kernel/mm/damon/admin/kdamonds/nr_kdamonds
echo 1 > $D/contexts/nr_contexts
echo vaddr > $D/contexts/0/operationsecho 1 > $D/contexts/0/targets/nr_targets
echo $PID > $D/contexts/0/targets/0/pid_target
echo 0 > $D/contexts/0/targets/0/regions/nr_regions# PEBS MEM_LOAD_RETIRED.L3_MISS, frequency-based, vaddr-stamped:
echo 1 > $PE/nr_perf_events
echo 4 > $PE/0/type #PERF_TYPE_RAW
echo0x20d1> $PE/0/config # umask=0x20 event=0xd1
echo 0 > $PE/0/sample_phys_addr
echo 1 > $PE/0/freq
echo 5003 > $PE/0/sample_freq
echo 2 > $PE/0/precise_ip
echo 1 > $PE/0/wakeup_events# Single
migrate_hotscheme with two weighted destinations # (DRAM + CXL). Userspace tunes the steady-state interleave by # writing dests/{0,1}/weight.
Quoted 6 lines
echo on > $D/state
Workload: 32 multichase multiload threads with a 4 GiB working set each (~128 GiB aggregate) running directly on the host, monitored by DAMON via the multiload PID. Validated on Intel Granite Rapids (144-CPU). Convergence is fast and the system is stable.
Thank you so much for sharing the great prototype implementation and test results!
I will try to make fast progress on milestone 1. I will hold reviewing details of this series for now, as there could be more changes. But in the high level, this looks promising.
Quoted 3 lines
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/[email protected]
[1] https://lore.kernel.org/[email protected]/
Thanks,
SJ
[...]
Hello Ravi and SeongJae,
2026年5月30日(土) 9:05 SeongJae Park <[email protected]>:
Quoted 27 lines · On Fri, 29 May 2026 09:56:34 -0700 Ravi Jonnalagadda <[email protected]>…
Quoted 9 lines
This series introduces a vendor and PMU-agnostic substrate inside DAMON that consumes hardware-sampled access reports through the standard perf-event interface. Userspace selects the PMU through sysfs (raw type/config knobs), driving either Intel PEBS L3-miss sampling or AMD IBS Op sampling.
Why a unified perf-event substrate
Quoted 8 lines
Earlier hardware-sampled access-monitoring proposal [1] took an AMD IBS specific module path backend, owning its own probe configuration, sysfs knobs, and lifecycle.
SeongJae Park has previously highlighted the advantage of Akinobu Mita's perf-event proposal [2]: let DAMON register kernel-counter perf events and consume samples from any sampling PMU that perf core knows about. This series builds on that direction
Ah great, so we have no unclear challenge (additional loadable module support and conflicts with other IBS modules) on our road for now! That is, we can reuse the stable perf event interface and achieve all our goals! As I previously shared [1], it would take time, but I'm very optimistic about the success of this project. I don't like promising too much, but this project looks like something that we can "consider it done".
Quoted 3 lines
We can also say that the current candidate of the first damon_report_access()-based data attributes monitoring (milestone 2 [1] final deliverable) is the perf event based monitoring.
That's good!
From a quick look, it seems to have all the features I need, so I'd like to evaluate it based on Ravi's patch. If any extensions require changes, I will let you know as feedback.
Ravi,
You can also add my Co-developed-by and Signed-off-by tags to the appropriate patch, so please post to the mailing list.
I am currently working on a change to allow selecting perf events from the damo tool by specifying the event name, similar to the perf record -e option (e.g., "cpu/mem-loads,ldlat=30,freq=5000/P" or "cpu/mem-stores,freq=5000/P").
I'll share the progress once it reaches a certain point. A change to the perf file, as shown in the attachment, will be necessary, but I believe it can be handled without changing Ravi's current patch set.
Quoted 179 lines
Quoted 78 lines
with the changes we
needed to run it cross-vendor:- a per-CPU lockless ring between the NMI sample handler and the kdamond drain,
- per-CPU events that follow CPU hotplug cleanly,
- events fire only while the monitor is running -- created disabled, armed when kdamond starts, disarmed and drained when it stops,
- all-or-nothing init across CPUs: a partial-CPU create failure rolls the whole event back rather than leaving silent gaps,
- safe handling of vendor sample-validity flags so a stale or unpopulated address is never mistaken for a valid sample.What the series adds
Patch 1 introduces the substrate's data types: a per-event configuration struct and a per-context list to hang them on. A
CONFIG_PERF_EVENTS=nbuild folds to no-op stubs.Patch 2 exposes those types through sysfs. Each entry maps to one perf event and lets userspace pick the PMU and how to sample it: the raw PMU type/config, addressing flags, and period or frequency. The defaults are tuned for Intel PEBS; userspace overrides them for other PMUs.
Patch 3 wires the sysfs apply path so configured events get attached to the running monitoring context.
Patch 4 is the core of the series. It replaces the mutex-protected report queue with a per-CPU lockless ring fed from NMI by the perf overflow handler and drained once per sample tick by the kdamond. Drained reports are matched to monitored regions by binary search over a per-tick snapshot. The patch also wires the per-event lifecycle into kdamond: events arm when the monitor starts, disarm and drain when it stops, roll back cleanly when per-CPU init fails on some CPUs, and a second context that asks for the substrate while it is in use is rejected with
-EBUSY.Patch 5 is the perf-event backend. Two stateless overflow handlers (one vaddr-keyed, one paddr-keyed) are picked at event creation time and submit samples into the per-CPU ring. Vendor-specific sample validity is honored at this layer.
Patch 6 adds a tracepoint at every
node_eligible_mem_bpquota-goal evaluation so userspace can watch goal convergence without polling sysfs.Userspace setup model
Userspace selects the sampling PMU by pointing the perf event's
type/configat it, and chooses the scheme topology that suits the address space the PMU reports on. No module load or unload step is involved;echo on > statearms the substrate,echo off > statedisarms it.Two configurations were used for validation.
Configuration A: AMD IBS Op, paddr ops, system-wide PULL+PUSH tiering
IBS Op stamps samples with physical addresses, so DAMON reasons over every backing page in the system regardless of which task or guest touched it -- the substrate becomes a system-wide tiering controller.
Setup (abridged;
D=/sys/kernel/mm/damon/admin/kdamonds/0):echo 1 >
/sys/kernel/mm/damon/admin/kdamonds/nr_kdamonds
echo 1 > $D/contexts/nr_contexts
echo paddr > $D/contexts/0/operations# Two regions, one per NUMA node (DRAM + CXL). PA ranges # are derived per host from
/proc/iomem; omitted here. echo 1 > $D/contexts/0/targets/nr_targets
echo 2 > $D/contexts/0/targets/0/regions/nr_regions echo <DRAM_LO> > $D/contexts/0/targets/0/regions/0/start echo <DRAM_HI> > $D/contexts/0/targets/0/regions/0/end echo <CXL_LO> > $D/contexts/0/targets/0/regions/1/start echo <CXL_HI> > $D/contexts/0/targets/0/regions/1/endQuoted 10 lines
# IBS Op event, period-based, paddr-stamped:
PE=$D/contexts/0/monitoring_attrs/sample/perf_events echo 1 > $PE/nr_perf_events
echo $(cat/sys/bus/event_source/devices/ibs_op/type) > $PE/0/type
echo 0 > $PE/0/config
echo 1 > $PE/0/sample_phys_addr
echo 0 > $PE/0/freq
echo 262144 > $PE/0/sample_period
echo 0 > $PE/0/exclude_kernel
echo 0 > $PE/0/exclude_hvFYI, and as you may already know, the current plan [1] is to use the attributes probe interface. With it, the above IBS Op event setup part would look like,
mon_attr=/sys/kernel/mm/damon/admin/kdamonds/0/contexts/0/monitoring_attrs echo 1 > $mon_attr/probes/nr_probes
probe=$mon_attr/probes/0
echo 1 > $probe/filters/nr_filters
filter=$probe/filters/0
echoperf_event> $filter/type
echoibs_op> $filter/perf_event_type
echo Y > $filter/allowOf course, more details could change later.
Quoted 58 lines
# PULL scheme:
migrate_hottoward DRAM, gated on
#node_eligible_mem_bp(nid=DRAM)goal target_value=TARGET_BP. # addr filter restricts source to the CXL range.
# PUSH scheme:migrate_hottoward CXL, gated on
#node_eligible_mem_bp(nid=CXL)target_value=10000-TARGET_BP. # addr filter restricts source to the DRAM range.
# Both schemes aremigrate_hot; they converge from opposite # directions on the same hot working set.echo on > $D/state
Userspace tunes the steady-state DRAM:CXL split by writing the goal
target_values; DAMON's quota autotuner drives migration intensity to match.Workload: a QEMU/KVM guest pinned to one NUMA node, running 32 multichase multiload threads each touching a 4 GiB working set (~128 GiB aggregate) with the memcpy-libc kernel. The guest sees a flat single-NUMA layout and has no direct view of the host's tiering topology, yet its hot pages are migrated to DRAM and cold pages pushed to CXL by host-side DAMON acting on IBS-stamped physical addresses -- the application inside the guest benefits from tiering it never had to be aware of. Validated on AMD Turin (132-CPU EPYC). The configuration converged to its target ratio in seconds and remained stable for 7+ hours continuously, with no perf core auto-throttle and no measurable drift in the achieved interleave ratio.
Configuration B: Intel PEBS L3-miss, vaddr ops, per-PID weighted-dest
PEBS reports vaddr samples in the context of the running task. DAMON's vaddr ops monitors a specific PID.
Setup (abridged):
echo 1 >
/sys/kernel/mm/damon/admin/kdamonds/nr_kdamonds
echo 1 > $D/contexts/nr_contexts
echo vaddr > $D/contexts/0/operationsecho 1 > $D/contexts/0/targets/nr_targets
echo $PID > $D/contexts/0/targets/0/pid_target
echo 0 > $D/contexts/0/targets/0/regions/nr_regions# PEBS MEM_LOAD_RETIRED.L3_MISS, frequency-based, vaddr-stamped:
echo 1 > $PE/nr_perf_events
echo 4 > $PE/0/type #PERF_TYPE_RAW
echo0x20d1> $PE/0/config # umask=0x20 event=0xd1
echo 0 > $PE/0/sample_phys_addr
echo 1 > $PE/0/freq
echo 5003 > $PE/0/sample_freq
echo 2 > $PE/0/precise_ip
echo 1 > $PE/0/wakeup_events# Single
migrate_hotscheme with two weighted destinations # (DRAM + CXL). Userspace tunes the steady-state interleave by # writing dests/{0,1}/weight.Quoted 6 lines
echo on > $D/state
Workload: 32 multichase multiload threads with a 4 GiB working set each (~128 GiB aggregate) running directly on the host, monitored by DAMON via the multiload PID. Validated on Intel Granite Rapids (144-CPU). Convergence is fast and the system is stable.
Thank you so much for sharing the great prototype implementation and test results!
I will try to make fast progress on milestone 1. I will hold reviewing details of this series for now, as there could be more changes. But in the high level, this looks promising.
Quoted 7 lines
[1] https://lore.kernel.org/[email protected]/
Thanks,
SJ[...]
From b11bb44d228d51272c6138559cb772297ba471ac Mon Sep 17 00:00:00 2001
From: Akinobu Mita <[email protected]>
Date: Wed, 27 May 2026 19:00:41 +0900
Subject: [PATCH 10/10] perf python: Add member access to config1 and config2
of evsel
This change is necessary to specify the same PMU event selection as the 'perf record' -e option from DAMON's userspace tools.
For example, a Python script like the following will allow you to obtain the values to be set in the type, config, config1, and config2 members of perf_event_attr by providing a symbolic event name.
import perf
if __name__ == '__main__':
evlist = perf.parse_events("cpu/mem-loads,ldlat=30/P")
for evsel in evlist:
print(f"{evsel}: type={evsel.type} config={evsel.config}",
f"config1={evsel.config1} config2={evsel.config2}")--- tools/perf/util/python.c | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/python.c +2 -0
@@ -1241,6 +1241,8 @@ static PyMemberDef pyrf_evsel__members[] = {evsel_attr_member_def (sample_type,T_ULONGLONG ,"attribute sample_type." ),evsel_attr_member_def (read_format,T_ULONGLONG ,"attribute read_format." ),evsel_attr_member_def (wakeup_events,T_UINT ,"attribute wakeup_events." ), +evsel_attr_member_def (config1,T_ULONGLONG ,"attribute config1." ), +evsel_attr_member_def (config2,T_ULONGLONG ,"attribute config2." ), { .name = NULL, }, };
Signature · 1 line
2.43.0
Hi SeongJae and Akinobu,
Thank you both for the warm reception and for the clear direction.
Quoted 34 lines · Akinobu Mita
Hello Ravi and SeongJae,
2026年5月30日(土) 9:05 SeongJae Park <[email protected]>:
Quoted 30 lines · On Fri, 29 May 2026 09:56:34 -0700 Ravi Jonnalagadda <[email protected]>…
Quoted 9 lines
This series introduces a vendor and PMU-agnostic substrate inside DAMON that consumes hardware-sampled access reports through the standard perf-event interface. Userspace selects the PMU through sysfs (raw type/config knobs), driving either Intel PEBS L3-miss sampling or AMD IBS Op sampling.
Why a unified perf-event substrate
Quoted 8 lines
Earlier hardware-sampled access-monitoring proposal [1] took an AMD IBS specific module path backend, owning its own probe configuration, sysfs knobs, and lifecycle.
SeongJae Park has previously highlighted the advantage of Akinobu Mita's perf-event proposal [2]: let DAMON register kernel-counter perf events and consume samples from any sampling PMU that perf core knows about. This series builds on that direction
Ah great, so we have no unclear challenge (additional loadable module support and conflicts with other IBS modules) on our road for now! That is, we can reuse the stable perf event interface and achieve all our goals! As I previously shared [1], it would take time, but I'm very optimistic about the success of this project. I don't like promising too much, but this project looks like something that we can "consider it done".
We can also say that the current candidate of the first damon_report_access()-based data attributes monitoring (milestone 2 [1] final deliverable) is the perf event based monitoring.
Glad this aligns with the milestone roadmap.
Quoted 6 lines
That's good!
From a quick look, it seems to have all the features I need, so I'd like to evaluate it based on Ravi's patch. If any extensions require changes, I will let you know as feedback.
Great, please do. Happy to fold any feedback into v2.
Quoted 5 lines
Ravi,
You can also add my Co-developed-by and Signed-off-by tags to the appropriate patch, so please post to the mailing list.
Will do. In v2 will add Co-developed-by and Signed-off-by tags
to patches 1, 4, and 5:
- Patch 1 (struct damon_perf_event{,_attr} + per-ctx list)
- Patch 4 (per-CPU SPSC ring drain + perf-event lifecycle)
- Patch 5 (vaddr/paddr perf-event backend)
Patches 2 and 3 are the sysfs surface that will move to the probes/filters interface; patch 6 is the unrelated damos_node_eligible_mem_bp tracepoint.
Quoted 7 lines
I am currently working on a change to allow selecting perf events from the damo tool by specifying the event name, similar to the perf record -e option (e.g., "cpu/mem-loads,ldlat=30,freq=5000/P" or "cpu/mem-stores,freq=5000/P").
I'll share the progress once it reaches a certain point. A change to the perf file, as shown in the attachment, will be necessary, but I believe it can be handled without changing Ravi's current patch set.
Nice. When the damo side is ready I will rerun the existing AMD IBS and Intel PEBS configurations through it.
Quoted 102 lines
Quoted 102 lines
Quoted 79 lines
with the changes we
needed to run it cross-vendor:- a per-CPU lockless ring between the NMI sample handler and the kdamond drain,
- per-CPU events that follow CPU hotplug cleanly,
- events fire only while the monitor is running -- created disabled, armed when kdamond starts, disarmed and drained when it stops,
- all-or-nothing init across CPUs: a partial-CPU create failure rolls the whole event back rather than leaving silent gaps,
- safe handling of vendor sample-validity flags so a stale or unpopulated address is never mistaken for a valid sample.What the series adds
Patch 1 introduces the substrate's data types: a per-event configuration struct and a per-context list to hang them on. A
CONFIG_PERF_EVENTS=nbuild folds to no-op stubs.Patch 2 exposes those types through sysfs. Each entry maps to one perf event and lets userspace pick the PMU and how to sample it: the raw PMU type/config, addressing flags, and period or frequency. The defaults are tuned for Intel PEBS; userspace overrides them for other PMUs.
Patch 3 wires the sysfs apply path so configured events get attached to the running monitoring context.
Patch 4 is the core of the series. It replaces the mutex-protected report queue with a per-CPU lockless ring fed from NMI by the perf overflow handler and drained once per sample tick by the kdamond. Drained reports are matched to monitored regions by binary search over a per-tick snapshot. The patch also wires the per-event lifecycle into kdamond: events arm when the monitor starts, disarm and drain when it stops, roll back cleanly when per-CPU init fails on some CPUs, and a second context that asks for the substrate while it is in use is rejected with
-EBUSY.Patch 5 is the perf-event backend. Two stateless overflow handlers (one vaddr-keyed, one paddr-keyed) are picked at event creation time and submit samples into the per-CPU ring. Vendor-specific sample validity is honored at this layer.
Patch 6 adds a tracepoint at every
node_eligible_mem_bpquota-goal evaluation so userspace can watch goal convergence without polling sysfs.Userspace setup model
Userspace selects the sampling PMU by pointing the perf event's
type/configat it, and chooses the scheme topology that suits the address space the PMU reports on. No module load or unload step is involved;echo on > statearms the substrate,echo off > statedisarms it.Two configurations were used for validation.
Configuration A: AMD IBS Op, paddr ops, system-wide PULL+PUSH tiering
IBS Op stamps samples with physical addresses, so DAMON reasons over every backing page in the system regardless of which task or guest touched it -- the substrate becomes a system-wide tiering controller.
Setup (abridged;
D=/sys/kernel/mm/damon/admin/kdamonds/0):echo 1 >
/sys/kernel/mm/damon/admin/kdamonds/nr_kdamonds
echo 1 > $D/contexts/nr_contexts
echo paddr > $D/contexts/0/operations# Two regions, one per NUMA node (DRAM + CXL). PA ranges # are derived per host from
/proc/iomem; omitted here. echo 1 > $D/contexts/0/targets/nr_targets
echo 2 > $D/contexts/0/targets/0/regions/nr_regions echo <DRAM_LO> > $D/contexts/0/targets/0/regions/0/start echo <DRAM_HI> > $D/contexts/0/targets/0/regions/0/end echo <CXL_LO> > $D/contexts/0/targets/0/regions/1/start echo <CXL_HI> > $D/contexts/0/targets/0/regions/1/endQuoted 10 lines
# IBS Op event, period-based, paddr-stamped:
PE=$D/contexts/0/monitoring_attrs/sample/perf_events echo 1 > $PE/nr_perf_events
echo $(cat/sys/bus/event_source/devices/ibs_op/type) > $PE/0/type
echo 0 > $PE/0/config
echo 1 > $PE/0/sample_phys_addr
echo 0 > $PE/0/freq
echo 262144 > $PE/0/sample_period
echo 0 > $PE/0/exclude_kernel
echo 0 > $PE/0/exclude_hvFYI, and as you may already know, the current plan [1] is to use the attributes probe interface. With it, the above IBS Op event setup part would look like,
mon_attr=/sys/kernel/mm/damon/admin/kdamonds/0/contexts/0/monitoring_attrs echo 1 > $mon_attr/probes/nr_probes
probe=$mon_attr/probes/0
echo 1 > $probe/filters/nr_filters
filter=$probe/filters/0
echoperf_event> $filter/type
echoibs_op> $filter/perf_event_type
echo Y > $filter/allow
Quoted 1 line
Quoted 1 line
Of course, more details could change later.
Understood. will hold for milestone 1.
Quoted 77 lines
Quoted 77 lines
Quoted 59 lines
# PULL scheme:
migrate_hottoward DRAM, gated on
#node_eligible_mem_bp(nid=DRAM)goal target_value=TARGET_BP. # addr filter restricts source to the CXL range.
# PUSH scheme:migrate_hottoward CXL, gated on
#node_eligible_mem_bp(nid=CXL)target_value=10000-TARGET_BP. # addr filter restricts source to the DRAM range.
# Both schemes aremigrate_hot; they converge from opposite # directions on the same hot working set.echo on > $D/state
Userspace tunes the steady-state DRAM:CXL split by writing the goal
target_values; DAMON's quota autotuner drives migration intensity to match.Workload: a QEMU/KVM guest pinned to one NUMA node, running 32 multichase multiload threads each touching a 4 GiB working set (~128 GiB aggregate) with the memcpy-libc kernel. The guest sees a flat single-NUMA layout and has no direct view of the host's tiering topology, yet its hot pages are migrated to DRAM and cold pages pushed to CXL by host-side DAMON acting on IBS-stamped physical addresses -- the application inside the guest benefits from tiering it never had to be aware of. Validated on AMD Turin (132-CPU EPYC). The configuration converged to its target ratio in seconds and remained stable for 7+ hours continuously, with no perf core auto-throttle and no measurable drift in the achieved interleave ratio.
Configuration B: Intel PEBS L3-miss, vaddr ops, per-PID weighted-dest
PEBS reports vaddr samples in the context of the running task. DAMON's vaddr ops monitors a specific PID.
Setup (abridged):
echo 1 >
/sys/kernel/mm/damon/admin/kdamonds/nr_kdamonds
echo 1 > $D/contexts/nr_contexts
echo vaddr > $D/contexts/0/operationsecho 1 > $D/contexts/0/targets/nr_targets
echo $PID > $D/contexts/0/targets/0/pid_target
echo 0 > $D/contexts/0/targets/0/regions/nr_regions# PEBS MEM_LOAD_RETIRED.L3_MISS, frequency-based, vaddr-stamped:
echo 1 > $PE/nr_perf_events
echo 4 > $PE/0/type #PERF_TYPE_RAW
echo0x20d1> $PE/0/config # umask=0x20 event=0xd1
echo 0 > $PE/0/sample_phys_addr
echo 1 > $PE/0/freq
echo 5003 > $PE/0/sample_freq
echo 2 > $PE/0/precise_ip
echo 1 > $PE/0/wakeup_events# Single
migrate_hotscheme with two weighted destinations # (DRAM + CXL). Userspace tunes the steady-state interleave by # writing dests/{0,1}/weight.Quoted 6 lines
echo on > $D/state
Workload: 32 multichase multiload threads with a 4 GiB working set each (~128 GiB aggregate) running directly on the host, monitored by DAMON via the multiload PID. Validated on Intel Granite Rapids (144-CPU). Convergence is fast and the system is stable.
Thank you so much for sharing the great prototype implementation and test results!
I will try to make fast progress on milestone 1. I will hold reviewing details of this series for now, as there could be more changes. But in the high level, this looks promising.
Quoted 7 lines
Quoted 7 lines
[1] https://lore.kernel.org/[email protected]/
Thanks,
SJ[...]
Thanks,
Ravi.
Hi Ravi,
Quoted 6 lines · Ravi Jonnalagadda
This series introduces a vendor and PMU-agnostic substrate inside DAMON that consumes hardware-sampled access reports through the standard perf-event interface. Userspace selects the PMU through sysfs (raw type/config knobs), driving either Intel PEBS L3-miss sampling or AMD IBS Op sampling.
[...]
Quoted 21 lines
Ravi Jonnalagadda (6):
mm/damon: add struct damon_perf_event{,_attr} and per-ctxperf_events
list
mm/damon/sysfs-sample: exposeperf_eventsconfiguration via sysfsmm/damon/sysfs: installperf_eventson applymm/damon/core: per-CPU SPSC ring drain anddamon_perf_eventlifecyclemm/damon/vaddr: implement perf-event access check mm/damon: adddamos_node_eligible_mem_bptracepointinclude/linux/damon.h | 80 +++++ include/trace/events/damon.h | 49 +++ mm/damon/core.c | 403 ++++++++++++++++++++---- mm/damon/ops-common.h | 39 +++ mm/damon/sysfs-common.h | 6 + mm/damon/sysfs-sample.c | 579 +++++++++++++++++++++++++++++++++++ mm/damon/sysfs.c | 3 + mm/damon/vaddr.c | 267 ++++++++++++++++ 8 files changed, 1370 insertions(+), 56 deletions(-)
Quoted 1 line
base-commit:
4c8ad15abf15eb480d3ad85f902001e35465ef18
I wasn't able to apply this patch series to the linux (and linux-next) mainline branch, and also had trouble identifying the source of the base commit.
Would you mind sharing where this baseline is from?
Thanks in advance!
Best Regards,
Zeng Heng
SeongJae Park
maintainerHello Zeng,
Quoted 33 lines · On Tue, 23 Jun 2026 22:08:03 +0800 Zeng Heng <[email protected]> wrote:
Hi Ravi,
Quoted 6 lines · Ravi Jonnalagadda
This series introduces a vendor and PMU-agnostic substrate inside DAMON that consumes hardware-sampled access reports through the standard perf-event interface. Userspace selects the PMU through sysfs (raw type/config knobs), driving either Intel PEBS L3-miss sampling or AMD IBS Op sampling.
[...]
Quoted 21 lines
Ravi Jonnalagadda (6):
mm/damon: add struct damon_perf_event{,_attr} and per-ctxperf_events
list
mm/damon/sysfs-sample: exposeperf_eventsconfiguration via sysfsmm/damon/sysfs: installperf_eventson applymm/damon/core: per-CPU SPSC ring drain anddamon_perf_eventlifecyclemm/damon/vaddr: implement perf-event access check mm/damon: adddamos_node_eligible_mem_bptracepointinclude/linux/damon.h | 80 +++++ include/trace/events/damon.h | 49 +++ mm/damon/core.c | 403 ++++++++++++++++++++---- mm/damon/ops-common.h | 39 +++ mm/damon/sysfs-common.h | 6 + mm/damon/sysfs-sample.c | 579 +++++++++++++++++++++++++++++++++++ mm/damon/sysfs.c | 3 + mm/damon/vaddr.c | 267 ++++++++++++++++ 8 files changed, 1370 insertions(+), 56 deletions(-)
Quoted 7 lines
Quoted 1 line
base-commit:
4c8ad15abf15eb480d3ad85f902001e35465ef18I wasn't able to apply this patch series to the linux (and linux-next) mainline branch, and also had trouble identifying the source of the base commit.
Would you mind sharing where this baseline is from?
TLDR: I pushed [1] a tree having this series applied on top of the baseline to GitHub. Please feel free to use it.
I think the baseline was a commit on damon/next tree [2]. Because damon/next is continuously rebased, we cannot get the commit in a simple way. Fortunately the commit is still available on my local tree. So I applied this patch series on top of the commit and pushed [1] to a branch of DAMON kernel tree at GitHub.
Note that the branch is not guaranteed to exist there for long term. But hopefully this series will be merged into the mainline before that.
[1] https://github.com/damonitor/linux/tree/ravi_hw_sampled_access_reports_rfc_v1
[2] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees
Thanks,
SJ
[...]
Hi SeongJae,
Quoted 56 lines · SeongJae Park
Hello Zeng,
Quoted 33 lines · On Tue, 23 Jun 2026 22:08:03 +0800 Zeng Heng <[email protected]> wrote:
Hi Ravi,
Quoted 6 lines · Ravi Jonnalagadda
This series introduces a vendor and PMU-agnostic substrate inside DAMON that consumes hardware-sampled access reports through the standard perf-event interface. Userspace selects the PMU through sysfs (raw type/config knobs), driving either Intel PEBS L3-miss sampling or AMD IBS Op sampling.
[...]
Quoted 21 lines
Ravi Jonnalagadda (6):
mm/damon: add struct damon_perf_event{,_attr} and per-ctxperf_events
list
mm/damon/sysfs-sample: exposeperf_eventsconfiguration via sysfsmm/damon/sysfs: installperf_eventson applymm/damon/core: per-CPU SPSC ring drain anddamon_perf_eventlifecyclemm/damon/vaddr: implement perf-event access check mm/damon: adddamos_node_eligible_mem_bptracepointinclude/linux/damon.h | 80 +++++ include/trace/events/damon.h | 49 +++ mm/damon/core.c | 403 ++++++++++++++++++++---- mm/damon/ops-common.h | 39 +++ mm/damon/sysfs-common.h | 6 + mm/damon/sysfs-sample.c | 579 +++++++++++++++++++++++++++++++++++ mm/damon/sysfs.c | 3 + mm/damon/vaddr.c | 267 ++++++++++++++++ 8 files changed, 1370 insertions(+), 56 deletions(-)Quoted 7 lines
Quoted 1 line
base-commit:
4c8ad15abf15eb480d3ad85f902001e35465ef18I wasn't able to apply this patch series to the linux (and linux-next) mainline branch, and also had trouble identifying the source of the base commit.
Would you mind sharing where this baseline is from?
TLDR: I pushed [1] a tree having this series applied on top of the baseline to GitHub. Please feel free to use it.
I think the baseline was a commit on damon/next tree [2]. Because damon/next is continuously rebased, we cannot get the commit in a simple way. Fortunately the commit is still available on my local tree. So I applied this patch series on top of the commit and pushed [1] to a branch of DAMON kernel tree at GitHub.
Note that the branch is not guaranteed to exist there for long term. But hopefully this series will be merged into the mainline before that.
Quoted 7 lines
[1] https://github.com/damonitor/linux/tree/ravi_hw_sampled_access_reports_rfc_v1
[2] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-treesThanks,
SJ
Thanks a lot for providing the branch on GitHub. I've pulled it and confirmed it builds cleanly on my end.
Appreciate the help!
Best Regards,
Zeng Heng
Hello Zeng and SJ,
Glad the branch built cleanly for you.
You can also refer to this branch, which carries the same series
with a few fixes from an internal sashiko run, folded in preparation for v2.
https://github.com/ravis-opensrc/linux/tree/damon/perf-event-integrated-rfc-v2
Note this is still based on the v1 sysfs surface (raw type/config
knobs). The v2 I post to the list will reshape that userspace surface to align with SJ's milestone plan, so the configuration interface will change:
https://lore.kernel.org/all/[email protected]/
Happy to help if you hit anything while testing — particularly
interested in which PMU you're sampling with (PEBS / IBS / something on your platform).
Best,
Ravi
Quoted 76 lines · Zeng Heng
Hi SeongJae,
Quoted 56 lines · SeongJae Park
Hello Zeng,
Quoted 33 lines · On Tue, 23 Jun 2026 22:08:03 +0800 Zeng Heng <[email protected]> wrote:
Hi Ravi,
Quoted 6 lines · Ravi Jonnalagadda
This series introduces a vendor and PMU-agnostic substrate inside DAMON that consumes hardware-sampled access reports through the standard perf-event interface. Userspace selects the PMU through sysfs (raw type/config knobs), driving either Intel PEBS L3-miss sampling or AMD IBS Op sampling.
[...]
Quoted 21 lines
Ravi Jonnalagadda (6):
mm/damon: add struct damon_perf_event{,_attr} and per-ctxperf_events
list
mm/damon/sysfs-sample: exposeperf_eventsconfiguration via sysfsmm/damon/sysfs: installperf_eventson applymm/damon/core: per-CPU SPSC ring drain anddamon_perf_eventlifecyclemm/damon/vaddr: implement perf-event access check mm/damon: adddamos_node_eligible_mem_bptracepointinclude/linux/damon.h | 80 +++++ include/trace/events/damon.h | 49 +++ mm/damon/core.c | 403 ++++++++++++++++++++---- mm/damon/ops-common.h | 39 +++ mm/damon/sysfs-common.h | 6 + mm/damon/sysfs-sample.c | 579 +++++++++++++++++++++++++++++++++++ mm/damon/sysfs.c | 3 + mm/damon/vaddr.c | 267 ++++++++++++++++ 8 files changed, 1370 insertions(+), 56 deletions(-)Quoted 7 lines
Quoted 1 line
base-commit:
4c8ad15abf15eb480d3ad85f902001e35465ef18I wasn't able to apply this patch series to the linux (and linux-next) mainline branch, and also had trouble identifying the source of the base commit.
Would you mind sharing where this baseline is from?
TLDR: I pushed [1] a tree having this series applied on top of the baseline to GitHub. Please feel free to use it.
I think the baseline was a commit on damon/next tree [2]. Because damon/next is continuously rebased, we cannot get the commit in a simple way. Fortunately the commit is still available on my local tree. So I applied this patch series on top of the commit and pushed [1] to a branch of DAMON kernel tree at GitHub.
Note that the branch is not guaranteed to exist there for long term. But hopefully this series will be merged into the mainline before that.
Quoted 7 lines
[1] https://github.com/damonitor/linux/tree/ravi_hw_sampled_access_reports_rfc_v1
[2] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-treesThanks,
SJThanks a lot for providing the branch on GitHub. I've pulled it and confirmed it builds cleanly on my end.
Appreciate the help!
Best Regards,
Zeng Heng
On Fri, 29 May 2026 09:56:34 -0700 Ravi Jonnalagadda <[email protected]> wrote:
Hi Ravi,
I've been building on your RFC [1] to add ARM SPE support to DAMON, and wanted to share what we've implemented and where things stand.
Your series provides the vendor- and PMU-agnostic reporting substrate, including the per-CPU SPSC ring and kdamond drain:
Quoted 43 lines
This series introduces a vendor and PMU-agnostic substrate inside DAMON that consumes hardware-sampled access reports through the standard perf-event interface. Userspace selects the PMU through sysfs (raw type/config knobs), driving either Intel PEBS L3-miss sampling or AMD IBS Op sampling.
Why a unified perf-event substrate
Earlier hardware-sampled access-monitoring proposal [1] took an AMD IBS specific module path backend, owning its own probe configuration, sysfs knobs, and lifecycle.
SeongJae Park has previously highlighted the advantage of Akinobu Mita's perf-event proposal [2]: let DAMON register kernel-counter perf events and consume samples from any sampling PMU that perf core knows about. This series builds on that direction with the changes we needed to run it cross-vendor:
- a per-CPU lockless ring between the NMI sample handler and the kdamond drain,
- per-CPU events that follow CPU hotplug cleanly,
- events fire only while the monitor is running -- created disabled, armed when kdamond starts, disarmed and drained when it stops,
- all-or-nothing init across CPUs: a partial-CPU create failure rolls the whole event back rather than leaving silent gaps,
- safe handling of vendor sample-validity flags so a stale or unpopulated address is never mistaken for a valid sample.What the series adds
Patch 1 introduces the substrate's data types: a per-event configuration struct and a per-context list to hang them on. A
CONFIG_PERF_EVENTS=nbuild folds to no-op stubs.Patch 2 exposes those types through sysfs. Each entry maps to one perf event and lets userspace pick the PMU and how to sample it: the raw PMU type/config, addressing flags, and period or frequency. The defaults are tuned for Intel PEBS; userspace overrides them for other PMUs.
Patch 3 wires the sysfs apply path so configured events get attached to the running monitoring context.
Quoted 9 lines
Patch 4 is the core of the series. It replaces the mutex-protected report queue with a per-CPU lockless ring fed from NMI by the perf overflow handler and drained once per sample tick by the kdamond. Drained reports are matched to monitored regions by binary search over a per-tick snapshot. The patch also wires the per-event lifecycle into kdamond: events arm when the monitor starts, disarm and drain when it stops, roll back cleanly when per-CPU init fails on some CPUs, and a second context that asks for the substrate while it is in use is rejected with
-EBUSY.
ARM SPE delivers samples through the AUX trace buffer rather than the regular perf overflow callback, so perf_event_create_kernel_counter() does not provide a way to consume the SPE AUX trace stream directly. To close this gap, we developed two pieces:
1. A perf AUX kernel-consumer API [2] that allows in-kernel code to consume AUX trace data.
2. A DAMON ARM SPE AUX backend [3] that feeds the decoded access reports into damon_report_access(). This is a transport layer and does not change DAMON's matching logic; it provides another way for hardware samples to enter the existing reporting pipeline.
While bringing up the SPE backend, we kept hitting the same question:
"why does the PMU report zero accesses?" The answer could be anywhere in the pipeline — event creation, binding, enabling, the PMU itself, the ring, or the drain — and without per-stage visibility, the only practical way to debug this was to add printk instrumentation throughout the pipeline.
So we also developed a lightweight PMU-agnostic observability framework
[4] that instruments the pipeline with per-CPU monotonic counters and tracepoints. It immediately helped diagnose the initial SPE issue:
event creation, binding and enabling all passed, while the PMU produced no samples. This pointed to a PMU-level issue rather than a DAMON pipeline issue, and confirmed that SPE needed an AUX-based backend.
We used the framework throughout the AUX backend development to verify each stage of the pipeline. With the completed AUX backend, the same framework showed a functional end-to-end pipeline: 27/0/0 selftest results, 47,248 callbacks, with all seven stages observed as expected.
One interesting observation is that the framework's ring counters showed 32,087 dropped reports. This is about 68% of the 47,248 callbacks. The current DAMON_REPORT_RING_SIZE=256 and drain interval were designed around much lower sampling rates, while SPE can produce samples at a much higher rate. On the current Kunpeng 920 setup, the SPE sample rate can fill the 256-entry ring much faster than the current drain interval.
This looks more like a throughput/rate mismatch than a correctness issue with the reporting path. For high-rate PMUs such as SPE, do you think the ring size or drain interval should eventually be tunable?
The observability framework is PMU-agnostic and is posted as a standalone series [4], so that other PMU backends can reuse the same instrumentation.
The relationship between the pieces is roughly:
Ravi's hardware-sampled reporting infrastructure
|
+---------+---------+
| |
perf overflow ARM SPE AUX
| |
| AUX kernel consumer
| |
| SPE AUX backend
| |
+---------+---------+
|
damon_report_access()
|
report ring
|
kdamond drainThe observability framework is orthogonal to these transport paths and can observe both of them.
Everything has been tested on Kunpeng 920 (256 CPUs, ARM SPE). The DAMON AUX backend [3] and the observability framework [4] are separate RFC series, both based on the infrastructure from [1].
Would appreciate any feedback on the approach, especially on extending the reporting infrastructure from perf overflow samples to AUX-based PMUs.
Thanks for the foundation — the per-CPU reporting and drain infrastructure provided a useful base for the AUX path.
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/
Quoted 139 lines
Patch 5 is the perf-event backend. Two stateless overflow handlers (one vaddr-keyed, one paddr-keyed) are picked at event creation time and submit samples into the per-CPU ring. Vendor-specific sample validity is honored at this layer.
Patch 6 adds a tracepoint at every
node_eligible_mem_bpquota-goal evaluation so userspace can watch goal convergence without polling sysfs.Userspace setup model
Userspace selects the sampling PMU by pointing the perf event's
type/configat it, and chooses the scheme topology that suits the address space the PMU reports on. No module load or unload step is involved;echo on > statearms the substrate,echo off > statedisarms it.Two configurations were used for validation.
Configuration A: AMD IBS Op, paddr ops, system-wide PULL+PUSH tiering
IBS Op stamps samples with physical addresses, so DAMON reasons over every backing page in the system regardless of which task or guest touched it -- the substrate becomes a system-wide tiering controller.
Setup (abridged;
D=/sys/kernel/mm/damon/admin/kdamonds/0):echo 1 >
/sys/kernel/mm/damon/admin/kdamonds/nr_kdamonds
echo 1 > $D/contexts/nr_contexts
echo paddr > $D/contexts/0/operations# Two regions, one per NUMA node (DRAM + CXL). PA ranges # are derived per host from
/proc/iomem; omitted here. echo 1 > $D/contexts/0/targets/nr_targets
echo 2 > $D/contexts/0/targets/0/regions/nr_regions echo <DRAM_LO> > $D/contexts/0/targets/0/regions/0/start echo <DRAM_HI> > $D/contexts/0/targets/0/regions/0/end echo <CXL_LO> > $D/contexts/0/targets/0/regions/1/start echo <CXL_HI> > $D/contexts/0/targets/0/regions/1/end# IBS Op event, period-based, paddr-stamped:
PE=$D/contexts/0/monitoring_attrs/sample/perf_events echo 1 > $PE/nr_perf_events
echo $(cat/sys/bus/event_source/devices/ibs_op/type) > $PE/0/type
echo 0 > $PE/0/config
echo 1 > $PE/0/sample_phys_addr
echo 0 > $PE/0/freq
echo 262144 > $PE/0/sample_period
echo 0 > $PE/0/exclude_kernel
echo 0 > $PE/0/exclude_hv# PULL scheme:
migrate_hottoward DRAM, gated on
#node_eligible_mem_bp(nid=DRAM)goal target_value=TARGET_BP. # addr filter restricts source to the CXL range.
# PUSH scheme:migrate_hottoward CXL, gated on
#node_eligible_mem_bp(nid=CXL)target_value=10000-TARGET_BP. # addr filter restricts source to the DRAM range.
# Both schemes aremigrate_hot; they converge from opposite # directions on the same hot working set.echo on > $D/state
Userspace tunes the steady-state DRAM:CXL split by writing the goal
target_values; DAMON's quota autotuner drives migration intensity to match.Workload: a QEMU/KVM guest pinned to one NUMA node, running 32 multichase multiload threads each touching a 4 GiB working set (~128 GiB aggregate) with the memcpy-libc kernel. The guest sees a flat single-NUMA layout and has no direct view of the host's tiering topology, yet its hot pages are migrated to DRAM and cold pages pushed to CXL by host-side DAMON acting on IBS-stamped physical addresses -- the application inside the guest benefits from tiering it never had to be aware of. Validated on AMD Turin (132-CPU EPYC). The configuration converged to its target ratio in seconds and remained stable for 7+ hours continuously, with no perf core auto-throttle and no measurable drift in the achieved interleave ratio.
Configuration B: Intel PEBS L3-miss, vaddr ops, per-PID weighted-dest
PEBS reports vaddr samples in the context of the running task. DAMON's vaddr ops monitors a specific PID.
Setup (abridged):
echo 1 >
/sys/kernel/mm/damon/admin/kdamonds/nr_kdamonds
echo 1 > $D/contexts/nr_contexts
echo vaddr > $D/contexts/0/operationsecho 1 > $D/contexts/0/targets/nr_targets
echo $PID > $D/contexts/0/targets/0/pid_target
echo 0 > $D/contexts/0/targets/0/regions/nr_regions# PEBS MEM_LOAD_RETIRED.L3_MISS, frequency-based, vaddr-stamped:
echo 1 > $PE/nr_perf_events
echo 4 > $PE/0/type #PERF_TYPE_RAW
echo0x20d1> $PE/0/config # umask=0x20 event=0xd1
echo 0 > $PE/0/sample_phys_addr
echo 1 > $PE/0/freq
echo 5003 > $PE/0/sample_freq
echo 2 > $PE/0/precise_ip
echo 1 > $PE/0/wakeup_events# Single
migrate_hotscheme with two weighted destinations # (DRAM + CXL). Userspace tunes the steady-state interleave by # writing dests/{0,1}/weight.echo on > $D/state
Workload: 32 multichase multiload threads with a 4 GiB working set each (~128 GiB aggregate) running directly on the host, monitored by DAMON via the multiload PID. Validated on Intel Granite Rapids (144-CPU). Convergence is fast and the system is stable.
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/[email protected]Ravi Jonnalagadda (6):
mm/damon: add struct damon_perf_event{,_attr} and per-ctxperf_events
list
mm/damon/sysfs-sample: exposeperf_eventsconfiguration via sysfsmm/damon/sysfs: installperf_eventson applymm/damon/core: per-CPU SPSC ring drain anddamon_perf_eventlifecyclemm/damon/vaddr: implement perf-event access check mm/damon: adddamos_node_eligible_mem_bptracepointinclude/linux/damon.h | 80 +++++ include/trace/events/damon.h | 49 +++ mm/damon/core.c | 403 ++++++++++++++++++++---- mm/damon/ops-common.h | 39 +++ mm/damon/sysfs-common.h | 6 + mm/damon/sysfs-sample.c | 579 +++++++++++++++++++++++++++++++++++ mm/damon/sysfs.c | 3 + mm/damon/vaddr.c | 267 ++++++++++++++++ 8 files changed, 1370 insertions(+), 56 deletions(-)
Quoted 5 lines
base-commit:
4c8ad15abf15eb480d3ad85f902001e35465ef18Signature · 1 line
2.43.0
Sent using hkml (https://github.com/sjp38/hackermail)
Quoted 114 lines · Kunwu Chan
On Fri, 29 May 2026 09:56:34 -0700 Ravi Jonnalagadda <[email protected]> wrote:
Hi Ravi,
I've been building on your RFC [1] to add ARM SPE support to DAMON, and wanted to share what we've implemented and where things stand.
Your series provides the vendor- and PMU-agnostic reporting substrate, including the per-CPU SPSC ring and kdamond drain:
Quoted 43 lines
This series introduces a vendor and PMU-agnostic substrate inside DAMON that consumes hardware-sampled access reports through the standard perf-event interface. Userspace selects the PMU through sysfs (raw type/config knobs), driving either Intel PEBS L3-miss sampling or AMD IBS Op sampling.
Why a unified perf-event substrate
Earlier hardware-sampled access-monitoring proposal [1] took an AMD IBS specific module path backend, owning its own probe configuration, sysfs knobs, and lifecycle.
SeongJae Park has previously highlighted the advantage of Akinobu Mita's perf-event proposal [2]: let DAMON register kernel-counter perf events and consume samples from any sampling PMU that perf core knows about. This series builds on that direction with the changes we needed to run it cross-vendor:
- a per-CPU lockless ring between the NMI sample handler and the kdamond drain,
- per-CPU events that follow CPU hotplug cleanly,
- events fire only while the monitor is running -- created disabled, armed when kdamond starts, disarmed and drained when it stops,
- all-or-nothing init across CPUs: a partial-CPU create failure rolls the whole event back rather than leaving silent gaps,
- safe handling of vendor sample-validity flags so a stale or unpopulated address is never mistaken for a valid sample.What the series adds
Patch 1 introduces the substrate's data types: a per-event configuration struct and a per-context list to hang them on. A
CONFIG_PERF_EVENTS=nbuild folds to no-op stubs.Patch 2 exposes those types through sysfs. Each entry maps to one perf event and lets userspace pick the PMU and how to sample it: the raw PMU type/config, addressing flags, and period or frequency. The defaults are tuned for Intel PEBS; userspace overrides them for other PMUs.
Patch 3 wires the sysfs apply path so configured events get attached to the running monitoring context.
Quoted 9 lines
Patch 4 is the core of the series. It replaces the mutex-protected report queue with a per-CPU lockless ring fed from NMI by the perf overflow handler and drained once per sample tick by the kdamond. Drained reports are matched to monitored regions by binary search over a per-tick snapshot. The patch also wires the per-event lifecycle into kdamond: events arm when the monitor starts, disarm and drain when it stops, roll back cleanly when per-CPU init fails on some CPUs, and a second context that asks for the substrate while it is in use is rejected with
-EBUSY.ARM SPE delivers samples through the AUX trace buffer rather than the regular perf overflow callback, so
perf_event_create_kernel_counter()does not provide a way to consume the SPE AUX trace stream directly. To close this gap, we developed two pieces:1. A perf AUX kernel-consumer API [2] that allows in-kernel code to consume AUX trace data.
2. A DAMON ARM SPE AUX backend [3] that feeds the decoded access reports into
damon_report_access(). This is a transport layer and does not change DAMON's matching logic; it provides another way for hardware samples to enter the existing reporting pipeline.While bringing up the SPE backend, we kept hitting the same question:
"why does the PMU report zero accesses?" The answer could be anywhere in the pipeline — event creation, binding, enabling, the PMU itself, the ring, or the drain — and without per-stage visibility, the only practical way to debug this was to add printk instrumentation throughout the pipeline.So we also developed a lightweight PMU-agnostic observability framework
[4] that instruments the pipeline with per-CPU monotonic counters and tracepoints. It immediately helped diagnose the initial SPE issue:
event creation, binding and enabling all passed, while the PMU produced no samples. This pointed to a PMU-level issue rather than a DAMON pipeline issue, and confirmed that SPE needed an AUX-based backend.We used the framework throughout the AUX backend development to verify each stage of the pipeline. With the completed AUX backend, the same framework showed a functional end-to-end pipeline: 27/0/0 selftest results, 47,248 callbacks, with all seven stages observed as expected.
One interesting observation is that the framework's ring counters showed 32,087 dropped reports. This is about 68% of the 47,248 callbacks. The current
DAMON_REPORT_RING_SIZE=256and drain interval were designed around much lower sampling rates, while SPE can produce samples at a much higher rate. On the current Kunpeng 920 setup, the SPE sample rate can fill the 256-entry ring much faster than the current drain interval.This looks more like a throughput/rate mismatch than a correctness issue with the reporting path. For high-rate PMUs such as SPE, do you think the ring size or drain interval should eventually be tunable?
The observability framework is PMU-agnostic and is posted as a standalone series [4], so that other PMU backends can reuse the same instrumentation.
The relationship between the pieces is roughly:
Ravi's hardware-sampled reporting infrastructure
Quoted 17 lines
|
+---------+---------+
| |
perf overflow ARM SPE AUX
| |
| AUX kernel consumer
| |
| SPE AUX backend
| |
+---------+---------+
|
damon_report_access()
|
report ring
|
kdamond drainHello Kunwu,
Thanks for this, and sorry for the slow reply. I have been off for a couple
of days this week.
The shape you picked is exactly the one the RFC was hoping for:
a new transport feeding the same damon_report_access() sink. Reaching an AUX-only PMU from an in-kernel consumer is a real gap, and closing it with a small generic API in perf/core is the right layering. Good to see the substrate turn out to be useful this way.
Two things to flag:
1. The event-configuration surface changes in my upcoming v2
------------------------------------------------
Your series is based on the v1 substrate, and the way an event is configured is the part that moves most.
In v1 a perf event is a property of the sampling attributes: a flat array under
monitoring_attrs/sample/perf_events/nr_perf_events monitoring_attrs/sample/perf_events/<N>/{type,config,freq,sample_period}
which is what your selftest drives, and struct damon_perf_event is the in-kernel object.
In v2 the configuration hangs off a *probe* instead. A probe is the unit of "one thing DAMON measures about a region", it carries a weight, and the region score is the weighted sum over probes. A perf event is then one kind of *prep* action on a probe -- prep_action = "perf_event" -- so the same probe machinery covers both a PTE-scanning probe and a hardware-sampled one, and several can coexist and be weighted against each other:
monitoring_attrs/probes/nr_probes monitoring_attrs/probes/<N>/weight monitoring_attrs/probes/<N>/filters/... monitoring_attrs/probes/<N>/preps/nr_preps
monitoring_attrs/probes/<N>/preps/<M>/prep_action <- "perf_event"
monitoring_attrs/probes/<N>/preps/<M>/{type,config,config1,config2,
sample_period,sample_freq,freq,wakeup_events,precise_ip,
sample_phys_addr,sample_weight_struct,exclude_kernel,exclude_hv,
single_instance}So for SPE the freq=0 / sample_period=256 pair your selftest sets keeps the same names, just under preps/<M>/ rather than perf_events/<N>/.
This is done as part of the roadmap plan of SJ.
https://lore.kernel.org/damon/[email protected]/
2. The 67.9% drop rate is fan-in, not sizing
--------------------------------------------
You asked whether DAMON_REPORT_RING_SIZE and the drain interval should become tunable. I don't think either knob is the fix here.
- The cause is where the drain runs, not how big the ring is. damon_report_access() picks the ring with this_cpu_ptr(), i.e. by the CPU of the caller. Decoding every CPU's AUX buffer from the single kdamond thread therefore funnels the whole machine into one ring, so capacity per aggregation tick is 255 rather than 255 * nCPUs.
- I avoided it by draining on the source CPU -- per-CPU parse work queued over the cpumask, so each ring keeps a single producer and the ring geometry stays as is. One detail worth knowing: it has to be system_percpu_wq, since an unbound queue silently ignores queue_work_on()'s CPU targeting. Your ops already carry a cpu argument, so it should be a contained change.
- I did a quick sanity test on a plain QEMU guest with a virtual PMU in AUX mode on the branch below with your RFC patches.
https://github.com/ravis-opensrc/linux.git
branch damon/perf-rfc-v2-08-20-26
Thanks again for taking this on and sharing your results.
Best Regards,
Ravi.
Quoted 166 lines
The observability framework is orthogonal to these transport paths and can observe both of them.
Everything has been tested on Kunpeng 920 (256 CPUs, ARM SPE). The DAMON AUX backend [3] and the observability framework [4] are separate RFC series, both based on the infrastructure from [1].
Would appreciate any feedback on the approach, especially on extending the reporting infrastructure from perf overflow samples to AUX-based PMUs.
Thanks for the foundation — the per-CPU reporting and drain infrastructure provided a useful base for the AUX path.
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/Quoted 139 lines
Patch 5 is the perf-event backend. Two stateless overflow handlers (one vaddr-keyed, one paddr-keyed) are picked at event creation time and submit samples into the per-CPU ring. Vendor-specific sample validity is honored at this layer.
Patch 6 adds a tracepoint at every
node_eligible_mem_bpquota-goal evaluation so userspace can watch goal convergence without polling sysfs.Userspace setup model
Userspace selects the sampling PMU by pointing the perf event's
type/configat it, and chooses the scheme topology that suits the address space the PMU reports on. No module load or unload step is involved;echo on > statearms the substrate,echo off > statedisarms it.Two configurations were used for validation.
Configuration A: AMD IBS Op, paddr ops, system-wide PULL+PUSH tiering
IBS Op stamps samples with physical addresses, so DAMON reasons over every backing page in the system regardless of which task or guest touched it -- the substrate becomes a system-wide tiering controller.
Setup (abridged;
D=/sys/kernel/mm/damon/admin/kdamonds/0):echo 1 >
/sys/kernel/mm/damon/admin/kdamonds/nr_kdamonds
echo 1 > $D/contexts/nr_contexts
echo paddr > $D/contexts/0/operations# Two regions, one per NUMA node (DRAM + CXL). PA ranges # are derived per host from
/proc/iomem; omitted here. echo 1 > $D/contexts/0/targets/nr_targets
echo 2 > $D/contexts/0/targets/0/regions/nr_regions echo <DRAM_LO> > $D/contexts/0/targets/0/regions/0/start echo <DRAM_HI> > $D/contexts/0/targets/0/regions/0/end echo <CXL_LO> > $D/contexts/0/targets/0/regions/1/start echo <CXL_HI> > $D/contexts/0/targets/0/regions/1/end# IBS Op event, period-based, paddr-stamped:
PE=$D/contexts/0/monitoring_attrs/sample/perf_events echo 1 > $PE/nr_perf_events
echo $(cat/sys/bus/event_source/devices/ibs_op/type) > $PE/0/type
echo 0 > $PE/0/config
echo 1 > $PE/0/sample_phys_addr
echo 0 > $PE/0/freq
echo 262144 > $PE/0/sample_period
echo 0 > $PE/0/exclude_kernel
echo 0 > $PE/0/exclude_hv# PULL scheme:
migrate_hottoward DRAM, gated on
#node_eligible_mem_bp(nid=DRAM)goal target_value=TARGET_BP. # addr filter restricts source to the CXL range.
# PUSH scheme:migrate_hottoward CXL, gated on
#node_eligible_mem_bp(nid=CXL)target_value=10000-TARGET_BP. # addr filter restricts source to the DRAM range.
# Both schemes aremigrate_hot; they converge from opposite # directions on the same hot working set.echo on > $D/state
Userspace tunes the steady-state DRAM:CXL split by writing the goal
target_values; DAMON's quota autotuner drives migration intensity to match.Workload: a QEMU/KVM guest pinned to one NUMA node, running 32 multichase multiload threads each touching a 4 GiB working set (~128 GiB aggregate) with the memcpy-libc kernel. The guest sees a flat single-NUMA layout and has no direct view of the host's tiering topology, yet its hot pages are migrated to DRAM and cold pages pushed to CXL by host-side DAMON acting on IBS-stamped physical addresses -- the application inside the guest benefits from tiering it never had to be aware of. Validated on AMD Turin (132-CPU EPYC). The configuration converged to its target ratio in seconds and remained stable for 7+ hours continuously, with no perf core auto-throttle and no measurable drift in the achieved interleave ratio.
Configuration B: Intel PEBS L3-miss, vaddr ops, per-PID weighted-dest
PEBS reports vaddr samples in the context of the running task. DAMON's vaddr ops monitors a specific PID.
Setup (abridged):
echo 1 >
/sys/kernel/mm/damon/admin/kdamonds/nr_kdamonds
echo 1 > $D/contexts/nr_contexts
echo vaddr > $D/contexts/0/operationsecho 1 > $D/contexts/0/targets/nr_targets
echo $PID > $D/contexts/0/targets/0/pid_target
echo 0 > $D/contexts/0/targets/0/regions/nr_regions# PEBS MEM_LOAD_RETIRED.L3_MISS, frequency-based, vaddr-stamped:
echo 1 > $PE/nr_perf_events
echo 4 > $PE/0/type #PERF_TYPE_RAW
echo0x20d1> $PE/0/config # umask=0x20 event=0xd1
echo 0 > $PE/0/sample_phys_addr
echo 1 > $PE/0/freq
echo 5003 > $PE/0/sample_freq
echo 2 > $PE/0/precise_ip
echo 1 > $PE/0/wakeup_events# Single
migrate_hotscheme with two weighted destinations # (DRAM + CXL). Userspace tunes the steady-state interleave by # writing dests/{0,1}/weight.echo on > $D/state
Workload: 32 multichase multiload threads with a 4 GiB working set each (~128 GiB aggregate) running directly on the host, monitored by DAMON via the multiload PID. Validated on Intel Granite Rapids (144-CPU). Convergence is fast and the system is stable.
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/[email protected]Ravi Jonnalagadda (6):
mm/damon: add struct damon_perf_event{,_attr} and per-ctxperf_events
list
mm/damon/sysfs-sample: exposeperf_eventsconfiguration via sysfsmm/damon/sysfs: installperf_eventson applymm/damon/core: per-CPU SPSC ring drain anddamon_perf_eventlifecyclemm/damon/vaddr: implement perf-event access check mm/damon: adddamos_node_eligible_mem_bptracepointinclude/linux/damon.h | 80 +++++ include/trace/events/damon.h | 49 +++ mm/damon/core.c | 403 ++++++++++++++++++++---- mm/damon/ops-common.h | 39 +++ mm/damon/sysfs-common.h | 6 + mm/damon/sysfs-sample.c | 579 +++++++++++++++++++++++++++++++++++ mm/damon/sysfs.c | 3 + mm/damon/vaddr.c | 267 ++++++++++++++++ 8 files changed, 1370 insertions(+), 56 deletions(-)Quoted 5 lines
base-commit:
4c8ad15abf15eb480d3ad85f902001e35465ef18--
2.43.0Sent using hkml (https://github.com/sjp38/hackermail)
Hi Ravi,
Thanks for the detailed reply. The fan-in diagnosis makes perfect sense.
Quoted 4 lines
Your series is based on the v1 substrate, and the way an event is configured is the part that moves most.
[...]
Glad to hear v2 is on the way. The probe-based model is actually something I encountered while building the AUX backend. When multiple sources can feed the same region (e.g. PTE scanning + SPE/IBS), the question of how to combine their reports becomes interesting.
For example, CXL tiering may care about physical-address locality, while per-process monitoring may need virtual-address attribution. How do you see probe weights being determined — is that expected to be scenario-specific, or is there a more general principle behind the weighting?
Quoted 5 lines
2. The 67.9% drop rate is fan-in, not sizing
---
[...]
I completely missed this. The observability framework showed the symptom (67.9% drop) but got the root cause wrong — it's not a ring sizing issue, it's a fan-in problem. With a single kdamond thread draining the per-CPU sources, the samples effectively get funneled into a single ring, which explains the numbers.
The per-CPU drain approach using system_percpu_wq and queue_work_on() looks like the right fix. Our AUX backend already carries a CPU argument through the ops, so adapting it should be straightforward. I'll take a look at your v2 branch and re-test with the per-CPU drain.
Two questions:
1. Is damon/perf-rfc-v2-08-20-26 ready for me to rebase the AUX backend and observability framework on top of it? I'd like to validate the per-CPU drain fix with real SPE hardware.
2. For the probe-based configuration, does the prep_action = "perf_event" model preserve the same event lifecycle? Our AUX path needs to create and bind the event during apply, keep it disabled initially, and enable it when kdamond starts.
Thanks,
KunWu
Quoted 15 lines · KunWu Chan
Hi Ravi,
Thanks for the detailed reply. The fan-in diagnosis makes perfect sense.
Quoted 4 lines
Your series is based on the v1 substrate, and the way an event is configured is the part that moves most.
[...]
Glad to hear v2 is on the way. The probe-based model is actually something I encountered while building the AUX backend. When multiple sources can feed the same region (e.g. PTE scanning + SPE/IBS), the question of how to combine their reports becomes interesting.
Quoted 5 lines
For example, CXL tiering may care about physical-address locality, while per-process monitoring may need virtual-address attribution. How do you see probe weights being determined — is that expected to be scenario-specific, or is there a more general principle behind the weighting?
Hello KunWu,
SJ can answer that authoritatively -- the probe and weight interface is his. Here is my understanding which SJ can confirm later:
Weights are relative, and only among probes. A context can hold up to four; each report carries its probe index and credits that probe's own hit count, so two PMU-based probes in one context are scored in proportion to their weights, and that is where a scenario-specific choice belongs.
What does not mix is a weighted probe with the other two sources. Any nonzero weight switches the whole context to probe-weighted scoring, which turns page-table access checking off -- so SPE cannot be blended with PTE scanning, it replaces it. Page-fault reports carry no probe index; they credit the region's access rate but have no hit count, so under weighted scoring they are not part of the score either. Both coexist with a probe only at weight zero, where everything feeds the same access rate and is indistinguishable afterwards.
So for your case I would read it as: PA locality and VA attribution are different targets and different address kinds, which points at separate contexts rather than one context with tuned weights.
Quoted 18 lines
Quoted 6 lines
2. The 67.9% drop rate is fan-in, not sizing
---
[...]
I completely missed this. The observability framework showed the symptom (67.9% drop) but got the root cause wrong — it's not a ring sizing issue, it's a fan-in problem. With a single kdamond thread draining the per-CPU sources, the samples effectively get funneled into a single ring, which explains the numbers.
The per-CPU drain approach using
system_percpu_wqandqueue_work_on()looks like the right fix. Our AUX backend already carries a CPU argument through the ops, so adapting it should be straightforward. I'll take a look at your v2 branch and re-test with the per-CPU drain.
Quoted 5 lines
Two questions:
1. Isdamon/perf-rfc-v2-08-20-26ready for me to rebase the AUX backend and observability framework on top of it? I'd like to validate the per-CPU drain fix with real SPE hardware.
Yes:
https://github.com/ravis-opensrc/linux.git
branch damon/perf-rfc-v2-08-20-26, tip 9c0410564596
That is the branch I used to exercise the AUX path. It carries all five of your AUX kernel-consumer API patches unmodified, and from the SPE series, patch 1/4 plus the generic half of 2/4. 2/4's SPE backend and parser, and 3/4 and 4/4 which test them, are SPE-specific and I used an x86 box with virtual PMU.
The branch is force-updated post fixing two trailers please re-fetch if necessary.
None of it is meant for my v2 posting.
This branch is only the vehicle for testing the AUX report path.
The SHAs you will care about:
808519650a7a the per-CPU report side e3323a3bdc75 your AUX interface, ported to the probe model 1c347519c626 parse each CPU's AUX buffer on that CPU 9c0410564596 perf/core: balance the AUX buffer reference on kernel
release
1c347519c626 drains with one work item per CPU in the event's cpumask, via queue_work_on() on system_percpu_wq -- system_wq would not do, being unbound it silently ignores the CPU targeting.
Two things came out of a quick test in a VM:
- spe_backend_init() calls perf_event_setup_aux(), but I could not find any path calling perf_event_release_aux() -- spe_backend_cleanup() frees only st->win, and your kerneldoc says the release must happen before perf_event_release_kernel(). Left alone on my branch.
- 9c0410564596: the explicit ring_buffer_put() in perf_event_release_aux() is one too many, since ring_buffer_attach(event, NULL) just above already drops the event's reference.
Quoted 5 lines
2. For the probe-based configuration, does the
prep_action = "perf_event"model preserve the same event lifecycle? Our AUX path needs to create and bind the event during apply, keep it disabled initially, and enable it when kdamond starts.
Yes -- created disabled during apply, bound, then enabled. Per CPU, on the kdamond turn-on path:
perf_event_create_kernel_counter() attr has .pinned = 1, .disabled = 1,
so the counter is installed but not yet schedulable
ops->init(event, cpu, perf_event) your backend attaches the AUX buffer
here, via perf_event_setup_aux()
perf_event_enable() only now can the PMU be scheduled in
So the buffer is always attached before the counter starts. If ops->init() fails the counter is released without ever being enabled. kernel/watchdog_perf.c uses the same pinned + disabled-then-enable pairing.
Sanity-tested both report paths in a VM.
Best Regards,
Ravi.
Quoted 2 lines
Thanks,
KunWu
SJ Park
maintainerQuoted 41 lines · On Fri, 21 Aug 2026 09:32:02 -0700 Ravi Jonnalagadda <[email protected]>…
Quoted 15 lines · KunWu Chan
Hi Ravi,
Thanks for the detailed reply. The fan-in diagnosis makes perfect sense.
Quoted 4 lines
Your series is based on the v1 substrate, and the way an event is configured is the part that moves most.
[...]
Glad to hear v2 is on the way. The probe-based model is actually something I encountered while building the AUX backend. When multiple sources can feed the same region (e.g. PTE scanning + SPE/IBS), the question of how to combine their reports becomes interesting.
Quoted 5 lines
For example, CXL tiering may care about physical-address locality, while per-process monitoring may need virtual-address attribution. How do you see probe weights being determined — is that expected to be scenario-specific, or is there a more general principle behind the weighting?
Hello KunWu,
SJ can answer that authoritatively -- the probe and weight interface is his. Here is my understanding which SJ can confirm later:
Weights are relative, and only among probes. A context can hold up to four; each report carries its probe index and credits that probe's own hit count, so two PMU-based probes in one context are scored in proportion to their weights, and that is where a scenario-specific choice belongs.
What does not mix is a weighted probe with the other two sources. Any nonzero weight switches the whole context to probe-weighted scoring, which turns page-table access checking off -- so SPE cannot be blended with PTE scanning, it replaces it. Page-fault reports carry no probe index; they credit the region's access rate but have no hit count, so under weighted scoring they are not part of the score either. Both coexist with a probe only at weight zero, where everything feeds the same access rate and is indistinguishable afterwards.
Quoted 3 lines
So for your case I would read it as: PA locality and VA attribution are different targets and different address kinds, which points at separate contexts rather than one context with tuned weights.
Thank you for detailed response, Ravi. Ravi is correct. Physical address and virtual addresses wouldn't be able to be monitored with a single DAMON context. The user may need to have a DAMON context for physical address space, and another DAMON context for virtual address spaces.
Thanks,
SJ
[...]
Quoted 44 lines · SJ Park
Quoted 41 lines · On Fri, 21 Aug 2026 09:32:02 -0700 Ravi Jonnalagadda <[email protected]>…
Quoted 15 lines · KunWu Chan
Hi Ravi,
Thanks for the detailed reply. The fan-in diagnosis makes perfect sense.
Quoted 4 lines
Your series is based on the v1 substrate, and the way an event is configured is the part that moves most.
[...]
Glad to hear v2 is on the way. The probe-based model is actually something I encountered while building the AUX backend. When multiple sources can feed the same region (e.g. PTE scanning + SPE/IBS), the question of how to combine their reports becomes interesting.
Quoted 5 lines
For example, CXL tiering may care about physical-address locality, while per-process monitoring may need virtual-address attribution. How do you see probe weights being determined — is that expected to be scenario-specific, or is there a more general principle behind the weighting?
Hello KunWu,
SJ can answer that authoritatively -- the probe and weight interface is his. Here is my understanding which SJ can confirm later:
Weights are relative, and only among probes. A context can hold up to four; each report carries its probe index and credits that probe's own hit count, so two PMU-based probes in one context are scored in proportion to their weights, and that is where a scenario-specific choice belongs.
What does not mix is a weighted probe with the other two sources. Any nonzero weight switches the whole context to probe-weighted scoring, which turns page-table access checking off -- so SPE cannot be blended with PTE scanning, it replaces it. Page-fault reports carry no probe index; they credit the region's access rate but have no hit count, so under weighted scoring they are not part of the score either. Both coexist with a probe only at weight zero, where everything feeds the same access rate and is indistinguishable afterwards.
Quoted 4 lines
Quoted 3 lines
So for your case I would read it as: PA locality and VA attribution are different targets and different address kinds, which points at separate contexts rather than one context with tuned weights.
Thanks, SJ and Ravi, for the detailed clarification.
Quoted 5 lines
Thank you for detailed response, Ravi. Ravi is correct. Physical address and virtual addresses wouldn't be able to be monitored with a single DAMON context. The user may need to have a DAMON context for physical address space, and another DAMON context for virtual address spaces.
This also corrects an assumption I had about how the DAMON access reporting model currently combines different sources.
I had previously understood the new push model as something that could be combined with the existing pull model within the same context. I now understand that, in the current design, probe-weighted scoring switches the context away from the existing PTE-based access checking rather than blending the two.
My previous understanding was therefore off. Thanks for the clarification.
I'll update this point in the blog I'm currently working on, which I've been writing on and off for almost a month. I'm using it to document the evolution of the DAMON architecture and the transition from the traditional pull-based access monitoring toward the new push/probe-based reporting model.
Thanks,
KunWu
Quoted 5 lines
Thanks,
SJ[...]
Quoted 23 lines · Ravi Jonnalagadda
Quoted 15 lines · KunWu Chan
Hi Ravi,
Thanks for the detailed reply. The fan-in diagnosis makes perfect sense.
Quoted 4 lines
Your series is based on the v1 substrate, and the way an event is configured is the part that moves most.
[...]
Glad to hear v2 is on the way. The probe-based model is actually something I encountered while building the AUX backend. When multiple sources can feed the same region (e.g. PTE scanning + SPE/IBS), the question of how to combine their reports becomes interesting.
Quoted 5 lines
For example, CXL tiering may care about physical-address locality, while per-process monitoring may need virtual-address attribution. How do you see probe weights being determined — is that expected to be scenario-specific, or is there a more general principle behind the weighting?
Quoted 5 lines
Hello KunWu,
SJ can answer that authoritatively -- the probe and weight interface is his. Here is my understanding which SJ can confirm later:
Hi Ravi,
Thanks for your detailed reply and for sharing your understanding. The probe-weight framing clears up the part I had backwards.
Quoted 5 lines
Weights are relative, and only among probes. A context can hold up to four; each report carries its probe index and credits that probe's own hit count, so two PMU-based probes in one context are scored in proportion to their weights, and that is where a scenario-specific choice belongs.
This makes sense. I had initially been thinking about using the weights to tune SPE against PTE scanning within the same context. I now understand that the weights are for combining multiple PMU probes within a context, rather than blending PMU reports with the existing PTE-based access checking.
Quoted 9 lines
What does not mix is a weighted probe with the other two sources. Any nonzero weight switches the whole context to probe-weighted scoring, which turns page-table access checking off -- so SPE cannot be blended with PTE scanning, it replaces it. Page-fault reports carry no probe index; they credit the region's access rate but have no hit count, so under weighted scoring they are not part of the score either. Both coexist with a probe only at weight zero, where everything feeds the same access rate and is indistinguishable afterwards.
The "replace, not blend" distinction was the key correction for me. For PA locality versus VA attribution, using separate contexts therefore makes more sense.
Quoted 30 lines
So for your case I would read it as: PA locality and VA attribution are different targets and different address kinds, which points at separate contexts rather than one context with tuned weights.
Quoted 18 lines
Quoted 6 lines
2. The 67.9% drop rate is fan-in, not sizing
---
[...]
I completely missed this. The observability framework showed the symptom (67.9% drop) but got the root cause wrong — it's not a ring sizing issue, it's a fan-in problem. With a single kdamond thread draining the per-CPU sources, the samples effectively get funneled into a single ring, which explains the numbers.
The per-CPU drain approach using
system_percpu_wqandqueue_work_on()looks like the right fix. Our AUX backend already carries a CPU argument through the ops, so adapting it should be straightforward. I'll take a look at your v2 branch and re-test with the per-CPU drain.Quoted 5 lines
Two questions:
1. Isdamon/perf-rfc-v2-08-20-26ready for me to rebase the AUX backend and observability framework on top of it? I'd like to validate the per-CPU drain fix with real SPE hardware.Yes:
Quoted 9 lines
https://github.com/ravis-opensrc/linux.git
branch damon/perf-rfc-v2-08-20-26, tip9c0410564596That is the branch I used to exercise the AUX path. It carries all five of your AUX kernel-consumer API patches unmodified, and from the SPE series, patch 1/4 plus the generic half of 2/4. 2/4's SPE backend and parser, and 3/4 and 4/4 which test them, are SPE-specific and I used an x86 box with virtual PMU.
Thanks for making the testing branch available. I'll use it as the base for the rebase and testing below.
Quoted 6 lines
The branch is force-updated post fixing two trailers please re-fetch if necessary.
None of it is meant for my v2 posting.
This branch is only the vehicle for testing the AUX report path.
Quoted 8 lines
The SHAs you will care about:
808519650a7a the per-CPU report side e3323a3bdc75 your AUX interface, ported to the probe model 1c347519c626 parse each CPU's AUX buffer on that CPU 9c0410564596 perf/core: balance the AUX buffer reference on kernelrelease
Thanks for this detailed information.
Quoted 4 lines
1c347519c626drains with one work item per CPU in the event's cpumask, viaqueue_work_on()onsystem_percpu_wq--system_wqwould not do, being unbound it silently ignores the CPU targeting.
Understood. This also matches the fan-in issue you pointed out earlier. I'll keep the CPU-local drain model when reworking the AUX backend.
Quoted 7 lines
Two things came out of a quick test in a VM:
-
spe_backend_init()callsperf_event_setup_aux(), but I could not find any path callingperf_event_release_aux()--spe_backend_cleanup()frees onlyst->win, and your kerneldoc says the release must happen beforeperf_event_release_kernel(). Left alone on my branch.
Thanks for catching this. I'll trace the cleanup path and make sure the missing perf_event_release_aux() is called at the appropriate point before perf_event_release_kernel(), then re-test the lifetime path.
Quoted 4 lines
-
9c0410564596: the explicitring_buffer_put()inperf_event_release_aux()is one too many, sincering_buffer_attach(event, NULL)just above already drops the event's reference.
Thanks for catching this as well. I'll keep 9c0410564596 when rebasing the AUX work.
Quoted 16 lines
Quoted 5 lines
2. For the probe-based configuration, does the
prep_action = "perf_event"model preserve the same event lifecycle? Our AUX path needs to create and bind the event during apply, keep it disabled initially, and enable it when kdamond starts.Yes -- created disabled during apply, bound, then enabled. Per CPU, on the kdamond turn-on path:
perf_event_create_kernel_counter()attr has .pinned = 1, .disabled = 1,
so the counter is installed but not yet schedulable
ops->init(event, cpu, perf_event)your backend attaches the AUX buffer
here, viaperf_event_setup_aux()
perf_event_enable()only now can the PMU be scheduled in
Quoted 4 lines
So the buffer is always attached before the counter starts. If
ops->init()fails the counter is released without ever being enabled.kernel/watchdog_perf.cuses the same pinned + disabled-then-enable pairing.
This lifecycle is exactly what the AUX path needs: the AUX buffer is attached during ops->init() while the event is still disabled, and the event is only enabled after successful initialization.
Quoted 5 lines
Sanity-tested both report paths in a VM.
Best Regards,
Ravi.
I'm looking forward to the formal v2 as well. I'll continue working on the perf-side changes so that the new model can be exercised with hardware-sampled access reports in practice.
My next steps are:
1. Re-fetch damon/perf-rfc-v2-08-20-26 and rebase my AUX backend and observability framework onto the probe model, including the SPE-specific backend/parser and tests.
2. Integrate the per-CPU AUX drain from 1c347519c626, using queue_work_on() on system_percpu_wq, and validate that the fan-in problem is gone.
3. Fix the AUX lifetime path by making sure perf_event_release_aux() is called at the appropriate point before perf_event_release_kernel(). I'll also keep 9c0410564596 for the ring_buffer_put() fix.
4. Re-test the complete lifecycle and the per-CPU drain on real ARM SPE, including stop/restart, CPU hotplug, and failure paths, and compare the observability counters with the previous 67.9% drop result.
I'll report back with the results.
Thanks,
KunWu