[RFC PATCH V1 6/6] sched/numa: Allow scanning of shared VMAs

From: Raghavendra K T
Date: Tue Aug 29 2023 - 02:08:49 EST


VMAs being accessed by more than two tasks are critical. Scan them
unconditionally. Note that current patch considers full history of
VMA access.

Signed-off-by: Raghavendra K T <raghavendra.kt@xxxxxxx>
---
kernel/sched/fair.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 6529da7f370a..70c8e62c1a89 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2981,6 +2981,19 @@ static inline bool vma_accessed_recent(struct vm_area_struct *vma)
return (bitmap_weight(pids, BITS_PER_LONG) >= 1);
}

+#define SHARED_VMA_THRESH 3
+
+static inline bool vma_shared_access(struct vm_area_struct *vma)
+{
+ int i;
+ unsigned long pids = 0;
+
+ for (i = 0; i < NR_ACCESS_PID_HIST; i++)
+ pids |= vma->numab_state->access_pids[i];
+
+ return (bitmap_weight(&pids, BITS_PER_LONG) >= SHARED_VMA_THRESH);
+}
+
static bool vma_is_accessed(struct vm_area_struct *vma)
{
/* Check at least one task had accessed VMA recently. */
@@ -2991,7 +3004,8 @@ static bool vma_is_accessed(struct vm_area_struct *vma)
if (vma_test_access_pid_history(vma))
return true;

- return false;
+ /* Check if VMA is shared by many tasks. */
+ return vma_shared_access(vma);
}

#define VMA_PID_RESET_PERIOD (4 * sysctl_numa_balancing_scan_delay)
--
2.34.1