Skip to content

Commit 0fc0531

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu: percpu: update comments to reflect that percpu allocations are always zero-filled percpu: Optimize __get_cpu_var() x86, percpu: Optimize this_cpu_ptr percpu: clear memory allocated with the km allocator percpu: fix build breakage on s390 and cleanup build configuration tests percpu: use percpu allocator on UP too percpu: reduce PCPU_MIN_UNIT_SIZE to 32k vmalloc: pcpu_get/free_vm_areas() aren't needed on UP Fixed up trivial conflicts in include/linux/percpu.h
2 parents 91b7450 + 9329ba9 commit 0fc0531

10 files changed

Lines changed: 281 additions & 236 deletions

File tree

‎arch/x86/include/asm/percpu.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@
4747
#ifdef CONFIG_SMP
4848
#define __percpu_arg(x) "%%"__stringify(__percpu_seg)":%P" #x
4949
#define __my_cpu_offset percpu_read(this_cpu_off)
50+
51+
/*
52+
* Compared to the generic __my_cpu_offset version, the following
53+
* saves one instruction and avoids clobbering a temp register.
54+
*/
55+
#define __this_cpu_ptr(ptr) \
56+
({ \
57+
unsigned long tcp_ptr__; \
58+
__verify_pcpu_ptr(ptr); \
59+
asm volatile("add " __percpu_arg(1) ", %0" \
60+
: "=r" (tcp_ptr__) \
61+
: "m" (this_cpu_off), "0" (ptr)); \
62+
(typeof(*(ptr)) __kernel __force *)tcp_ptr__; \
63+
})
5064
#else
5165
#define __percpu_arg(x) "%P" #x
5266
#endif

‎include/asm-generic/percpu.h‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ extern unsigned long __per_cpu_offset[NR_CPUS];
5555
*/
5656
#define per_cpu(var, cpu) \
5757
(*SHIFT_PERCPU_PTR(&(var), per_cpu_offset(cpu)))
58-
#define __get_cpu_var(var) \
59-
(*SHIFT_PERCPU_PTR(&(var), my_cpu_offset))
60-
#define __raw_get_cpu_var(var) \
61-
(*SHIFT_PERCPU_PTR(&(var), __my_cpu_offset))
6258

63-
#define this_cpu_ptr(ptr) SHIFT_PERCPU_PTR(ptr, my_cpu_offset)
59+
#ifndef __this_cpu_ptr
6460
#define __this_cpu_ptr(ptr) SHIFT_PERCPU_PTR(ptr, __my_cpu_offset)
61+
#endif
62+
#ifdef CONFIG_DEBUG_PREEMPT
63+
#define this_cpu_ptr(ptr) SHIFT_PERCPU_PTR(ptr, my_cpu_offset)
64+
#else
65+
#define this_cpu_ptr(ptr) __this_cpu_ptr(ptr)
66+
#endif
6567

68+
#define __get_cpu_var(var) (*this_cpu_ptr(&(var)))
69+
#define __raw_get_cpu_var(var) (*__this_cpu_ptr(&(var)))
6670

6771
#ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
6872
extern void setup_per_cpu_areas(void);

‎include/linux/percpu.h‎

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@
4848
preempt_enable(); \
4949
} while (0)
5050

51-
#ifdef CONFIG_SMP
52-
5351
/* minimum unit size, also is the maximum supported allocation size */
54-
#define PCPU_MIN_UNIT_SIZE PFN_ALIGN(64 << 10)
52+
#define PCPU_MIN_UNIT_SIZE PFN_ALIGN(32 << 10)
5553

5654
/*
5755
* Percpu allocator can serve percpu allocations before slab is
@@ -146,37 +144,20 @@ extern int __init pcpu_page_first_chunk(size_t reserved_size,
146144
* dynamically allocated. Non-atomic access to the current CPU's
147145
* version should probably be combined with get_cpu()/put_cpu().
148146
*/
147+
#ifdef CONFIG_SMP
149148
#define per_cpu_ptr(ptr, cpu) SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)))
149+
#else
150+
#define per_cpu_ptr(ptr, cpu) ({ (void)(cpu); VERIFY_PERCPU_PTR((ptr)); })
151+
#endif
150152

151153
extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align);
152154
extern bool is_kernel_percpu_address(unsigned long addr);
153155

154-
#ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
156+
#if !defined(CONFIG_SMP) || !defined(CONFIG_HAVE_SETUP_PER_CPU_AREA)
155157
extern void __init setup_per_cpu_areas(void);
156158
#endif
157159
extern void __init percpu_init_late(void);
158160

159-
#else /* CONFIG_SMP */
160-
161-
#define per_cpu_ptr(ptr, cpu) ({ (void)(cpu); VERIFY_PERCPU_PTR((ptr)); })
162-
163-
/* can't distinguish from other static vars, always false */
164-
static inline bool is_kernel_percpu_address(unsigned long addr)
165-
{
166-
return false;
167-
}
168-
169-
static inline void __init setup_per_cpu_areas(void) { }
170-
171-
static inline void __init percpu_init_late(void) { }
172-
173-
static inline void *pcpu_lpage_remapped(void *kaddr)
174-
{
175-
return NULL;
176-
}
177-
178-
#endif /* CONFIG_SMP */
179-
180161
extern void __percpu *__alloc_percpu(size_t size, size_t align);
181162
extern void free_percpu(void __percpu *__pdata);
182163
extern phys_addr_t per_cpu_ptr_to_phys(void *addr);

‎include/linux/vmalloc.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ extern rwlock_t vmlist_lock;
117117
extern struct vm_struct *vmlist;
118118
extern __init void vm_area_register_early(struct vm_struct *vm, size_t align);
119119

120+
#ifdef CONFIG_SMP
120121
struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
121122
const size_t *sizes, int nr_vms,
122123
size_t align, gfp_t gfp_mask);
123124

124125
void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
126+
#endif
125127

126128
#endif /* _LINUX_VMALLOC_H */

‎mm/Kconfig‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,11 @@ config NOMMU_INITIAL_TRIM_EXCESS
301301
of 1 says that all excess pages should be trimmed.
302302

303303
See Documentation/nommu-mmap.txt for more information.
304+
305+
#
306+
# UP and nommu archs use km based percpu allocator
307+
#
308+
config NEED_PER_CPU_KM
309+
depends on !SMP
310+
bool
311+
default y

‎mm/Makefile‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ obj-y := bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \
1111
maccess.o page_alloc.o page-writeback.o \
1212
readahead.o swap.o truncate.o vmscan.o shmem.o \
1313
prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \
14-
page_isolation.o mm_init.o mmu_context.o \
14+
page_isolation.o mm_init.o mmu_context.o percpu.o \
1515
$(mmu-y)
1616
obj-y += init-mm.o
1717

@@ -36,11 +36,6 @@ obj-$(CONFIG_FAILSLAB) += failslab.o
3636
obj-$(CONFIG_MEMORY_HOTPLUG) += memory_hotplug.o
3737
obj-$(CONFIG_FS_XIP) += filemap_xip.o
3838
obj-$(CONFIG_MIGRATION) += migrate.o
39-
ifdef CONFIG_SMP
40-
obj-y += percpu.o
41-
else
42-
obj-y += percpu_up.o
43-
endif
4439
obj-$(CONFIG_QUICKLIST) += quicklist.o
4540
obj-$(CONFIG_CGROUP_MEM_RES_CTLR) += memcontrol.o page_cgroup.o
4641
obj-$(CONFIG_MEMORY_FAILURE) += memory-failure.o

‎mm/percpu-km.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@
2727
* chunk size is not aligned. percpu-km code will whine about it.
2828
*/
2929

30-
#ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
30+
#if defined(CONFIG_SMP) && defined(CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK)
3131
#error "contiguous percpu allocation is incompatible with paged first chunk"
3232
#endif
3333

3434
#include <linux/log2.h>
3535

3636
static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size)
3737
{
38-
/* noop */
38+
unsigned int cpu;
39+
40+
for_each_possible_cpu(cpu)
41+
memset((void *)pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size);
42+
3943
return 0;
4044
}
4145

0 commit comments

Comments
 (0)