From: Martin Hicks Here is a patch that changes mmu_gathers into a per-cpu resource. It includes the changes for all arches except ia64. I've sent a separate patch to David Mosberger for ia64. arch/alpha/mm/init.c | 2 +- arch/i386/mm/init.c | 2 +- arch/m68k/mm/init.c | 2 +- arch/mips/mm/init.c | 2 +- arch/mips64/mm/init.c | 2 +- arch/parisc/mm/init.c | 2 +- arch/ppc/mm/init.c | 2 +- arch/ppc64/mm/init.c | 2 +- arch/s390/mm/init.c | 2 +- arch/sh/mm/init.c | 2 +- arch/sparc/mm/init.c | 2 +- arch/sparc64/mm/init.c | 2 +- arch/um/kernel/mem.c | 2 +- arch/x86_64/mm/init.c | 2 +- include/asm-arm/tlb.h | 4 ++-- include/asm-generic/tlb.h | 4 ++-- 16 files changed, 18 insertions(+), 18 deletions(-) diff -puN arch/alpha/mm/init.c~per-cpu-mmu_gathers arch/alpha/mm/init.c --- 25/arch/alpha/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/alpha/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -34,7 +34,7 @@ #include #include -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); extern void die_if_kernel(char *,struct pt_regs *,long); diff -puN arch/i386/mm/init.c~per-cpu-mmu_gathers arch/i386/mm/init.c --- 25/arch/i386/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/i386/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -41,7 +41,7 @@ #include #include -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); unsigned long highstart_pfn, highend_pfn; static int do_test_wp_bit(void); diff -puN arch/m68k/mm/init.c~per-cpu-mmu_gathers arch/m68k/mm/init.c --- 25/arch/m68k/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/m68k/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -33,7 +33,7 @@ #endif #include -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); /* * ZERO_PAGE is a special page that is used for zero-initialized diff -puN arch/mips64/mm/init.c~per-cpu-mmu_gathers arch/mips64/mm/init.c --- 25/arch/mips64/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/mips64/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -35,7 +35,7 @@ #include #include -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); void pgd_init(unsigned long page) { diff -puN arch/mips/mm/init.c~per-cpu-mmu_gathers arch/mips/mm/init.c --- 25/arch/mips/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/mips/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -42,7 +42,7 @@ #include #include -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); extern void prom_free_prom_memory(void); diff -puN arch/parisc/mm/init.c~per-cpu-mmu_gathers arch/parisc/mm/init.c --- 25/arch/parisc/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/parisc/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -23,7 +23,7 @@ #include #include -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); extern char _text; /* start of kernel code, defined by linker */ extern int data_start; diff -puN arch/ppc64/mm/init.c~per-cpu-mmu_gathers arch/ppc64/mm/init.c --- 25/arch/ppc64/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/ppc64/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -93,7 +93,7 @@ unsigned long __max_memory; /* This is declared as we are using the more or less generic * include/asm-ppc64/tlb.h file -- tgall */ -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); void show_mem(void) { diff -puN arch/ppc/mm/init.c~per-cpu-mmu_gathers arch/ppc/mm/init.c --- 25/arch/ppc/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/ppc/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -53,7 +53,7 @@ #endif #define MAX_LOW_MEM CONFIG_LOWMEM_SIZE -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); unsigned long total_memory; unsigned long total_lowmem; diff -puN arch/s390/mm/init.c~per-cpu-mmu_gathers arch/s390/mm/init.c --- 25/arch/s390/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/s390/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -38,7 +38,7 @@ #include #include -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE))); char empty_zero_page[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE))); diff -puN arch/sh/mm/init.c~per-cpu-mmu_gathers arch/sh/mm/init.c --- 25/arch/sh/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/sh/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -36,7 +36,7 @@ #include #include -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); /* * Cache of MMU context last used. diff -puN arch/sparc64/mm/init.c~per-cpu-mmu_gathers arch/sparc64/mm/init.c --- 25/arch/sparc64/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/sparc64/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -36,7 +36,7 @@ #include #include -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); extern void device_scan(void); diff -puN arch/sparc/mm/init.c~per-cpu-mmu_gathers arch/sparc/mm/init.c --- 25/arch/sparc/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/sparc/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -32,7 +32,7 @@ #include /* bug in asm-generic/tlb.h: check_pgt_cache */ #include -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); unsigned long *sparc_valid_addr_bitmap; diff -puN arch/um/kernel/mem.c~per-cpu-mmu_gathers arch/um/kernel/mem.c --- 25/arch/um/kernel/mem.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/um/kernel/mem.c 2003-05-23 18:50:43.000000000 -0700 @@ -45,7 +45,7 @@ extern char __init_begin, __init_end; extern long physmem_size; /* Not changed by UML */ -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); /* Changed during early boot */ int kmalloc_ok = 0; diff -puN arch/x86_64/mm/init.c~per-cpu-mmu_gathers arch/x86_64/mm/init.c --- 25/arch/x86_64/mm/init.c~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/arch/x86_64/mm/init.c 2003-05-23 18:50:43.000000000 -0700 @@ -41,7 +41,7 @@ #define Dprintk(x...) -struct mmu_gather mmu_gathers[NR_CPUS]; +DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); /* * NOTE: pagetable_init alloc all the fixmap pagetables contiguous on the diff -puN include/asm-arm/tlb.h~per-cpu-mmu_gathers include/asm-arm/tlb.h --- 25/include/asm-arm/tlb.h~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/include/asm-arm/tlb.h 2003-05-23 18:50:43.000000000 -0700 @@ -33,13 +33,13 @@ struct mmu_gather { unsigned int avoided_flushes; }; -extern struct mmu_gather mmu_gathers[NR_CPUS]; +DECLARE_PER_CPU(struct mmu_gather, mmu_gathers); static inline struct mmu_gather * tlb_gather_mmu(struct mm_struct *mm, unsigned int full_mm_flush) { int cpu = smp_processor_id(); - struct mmu_gather *tlb = &mmu_gathers[cpu]; + struct mmu_gather *tlb = &per_cpu(mmu_gathers, cpu); tlb->mm = mm; tlb->freed = 0; diff -puN include/asm-generic/tlb.h~per-cpu-mmu_gathers include/asm-generic/tlb.h --- 25/include/asm-generic/tlb.h~per-cpu-mmu_gathers 2003-05-23 18:50:43.000000000 -0700 +++ 25-akpm/include/asm-generic/tlb.h 2003-05-23 18:50:43.000000000 -0700 @@ -44,7 +44,7 @@ struct mmu_gather { }; /* Users of the generic TLB shootdown code must declare this storage space. */ -extern struct mmu_gather mmu_gathers[NR_CPUS]; +DECLARE_PER_CPU(struct mmu_gather, mmu_gathers); /* tlb_gather_mmu * Return a pointer to an initialized struct mmu_gather. @@ -52,7 +52,7 @@ extern struct mmu_gather mmu_gathers[NR_ static inline struct mmu_gather * tlb_gather_mmu(struct mm_struct *mm, unsigned int full_mm_flush) { - struct mmu_gather *tlb = &mmu_gathers[smp_processor_id()]; + struct mmu_gather *tlb = &per_cpu(mmu_gathers, smp_processor_id()); tlb->mm = mm; _