Skip to contentSkip to conversation

Improve alloc_percpu: expose percpu_modalloc and percpu_modfree

PATCH In review Rusty Russell 2 participants 4 messages Nov 17, 2008 – Nov 18, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/7 Improve alloc_percpu: expose percpu_modalloc and percpu_modfree

This simply moves the percpu allocator functions from the module code to mm/allocpercpu.c. percpu_modinit is renamed percpu_alloc_init and called from init/main.c.

(Note: this allocator will need to be weaned off krealloc for use in the slab allocator itself as Christoph does in one of his patches).

Cc Christoph Lameter <[email protected]>
---
 include/linux/percpu.h |   11 +++
 kernel/module.c        |  145 -------------------------------------------------
 mm/allocpercpu.c       |  134 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 146 insertions(+), 144 deletions(-)
include/linux/percpu.h +13 -0
diff -r 81ce6015186e include/linux/percpu.h
@@ -78,6 +78,8 @@
 extern void *__percpu_alloc_mask(size_t size, gfp_t gfp, cpumask_t *mask);
 extern void percpu_free(void *__pdata);
 
+void *percpu_modalloc(unsigned long size, unsigned long align);
+void percpu_modfree(void *pcpuptr);
 #else /* CONFIG_SMP */
 
 #define percpu_ptr(ptr, cpu) ({ (void)(cpu); (ptr); })
@@ -92,6 +94,15 @@
 	kfree(__pdata);
 }
 
+static inline void *percpu_modalloc(unsigned long size, unsigned long align)
+{
+	return kzalloc(size);
+}
+
+static inline void percpu_modfree(void *pcpuptr)
+{
+	kfree(pcpuptr);
+}
 #endif /* CONFIG_SMP */
 
 #define percpu_alloc_mask(size, gfp, mask) \
@@ -108,4 +119,6 @@
 #define free_percpu(ptr)	percpu_free((ptr))
 #define per_cpu_ptr(ptr, cpu)	percpu_ptr((ptr), (cpu))
 
+void percpu_alloc_init(void);
+
 #endif /* __LINUX_PERCPU_H */
init/main.c +1 -0
diff -r 81ce6015186e init/main.c
@@ -655,6 +655,7 @@
 	enable_debug_pagealloc();
 	cpu_hotplug_init();
 	kmem_cache_init();
+	percpu_alloc_init();
 	debug_objects_mem_init();
 	idr_init_cache();
 	setup_per_cpu_pageset();
kernel/module.c +1 -144

164 lines not on this page · raw message

mm/allocpercpu.c +131 -0

143 lines not on this page · raw message

#1 lore raw

include/linux/percpu.h line 100

Quoted 4 lines · Rusty Russell
include/linux/percpu.h +4 -0
+static inline void *percpu_modalloc(unsigned long size, unsigned long align)
+{
+	return kzalloc(size);
+}

You didn't test the patches much, did you? :)

Jörn

Signature · 2 lines
This above all: to thine own self be true.
-- Shakespeare
#2 lore raw
Quoted 7 lines · On Tuesday 18 November 2008 00:17:13 Jörn Engel wrote:

Review

Quoted 4 lines · Rusty Russell
(quoted diff) +4 -0
+static inline void *percpu_modalloc(unsigned long size, unsigned long align)
+{
+	return kzalloc(size);
+}

You didn't test the patches much, did you? :)

No, not UP :) I'd spent over four hours on them, so I figured it was time to post them and get some concrete discussion.

Compiled and tested now, thanks!
Rusty.

cpualloc: Fixes for CONFIG_SMP=n

include/linux/percpu.h +5 -1
diff -r 275b441d957b include/linux/percpu.h
@@ -79,12 +79,16 @@
 #else
 static inline void *__alloc_percpu(unsigned long size, unsigned long align)
 {
-	return kzalloc(size);
+	return kzalloc(size, GFP_KERNEL);
 }
 
 static inline void free_percpu(void *pcpuptr)
 {
 	kfree(pcpuptr);
+}
+
+static inline void percpu_alloc_init(void)
+{
 }
 #endif /* CONFIG_SMP */
 
#3 lore raw
Quoted 6 lines · Rusty Russell
Quoted 2 lines · On Tuesday 18 November 2008 00:17:13 Jörn Engel wrote:

You didn't test the patches much, did you? :)

No, not UP :) I'd spent over four hours on them, so I figured it was time to post them and get some concrete discussion.

Oh, absolutely. I just wish I could give a more substantial comment to all this.

Jörn

Signature · 2 lines
A defeated army first battles and then seeks victory.
-- Sun Tzu