
hulk inclusion category:feature bugzilla:https://gitee.com/openeuler/kernel/issues/IC8KS8 CVE: NA -------------------------------- Extend the /proc/sys/kernel/mem_sampling_enable sysctl interface to provide finer-grained control over mem_sampling usage across kernel subsystems including DAMON and NUMA balancing. Updated control values: 0 - Disable mem_sampling entirely 1 - Enable mem_sampling (for perf or general sampling) 2 - Enable mem_sampling and allow NUMA balancing to use access hints 3 - Enable mem_sampling and allow DAMON to use access records 4 - Fully enable mem_sampling for both NUMA and DAMON This multi-level control allows users to selectively enable hardware- assisted memory sampling for specific subsystems based on performance and observability needs. It also helps avoid conflicts when multiple features compete for access to underlying sampling resources (e.g. ARM SPE). The implementation ensures that mutual exclusion with perf is respected. If perf starts using SPE, mem_sampling is automatically disabled, and DAMON/NUMA consumers will stop using sampled access data accordingly. This extension improves runtime configurability and makes mem_sampling integration more practical for dynamic and hybrid workloads. Signed-off-by: Ze Zuo <zuoze1@huawei.com> Signed-off-by: Tong Tiangen <tongtiangen@huawei.com> Signed-off-by: Shuang Yan <yanshuang7@huawei.com> --- mm/mem_sampling.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mm/mem_sampling.c b/mm/mem_sampling.c index 65f047ae8b84..126cf71a9fb2 100644 --- a/mm/mem_sampling.c +++ b/mm/mem_sampling.c @@ -27,7 +27,7 @@ #define MEM_SAMPLING_DISABLED 0x0 #define MEM_SAMPLING_NORMAL 0x1 #define MEM_SAMPLING_MIN_VALUE 0 -#define MEM_SAMPLING_MAX_VALUE 3 +#define MEM_SAMPLING_MAX_VALUE 5 struct mem_sampling_ops_struct mem_sampling_ops; static int mem_sampling_override __initdata; @@ -483,6 +483,11 @@ static int proc_mem_sampling_enable(struct ctl_table *table, int write, state = 1; if (static_branch_likely(&sched_numabalancing_mem_sampling)) state = 2; + if (static_branch_likely(&mm_damon_mem_sampling)) + state = 3; + if (static_branch_likely(&mm_damon_mem_sampling) && + static_branch_likely(&sched_numabalancing_mem_sampling)) + state = 4; if (write && !capable(CAP_SYS_ADMIN)) return -EPERM; @@ -504,8 +509,19 @@ static int proc_mem_sampling_enable(struct ctl_table *table, int write, set_mem_sampling_state(true); break; case 2: + set_mem_sampling_state(false); + set_mem_sampling_state(true); + set_numabalancing_mem_sampling_state(true); + break; + case 3: + set_mem_sampling_state(false); + set_mem_sampling_state(true); + set_damon_mem_sampling_state(true); + break; + case 4: set_mem_sampling_state(true); set_numabalancing_mem_sampling_state(true); + set_damon_mem_sampling_state(true); break; default: return -EINVAL; -- 2.25.1