cpu alloc v1: Optimize by removing arrays of pointers to per cpu objects
Subsystems (27)
cover cpu alloc v1: Optimize by removing arrays of pointers to per cpu objects
In various places the kernel maintains arrays of pointers indexed by processor numbers. These are used to locate objects that need to be used when executing on a specirfic processor. Both the slab allocator and the page allocator use these arrays and there the arrays are used in performance critical code. The allocpercpu functionality is a simple allocator to provide these arrays. However, there are certain drawbacks in using such arrays:
1. The arrays become huge for large systems and may be very sparsely populated (if they are dimensionied for NR_CPUS) on an architecture like IA64 that allows up to 4k cpus if a kernel is then booted on a machine that only supports 8 processors.
2. The arrays cause surrounding variables to no longer fit into a single cacheline. The layout of core data structure is typically optimized so that variables frequently used together are placed in the same cacheline. Arrays of pointers move these variables far apart and destroy this effect.
3. A processor frequently follows only one pointer for its own use. Thus that cacheline with that pointer has to be kept in memory. The neighboring pointers are all to other processors that are rarely used. So a whole cacheline of 128 bytes may be consumed but only 8 bytes of information is constant use. It would be better to be able to place more information in this cacheline.
4. The lookup of the per cpu object is expensive and requires multiple memory accesses to:
A) smp_processor_id()
B) pointer to the base of the per cpu pointer array
C) pointer to the per cpu object in the pointer array
D) the per cpu object itself.
5. Each use of allocper requires its own per cpu array. On large system large arrays have to be allocated again and again.
6. Processor hotplug cannot effectively track the per cpu objects since the VM cannot find all memory that was allocated for a specific cpu. It is impossible to add or remove objects in a consistent way. Although the allocpercpu subsystem was extended to add that capability is not used since use would require adding cpu hotplug callbacks to each and every use of allocpercpu in the kernel.
The patchset here provides an cpu allocator that arranges data differently. Objects are placed tightly in linear areas reserved for each processor. The areas are of a fixed size so that address calculation can be used instead of a lookup. This means that
6. The VM knows where all the per cpu variables are and it could remove or add cpu areas as cpus come online or go offline.
5. There is no need for per cpu pointer arrays.
4. The lookup of a per cpu object is easy and requires memory access to:
A) smp_processor_id()
B) cpu pointer to the object
C) the per cpu object itself.
3. So one access to the not very friendly cacheline that only contains a single useful pointer is avoided. The cache footprint is reduced.
2. Surrounding variables can be placed in the same cacheline. This allow f.e. in SLUB to avoid caching objects in per cpu structures since the kmem_cache structure is finally available without the need to access a cache cold cacheline.
1. A single pointer can be used regardless of the number of processors in the system.
The cpu allocator managed data beginning at CPU_AREA_BASE. The pointer to access item DATA on processor X can then be calculated using
POINTER = CPU_AREA_BASE + DATA + (X << CPU_AREA_ORDER)
This makes the allocator rely on a fixed address of the cpu area and on a fixed size of memory for each processor (similar to S/390s way of addressing percpu variables).
The allocator can be configured in two ways:
1. Static configuration
The cpu areas are directly mapped memory addresses. Thus the memory in the cpu areas is fixed and is allocated as a static variable.
The default configuration of the cpu allocator (if no arch code changed settings) is to reserve a 64k area for each processor.
2. Virtual configuration
The cpu areas are virtualized. Memory in cpu areas is allocated on demand. The MMU is used to map memory allocated into the cpu areas (in same way that the virtual memmap functionality does it).
The maximum sizes for the cpu areas is only dependent on the amount of virtual memory available. The virtualization can use large mappings (PMDs f.e.) in order to avoid TLB pressure that could occur on system that only have a small page when heavy use of cpu areas is made.
This patch increases the speed of the SLUB fastpath and it is likely that similar results can be obtained for other kernel subsystems :
Allocation of 10000 objects of each size. Measurement of the cycles for each action:
Size SLUBmm cpu alloc
-------------------------
8 45 38 16 49 43 32 61 53 64 82 75 128 188 176 256 207 204 512 260 250 1024 398 391 2048 530 511 4096 342 376
Allocation and then immeidate freeing of an object. Measured in cycles for each alloc/free action:
alloc/free test
SLUBmm cpu alloc
68-72 56-58
The cpu allocator also removes the difference in handling SMP, UP and NUMA in the slab and page allocate and simplifies code. It is advantageous even for UP to place per cpu data from different zones or different slabs in the same cacheline. Cpu alloc makes uniform handling of cpu data on all three different types of configurations possible.
The cpu allocator also decreases the memory needs for per cpu storage.
On a classic configuration with SLAB, 32 processors and the allocation of a 4 byte counter via allocpercpu one needs the following on a 64 bit platform:
32 * 8 256 Array indexed by processor
32 * 32 1024 32 objects. The minimum allocation size of SLAB is 32.
------------------------------------------------------------------------------
Total 1280 bytes
cpu alloc needs
32 * 4 128 bytes
This is one tenth of storage. Granted this is the worst case scenario for a 32 processor system but it shows the savings that can be had. cpu alloc can allocate 10 counters in the same cacheline for the price of one with allocpercpu. The allocpercpu counters are likely dispersed over all of memory. So multiple cachelines (in the worst case 10) need to be kept in memory if those counters need constant updating. cpu alloc will keep the 10 counter in a single cacheline. cpu alloc can keep up to 16 counters in the same cacheline if the machine has a 64 byte cacheline size.
The use of the cpu area is usually pretty minimal. 32 bit SMP systems typicaly use about 8k of cpu area space after bootup. 64 bit SMP around 16k. Small NUMA systems (8p 4node) use about 64k. Large NUMA system may need a megabyte of cpu area.
The usage of the per cpu areas typically increases by
1. New slabs being created (needs about 12 bytes per slab on 32 bit, 20 on 64 bit)
2. New devices being mounted that need cpu data for statistics
3. Network devices statistics
4. Special network features (Dave needs to run 100000 IP tunnels)
The current use of the cpu area can be seen in the field
cpu_bytes
in /proc/vmstat
Drawbacks:
1. The per cpu area size is fixed
If we use a virtually mapped area then this is not a problem if there is sufficient virtual space. The 100000 IP tunnels are only realistic with a virtually mapped cpu area.
2. The cpu allocator cannot control allocation of individual objects like allocpercpu may. This is in actuality never used except in net/iucv/iucv.c where we have a single case of a per cpu allocation being used to allocate GFP_DMA structures(!). A patch is provided that replaces the use of allocpercpu with explicit calls to allocators for each object in iucv.c
TODO:
- Currently only i386, ia64 and x86_64 arch definitions are provided. Other arches fall back to 64k static configurations.
- Cpu hotplug support. Current we simply allocate for all possible processors. We could reduce this to only online processors if we could allocate the cpu area for the new processor before the callbacks are run and if we could free the cpu areas for a processor going down after all the callbacks for that were run.
- There are various modifications to exotic configurations that still need some testing (f.e. s/390 iucv--whatever that is--) etc. Tests were done on UP(i386) SMP(i386, x86_64) and NUMA (x86_64, ia64)
The patchset implements cpu alloc and then gradually replaces all uses of allocpercpu in the kernel. The last patch removes the allocpercpu support. If the last patch is not applied then allocpercpu can coexist with cpu alloc.
The patchset is available also via
git pull git://git.kernel.org/pub/scm/linux/kernel/git/christoph/slab.git cpu_alloc
The following patches are based on the linux-2.6 git tree +
git://git.kernel.org/pub/scm/linux/kernel/git/christoph/slab.git performance
(which is the mm version of SLUB)
PATCH 1/28 cpu alloc: The allocator
The core portion of the cpu allocator.
The per cpu allocator allows dynamic allocation of memory on all processor simultaneously. A bitmap is used to track used areas. The allocator implements tight packing to reduce the cache footprint and increase speed since cacheline contention is typically not a concern for memory mainly used by a single cpu. Small objects will fill up gaps left by larger allocations that required alignments.
--- include/linux/cpu_alloc.h | 56 ++++++ include/linux/mm.h | 13 + include/linux/vmstat.h | 2 mm/Kconfig | 33 +++ mm/Makefile | 3 mm/cpu_alloc.c | 407 ++++++++++++++++++++++++++++++++++++++++++++++ mm/vmstat.c | 1 7 files changed, 512 insertions(+), 3 deletions(-)
mm/cpu_alloc.c new file +407 -0
@@ -0,0 +1,407 @@ +/* +* Cpu allocator - Manage objects allocated for each processor +* +* (C) 2007 SGI, Christoph Lameter <[email protected]> +* Basic implementation with allocation and free from a dedicated per +* cpu area. +* +* The per cpu allocator allows dynamic allocation of memory on all +* processor simultaneously. A bitmap is used to track used areas. +* The allocator implements tight packing to reduce the cache footprint +* and increase speed since cacheline contention is typically not a concern +* for memory mainly used by a single cpu. Small objects will fill up gaps +* left by larger allocations that required alignments. +*/ +#include <linux/mm.h> +#include <linux/mmzone.h> +#include <linux/module.h> +#include <linux/cpu_alloc.h> +#include <linux/bitmap.h> +#include <linux/vmalloc.h> +#include <linux/bootmem.h> +#include <linux/sched.h> /* i386 definition of init_mm */ +#include <linux/highmem.h> /* i386 dependency on highmem config */ +#include <asm/pgtable.h> +#include <asm/pgalloc.h> + +/* +* Basic allocation unit. A bit map is created to track the use of each +* UNIT_SIZE element in the cpu area. +*/ + +#define UNIT_SIZE sizeof(int) +#define UNITS_PER_BLOCK (ALLOC_SIZE / UNIT_SIZE) + +/* +* Lock to protect the bitmap and the meta data for the cpu allocator. +*/ +static DEFINE_SPINLOCK (cpu_alloc_map_lock); + +#ifdef CONFIG_CPU_AREA_VIRTUAL + +/* +* Virtualized cpu area. The cpu area can be extended if more space is needed. +*/ + +#define cpu_area ((u8 *)(CPU_AREA_BASE)) +#define ALLOC_SIZE (1UL << (CONFIG_CPU_AREA_ALLOC_ORDER + PAGE_SHIFT)) + +/* +* The maximum number of blocks is the maximum size of the +* cpu area for one processor divided by the size of an allocation +* block. +*/ +#define MAX_BLOCKS (1UL << (CONFIG_CPU_AREA_ORDER - \ + CONFIG_CPU_AREA_ALLOC_ORDER)) + + +static unsigned long *cpu_alloc_map =NULL ; +static int cpu_alloc_map_order =-1 ;/* Size of the bitmap in page order */ +static unsigned long active_blocks;/* Number of block allocated on each cpu */ +static unsigned long units_free;/* Number of available units */ +static unsigned long units_total;/* Total units that are managed */ + +/* +* Allocate a block of memory to be used to provide cpu area memory +* or to extend the bitmap for the cpu map. +*/ +void *cpu_area_alloc_block (unsigned long size,gfp_t flags,int node) +{ +struct page *page =alloc_pages_node (node, + flags,get_order (size)); +if (page) +return page_address (page); +return NULL ; +} + +pte_t *cpu_area_pte_populate (pmd_t *pmd,unsigned long addr, +gfp_t flags,int node) +{ +pte_t *pte =pte_offset_kernel (pmd, addr); +if (pte_none (*pte)) { +pte_t entry; +void *p =cpu_area_alloc_block (PAGE_SIZE , flags, node); +if (!p) +return 0 ; + entry =pfn_pte (__pa (p) >>PAGE_SHIFT ,PAGE_KERNEL ); +set_pte_at (&init_mm, addr, pte, entry); + } +return pte; +} + +pmd_t *cpu_area_pmd_populate (pud_t *pud,unsigned long addr, +gfp_t flags,int node) +{ +pmd_t *pmd =pmd_offset (pud, addr); +if (pmd_none (*pmd)) { +void *p =cpu_area_alloc_block (PAGE_SIZE , flags, node); +if (!p) +return 0 ; +pmd_populate_kernel (&init_mm, pmd, p); + } +return pmd; +} + +pud_t *cpu_area_pud_populate (pgd_t *pgd,unsigned long addr, +gfp_t flags,int node) +{ +pud_t *pud =pud_offset (pgd, addr); +if (pud_none (*pud)) { +void *p =cpu_area_alloc_block (PAGE_SIZE , flags, node); +if (!p) +return 0 ; +pud_populate (&init_mm, pud, p); + } +return pud; +} + +pgd_t *cpu_area_pgd_populate (unsigned long addr,gfp_t flags,int node) +{ +pgd_t *pgd =pgd_offset_k (addr); +if (pgd_none (*pgd)) { +void *p =cpu_area_alloc_block (PAGE_SIZE , flags, node); +if (!p) +return 0 ; +pgd_populate (&init_mm, pgd, p); + } +return pgd; +} + +int cpu_area_populate_basepages (void *start,unsigned long size, +gfp_t flags,int node) +{ +unsigned long addr = (unsigned long )start; +unsigned long end = addr + size; +pgd_t *pgd; +pud_t *pud; +pmd_t *pmd; +pte_t *pte; + +for (; addr < end; addr +=PAGE_SIZE ) { + pgd =cpu_area_pgd_populate (addr, flags, node); +if (!pgd) +return -ENOMEM ; + pud =cpu_area_pud_populate (pgd, addr, flags, node); +if (!pud) +return -ENOMEM ; + pmd =cpu_area_pmd_populate (pud, addr, flags, node); +if (!pmd) +return -ENOMEM ; + pte =cpu_area_pte_populate (pmd, addr, flags, node); +if (!pte) +return -ENOMEM ; + } + +return 0 ; +} + +/* +* If no other population function is defined then this function will stand +* in and provide the capability to map PAGE_SIZE pages into the cpu area. +*/ +int __attribute__((weak))cpu_area_populate (void *start,unsigned long size, +gfp_t flags,int node) +{ +return cpu_area_populate_basepages (start, size, flags, node); +} + +/* +* Extend the areas on all processors. This function may be called repeatedly +* until we have enough space to accomodate a newly allocated object. +* +* Must hold the cpu_alloc_map_lock on entry. Will drop the lock and then +* regain it. +*/ +static int expand_cpu_area (gfp_t flags) +{ +unsigned long blocks = active_blocks; +unsigned long bits; +int cpu; +int err = -ENOMEM ; +int map_order; +unsigned long *new_map =NULL ; +void *start; + +if (active_blocks ==MAX_BLOCKS ) + goto out; + +spin_unlock (&cpu_alloc_map_lock); + +/* +* Determine the size of the bit map needed +*/ + bits = (blocks +1 ) *UNITS_PER_BLOCK ; + map_order =get_order (DIV_ROUND_UP (bits,8 )); + start = cpu_area + \ + (blocks << (PAGE_SHIFT +CONFIG_CPU_AREA_ALLOC_ORDER )); + +for_each_possible_cpu (cpu) { + err =cpu_area_populate (CPU_PTR (start, cpu),ALLOC_SIZE , + flags,cpu_to_node (cpu)); + +if (err) { +spin_lock (&cpu_alloc_map_lock); + goto out; + } + } + +if (map_order > cpu_alloc_map_order) { + new_map =cpu_area_alloc_block (PAGE_SIZE << map_order, + flags | __GFP_ZERO,0 ); +if (!new_map) + goto out; + } + +spin_lock (&cpu_alloc_map_lock); + +/* +* We dropped the lock. Another processor may have already extended +* the cpu area size as needed. +*/ +if (blocks != active_blocks) { +if (new_map) +free_pages ((unsigned long )new_map, + map_order); + err =0 ; + goto out; + } + +if (new_map) { +/* +* Need to extend the bitmap +*/ +if (cpu_alloc_map) +memcpy (new_map, cpu_alloc_map, +PAGE_SIZE << cpu_alloc_map_order); + cpu_alloc_map = new_map; + cpu_alloc_map_order = map_order; + } + + active_blocks++; + units_total +=UNITS_PER_BLOCK ; + units_free +=UNITS_PER_BLOCK ; + err =0 ; +out: +return err; +} + +#else + +/* +* Static fallback configuration. The cpu areas are of a fixed size and +* cannot be extended. Such configurations are mainly useful on +* machines that do not have MMU support. +*/ +#define MAX_BLOCKS 1 +#define ALLOC_SIZE (1UL << (CONFIG_CPU_AREA_ORDER + PAGE_SHIFT)) + +static u8 cpu_area[NR_CPUS *ALLOC_SIZE ]; +static DECLARE_BITMAP(cpu_alloc_map, UNITS_PER_BLOCK); +static int units_free =UNITS_PER_BLOCK ; +#define cpu_alloc_map_order CONFIG_CPU_AREA_ORDER +#define units_total UNITS_PER_BLOCK + +static inline int expand_cpu_area (gfp_t flags) +{ +return -ENOSYS ; +} +#endif + +static int first_free;/* First known free unit */ + +/* +* How many units are needed for an object of a given size +*/ +static int size_to_units (unsigned long size) +{ +return DIV_ROUND_UP (size,UNIT_SIZE ); +} + +/* +* Mark an object as used in the cpu_alloc_map +* +* Must hold cpu_alloc_map_lock +*/ +static void set_map (int start,int length) +{ +while (length-- >0 ) +__set_bit (start++, cpu_alloc_map); +} + +/* +* Mark an area as freed. +* +* Must hold cpu_alloc_map_lock +*/ +static void clear_map (int start,int length) +{ +while (length-- >0 ) +__clear_bit (start++, cpu_alloc_map); +} + +/* +* Allocate an object of a certain size +* +* Returns a special pointer that can be used with CPU_PTR to find the +* address of the object for a certain cpu. +*/ +void *cpu_alloc (unsigned long size,gfp_t gfpflags,unsigned long align) +{ +unsigned long start; +int units =size_to_units (size); +void *ptr; +int first; +unsigned long map_size; + +BUG_ON (gfpflags & ~(GFP_RECLAIM_MASK | __GFP_ZERO)); + +spin_lock (&cpu_alloc_map_lock); + +restart: + map_size =PAGE_SIZE << cpu_alloc_map_order; + first =1 ; + start = first_free; + +for ( ; ; ) { + + start =find_next_zero_bit (cpu_alloc_map, map_size, start); +if (first) + first_free = start; + +if (start >= units_total) { +if (expand_cpu_area (gfpflags)) + goto out_of_memory; + goto restart; + } + +/* +* Check alignment and that there is enough space after +* the starting unit. +*/ +if (start % (align /UNIT_SIZE ) ==0 && +find_next_bit (cpu_alloc_map, map_size, start +1 ) + >= start + units) +break ; + start++; + first =0 ; + } + +if (first) + first_free = start + units; + +while (start + units > units_total) { +if (expand_cpu_area (gfpflags)) + goto out_of_memory; + } + +set_map (start, units); + units_free -= units; +__count_vm_events (CPU_BYTES , units *UNIT_SIZE ); + +spin_unlock (&cpu_alloc_map_lock); + + ptr = cpu_area + start *UNIT_SIZE ; + +if (gfpflags & __GFP_ZERO) { +int cpu; + +for_each_possible_cpu (cpu) +memset (CPU_PTR (ptr, cpu),0 , size); + } + +return ptr; + +out_of_memory: +spin_unlock (&cpu_alloc_map_lock); +return NULL ; +} +EXPORT_SYMBOL (cpu_alloc); + +/* +* Free an object. The pointer must be a cpu pointer allocated +* via cpu_alloc. +*/ +void cpu_free (void *start,unsigned long size) +{ +int units =size_to_units (size); +int index; +u8 *p = start; + +BUG_ON (p < cpu_area); + index = (p - cpu_area) /UNIT_SIZE ; +BUG_ON (!test_bit (index, cpu_alloc_map) || + index >= units_total); + +spin_lock (&cpu_alloc_map_lock); + +clear_map (index, units); + units_free += units; +__count_vm_events (CPU_BYTES , -units *UNIT_SIZE ); +if (index < first_free) + first_free = index; + +spin_unlock (&cpu_alloc_map_lock); +} +EXPORT_SYMBOL (cpu_free); + +
include/linux/vmstat.h +1 -1
@@ -36,7 +36,7 @@FOR_ALL_ZONES (PGSCAN_KSWAPD ),FOR_ALL_ZONES (PGSCAN_DIRECT ),PGINODESTEAL ,SLABS_SCANNED ,KSWAPD_STEAL ,KSWAPD_INODESTEAL , -PAGEOUTRUN ,ALLOCSTALL ,PGROTATED , +PAGEOUTRUN ,ALLOCSTALL ,PGROTATED ,CPU_BYTES ,NR_VM_EVENT_ITEMS };
mm/Makefile +1 -2
@@ -11,7 +11,7 @@ page_alloc.o page-writeback.o pdflush.o \ readahead.o swap.o truncate.o vmscan.o \ prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \ - page_isolation.o $(mmu-y) + page_isolation.o cpu_alloc.o $(mmu-y) obj-$(CONFIG_BOUNCE) += bounce.o obj-$(CONFIG_SWAP) += page_io.o swap_state.o swapfile.o thrash.o
@@ -30,4 +30,3 @@ obj-$(CONFIG_MIGRATION) += migrate.o obj-$(CONFIG_SMP) += allocpercpu.o obj-$(CONFIG_QUICKLIST) += quicklist.o -
mm/vmstat.c +1 -0
@@ -642,6 +642,7 @@"allocstall" ,"pgrotated" , + "cpu_bytes", #endif };
include/linux/cpu_alloc.h new file +56 -0
56 lines not on this page · raw message
mm/Kconfig +12 -0
@@ -194,3 +194,15 @@ config VIRT_TO_BUS def_bool y depends on !ARCH_NO_VIRT_TO_BUS + +config CPU_AREA_ORDER + int "Maximum order of CPU area" + default "16" if CPU_AREA_VIRTUAL + default "4" if !CPU_AREA_VIRTUAL + help + Sets the maximum amount of memory that can be allocated via cpu_alloc + The size is set in page order. The size set (times the maximum + number of processors) determines the amount of virtual memory that + is set aside for the per cpu areas. + +
include/linux/mm.h +13 -0
@@ -1141,5 +1141,18 @@ unsigned long pages, int node);int vmemmap_populate (struct page *start_page,unsigned long pages,int node); +pgd_t *cpu_area_pgd_populate (unsigned long addr,gfp_t flags,int node); +pud_t *cpu_area_pud_populate (pgd_t *pgd,unsigned long addr, +gfp_t flags,int node); +pmd_t *cpu_area_pmd_populate (pud_t *pud,unsigned long addr, +gfp_t flags,int node); +pte_t *cpu_area_pte_populate (pmd_t *pmd,unsigned long addr, +gfp_t flags,int node); +void *cpu_area_alloc_block (unsigned long size,gfp_t flags,int node); +int cpu_area_populate_basepages (void *start,unsigned long size, +gfp_t flags,int node); +int cpu_area_populate (void *start,unsigned long size, +gfp_t flags,int node); +#endif /* __KERNEL__ */ #endif /* _LINUX_MM_H */
Peter Zijlstra
maintainerRe: [patch 01/28] cpu alloc: The allocator
mm/cpu_alloc.c line 38
Quoted 4 lines · Christoph Lameter
mm/cpu_alloc.c new file +4
-0+/* +* Lock to protect the bitmap and the meta data for the cpu allocator. +*/ +static DEFINE_SPINLOCK (cpu_alloc_map_lock);
I thought you got nightmares from global locks :-)
Quoted 94 lines
mm/cpu_alloc.c new file +94
-0+/* +* Allocate an object of a certain size +* +* Returns a special pointer that can be used with CPU_PTR to find the +* address of the object for a certain cpu. +*/ +void *cpu_alloc (unsigned long size,gfp_t gfpflags,unsigned long align) +{ +unsigned long start; +int units =size_to_units (size); +void *ptr; +int first; +unsigned long map_size; + +BUG_ON (gfpflags & ~(GFP_RECLAIM_MASK | __GFP_ZERO)); + +spin_lock (&cpu_alloc_map_lock); + +restart: + map_size =PAGE_SIZE << cpu_alloc_map_order; + first =1 ; + start = first_free; + +for ( ; ; ) { + + start =find_next_zero_bit (cpu_alloc_map, map_size, start); +if (first) + first_free = start; + +if (start >= units_total) { +if (expand_cpu_area (gfpflags)) + goto out_of_memory; + goto restart; + } + +/* +* Check alignment and that there is enough space after +* the starting unit. +*/ +if (start % (align /UNIT_SIZE ) ==0 && +find_next_bit (cpu_alloc_map, map_size, start +1 ) + >= start + units) +break ; + start++; + first =0 ; + } + +if (first) + first_free = start + units; + +while (start + units > units_total) { +if (expand_cpu_area (gfpflags)) + goto out_of_memory; + } + +set_map (start, units); + units_free -= units; +__count_vm_events (CPU_BYTES , units *UNIT_SIZE ); + +spin_unlock (&cpu_alloc_map_lock); + + ptr = cpu_area + start *UNIT_SIZE ; + +if (gfpflags & __GFP_ZERO) { +int cpu; + +for_each_possible_cpu (cpu) +memset (CPU_PTR (ptr, cpu),0 , size); + } + +return ptr; + +out_of_memory: +spin_unlock (&cpu_alloc_map_lock); +return NULL ; +} +EXPORT_SYMBOL (cpu_alloc); + +/* +* Free an object. The pointer must be a cpu pointer allocated +* via cpu_alloc. +*/ +void cpu_free (void *start,unsigned long size) +{ +int units =size_to_units (size); +int index; +u8 *p = start; + +BUG_ON (p < cpu_area); + index = (p - cpu_area) /UNIT_SIZE ; +BUG_ON (!test_bit (index, cpu_alloc_map) || + index >= units_total); + +spin_lock (&cpu_alloc_map_lock);
mm/cpu_alloc.c line 405
Quoted 10 lines
mm/cpu_alloc.c new file +10
-0+ +clear_map (index, units); + units_free += units; +__count_vm_events (CPU_BYTES , -units *UNIT_SIZE ); +if (index < first_free) + first_free = index; + +spin_unlock (&cpu_alloc_map_lock); +} +EXPORT_SYMBOL (cpu_free);
Why a bitmap allocator and not a heap allocator?
Also, looking at the lock usage, this thing is not IRQ safe, so it should not be called from hardirq context. Please document this.
Quoted 13 lines
include/linux/cpu_alloc.h new file +13
-0+#ifndef _LINUX_CPU_ALLOC_H_ +#define _LINUX_CPU_ALLOC_H_ + +#define CPU_OFFSET (__cpu) \ + ((unsigned long)(__cpu) << (CONFIG_CPU_AREA_ORDER + PAGE_SHIFT)) + +#define CPU_PTR (__p, __cpu) ((__typeof__(__p))((void *)(__p) + \ + CPU_OFFSET(__cpu))) + +#define CPU_ALLOC (type, flags) cpu_alloc(sizeof(type), flags, \ + __alignof__(type)) +#define CPU_FREE (pointer) cpu_free(pointer, sizeof(*(pointer))) +
include/linux/cpu_alloc.h line 55
Quoted 10 lines
include/linux/cpu_alloc.h new file +10
-0+#define THIS_CPU (__p) CPU_PTR(__p, smp_processor_id()) +#define __THIS_CPU (__p) CPU_PTR(__p, raw_smp_processor_id()) + +/* +* Raw calls +*/ +void *cpu_alloc (unsigned long size,gfp_t gfp,unsigned long align); +void cpu_free (void *cpu_pointer,unsigned long size); + +#endif /* _LINUX_CPU_ALLOC_H_ */
Like said in the previous mail (which due to creative mailing from your end never made it out to the lists), I dislike those shouting macros. Please lowercase them.
Peter Zijlstra
maintainerRe: [patch 01/28] cpu alloc: The allocator
Quoted 21 lines · Peter Zijlstra
Quoted 19 lines · Christoph Lameter
include/linux/cpu_alloc.h new file +19
-0+#ifndef _LINUX_CPU_ALLOC_H_ +#define _LINUX_CPU_ALLOC_H_ + +#define CPU_OFFSET (__cpu) \ + ((unsigned long)(__cpu) << (CONFIG_CPU_AREA_ORDER + PAGE_SHIFT)) + +#define CPU_PTR (__p, __cpu) ((__typeof__(__p))((void *)(__p) + \ + CPU_OFFSET(__cpu))) + +#define CPU_ALLOC (type, flags) cpu_alloc(sizeof(type), flags, \ + __alignof__(type)) +#define CPU_FREE (pointer) cpu_free(pointer, sizeof(*(pointer))) + +#define THIS_CPU (__p) CPU_PTR(__p, smp_processor_id()) +#define __THIS_CPU (__p) CPU_PTR(__p, raw_smp_processor_id()) + +/* +* Raw calls +*/
Quoted 8 lines
include/linux/cpu_alloc.h line 55
Quoted 4 lines
include/linux/cpu_alloc.h new file +4
-0+void *cpu_alloc (unsigned long size,gfp_t gfp,unsigned long align); +void cpu_free (void *cpu_pointer,unsigned long size); + +#endif /* _LINUX_CPU_ALLOC_H_ */ Like said in the previous mail (which due to creative mailing from your end never made it out to the lists), I dislike those shouting macros. Please lowercase them.
sed -i -e 's/CPU_OFFSET/cpu_offset/g' -e 's/CPU_PTR/cpu_ptr/' -e 's/CPU_ALLOC/cpu_alloc_type/g' -e 's/cpu_free/__cpu_free/g' -e 's/CPU_FREE/cpu_free/' -e 's/THIS_CPU/this_cpu/g' patches/*.patch
should get you there.
Re: [patch 01/28] cpu alloc: The allocator
In reply to Peter ZijlstraQuoted 8 lines · Peter Zijlstra
mm/cpu_alloc.c line 38
Quoted 4 lines · Christoph Lameter
mm/cpu_alloc.c new file +4
-0+/* +* Lock to protect the bitmap and the meta data for the cpu allocator. +*/ +static DEFINE_SPINLOCK (cpu_alloc_map_lock);I thought you got nightmares from global locks :-)
Yes but this one is rarely taken.
Quoted 1 line
Why a bitmap allocator and not a heap allocator?
Because the allocator must be able to deal with small 4 byte entities.
Quoted 2 lines
Also, looking at the lock usage, this thing is not IRQ safe, so it should not be called from hardirq context. Please document this.
Ok.
Re: [patch 01/28] cpu alloc: The allocator
Quoted 2 lines · Christoph Lameter
Quoted 2 lines
Also, looking at the lock usage, this thing is not IRQ safe, so it should not be called from hardirq context. Please document this.
Well I went the other way and made it work like the slab allocators.
cpu_alloc: Make it irq safe
Use the same method as used in SLAB/SLUB to make the allocator interrupt safe. disable interrupts when allocator metadata is processed. Reenable interrupts during page allocator calls if __GFP_WAIT is set in the flags passed to the allocator.
--- mm/cpu_alloc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
mm/cpu_alloc.c +11 -5
@@ -186,6 +186,8 @@ static int expand_cpu_area(gfp_t flags) goto out;spin_unlock (&cpu_alloc_map_lock); +if (flags & __GFP_WAIT) +local_irq_enable ();/* * Determine the size of the bit map needed
@@ -212,6 +214,8 @@ static int expand_cpu_area(gfp_t flags) goto out; } +if (flags & __GFP_WAIT) +local_irq_disable ();spin_lock (&cpu_alloc_map_lock);/*
@@ -312,10 +316,11 @@ void *cpu_alloc(unsigned long size, gfp_void *ptr;int first;unsigned long map_size; +unsigned long flags;BUG_ON (gfpflags & ~(GFP_RECLAIM_MASK | __GFP_ZERO)); -spin_lock (&cpu_alloc_map_lock); +spin_lock_irqsave (&cpu_alloc_map_lock, flags); restart: map_size =PAGE_SIZE << cpu_alloc_map_order;
@@ -358,7 +363,7 @@ restart: units_free -= units;__count_vm_events (CPU_BYTES , units *UNIT_SIZE ); -spin_unlock (&cpu_alloc_map_lock); +spin_unlock_irqrestore (&cpu_alloc_map_lock, flags); ptr = cpu_area + start *UNIT_SIZE ;
@@ -372,7 +377,7 @@ restart:return ptr; out_of_memory: -spin_unlock (&cpu_alloc_map_lock); +spin_unlock_irqrestore (&cpu_alloc_map_lock, flags);return NULL ; }EXPORT_SYMBOL (cpu_alloc);
@@ -386,13 +391,14 @@ void cpu_free(void *start, unsigned longint units =size_to_units (size);int index;u8 *p = start; +unsigned long flags;BUG_ON (p < cpu_area); index = (p - cpu_area) /UNIT_SIZE ;BUG_ON (!test_bit (index, cpu_alloc_map) || index >= units_total); -spin_lock (&cpu_alloc_map_lock); +spin_lock_irqsave (&cpu_alloc_map_lock, flags);clear_map (index, units); units_free += units;
@@ -400,6 +406,6 @@ void cpu_free(void *start, unsigned longif (index < first_free) first_free = index; -spin_unlock (&cpu_alloc_map_lock); +spin_unlock_irqrestore (&cpu_alloc_map_lock, flags); }EXPORT_SYMBOL (cpu_free);
Peter Zijlstra
maintainerRe: [patch 01/28] cpu alloc: The allocator
Quoted 6 lines · Christoph Lameter
Quoted 2 lines · Christoph Lameter
Quoted 2 lines
Also, looking at the lock usage, this thing is not IRQ safe, so it should not be called from hardirq context. Please document this.
Well I went the other way and made it work like the slab allocators.
Nice.
A message that is not in the archive (sent off-list or not yet received): 1194522615.6289.136.camel@twins
A message that is not in the archive (sent off-list or not yet received): [email protected]
Peter Zijlstra
maintainerRe: [patch 01/28] cpu alloc: The allocator
Quoted 25 lines · Christoph Lameter
Quoted 14 lines · Peter Zijlstra
Quoted 14 lines
include/linux/cpu_alloc.h new file +14
-0+#define CPU_OFFSET (__cpu) \ + ((unsigned long)(__cpu) << (CONFIG_CPU_AREA_ORDER + PAGE_SHIFT)) + +#define CPU_PTR (__p, __cpu) ((__typeof__(__p))((void *)(__p) + \ + CPU_OFFSET(__cpu))) + +#define CPU_ALLOC (type, flags) cpu_alloc(sizeof(type), flags, \ + __alignof__(type)) +#define CPU_FREE (pointer) cpu_free(pointer, sizeof(*(pointer))) + +#define THIS_CPU (__p) CPU_PTR(__p, smp_processor_id()) +#define __THIS_CPU (__p) CPU_PTR(__p, raw_smp_processor_id()) + +/* Quoted 8 lines
include/linux/cpu_alloc.h line 55
Quoted 6 lines
+ * Raw calls
+ */include/linux/cpu_alloc.h new file +4
-0+void *cpu_alloc (unsigned long size,gfp_t gfp,unsigned long align); +void cpu_free (void *cpu_pointer,unsigned long size); + +#endif /* _LINUX_CPU_ALLOC_H_ */ I don't like those shouting macros.
Quoted 1 line
The convention for macros is to use upper case.
We have plent macros that look like regular functions. And as a primary interface to this functionality these shouting things look really out of place.
Re: [patch 01/28] cpu alloc: The allocator
Quoted 5 lines · Peter Zijlstra
Quoted 1 line
The convention for macros is to use upper case.
We have plent macros that look like regular functions. And as a primary interface to this functionality these shouting things look really out of place.
One point of the patchset is to clean up the messy handling of the allocpercpu interface which uses lower case for macros. It is a bit confusing that a function like alloc_percpu() can take a type argument. I think this needs to be uppercase for clarity.
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Christoph Lameter <[email protected]>
Date: Thu, 8 Nov 2007 12:24:22 -0800 (PST)
Quoted 12 lines · Peter Zijlstra
Quoted 6 lines
Quoted 2 lines
The convention for macros is to use upper case.
We have plent macros that look like regular functions. And as a primary interface to this functionality these shouting things look really out of place.
One point of the patchset is to clean up the messy handling of the allocpercpu interface which uses lower case for macros. It is a bit confusing that a function like
alloc_percpu()can take a type argument. I think this needs to be uppercase for clarity.
Without a doubt.
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
In reply to Peter ZijlstraFrom: Peter Zijlstra <[email protected]>
Date: Thu, 08 Nov 2007 21:19:08 +0100
Quoted 11 lines · Christoph Lameter
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines
I don't like those shouting macros.
The convention for macros is to use upper case.
We have plent macros that look like regular functions. And as a primary interface to this functionality these shouting things look really out of place.
I disagree, macros in upper case make sense here. Macros should SHOUT at you because CPP is MAGIC and has side effects that normal real functions do not have, and therefore you need to be REMINDED.
And, honestly, aren't there more important issues about his patches to review than macro capitalization?
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
In reply to Christoph LameterFrom: Christoph Lameter <[email protected]>
Date: Tue, 06 Nov 2007 11:51:45 -0800
Quoted 10 lines
The core portion of the cpu allocator.
The per cpu allocator allows dynamic allocation of memory on all processor simultaneously. A bitmap is used to track used areas. The allocator implements tight packing to reduce the cache footprint and increase speed since cacheline contention is typically not a concern for memory mainly used by a single cpu. Small objects will fill up gaps left by larger allocations that required alignments.
Signed-off-by Christoph Lameter <[email protected]>
Unfortunately, sparc64 fails to boot even with just this patch applied.
The problem is that for the non-virtualized case this patch bloats up the BSS section to be more than 8MB in size. Sparc64 kernel images cannot be more than 8MB in size total due to various boot loader and firmware limitations.
I have NR_CPUS set to 64, but it can be up to 4096 on sparc64.
Yes, I could add virtualized area support to sparc64, but we cannot impose this on every platform.
One thing you could do is simply use a vmalloc allocation in the non-virtualized case.
Re: [patch 01/28] cpu alloc: The allocator
Quoted 2 lines · David Miller
One thing you could do is simply use a vmalloc allocation in the non-virtualized case.
Yuck. Meaning to add more crappy code. The bss limitations to 8M is a bit strange though. Do other platforms have the same issues?
Re: [patch 01/28] cpu alloc: The allocator
Quoted 6 lines · Christoph Lameter
Quoted 2 lines · David Miller
One thing you could do is simply use a vmalloc allocation in the non-virtualized case.
Yuck. Meaning to add more crappy code. The bss limitations to 8M is a bit strange though. Do other platforms have the same issues?
Maybe not so crappy, because even for i386 code, you might use not a strict vmalloc() implementation but at least reserving percpu space inside the vmalloc range. (ie not use a dedicated area as your current patchset does)
This is because NR_CPUS is defaulted to 32 on i386 (with a limit of 256), so reserving 256*256KB = 64 MB of virtual space might be too much. (this is half the typical vmalloc area)
The idea would be :
- Reserving an area of NR_CPUS*256KB inside vmalloc() space (but of course not allocating pages)
- Then for each non possible cpu, 'release' its 256KB area and give it back to vmalloc free areas pool.
Once you add in mm/vmalloc.c all needed helpers, no need to use BSS Megablob anymore ?
Re: [patch 01/28] cpu alloc: The allocator
Quoted 2 lines · Eric Dumazet
Once you add in
mm/vmalloc.call needed helpers, no need to use BSS Megablob anymore ?
Well I think all of this can be avoided by simply copying the existing vmemmap helper functions and providing a virtual address for sparc64.
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Christoph Lameter <[email protected]>
Date: Tue, 13 Nov 2007 14:00:45 -0800 (PST)
Quoted 7 lines · Eric Dumazet
Quoted 3 lines
Once you add in
mm/vmalloc.call needed helpers, no need to use BSS Megablob anymore ?Well I think all of this can be avoided by simply copying the existing vmemmap helper functions and providing a virtual address for sparc64.
I intend to do that in the end, but you miss my point. Requiring this is unreasonable.
And nobody is going to do the virt stuff for platforms like sparc32. And I do mean nobody.
Re: [patch 01/28] cpu alloc: The allocator
In reply to Eric DumazetQuoted 3 lines · Eric Dumazet
This is because
NR_CPUSis defaulted to 32 on i386 (with a limit of 256), so reserving 256*256KB = 64 MB of virtual space might be too much. (this is half the typical vmalloc area)
It defaults to 8 except if you use a NUMA system.
config NR_CPUS
int "Maximum number of CPUs (2-255)"
range 2 255
depends on SMP
default "32" if X86_NUMAQ || X86_SUMMIT || X86_BIGSMP || X86_ES7000
default "8"David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
In reply to Christoph LameterFrom: Christoph Lameter <[email protected]>
Date: Tue, 13 Nov 2007 13:40:19 -0800 (PST)
Quoted 7 lines · David Miller
Quoted 3 lines
One thing you could do is simply use a vmalloc allocation in the non-virtualized case.
Yuck. Meaning to add more crappy code. The bss limitations to 8M is a bit strange though. Do other platforms have the same issues?
sparc32 has the same limit.
I'm surprised this is your reaction instead of "oh damn, sorry I bloated up the kernel image size by 8mb, I'll find a way to fix that."
Re: [patch 01/28] cpu alloc: The allocator
Quoted 3 lines · David Miller
I'm surprised this is your reaction instead of "oh damn, sorry I bloated up the kernel image size by 8mb, I'll find a way to fix that."
Well I found a way to fix that and its in the patch...
Re: [patch 01/28] cpu alloc: The allocator
In reply to David MillerQuoted 2 lines · David Miller
Yes, I could add virtualized area support to sparc64, but we cannot impose this on every platform.
Other platforms do not have the 8MB restriction nor do they have so many processors.
Here is the draft of a virtual cpu area implementation for sparc64. Uses the VMEMMAP chunks:
--- arch/sparc64/Kconfig | 12 ++++++++++++ arch/sparc64/mm/init.c | 34 ++++++++++++++++++++++++++++++++++ include/asm-sparc64/pgtable.h | 1 + 3 files changed, 47 insertions(+)
arch/sparc64/mm/init.c +34 -0
@@ -1697,6 +1697,40 @@ int __meminit vmemmap_populate(struct pa }#endif /* CONFIG_SPARSEMEM_VMEMMAP */ +int cpu_area_populate (void *start,unsigned long size,gfp_t flags,int node) +{ +unsigned long vstart = (unsigned long ) start; +unsigned long vend = (unsigned long ) (start + size); +unsigned long phys_start = (vstart -CPU_AREA_BASE ); +unsigned long phys_end = (vend -CPU_AREA_BASE ); +unsigned long addr = phys_start &VMEMMAP_CHUNK_MASK ; +unsigned long end =VMEMMAP_ALIGN (phys_end); +unsigned long pte_base; + + pte_base = (_PAGE_VALID | _PAGE_SZ4MB_4U | + _PAGE_CP_4U | _PAGE_CV_4U | + _PAGE_P_4U | _PAGE_W_4U); +if (tlb_type == hypervisor) + pte_base = (_PAGE_VALID | _PAGE_SZ4MB_4V | + _PAGE_CP_4V | _PAGE_CV_4V | + _PAGE_P_4V | _PAGE_W_4V); + +for (; addr < end; addr +=VMEMMAP_CHUNK ) { +unsigned long *vmem_pp = + vmemmap_table + (addr >>VMEMMAP_CHUNK_SHIFT ); +void *block; + +if (!(*vmem_pp & _PAGE_VALID)) { + block =vmemmap_alloc_block (1UL <<22 , flags, node); +if (!block) +return -ENOMEM ; + + *vmem_pp = pte_base |__pa (block); + } + } +return 0 ; +} + static void prot_init_common(unsigned long page_none, unsigned long page_shared, unsigned long page_copy,
arch/sparc64/Kconfig +12 -0
@@ -76,6 +76,18 @@ config GENERIC_HARDIRQS_NO__DO_IRQ bool def_bool y +config CPU_AREA_VIRTUAL + bool + def_bool y + +config CPU_AREA_ORDER + int + default "10" + +config CPU_AREA_ALLOC_ORDER + int + default "0" + choice prompt "Kernel page size" default SPARC64_PAGE_SIZE_8KB
include/asm-sparc64/pgtable.h +1 -0
@@ -43,6 +43,7 @@#define VMALLOC_START _AC(0x0000000100000000,UL)#define VMALLOC_END _AC(0x0000000200000000,UL)#define VMEMMAP_BASE _AC(0x0000000200000000,UL) +#define CPU_AREA_BASE _AC(0x0000000300000000,UL)#define vmemmap ((struct page *)VMEMMAP_BASE)
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Christoph Lameter <[email protected]>
Date: Tue, 13 Nov 2007 14:20:02 -0800 (PST)
Quoted 7 lines · David Miller
Quoted 3 lines
Yes, I could add virtualized area support to sparc64, but we cannot impose this on every platform.
Other platforms do not have the 8MB restriction nor do they have so many processors.
sparc32 has the same limitations, nobody is going to implement the virt stuff there.
Quoted 2 lines
Here is the draft of a virtual cpu area implementation for sparc64. Uses the VMEMMAP chunks:
This doesn't avoid the core problem. Bloating up the BSS like that is bad, end enforcing a virt implementation to avoid that is an anti-social way to go about implementing this feature.
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
In reply to Christoph LameterBTW, I'm going to stop testing your patches on sparc64 for a while until you start to make me feel like you understand that ignoring the BSS bloat issue is bad.
Re: [patch 01/28] cpu alloc: The allocator
Quoted 3 lines · David Miller
BTW, I'm going to stop testing your patches on sparc64 for a while until you start to make me feel like you understand that ignoring the BSS bloat issue is bad.
Well this is just the fallback. How can I avoid this and still keep a constant? Add a new segment to vmlinux.lds.S?
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Christoph Lameter <[email protected]>
Date: Tue, 13 Nov 2007 17:50:24 -0800 (PST)
Quoted 8 lines · David Miller
Quoted 4 lines
BTW, I'm going to stop testing your patches on sparc64 for a while until you start to make me feel like you understand that ignoring the BSS bloat issue is bad.
Well this is just the fallback. How can I avoid this and still keep a constant? Add a new segment to
vmlinux.lds.S?
I'm not so sure.
The idea about doling out vmalloc space seemed the most promising.
Re: [patch 01/28] cpu alloc: The allocator
Quoted 1 line · David Miller
The idea about doling out vmalloc space seemed the most promising.
Well that is basically the same as the virtual mode. Just ditch the fallback mode? vmalloc directly does not guarantee a fixed address.
Re: [patch 01/28] cpu alloc: The allocator
In reply to David MillerQuoted 5 lines · David Miller
The problem is that for the non-virtualized case this patch bloats up the BSS section to be more than 8MB in size. Sparc64 kernel images cannot be more than 8MB in size total due to various boot loader and firmware limitations.
I recently ran into a similar problem with x86-64 and large BSS from lockdep conflicting with a 16MB kdump kernel. Solution was to do another early allocator before bootmem and then move the tables into there.
-Andi
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Andi Kleen <[email protected]>
Date: Wed, 14 Nov 2007 02:06:28 +0100
Quoted 11 lines
Quoted 5 lines · David Miller
The problem is that for the non-virtualized case this patch bloats up the BSS section to be more than 8MB in size. Sparc64 kernel images cannot be more than 8MB in size total due to various boot loader and firmware limitations.
I recently ran into a similar problem with x86-64 and large BSS from lockdep conflicting with a 16MB kdump kernel. Solution was to do another early allocator before bootmem and then move the tables into there.
Yes, I've run into similar problems with lockdep as well. I had to build an ultra minimalized kernel to get it to boot on my Niagara boxes.
I think I even looked at the same lockdep code, and I'd appreciate it if you'd submit your fix for this if you haven't already.
Re: [patch 01/28] cpu alloc: The allocator
Quoted 3 lines · David Miller
Yes, I've run into similar problems with lockdep as well. I had to build an ultra minimalized kernel to get it to boot on my Niagara boxes.
Hmmmm. cpu_alloc really does not need zeroed data. Just an address fixed by the compiler where stuff can be put. Can the loader do that somehow?
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Christoph Lameter <[email protected]>
Date: Tue, 13 Nov 2007 17:57:15 -0800 (PST)
Quoted 3 lines
Hmmmm.
cpu_allocreally does not need zeroed data. Just an address fixed by the compiler where stuff can be put. Can the loader do that somehow?
Yes, and I think IA64 uses such a scheme for it's 64KB fixed per-cpu TLB mapping thing doesn't it?
Re: [patch 01/28] cpu alloc: The allocator
Quoted 9 lines · David Miller
From: Christoph Lameter <[email protected]>
Date: Tue, 13 Nov 2007 17:57:15 -0800 (PST)Quoted 3 lines
Hmmmm.
cpu_allocreally does not need zeroed data. Just an address fixed by the compiler where stuff can be put. Can the loader do that somehow?Yes, and I think IA64 uses such a scheme for it's 64KB fixed per-cpu TLB mapping thing doesn't it?
The per cpu TLB mapping is virtually mapped. The real memory allocation behind it occurs dynamically from bootmem.
Re: [patch 01/28] cpu alloc: The allocator
In reply to David MillerQuoted 7 lines · David Miller
Yes, I've run into similar problems with lockdep as well. I had to build an ultra minimalized kernel to get it to boot on my Niagara boxes.
I think I even looked at the same lockdep code, and I'd appreciate it if you'd submit your fix for this if you haven't already.
ftp://firstfloor.org/pub/ak/x86_64/quilt/patches/early-reserve ftp://firstfloor.org/pub/ak/x86_64/quilt/patches/early-alloc ftp://firstfloor.org/pub/ak/x86_64/quilt/patches/lockdep-early-alloc
I didn't plan to submit it for .24, just .25. Or do you need it urgently?
Also it would require you to write a sparc specific arch_early_alloc() of course. I've only done the x86-64 version.
-Andi
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Andi Kleen <[email protected]>
Date: Wed, 14 Nov 2007 03:28:32 +0100
Quoted 6 lines
ftp://firstfloor.org/pub/ak/x86_64/quilt/patches/early-reserve ftp://firstfloor.org/pub/ak/x86_64/quilt/patches/early-alloc ftp://firstfloor.org/pub/ak/x86_64/quilt/patches/lockdep-early-alloc
I didn't plan to submit it for .24, just .25. Or do you need it urgently?
I don't need it urgently, 2.6.25 is perfectly fine.
Quoted 2 lines
Also it would require you to write a sparc specific
arch_early_alloc()of course. I've only done the x86-64 version.
I'll be sure to take care of that when it hits .25
Thanks Andi.
Re: [patch 01/28] cpu alloc: The allocator
In reply to Andi KleenQuoted 13 lines · Andi Kleen
Quoted 7 lines · David Miller
Yes, I've run into similar problems with lockdep as well. I had to build an ultra minimalized kernel to get it to boot on my Niagara boxes.
I think I even looked at the same lockdep code, and I'd appreciate it if you'd submit your fix for this if you haven't already.
ftp://firstfloor.org/pub/ak/x86_64/quilt/patches/early-reserve ftp://firstfloor.org/pub/ak/x86_64/quilt/patches/early-alloc ftp://firstfloor.org/pub/ak/x86_64/quilt/patches/lockdep-early-alloc
Quoted 5 lines
I didn't plan to submit it for .24, just .25. Or do you need it urgently?
Also it would require you to write a sparc specific
arch_early_alloc()of course. I've only done the x86-64 version.
IA64 also has no lockdep. What arches support lockdep?
Peter Zijlstra
maintainerlarge lockdep bss (was: Re: [patch 01/28] cpu alloc: The allocator)
In reply to Andi KleenQuoted 13 lines · Andi Kleen
Quoted 7 lines · David Miller
Yes, I've run into similar problems with lockdep as well. I had to build an ultra minimalized kernel to get it to boot on my Niagara boxes.
I think I even looked at the same lockdep code, and I'd appreciate it if you'd submit your fix for this if you haven't already.
ftp://firstfloor.org/pub/ak/x86_64/quilt/patches/early-reserve ftp://firstfloor.org/pub/ak/x86_64/quilt/patches/early-alloc ftp://firstfloor.org/pub/ak/x86_64/quilt/patches/lockdep-early-alloc
Quoted 5 lines
I didn't plan to submit it for .24, just .25. Or do you need it urgently?
Also it would require you to write a sparc specific
arch_early_alloc()of course. I've only done the x86-64 version.
Would've been nice to have heard about this lockdep problem. Anyway, thanks for tackling it.
How about moving this bit:
+#ifndef ARCH_HAS_EARLY_ALLOC
+#define LARGEVAR(x,y) { static typeof(*x) __ ## x[y]; x = __ ## x; } +#else
+#define LARGEVAR(x,y) x = arch_early_alloc(sizeof(*x) * y) +#endif
out of the lockdep code and into the generic early alloc code?
Re: large lockdep bss (was: Re: [patch 01/28] cpu alloc: The allocator)
Quoted 9 lines
How about moving this bit:
(quoted diff) +5
-0+#ifndef ARCH_HAS_EARLY_ALLOC +#define LARGEVAR(x,y) { static typeof(*x) __ ## x[y]; x = __ ## x; } +#else +#define LARGEVAR(x,y) x = arch_early_alloc(sizeof(*x) * y) +#endifout of the lockdep code and into the generic early alloc code?
Will do.
-Andi
Re: [patch 01/28] cpu alloc: The allocator
In reply to Andi KleenHmmm.. I have v2 in preparation here that puts the pda and the per cpu data into the cpu_alloc area. Thus gs: can be used to access all per cpu data.
Any ideas how to abstract out the pda operations? Wasnt local_t supposed to be able to do atomic ops on cpu data? Is there an segment register version of local_t? I want also to have cmpxchg xchg etc that are all atomic without requiring any interrupt disable or preempt disable.
cpu_alloc allows pointer arithmetic on cpu area pointers. The segment prefix can then be used to select the appropriate area.
Guess I need also to add an arch configuration guide to V2 as well so that the other arches can do similar tricks and emphasize that the static default that requires bss is only suitable for small systems.
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Christoph Lameter <[email protected]>
Date: Tue, 13 Nov 2007 20:15:55 -0800 (PST)
Quoted 3 lines
Guess I need also to add an arch configuration guide to V2 as well so that the other arches can do similar tricks and emphasize that the static default that requires bss is only suitable for small systems.
I'm going to be against your changes until you implement a real fix for the BSS bloat problems.
It's worse than the per-cpu allocator we have now, much worse.
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
BTW [email protected] does not exist, please remove it from the CC: in the future :-)
Thanks.
Re: [patch 01/28] cpu alloc: The allocator
In reply to David MillerQuoted 7 lines · David Miller
From: Christoph Lameter <[email protected]>
Date: Tue, 13 Nov 2007 20:15:55 -0800 (PST)Quoted 3 lines
Guess I need also to add an arch configuration guide to V2 as well so that the other arches can do similar tricks and emphasize that the static default that requires bss is only suitable for small systems.
Quoted 5 lines
I'm going to be against your changes until you implement a real fix for the BSS bloat problems.
It's worse than the per-cpu allocator we have now, much worse.
You need to configure cpu_alloc for your arch and so far you seem to not have had the time to understand how it works otherwise you would not repeat these statements and ask me to implement what the patch already provides.
The only problem that I see so far is a communication problem. Thus we need more documentation.
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Christoph Lameter <[email protected]>
Date: Tue, 13 Nov 2007 20:26:33 -0800 (PST)
Quoted 2 lines
The only problem that I see so far is a communication problem. Thus we need more documentation.
Fair enough, I'll look more closely at the next rev of your patch set.
Re: [patch 01/28] cpu alloc: The allocator
Well there is an LWN article now that also claims that the cpu_alloc patchset requires a large bss space. Sigh. See
http://lwn.net/Articles/257828/
Not true! 44 bytes is reasonable.
christoph@stapp:~/linux-2.6$ size mm/cpu_alloc.o text data bss dec hex filename 5625 36 44 5705 1649 mm/cpu_alloc.o
Need to separate out the virtualization into a separate patch in V2 to make clear that it is there.
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Christoph Lameter <[email protected]>
Date: Thu, 15 Nov 2007 10:49:37 -0800 (PST)
Quoted 6 lines
Well there is an LWN article now that also claims that the
cpu_allocpatchset requires a large bss space. Sigh. Seehttp://lwn.net/Articles/257828/
Not true! 44 bytes is reasonable.
Well, the first version of the patch set, the one I tested, did require a lot of BSS space. And that's the one they are writing about.
I don't see how you can even remotely claim that LWN's reporting is inaccurate here.
Re: [patch 01/28] cpu alloc: The allocator
Quoted 3 lines · David Miller
Well, the first version of the patch set, the one I tested, did require a lot of BSS space. And that's the one they are writing about.
I am running the same version that you also ran. The problem is that you did not configure the stuff properly for your box and I did not include a configuration for sparc64 since I did not know how it needed to be configured for sparc64. You ignored the patch for sparc64 that I provided to correct the problem.
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Christoph Lameter <[email protected]>
Date: Thu, 15 Nov 2007 18:19:37 -0800 (PST)
Quoted 11 lines · David Miller
Quoted 4 lines
Well, the first version of the patch set, the one I tested, did require a lot of BSS space. And that's the one they are writing about.
I am running the same version that you also ran. The problem is that you did not configure the stuff properly for your box and I did not include a configuration for sparc64 since I did not know how it needed to be configured for sparc64. You ignored the patch for sparc64 that I provided to correct the problem.
If you're talking about the VMEMMAP thing, that patch didn't remove the problem, it simply added optimizations for sparc64 so that you could sweep the problem under the rug.
Sparc32 is still broken, as just one of several possible examples. The BSS usage is still there for platforms that don't use VMEMMAP.
So again, the lwn.net report is accurate.
Re: [patch 01/28] cpu alloc: The allocator
Quoted 3 lines · David Miller
If you're talking about the VMEMMAP thing, that patch didn't remove the problem, it simply added optimizations for sparc64 so that you could sweep the problem under the rug.
The virtual mapping of the cpu areas is used by the patch I posted for i386, ia64 and x86_64. All the ones that I have access to here.
Quoted 1 line
Sparc32 is still broken, as just one of several possible examples.
I have not looked at sparc32 sorry. If you simply set up a couple of configuration values in arch/sparc32/Kconfig then everything will be fine.
Quoted 1 line
The BSS usage is still there for platforms that don't use VMEMMAP.
All MMU platforms can use the virtual mappings. The main use of the static configuration is for embedded systems.
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Christoph Lameter <[email protected]>
Date: Thu, 15 Nov 2007 18:55:21 -0800 (PST)
Quoted 6 lines · David Miller
Quoted 2 lines
Sparc32 is still broken, as just one of several possible examples.
I have not looked at sparc32 sorry. If you simply set up a couple of configuration values in
arch/sparc32/Kconfigthen everything will be fine.
There is assembler code to write, which as I stated several times nobody is going to work on or test.
It is unreasonable to add this new VMEMMAP requirement in order for your patches to work properly.
Quoted 4 lines
Quoted 1 line
The BSS usage is still there for platforms that don't use VMEMMAP.
All MMU platforms can use the virtual mappings. The main use of the static configuration is for embedded systems.
Someone has to implement and test VMEMMAP now on all of these architectures, it is becomming a requirement unlike in the sparsemem patches case where it was optional.
That's unreasonable.
Re: [patch 01/28] cpu alloc: The allocator
Quoted 5 lines · David Miller
Quoted 2 lines
I have not looked at sparc32 sorry. If you simply set up a couple of configuration values in
arch/sparc32/Kconfigthen everything will be fine.There is assembler code to write, which as I stated several times nobody is going to work on or test.
There is no assembly code required. I overdid it in the patch that I sent you trying to make sparc64 use large mappings like x86_64 NUMA. You really do not need that. Look at the IA64 and i386 configurations. There is no C code required. The x86_64 code only adds some special C code for the NUMA case.
Quoted 8 lines
Quoted 2 lines
All MMU platforms can use the virtual mappings. The main use of the static configuration is for embedded systems.
Someone has to implement and test VMEMMAP now on all of these architectures, it is becomming a requirement unlike in the sparsemem patches case where it was optional.
That's unreasonable.
VMEMMAP is something different from the cpu allocator. All MMU platforms have vmalloc support and you even suggested the use of vmalloc.
David Miller
maintainerRe: [patch 01/28] cpu alloc: The allocator
From: Christoph Lameter <[email protected]>
Date: Thu, 15 Nov 2007 19:10:15 -0800 (PST)
Quoted 5 lines · David Miller
Quoted 4 lines
Quoted 3 lines
I have not looked at sparc32 sorry. If you simply set up a couple of configuration values in
arch/sparc32/Kconfigthen everything will be fine.
Quoted 8 lines
Quoted 2 lines
There is assembler code to write, which as I stated several times nobody is going to work on or test.
There is no assembly code required. I overdid it in the patch that I sent you trying to make sparc64 use large mappings like
x86_64NUMA. You really do not need that. Look at the IA64 and i386 configurations. There is no C code required. Thex86_64code only adds some special C code for the NUMA case.
Ok, and like I said last time, I'll examine this more closely when you spin your next version of these patches.
Please post them soon as I'm eager to test this stuff out for you.
Thanks.
Re: [patch 01/28] cpu alloc: The allocator
Quoted 8 lines · David Miller
Quoted 5 lines
There is no assembly code required. I overdid it in the patch that I sent you trying to make sparc64 use large mappings like
x86_64NUMA. You really do not need that. Look at the IA64 and i386 configurations. There is no C code required. Thex86_64code only adds some special C code for the NUMA case.Ok, and like I said last time, I'll examine this more closely when you spin your next version of these patches.
All the above statements are about the version of the patch that I thought you had a look at.
Quoted 2 lines
Please post them soon as I'm eager to test this stuff out for you.
Ok. Thanks. (You could test it with the current version.... Just edit Kconfig and try a few things and I could include the settings in the next release.)
PATCH 2/28 cpu alloc: x86_64 support
In reply to Christoph LameterSet up a cpu area that allows the use of up 256MB for each processor.
Cpu memory use can grow rapidly. F.e. if we assume that a page struct occupies 64 bytes of memory and we have 3 zones per node then we need 3 * 1k * 16k = 50 million pagesets or 3096 pagesets per processor. This results in a total of 3.2 GB of page structs. So each cpu needs around 200k of cpu storage for the page allocator alone.
For the UP and SMP case map the area using 4k ptes. Typical use of per cpu data is around 16k for UP and SMP configurations. Allocating a 2M segment would be overkill. There is enough reserve around to run a few 100000 ip tunnels if one wants to and other lots of other frills.
For NUMA map the area using 2M PMDs. A large NUMA system may use lots of cpu data for the page allocator data alone. We typically have large amounts of memory around. Using a 2M page size reduces TLB pressure.
Some numbers for envisioned maximum configurations of NUMA systems:
4k cpu configurations with 256 nodes:
4096 * 256MB = 1TB of virtual space.
Maximum theoretical configuration 16384 processors 1k nodes:
16384 * 256MB = 4TB of virtual space.
Both fit within the established limits established.
--- arch/x86/Kconfig.x86_64 | 13 +++++++++++++ arch/x86/mm/init_64.c | 39 +++++++++++++++++++++++++++++++++++++++ include/asm-x86/pgtable_64.h | 1 + 3 files changed, 53 insertions(+)
arch/x86/mm/init_64.c +39 -0
@@ -28,6 +28,7 @@#include <linux/module.h> #include <linux/memory_hotplug.h> #include <linux/nmi.h> +#include <linux/cpu_alloc.h> #include <asm/processor.h> #include <asm/system.h>
@@ -781,3 +782,41 @@ int __meminit vmemmap_populate(struct pareturn 0 ; }#endif + +#ifdef CONFIG_NUMA +int __meminit cpu_area_populate (void *start,unsigned long size, +gfp_t flags,int node) +{ +unsigned long addr = (unsigned long )start; +unsigned long end = addr + size; +unsigned long next; +pgd_t *pgd; +pud_t *pud; +pmd_t *pmd; + +for (; addr < end; addr = next) { + next =pmd_addr_end (addr, end); + + pgd =cpu_area_pgd_populate (addr, flags, node); +if (!pgd) +return -ENOMEM ; + pud =cpu_area_pud_populate (pgd, addr, flags, node); +if (!pud) +return -ENOMEM ; + + pmd =pmd_offset (pud, addr); +if (pmd_none (*pmd)) { +pte_t entry; +void *p =cpu_area_alloc_block (PMD_SIZE , flags, node); +if (!p) +return -ENOMEM ; + + entry =pfn_pte (__pa (p) >>PAGE_SHIFT ,PAGE_KERNEL ); +mk_pte_huge (entry); +set_pmd (pmd,__pmd (pte_val (entry))); + } + } + +return 0 ; +} +#endif
arch/x86/Kconfig.x86_64 +13 -0
@@ -137,6 +137,19 @@ config ARCH_HAS_ILOG2_U64 bool default n +config CPU_AREA_VIRTUAL + bool + default y + +config CPU_AREA_ORDER + int + default "16" + +config CPU_AREA_ALLOC_ORDER + int + default "9" if NUMA + default "0" if !NUMA + source "init/Kconfig"
include/asm-x86/pgtable_64.h +1 -0
@@ -138,6 +138,7 @@ static inline pte_t ptep_get_and_clear_f#define VMALLOC_START _AC(0xffffc20000000000, UL)#define VMALLOC_END _AC(0xffffe1ffffffffff, UL)#define VMEMMAP_START _AC(0xffffe20000000000, UL) +#define CPU_AREA_BASE _AC(0xfffff20000000000, UL)#define MODULES_VADDR _AC(0xffffffff88000000, UL)#define MODULES_END _AC(0xfffffffffff00000, UL)#define MODULES_LEN (MODULES_END - MODULES_VADDR)
PATCH 3/28 cpu alloc: IA64 support
In reply to Christoph LameterTypical use of per cpu memory for a small system of 8G 8p 4node is less than 64k per cpu memory. This is increasing rapidly for larger systems where we can get up to 512k or 1M of memory used for cpu storage.
The maximum size of the cpu area is 128MB of memory.
The cpu area is placed in region 5 with the kernel, vmemmap and vmalloc areas. So with this version we are limited to PAGE_SIZEd mappings. The cpu area and the vmemmap area could use a large TLB size.
--- arch/ia64/Kconfig | 19 +++++++++++++++++++ include/asm-ia64/pgtable.h | 27 +++++++++++++++++++++------ 2 files changed, 40 insertions(+), 6 deletions(-)
include/asm-ia64/pgtable.h +26 -6
@@ -224,21 +224,41 @@*/ +/* +* Layout of the RGN_GAGE +* +* 47 bits wide (16kb pages) +* +* 0xa000000000000000-0xa00000200000000 8G Kernel data area +* 0xa000002000000000-0xa00040000000000 64T vmalloc +* 0xa000400000000000-0xa00060000000000 32T vmemmmap +* 0xa000600000000000-0xa00080000000000 32T cpu area +* +* 55 bits wide (64kb pages) +* +* 0xa000000000000000-0xa00000200000000 8G Kernel data area +* 0xa000002000000000-0xa04000000000000 16P vmalloc +* 0xa040000000000000-0xa06000000000000 8P vmemmmap +* 0xa060000000000000-0xa08000000000000 8P cpu area +*/ +#define VMALLOC_START (RGN_BASE(RGN_GATE) + 0x200000000UL) +#define VMALLOC_END_INIT (RGN_BASE(RGN_GATE) + (1UL << (4*PAGE_SHIFT - 10))) +#ifdef CONFIG_VIRTUAL_MEM_MAP -# define VMALLOC_END_INIT (RGN_BASE(RGN_GATE) + (1UL << (4*PAGE_SHIFT - 9)))# define VMALLOC_END vmalloc_endextern unsigned long vmalloc_end;#else +# define VMALLOC_END VMALLOC_END_INIT +#endif +#if defined(CONFIG_SPARSEMEM ) && defined(CONFIG_SPARSEMEM_VMEMMAP )/* SPARSEMEM_VMEMMAP uses half of vmalloc... */ -# define VMALLOC_END (RGN_BASE(RGN_GATE) + (1UL << (4*PAGE_SHIFT - 10))) -# define vmemmap ((struct page *)VMALLOC_END) -#else -# define VMALLOC_END (RGN_BASE(RGN_GATE) + (1UL << (4*PAGE_SHIFT - 9))) -#endif +# define vmemmap ((struct page *)VMALLOC_END_INIT)#endif +#define CPU_AREA_BASE (RGN_BASE(RGN_GATE) + (3UL << (4*PAGE_SHIFT - 11))) +/* fs/proc/kcore.c */ #define kc_vaddr_to_offset (v) ((v) - RGN_BASE(RGN_GATE))#define kc_offset_to_vaddr (o) ((o) + RGN_BASE(RGN_GATE))
arch/ia64/Kconfig +19 -0
@@ -99,6 +99,25 @@ bool default y +config CPU_AREA_VIRTUAL + bool + default y + +# Maximum of 128 MB cpu_alloc space per cpu +config CPU_AREA_ORDER + int + default "13" + +# +# Expand the area in PAGE_SIZE steps. We could be using +# huge pages if we would move this into region 5. But with the move +# to 64k we will likely be fine here. 64k is more than enough +# for most configurations. +# +config CPU_AREA_ALLOC_ORDER + int + default "0" + choice prompt "System type" default IA64_GENERIC
PATCH 4/28 cpu alloc: i386 support
In reply to Christoph LameterSetup a 256 kB area for the cpu areas below the FIXADDR area.
The use of the cpu alloc area is pretty minimal on i386. An 8p system with no extras uses only ~8kb. So 256kb should be plenty. A configuration that supports up to 8 processors takes up 2MB of the scarce virtual address space.
--- arch/x86/Kconfig.i386 | 12 ++++++++++++ arch/x86/mm/init_32.c | 3 +++ include/asm-x86/pgtable_32.h | 7 +++++-- 3 files changed, 20 insertions(+), 2 deletions(-)
arch/x86/Kconfig.i386 +12 -0
@@ -95,6 +95,18 @@ bool default y +config CPU_AREA_VIRTUAL + bool + default y + +config CPU_AREA_ORDER + int + default "6" + +config CPU_AREA_ALLOC_ORDER + int + default "0" + source "init/Kconfig" menu "Processor type and features"
arch/x86/mm/init_32.c +3 -0
@@ -674,6 +674,7 @@#if 1 /* double-sanity-check paranoia */ printk("virtual kernel memory layout:\n" " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n" + " cpu area: 0x%08lx - 0x%08lx (%4ld kb)\n" #ifdef CONFIG_HIGHMEM " pkmap : 0x%08lx - 0x%08lx (%4ld kB)\n"#endif
@@ -684,6 +685,8 @@" .text : 0x%08lx - 0x%08lx (%4ld kB)\n" ,FIXADDR_START ,FIXADDR_TOP , (FIXADDR_TOP -FIXADDR_START ) >>10 , +CPU_AREA_BASE ,FIXADDR_START , + (FIXADDR_START -CPU_AREA_BASE ) >>10 , #ifdef CONFIG_HIGHMEM PKMAP_BASE, PKMAP_BASE+LAST_PKMAP*PAGE_SIZE,
include/asm-x86/pgtable_32.h +5 -2
@@ -79,11 +79,14 @@#define VMALLOC_START (((unsigned long) high_memory + \ 2*VMALLOC_OFFSET-1) & ~(VMALLOC_OFFSET-1))#ifdef CONFIG_HIGHMEM -# define VMALLOC_END (PKMAP_BASE-2*PAGE_SIZE) +# define CPU_AREA_BASE (PKMAP_BASE - NR_CPUS * \ + (1 << (CONFIG_CPU_AREA_ORDER + PAGE_SHIFT)))#else -# define VMALLOC_END (FIXADDR_START-2*PAGE_SIZE) +# define CPU_AREA_BASE (FIXADDR_START - NR_CPUS * \ + (1 << (CONFIG_CPU_AREA_ORDER + PAGE_SHIFT)))#endif +#define VMALLOC_END (CPU_AREA_BASE - 2 * PAGE_SIZE)/* * _PAGE_PSE set in the page directory entry just means that * the page directory entry points directly to a 4MB-aligned block of
PATCH 5/28 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 alloc_percpu 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.
3. We can remove the diddle widdle with allocating and releasing kmem_cache_cpu structures when bringing up and shuttting down cpus. The allocpercpu logic will do it all for us.
4. Fastpath performance increases by another 20% vs. the earlier improvements. Instead of having fastpath with 45-50 cycles it is now possible to get below 40.
--- include/linux/slub_def.h | 6 - mm/slub.c | 183 ++++++----------------------------------------- 2 files changed, 26 insertions(+), 163 deletions(-)
include/linux/slub_def.h +1 -5
@@ -34,6 +34,7 @@ struct kmem_cache_node {* 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 */
@@ -63,11 +64,6 @@ struct kmem_cache {int 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 -158
323 lines not on this page · raw message
PATCH 6/28 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 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 an additional cacheline anymore. This results in consistent use of setting the freepointer for objects throughout SLUB.
--- include/linux/slub_def.h | 3 -- mm/slub.c | 50 +++++++++++++++-------------------------------- 2 files changed, 17 insertions(+), 36 deletions(-)
include/linux/slub_def.h +0 -3
@@ -15,9 +15,6 @@ struct kmem_cache_cpu {void **freelist;struct page *page;int node; -unsigned int offset; -unsigned int objsize; -unsigned int objects; };struct kmem_cache_node {
mm/slub.c +17 -33
140 lines not on this page · raw message
PATCH 7/28 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/mmzone.h +2 -10
@@ -121,13 +121,7 @@ struct per_cpu_pageset {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 +};enum zone_type {#ifdef CONFIG_ZONE_DMA
@@ -231,10 +225,8 @@ struct zone {*/ 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 +63 -99
277 lines not on this page · raw message
include/linux/mm.h +0 -4
@@ -931,11 +931,7 @@ extern void show_mem(void);extern void si_meminfo (struct sysinfo * val);extern void si_meminfo_node (struct sysinfo *val,int nid); -#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);
mm/vmstat.c +9 -6
@@ -14,6 +14,7 @@#include <linux/module.h> #include <linux/cpu.h> #include <linux/sched.h> +#include <linux/cpu_alloc.h> #ifdef CONFIG_VM_EVENT_COUNTERS DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}};
@@ -147,7 +148,8 @@ static void refresh_zone_stat_thresholds threshold =calculate_threshold (zone);for_each_online_cpu (cpu) -zone_pcp (zone, cpu)->stat_threshold = threshold; +CPU_PTR (zone->pageset, cpu)->stat_threshold + = threshold; } }
@@ -157,7 +159,8 @@ static void refresh_zone_stat_thresholdsvoid __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;
@@ -210,7 +213,7 @@ EXPORT_SYMBOL(mod_zone_page_state);*/ 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)++;
@@ -231,7 +234,7 @@ EXPORT_SYMBOL(__inc_zone_page_state);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 +310,7 @@ void refresh_cpu_vm_stats(int cpu)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]) {
@@ -684,7 +687,7 @@ static void zoneinfo_show_print(struct sstruct per_cpu_pageset *pageset;int j; - pageset =zone_pcp (zone, i); + pageset =CPU_PTR (zone->pageset, i);for (j =0 ; j <ARRAY_SIZE (pageset->pcp); j++) {seq_printf (m, "\n cpu: %i pcp: %i"
PATCH 8/28 cpu alloc: percpu_counter conversion
In reply to Christoph Lameter--- include/linux/percpu_counter.h | 1 - lib/percpu_counter.c | 13 +++++++------ 2 files changed, 7 insertions(+), 7 deletions(-)
include/linux/percpu_counter.h +0 -1
@@ -10,7 +10,6 @@#include <linux/smp.h> #include <linux/list.h> #include <linux/threads.h> -#include <linux/percpu.h> #include <linux/types.h> #ifdef CONFIG_SMP
lib/percpu_counter.c +7 -6
@@ -8,6 +8,7 @@#include <linux/init.h> #include <linux/cpu.h> #include <linux/module.h> +#include <linux/cpu_alloc.h> #ifdef CONFIG_HOTPLUG_CPU static LIST_HEAD (percpu_counters);
@@ -20,7 +21,7 @@ void percpu_counter_set(struct percpu_cospin_lock (&fbc->lock);for_each_possible_cpu (cpu) { -s32 *pcount =per_cpu_ptr (fbc->counters, cpu); +s32 *pcount =CPU_PTR (fbc->counters, cpu); *pcount =0 ; } fbc->count = amount;
@@ -34,7 +35,7 @@ void __percpu_counter_add(struct percpu_s32 *pcount;int cpu =get_cpu (); - pcount =per_cpu_ptr (fbc->counters, cpu); + pcount =CPU_PTR (fbc->counters, cpu); count = *pcount + amount;if (count >= batch || count <= -batch) {spin_lock (&fbc->lock);
@@ -60,7 +61,7 @@ s64 __percpu_counter_sum(struct percpu_cspin_lock (&fbc->lock); ret = fbc->count;for_each_online_cpu (cpu) { -s32 *pcount =per_cpu_ptr (fbc->counters, cpu); +s32 *pcount =CPU_PTR (fbc->counters, cpu); ret += *pcount; }spin_unlock (&fbc->lock);
@@ -74,7 +75,7 @@ int percpu_counter_init(struct percpu_co {spin_lock_init (&fbc->lock); fbc->count = amount; - fbc->counters =alloc_percpu (s32); + fbc->counters =CPU_ALLOC (s32,GFP_KERNEL |__GFP_ZERO);if (!fbc->counters)return -ENOMEM ;#ifdef CONFIG_HOTPLUG_CPU
@@ -101,7 +102,7 @@ void percpu_counter_destroy(struct percpif (!fbc->counters)return ; -free_percpu (fbc->counters); +CPU_FREE (fbc->counters);#ifdef CONFIG_HOTPLUG_CPU mutex_lock (&percpu_counters_lock);list_del (&fbc->list);
@@ -127,7 +128,7 @@ static int __cpuinit percpu_counter_hotcunsigned long flags;spin_lock_irqsave (&fbc->lock, flags); - pcount =per_cpu_ptr (fbc->counters, cpu); + pcount =CPU_PTR (fbc->counters, cpu); fbc->count += *pcount; *pcount =0 ;spin_unlock_irqrestore (&fbc->lock, flags);
PATCH 9/28 cpu alloc: crash_notes conversion
In reply to Christoph Lameter--- arch/ia64/kernel/crash.c | 2 +- drivers/base/cpu.c | 3 ++- kernel/kexec.c | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-)
kernel/kexec.c +3 -2
@@ -24,6 +24,7 @@#include <linux/utsrelease.h> #include <linux/utsname.h> #include <linux/numa.h> +#include <linux/cpu_alloc.h> #include <asm/page.h> #include <asm/uaccess.h>
@@ -1122,7 +1123,7 @@ void crash_save_cpu(struct pt_regs *regs* squirrelled away. ELF notes happen to provide * all of that, so there is no need to invent something new. */ - buf = (u32 *)per_cpu_ptr (crash_notes, cpu); + buf = (u32 *)CPU_PTR (crash_notes, cpu);if (!buf)return ;memset (&prstatus,0 ,sizeof (prstatus));
@@ -1136,7 +1137,7 @@ void crash_save_cpu(struct pt_regs *regsstatic int __init crash_notes_memory_init (void ) {/* Allocate memory for saving cpu registers. */ - crash_notes =alloc_percpu (note_buf_t); + crash_notes =CPU_ALLOC (note_buf_t,GFP_KERNEL |__GFP_ZERO);if (!crash_notes) {printk ("Kexec: Memory allocation for saving cpu register" " states failed\n" );
drivers/base/cpu.c +2 -1
@@ -10,6 +10,7 @@#include <linux/topology.h> #include <linux/device.h> #include <linux/node.h> +#include <linux/cpu_alloc.h> #include "base.h"
@@ -95,7 +96,7 @@ static ssize_t show_crash_notes(struct s* boot up and this data does not change there after. Hence this * operation should be safe. No locking required. */ - addr =__pa (per_cpu_ptr (crash_notes, cpunum)); + addr =__pa (CPU_PTR (crash_notes, cpunum)); rc =sprintf (buf,"%Lx\n" , addr);return rc; }
arch/ia64/kernel/crash.c +1 -1
@@ -71,7 +71,7 @@ crash_save_this_cpu(void) dst[46 ] = (unsigned long )ia64_rse_skip_regs ((unsigned long *)dst[46 ], sof - sol); - buf = (u64 *)per_cpu_ptr (crash_notes, cpu); + buf = (u64 *)CPU_PTR (crash_notes, cpu);if (!buf)return ; buf = append_elf_note(buf, KEXEC_CORE_NOTE_NAME, NT_PRSTATUS, prstatus,
PATCH 10/28 cpu alloc: workqueue conversion
In reply to Christoph Lameter--- kernel/workqueue.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
kernel/workqueue.c +15 -13
@@ -33,6 +33,7 @@#include <linux/kallsyms.h> #include <linux/debug_locks.h> #include <linux/lockdep.h> +#include <linux/cpu_alloc.h> /* * The per-CPU workqueue (if single thread, we always use the first
@@ -100,7 +101,7 @@ struct cpu_workqueue_struct *wq_per_cpu( {if (unlikely (is_single_threaded (wq))) cpu = singlethread_cpu; -return per_cpu_ptr (wq->cpu_wq, cpu); +return CPU_PTR (wq->cpu_wq, cpu); }/*
@@ -398,7 +399,7 @@ void fastcall flush_workqueue(struct worlock_acquire (&wq->lockdep_map,0 ,0 ,0 ,2 , _THIS_IP_);lock_release (&wq->lockdep_map,1 , _THIS_IP_);for_each_cpu_mask (cpu, *cpu_map) -flush_cpu_workqueue (per_cpu_ptr (wq->cpu_wq, cpu)); +flush_cpu_workqueue (CPU_PTR (wq->cpu_wq, cpu)); }EXPORT_SYMBOL_GPL (flush_workqueue);
@@ -478,7 +479,7 @@ static void wait_on_work(struct work_str cpu_map =wq_cpu_map (wq);for_each_cpu_mask (cpu, *cpu_map) -wait_on_cpu_work (per_cpu_ptr (wq->cpu_wq, cpu), work); +wait_on_cpu_work (CPU_PTR (wq->cpu_wq, cpu), work); } static int __cancel_work_timer(struct work_struct *work,
@@ -601,21 +602,21 @@ int schedule_on_each_cpu(work_func_t funint cpu;struct work_struct *works; - works = alloc_percpu(struct work_struct); + works = CPU_ALLOC(struct work_struct, GFP_KERNEL);if (!works)return -ENOMEM ;preempt_disable ();/* CPU hotplug */ for_each_online_cpu (cpu) { -struct work_struct *work =per_cpu_ptr (works, cpu); +struct work_struct *work =CPU_PTR (works, cpu);INIT_WORK (work, func);set_bit (WORK_STRUCT_PENDING ,work_data_bits (work)); -__queue_work (per_cpu_ptr (keventd_wq->cpu_wq, cpu), work); +__queue_work (CPU_PTR (keventd_wq->cpu_wq, cpu), work); }preempt_enable ();flush_workqueue (keventd_wq); -free_percpu (works); +CPU_FREE (works);return 0 ; }
@@ -664,7 +665,7 @@ int current_is_keventd(void)BUG_ON (!keventd_wq); - cwq =per_cpu_ptr (keventd_wq->cpu_wq, cpu); + cwq =CPU_PTR (keventd_wq->cpu_wq, cpu);if (current == cwq->thread) ret =1 ;
@@ -675,7 +676,7 @@ int current_is_keventd(void)static struct cpu_workqueue_struct *init_cpu_workqueue (struct workqueue_struct *wq,int cpu) { -struct cpu_workqueue_struct *cwq =per_cpu_ptr (wq->cpu_wq, cpu); +struct cpu_workqueue_struct *cwq =CPU_PTR (wq->cpu_wq, cpu); cwq->wq = wq;spin_lock_init (&cwq->lock);
@@ -732,7 +733,8 @@ struct workqueue_struct *__create_workquif (!wq)return NULL ; - wq->cpu_wq = alloc_percpu(struct cpu_workqueue_struct); + wq->cpu_wq = CPU_ALLOC(struct cpu_workqueue_struct, +GFP_KERNEL |__GFP_ZERO);if (!wq->cpu_wq) {kfree (wq);return NULL ;
@@ -814,11 +816,11 @@ void destroy_workqueue(struct workqueue_mutex_unlock (&workqueue_mutex);for_each_cpu_mask (cpu, *cpu_map) { - cwq =per_cpu_ptr (wq->cpu_wq, cpu); + cwq =CPU_PTR (wq->cpu_wq, cpu);cleanup_workqueue_thread (cwq, cpu); } -free_percpu (wq->cpu_wq); +CPU_FREE (wq->cpu_wq);kfree (wq); }EXPORT_SYMBOL_GPL (destroy_workqueue);
@@ -847,7 +849,7 @@ static int __devinit workqueue_cpu_callb }list_for_each_entry (wq, &workqueues, list) { - cwq =per_cpu_ptr (wq->cpu_wq, cpu); + cwq =CPU_PTR (wq->cpu_wq, cpu);switch (action) {case CPU_UP_PREPARE :
PATCH 11/28 cpu alloc: ACPI cstate handling conversion
In reply to Christoph Lameter--- arch/x86/kernel/acpi/cstate.c | 10 ++++++---- arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c | 8 +++++--- drivers/acpi/processor_perflib.c | 5 +++-- 3 files changed, 14 insertions(+), 9 deletions(-)
arch/x86/kernel/acpi/cstate.c +6 -4
@@ -15,6 +15,7 @@#include <acpi/processor.h> #include <asm/acpi.h> +#include <linux/cpu_alloc.h> /* * Initialize bm_flags based on the CPU cache properties
@@ -87,7 +88,7 @@ int acpi_processor_ffh_cstate_probe(unsiif (reg->bit_offset !=NATIVE_CSTATE_BEYOND_HALT )return -1 ; - percpu_entry =per_cpu_ptr (cpu_cstate_entry, cpu); + percpu_entry =CPU_PTR (cpu_cstate_entry, cpu); percpu_entry->states[cx->index].eax =0 ; percpu_entry->states[cx->index].ecx =0 ;
@@ -138,7 +139,7 @@ void acpi_processor_ffh_cstate_enter(strunsigned int cpu =smp_processor_id ();struct cstate_entry *percpu_entry; - percpu_entry =per_cpu_ptr (cpu_cstate_entry, cpu); + percpu_entry =CPU_PTR (cpu_cstate_entry, cpu);mwait_idle_with_hints (percpu_entry->states[cx->index].eax, percpu_entry->states[cx->index].ecx); }
@@ -150,13 +151,14 @@ static int __init ffh_cstate_init(void)if (c->x86_vendor !=X86_VENDOR_INTEL )return -1 ; - cpu_cstate_entry = alloc_percpu(struct cstate_entry); + cpu_cstate_entry = CPU_ALLOC(struct cstate_entry, +GFP_KERNEL |__GFP_ZERO);return 0 ; } static void __exit ffh_cstate_exit(void) { -free_percpu (cpu_cstate_entry); +CPU_FREE (cpu_cstate_entry); cpu_cstate_entry =NULL ; }
arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c +5 -3
@@ -36,6 +36,7 @@#include <linux/acpi.h> #include <acpi/processor.h> +#include <linux/cpu_alloc.h> #include <asm/io.h> #include <asm/msr.h>
@@ -513,7 +514,8 @@ static int __init acpi_cpufreq_early_ini {dprintk ("acpi_cpufreq_early_init\n" ); - acpi_perf_data = alloc_percpu(struct acpi_processor_performance); + acpi_perf_data = CPU_ALLOC(struct acpi_processor_performance, +GFP_KERNEL |__GFP_ZERO);if (!acpi_perf_data) {dprintk ("Memory allocation error for acpi_perf_data.\n" );return -ENOMEM ;
@@ -569,7 +571,7 @@ static int acpi_cpufreq_cpu_init(structif (!data)return -ENOMEM ; - data->acpi_data =percpu_ptr (acpi_perf_data, cpu); + data->acpi_data =CPU_PTR (acpi_perf_data, cpu); drv_data[cpu] = data;if (cpu_has (c,X86_FEATURE_CONSTANT_TSC ))
@@ -782,7 +784,7 @@ static void __exit acpi_cpufreq_exit(voicpufreq_unregister_driver (&acpi_cpufreq_driver); -free_percpu (acpi_perf_data); +CPU_FREE (acpi_perf_data);return ; }
drivers/acpi/processor_perflib.c +3 -2
@@ -30,6 +30,7 @@#include <linux/module.h> #include <linux/init.h> #include <linux/cpufreq.h> +#include <linux/cpu_alloc.h> #ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF #include <linux/proc_fs.h>
@@ -567,12 +568,12 @@ int acpi_processor_preregister_performancontinue ; } -if (!performance || !percpu_ptr (performance, i)) { +if (!performance || !CPU_PTR (performance, i)) { retval = -EINVAL ;continue ; } - pr->performance =percpu_ptr (performance, i); + pr->performance =CPU_PTR (performance, i);cpu_set (i, pr->performance->shared_cpu_map);if (acpi_processor_get_psd (pr)) { retval = -EINVAL ;
PATCH 12/28 cpu alloc: genhd statistics conversion
In reply to Christoph Lameter--- include/linux/genhd.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
include/linux/genhd.h +6 -5
@@ -12,6 +12,7 @@#include <linux/types.h> #ifdef CONFIG_BLOCK +#include <linux/cpu_alloc.h> enum {/* These three have identical behaviour; use the second one if DOS FDISK gets
@@ -158,21 +159,21 @@ struct disk_attribute {*/ #ifdef CONFIG_SMP #define __disk_stat_add (gendiskp, field, addnd) \ - (per_cpu_ptr(gendiskp->dkstats, smp_processor_id())->field += addnd) + (THIS_CPU(gendiskp->dkstats)->field += addnd)#define disk_stat_read (gendiskp, field) \ ({ \ typeof(gendiskp->dkstats->field) res = 0; \ int i; \ for_each_possible_cpu(i) \ - res += per_cpu_ptr(gendiskp->dkstats, i)->field; \ + res += CPU_PTR(gendiskp->dkstats, i)->field; \ res; \ })static inline void disk_stat_set_all (struct gendisk *gendiskp,int value) {int i;for_each_possible_cpu (i) -memset (per_cpu_ptr (gendiskp->dkstats, i), value, +memset (CPU_PTR (gendiskp->dkstats, i), value,sizeof (struct disk_stats )); }
@@ -209,7 +210,7 @@ static inline void disk_stat_set_all(str#ifdef CONFIG_SMP static inline int init_disk_stats (struct gendisk *disk) { - disk->dkstats = alloc_percpu(struct disk_stats); + disk->dkstats = CPU_ALLOC(struct disk_stats, GFP_KERNEL | __GFP_ZERO);if (!disk->dkstats)return 0 ;return 1 ;
@@ -217,7 +218,7 @@ static inline int init_disk_stats(structstatic inline void free_disk_stats (struct gendisk *disk) { -free_percpu (disk->dkstats); +CPU_FREE (disk->dkstats); }#else /* CONFIG_SMP */ static inline int init_disk_stats (struct gendisk *disk)
PATCH 13/28 cpu alloc: blktrace conversion
In reply to Christoph Lameter--- block/blktrace.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
block/blktrace.c +5 -5
@@ -18,12 +18,12 @@#include <linux/kernel.h> #include <linux/blkdev.h> #include <linux/blktrace_api.h> -#include <linux/percpu.h> #include <linux/init.h> #include <linux/mutex.h> #include <linux/debugfs.h> #include <linux/time.h> #include <asm/uaccess.h> +#include <linux/cpu_alloc.h> static DEFINE_PER_CPU(unsigned long long, blk_trace_cpu_offset) = { 0, };static unsigned int blktrace_seq__read_mostly =1 ;
@@ -155,7 +155,7 @@ void __blk_add_trace(struct blk_trace *b t =relay_reserve (bt->rchan,sizeof (*t) + pdu_len);if (t) { cpu =smp_processor_id (); - sequence =per_cpu_ptr (bt->sequence, cpu); + sequence =CPU_PTR (bt->sequence, cpu); t->magic =BLK_IO_TRACE_MAGIC |BLK_IO_TRACE_VERSION ; t->sequence = ++(*sequence);
@@ -227,7 +227,7 @@ static void blk_trace_cleanup(struct blkrelay_close (bt->rchan);debugfs_remove (bt->dropped_file);blk_remove_tree (bt->dir); -free_percpu (bt->sequence); +CPU_FREE (bt->sequence);kfree (bt); }
@@ -338,7 +338,7 @@ int do_blk_trace_setup(struct request_quif (!bt) goto err; - bt->sequence = alloc_percpu(unsigned long); + bt->sequence = CPU_ALLOC(unsigned long, GFP_KERNEL | __GFP_ZERO);if (!bt->sequence) goto err;
@@ -387,7 +387,7 @@ err:if (bt) {if (bt->dropped_file)debugfs_remove (bt->dropped_file); -free_percpu (bt->sequence); +CPU_FREE (bt->sequence);if (bt->rchan)relay_close (bt->rchan);kfree (bt);
PATCH 14/28 cpu alloc: SRCU
In reply to Christoph Lameter--- kernel/rcutorture.c | 4 ++-- kernel/srcu.c | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-)
kernel/srcu.c +7 -6
@@ -26,7 +26,7 @@#include <linux/module.h> #include <linux/mutex.h> -#include <linux/percpu.h> +#include <linux/cpu_alloc.h> #include <linux/preempt.h> #include <linux/rcupdate.h> #include <linux/sched.h>
@@ -46,7 +46,8 @@ int init_srcu_struct(struct srcu_struct { sp->completed =0 ;mutex_init (&sp->mutex); - sp->per_cpu_ref = alloc_percpu(struct srcu_struct_array); + sp->per_cpu_ref = CPU_ALLOC(struct srcu_struct_array, +GFP_KERNEL |__GFP_ZERO);return (sp->per_cpu_ref ?0 : -ENOMEM ); }
@@ -62,7 +63,7 @@ static int srcu_readers_active_idx(struc sum =0 ;for_each_possible_cpu (cpu) - sum +=per_cpu_ptr (sp->per_cpu_ref, cpu)->c[idx]; + sum +=CPU_PTR (sp->per_cpu_ref, cpu)->c[idx];return sum; }
@@ -94,7 +95,7 @@ void cleanup_srcu_struct(struct srcu_strWARN_ON (sum);/* Leakage unless caller handles error. */ if (sum !=0 )return ; -free_percpu (sp->per_cpu_ref); +CPU_FREE (sp->per_cpu_ref); sp->per_cpu_ref =NULL ; }
@@ -113,7 +114,7 @@ int srcu_read_lock(struct srcu_struct *spreempt_disable (); idx = sp->completed &0x1 ;barrier ();/* ensure compiler looks -once- at sp->completed. */ -per_cpu_ptr (sp->per_cpu_ref,smp_processor_id ())->c[idx]++; +THIS_CPU (sp->per_cpu_ref)->c[idx]++;srcu_barrier ();/* ensure compiler won't misorder critical section. */ preempt_enable ();return idx;
@@ -133,7 +134,7 @@ void srcu_read_unlock(struct srcu_struct {preempt_disable ();srcu_barrier ();/* ensure compiler won't misorder critical section. */ -per_cpu_ptr (sp->per_cpu_ref,smp_processor_id ())->c[idx]--; +THIS_CPU (sp->per_cpu_ref)->c[idx]--;preempt_enable (); }
kernel/rcutorture.c +2 -2
@@ -441,8 +441,8 @@ static int srcu_torture_stats(char *page torture_type, TORTURE_FLAG, idx);for_each_possible_cpu (cpu) { cnt +=sprintf (&page[cnt]," %d(%d,%d)" , cpu, -per_cpu_ptr (srcu_ctl.per_cpu_ref, cpu)->c[!idx], -per_cpu_ptr (srcu_ctl.per_cpu_ref, cpu)->c[idx]); +CPU_PTR (srcu_ctl.per_cpu_ref, cpu)->c[!idx], +CPU_PTR (srcu_ctl.per_cpu_ref, cpu)->c[idx]); } cnt +=sprintf (&page[cnt],"\n" );return cnt;
PATCH 15/28 cpu alloc: XFS counters
In reply to Christoph LameterAlso remove the useless zeroing after allocation. Allocpercpu already zeroed the objects.
--- fs/xfs/xfs_mount.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)
fs/xfs/xfs_mount.c +8 -16
@@ -1924,7 +1924,7 @@ xfs_icsb_cpu_notify( mp = (xfs_mount_t *)container_of (nfb, xfs_mount_t, m_icsb_notifier); cntp = (xfs_icsb_cnts_t *) -per_cpu_ptr (mp->m_sb_cnts, (unsigned long )hcpu); +CPU_PTR (mp->m_sb_cnts, (unsigned long )hcpu);switch (action) {case CPU_UP_PREPARE :case CPU_UP_PREPARE_FROZEN :
@@ -1976,10 +1976,7 @@ intxfs_icsb_init_counters ( xfs_mount_t *mp) { -xfs_icsb_cnts_t *cntp; -int i; - - mp->m_sb_cnts =alloc_percpu (xfs_icsb_cnts_t); + mp->m_sb_cnts =CPU_ALLOC (xfs_icsb_cnts_t,GFP_KERNEL | __GFP_ZERO);if (mp->m_sb_cnts ==NULL )return -ENOMEM ;
@@ -1989,11 +1986,6 @@ xfs_icsb_init_counters(register_hotcpu_notifier (&mp->m_icsb_notifier);#endif /* CONFIG_HOTPLUG_CPU */ -for_each_online_cpu (i) { - cntp = (xfs_icsb_cnts_t *)per_cpu_ptr (mp->m_sb_cnts, i); -memset (cntp,0 ,sizeof (xfs_icsb_cnts_t)); - } -mutex_init (&mp->m_icsb_mutex);/*
@@ -2026,7 +2018,7 @@ xfs_icsb_destroy_counters( {if (mp->m_sb_cnts) {unregister_hotcpu_notifier (&mp->m_icsb_notifier); -free_percpu (mp->m_sb_cnts); +CPU_FREE (mp->m_sb_cnts); }mutex_destroy (&mp->m_icsb_mutex); }
@@ -2056,7 +2048,7 @@ xfs_icsb_lock_all_counters(int i;for_each_online_cpu (i) { - cntp = (xfs_icsb_cnts_t *)per_cpu_ptr (mp->m_sb_cnts, i); + cntp = (xfs_icsb_cnts_t *)CPU_PTR (mp->m_sb_cnts, i);xfs_icsb_lock_cntr (cntp); } }
@@ -2069,7 +2061,7 @@ xfs_icsb_unlock_all_counters(int i;for_each_online_cpu (i) { - cntp = (xfs_icsb_cnts_t *)per_cpu_ptr (mp->m_sb_cnts, i); + cntp = (xfs_icsb_cnts_t *)CPU_PTR (mp->m_sb_cnts, i);xfs_icsb_unlock_cntr (cntp); } }
@@ -2089,7 +2081,7 @@ xfs_icsb_count(xfs_icsb_lock_all_counters (mp);for_each_online_cpu (i) { - cntp = (xfs_icsb_cnts_t *)per_cpu_ptr (mp->m_sb_cnts, i); + cntp = (xfs_icsb_cnts_t *)CPU_PTR (mp->m_sb_cnts, i); cnt->icsb_icount += cntp->icsb_icount; cnt->icsb_ifree += cntp->icsb_ifree; cnt->icsb_fdblocks += cntp->icsb_fdblocks;
@@ -2167,7 +2159,7 @@ xfs_icsb_enable_counter(xfs_icsb_lock_all_counters (mp);for_each_online_cpu (i) { - cntp =per_cpu_ptr (mp->m_sb_cnts, i); + cntp =CPU_PTR (mp->m_sb_cnts, i);switch (field) {case XFS_SBS_ICOUNT : cntp->icsb_icount = count + resid;
@@ -2307,7 +2299,7 @@ xfs_icsb_modify_counters(might_sleep (); again: cpu =get_cpu (); - icsbp = (xfs_icsb_cnts_t *)per_cpu_ptr (mp->m_sb_cnts, cpu); + icsbp = (xfs_icsb_cnts_t *)CPU_PTR (mp->m_sb_cnts, cpu);/* * if the counter is disabled, go to slow path
PATCH 16/28 cpu alloc: NFS statistics
In reply to Christoph Lameter--- fs/nfs/iostat.h | 9 +++++---- fs/nfs/super.c | 2 +- include/linux/neighbour.h | 1 + 3 files changed, 7 insertions(+), 5 deletions(-)
fs/nfs/iostat.h +5 -4
@@ -20,6 +20,7 @@#ifndef _NFS_IOSTAT#define _NFS_IOSTAT +#include <linux/cpu_alloc.h> #define NFS_IOSTAT_VERS "1.0"
@@ -123,7 +124,7 @@ static inline void nfs_inc_server_stats(int cpu; cpu =get_cpu (); - iostats =per_cpu_ptr (server->io_stats, cpu); + iostats =CPU_PTR (server->io_stats, cpu); iostats->events[stat] ++;put_cpu_no_resched (); }
@@ -139,7 +140,7 @@ static inline void nfs_add_server_stats(int cpu; cpu =get_cpu (); - iostats =per_cpu_ptr (server->io_stats, cpu); + iostats =CPU_PTR (server->io_stats, cpu); iostats->bytes[stat] += addend;put_cpu_no_resched (); }
@@ -151,13 +152,13 @@ static inline void nfs_add_stats(structstatic inline struct nfs_iostats *nfs_alloc_iostats (void ) { - return alloc_percpu(struct nfs_iostats); + return CPU_ALLOC(struct nfs_iostats, GFP_KERNEL | __GFP_ZERO); }static inline void nfs_free_iostats (struct nfs_iostats *stats) {if (stats !=NULL ) -free_percpu (stats); +CPU_FREE (stats); }#endif
include/linux/neighbour.h +1 -0
@@ -2,6 +2,7 @@#define __LINUX_NEIGHBOUR_H#include <linux/netlink.h> +#include <linux/cpu_alloc.h> struct ndmsg {
fs/nfs/super.c +1 -1
@@ -529,7 +529,7 @@ static int nfs_show_stats(struct seq_filstruct nfs_iostats *stats;preempt_disable (); - stats =per_cpu_ptr (nfss->io_stats, cpu); + stats =CPU_PTR (nfss->io_stats, cpu);for (i =0 ; i < __NFSIOS_COUNTSMAX; i++) totals.events[i] += stats->events[i];
PATCH 17/28 cpu alloc: neigbour statistics
In reply to Christoph Lameter--- include/net/neighbour.h | 2 +- net/core/neighbour.c | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-)
net/core/neighbour.c +7 -5
@@ -35,6 +35,7 @@#include <linux/random.h> #include <linux/string.h> #include <linux/log2.h> +#include <linux/cpu_alloc.h> #define NEIGH_DEBUG 1
@@ -1348,7 +1349,8 @@ void neigh_table_init_no_netlink(structkmem_cache_create (tbl->id, tbl->entry_size,0 ,SLAB_HWCACHE_ALIGN |SLAB_PANIC ,NULL ); - tbl->stats = alloc_percpu(struct neigh_statistics); + tbl->stats = CPU_ALLOC(struct neigh_statistics, +GFP_KERNEL | __GFP_ZERO);if (!tbl->stats)panic ("cannot create neighbour cache statistics" );
@@ -1435,7 +1437,7 @@ int neigh_table_clear(struct neigh_tablekfree (tbl->phash_buckets); tbl->phash_buckets =NULL ; -free_percpu (tbl->stats); +CPU_FREE (tbl->stats); tbl->stats =NULL ;kmem_cache_destroy (tbl->kmem_cachep);
@@ -1692,7 +1694,7 @@ static int neightbl_fill_info(struct sk_for_each_possible_cpu (cpu) {struct neigh_statistics *st; - st =per_cpu_ptr (tbl->stats, cpu); + st =CPU_PTR (tbl->stats, cpu); ndst.ndts_allocs += st->allocs; ndst.ndts_destroys += st->destroys; ndst.ndts_hash_grows += st->hash_grows;
@@ -2341,7 +2343,7 @@ static void *neigh_stat_seq_start(structif (!cpu_possible (cpu))continue ; *pos = cpu+1 ; -return per_cpu_ptr (tbl->stats, cpu); +return CPU_PTR (tbl->stats, cpu); }return NULL ; }
@@ -2356,7 +2358,7 @@ static void *neigh_stat_seq_next(structif (!cpu_possible (cpu))continue ; *pos = cpu+1 ; -return per_cpu_ptr (tbl->stats, cpu); +return CPU_PTR (tbl->stats, cpu); }return NULL ; }
include/net/neighbour.h +1 -1
@@ -83,7 +83,7 @@ struct neigh_statistics#define NEIGH_CACHE_STAT_INC (tbl, field) \ do { \ preempt_disable(); \ - (per_cpu_ptr((tbl)->stats, smp_processor_id())->field)++; \ + (THIS_CPU((tbl)->stats)->field)++; \ preempt_enable(); \ } while (0)
PATCH 18/28 cpu alloc: tcp statistics
In reply to Christoph Lameter--- net/ipv4/tcp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/ipv4/tcp.c +5 -5
@@ -2273,7 +2273,7 @@ static void __tcp_free_md5sig_pool(struc {int cpu;for_each_possible_cpu (cpu) { -struct tcp_md5sig_pool *p = *per_cpu_ptr (pool, cpu); +struct tcp_md5sig_pool *p = *CPU_PTR (pool, cpu);if (p) {if (p->md5_desc.tfm)crypto_free_hash (p->md5_desc.tfm);
@@ -2281,7 +2281,7 @@ static void __tcp_free_md5sig_pool(struc p =NULL ; } } -free_percpu (pool); +CPU_FREE (pool); }void tcp_free_md5sig_pool (void )
@@ -2305,7 +2305,7 @@ static struct tcp_md5sig_pool **__tcp_alint cpu;struct tcp_md5sig_pool **pool; - pool = alloc_percpu(struct tcp_md5sig_pool *); + pool = CPU_ALLOC(struct tcp_md5sig_pool *, GFP_KERNEL);if (!pool)return NULL ;
@@ -2316,7 +2316,7 @@ static struct tcp_md5sig_pool **__tcp_al p =kzalloc (sizeof (*p),GFP_KERNEL );if (!p) goto out_free; - *per_cpu_ptr (pool, cpu) = p; + *CPU_PTR (pool, cpu) = p; hash =crypto_alloc_hash ("md5" ,0 ,CRYPTO_ALG_ASYNC );if (!hash ||IS_ERR (hash))
@@ -2381,7 +2381,7 @@ struct tcp_md5sig_pool *__tcp_get_md5sigif (p) tcp_md5sig_users++;spin_unlock_bh (&tcp_md5sig_pool_lock); -return (p ? *per_cpu_ptr (p, cpu) :NULL ); +return (p ? *CPU_PTR (p, cpu) :NULL ); }EXPORT_SYMBOL (__tcp_get_md5sig_pool);
PATCH 19/28 cpu alloc: convert scatches
In reply to Christoph Lameter--- net/ipv4/ipcomp.c | 26 +++++++++++++------------- net/ipv6/ipcomp6.c | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-)
net/ipv4/ipcomp.c +13 -13
@@ -47,8 +47,8 @@ static int ipcomp_decompress(struct xfrmint dlen =IPCOMP_SCRATCH_SIZE ;const u8 *start = skb->data;const int cpu =get_cpu (); -u8 *scratch = *per_cpu_ptr (ipcomp_scratches, cpu); -struct crypto_comp *tfm = *per_cpu_ptr (ipcd->tfms, cpu); +u8 *scratch = *CPU_PTR (ipcomp_scratches, cpu); +struct crypto_comp *tfm = *CPU_PTR (ipcd->tfms, cpu);int err =crypto_comp_decompress (tfm, start, plen, scratch, &dlen);if (err)
@@ -102,8 +102,8 @@ static int ipcomp_compress(struct xfrm_sint dlen =IPCOMP_SCRATCH_SIZE ;u8 *start = skb->data;const int cpu =get_cpu (); -u8 *scratch = *per_cpu_ptr (ipcomp_scratches, cpu); -struct crypto_comp *tfm = *per_cpu_ptr (ipcd->tfms, cpu); +u8 *scratch = *CPU_PTR (ipcomp_scratches, cpu); +struct crypto_comp *tfm = *CPU_PTR (ipcd->tfms, cpu);int err =crypto_comp_compress (tfm, start, plen, scratch, &dlen);if (err)
@@ -251,9 +251,9 @@ static void ipcomp_free_scratches(void)return ;for_each_possible_cpu (i) -vfree (*per_cpu_ptr (scratches, i)); +vfree (*CPU_PTR (scratches, i)); -free_percpu (scratches); +CPU_FREE (scratches); }static void **ipcomp_alloc_scratches (void )
@@ -264,7 +264,7 @@ static void **ipcomp_alloc_scratches(voiif (ipcomp_scratch_users++)return ipcomp_scratches; - scratches = alloc_percpu(void *); + scratches = CPU_ALLOC(void *, GFP_KERNEL);if (!scratches)return NULL ;
@@ -274,7 +274,7 @@ static void **ipcomp_alloc_scratches(voivoid *scratch =vmalloc (IPCOMP_SCRATCH_SIZE );if (!scratch)return NULL ; - *per_cpu_ptr (scratches, i) = scratch; + *CPU_PTR (scratches, i) = scratch; }return scratches;
@@ -302,10 +302,10 @@ static void ipcomp_free_tfms(struct crypreturn ;for_each_possible_cpu (cpu) { -struct crypto_comp *tfm = *per_cpu_ptr (tfms, cpu); +struct crypto_comp *tfm = *CPU_PTR (tfms, cpu);crypto_free_comp (tfm); } -free_percpu (tfms); +CPU_FREE (tfms); }static struct crypto_comp **ipcomp_alloc_tfms (const char *alg_name)
@@ -321,7 +321,7 @@ static struct crypto_comp **ipcomp_allocstruct crypto_comp *tfm; tfms = pos->tfms; - tfm = *per_cpu_ptr (tfms, cpu); + tfm = *CPU_PTR (tfms, cpu);if (!strcmp (crypto_comp_name (tfm), alg_name)) { pos->users++;
@@ -337,7 +337,7 @@ static struct crypto_comp **ipcomp_allocINIT_LIST_HEAD (&pos->list);list_add (&pos->list, &ipcomp_tfms_list); - pos->tfms = tfms = alloc_percpu(struct crypto_comp *); + pos->tfms = tfms = CPU_ALLOC(struct crypto_comp *, GFP_KERNEL);if (!tfms) goto error;
@@ -346,7 +346,7 @@ static struct crypto_comp **ipcomp_alloc CRYPTO_ALG_ASYNC);if (!tfm) goto error; - *per_cpu_ptr (tfms, cpu) = tfm; + *CPU_PTR (tfms, cpu) = tfm; }return tfms;
net/ipv6/ipcomp6.c +13 -13
@@ -87,8 +87,8 @@ static int ipcomp6_input(struct xfrm_sta start = skb->data; cpu =get_cpu (); - scratch = *per_cpu_ptr (ipcomp6_scratches, cpu); - tfm = *per_cpu_ptr (ipcd->tfms, cpu); + scratch = *CPU_PTR (ipcomp6_scratches, cpu); + tfm = *CPU_PTR (ipcd->tfms, cpu); err =crypto_comp_decompress (tfm, start, plen, scratch, &dlen);if (err)
@@ -139,8 +139,8 @@ static int ipcomp6_output(struct xfrm_st start = skb->data; cpu =get_cpu (); - scratch = *per_cpu_ptr (ipcomp6_scratches, cpu); - tfm = *per_cpu_ptr (ipcd->tfms, cpu); + scratch = *CPU_PTR (ipcomp6_scratches, cpu); + tfm = *CPU_PTR (ipcd->tfms, cpu); err =crypto_comp_compress (tfm, start, plen, scratch, &dlen);if (err || (dlen +sizeof (*ipch)) >= plen) {
@@ -262,12 +262,12 @@ static void ipcomp6_free_scratches(void)return ;for_each_possible_cpu (i) { -void *scratch = *per_cpu_ptr (scratches, i); +void *scratch = *CPU_PTR (scratches, i);vfree (scratch); } -free_percpu (scratches); +CPU_FREE (scratches); }static void **ipcomp6_alloc_scratches (void )
@@ -278,7 +278,7 @@ static void **ipcomp6_alloc_scratches(voif (ipcomp6_scratch_users++)return ipcomp6_scratches; - scratches = alloc_percpu(void *); + scratches = CPU_ALLOC(void *, GFP_KERNEL);if (!scratches)return NULL ;
@@ -288,7 +288,7 @@ static void **ipcomp6_alloc_scratches(vovoid *scratch =vmalloc (IPCOMP_SCRATCH_SIZE );if (!scratch)return NULL ; - *per_cpu_ptr (scratches, i) = scratch; + *CPU_PTR (scratches, i) = scratch; }return scratches;
@@ -316,10 +316,10 @@ static void ipcomp6_free_tfms(struct cryreturn ;for_each_possible_cpu (cpu) { -struct crypto_comp *tfm = *per_cpu_ptr (tfms, cpu); +struct crypto_comp *tfm = *CPU_PTR (tfms, cpu);crypto_free_comp (tfm); } -free_percpu (tfms); +CPU_FREE (tfms); }static struct crypto_comp **ipcomp6_alloc_tfms (const char *alg_name)
@@ -335,7 +335,7 @@ static struct crypto_comp **ipcomp6_allostruct crypto_comp *tfm; tfms = pos->tfms; - tfm = *per_cpu_ptr (tfms, cpu); + tfm = *CPU_PTR (tfms, cpu);if (!strcmp (crypto_comp_name (tfm), alg_name)) { pos->users++;
@@ -351,7 +351,7 @@ static struct crypto_comp **ipcomp6_alloINIT_LIST_HEAD (&pos->list);list_add (&pos->list, &ipcomp6_tfms_list); - pos->tfms = tfms = alloc_percpu(struct crypto_comp *); + pos->tfms = tfms = CPU_ALLOC(struct crypto_comp *, GFP_KERNEL);if (!tfms) goto error;
@@ -360,7 +360,7 @@ static struct crypto_comp **ipcomp6_allo CRYPTO_ALG_ASYNC);if (!tfm) goto error; - *per_cpu_ptr (tfms, cpu) = tfm; + *CPU_PTR (tfms, cpu) = tfm; }return tfms;
PATCH 20/28 cpu alloc: dmaengine conversion
In reply to Christoph Lameter--- drivers/dma/dmaengine.c | 27 ++++++++++++++------------- include/linux/dmaengine.h | 5 +++-- 2 files changed, 17 insertions(+), 15 deletions(-)
drivers/dma/dmaengine.c +14 -13
@@ -84,7 +84,7 @@ static ssize_t show_memcpy_count(structint i;for_each_possible_cpu (i) - count +=per_cpu_ptr (chan->local, i)->memcpy_count; + count +=CPU_PTR (chan->local, i)->memcpy_count;return sprintf (buf,"%lu\n" , count); }
@@ -96,7 +96,7 @@ static ssize_t show_bytes_transferred(stint i;for_each_possible_cpu (i) - count +=per_cpu_ptr (chan->local, i)->bytes_transferred; + count +=CPU_PTR (chan->local, i)->bytes_transferred;return sprintf (buf,"%lu\n" , count); }
@@ -110,7 +110,7 @@ static ssize_t show_in_use(struct class_ atomic_read(&chan->refcount.refcount) > 1) in_use = 1; else { -if (local_read (&(per_cpu_ptr (chan->local, +if (local_read (&(CPU_PTR (chan->local,get_cpu ())->refcount)) >0 ) in_use =1 ;put_cpu ();
@@ -227,7 +227,7 @@ static void dma_chan_free_rcu(struct rcuint bias =0x7FFFFFFF ;int i;for_each_possible_cpu (i) - bias -=local_read (&per_cpu_ptr (chan->local, i)->refcount); + bias -=local_read (&CPU_PTR (chan->local, i)->refcount);atomic_sub (bias, &chan->refcount.refcount);kref_put (&chan->refcount, dma_chan_cleanup); }
@@ -379,7 +379,8 @@ int dma_async_device_register(struct dma/* represent channels in sysfs. Probably want devs too */ list_for_each_entry (chan, &device->channels, device_node) { - chan->local =alloc_percpu (typeof (*chan->local)); + chan->local =CPU_ALLOC (typeof (*chan->local), +GFP_KERNEL | __GFP_ZERO);if (chan->local ==NULL )continue ;
@@ -392,7 +393,7 @@ int dma_async_device_register(struct dma rc =class_device_register (&chan->class_dev);if (rc) { chancnt--; -free_percpu (chan->local); +CPU_FREE (chan->local); chan->local =NULL ; goto err_out; }
@@ -418,7 +419,7 @@ err_out:kref_put (&device->refcount, dma_async_device_cleanup);class_device_unregister (&chan->class_dev); chancnt--; -free_percpu (chan->local); +CPU_FREE (chan->local); }return rc; }
@@ -494,8 +495,8 @@ dma_async_memcpy_buf_to_buf(struct dma_c cookie = tx->tx_submit (tx); cpu =get_cpu (); -per_cpu_ptr (chan->local, cpu)->bytes_transferred += len; -per_cpu_ptr (chan->local, cpu)->memcpy_count++; +CPU_PTR (chan->local, cpu)->bytes_transferred += len; +CPU_PTR (chan->local, cpu)->memcpy_count++;put_cpu ();return cookie;
@@ -538,8 +539,8 @@ dma_async_memcpy_buf_to_pg(struct dma_ch cookie = tx->tx_submit (tx); cpu =get_cpu (); -per_cpu_ptr (chan->local, cpu)->bytes_transferred += len; -per_cpu_ptr (chan->local, cpu)->memcpy_count++; +CPU_PTR (chan->local, cpu)->bytes_transferred += len; +CPU_PTR (chan->local, cpu)->memcpy_count++;put_cpu ();return cookie;
@@ -584,8 +585,8 @@ dma_async_memcpy_pg_to_pg(struct dma_cha cookie = tx->tx_submit (tx); cpu =get_cpu (); -per_cpu_ptr (chan->local, cpu)->bytes_transferred += len; -per_cpu_ptr (chan->local, cpu)->memcpy_count++; +CPU_PTR (chan->local, cpu)->bytes_transferred += len; +CPU_PTR (chan->local, cpu)->memcpy_count++;put_cpu ();return cookie;
include/linux/dmaengine.h +3 -2
@@ -27,6 +27,7 @@#include <linux/completion.h> #include <linux/rcupdate.h> #include <linux/dma-mapping.h> +#include <linux/cpu_alloc.h> /** * enum dma_state - resource PNP/power managment state
@@ -150,7 +151,7 @@ static inline void dma_chan_get(struct dif (unlikely (chan->slow_ref))kref_get (&chan->refcount);else { -local_inc (&(per_cpu_ptr (chan->local,get_cpu ())->refcount)); +local_inc (&CPU_PTR (chan->local,get_cpu ())->refcount);put_cpu (); } }
@@ -160,7 +161,7 @@ static inline void dma_chan_put(struct dif (unlikely (chan->slow_ref))kref_put (&chan->refcount, dma_chan_cleanup);else { -local_dec (&(per_cpu_ptr (chan->local,get_cpu ())->refcount)); +local_dec (&CPU_PTR (chan->local,get_cpu ())->refcount);put_cpu (); } }
PATCH 21/28 cpu alloc: convert loopback statistics
In reply to Christoph Lameter--- drivers/net/loopback.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/loopback.c +4 -4
@@ -156,7 +156,7 @@ static int loopback_xmit(struct sk_buff/* it's OK to use per_cpu_ptr() because BHs are off */ pcpu_lstats =netdev_priv (dev); - lb_stats =per_cpu_ptr (pcpu_lstats,smp_processor_id ()); + lb_stats =THIS_CPU (pcpu_lstats); lb_stats->bytes += skb->len; lb_stats->packets++;
@@ -177,7 +177,7 @@ static struct net_device_stats *get_statfor_each_possible_cpu (i) {const struct pcpu_lstats *lb_stats; - lb_stats =per_cpu_ptr (pcpu_lstats, i); + lb_stats =CPU_PTR (pcpu_lstats, i); bytes += lb_stats->bytes; packets += lb_stats->packets; }
@@ -205,7 +205,7 @@ static int loopback_dev_init(struct net_ {struct pcpu_lstats *lstats; - lstats = alloc_percpu(struct pcpu_lstats); + lstats = CPU_ALLOC(struct pcpu_lstats, GFP_KERNEL | __GFP_ZERO);if (!lstats)return -ENOMEM ;
@@ -217,7 +217,7 @@ static void loopback_dev_free(struct net {struct pcpu_lstats *lstats =netdev_priv (dev); -free_percpu (lstats); +CPU_FREE (lstats);free_netdev (dev); }
PATCH 22/28 cpu alloc: veth conversion
In reply to Christoph Lameter--- drivers/net/veth.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/veth.c +5 -5
@@ -162,7 +162,7 @@ static int veth_xmit(struct sk_buff *skb rcv_priv =netdev_priv (rcv); cpu =smp_processor_id (); - stats =per_cpu_ptr (priv->stats, cpu); + stats =CPU_PTR (priv->stats, cpu);if (!(rcv->flags &IFF_UP )) goto outf;
@@ -183,7 +183,7 @@ static int veth_xmit(struct sk_buff *skb stats->tx_bytes += length; stats->tx_packets++; - stats =per_cpu_ptr (rcv_priv->stats, cpu); + stats =CPU_PTR (rcv_priv->stats, cpu); stats->rx_bytes += length; stats->rx_packets++;
@@ -217,7 +217,7 @@ static struct net_device_stats *veth_get dev_stats->tx_dropped =0 ;for_each_online_cpu (cpu) { - stats =per_cpu_ptr (priv->stats, cpu); + stats =CPU_PTR (priv->stats, cpu); dev_stats->rx_packets += stats->rx_packets; dev_stats->tx_packets += stats->tx_packets;
@@ -261,7 +261,7 @@ static int veth_dev_init(struct net_devistruct veth_net_stats *stats;struct veth_priv *priv; - stats = alloc_percpu(struct veth_net_stats); + stats = CPU_ALLOC(struct veth_net_stats, GFP_KERNEL | __GFP_ZER);if (stats ==NULL )return -ENOMEM ;
@@ -275,7 +275,7 @@ static void veth_dev_free(struct net_devstruct veth_priv *priv; priv =netdev_priv (dev); -free_percpu (priv->stats); +CPU_FREE (priv->stats);free_netdev (dev); }
PATCH 23/28 cpu alloc: Chelsio statistics conversion
In reply to Christoph Lameter--- drivers/net/chelsio/sge.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/net/chelsio/sge.c +7 -6
@@ -805,7 +805,7 @@ void t1_sge_destroy(struct sge *sge)int i;for_each_port (sge->adapter, i) -free_percpu (sge->port_stats[i]); +CPU_FREE (sge->port_stats[i]);kfree (sge->tx_sched);free_tx_resources (sge);
@@ -984,7 +984,7 @@ void t1_sge_get_port_stats(const structmemset (ss,0 ,sizeof (*ss));for_each_possible_cpu (cpu) { -struct sge_port_stats *st =per_cpu_ptr (sge->port_stats[port], cpu); +struct sge_port_stats *st =CPU_PTR (sge->port_stats[port], cpu); ss->rx_packets += st->rx_packets; ss->rx_cso_good += st->rx_cso_good;
@@ -1380,7 +1380,7 @@ static void sge_rx(struct sge *sge, stru__skb_pull (skb,sizeof (*p)); skb->dev->last_rx = jiffies; - st =per_cpu_ptr (sge->port_stats[p->iff],smp_processor_id ()); + st =THIS_CPU (sge->port_stats[p->iff]); st->rx_packets++; skb->protocol =eth_type_trans (skb, adapter->port[p->iff].dev);
@@ -1848,7 +1848,7 @@ int t1_start_xmit(struct sk_buff *skb, s {struct adapter *adapter = dev->priv;struct sge *sge = adapter->sge; -struct sge_port_stats *st =per_cpu_ptr (sge->port_stats[dev->if_port],smp_processor_id ()); +struct sge_port_stats *st =THIS_CPU (sge->port_stats[dev->if_port]);struct cpl_tx_pkt *cpl;struct sk_buff *orig_skb = skb;int ret;
@@ -2165,7 +2165,8 @@ struct sge * __devinit t1_sge_create(str sge->jumbo_fl =t1_is_T1B (adapter) ?1 :0 ;for_each_port (adapter, i) { - sge->port_stats[i] = alloc_percpu(struct sge_port_stats); + sge->port_stats[i] = CPU_ALLOC(struct sge_port_stats, +GFP_KERNEL | __GFP_ZERO);if (!sge->port_stats[i]) goto nomem_port; }
@@ -2209,7 +2210,7 @@ struct sge * __devinit t1_sge_create(strreturn sge; nomem_port:while (i >=0 ) { -free_percpu (sge->port_stats[i]); +CPU_FREE (sge->port_stats[i]); --i; }kfree (sge);
PATCH 24/28 cpu alloc: convert mib handling to cpu alloc
In reply to Christoph LameterUse the cpu alloc functions for the mib handling functions in the net layer. The API for snmp_mib_free() is changed to add a size parameter since cpu_fre requires that.
--- include/net/ip.h | 2 +- include/net/snmp.h | 14 +++++++------- net/dccp/proto.c | 12 +++++++----- net/ipv4/af_inet.c | 32 ++++++++++++++++++-------------- net/ipv6/addrconf.c | 10 +++++----- net/ipv6/af_inet6.c | 18 +++++++++--------- net/sctp/proc.c | 4 ++-- net/sctp/protocol.c | 13 ++++++++----- 8 files changed, 57 insertions(+), 48 deletions(-)
include/net/snmp.h +7 -7
@@ -133,18 +133,18 @@ struct linux_mib {#define SNMP_STAT_USRPTR (name) (name[1])#define SNMP_INC_STATS_BH (mib, field) \ - (per_cpu_ptr(mib[0], raw_smp_processor_id())->mibs[field]++) + (__THIS_CPU(mib[0])->mibs[field]++)#define SNMP_INC_STATS_OFFSET_BH (mib, field, offset) \ - (per_cpu_ptr(mib[0], raw_smp_processor_id())->mibs[field + (offset)]++) + (__THIS_CPU(mib[0])->mibs[field + (offset)]++)#define SNMP_INC_STATS_USER (mib, field) \ - (per_cpu_ptr(mib[1], raw_smp_processor_id())->mibs[field]++) + (__THIS_CPU(mib[1])->mibs[field]++)#define SNMP_INC_STATS (mib, field) \ - (per_cpu_ptr(mib[!in_softirq()], raw_smp_processor_id())->mibs[field]++) + (__THIS_CPU(mib[!in_softirq()])->mibs[field]++)#define SNMP_DEC_STATS (mib, field) \ - (per_cpu_ptr(mib[!in_softirq()], raw_smp_processor_id())->mibs[field]--) + (__THIS_CPU(mib[!in_softirq()])->mibs[field]--)#define SNMP_ADD_STATS_BH (mib, field, addend) \ - (per_cpu_ptr(mib[0], raw_smp_processor_id())->mibs[field] += addend) + (__THIS_CPU(mib[0])->mibs[field] += addend)#define SNMP_ADD_STATS_USER (mib, field, addend) \ - (per_cpu_ptr(mib[1], raw_smp_processor_id())->mibs[field] += addend) + (__THIS_CPU(mib[1])->mibs[field] += addend)#endif
net/dccp/proto.c +7 -5
@@ -990,11 +990,13 @@ static int __init dccp_mib_init(void) {int rc = -ENOMEM ; - dccp_statistics[0] = alloc_percpu(struct dccp_mib); + dccp_statistics[0] = CPU_ALLOC(struct dccp_mib, +GFP_KERNEL | __GFP_ZERO);if (dccp_statistics[0 ] ==NULL ) goto out; - dccp_statistics[1] = alloc_percpu(struct dccp_mib); + dccp_statistics[1] = CPU_ALLOC(struct dccp_mib, +GFP_KERNEL | __GFP_ZERO);if (dccp_statistics[1 ] ==NULL ) goto out_free_one;
@@ -1002,7 +1004,7 @@ static int __init dccp_mib_init(void) out:return rc; out_free_one: -free_percpu (dccp_statistics[0 ]); +CPU_FREE (dccp_statistics[0 ]); dccp_statistics[0 ] =NULL ; goto out;
@@ -1010,8 +1012,8 @@ out_free_one:static void dccp_mib_exit (void ) { -free_percpu (dccp_statistics[0 ]); -free_percpu (dccp_statistics[1 ]); +CPU_FREE (dccp_statistics[0 ]); +CPU_FREE (dccp_statistics[1 ]); dccp_statistics[0 ] = dccp_statistics[1 ] =NULL ; }
net/sctp/protocol.c +8 -5
@@ -61,6 +61,7 @@#include <net/addrconf.h> #include <net/inet_common.h> #include <net/inet_ecn.h> +#include <linux/cpu_alloc.h> /* Global data structures. */ struct sctp_globals sctp_globals__read_mostly ;
@@ -970,12 +971,14 @@ int sctp_register_pf(struct sctp_pf *pf,static int __init init_sctp_mibs (void ) { - sctp_statistics[0] = alloc_percpu(struct sctp_mib); + sctp_statistics[0] = CPU_ALLOC(struct sctp_mib, +GFP_KERNEL | __GFP_ZERO);if (!sctp_statistics[0 ])return -ENOMEM ; - sctp_statistics[1] = alloc_percpu(struct sctp_mib); + sctp_statistics[1] = CPU_ALLOC(struct sctp_mib, +GFP_KERNEL | __GFP_ZERO);if (!sctp_statistics[1 ]) { -free_percpu (sctp_statistics[0 ]); +CPU_FREE (sctp_statistics[0 ]);return -ENOMEM ; }return 0 ;
@@ -984,8 +987,8 @@ static int __init init_sctp_mibs(void)static void cleanup_sctp_mibs (void ) { -free_percpu (sctp_statistics[0 ]); -free_percpu (sctp_statistics[1 ]); +CPU_FREE (sctp_statistics[0 ]); +CPU_FREE (sctp_statistics[1 ]); }/* Initialize the universe into something sensible. */
net/ipv4/af_inet.c +18 -14
@@ -88,6 +88,7 @@#include <linux/poll.h> #include <linux/netfilter_ipv4.h> #include <linux/random.h> +#include <linux/cpu_alloc.h> #include <asm/uaccess.h> #include <asm/system.h>
@@ -1230,8 +1231,8 @@ unsigned long snmp_fold_field(void *mib[int i;for_each_possible_cpu (i) { - res += *(((unsigned long *)per_cpu_ptr (mib[0 ], i)) + offt); - res += *(((unsigned long *)per_cpu_ptr (mib[1 ], i)) + offt); + res += *(((unsigned long *)CPU_PTR (mib[0 ], i)) + offt); + res += *(((unsigned long *)CPU_PTR (mib[1 ], i)) + offt); }return res; }
@@ -1240,26 +1241,28 @@ EXPORT_SYMBOL_GPL(snmp_fold_field);int snmp_mib_init (void *ptr[2 ],size_t mibsize,size_t mibalign) {BUG_ON (ptr ==NULL ); - ptr[0 ] =__alloc_percpu (mibsize); + ptr[0 ] =cpu_alloc (mibsize,GFP_KERNEL | __GFP_ZERO, + mibalign);if (!ptr[0 ]) goto err0; - ptr[1 ] =__alloc_percpu (mibsize); + ptr[1 ] =cpu_alloc (mibsize,GFP_KERNEL | __GFP_ZERO, + mibalign);if (!ptr[1 ]) goto err1;return 0 ; err1: -free_percpu (ptr[0 ]); +cpu_free (ptr[0 ], mibsize); ptr[0 ] =NULL ; err0:return -ENOMEM ; }EXPORT_SYMBOL_GPL (snmp_mib_init); -void snmp_mib_free (void *ptr[2 ]) +void snmp_mib_free (void *ptr[2 ],size_t mibsize) {BUG_ON (ptr ==NULL ); -free_percpu (ptr[0 ]); -free_percpu (ptr[1 ]); +cpu_free (ptr[0 ], mibsize); +cpu_free (ptr[1 ], mibsize); ptr[0 ] = ptr[1 ] =NULL ; }EXPORT_SYMBOL_GPL (snmp_mib_free);
@@ -1324,17 +1327,18 @@ static int __init init_ipv4_mibs(void)return 0 ; err_udplite_mib: -snmp_mib_free ((void **)udp_statistics); +snmp_mib_free ((void **)udp_statistics,sizeof (struct udp_mib )); err_udp_mib: -snmp_mib_free ((void **)tcp_statistics); +snmp_mib_free ((void **)tcp_statistics,sizeof (struct tcp_mib )); err_tcp_mib: -snmp_mib_free ((void **)icmpmsg_statistics); +snmp_mib_free ((void **)icmpmsg_statistics, +sizeof (struct icmpmsg_mib )); err_icmpmsg_mib: -snmp_mib_free ((void **)icmp_statistics); +snmp_mib_free ((void **)icmp_statistics,sizeof (struct icmp_mib )); err_icmp_mib: -snmp_mib_free ((void **)ip_statistics); +snmp_mib_free ((void **)ip_statistics,sizeof (struct ipstats_mib )); err_ip_mib: -snmp_mib_free ((void **)net_statistics); +snmp_mib_free ((void **)net_statistics,sizeof (struct linux_mib )); err_net_mib:return -ENOMEM ; }
net/sctp/proc.c +2 -2
@@ -86,10 +86,10 @@ fold_field(void *mib[], int nr)for_each_possible_cpu (i) { res += - *((unsigned long *) (((void *)per_cpu_ptr (mib[0 ], i)) + + *((unsigned long *) (((void *)CPU_PTR (mib[0 ], i)) +sizeof (unsigned long ) * nr)); res += - *((unsigned long *) (((void *)per_cpu_ptr (mib[1 ], i)) + + *((unsigned long *) (((void *)CPU_PTR (mib[1 ], i)) +sizeof (unsigned long ) * nr)); }return res;
include/net/ip.h +1 -1
@@ -170,7 +170,7 @@ DECLARE_SNMP_STAT(struct linux_mib, net_extern unsigned long snmp_fold_field (void *mib[],int offt);extern int snmp_mib_init (void *ptr[2 ],size_t mibsize,size_t mibalign); -extern void snmp_mib_free (void *ptr[2 ]); +extern void snmp_mib_free (void *ptr[2 ],size_t mibsize);extern void inet_get_local_port_range (int *low,int *high);
net/ipv6/addrconf.c +5 -5
@@ -271,18 +271,18 @@ static int snmp6_alloc_dev(struct inet6_return 0 ; err_icmpmsg: -snmp_mib_free ((void **)idev->stats.icmpv6); +snmp_mib_free ((void **)idev->stats.icmpv6,sizeof (struct icmpv6_mib )); err_icmp: -snmp_mib_free ((void **)idev->stats.ipv6); +snmp_mib_free ((void **)idev->stats.ipv6,sizeof (struct ipstats_mib )); err_ip:return -ENOMEM ; }static void snmp6_free_dev (struct inet6_dev *idev) { -snmp_mib_free ((void **)idev->stats.icmpv6msg); -snmp_mib_free ((void **)idev->stats.icmpv6); -snmp_mib_free ((void **)idev->stats.ipv6); +snmp_mib_free ((void **)idev->stats.icmpv6msg,sizeof (struct icmpv6_mib )); +snmp_mib_free ((void **)idev->stats.icmpv6,sizeof (struct icmpv6_mib )); +snmp_mib_free ((void **)idev->stats.ipv6,sizeof (struct ipstats_mib )); }/* Nobody refers to this device, we may destroy it. */
net/ipv6/af_inet6.c +9 -9
@@ -731,13 +731,13 @@ static int __init init_ipv6_mibs(void)return 0 ; err_udplite_mib: -snmp_mib_free ((void **)udp_stats_in6); +snmp_mib_free ((void **)udp_stats_in6,sizeof (struct udp_mib )); err_udp_mib: -snmp_mib_free ((void **)icmpv6msg_statistics); +snmp_mib_free ((void **)icmpv6msg_statistics,sizeof (struct icmpv6_mib )); err_icmpmsg_mib: -snmp_mib_free ((void **)icmpv6_statistics); +snmp_mib_free ((void **)icmpv6_statistics,sizeof (struct icmpv6_mib )); err_icmp_mib: -snmp_mib_free ((void **)ipv6_statistics); +snmp_mib_free ((void **)ipv6_statistics,sizeof (struct ipstats_mib )); err_ip_mib:return -ENOMEM ;
@@ -745,11 +745,11 @@ err_ip_mib:static void cleanup_ipv6_mibs (void ) { -snmp_mib_free ((void **)ipv6_statistics); -snmp_mib_free ((void **)icmpv6_statistics); -snmp_mib_free ((void **)icmpv6msg_statistics); -snmp_mib_free ((void **)udp_stats_in6); -snmp_mib_free ((void **)udplite_stats_in6); +snmp_mib_free ((void **)ipv6_statistics,sizeof (struct ipstats_mib )); +snmp_mib_free ((void **)icmpv6_statistics,sizeof (struct icmpv6_mib )); +snmp_mib_free ((void **)icmpv6msg_statistics,sizeof (struct icmpv6_mib )); +snmp_mib_free ((void **)udp_stats_in6,sizeof (struct udp_mib )); +snmp_mib_free ((void **)udplite_stats_in6,sizeof (struct udp_mib )); }static int __init inet6_init (void )
PATCH 25/28 cpu alloc: Explicitly code allocpercpu calls in iucv
In reply to Christoph LameterThe iucv is the only user of the various functions that are used to bring parts of cpus up and down. Its the only allocpercpu user that will do I/O on per cpu objects (which is difficult to do with virtually mapped memory). And its the only use of allocpercpu where a GFP_DMA allocation is done.
Remove the allocpercpu calls from iucv and code the allocation and freeing manually.
--- net/iucv/iucv.c | 99 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 43 deletions(-)
net/iucv/iucv.c +56 -43
@@ -97,7 +97,7 @@ struct iucv_irq_list {struct iucv_irq_data data; }; -static struct iucv_irq_data *iucv_irq_data; +static struct iucv_irq_data *iucv_irq_data[NR_CPUS ];static cpumask_t iucv_buffer_cpumask =CPU_MASK_NONE ;static cpumask_t iucv_irq_cpumask =CPU_MASK_NONE ;
@@ -277,7 +277,7 @@ union iucv_param {/* * Anchor for per-cpu IUCV command parameter block. */ -static union iucv_param *iucv_param; +static union iucv_param *iucv_param[NR_CPUS ];/** * iucv_call_b2f0
@@ -356,7 +356,7 @@ static void iucv_allow_cpu(void *data)* 0x10 - Flag to allow priority message completion interrupts * 0x08 - Flag to allow IUCV control interrupts */ - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[cpu];memset (parm,0 ,sizeof (union iucv_param )); parm->set_mask.ipmask =0xf8 ;iucv_call_b2f0 (IUCV_SETMASK , parm);
@@ -377,7 +377,7 @@ static void iucv_block_cpu(void *data)union iucv_param *parm;/* Disable all iucv interrupts. */ - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[cpu];memset (parm,0 ,sizeof (union iucv_param ));iucv_call_b2f0 (IUCV_SETMASK , parm);
@@ -401,9 +401,9 @@ static void iucv_declare_cpu(void *data)return ;/* Declare interrupt buffer. */ - parm =percpu_ptr (iucv_param, cpu); + parm = iucv_param[cpu];memset (parm,0 ,sizeof (union iucv_param )); - parm->db.ipbfadr1 =virt_to_phys (percpu_ptr (iucv_irq_data, cpu)); + parm->db.ipbfadr1 =virt_to_phys (iucv_irq_data[cpu]); rc =iucv_call_b2f0 (IUCV_DECLARE_BUFFER , parm);if (rc) {char *err ="Unknown" ;
@@ -458,7 +458,7 @@ static void iucv_retrieve_cpu(void *dataiucv_block_cpu (NULL );/* Retrieve interrupt buffer. */ - parm =percpu_ptr (iucv_param, cpu); + parm = iucv_param[cpu];iucv_call_b2f0 (IUCV_RETRIEVE_BUFFER , parm);/* Clear indication that an iucv buffer exists for this cpu. */
@@ -558,13 +558,13 @@ static int __cpuinit iucv_cpu_notify(strswitch (action) {case CPU_UP_PREPARE :case CPU_UP_PREPARE_FROZEN : -if (!percpu_populate (iucv_irq_data, -sizeof (struct iucv_irq_data ), -GFP_KERNEL |GFP_DMA , cpu)) + iucv_irq_data[cpu] =kmalloc_node (sizeof (struct iucv_irq_data ), +GFP_KERNEL |GFP_DMA ,cpu_to_node (cpu)); +if (!iucv_irq_data[cpu])return NOTIFY_BAD ; -if (!percpu_populate (iucv_param,sizeof (union iucv_param ), -GFP_KERNEL |GFP_DMA , cpu)) { -percpu_depopulate (iucv_irq_data, cpu); + iucv_param[cpu] =kmalloc_node (sizeof (union iucv_param ), +GFP_KERNEL |GFP_DMA ,cpu_to_node (cpu)); +if (!iucv_param[cpu])return NOTIFY_BAD ; }break ;
@@ -572,8 +572,10 @@ static int __cpuinit iucv_cpu_notify(strcase CPU_UP_CANCELED_FROZEN :case CPU_DEAD :case CPU_DEAD_FROZEN : -percpu_depopulate (iucv_param, cpu); -percpu_depopulate (iucv_irq_data, cpu); +kfree (iucv_param[cpu]); + iucv_param[cpu] =NULL ; +kfree (iucv_irq_data[cpu]); + iucv_irq_data[cpu] =NULL ;break ;case CPU_ONLINE :case CPU_ONLINE_FROZEN :
@@ -612,7 +614,7 @@ static int iucv_sever_pathid(u16 pathid, {union iucv_param *parm; - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[smp_processor_id ()];memset (parm,0 ,sizeof (union iucv_param ));if (userdata)memcpy (parm->ctrl.ipuser, userdata,sizeof (parm->ctrl.ipuser));
@@ -755,7 +757,7 @@ int iucv_path_accept(struct iucv_path *plocal_bh_disable ();/* Prepare parameter block. */ - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[smp_processor_id ()];memset (parm,0 ,sizeof (union iucv_param )); parm->ctrl.ippathid = path->pathid; parm->ctrl.ipmsglim = path->msglim;
@@ -799,7 +801,7 @@ int iucv_path_connect(struct iucv_path *BUG_ON (in_atomic ());spin_lock_bh (&iucv_table_lock);iucv_cleanup_queue (); - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[smp_processor_id ()];memset (parm,0 ,sizeof (union iucv_param )); parm->ctrl.ipmsglim = path->msglim; parm->ctrl.ipflags1 = path->flags;
@@ -854,7 +856,7 @@ int iucv_path_quiesce(struct iucv_path *int rc;local_bh_disable (); - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[smp_processor_id ()];memset (parm,0 ,sizeof (union iucv_param ));if (userdata)memcpy (parm->ctrl.ipuser, userdata,sizeof (parm->ctrl.ipuser));
@@ -881,7 +883,7 @@ int iucv_path_resume(struct iucv_path *pint rc;local_bh_disable (); - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[smp_processor_id ()];memset (parm,0 ,sizeof (union iucv_param ));if (userdata)memcpy (parm->ctrl.ipuser, userdata,sizeof (parm->ctrl.ipuser));
@@ -936,7 +938,7 @@ int iucv_message_purge(struct iucv_pathint rc;local_bh_disable (); - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[smp_processor_id ()];memset (parm,0 ,sizeof (union iucv_param )); parm->purge.ippathid = path->pathid; parm->purge.ipmsgid = msg->id;
@@ -1003,7 +1005,7 @@ int iucv_message_receive(struct iucv_pat }local_bh_disable (); - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[smp_processor_id ()];memset (parm,0 ,sizeof (union iucv_param )); parm->db.ipbfadr1 = (u32 )(addr_t ) buffer; parm->db.ipbfln1f = (u32 ) size;
@@ -1040,7 +1042,7 @@ int iucv_message_reject(struct iucv_pathint rc;local_bh_disable (); - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[smp_processor_id ()];memset (parm,0 ,sizeof (union iucv_param )); parm->db.ippathid = path->pathid; parm->db.ipmsgid = msg->id;
@@ -1074,7 +1076,7 @@ int iucv_message_reply(struct iucv_pathint rc;local_bh_disable (); - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[smp_processor_id ()];memset (parm,0 ,sizeof (union iucv_param ));if (flags &IUCV_IPRMDATA ) { parm->dpl.ippathid = path->pathid;
@@ -1118,7 +1120,7 @@ int iucv_message_send(struct iucv_path *int rc;local_bh_disable (); - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[smp_processor_id ()];memset (parm,0 ,sizeof (union iucv_param ));if (flags &IUCV_IPRMDATA ) {/* Message of 8 bytes can be placed into the parameter list. */
@@ -1172,7 +1174,7 @@ int iucv_message_send2way(struct iucv_paint rc;local_bh_disable (); - parm =percpu_ptr (iucv_param,smp_processor_id ()); + parm = iucv_param[smp_processor_id ()];memset (parm,0 ,sizeof (union iucv_param ));if (flags &IUCV_IPRMDATA ) { parm->dpl.ippathid = path->pathid;
@@ -1559,7 +1561,7 @@ static void iucv_external_interrupt(u16struct iucv_irq_data *p;struct iucv_irq_list *work; - p =percpu_ptr (iucv_irq_data,smp_processor_id ()); + p = iucv_irq_data[smp_processor_id ()];if (p->ippathid >= iucv_max_pathid) { printk(KERN_WARNING "iucv_do_int: Got interrupt with " "pathid %d > max_connections (%ld)\n",
@@ -1598,6 +1600,7 @@ static void iucv_external_interrupt(u16static int __init iucv_init (void ) {int rc; +int cpu;if (!MACHINE_IS_VM ) { rc = -EPROTONOSUPPORT ;
@@ -1617,19 +1620,21 @@ static int __init iucv_init(void) rc =PTR_ERR (iucv_root); goto out_bus; } -/* Note: GFP_DMA used to get memory below 2G */ - iucv_irq_data =percpu_alloc (sizeof (struct iucv_irq_data ), -GFP_KERNEL |GFP_DMA ); -if (!iucv_irq_data) { - rc = -ENOMEM ; - goto out_root; - } -/* Allocate parameter blocks. */ - iucv_param =percpu_alloc (sizeof (union iucv_param ), -GFP_KERNEL |GFP_DMA ); -if (!iucv_param) { - rc = -ENOMEM ; - goto out_extint; + +for_each_online_cpu (cpu) { +/* Note: GFP_DMA used to get memory below 2G */ + iucv_irq_data[cpu] =kmalloc_node (sizeof (struct iucv_irq_data ), +GFP_KERNEL |GFP_DMA ,cpu_to_node (cpu)); +if (!iucv_irq_data[cpu]) { + rc = -ENOMEM ; + goto out_root; + +/* Allocate parameter blocks. */ + iucv_param[cpu] =kmalloc_node (sizeof (union iucv_param ), +GFP_KERNEL |GFP_DMA ,cpu_to_node (cpu)); +if (!iucv_param[cpu]) { + rc = -ENOMEM ; + goto out_extint; }register_hotcpu_notifier (&iucv_cpu_notifier);ASCEBC (iucv_error_no_listener,16 );
@@ -1639,7 +1644,10 @@ static int __init iucv_init(void)return 0 ; out_extint: -percpu_free (iucv_irq_data); +for_each_cpu (cpu) { +kfree (iucv_irq_data[cpu]); + iucv_irq_data[cpu] =NULL ; + } out_root:s390_root_dev_unregister (iucv_root); out_bus:
@@ -1658,6 +1666,7 @@ out: static void __exit iucv_exit(void) {struct iucv_irq_list *p, *n; +int cpu;spin_lock_irq (&iucv_queue_lock);list_for_each_entry_safe (p, n, &iucv_task_queue, list)
@@ -1666,8 +1675,12 @@ static void __exit iucv_exit(void)kfree (p);spin_unlock_irq (&iucv_queue_lock);unregister_hotcpu_notifier (&iucv_cpu_notifier); -percpu_free (iucv_param); -percpu_free (iucv_irq_data); +for_each_cpu (cpu) { +kfree (iucv_param[cpu]); + iucv_param[cpu] =NULL ; +kfree (iucv_irq_data[cpu]); + iucv_irq_data[cpu] =NULL ; + }s390_root_dev_unregister (iucv_root);bus_unregister (&iucv_bus);unregister_external_interrupt (0x4000 , iucv_external_interrupt);
PATCH 26/28 cpu alloc: Use for infiniband
In reply to Christoph Lameter--- drivers/infiniband/hw/ehca/ehca_irq.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/infiniband/hw/ehca/ehca_irq.c +11 -11
@@ -646,7 +646,7 @@ static void queue_comp_task(struct ehca_ cpu_id =find_next_online_cpu (pool);BUG_ON (!cpu_online (cpu_id)); - cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu_id); + cct =CPU_PTR (pool->cpu_comp_tasks, cpu_id);BUG_ON (!cct);spin_lock_irqsave (&cct->task_lock, flags);
@@ -654,7 +654,7 @@ static void queue_comp_task(struct ehca_spin_unlock_irqrestore (&cct->task_lock, flags);if (cq_jobs >0 ) { cpu_id =find_next_online_cpu (pool); - cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu_id); + cct =CPU_PTR (pool->cpu_comp_tasks, cpu_id);BUG_ON (!cct); }
@@ -727,7 +727,7 @@ static struct task_struct *create_comp_t {struct ehca_cpu_comp_task *cct; - cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); + cct =CPU_PTR (pool->cpu_comp_tasks, cpu);spin_lock_init (&cct->task_lock);INIT_LIST_HEAD (&cct->cq_list);init_waitqueue_head (&cct->wait_queue);
@@ -743,7 +743,7 @@ static void destroy_comp_task(struct ehcstruct task_struct *task;unsigned long flags_cct; - cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); + cct =CPU_PTR (pool->cpu_comp_tasks, cpu);spin_lock_irqsave (&cct->task_lock, flags_cct);
@@ -759,7 +759,7 @@ static void destroy_comp_task(struct ehcstatic void __cpuinit take_over_work (struct ehca_comp_pool *pool,int cpu) { -struct ehca_cpu_comp_task *cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); +struct ehca_cpu_comp_task *cct =CPU_PTR (pool->cpu_comp_tasks, cpu);LIST_HEAD (list);struct ehca_cq *cq;unsigned long flags_cct;
@@ -772,8 +772,7 @@ static void __cpuinit take_over_work(str cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);list_del (&cq->entry); -__queue_comp_task (cq,per_cpu_ptr (pool->cpu_comp_tasks, -smp_processor_id ())); +__queue_comp_task (cq,THIS_CPU (pool->cpu_comp_tasks)); }spin_unlock_irqrestore (&cct->task_lock, flags_cct);
@@ -799,14 +798,14 @@ static int __cpuinit comp_pool_callback(case CPU_UP_CANCELED :case CPU_UP_CANCELED_FROZEN :ehca_gen_dbg ("CPU: %x (CPU_CANCELED)" , cpu); - cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); + cct =CPU_PTR (pool->cpu_comp_tasks, cpu);kthread_bind (cct->task,any_online_cpu (cpu_online_map));destroy_comp_task (pool, cpu);break ;case CPU_ONLINE :case CPU_ONLINE_FROZEN :ehca_gen_dbg ("CPU: %x (CPU_ONLINE)" , cpu); - cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); + cct =CPU_PTR (pool->cpu_comp_tasks, cpu);kthread_bind (cct->task, cpu);wake_up_process (cct->task);break ;
@@ -849,7 +848,8 @@ int ehca_create_comp_pool(void)spin_lock_init (&pool->last_cpu_lock); pool->last_cpu =any_online_cpu (cpu_online_map); - pool->cpu_comp_tasks = alloc_percpu(struct ehca_cpu_comp_task); + pool->cpu_comp_tasks = CPU_ALLOC(struct ehca_cpu_comp_task, +GFP_KERNEL | __GFP_ZERO);if (pool->cpu_comp_tasks ==NULL ) {kfree (pool);return -EINVAL ;
@@ -883,6 +883,6 @@ void ehca_destroy_comp_pool(void)if (cpu_online (i))destroy_comp_task (pool, i); } -free_percpu (pool->cpu_comp_tasks); +CPU_FREE (pool->cpu_comp_tasks);kfree (pool); }
PATCH 27/28 cpu alloc: Use in the crypto subsystem.
In reply to Christoph Lameter--- crypto/async_tx/async_tx.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
crypto/async_tx/async_tx.c +8 -7
@@ -207,10 +207,10 @@ static void async_tx_rebalance(void)for_each_dma_cap_mask (cap, dma_cap_mask_all)for_each_possible_cpu (cpu) {struct dma_chan_ref *ref = -per_cpu_ptr (channel_table[cap], cpu)->ref; +CPU_PTR (channel_table[cap], cpu)->ref;if (ref) {atomic_set (&ref->count,0 ); -per_cpu_ptr (channel_table[cap], cpu)->ref = +CPU_PTR (channel_table[cap], cpu)->ref =NULL ; } }
@@ -223,7 +223,7 @@ static void async_tx_rebalance(void)else new =get_chan_ref_by_cap (cap,-1 ); -per_cpu_ptr (channel_table[cap], cpu)->ref = new; +CPU_PTR (channel_table[cap], cpu)->ref = new; }spin_unlock_irqrestore (&async_tx_lock, flags);
@@ -327,7 +327,8 @@ async_tx_init(void)clear_bit (DMA_INTERRUPT , dma_cap_mask_all.bits);for_each_dma_cap_mask (cap, dma_cap_mask_all) { - channel_table[cap] = alloc_percpu(struct chan_ref_percpu); + channel_table[cap] = CPU_ALLOC(struct chan_ref_percpu, +GFP_KERNEL | __GFP_ZERO);if (!channel_table[cap]) goto err; }
@@ -343,7 +344,7 @@ err:printk (KERN_ERR "async_tx: initialization failure\n" );while (--cap >=0 ) -free_percpu (channel_table[cap]); +CPU_FRE (channel_table[cap]);return 1 ; }
@@ -356,7 +357,7 @@ static void __exit async_tx_exit(void)for_each_dma_cap_mask (cap, dma_cap_mask_all)if (channel_table[cap]) -free_percpu (channel_table[cap]); +CPU_FREE (channel_table[cap]);dma_async_client_unregister (&async_tx_dma); }
@@ -378,7 +379,7 @@ async_tx_find_channel(struct dma_async_telse if (likely (channel_table_initialized)) {struct dma_chan_ref *ref;int cpu =get_cpu (); - ref =per_cpu_ptr (channel_table[tx_type], cpu)->ref; + ref =CPU_PTR (channel_table[tx_type], cpu)->ref;put_cpu ();return ref ? ref->chan :NULL ; }else
PATCH 28/28 cpu alloc: Remove the allocpercpu functionality
In reply to Christoph LameterThere is no user of allocpercpu left after all the earlier patches were applied. Remove the code that realizes allocpercpu.
--- include/linux/percpu.h | 79 ------------------------------ mm/Makefile | 1 mm/allocpercpu.c | 127 ------------------------------------------------- 3 files changed, 207 deletions(-)
include/linux/percpu.h +0 -79
@@ -31,83 +31,4 @@ &__get_cpu_var(var); }))#define put_cpu_var (var) preempt_enable() -#ifdef CONFIG_SMP - -struct percpu_data { -void *ptrs[NR_CPUS ]; -}; - -#define __percpu_disguise (pdata) (struct percpu_data *)~(unsigned long)(pdata) -/* -* Use this to get to a cpu's version of the per-cpu object dynamically -* allocated. Non-atomic access to the current CPU's version should -* probably be combined with get_cpu()/put_cpu(). -*/ -#define percpu_ptr (ptr, cpu) \ -({ \ - struct percpu_data *__p = __percpu_disguise(ptr); \ - (__typeof__(ptr))__p->ptrs[(cpu)]; \ -}) - -extern void *percpu_populate (void *__pdata,size_t size,gfp_t gfp,int cpu); -extern void percpu_depopulate (void *__pdata,int cpu); -extern int __percpu_populate_mask (void *__pdata,size_t size,gfp_t gfp, -cpumask_t *mask); -extern void __percpu_depopulate_mask (void *__pdata,cpumask_t *mask); -extern void *__percpu_alloc_mask (size_t size,gfp_t gfp,cpumask_t *mask); -extern void percpu_free (void *__pdata); - -#else /* CONFIG_SMP */ - -#define percpu_ptr (ptr, cpu) ({ (void)(cpu); (ptr); }) - -static inline void percpu_depopulate (void *__pdata,int cpu) -{ -} - -static inline void __percpu_depopulate_mask (void *__pdata,cpumask_t *mask) -{ -} - -static inline void *percpu_populate (void *__pdata,size_t size,gfp_t gfp, -int cpu) -{ -return percpu_ptr (__pdata, cpu); -} - -static inline int __percpu_populate_mask (void *__pdata,size_t size,gfp_t gfp, -cpumask_t *mask) -{ -return 0 ; -} - -static __always_inline void *__percpu_alloc_mask(size_t size, gfp_t gfp, cpumask_t *mask) -{ -return kzalloc (size, gfp); -} - -static inline void percpu_free (void *__pdata) -{ -kfree (__pdata); -} - -#endif /* CONFIG_SMP */ - -#define percpu_populate_mask (__pdata, size, gfp, mask) \ - __percpu_populate_mask((__pdata), (size), (gfp), &(mask)) -#define percpu_depopulate_mask (__pdata, mask) \ - __percpu_depopulate_mask((__pdata), &(mask)) -#define percpu_alloc_mask (size, gfp, mask) \ - __percpu_alloc_mask((size), (gfp), &(mask)) - -#define percpu_alloc (size, gfp) percpu_alloc_mask((size), (gfp), cpu_online_map) - -/* (legacy) interface for use without CPU hotplug handling */ - -#define __alloc_percpu (size) percpu_alloc_mask((size), GFP_KERNEL, \ - cpu_possible_map) -#define alloc_percpu (type) (type *)__alloc_percpu(sizeof(type)) -#define free_percpu (ptr) percpu_free((ptr)) -#define per_cpu_ptr (ptr, cpu) percpu_ptr((ptr), (cpu)) -#endif /* __LINUX_PERCPU_H */
mm/Makefile +0 -1
@@ -28,5 +28,4 @@ obj-$(CONFIG_SLUB) += slub.o obj-$(CONFIG_MEMORY_HOTPLUG) += memory_hotplug.o obj-$(CONFIG_FS_XIP) += filemap_xip.o obj-$(CONFIG_MIGRATION) += migrate.o -obj-$(CONFIG_SMP) += allocpercpu.o obj-$(CONFIG_QUICKLIST) += quicklist.o
mm/allocpercpu.c deleted +0 -127
127 lines not on this page · raw message
Quoted 11 lines · Christoph Lameter
TODO:
- Currently only i386, ia64 andx86_64arch definitions are provided. Other arches fall back to 64k static configurations.
- Cpu hotplug support. Current we simply allocate for all possible processors. We could reduce this to only online processors if we could allocate the cpu area for the new processor before the callbacks are run and if we could free the cpu areas for a processor going down after all the callbacks for that were run.
- There are various modifications to exotic configurations that still need some testing (f.e. s/390 iucv--whatever that is--) etc. Tests were done on UP(i386)SMP(i386, x86_64)and NUMA (x86_64, ia64)
IUCV = Inter-User-Communication-Vehicle. Nice name, isn't it?
It is a z/VM hypervisor interface that allows the different guests to communicate between each other. net/iucv.c is the base code, net/af_iucv.c implements the socket interface.
The patch you provided for iucv has a few bugs which are corrected with the patch below (please merge with patch #25). With it new cpu alloc code works fine on s390. We likely want to switch to a virtual configuration as well. For now we can live with the static configuration.
Signature · 9 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin. --- net/iucv/iucv.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
net/iucv/iucv.c +10 -8
@@ -566,7 +566,6 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self, GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));if (!iucv_param[cpu])return NOTIFY_BAD ; - }break ;case CPU_UP_CANCELED :case CPU_UP_CANCELED_FROZEN :
@@ -1622,19 +1621,21 @@ static int __init iucv_init(void) }for_each_online_cpu (cpu) { -/* Note: GFP_DMA used to get memory below 2G */ +/* Note: GFP_DMA used to get memory below 2G */ iucv_irq_data[cpu] =kmalloc_node (sizeof (struct iucv_irq_data ),GFP_KERNEL |GFP_DMA ,cpu_to_node (cpu));if (!iucv_irq_data[cpu]) { rc = -ENOMEM ; - goto out_root; + goto out_free; + }/* Allocate parameter blocks. */ iucv_param[cpu] =kmalloc_node (sizeof (union iucv_param ),GFP_KERNEL |GFP_DMA ,cpu_to_node (cpu));if (!iucv_param[cpu]) { rc = -ENOMEM ; - goto out_extint; + goto out_free; + } }register_hotcpu_notifier (&iucv_cpu_notifier);ASCEBC (iucv_error_no_listener,16 );
@@ -1643,12 +1644,13 @@ static int __init iucv_init(void) iucv_available =1 ;return 0 ; -out_extint: -for_each_cpu (cpu) { +out_free: +for_each_possible_cpu (cpu) { +kfree (iucv_param[cpu]); + iucv_param[cpu] =NULL ;kfree (iucv_irq_data[cpu]); iucv_irq_data[cpu] =NULL ; } -out_root:s390_root_dev_unregister (iucv_root); out_bus:bus_unregister (&iucv_bus);
@@ -1675,7 +1677,7 @@ static void __exit iucv_exit(void)kfree (p);spin_unlock_irq (&iucv_queue_lock);unregister_hotcpu_notifier (&iucv_cpu_notifier); -for_each_cpu (cpu) { +for_each_possible_cpu (cpu) {kfree (iucv_param[cpu]); iucv_param[cpu] =NULL ;kfree (iucv_irq_data[cpu]);
Quoted 5 lines · Martin Schwidefsky
The patch you provided for iucv has a few bugs which are corrected with the patch below (please merge with patch #25). With it new cpu alloc code works fine on s390. We likely want to switch to a virtual configuration as well. For now we can live with the static configuration.
Ok. Thanks!