Slab defrag: Add defrag_ratio Add a defrag ratio and set it to 30% by default. Signed-off-by: Christoph Lameter --- include/linux/slub_def.h | 7 +++++++ mm/slub.c | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) Index: linux-2.6.23-rc1/include/linux/slub_def.h =================================================================== --- linux-2.6.23-rc1.orig/include/linux/slub_def.h 2007-07-29 00:33:20.000000000 -0700 +++ linux-2.6.23-rc1/include/linux/slub_def.h 2007-07-29 00:33:22.000000000 -0700 @@ -45,6 +45,13 @@ struct kmem_cache { const struct kmem_cache_ops *ops; int inuse; /* Offset to metadata */ int align; /* Alignment */ + int defrag_ratio; /* + * objects/possible objects limit. If we have + * less that the specified percentage of + * objects allocated then defrag passes + * will start to occur during reclaim. + */ + const char *name; /* Name (only for display!) */ struct list_head list; /* List of slab caches */ #ifdef CONFIG_SLUB_DEBUG Index: linux-2.6.23-rc1/mm/slub.c =================================================================== --- linux-2.6.23-rc1.orig/mm/slub.c 2007-07-29 00:33:16.000000000 -0700 +++ linux-2.6.23-rc1/mm/slub.c 2007-07-29 00:33:22.000000000 -0700 @@ -2091,6 +2091,7 @@ static int kmem_cache_open(struct kmem_c goto error; s->refcount = 1; + s->defrag_ratio = 30; #ifdef CONFIG_NUMA s->remote_node_defrag_ratio = 100; #endif @@ -3533,6 +3534,22 @@ static ssize_t free_calls_show(struct km } SLAB_ATTR_RO(free_calls); +static ssize_t defrag_ratio_show(struct kmem_cache *s, char *buf) +{ + return sprintf(buf, "%d\n", s->defrag_ratio); +} + +static ssize_t defrag_ratio_store(struct kmem_cache *s, + const char *buf, size_t length) +{ + int n = simple_strtoul(buf, NULL, 10); + + if (n < 100) + s->defrag_ratio = n; + return length; +} +SLAB_ATTR(defrag_ratio); + #ifdef CONFIG_NUMA static ssize_t remote_node_defrag_ratio_show(struct kmem_cache *s, char *buf) { @@ -3575,6 +3592,7 @@ static struct attribute * slab_attrs[] = &shrink_attr.attr, &alloc_calls_attr.attr, &free_calls_attr.attr, + &defrag_ratio_attr.attr, #ifdef CONFIG_ZONE_DMA &cache_dma_attr.attr, #endif