Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Return SHRINK_STOP from shrinker when caches is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Yao <[email protected]>
  • Loading branch information
ryao committed Nov 3, 2014
1 parent 340b095 commit 1bf0a7a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions module/spl/spl-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,10 @@ __spl_kmem_cache_generic_shrinker(struct shrinker *shrink,
struct shrink_control *sc)
{
spl_kmem_cache_t *skc;
int alloc = 0;
int freeable = 0;
#ifdef HAVE_SPLIT_SHRINKER_CALLBACK
int freed = 0;
#endif

down_read(&spl_kmem_cache_sem);
list_for_each_entry(skc, &spl_kmem_cache_list, skc_list) {
Expand All @@ -2042,15 +2045,15 @@ __spl_kmem_cache_generic_shrinker(struct shrinker *shrink,
spl_kmem_cache_reap_now(skc,
MAX(sc->nr_to_scan >> fls64(skc->skc_slab_objs), 1));
if (oldalloc > skc->skc_obj_alloc)
alloc += oldalloc - skc->skc_obj_alloc;
freed += oldalloc - skc->skc_obj_alloc;
#else
spl_kmem_cache_reap_now(skc,
MAX(sc->nr_to_scan >> fls64(skc->skc_slab_objs), 1));
alloc += skc->skc_obj_alloc;
#endif /* HAVE_SPLIT_SHRINKER_CALLBACK */
freeable += skc->skc_obj_alloc;
} else {
/* Request to query number of freeable objects */
alloc += skc->skc_obj_alloc;
freeable += skc->skc_obj_alloc;
}
}
up_read(&spl_kmem_cache_sem);
Expand All @@ -2064,7 +2067,11 @@ __spl_kmem_cache_generic_shrinker(struct shrinker *shrink,
if ((spl_kmem_cache_reclaim & KMC_RECLAIM_ONCE) && sc->nr_to_scan)
return (SHRINK_STOP);

return (MAX(alloc, 0));
#ifdef HAVE_SPLIT_SHRINKER_CALLBACK
return ((freeable) ? freed : SHRINK_STOP);
#else
return (freeable);
#endif
}

SPL_SHRINKER_CALLBACK_WRAPPER(spl_kmem_cache_generic_shrinker);
Expand Down

0 comments on commit 1bf0a7a

Please sign in to comment.