rhashtable_free_and_destroy(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ rhashtable_free_and_destroy ✨

Okay bestie, welcome to the Kernel API Manual β€” this one's the cleanup queen of the rhashtable world: rhashtable_free_and_destroy, aka "free elements and destroy hash table" πŸ’…


🌸 SYNOPSIS 🌸

void rhashtable_free_and_destroy (struct rhashtable *ht , void
(*free_fn)(void *ptr, void *arg) , void *arg );

πŸŽ€ ARGUMENTS πŸŽ€

  • ht β€” the hash table you're about to destroy, no cap. This is the main character of the operation 🫢
  • free_fn β€” callback whose whole job is releasing the resources of an element ✨
  • arg β€” the pointer that gets passed on through to free_fn, iykyk πŸ¦‹

πŸ’– DESCRIPTION πŸ’–

So here's the vibe: this function stops an eventual async resize. Then, if free_fn is defined, it invokes free_fn for every single element so their resources get released. 🧚

⚠️ Heads up bestie, this part is literally so important: RCU protected readers may still be accessing the elements. So the releasing of resources has to happen in a compatible manner. Don't just yolo it 😭

After all that, it frees the bucket array. Slay.

Alsooo, this function will eventually sleep to wait for an async resize to complete 😴 β€” and the caller is responsible for making sure no further write operations occur in parallel. That's on you, not on the function, fr fr.

Once cancel_work_sync has returned, the deferred rehash worker is quiesced and β€” per the contract above β€” no other concurrent access to the rhashtable is possible. So the tables are owned exclusively by this function and can be walked without ht->mutex held. Iconic behavior honestly πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹

Kernel file ./lib/rhashtable.c, plus the whole walk-and-shrink friend group πŸ’œ


Alright bestie, that's the whole page πŸ“ β€” brought to you by ./lib, dated October 2026, and filed under rhashtable_free_and_destroy(9). Go free those elements responsibly πŸ’–βœ¨

πŸ“¦ where this page comes from