diff options
author | Brian Behlendorf <[email protected]> | 2011-03-30 17:44:35 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2011-04-06 20:06:03 -0700 |
commit | e76f4bf11d54479fe767d9647a10e8b98d7ffc4f (patch) | |
tree | 213970e408e6c9b808184abd7fb7e3920cee0c52 /include | |
parent | 83150861e610701d44510816e2062bcf407f51ab (diff) |
Add dnlc_reduce_cache() support
Provide the dnlc_reduce_cache() function which attempts to prune
cached entries from the dcache and icache. After the entries are
pruned any slabs which they may have been using are reaped.
Note the API takes a reclaim percentage but we don't have easy
access to the total number of cache entries to calculate the
reclaim count. However, in practice this doesn't need to be
exactly correct. We simply need to reclaim some useful fraction
(but not all) of the cache. The caller can determine if more
needs to be done.
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/mm_compat.h | 36 | ||||
-rw-r--r-- | include/sys/dnlc.h | 18 |
2 files changed, 53 insertions, 1 deletions
diff --git a/include/linux/mm_compat.h b/include/linux/mm_compat.h index 7e2f6b8a5..522db827f 100644 --- a/include/linux/mm_compat.h +++ b/include/linux/mm_compat.h @@ -56,6 +56,42 @@ extern invalidate_inodes_t invalidate_inodes_fn; #define invalidate_inodes(sb) invalidate_inodes_fn(sb) #endif /* HAVE_INVALIDATE_INODES */ +/* + * 2.6.xx API compat, + * There currently exists no exposed API to partially shrink the dcache. + * The expected mechanism to shrink the cache is a registered shrinker + * which is called during memory pressure. + */ +#ifndef HAVE_SHRINK_DCACHE_MEMORY +# ifdef HAVE_3ARGS_SHRINKER_CALLBACK +typedef int (*shrink_dcache_memory_t)(struct shrinker *, int, gfp_t); +extern shrink_dcache_memory_t shrink_dcache_memory_fn; +# define shrink_dcache_memory(nr, gfp) shrink_dcache_memory_fn(NULL, nr, gfp) +# else +typedef int (*shrink_dcache_memory_t)(int, gfp_t); +extern shrink_dcache_memory_t shrink_dcache_memory_fn; +# define shrink_dcache_memory(nr, gfp) shrink_dcache_memory_fn(nr, gfp) +# endif /* HAVE_3ARGS_SHRINKER_CALLBACK */ +#endif /* HAVE_SHRINK_DCACHE_MEMORY */ + +/* + * 2.6.xx API compat, + * There currently exists no exposed API to partially shrink the icache. + * The expected mechanism to shrink the cache is a registered shrinker + * which is called during memory pressure. + */ +#ifndef HAVE_SHRINK_ICACHE_MEMORY +# ifdef HAVE_3ARGS_SHRINKER_CALLBACK +typedef int (*shrink_icache_memory_t)(struct shrinker *, int, gfp_t); +extern shrink_icache_memory_t shrink_icache_memory_fn; +# define shrink_icache_memory(nr, gfp) shrink_icache_memory_fn(NULL, nr, gfp) +# else +typedef int (*shrink_icache_memory_t)(int, gfp_t); +extern shrink_icache_memory_t shrink_icache_memory_fn; +# define shrink_icache_memory(nr, gfp) shrink_icache_memory_fn(nr, gfp) +# endif /* HAVE_3ARGS_SHRINKER_CALLBACK */ +#endif /* HAVE_SHRINK_ICACHE_MEMORY */ + #ifdef HAVE_SET_SHRINKER typedef struct spl_shrinker { struct shrinker *shrinker; diff --git a/include/sys/dnlc.h b/include/sys/dnlc.h index 693e3d294..b63c94fef 100644 --- a/include/sys/dnlc.h +++ b/include/sys/dnlc.h @@ -25,6 +25,22 @@ #ifndef _SPL_DNLC_H #define _SPL_DNLC_H -#define dnlc_reduce_cache(percent) ((void)0) +/* + * Reduce the dcache and icache then reap the free'd slabs. Note the + * interface takes a reclaim percentage but we don't have easy access to + * the total number of entries to calculate the reclaim count. However, + * in practice this doesn't need to be even close to correct. We simply + * need to reclaim some useful fraction of the cache. The caller can + * determine if more needs to be done. + */ +static inline void +dnlc_reduce_cache(void *reduce_percent) +{ + int nr = (uintptr_t)reduce_percent * 10000; + + shrink_dcache_memory(nr, GFP_KERNEL); + shrink_icache_memory(nr, GFP_KERNEL); + kmem_reap(); +} #endif /* SPL_DNLC_H */ |