SLUB: Determine slub_max_order depending on the number of pages available Determine the maximum order to be used for slabs and the mininum desired number of objects in a slab from the amount of pages that a system has available (like SLAB does for the order 1/0 distinction). For systems with less than 128M only use order 0 allocations (SLAB does that for <32M only but SLUB can pack more into a slab). The order 0 config is useful for small systems to minimize the memory used. Memory easily fragments since we have less than 32k pages to play with. Order 0 insures that higher order allocations are minimized (SLUB must still use larger orders for objects that do not fit into order 0 pages). Systems with less than 1G get the default order 1 configurations. Most slab caches will be of order 0. Where a significant amount of memory can be saved will we go to order 1. This is basically equivalent to the corresponding SLAB configuration. If the system has more than 1G but less than 4G then we have a medium system. We allow order 2 allocations and require a mininum of 16 objects per slab. For systems with more than 4GB of memory we require a mininum of 32 objects per slab and allow up to order 3 allocations. Such systems have more than a million pages and we should be able to find 8 consecutive pages with reasonable effort. Signed-off-by: Christoph Lameter --- mm/slub.c | 47 +++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) Index: linux-2.6.23-rc8-mm2/mm/slub.c =================================================================== --- linux-2.6.23-rc8-mm2.orig/mm/slub.c 2007-10-02 17:04:40.000000000 -0700 +++ linux-2.6.23-rc8-mm2/mm/slub.c 2007-10-02 17:05:57.000000000 -0700 @@ -148,25 +148,6 @@ static inline void ClearSlabDebug(struct /* Enable to test recovery from slab corruption on boot */ #undef SLUB_RESILIENCY_TEST -#if PAGE_SHIFT <= 12 - -/* - * Small page size. Make sure that we do not fragment memory - */ -#define DEFAULT_MAX_ORDER 1 -#define DEFAULT_MIN_OBJECTS 4 - -#else - -/* - * Large page machines are customarily able to handle larger - * page orders. - */ -#define DEFAULT_MAX_ORDER 2 -#define DEFAULT_MIN_OBJECTS 8 - -#endif - /* * If antifragmentation methods are in effect then increase the * slab sizes to increase performance @@ -1738,8 +1719,8 @@ static int user_override; * take the list_lock. */ static int slub_min_order; -static int slub_max_order = DEFAULT_MAX_ORDER; -static int slub_min_objects = DEFAULT_MIN_OBJECTS; +static int slub_max_order; +static int slub_min_objects = 4; /* * Merge control. If this is set then no merging of slab caches will occur. @@ -2700,6 +2681,16 @@ int kmem_cache_shrink(struct kmem_cache } EXPORT_SYMBOL(kmem_cache_shrink); +/* + * Table to autotune the maximum slab order based on the number of pages + * that the system has available. + */ +static unsigned long __initdata phys_pages_for_order[PAGE_ALLOC_COSTLY_ORDER] = { + 32768, /* >128M if using 4K pages, >512M (16k), >2G (64k) */ + 256000, /* >1G if using 4k pages, >4G (16k), >16G (64k) */ + 1000000 /* >4G if using 4k pages, >16G (16k), >64G (64k) */ +}; + /******************************************************************** * Basic setup of slabs *******************************************************************/ @@ -2711,13 +2702,13 @@ void __init kmem_cache_init(void) init_alloc_cpu(); - if (!page_group_by_mobility_disabled && !user_override) { - /* - * Antifrag support available. Increase usable - * page order and generate slabs with more objects. - */ - slub_max_order = DEFAULT_ANTIFRAG_MAX_ORDER; - slub_min_objects = DEFAULT_ANTIFRAG_MIN_OBJECTS; + if (!user_override) { + /* No manual parameters. Autotune for system */ + for (i = 0; i < PAGE_ALLOC_COSTLY_ORDER; i++) + if (num_physpages > phys_pages_for_order[i]) { + slub_max_order++; + slub_min_objects <<= 1; + } } #ifdef CONFIG_NUMA