
hulk inclusion category:feature bugzilla:https://gitee.com/openeuler/kernel/issues/IC8KS8 CVE: NA -------------------------------- Enable NUMA balancing to use memory access information provided by the mem_sampling framework (e.g. from ARM SPE or other hardware samplers). When mem_sampling and its access hint mechanism are enabled, the regular address space scan in task_numa_work() is skipped. This reduces the overhead of NUMA balancing while still providing reliable memory access patterns for task placement decisions. A static key `sched_numabalancing_mem_sampling` is introduced to toggle this behavior, and is enabled when mem_sampling is active. This patch lays the groundwork for integrating hardware-assisted sampling into NUMA-aware scheduling decisions and avoids unnecessary software-based access detection. Note: PMD-level page migration is not supported in this mode. Signed-off-by: Ze Zuo <zuoze1@huawei.com> Signed-off-by: Tong Tiangen <tongtiangen@huawei.com> Signed-off-by: Shuang Yan <yanshuang7@huawei.com> --- include/linux/mem_sampling.h | 3 +++ kernel/sched/fair.c | 13 +++++++++++++ mm/mem_sampling.c | 1 + 3 files changed, 17 insertions(+) diff --git a/include/linux/mem_sampling.h b/include/linux/mem_sampling.h index bbe1e022d235..d93324ce8269 100644 --- a/include/linux/mem_sampling.h +++ b/include/linux/mem_sampling.h @@ -71,6 +71,9 @@ enum user_switch_type { USER_SWITCH_BACK_TO_MEM_SAMPLING, }; +DECLARE_STATIC_KEY_FALSE(sched_numabalancing_mem_sampling); +extern struct static_key_false mem_sampling_access_hints; + #ifdef CONFIG_ARM_SPE_MEM_SAMPLING int mm_spe_start(void); void mm_spe_stop(void); diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c530d501bb48..468a4d747933 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -48,6 +48,7 @@ #include <linux/ratelimit.h> #include <linux/task_work.h> #include <linux/rbtree_augmented.h> +#include <linux/mem_sampling.h> #include <asm/switch_to.h> @@ -3368,6 +3369,18 @@ static void task_numa_work(struct callback_head *work) long pages, virtpages; struct vma_iterator vmi; +#ifdef CONFIG_NUMABALANCING_MEM_SAMPLING + /* + * If we are using access hints from hardware (like using + * SPE), don't scan the address space. + * Note that currently PMD-level page migration is not + * supported. + */ + if (static_branch_unlikely(&mem_sampling_access_hints) && + static_branch_unlikely(&sched_numabalancing_mem_sampling)) + return; +#endif + SCHED_WARN_ON(p != container_of(work, struct task_struct, numa_work)); work->next = work; diff --git a/mm/mem_sampling.c b/mm/mem_sampling.c index bc0ca95bb5c9..a9832924509c 100644 --- a/mm/mem_sampling.c +++ b/mm/mem_sampling.c @@ -105,6 +105,7 @@ void mem_sampling_sched_in(struct task_struct *prev, struct task_struct *curr) mem_sampling_ops.sampling_stop(); } +DEFINE_STATIC_KEY_FALSE(sched_numabalancing_mem_sampling); #ifdef CONFIG_NUMABALANCING_MEM_SAMPLING static int numa_migrate_prep(struct folio *folio, struct vm_area_struct *vma, unsigned long addr, int page_nid, int *flags) -- 2.25.1