History

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.

Ingo Molnar committed 9 years ago

Commit 314ff781 parent 780de9d6 files · +25 −16Browse files

Unified · Split

6 files
  1. include/linux/mm_types.h +12 −0
  2. include/linux/sched.h +4 −7
  3. include/linux/vmacache.h +1 −1
  4. kernel/debug/debug_core.c +2 −2
  5. mm/nommu.c +1 −1
  6. mm/vmacache.c +5 −5
include/linux/mm_types.h+12−0
@@ -360,6 +360,18 @@ struct vm_area_struct { · 359 unmodified lines
360360 struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
361361 };
362362
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+
363375 struct core_thread {
364376 struct task_struct *task;
365377 struct core_thread *next;
include/linux/sched.h+4−7
@@ -134,10 +134,6 @@ struct blk_plug; · 133 unmodified lines
134134 struct filename;
135135 struct nameidata;
136136
137−#define VMACACHE_BITS 2
138−#define VMACACHE_SIZE (1U << VMACACHE_BITS)
139−#define VMACACHE_MASK (VMACACHE_SIZE - 1)
140−
141137 /*
142138 * These are the constant used to fake the fixed-point load-average
143139 * counting. Some notes:
@@ -1550,9 +1546,10 @@ struct task_struct { · 1406 unmodified lines
15501546 #endif
15511547
15521548 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+
15561553 #if defined(SPLIT_RSS_COUNTING)
15571554 struct task_rss_stat rss_stat;
15581555 #endif
include/linux/vmacache.h+1−1
@@ -12,7 +12,7 @@ · 11 unmodified lines
1212
1313 static inline void vmacache_flush(struct task_struct *tsk)
1414 {
15− memset(tsk->vmacache, 0, sizeof(tsk->vmacache));
15+ memset(tsk->vmacache.vmas, 0, sizeof(tsk->vmacache.vmas));
1616 }
1717
1818 extern void vmacache_flush_all(struct mm_struct *mm);
kernel/debug/debug_core.c+2−2
@@ -232,9 +232,9 @@ static void kgdb_flush_swbreak_addr(unsigned long addr) · 231 unmodified lines
232232 int i;
233233
234234 for (i = 0; i < VMACACHE_SIZE; i++) {
235− if (!current->vmacache[i])
235+ if (!current->vmacache.vmas[i])
236236 continue;
237− flush_cache_range(current->vmacache[i],
237+ flush_cache_range(current->vmacache.vmas[i],
238238 addr, addr + BREAK_INSTR_SIZE);
239239 }
240240 }
mm/nommu.c+1−1
@@ -757,7 +757,7 @@ static void delete_vma_from_mm(struct vm_area_struct *vma) · 756 unmodified lines
757757 mm->map_count--;
758758 for (i = 0; i < VMACACHE_SIZE; i++) {
759759 /* if the vma is cached, invalidate the entire cache */
760− if (curr->vmacache[i] == vma) {
760+ if (curr->vmacache.vmas[i] == vma) {
761761 vmacache_invalidate(mm);
762762 break;
763763 }
mm/vmacache.c+5−5
@@ -60,7 +60,7 @@ static inline bool vmacache_valid_mm(struct mm_struct *mm) · 59 unmodified lines
6060 void vmacache_update(unsigned long addr, struct vm_area_struct *newvma)
6161 {
6262 if (vmacache_valid_mm(newvma->vm_mm))
63− current->vmacache[VMACACHE_HASH(addr)] = newvma;
63+ current->vmacache.vmas[VMACACHE_HASH(addr)] = newvma;
6464 }
6565
6666 static bool vmacache_valid(struct mm_struct *mm)
@@ -71,12 +71,12 @@ static bool vmacache_valid(struct mm_struct *mm) · 4 unmodified lines
7171 return false;
7272
7373 curr = current;
74− if (mm->vmacache_seqnum != curr->vmacache_seqnum) {
74+ if (mm->vmacache_seqnum != curr->vmacache.seqnum) {
7575 /*
7676 * First attempt will always be invalid, initialize
7777 * the new cache for this task here.
7878 */
79− curr->vmacache_seqnum = mm->vmacache_seqnum;
79+ curr->vmacache.seqnum = mm->vmacache_seqnum;
8080 vmacache_flush(curr);
8181 return false;
8282 }
@@ -93,7 +93,7 @@ struct vm_area_struct *vmacache_find(struct mm_struct *mm, unsigned long addr) · 10 unmodified lines
9393 return NULL;
9494
9595 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];
9797
9898 if (!vma)
9999 continue;
@@ -121,7 +121,7 @@ struct vm_area_struct *vmacache_find_exact(struct mm_struct *mm, · 21 unmodified lines
121121 return NULL;
122122
123123 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];
125125
126126 if (vma && vma->vm_start == start && vma->vm_end == end) {
127127 count_vm_vmacache_event(VMACACHE_FIND_HITS);