cpu alloc stage 2
Subsystems (7)
cover cpu alloc stage 2
The second stage of the cpu_alloc patchset can be pulled from
git.kernel.org/pub/scm/linux/kernel/git/christoph/work.git cpu_alloc_stage2
Stage 2 includes the conversion of the page allocator and slub allocator to the use of the cpu allocator.
It also includes the core of the atomic vs. interrupt cpu ops and uses those for the vm statistics.
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/7 Increase default reserve percpu area
SLUB now requires a portion of the per cpu reserve. There are on average about 70 real slabs on a system (aliases do not count) and each needs 12 bytes of per cpu space. Thats 840 bytes. In debug mode all slabs will be real slabs which will make us end up with 150 -> 1800.
Things work fine without this patch but then slub will reduce the percpu reserve for modules.
Percpu data must be available regardless if modules are in use or not. So get rid of the #ifdef CONFIG_MODULES.
Make the size of the percpu area dependant on the size of a machine word. That way we have larger sizes for 64 bit machines. 64 bit machines need more percpu memory since the pointer and counters may have double the size. Plus there is lots of memory available on 64 bit.
include/linux/percpu.h +1 -1
@@ -44,7 +44,7 @@extern unsigned int percpu_reserve;/* Enough to cover all DEFINE_PER_CPUs in kernel, including modules. */ #ifndef PERCPU_AREA_SIZE -#define PERCPU_RESERVE_SIZE 8192 +#define PERCPU_RESERVE_SIZE (sizeof(unsigned long) * 2500)#define PERCPU_AREA_SIZE \ (__per_cpu_end - __per_cpu_start + percpu_reserve)
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/7 cpu alloc: Use in slub
In reply to Christoph LameterUsing cpu alloc removes the needs for the per cpu arrays in the kmem_cache struct. These could get quite big if we have to support system of up to thousands of cpus. The use of cpu_alloc means that:
1. The size of kmem_cache for SMP configuration shrinks since we will only need 1 pointer instead of NR_CPUS. The same pointer can be used by all processors. Reduces cache footprint of the allocator.
2. We can dynamically size kmem_cache according to the actual nodes in the system meaning less memory overhead for configurations that may potentially support up to 1k NUMA nodes / 4k cpus.
3. We can remove the diddle widdle with allocating and releasing of kmem_cache_cpu structures when bringing up and shutting down cpus. The cpu alloc logic will do it all for us. Removes some portions of the cpu hotplug functionality.
4. Fastpath performance increases.
include/linux/slub_def.h +1 -5
@@ -68,6 +68,7 @@* Slab cache management. */ struct kmem_cache { +struct kmem_cache_cpu *cpu_slab;/* Used for retriving partial slabs etc */ unsigned long flags;int size;/* The size of an object including meta data */
@@ -102,11 +103,6 @@int remote_node_defrag_ratio;struct kmem_cache_node *node[MAX_NUMNODES ];#endif -#ifdef CONFIG_SMP -struct kmem_cache_cpu *cpu_slab[NR_CPUS ]; -#else -struct kmem_cache_cpu cpu_slab; -#endif };/*
mm/slub.c +25 -155
316 lines not on this page · raw message
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/7 cpu alloc: Remove slub fields
In reply to Christoph LameterRemove the fields in kmem_cache_cpu that were used to cache data from kmem_cache when they were in different cachelines. The cacheline that holds the per cpu array pointer now also holds these values. We can cut down the struct kmem_cache_cpu size to almost half.
The get_freepointer() and set_freepointer() functions that used to be only intended for the slow path now are also useful for the hot path since access to the field does not require accessing an additional cacheline anymore. This results in consistent use of setting the freepointer for objects throughout SLUB.
Also we initialize all possible kmem_cache_cpu structures when a slab is created. No need to initialize them when a processor or node comes online. And all fields are set to zero. So just use __GFP_ZERO on cpu alloc.
--- include/linux/slub_def.h | 2 -- mm/slub.c | 39 +++++++++++---------------------------- 2 files changed, 11 insertions(+), 30 deletions(-)
include/linux/slub_def.h +0 -2
@@ -36,8 +36,6 @@void **freelist;/* Pointer to first free per cpu object */ struct page *page;/* The slab from which we are allocating */ int node;/* The node of the page (or -1 for debug) */ -unsigned int offset;/* Freepointer offset (in word units) */ -unsigned int objsize;/* Size of an object (from kmem_cache) */ #ifdef CONFIG_SLUB_STATS unsigned stat[NR_SLUB_STAT_ITEMS ];#endif
mm/slub.c +15 -62
170 lines not on this page · raw message
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/7 cpu ops: Core piece for generic atomic per cpu operations
In reply to Christoph LameterCurrently the per cpu subsystem is not able to use the atomic capabilities that are provided by many of the available processors.
This patch adds new functionality that allows the optimizing of per cpu variable handling. In particular it provides a simple way to exploit atomic operations in order to avoid having to disable interrupts or performing address calculation to access per cpu data.
F.e. Using our current methods we may do
unsigned long flags; struct stat_struct *p; local_irq_save(flags); /* Calculate address of per processor area */ p = CPU_PTR(stat, smp_processor_id()); p->counter++; local_irq_restore(flags);
The segment can be replaced by a single atomic CPU operation:
CPU_INC(stat->counter);
Most processors have instructions to perform the increment using a a single atomic instruction. Processors may have segment registers, global registers or per cpu mappings of per cpu areas that can be used to generate atomic instructions that combine the following in a single operation:
1. Adding of an offset / register to a base address
2. Read modify write operation on the address calculated by the instruction.
If 1+2 are combined in an instruction then the instruction is atomic vs interrupts. This means that percpu atomic operations do not need to disable interrupts to increments counters etc.
The existing methods in use in the kernel cannot utilize the power of these atomic instructions. local_t is not really addressing the issue since the offset calculation performed before the atomic operation. The operation is therefor not atomic. Disabling interrupt or preemption is required in order to use local_t.
local_t is also very specific to the x86 processor. The solution here can utilize other methods than just those provided by the x86 instruction set.
On x86 the above CPU_INC translated into a single instruction:
inc %%gs:(&stat->counter)
This instruction is interrupt safe since it can either be completed or not. Both adding of the offset and the read modify write are combined in one instruction.
The determination of the correct per cpu area for the current processor does not require access to smp_processor_id() (expensive...). The gs register is used to provide a processor specific offset to the respective per cpu area where the per cpu variable resides.
Note that the counter offset into the struct was added *before* the segment selector was added. This is necessary to avoid calculations. In the past we first determine the address of the stats structure on the respective processor and then added the field offset. However, the offset may as well be added earlier. The adding of the per cpu offset (here through the gs register) must be done by the instruction used for atomic per cpu access.
If "stat" was declared via DECLARE_PER_CPU then this patchset is capable of convincing the linker to provide the proper base address. In that case no calculations are necessary.
Should the stat structure be reachable via a register then the address calculation capabilities can be leveraged to avoid calculations.
On IA64 we can get the same combination of operations in a single instruction by using the virtual address that always maps to the local per cpu area:
fetchadd &stat->counter + (VCPU_BASE - __per_cpu_start)
The access is forced into the per cpu address reachable via the virtualized address. IA64 allows the embedding of an offset into the instruction. So the fetchadd can perform both the relocation of the pointer into the per cpu area as well as the atomic read modify write cycle.
In order to be able to exploit the atomicity of these instructions we introduce a series of new functions that take either:
1. A per cpu pointer as returned by cpu_alloc() or CPU_ALLOC().
2. A per cpu variable address as returned by per_cpu_var(<percpuvarname>).
CPU_READ()CPU_WRITE()CPU_INCCPU_DECCPU_ADDCPU_SUBCPU_XCHGCPU_CMPXCHG
--- include/linux/percpu.h | 135 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+)
include/linux/percpu.h +135 -0
@@ -162,4 +162,139 @@#define CPU_FREE (pointer) cpu_free((pointer), sizeof(*(pointer))) +/* +* Fast atomic per cpu operations. +* +* The following operations can be overridden by arches to implement fast +* and efficient operations. The operations are atomic meaning that the +* determination of the processor, the calculation of the address and the +* operation on the data is an atomic operation. +* +* The parameter passed to the atomic per cpu operations is an lvalue not a +* pointer to the object. +*/ +#ifndef CONFIG_HAVE_CPU_OPS + +/* +* Fallback in case the arch does not provide for atomic per cpu operations. +* +* The first group of macros is used when it is safe to update the per +* cpu variable because preemption is off (per cpu variables that are not +* updated from interrupt context) or because interrupts are already off. +*/ +#define __CPU_READ (var) \ +({ \ + (*THIS_CPU(&(var))); \ +}) + +#define __CPU_WRITE (var, value) \ +({ \ + *THIS_CPU(&(var)) = (value); \ +}) + +#define __CPU_ADD (var, value) \ +({ \ + *THIS_CPU(&(var)) += (value); \ +}) + +#define __CPU_INC (var) __CPU_ADD((var), 1) +#define __CPU_DEC (var) __CPU_ADD((var), -1) +#define __CPU_SUB (var, value) __CPU_ADD((var), -(value)) + +#define __CPU_CMPXCHG (var, old, new) \ +({ \ + typeof(obj) x; \ + typeof(obj) *p = THIS_CPU(&(obj)); \ + x = *p; \ + if (x == (old)) \ + *p = (new); \ + (x); \ +}) + +#define __CPU_XCHG (obj, new) \ +({ \ + typeof(obj) x; \ + typeof(obj) *p = THIS_CPU(&(obj)); \ + x = *p; \ + *p = (new); \ + (x); \ +}) + +/* +* Second group used for per cpu variables that are not updated from an +* interrupt context. In that case we can simply disable preemption which +* may be free if the kernel is compiled without support for preemption. +*/ +#define _CPU_READ __CPU_READ +#define _CPU_WRITE __CPU_WRITE + +#define _CPU_ADD (var, value) \ +({ \ + preempt_disable(); \ + __CPU_ADD((var), (value)); \ + preempt_enable(); \ +}) + +#define _CPU_INC (var) _CPU_ADD((var), 1) +#define _CPU_DEC (var) _CPU_ADD((var), -1) +#define _CPU_SUB (var, value) _CPU_ADD((var), -(value)) + +#define _CPU_CMPXCHG (var, old, new) \ +({ \ + typeof(addr) x; \ + preempt_disable(); \ + x = __CPU_CMPXCHG((var), (old), (new)); \ + preempt_enable(); \ + (x); \ +}) + +#define _CPU_XCHG (var, new) \ +({ \ + typeof(var) x; \ + preempt_disable(); \ + x = __CPU_XCHG((var), (new)); \ + preempt_enable(); \ + (x); \ +}) + +/* +* Third group: Interrupt safe CPU functions +*/ +#define CPU_READ __CPU_READ +#define CPU_WRITE __CPU_WRITE + +#define CPU_ADD (var, value) \ +({ \ + unsigned long flags; \ + local_irq_save(flags); \ + __CPU_ADD((var), (value)); \ + local_irq_restore(flags); \ +}) + +#define CPU_INC (var) CPU_ADD((var), 1) +#define CPU_DEC (var) CPU_ADD((var), -1) +#define CPU_SUB (var, value) CPU_ADD((var), -(value)) + +#define CPU_CMPXCHG (var, old, new) \ +({ \ + unsigned long flags; \ + typeof(var) x; \ + local_irq_save(flags); \ + x = __CPU_CMPXCHG((var), (old), (new)); \ + local_irq_restore(flags); \ + (x); \ +}) + +#define CPU_XCHG (var, new) \ +({ \ + unsigned long flags; \ + typeof(var) x; \ + local_irq_save(flags); \ + x = __CPU_XCHG((var), (new)); \ + local_irq_restore(flags); \ + (x); \ +}) + +#endif /* CONFIG_HAVE_CPU_OPS */ +#endif /* __LINUX_PERCPU_H */
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 4/7] cpu ops: Core piece for generic atomic per cpu operations
include/linux/percpu.h line 212
Quoted 10 lines · Christoph Lameter
include/linux/percpu.h +10
-0+ +#define __CPU_CMPXCHG (var, old, new) \ +({ \ + typeof(obj) x; \ + typeof(obj) *p = THIS_CPU(&(obj)); \ + x = *p; \ + if (x == (old)) \ + *p = (new); \ + (x); \ +})
I don't think that will compile - s/obj/var/ perhaps?
Cheers,
Dave.
Signature · 8 lines
Dave Chinner [email protected] -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 4/7] cpu ops: Core piece for generic atomic per cpu operations
Quoted 13 lines · Dave Chinner
include/linux/percpu.h line 212
Quoted 10 lines · Christoph Lameter
include/linux/percpu.h +10
-0+ +#define __CPU_CMPXCHG (var, old, new) \ +({ \ + typeof(obj) x; \ + typeof(obj) *p = THIS_CPU(&(obj)); \ + x = *p; \ + if (x == (old)) \ + *p = (new); \ + (x); \ +})I don't think that will compile - s/obj/var/ perhaps?
Correct.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 5/7 x86_64: Support for cpu ops
In reply to Christoph LameterSupport fast cpu ops in x86_64 by providing a series of functions that generate the proper instructions.
Define CONFIG_HAVE_CPU_OPS so that core code can exploit the availability of fast per cpu operations.
--- arch/x86/Kconfig | 9 +++++++++ include/asm-x86/percpu.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
arch/x86/Kconfig +9 -0
@@ -164,6 +164,15 @@ depends on GENERIC_HARDIRQS && SMP default y +# +# X86_64's spare segment register points to the PDA instead of the per +# cpu area. Therefore x86_64 is not able to generate atomic vs. interrupt +# per cpu instructions. +# +config HAVE_CPU_OPS + def_bool y + depends on X86_32 + config X86_SMP bool depends on SMP && ((X86_32 && !X86_VOYAGER) || X86_64)
arch/x86/include/asm/percpu.h +87 -0
97 lines not on this page · raw message
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 5/7] x86_64: Support for cpu ops
arch/x86/Kconfig line 175
Quoted 9 lines · Christoph Lameter
arch/x86/Kconfig +9
-0+# +# X86_64's spare segment register points to the PDA instead of the per +# cpu area. Therefore x86_64 is not able to generate atomic vs. interrupt +# per cpu instructions. +# +config HAVE_CPU_OPS + def_bool y + depends on X86_32 +
hm, what happened to the rebase-PDA-to-percpu-area optimization patches you guys were working on? I remember there was some binutils flakiness - weird crashes and things like that. Did you ever manage to stabilize it? It would be sad if only 32-bit could take advantage of the optimized ops.
Ingo
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 5/7] x86_64: Support for cpu ops
Quoted 5 lines · Ingo Molnar
hm, what happened to the rebase-PDA-to-percpu-area optimization patches you guys were working on? I remember there was some binutils flakiness - weird crashes and things like that. Did you ever manage to stabilize it? It would be sad if only 32-bit could take advantage of the optimized ops.
I thought that was in your tree? I saw a conflict in -next with the zero based stuff a couple of weeks ago. Mike is working on that AFAICT.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 5/7] x86_64: Support for cpu ops
Quoted 11 lines · Christoph Lameter
Quoted 5 lines · Ingo Molnar
hm, what happened to the rebase-PDA-to-percpu-area optimization patches you guys were working on? I remember there was some binutils flakiness - weird crashes and things like that. Did you ever manage to stabilize it? It would be sad if only 32-bit could take advantage of the optimized ops.
I thought that was in your tree? I saw a conflict in -next with the zero based stuff a couple of weeks ago. Mike is working on that AFAICT.
No, what's in tip/core/percpu is not the PDA patches:
f8d90d9: percpu: zero based percpu build error on s390
cfcfdff: Merge branch 'linus' into core/percpu
d379497: Zero based percpu: infrastructure to rebase the per cpu area to zero
b3a0cb4: x86: extend percpu ops to 64 bit
But it's not actually utilized on x86. AFAICS you guys never came back with working patches for that (tip/x86/percpu is empty currently), and now i see something related on lkml on a separate track not Cc:-ed to the x86 folks so i thought i'd ask whether more coordination is desired here.
So ... what's the merge plan here? I like your fundamental idea, it's a nice improvement in a couple of areas and i'd like to help out make it happen. Also, the new per-cpu allocator would be nice for the sparseirq code.
Ingo
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 5/7] x86_64: Support for cpu ops
Quoted 26 lines · Ingo Molnar
Quoted 10 lines · Christoph Lameter
Quoted 5 lines · Ingo Molnar
hm, what happened to the rebase-PDA-to-percpu-area optimization patches you guys were working on? I remember there was some binutils flakiness - weird crashes and things like that. Did you ever manage to stabilize it? It would be sad if only 32-bit could take advantage of the optimized ops.
I thought that was in your tree? I saw a conflict in -next with the zero based stuff a couple of weeks ago. Mike is working on that AFAICT.
No, what's in tip/core/percpu is not the PDA patches:
f8d90d9: percpu: zero based percpu build error on s390
cfcfdff: Merge branch 'linus' into core/percpu
d379497: Zero based percpu: infrastructure to rebase the per cpu area to zero
b3a0cb4: x86: extend percpu ops to 64 bitBut it's not actually utilized on x86. AFAICS you guys never came back with working patches for that (tip/x86/percpu is empty currently), and now i see something related on lkml on a separate track not Cc:-ed to the x86 folks so i thought i'd ask whether more coordination is desired here.
Quoted 6 lines
So ... what's the merge plan here? I like your fundamental idea, it's a nice improvement in a couple of areas and i'd like to help out make it happen. Also, the new per-cpu allocator would be nice for the sparseirq code.
Ingo
Sorry, this was on my plate but the 4096 cpus if far more critical to get released and available. As soon as that's finally done, I can get back to the pda/zero-based changes.
Thanks,
Mike
Re: [patch 5/7] x86_64: Support for cpu ops
Quoted 3 lines · Mike Travis
Sorry, this was on my plate but the 4096 cpus if far more critical to get released and available. As soon as that's finally done, I can get back to the pda/zero-based changes.
You cannot solve your 4k issues without getting the zerobased stuff in becaus otherwise the large pointer arrays in the core (page allocator and slab allocator etc) are not removable. Without getting zerobased sorted out you will produce a lot of hacks around subsystems that create pointer arrays that would go away easily if you had the percpu aallocator.
I'd say getting the zero based stuff issues fixed is a prerequisie for further work on 4k making sense.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 5/7] x86_64: Support for cpu ops
In reply to Ingo MolnarQuoted 5 lines · Ingo Molnar
But it's not actually utilized on x86. AFAICS you guys never came back with working patches for that (tip/x86/percpu is empty currently), and now i see something related on lkml on a separate track not Cc:-ed to the x86 folks so i thought i'd ask whether more coordination is desired here.
We should definitely look into this but my priorities have changed a bit. 32 bit is far more significant for me now.
Could you point me to a post that describes the currently open issues with x86_64? Mike handled that before.
Quoted 4 lines
So ... what's the merge plan here? I like your fundamental idea, it's a nice improvement in a couple of areas and i'd like to help out make it happen. Also, the new per-cpu allocator would be nice for the sparseirq code.
Right. Its good in many areas.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 6/7 VM statistics: Use CPU ops
In reply to Christoph LameterThe use of CPU ops here avoids the offset calculations that we used to have to do with per cpu operations. The result of this patch is that event counters are coded with a single instruction the following way:
incq %gs:offset(%rip)
Without these patches this was:
mov %gs:0x8,%rdx mov %eax,0x38(%rsp) mov xxx(%rip),%eax mov %eax,0x48(%rsp) mov varoffset,%rax incq 0x110(%rax,%rdx,1)
--- include/linux/vmstat.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
include/linux/vmstat.h +4 -6
@@ -75,24 +75,22 @@static inline void __count_vm_event (enum vm_event_item item) { -__get_cpu_var (vm_event_states).event[item]++; +__CPU_INC (per_cpu_var (vm_event_states).event[item]); }static inline void count_vm_event (enum vm_event_item item) { -get_cpu_var (vm_event_states).event[item]++; -put_cpu (); +_CPU_INC (per_cpu_var (vm_event_states).event[item]); }static inline void __count_vm_events (enum vm_event_item item,long delta) { -__get_cpu_var (vm_event_states).event[item] += delta; +__CPU_ADD (per_cpu_var (vm_event_states).event[item], delta); }static inline void count_vm_events (enum vm_event_item item,long delta) { -get_cpu_var (vm_event_states).event[item] += delta; -put_cpu (); +_CPU_ADD (per_cpu_var (vm_event_states).event[item], delta); }extern void all_vm_events (unsigned long *);
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 7/7 cpu alloc: page allocator conversion
In reply to Christoph LameterUse the new cpu_alloc functionality to avoid per cpu arrays in struct zone. This drastically reduces the size of struct zone for systems with a large amounts of processors and allows placement of critical variables of struct zone in one cacheline even on very large systems.
Another effect is that the pagesets of one processor are placed near one another. If multiple pagesets from different zones fit into one cacheline then additional cacheline fetches can be avoided on the hot paths when allocating memory from multiple zones.
Surprisingly this clears up much of the painful NUMA bringup. Bootstrap becomes simpler if we use the same scheme for UP, SMP, NUMA. #ifdefs are reduced and we can drop the zone_pcp macro.
Hotplug handling is also simplified since cpu alloc can bring up and shut down cpu areas for a specific cpu as a whole. So there is no need to allocate or free individual pagesets.
--- include/linux/mm.h | 4 - include/linux/mmzone.h | 12 --- mm/page_alloc.c | 162 +++++++++++++++++++------------------------------ mm/vmstat.c | 15 ++-- 4 files changed, 74 insertions(+), 119 deletions(-)
include/linux/mm.h +0 -4
@@ -1042,11 +1042,7 @@extern void si_meminfo_node (struct sysinfo *val,int nid);extern int after_bootmem; -#ifdef CONFIG_NUMA extern void setup_per_cpu_pageset (void ); -#else -static inline void setup_per_cpu_pageset (void ) {} -#endif /* prio_tree.c */ void vma_prio_tree_add (struct vm_area_struct *,struct vm_area_struct *old);
include/linux/mmzone.h +2 -10
@@ -182,13 +182,7 @@s8 stat_threshold;s8 vm_stat_diff[NR_VM_ZONE_STAT_ITEMS ]; #endif -}____cacheline_aligned_in_smp ; - -#ifdef CONFIG_NUMA -#define zone_pcp (__z, __cpu) ((__z)->pageset[(__cpu)]) -#else -#define zone_pcp (__z, __cpu) (&(__z)->pageset[(__cpu)]) -#endif +};#endif /* !__GENERATING_BOUNDS.H */
@@ -283,10 +277,8 @@*/ unsigned long min_unmapped_pages;unsigned long min_slab_pages; -struct per_cpu_pageset *pageset[NR_CPUS ]; -#else -struct per_cpu_pageset pageset[NR_CPUS ];#endif +struct per_cpu_pageset *pageset;/* * free areas of different sizes */
mm/page_alloc.c +50 -101
264 lines not on this page · raw message
mm/vmstat.c +8 -6
@@ -143,7 +143,8 @@ threshold =calculate_threshold (zone);for_each_online_cpu (cpu) -zone_pcp (zone, cpu)->stat_threshold = threshold; +CPU_PTR (zone->pageset, cpu)->stat_threshold + = threshold; } }
@@ -153,7 +154,8 @@void __mod_zone_page_state (struct zone *zone,enum zone_stat_item item,int delta) { -struct per_cpu_pageset *pcp =zone_pcp (zone,smp_processor_id ()); +struct per_cpu_pageset *pcp =THIS_CPU (zone->pageset); +s8 *p = pcp->vm_stat_diff + item;long x;
@@ -206,7 +208,7 @@*/ void __inc_zone_state (struct zone *zone,enum zone_stat_item item) { -struct per_cpu_pageset *pcp =zone_pcp (zone,smp_processor_id ()); +struct per_cpu_pageset *pcp =THIS_CPU (zone->pageset);s8 *p = pcp->vm_stat_diff + item; (*p)++;
@@ -227,7 +229,7 @@void __dec_zone_state (struct zone *zone,enum zone_stat_item item) { -struct per_cpu_pageset *pcp =zone_pcp (zone,smp_processor_id ()); +struct per_cpu_pageset *pcp =THIS_CPU (zone->pageset);s8 *p = pcp->vm_stat_diff + item; (*p)--;
@@ -307,7 +309,7 @@if (!populated_zone (zone))continue ; - p =zone_pcp (zone, cpu); + p =CPU_PTR (zone->pageset, cpu);for (i =0 ; i <NR_VM_ZONE_STAT_ITEMS ; i++)if (p->vm_stat_diff[i]) {
@@ -759,7 +761,7 @@for_each_online_cpu (i) {struct per_cpu_pageset *pageset; - pageset =zone_pcp (zone, i); + pageset =CPU_PTR (zone->pageset, i);seq_printf (m,"\n cpu: %i" "\n count: %i"
mm/cpu_alloc.c +4 -0
@@ -189,6 +189,8 @@void __init cpu_alloc_init (void ) { +extern void allocate_pagesets (void ); +#ifdef CONFIG_SMP base_percpu_in_units = (__per_cpu_end - __per_cpu_start +UNIT_SIZE -1 ) /UNIT_SIZE ;
@@ -199,5 +201,7 @@#ifndef CONFIG_SMP cpu_alloc_start =alloc_bootmem (nr_units *UNIT_SIZE );#endif +/* Allocate pagesets whose allocation was deferred */ +allocate_pagesets (); }
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 7/7] cpu alloc: page allocator conversion
Quoted 8 lines
mm/page_alloc.c +1
-0+#ifdef CONFIG_SMP static int __cpuinit pageset_cpuup_callback (struct notifier_block *nfb,unsigned long action,void *hcpu)@@ -2800,14 +2746,7 @@switch (action) {case CPU_UP_PREPARE :case CPU_UP_PREPARE_FROZEN :
mm/page_alloc.c line 2750
Quoted 10 lines
mm/page_alloc.c +1
-8-if (process_zones (cpu)) - ret =NOTIFY_BAD ; -break ; -case CPU_UP_CANCELED : -case CPU_UP_CANCELED_FROZEN : -case CPU_DEAD : -case CPU_DEAD_FROZEN : -free_zone_pagesets (cpu); +process_zones (cpu);break ;
Why do you drop cpu unplug code?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 7/7] cpu alloc: page allocator conversion
Quoted 5 lines · KOSAKI Motohiro
mm/page_alloc.c line 2750
Quoted 3 lines
mm/page_alloc.c +1
-1-free_zone_pagesets (cpu); +process_zones (cpu);break ;Why do you drop cpu unplug code?
Because it does not do anything. Percpu areas are traditionally allocated for each possible cpu not for each online cpu.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 7/7] cpu alloc: page allocator conversion
Quoted 10 lines · KOSAKI Motohiro
Quoted 6 lines
mm/page_alloc.c line 2750
Quoted 4 lines
mm/page_alloc.c +1
-1-free_zone_pagesets (cpu); +process_zones (cpu);break ;Why do you drop cpu unplug code?
Because it does not do anything. Percpu areas are traditionally allocated for each possible cpu not for each online cpu.
Yup, Agreed.
However, if cpu-unplug happend, any pages in pcp should flush to buddy (I think).
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 7/7] cpu alloc: page allocator conversion
Quoted 1 line · KOSAKI Motohiro
However, if cpu-unplug happend, any pages in pcp should flush to buddy (I think).
Right. They are not?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 7/7] cpu alloc: page allocator conversion
Quoted 6 lines · KOSAKI Motohiro
Quoted 2 lines
However, if cpu-unplug happend, any pages in pcp should flush to buddy (I think).
Right. They are not?
Doh, I really silly.
yes, pcp dropping is processed by another function. I missed it.
very sorry.
In addition, I think cleanup is better.
I made the patch.
===========================================================
Now, page_alloc_init() doesn't have page allocator stuff and there are the cpu unplug processing for pcp in two place (pageset_cpuup_callback() and page_alloc_init()).
it isn't reasonable nor easy readable.
cleanup here.
--- init/main.c | 1 mm/page_alloc.c | 60 +++++++++++++++++++++++++------------------------------- 2 files changed, 27 insertions(+), 34 deletions(-)
mm/page_alloc.c +27 -33
@@ -2765,6 +2765,28 @@ static void __cpuinit process_zones(int }#ifdef CONFIG_SMP +static void drain_pages_and_fold_stats (int cpu) +{ +drain_pages (cpu); + +/* +* Spill the event counters of the dead processor +* into the current processors event counters. +* This artificially elevates the count of the current +* processor. +*/ +vm_events_fold_cpu (cpu); + +/* +* Zero the differential counters of the dead processor +* so that the vm statistics are consistent. +* +* This is only okay since the processor is dead and cannot +* race with what we are doing. +*/ +refresh_cpu_vm_stats (cpu); +} +static int __cpuinit pageset_cpuup_callback (struct notifier_block *nfb,unsigned long action,void *hcpu)
@@ -2777,6 +2799,11 @@ static int __cpuinit pageset_cpuup_callbcase CPU_UP_PREPARE_FROZEN :process_zones (cpu);break ; +case CPU_DEAD : +case CPU_DEAD_FROZEN : +drain_pages_and_fold_stats (cpu); +break ; +default :break ; }
@@ -4092,39 +4119,6 @@ void __init free_area_init(unsigned long __pa(PAGE_OFFSET) >> PAGE_SHIFT, NULL); } -static int page_alloc_cpu_notify (struct notifier_block *self, -unsigned long action,void *hcpu) -{ -int cpu = (unsigned long )hcpu; - -if (action ==CPU_DEAD || action ==CPU_DEAD_FROZEN ) { -drain_pages (cpu); - -/* -* Spill the event counters of the dead processor -* into the current processors event counters. -* This artificially elevates the count of the current -* processor. -*/ -vm_events_fold_cpu (cpu); - -/* -* Zero the differential counters of the dead processor -* so that the vm statistics are consistent. -* -* This is only okay since the processor is dead and cannot -* race with what we are doing. -*/ -refresh_cpu_vm_stats (cpu); - } -return NOTIFY_OK ; -} - -void __init page_alloc_init (void ) -{ -hotcpu_notifier (page_alloc_cpu_notify,0 ); -} -/* * calculate_totalreserve_pages - called when sysctl_lower_zone_reserve_ratio * or min_free_kbytes changes.
init/main.c +0 -1
@@ -619,7 +619,6 @@ asmlinkage void __init start_kernel(void*/ preempt_disable ();build_all_zonelists (); -page_alloc_init ();printk (KERN_NOTICE "Kernel command line: %s\n" , boot_command_line);parse_early_param (); parse_args("Booting kernel", static_command_line, __start___param,
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [patch 7/7] cpu alloc: page allocator conversion
Thanks for the patch. Folded into this one with your signoff (okay right?)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 9 lines · On Wed, 05 Nov 2008 17:16:34 -0600 Christoph Lameter <[email protected]>…
The second stage of the
cpu_allocpatchset can be pulled fromgit.kernel.org/pub/scm/linux/kernel/git/christoph/work.git
cpu_alloc_stage2Stage 2 includes the conversion of the page allocator and slub allocator to the use of the cpu allocator.
It also includes the core of the atomic vs. interrupt cpu ops and uses those for the vm statistics.
It all looks very nice to me. It's a shame about the lack of any commonality with local_t though.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines · Andrew Morton
It all looks very nice to me. It's a shame about the lack of any commonality with
local_tthough.
At the end of the full patchset local_t is no more because cpu ops can completely replace all use cases for local_t.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Christoph,
Quoted 10 lines · On Wed, 05 Nov 2008 17:16:34 -0600 Christoph Lameter <[email protected]>…
The second stage of the
cpu_allocpatchset can be pulled fromgit.kernel.org/pub/scm/linux/kernel/git/christoph/work.git
cpu_alloc_stage2Stage 2 includes the conversion of the page allocator and slub allocator to the use of the cpu allocator.
It also includes the core of the atomic vs. interrupt cpu ops and uses those for the vm statistics.
I have seen some discussion of these patches (and some fixes for the previous set). Are they in a state that they should be in linux-next yet?
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
Quoted 2 lines · Stephen Rothwell
I have seen some discussion of these patches (and some fixes for the previous set). Are they in a state that they should be in linux-next yet?
I will push out a new patchset and tree in the next hour or so for you to merge into linux-next.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Christoph,
Quoted 8 lines · On Wed, 12 Nov 2008 14:07:51 -0600 (CST) Christoph Lameter…
Quoted 2 lines · Stephen Rothwell
I have seen some discussion of these patches (and some fixes for the previous set). Are they in a state that they should be in linux-next yet?
I will push out a new patchset and tree in the next hour or so for you to merge into linux-next.
Why not just add these to the cpu_alloc tree I already have?
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
Quoted 4 lines · Stephen Rothwell
Quoted 2 lines
I will push out a new patchset and tree in the next hour or so for you to merge into linux-next.
Why not just add these to the
cpu_alloctree I already have?
What happens if there are problems with the next stage? I want to make sure that at least the basis is merged.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
I put a cpu_alloc_stage2 onto the git archive
git.kernel.org/pub/scm/linux/kernel/git/christoph/work.git cpu_alloc_stage2
Not sure if I should dare to merge it into the cpu_alloc branch. Its pretty touchy work with some of the core components.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>