Skip to content

Commit de03c72

Browse files
kosakitorvalds
authored andcommitted
mm: convert mm->cpu_vm_cpumask into cpumask_var_t
cpumask_t is very big struct and cpu_vm_mask is placed wrong position. It might lead to reduce cache hit ratio. This patch has two change. 1) Move the place of cpumask into last of mm_struct. Because usually cpumask is accessed only front bits when the system has cpu-hotplug capability 2) Convert cpu_vm_mask into cpumask_var_t. It may help to reduce memory footprint if cpumask_size() will use nr_cpumask_bits properly in future. In addition, this patch change the name of cpu_vm_mask with cpu_vm_mask_var. It may help to detect out of tree cpu_vm_mask users. This patch has no functional change. [akpm@linux-foundation.org: build fix] [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: David Howells <dhowells@redhat.com> Cc: Koichi Yasutake <yasutake.koichi@jp.panasonic.com> Cc: Hugh Dickins <hughd@google.com> Cc: Chris Metcalf <cmetcalf@tilera.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 692e0b3 commit de03c72

7 files changed

Lines changed: 44 additions & 9 deletions

File tree

‎Documentation/cachetlb.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on all processors in the system. Don't let this scare you into
1616
thinking SMP cache/tlb flushing must be so inefficient, this is in
1717
fact an area where many optimizations are possible. For example,
1818
if it can be proven that a user address space has never executed
19-
on a cpu (see vma->cpu_vm_mask), one need not perform a flush
19+
on a cpu (see mm_cpumask()), one need not perform a flush
2020
for this address space on that cpu.
2121

2222
First, the TLB flushing interfaces, since they are the simplest. The

‎arch/x86/kernel/tboot.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ static struct mm_struct tboot_mm = {
110110
.mmap_sem = __RWSEM_INITIALIZER(init_mm.mmap_sem),
111111
.page_table_lock = __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock),
112112
.mmlist = LIST_HEAD_INIT(init_mm.mmlist),
113-
.cpu_vm_mask = CPU_MASK_ALL,
114113
};
115114

116115
static inline void switch_to_tboot_pt(void)

‎include/linux/mm_types.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ struct mm_struct {
265265

266266
struct linux_binfmt *binfmt;
267267

268-
cpumask_t cpu_vm_mask;
269-
270268
/* Architecture-specific MM context */
271269
mm_context_t context;
272270

@@ -316,9 +314,14 @@ struct mm_struct {
316314
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
317315
pgtable_t pmd_huge_pte; /* protected by page_table_lock */
318316
#endif
317+
318+
cpumask_var_t cpu_vm_mask_var;
319319
};
320320

321321
/* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
322-
#define mm_cpumask(mm) (&(mm)->cpu_vm_mask)
322+
static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
323+
{
324+
return mm->cpu_vm_mask_var;
325+
}
323326

324327
#endif /* _LINUX_MM_TYPES_H */

‎include/linux/sched.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,7 @@ static inline void mmdrop(struct mm_struct * mm)
21762176
if (unlikely(atomic_dec_and_test(&mm->mm_count)))
21772177
__mmdrop(mm);
21782178
}
2179+
extern int mm_init_cpumask(struct mm_struct *mm, struct mm_struct *oldmm);
21792180

21802181
/* mmput gets rid of the mappings and all user-space */
21812182
extern void mmput(struct mm_struct *);

‎init/main.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ asmlinkage void __init start_kernel(void)
509509
sort_main_extable();
510510
trap_init();
511511
mm_init();
512+
BUG_ON(mm_init_cpumask(&init_mm, 0));
513+
512514
/*
513515
* Set up the scheduler prior starting any interrupts (such as the
514516
* timer interrupt). Full topology setup happens at smp_init()

‎kernel/fork.c‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,20 @@ static void mm_init_aio(struct mm_struct *mm)
485485
#endif
486486
}
487487

488+
int mm_init_cpumask(struct mm_struct *mm, struct mm_struct *oldmm)
489+
{
490+
#ifdef CONFIG_CPUMASK_OFFSTACK
491+
if (!alloc_cpumask_var(&mm->cpu_vm_mask_var, GFP_KERNEL))
492+
return -ENOMEM;
493+
494+
if (oldmm)
495+
cpumask_copy(mm_cpumask(mm), mm_cpumask(oldmm));
496+
else
497+
memset(mm_cpumask(mm), 0, cpumask_size());
498+
#endif
499+
return 0;
500+
}
501+
488502
static struct mm_struct * mm_init(struct mm_struct * mm, struct task_struct *p)
489503
{
490504
atomic_set(&mm->mm_users, 1);
@@ -521,10 +535,20 @@ struct mm_struct * mm_alloc(void)
521535
struct mm_struct * mm;
522536

523537
mm = allocate_mm();
524-
if (mm) {
525-
memset(mm, 0, sizeof(*mm));
526-
mm = mm_init(mm, current);
538+
if (!mm)
539+
return NULL;
540+
541+
memset(mm, 0, sizeof(*mm));
542+
mm = mm_init(mm, current);
543+
if (!mm)
544+
return NULL;
545+
546+
if (mm_init_cpumask(mm, NULL)) {
547+
mm_free_pgd(mm);
548+
free_mm(mm);
549+
return NULL;
527550
}
551+
528552
return mm;
529553
}
530554

@@ -536,6 +560,7 @@ struct mm_struct * mm_alloc(void)
536560
void __mmdrop(struct mm_struct *mm)
537561
{
538562
BUG_ON(mm == &init_mm);
563+
free_cpumask_var(mm->cpu_vm_mask_var);
539564
mm_free_pgd(mm);
540565
destroy_context(mm);
541566
mmu_notifier_mm_destroy(mm);
@@ -690,6 +715,9 @@ struct mm_struct *dup_mm(struct task_struct *tsk)
690715
if (!mm_init(mm, tsk))
691716
goto fail_nomem;
692717

718+
if (mm_init_cpumask(mm, oldmm))
719+
goto fail_nocpumask;
720+
693721
if (init_new_context(tsk, mm))
694722
goto fail_nocontext;
695723

@@ -716,6 +744,9 @@ struct mm_struct *dup_mm(struct task_struct *tsk)
716744
return NULL;
717745

718746
fail_nocontext:
747+
free_cpumask_var(mm->cpu_vm_mask_var);
748+
749+
fail_nocpumask:
719750
/*
720751
* If init_new_context() failed, we cannot use mmput() to free the mm
721752
* because it calls destroy_context()

‎mm/init-mm.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ struct mm_struct init_mm = {
2121
.mmap_sem = __RWSEM_INITIALIZER(init_mm.mmap_sem),
2222
.page_table_lock = __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock),
2323
.mmlist = LIST_HEAD_INIT(init_mm.mmlist),
24-
.cpu_vm_mask = CPU_MASK_ALL,
2524
INIT_MM_CONTEXT(init_mm)
2625
};

0 commit comments

Comments
 (0)