__swap_cache_add_check(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… __swap_cache_add_check β€” the kernel API manual, but make it make sense

okay so bestie, we're in __swap_cache_add_check(9) territory today and honestly? it's giving "quiet little helper function that does a LOT of checking." no cap. let's get into it 🫢


✨ NAME ✨

__swap_cache_add_check β€” literally just vibe-checks whether a range is even allowed to have a folio added to it. that's it. that's the whole job. πŸŽ€


✨ SYNOPSIS ✨

int __swap_cache_add_check (struct swap_cluster_info *ci , swp_entry_t
targ_entry , unsigned long nr , void **shadowp , unsigned short
*memcg_id );

✨ ARGUMENTS ✨

here's the roster, bestie, and every single one of them matters πŸ’–

  • ci β€” the locked swap cluster. yes, locked. it says locked. do not come to this function with an unlocked cluster, that's not the vibe 😭
  • targ_entry β€” the target swap entry you want checked. heads up: it gets rounded down by nr. she snaps to the grid, periodt.
  • nr β€” how many slots we're checking. must be a power of 2. like, non-negotiable. powers of 2 only, that's the rule 🌸
  • shadowp β€” this one returns the shadow value if one exists in the range. so if there's a shadow lurking in there, you'll get it back here.
  • memcg_id β€” returns the memory cgroup id. pass NULL if you want to ignore the cgroup check entirely. your call, bestie ✨

✨ DESCRIPTION ✨

okay so here's what she actually does πŸ‘‘

she checks if all the slots covered by the given range have a swap count >= 1. all of them. every single one. no skipping, no "close enough," none of that πŸ™ˆ

while she's in there, she also retrieves the shadow if there is one. so that's two birds, one function call, we love efficiency πŸ’…

and if memcg_id is not NULL? she goes the extra mile and also checks whether all the slots belong to the same cgroup, and returns the cgroup private id. icon behavior, honestly πŸ”₯


✨ CONTEXT ✨

⚠️ real talk: the caller must lock the cluster. this is not optional. this is not a suggestion. lock the cluster before you call her or things get weird πŸ’€

✨ RETURN ✨

  • 0 if success β€” slay, you're good to go πŸŽ‰
  • error code if failed β€” something went wrong, read the code, you got this 😭

✨ SEE ALSO ✨

kernel file ./mm/swap_state.c plus the whole friend group:

go read them too, iykyk πŸ¦‹


mwah πŸ’œ that's the whole page, brought to you fresh out of ./mm, dated October 2026, and officially filed under __swap_cache_add_check(9). stay locked, stay checking, stay iconic πŸ‘‘βœ¨

πŸ“¦ where this page comes from