Re: [PATCH v6 25/29] memcg/sl[au]b: shrink dead caches

Christoph Lameter
2012-11-08T17:15:40Z

On Wed, 7 Nov 2012, Andrew Morton wrote:

> What's up with kmem_cache_shrink? It's global and exported to modules
> but its only external caller is some weird and hopelessly poorly
> documented site down in drivers/acpi/osl.c. slab and slob implement
> kmem_cache_shrink() *only* for acpi! wtf? Let's work out what acpi is
> trying to actually do there, then do it properly, then killkillkill!

kmem_cache_shrink is also used internally. Its simply releasing unused
cached objects.

> Secondly, as slab and slub (at least) have the ability to shed cached
> memory, why aren't they hooked into the core cache-shinking machinery.
> After all, it's called "shrink_slab"!

Because the core cache shrinking needs the slab caches to free up memory
from inodes and dentries. We could call kmem_cache_shrink at the end of
the shrink passes in vmscan. The price would be that the caches would have
to be repopulated when new allocations occur.
>
> If we can fix all that up then I wonder whether this particular patch
> needs to exist at all. If the kmem_cache is no longer used then we
> can simply leave it floating around in memory and the regular cache
> shrinking code out of shrink_slab() will clean up any remaining pages.
> The kmem_cache itself can be reclaimed via another shrinker, if
> necessary?

The kmem_cache can only be released if all its objects (used and unused)
are released. kmem_cache_shrink drops the unused objects on some internal
slab specific list. That may enable us to release the kmem_cache
structure.