kmem_cache_shrink return value
Subsystems (3)
PATCH 1/1 kmem_cache_shrink return value
Currently kmem_cache_shrink returns 1 normally and 0 in the case all slabs were released. This is almost useless for normal use and in fact only one user actually checked it. This user (drivers/s390/ccwcache.c) shouldn't have used kmem_cache_shrink in the first place and does even cause an OOPS due to kmem_cache_destroy on a NUL-pointer if kmem_cache_shrink returned 0...
This patch instead makes kmem_cache_shrink return the number of pages released to help the VM doing balancing. The -rmap VM already uses this (it has this patch already included) and one of akpm's comments in the -aa split patches addresses the same issue.
drivers/s390/ccwcache.c +2 -0
@@ -291,9 +291,11 @@/* Shrink the caches, if available */ for ( cachind =0 ; cachind <CCW_NUMBER_CACHES ; cachind ++ ) {if ( ccw_cache[cachind] ) { +#if 0 /* this is useless and could cause an OOPS in the worst case */ if (kmem_cache_shrink (ccw_cache[cachind]) ==0 ) { ccw_cache[cachind] =NULL ; } +#endif kmem_cache_destroy (ccw_cache[cachind]); } }
fs/dcache.c +1 -2
@@ -568,8 +568,7 @@ count = dentry_stat.nr_unused / priority;prune_dcache (count); -kmem_cache_shrink (dentry_cache); -return 0 ; +return kmem_cache_shrink (dentry_cache); }#define NAME_ALLOC_LEN (len) ((len+16) & ~15)
fs/dquot.c +1 -2
@@ -413,8 +413,7 @@lock_kernel ();prune_dqcache (nr_free_dquots / (priority +1 ));unlock_kernel (); -kmem_cache_shrink (dquot_cachep); -return 0 ; +return kmem_cache_shrink (dquot_cachep); }/* NOTE: If you change this function please check whether dqput_blocks() works right... */
fs/inode.c +1 -2
@@ -725,8 +725,7 @@ count = inodes_stat.nr_unused / priority;prune_icache (count); -kmem_cache_shrink (inode_cachep); -return 0 ; +return kmem_cache_shrink (inode_cachep); }/*
mm/slab.c +29 -9
@@ -909,14 +909,13 @@#define drain_cpu_caches (cachep) do { } while (0)#endif -static int __kmem_cache_shrink (kmem_cache_t *cachep) +/* +* Called with the &cachep->spinlock held, returns number of slabs released +*/ +static int __kmem_cache_shrink_locked (kmem_cache_t *cachep) {slab_t *slabp; -int ret; - -drain_cpu_caches (cachep); - -spin_lock_irq (&cachep->spinlock); +int ret =0 ;/* If the cache is growing, stop shrinking. */ while (!cachep->growing) {
@@ -935,9 +934,22 @@spin_unlock_irq (&cachep->spinlock);kmem_slab_destroy (cachep, slabp); + ret++;spin_lock_irq (&cachep->spinlock); } - ret = !list_empty (&cachep->slabs_full) || !list_empty (&cachep->slabs_partial); +return ret; +} + +static int __kmem_cache_shrink (kmem_cache_t *cachep) +{ +int ret; + +drain_cpu_caches (cachep); + +spin_lock_irq (&cachep->spinlock); +__kmem_cache_shrink_locked (cachep); + ret = !list_empty (&cachep->slabs_full) || + !list_empty (&cachep->slabs_partial);spin_unlock_irq (&cachep->spinlock);return ret; }
@@ -947,14 +959,22 @@* @cachep: The cache to shrink. * * Releases as many slabs as possible for a cache. -* To help debugging, a zero exit status indicates all slabs were released. +* Returns number of pages released. */ int kmem_cache_shrink (kmem_cache_t *cachep) { +int ret; +if (!cachep ||in_interrupt () || !is_chained_kmem_cache (cachep))BUG (); -return __kmem_cache_shrink (cachep); +drain_cpu_caches (cachep); + +spin_lock_irq (&cachep->spinlock); + ret =__kmem_cache_shrink_locked (cachep); +spin_unlock_irq (&cachep->spinlock); + +return ret << cachep->gfporder; }/**
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/