shrink_slab(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… shrink_slab β€” bestie edition

ok so this is a page from the Kernel API Manual, and we're talking about shrink_slab β€” a lil kernel function with main character energy that shrinks slab caches. yes. that's the whole vibe. let's get into it πŸŽ€

✨ NAME ✨

shrink_slab β€” shrink slab caches. that's it. that's the function. it makes the slab caches smaller and honestly it ate πŸ’…


🌸 SYNOPSIS 🌸

unsigned long shrink_slab (gfp_t gfp_mask , int nid , struct mem_cgroup
*memcg , int priority );

look at her. four arguments, returns an unsigned long. iconic behavior fr fr ✨


πŸ¦‹ ARGUMENTS πŸ¦‹

  • gfp_mask β€” the allocation context. yep, that's the whole description, it's giving minimal and mysterious πŸ™ˆ
  • nid β€” the node whose slab caches we're targeting. very "I know a guy" energy.
  • memcg β€” the memory cgroup whose slab caches we're targeting. sister argument to nid, we love a matched set πŸ’–
  • priority β€” the reclaim priority. lowkey the moment of truth, more on that below πŸ‘‘

πŸ”₯ DESCRIPTION πŸ”₯

So what does she actually do? She calls the shrink functions to age shrinkable caches. that's the job. that's the assignment. aging caches like they're fine wine πŸ“

Now the details, bestie, don't skip:

nid gets passed along to shrinkers that have SHRINKER_NUMA_AWARE set. the unaware shrinkers β€” bless them β€” will receive a node id of 0 instead. no cap, that's literally just how it works.

memcg specifies the memory cgroup to target. and here's the thing: the unaware shrinkers are called only if it is the root cgroup. so if you're not at root, those unaware shrinkers are simply not invited to the function. sorry bestie 🫢

priority is sc->priority β€” and this part is so clever. we take the number of objects and >> by priority in order to get the scan target. shift it right, that's the whole trick. the way that priority just slides the numbers down 😭✨

and the return value? the number of reclaimed slab objects. that's your receipt. keep it.

⚠️ tiny heads-up: everything above is exactly what the page says β€” I'm not adding lore, that's all of it πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

  • Kernel file ./mm/shrinker.c β€” go read the source, bestie, it's right there πŸ”₯

ok that's the whole page and honestly it was short but she made her point 🌈 stay shiny, keep your caches aged, and remember: unaware shrinkers get node id 0 and they get called only at the root cgroup. periodt. πŸ’œ

β€” this has been the ./mm corner of the world, dated October 2026, brought to you by the shrink_slab(9) entry itself πŸŽ€βœ¨

πŸ“¦ where this page comes from