rhashtable_free_and_destroy(9)
β¨ 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 tofree_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 π
rhashtable_shrink(9)rhashtable_next_key(9)rhashtable_walk_enter(9)rhashtable_walk_exit(9)rhashtable_walk_start_check(9)__rhashtable_walk_find_next(9)rhashtable_walk_next(9)rhashtable_walk_peek(9)rhashtable_walk_stop(9)
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
- 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