Subject: Slab defrag: Sort slab list and establish maximum objects for defrag slabs When we defragmenting slabs then it is advantageous to have them all together. So put defragmentable slabs first. Having the maximum number of objects in defragmentable slabs allows the allocation of arrays holding refs to these objects later. Signed-off-by: Christoph Lameter --- mm/slub.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) Index: linux-2.6/mm/slub.c =================================================================== --- linux-2.6.orig/mm/slub.c 2007-07-29 15:31:11.000000000 -0700 +++ linux-2.6/mm/slub.c 2007-07-29 15:38:16.000000000 -0700 @@ -235,6 +235,9 @@ static enum { static DECLARE_RWSEM(slub_lock); static LIST_HEAD(slab_caches); +/* Maximum objects in defragmentable slabs */ +static unsigned int max_defrag_slab_objects = 0; + /* * Tracking user of a slab. */ @@ -2267,7 +2270,7 @@ static struct kmem_cache *create_kmalloc flags, NULL)) goto panic; - list_add(&s->list, &slab_caches); + list_add_tail(&s->list, &slab_caches); up_write(&slub_lock); if (sysfs_slab_add(s)) goto panic; @@ -2454,6 +2457,11 @@ void kmem_cache_setup_defrag(struct kmem BUG_ON(s->refcount > 1); /* Must not have aliases */ s->get = get; s->kick = kick; + down_write(&slub_lock); + list_move(&s->list, &slab_caches); + if (s->objects > max_defrag_slab_objects) + max_defrag_slab_objects = s->objects; + up_write(&slub_lock); } EXPORT_SYMBOL(kmem_cache_setup_defrag); @@ -2716,7 +2724,7 @@ struct kmem_cache *kmem_cache_create(con if (s) { if (kmem_cache_open(s, GFP_KERNEL, name, size, align, flags, ctor)) { - list_add(&s->list, &slab_caches); + list_add_tail(&s->list, &slab_caches); up_write(&slub_lock); if (sysfs_slab_add(s)) goto err;