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.
Unified · Split
| @@ -360,6 +360,18 @@ struct vm_area_struct { · 359 unmodified lines | ||
| 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; |
| @@ -134,10 +134,6 @@ struct blk_plug; · 133 unmodified lines | ||
| 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: |
| @@ -1550,9 +1546,10 @@ struct task_struct { · 1406 unmodified lines | ||
| 1550 | 1546 | #endif |
| 1551 | 1547 | |
| 1552 | 1548 | struct mm_struct *mm, *active_mm; |
| 1553 | − /* per-thread vma caching */ | |
| 1554 | − u32 vmacache_seqnum; | |
| 1555 | − struct vm_area_struct *vmacache[VMACACHE_SIZE]; | |
| 1549 | + | |
| 1550 | + /* Per-thread vma caching: */ | |
| 1551 | + struct vmacache vmacache; | |
| 1552 | + | |
| 1556 | 1553 | #if defined(SPLIT_RSS_COUNTING) |
| 1557 | 1554 | struct task_rss_stat rss_stat; |
| 1558 | 1555 | #endif |
| @@ -12,7 +12,7 @@ · 11 unmodified lines | ||
| 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); |
| @@ -232,9 +232,9 @@ static void kgdb_flush_swbreak_addr(unsigned long addr) · 231 unmodified lines | ||
| 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 | } |
| @@ -757,7 +757,7 @@ static void delete_vma_from_mm(struct vm_area_struct *vma) · 756 unmodified lines | ||
| 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 | } |
| @@ -60,7 +60,7 @@ static inline bool vmacache_valid_mm(struct mm_struct *mm) · 59 unmodified lines | ||
| 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,12 +71,12 @@ static bool vmacache_valid(struct mm_struct *mm) · 4 unmodified lines | ||
| 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,7 +93,7 @@ struct vm_area_struct *vmacache_find(struct mm_struct *mm, unsigned long addr) · 10 unmodified lines | ||
| 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,7 +121,7 @@ struct vm_area_struct *vmacache_find_exact(struct mm_struct *mm, · 21 unmodified lines | ||
| 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); |