Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/vmacache, sched/headers: Introduce 'struct vmacache' and move it from <linux/sched.h> to <linux/mm_types>

The <linux/sched.h> header includes various vmacache related defines,
which are arguably misplaced.

Move them to mm_types.h and minimize the sched.h impact by putting
all task vmacache state into a new 'struct vmacache' structure.

No change in functionality.

Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

+25 -16
+12
include/linux/mm_types.h
··· 360 360 struct vm_userfaultfd_ctx vm_userfaultfd_ctx; 361 361 }; 362 362 363 + /* 364 + * The per task VMA cache array: 365 + */ 366 + #define VMACACHE_BITS 2 367 + #define VMACACHE_SIZE (1U << VMACACHE_BITS) 368 + #define VMACACHE_MASK (VMACACHE_SIZE - 1) 369 + 370 + struct vmacache { 371 + u32 seqnum; 372 + struct vm_area_struct *vmas[VMACACHE_SIZE]; 373 + }; 374 + 363 375 struct core_thread { 364 376 struct task_struct *task; 365 377 struct core_thread *next;
+4 -7
include/linux/sched.h
··· 134 134 struct filename; 135 135 struct nameidata; 136 136 137 - #define VMACACHE_BITS 2 138 - #define VMACACHE_SIZE (1U << VMACACHE_BITS) 139 - #define VMACACHE_MASK (VMACACHE_SIZE - 1) 140 - 141 137 /* 142 138 * These are the constant used to fake the fixed-point load-average 143 139 * counting. Some notes: ··· 1546 1550 #endif 1547 1551 1548 1552 struct mm_struct *mm, *active_mm; 1549 - /* per-thread vma caching */ 1550 - u32 vmacache_seqnum; 1551 - struct vm_area_struct *vmacache[VMACACHE_SIZE]; 1553 + 1554 + /* Per-thread vma caching: */ 1555 + struct vmacache vmacache; 1556 + 1552 1557 #if defined(SPLIT_RSS_COUNTING) 1553 1558 struct task_rss_stat rss_stat; 1554 1559 #endif
+1 -1
include/linux/vmacache.h
··· 12 12 13 13 static inline void vmacache_flush(struct task_struct *tsk) 14 14 { 15 - memset(tsk->vmacache, 0, sizeof(tsk->vmacache)); 15 + memset(tsk->vmacache.vmas, 0, sizeof(tsk->vmacache.vmas)); 16 16 } 17 17 18 18 extern void vmacache_flush_all(struct mm_struct *mm);
+2 -2
kernel/debug/debug_core.c
··· 232 232 int i; 233 233 234 234 for (i = 0; i < VMACACHE_SIZE; i++) { 235 - if (!current->vmacache[i]) 235 + if (!current->vmacache.vmas[i]) 236 236 continue; 237 - flush_cache_range(current->vmacache[i], 237 + flush_cache_range(current->vmacache.vmas[i], 238 238 addr, addr + BREAK_INSTR_SIZE); 239 239 } 240 240 }
+1 -1
mm/nommu.c
··· 757 757 mm->map_count--; 758 758 for (i = 0; i < VMACACHE_SIZE; i++) { 759 759 /* if the vma is cached, invalidate the entire cache */ 760 - if (curr->vmacache[i] == vma) { 760 + if (curr->vmacache.vmas[i] == vma) { 761 761 vmacache_invalidate(mm); 762 762 break; 763 763 }
+5 -5
mm/vmacache.c
··· 60 60 void vmacache_update(unsigned long addr, struct vm_area_struct *newvma) 61 61 { 62 62 if (vmacache_valid_mm(newvma->vm_mm)) 63 - current->vmacache[VMACACHE_HASH(addr)] = newvma; 63 + current->vmacache.vmas[VMACACHE_HASH(addr)] = newvma; 64 64 } 65 65 66 66 static bool vmacache_valid(struct mm_struct *mm) ··· 71 71 return false; 72 72 73 73 curr = current; 74 - if (mm->vmacache_seqnum != curr->vmacache_seqnum) { 74 + if (mm->vmacache_seqnum != curr->vmacache.seqnum) { 75 75 /* 76 76 * First attempt will always be invalid, initialize 77 77 * the new cache for this task here. 78 78 */ 79 - curr->vmacache_seqnum = mm->vmacache_seqnum; 79 + curr->vmacache.seqnum = mm->vmacache_seqnum; 80 80 vmacache_flush(curr); 81 81 return false; 82 82 } ··· 93 93 return NULL; 94 94 95 95 for (i = 0; i < VMACACHE_SIZE; i++) { 96 - struct vm_area_struct *vma = current->vmacache[i]; 96 + struct vm_area_struct *vma = current->vmacache.vmas[i]; 97 97 98 98 if (!vma) 99 99 continue; ··· 121 121 return NULL; 122 122 123 123 for (i = 0; i < VMACACHE_SIZE; i++) { 124 - struct vm_area_struct *vma = current->vmacache[i]; 124 + struct vm_area_struct *vma = current->vmacache.vmas[i]; 125 125 126 126 if (vma && vma->vm_start == start && vma->vm_end == end) { 127 127 count_vm_vmacache_event(VMACACHE_FIND_HITS);