assoc_array_gc(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… assoc_array_gc β€” Garbage collect an associative array πŸ’…

okay bestie, welcome to the Kernel API Manual entry for assoc_array_gc β€” yes it's a kernel function, yes it's in section 9, and yes we're gonna get through it together 🫢


✨ NAME ✨

assoc_array_gc β€” Collect garbage from an associative array, bestie. That's literally the whole job πŸ’–


🌸 SYNOPSIS 🌸

int assoc_array_gc (struct assoc_array *array , const struct
       assoc_array_ops *ops , bool (*iterator)(void *object, void
       *iterator_data) , void *iterator_data );

look at that signature. four whole parameters. she's thorough πŸ’…


πŸŽ€ ARGUMENTS πŸŽ€

  • array β€” the array you wanna clean, bestie. the glow-up target 🌈
  • ops β€” the operations to use. like, the instruction set for the whole operation ✨
  • iterator β€” a callback function that gets to pass judgement on each object. she's the judge, jury, and vibe checker πŸ‘‘
  • iterator_data β€” private data for the callback function. just for her, no one else πŸ™ˆ

πŸ¦‹ DESCRIPTION πŸ¦‹

So the whole point: this function collects garbage from an associative array and packs down the internal tree to save memory. it's giving spring cleaning πŸ§ΉπŸ’–

The iterator function is asked to pass judgement upon each object in the array. and this is the important part, so listen up:

  • if it returns false, the object is discarded (gone, bye πŸ‘‹)
  • if it returns true, the object is kept

and if it returns true, it must increment the object's usage count (or whatever it needs to do to retain it) before returning. like, no cap, do the bookkeeping first πŸ”₯

This function returns 0 if successful or -ENOMEM if out of memory. In the latter case, the array is not changed 🫢

⭐ the caller should lock against other modifications and must continue to hold the lock until assoc_array_apply_edit has been called. do not let go early, bestie 😭

Accesses to the tree may take place concurrently with this function, provided they hold the RCU read lock. so yeah, other readers can vibe alongside, as long as they've got that lock πŸ’œ


🌟 SEE ALSO 🌟

Kernel file ./lib/assoc_array.c β€” and the whole assoc_array friend group, honestly:

go read them, they all ate πŸ’…βœ¨


and that's the page, bestie πŸŽ€ this one lives in ./lib, October 2026 edition β€” so if you stan the kernel source era, this is your page. mwah πŸ’‹πŸŒˆ

πŸ“¦ where this page comes from