Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Slab allocators: define common size limitations

Currently we have a maze of configuration variables that determine the
maximum slab size. Worst of all it seems to vary between SLAB and SLUB.

So define a common maximum size for kmalloc. For conveniences sake we use
the maximum size ever supported which is 32 MB. We limit the maximum size
to a lower limit if MAX_ORDER does not allow such large allocations.

For many architectures this patch will have the effect of adding large
kmalloc sizes. x86_64 adds 5 new kmalloc sizes. So a small amount of
memory will be needed for these caches (contemporary SLAB has dynamically
sizeable node and cpu structure so the waste is less than in the past)

Most architectures will then be able to allocate object with sizes up to
MAX_ORDER. We have had repeated breakage (in fact whenever we doubled the
number of supported processors) on IA64 because one or the other struct
grew beyond what the slab allocators supported. This will avoid future
issues and f.e. avoid fixes for 2k and 4k cpu support.

CONFIG_LARGE_ALLOCS is no longer necessary so drop it.

It fixes sparc64 with SLAB.

Signed-off-by: Christoph Lameter <clameter@sgi.com>
Signed-off-by: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Christoph Lameter and committed by
Linus Torvalds
0aa817f0 3ec09742

+34 -71
-8
arch/blackfin/Kconfig
··· 560 560 561 561 source "mm/Kconfig" 562 562 563 - config LARGE_ALLOCS 564 - bool "Allow allocating large blocks (> 1MB) of memory" 565 - help 566 - Allow the slab memory allocator to keep chains for very large 567 - memory sizes - upto 32MB. You may need this if your system has 568 - a lot of RAM, and you need to able to allocate very large 569 - contiguous chunks. If unsure, say N. 570 - 571 563 config BFIN_DMA_5XX 572 564 bool "Enable DMA Support" 573 565 depends on (BF533 || BF532 || BF531 || BF537 || BF536 || BF534 || BF561)
-8
arch/frv/Kconfig
··· 102 102 with a lot of RAM, this can be wasteful of precious low memory. 103 103 Setting this option will put user-space page tables in high memory. 104 104 105 - config LARGE_ALLOCS 106 - bool "Allow allocating large blocks (> 1MB) of memory" 107 - help 108 - Allow the slab memory allocator to keep chains for very large memory 109 - sizes - up to 32MB. You may need this if your system has a lot of 110 - RAM, and you need to able to allocate very large contiguous chunks. 111 - If unsure, say N. 112 - 113 105 source "mm/Kconfig" 114 106 115 107 choice
-8
arch/m68knommu/Kconfig
··· 470 470 default y 471 471 depends on (AVNET5282) 472 472 473 - config LARGE_ALLOCS 474 - bool "Allow allocating large blocks (> 1MB) of memory" 475 - help 476 - Allow the slab memory allocator to keep chains for very large 477 - memory sizes - upto 32MB. You may need this if your system has 478 - a lot of RAM, and you need to able to allocate very large 479 - contiguous chunks. If unsure, say N. 480 - 481 473 config 4KSTACKS 482 474 bool "Use 4Kb for kernel stacks instead of 8Kb" 483 475 default y
-8
arch/v850/Kconfig
··· 240 240 config RESET_GUARD 241 241 bool "Reset Guard" 242 242 243 - config LARGE_ALLOCS 244 - bool "Allow allocating large blocks (> 1MB) of memory" 245 - help 246 - Allow the slab memory allocator to keep chains for very large 247 - memory sizes - upto 32MB. You may need this if your system has 248 - a lot of RAM, and you need to able to allocate very large 249 - contiguous chunks. If unsure, say N. 250 - 251 243 source "mm/Kconfig" 252 244 253 245 endmenu
+15 -5
include/linux/kmalloc_sizes.h
··· 19 19 CACHE(32768) 20 20 CACHE(65536) 21 21 CACHE(131072) 22 - #if (NR_CPUS > 512) || (MAX_NUMNODES > 256) || !defined(CONFIG_MMU) 22 + #if KMALLOC_MAX_SIZE >= 262144 23 23 CACHE(262144) 24 24 #endif 25 - #ifndef CONFIG_MMU 25 + #if KMALLOC_MAX_SIZE >= 524288 26 26 CACHE(524288) 27 + #endif 28 + #if KMALLOC_MAX_SIZE >= 1048576 27 29 CACHE(1048576) 28 - #ifdef CONFIG_LARGE_ALLOCS 30 + #endif 31 + #if KMALLOC_MAX_SIZE >= 2097152 29 32 CACHE(2097152) 33 + #endif 34 + #if KMALLOC_MAX_SIZE >= 4194304 30 35 CACHE(4194304) 36 + #endif 37 + #if KMALLOC_MAX_SIZE >= 8388608 31 38 CACHE(8388608) 39 + #endif 40 + #if KMALLOC_MAX_SIZE >= 16777216 32 41 CACHE(16777216) 42 + #endif 43 + #if KMALLOC_MAX_SIZE >= 33554432 33 44 CACHE(33554432) 34 - #endif /* CONFIG_LARGE_ALLOCS */ 35 - #endif /* CONFIG_MMU */ 45 + #endif
+15
include/linux/slab.h
··· 74 74 #endif 75 75 76 76 /* 77 + * The largest kmalloc size supported by the slab allocators is 78 + * 32 megabyte (2^25) or the maximum allocatable page order if that is 79 + * less than 32 MB. 80 + * 81 + * WARNING: Its not easy to increase this value since the allocators have 82 + * to do various tricks to work around compiler limitations in order to 83 + * ensure proper constant folding. 84 + */ 85 + #define KMALLOC_SHIFT_HIGH ((MAX_ORDER + PAGE_SHIFT) <= 25 ? \ 86 + (MAX_ORDER + PAGE_SHIFT) : 25) 87 + 88 + #define KMALLOC_MAX_SIZE (1UL << KMALLOC_SHIFT_HIGH) 89 + #define KMALLOC_MAX_ORDER (KMALLOC_SHIFT_HIGH - PAGE_SHIFT) 90 + 91 + /* 77 92 * Common kmalloc functions provided by all allocators 78 93 */ 79 94 void *__kmalloc(size_t, gfp_t);
+2 -17
include/linux/slub_def.h
··· 58 58 */ 59 59 #define KMALLOC_SHIFT_LOW 3 60 60 61 - #ifdef CONFIG_LARGE_ALLOCS 62 - #define KMALLOC_SHIFT_HIGH ((MAX_ORDER + PAGE_SHIFT) =< 25 ? \ 63 - (MAX_ORDER + PAGE_SHIFT - 1) : 25) 64 - #else 65 - #if !defined(CONFIG_MMU) || NR_CPUS > 512 || MAX_NUMNODES > 256 66 - #define KMALLOC_SHIFT_HIGH 20 67 - #else 68 - #define KMALLOC_SHIFT_HIGH 18 69 - #endif 70 - #endif 71 - 72 61 /* 73 62 * We keep the general caches in an array of slab caches that are used for 74 63 * 2^x bytes of allocations. ··· 68 79 * Sorry that the following has to be that ugly but some versions of GCC 69 80 * have trouble with constant propagation and loops. 70 81 */ 71 - static inline int kmalloc_index(int size) 82 + static inline int kmalloc_index(size_t size) 72 83 { 73 84 /* 74 85 * We should return 0 if size == 0 but we use the smallest object ··· 76 87 */ 77 88 WARN_ON_ONCE(size == 0); 78 89 79 - if (size > (1 << KMALLOC_SHIFT_HIGH)) 90 + if (size > KMALLOC_MAX_SIZE) 80 91 return -1; 81 92 82 93 if (size > 64 && size <= 96) ··· 99 110 if (size <= 64 * 1024) return 16; 100 111 if (size <= 128 * 1024) return 17; 101 112 if (size <= 256 * 1024) return 18; 102 - #if KMALLOC_SHIFT_HIGH > 18 103 113 if (size <= 512 * 1024) return 19; 104 114 if (size <= 1024 * 1024) return 20; 105 - #endif 106 - #if KMALLOC_SHIFT_HIGH > 20 107 115 if (size <= 2 * 1024 * 1024) return 21; 108 116 if (size <= 4 * 1024 * 1024) return 22; 109 117 if (size <= 8 * 1024 * 1024) return 23; 110 118 if (size <= 16 * 1024 * 1024) return 24; 111 119 if (size <= 32 * 1024 * 1024) return 25; 112 - #endif 113 120 return -1; 114 121 115 122 /*
+2 -17
mm/slab.c
··· 569 569 #endif 570 570 571 571 /* 572 - * Maximum size of an obj (in 2^order pages) and absolute limit for the gfp 573 - * order. 574 - */ 575 - #if defined(CONFIG_LARGE_ALLOCS) 576 - #define MAX_OBJ_ORDER 13 /* up to 32Mb */ 577 - #define MAX_GFP_ORDER 13 /* up to 32Mb */ 578 - #elif defined(CONFIG_MMU) 579 - #define MAX_OBJ_ORDER 5 /* 32 pages */ 580 - #define MAX_GFP_ORDER 5 /* 32 pages */ 581 - #else 582 - #define MAX_OBJ_ORDER 8 /* up to 1Mb */ 583 - #define MAX_GFP_ORDER 8 /* up to 1Mb */ 584 - #endif 585 - 586 - /* 587 572 * Do not go above this order unless 0 objects fit into the slab. 588 573 */ 589 574 #define BREAK_GFP_ORDER_HI 1 ··· 1987 2002 size_t left_over = 0; 1988 2003 int gfporder; 1989 2004 1990 - for (gfporder = 0; gfporder <= MAX_GFP_ORDER; gfporder++) { 2005 + for (gfporder = 0; gfporder <= KMALLOC_MAX_ORDER; gfporder++) { 1991 2006 unsigned int num; 1992 2007 size_t remainder; 1993 2008 ··· 2133 2148 * Sanity checks... these are all serious usage bugs. 2134 2149 */ 2135 2150 if (!name || in_interrupt() || (size < BYTES_PER_WORD) || 2136 - (size > (1 << MAX_OBJ_ORDER) * PAGE_SIZE) || dtor) { 2151 + size > KMALLOC_MAX_SIZE || dtor) { 2137 2152 printk(KERN_ERR "%s: Early error in slab %s\n", __FUNCTION__, 2138 2153 name); 2139 2154 BUG();