cpu alloc / cpu ops v3: Optimize per cpu access
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest41 patches 118 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/41 | cpu_alloc: Increase percpu area size to 128kinclude/ | +1 | 4 replies | |
| 2/41 | cpu alloc: The allocatorinclude/ include/ mm/ +3 more | +222 | 23 replies | |
| 3/41 | cpu alloc: Use cpu allocator instead of the builtin modules per cpu allocatorarch/ arch/ arch/ +6 more | +28 | 5 replies | |
| 4/41 | cpu ops: Core piece for generic atomic per cpu operationsinclude/ | +135 | 35 replies | |
| 5/41 | cpu alloc: Percpu_counter conversionlib/ | +10 | 2 replies | |
| 6/41 | cpu alloc: crash_notes conversionarch/ drivers/ kernel/ | +4 | 0 replies | |
| 7/41 | cpu alloc: Workqueue conversionkernel/ | +21 | 0 replies | |
| 8/41 | cpu alloc: ACPI cstate handling conversionarch/ arch/ drivers/ | +11 | 0 replies | |
| 9/41 | cpu alloc: Genhd statistics conversioninclude/ | +25 | 0 replies | |
| 10/41 | cpu alloc: blktrace conversionblock/ | +10 | 0 replies | |
| 11/41 | cpu alloc: SRCU cpu alloc conversionkernel/ kernel/ | +10 | 0 replies | |
| 12/41 | cpu alloc: XFS counter conversion.fs/ | +8 | 0 replies | |
| 13/41 | cpu alloc: NFS statisticsfs/ fs/ | +12 | 0 replies | |
| 14/41 | cpu alloc: Neigbour statisticsinclude/ net/ | +7 | 0 replies | |
| 15/41 | cpu_alloc: Convert ip route statisticsnet/ net/ | +4 | 0 replies | |
| 16/41 | cpu alloc: Tcp statistics conversionnet/ | +5 | 0 replies | |
| 17/41 | cpu alloc: Convert scratches to cpu allocnet/ net/ | +26 | 0 replies | |
| 18/41 | cpu alloc: Dmaengine conversiondrivers/ include/ | +20 | 0 replies | |
| 19/41 | cpu alloc: Convert loopback statisticsdrivers/ | +7 | 0 replies | |
| 20/41 | cpu alloc: Veth conversiondrivers/ | +9 | 0 replies | |
| 21/41 | cpu alloc: Chelsio statistics conversiondrivers/ | +8 | 0 replies | |
| 22/41 | cpu alloc: Convert network sockets inuse counternet/ | +4 | 0 replies | |
| 23/41 | cpu alloc: Use it for infinibanddrivers/ | +11 | 0 replies | |
| 24/41 | cpu alloc: Use in the crypto subsystem.crypto/ | +9 | 0 replies | |
| 25/41 | cpu alloc: scheduler: Convert cpuusage to cpu_alloc.kernel/ | +5 | 0 replies | |
| 26/41 | cpu alloc: Convert mib handling to cpu allocinclude/ include/ net/ +5 more | +47 | 2 replies | |
| 27/41 | cpu alloc: Remove the allocpercpu functionalityinclude/ mm/ mm/ | +0 | 1 reply | |
| 28/41 | Module handling: Use CPU_xx ops to dynamically allocate countersinclude/ kernel/ | +16 | 0 replies | |
| 29/41 | x86_64: Use CPU ops for nmi alert counterarch/ | +4 | 0 replies | |
| 30/41 | Remove local_t supportDocumentation/ arch/ include/ +24 more | +3 | 0 replies | |
| 31/41 | VM statistics: Use CPU opsinclude/ | +4 | 0 replies | |
| 32/41 | cpu alloc: Use in slubinclude/ mm/ | +34 | 0 replies | |
| 33/41 | cpu alloc: Remove slub fieldsinclude/ mm/ | +11 | 0 replies | |
| 34/41 | cpu alloc: Page allocator conversionarch/ include/ include/ +4 more | +93 | 0 replies | |
| 35/41 | Support for CPU opsarch/ arch/ arch/ +6 more | +138 | 2 replies | |
| 36/41 | Zero based percpu: Infrastructure to rebase the per cpu area to zeroinclude/ include/ include/ +2 more | +44 | 0 replies | |
| 37/41 | x86_64: Fold pda into per cpu areaarch/ arch/ arch/ +2 more | +33 | 0 replies | |
| 38/41 | x86: Extend percpu ops to 64 bitinclude/ | +78 | 0 replies | |
| 39/41 | x86: Replace cpu_pda() using percpu logic and get rid of _cpu_pda()arch/ arch/ arch/ +6 more | +35 | 0 replies | |
| 40/41 | x86: Replace xxx_pda() operations with x86_xx_percpu().arch/ arch/ arch/ +12 more | +37 | 0 replies | |
| 41/41 | x86_64: Support for cpu opsarch/ include/ | +35 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [patch 00/41] cpu alloc / cpu ops v3: Optimize per cpu access
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. We could nr_cpu_ids there but we would still have to allocate all possible processors up to the number of processor ids. cpu_alloc can deal with sparse cpu_maps.
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
1. 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.
2. There is only a single per cpu array that is used for the percpu area and all per cpu allocations.
3. The lookup of a per cpu object is easy and requires memory access to (worst case: architecture does not provide cpu ops):
A) per cpu offset from the per cpu pointer table (if its the current processor then there is usually some more efficient means of retrieving the offset)
B) cpu pointer to the object
C) the per cpu object itself.
4. 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.
5. A single pointer can be used regardless of the number of processors in the system.
The cpu allocator manages a fixed size data per cpu data area. The size can be configured as needed.
The current usage of the cpu area can be seen in the field
cpu_bytes
in /proc/vmstat
The patchset is agsinst 2.6.26-rc4.
There are two arch implementation of cpu ops provides.
1. x86. Another version of the zero based x86 patches exist by Mike.
2. IA64. Limited implementation since IA64 has no fast RMV ops. But we can avoid the addition of the my_cpu_offset in hotpaths.
This is a rather complex patchset and I am not sure how to merge it. Maybe it would be best to merge a piece at a time beginning with the basic infrastructure in the first few patches?