Re: [RFC PATCH V3 09/17] mm: Add initial scan delay

Jonathan Cameron
2025-10-03T09:41:47Z

On Thu, 14 Aug 2025 15:32:59 +0000
Raghavendra K T <raghavendra.kt@amd.com> wrote:

> This is to prevent unnecessary scanning of short lived tasks
> to reduce CPU burning.
Add a tiny bit on why reusing the existing sysctl value.
Also useful to add a comment here on current default of that
so when considering this algorithm we know what it is.

>
> Signed-off-by: Raghavendra K T <raghavendra.kt@amd.com>
> ---
> mm/kscand.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/mm/kscand.c b/mm/kscand.c
> index 39a7fcef7de8..880c3693866d 100644
> --- a/mm/kscand.c
> +++ b/mm/kscand.c
> @@ -28,6 +28,7 @@
>
> static struct task_struct *kscand_thread __read_mostly;
> static DEFINE_MUTEX(kscand_mutex);
> +extern unsigned int sysctl_numa_balancing_scan_delay;

Maybe we need to move the declaration from kernel/sched/sched.h
I'd rather see that than a somewhat hidden away extern declaration.

>
> /*
> * Total VMA size to cover during scan.
> @@ -1010,6 +1011,7 @@ void __kscand_enter(struct mm_struct *mm)
> {
> struct kscand_mm_slot *kscand_slot;
> struct mm_slot *slot;
> + unsigned long now;
> int wakeup;
>
> /* __kscand_exit() must not run from under us */
> @@ -1020,10 +1022,12 @@ void __kscand_enter(struct mm_struct *mm)
> if (!kscand_slot)
> return;
>
> + now = jiffies;
> kscand_slot->address = 0;
> kscand_slot->scan_period = kscand_mm_scan_period_ms;
> kscand_slot->scan_size = kscand_scan_size;
> - kscand_slot->next_scan = 0;
> + kscand_slot->next_scan = now +
> + 2 * msecs_to_jiffies(sysctl_numa_balancing_scan_delay);

I think one tab beyond line above is enough for indent here.

> kscand_slot->scan_delta = 0;
>
> slot = &kscand_slot->slot;