From 15ea9ffa191781a4c10f5c52037b036ee53c1101 Mon Sep 17 00:00:00 2001
From: Christoph Lameter <clameter@sgi.com>
Date: Fri, 15 Feb 2008 15:22:22 -0800
Subject: [PATCH] slub: Adjust order boundaries and minimum objects per slab.

Since there is now no worry anymore about higher order allocs (hopefully).
Set the max order to default to PAGE_ALLOC_ORDER_COSTLY (32k) and require
slub to use a higher order if a certain object density cannot be reached.

The mininum objects per slab is calculated based on the number of processors
that may come online.

Processors	min_objects
---------------------------
1		4
2		8
4		12
8		16
16		20
32		24
64		28
1024		44
4096		52

V1->V2
- Add logic to compute min_objects based on processor count.

Signed-off-by: Christoph Lameter <clameter@sgi.com>
---
 mm/slub.c |   29 +++++++----------------------
 1 file changed, 7 insertions(+), 22 deletions(-)

Index: linux-2.6/mm/slub.c
===================================================================
--- linux-2.6.orig/mm/slub.c	2008-03-17 15:33:42.118699647 -0700
+++ linux-2.6/mm/slub.c	2008-03-17 15:49:57.459504642 -0700
@@ -5,7 +5,7 @@
  * The allocator synchronizes using per slab locks and only
  * uses a centralized lock to manage a pool of partial slabs.
  *
- * (C) 2007 SGI, Christoph Lameter <clameter@sgi.com>
+ * (C) 2007, 2008 SGI, Christoph Lameter <clameter@sgi.com>
  */
 
 #include <linux/mm.h>
@@ -149,24 +149,7 @@ 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
+#define DEFAULT_MAX_ORDER PAGE_ALLOC_COSTLY_ORDER
 
 /*
  * Mininum number of partial slabs. These will be left on the partial
@@ -1768,7 +1751,7 @@ static struct page *get_object_page(cons
  */
 static int slub_min_order;
 static int slub_max_order = DEFAULT_MAX_ORDER;
-static int slub_min_objects = DEFAULT_MIN_OBJECTS;
+static int slub_min_objects = -1;
 
 /*
  * Merge control. If this is set then no merging of slab caches will occur.
@@ -1845,9 +1828,11 @@ static inline int calculate_order(int si
 	 * we reduce the minimum objects required in a slab.
 	 */
 	min_objects = slub_min_objects;
+	if (min_objects <= 0)
+		min_objects = 4 * (fls(nr_cpu_ids) + 1);
 	while (min_objects > 1) {
-		fraction = 8;
-		while (fraction >= 4) {
+		fraction = 16;
+		while (fraction >= 8) {
 			order = slab_order(size, min_objects,
 						slub_max_order, fraction);
 			if (order <= slub_max_order)
