__swap_cache_add_check(9)
π __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 bynr. 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. passNULLif 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 β¨
0if 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:
swap_cache_get_folio(9)swap_cache_has_folio(9)swap_cache_get_shadow(9)__swap_cache_add_folio(9)__swap_cache_del_folio(9)swap_cache_del_folio(9)__swap_cache_replace_folio(9)swap_cache_alloc_folio(9)swap_update_readahead(9)swapin_sync(9)swap_cluster_readahead(9)swap_vma_readahead(9)swapin_readahead(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms