Skip to content

Commit ed2da8b

Browse files
gormanmingomolnar
authored andcommitted
sched/numa: Trace decisions related to skipping VMAs
NUMA balancing skips or scans VMAs for a variety of reasons. In preparation for completing scans of VMAs regardless of PID access, trace the reasons why a VMA was skipped. In a later patch, the tracing will be used to track if a VMA was forcibly scanned. Signed-off-by: Mel Gorman <mgorman@techsingularity.net> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20231010083143.19593-4-mgorman@techsingularity.net
1 parent f3a6c97 commit ed2da8b

3 files changed

Lines changed: 71 additions & 4 deletions

File tree

include/linux/sched/numa_balancing.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
#define TNF_FAULT_LOCAL 0x08
1616
#define TNF_MIGRATE_FAIL 0x10
1717

18+
enum numa_vmaskip_reason {
19+
NUMAB_SKIP_UNSUITABLE,
20+
NUMAB_SKIP_SHARED_RO,
21+
NUMAB_SKIP_INACCESSIBLE,
22+
NUMAB_SKIP_SCAN_DELAY,
23+
NUMAB_SKIP_PID_INACTIVE,
24+
};
25+
1826
#ifdef CONFIG_NUMA_BALANCING
1927
extern void task_numa_fault(int last_node, int node, int pages, int flags);
2028
extern pid_t task_numa_group_id(struct task_struct *p);

include/trace/events/sched.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,56 @@ DEFINE_EVENT(sched_numa_pair_template, sched_swap_numa,
664664
TP_ARGS(src_tsk, src_cpu, dst_tsk, dst_cpu)
665665
);
666666

667+
#ifdef CONFIG_NUMA_BALANCING
668+
#define NUMAB_SKIP_REASON \
669+
EM( NUMAB_SKIP_UNSUITABLE, "unsuitable" ) \
670+
EM( NUMAB_SKIP_SHARED_RO, "shared_ro" ) \
671+
EM( NUMAB_SKIP_INACCESSIBLE, "inaccessible" ) \
672+
EM( NUMAB_SKIP_SCAN_DELAY, "scan_delay" ) \
673+
EMe(NUMAB_SKIP_PID_INACTIVE, "pid_inactive" )
674+
675+
/* Redefine for export. */
676+
#undef EM
677+
#undef EMe
678+
#define EM(a, b) TRACE_DEFINE_ENUM(a);
679+
#define EMe(a, b) TRACE_DEFINE_ENUM(a);
680+
681+
NUMAB_SKIP_REASON
682+
683+
/* Redefine for symbolic printing. */
684+
#undef EM
685+
#undef EMe
686+
#define EM(a, b) { a, b },
687+
#define EMe(a, b) { a, b }
688+
689+
TRACE_EVENT(sched_skip_vma_numa,
690+
691+
TP_PROTO(struct mm_struct *mm, struct vm_area_struct *vma,
692+
enum numa_vmaskip_reason reason),
693+
694+
TP_ARGS(mm, vma, reason),
695+
696+
TP_STRUCT__entry(
697+
__field(unsigned long, numa_scan_offset)
698+
__field(unsigned long, vm_start)
699+
__field(unsigned long, vm_end)
700+
__field(enum numa_vmaskip_reason, reason)
701+
),
702+
703+
TP_fast_assign(
704+
__entry->numa_scan_offset = mm->numa_scan_offset;
705+
__entry->vm_start = vma->vm_start;
706+
__entry->vm_end = vma->vm_end;
707+
__entry->reason = reason;
708+
),
709+
710+
TP_printk("numa_scan_offset=%lX vm_start=%lX vm_end=%lX reason=%s",
711+
__entry->numa_scan_offset,
712+
__entry->vm_start,
713+
__entry->vm_end,
714+
__print_symbolic(__entry->reason, NUMAB_SKIP_REASON))
715+
);
716+
#endif /* CONFIG_NUMA_BALANCING */
667717

668718
/*
669719
* Tracepoint for waking a polling cpu without an IPI.

kernel/sched/fair.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3210,6 +3210,7 @@ static void task_numa_work(struct callback_head *work)
32103210
do {
32113211
if (!vma_migratable(vma) || !vma_policy_mof(vma) ||
32123212
is_vm_hugetlb_page(vma) || (vma->vm_flags & VM_MIXEDMAP)) {
3213+
trace_sched_skip_vma_numa(mm, vma, NUMAB_SKIP_UNSUITABLE);
32133214
continue;
32143215
}
32153216

@@ -3220,15 +3221,19 @@ static void task_numa_work(struct callback_head *work)
32203221
* as migrating the pages will be of marginal benefit.
32213222
*/
32223223
if (!vma->vm_mm ||
3223-
(vma->vm_file && (vma->vm_flags & (VM_READ|VM_WRITE)) == (VM_READ)))
3224+
(vma->vm_file && (vma->vm_flags & (VM_READ|VM_WRITE)) == (VM_READ))) {
3225+
trace_sched_skip_vma_numa(mm, vma, NUMAB_SKIP_SHARED_RO);
32243226
continue;
3227+
}
32253228

32263229
/*
32273230
* Skip inaccessible VMAs to avoid any confusion between
32283231
* PROT_NONE and NUMA hinting ptes
32293232
*/
3230-
if (!vma_is_accessible(vma))
3233+
if (!vma_is_accessible(vma)) {
3234+
trace_sched_skip_vma_numa(mm, vma, NUMAB_SKIP_INACCESSIBLE);
32313235
continue;
3236+
}
32323237

32333238
/* Initialise new per-VMA NUMAB state. */
32343239
if (!vma->numab_state) {
@@ -3250,12 +3255,16 @@ static void task_numa_work(struct callback_head *work)
32503255
* delay the scan for new VMAs.
32513256
*/
32523257
if (mm->numa_scan_seq && time_before(jiffies,
3253-
vma->numab_state->next_scan))
3258+
vma->numab_state->next_scan)) {
3259+
trace_sched_skip_vma_numa(mm, vma, NUMAB_SKIP_SCAN_DELAY);
32543260
continue;
3261+
}
32553262

32563263
/* Do not scan the VMA if task has not accessed */
3257-
if (!vma_is_accessed(vma))
3264+
if (!vma_is_accessed(vma)) {
3265+
trace_sched_skip_vma_numa(mm, vma, NUMAB_SKIP_PID_INACTIVE);
32583266
continue;
3267+
}
32593268

32603269
/*
32613270
* RESET access PIDs regularly for old VMAs. Resetting after checking

0 commit comments

Comments
 (0)