rhashtable_next_key(9)
π rhashtable_next_key(9) β the Kernel API Manual, bestie edition π
okay so you found the rhashtable_next_key(9) page in the Kernel API Manual and you're like "what is this" β don't worry, I got you, we're gonna read it together and it's gonna slay β¨
πΈ NAME πΈ
rhashtable_next_key β returns the next element after a given key, literally that's the whole vibe π¦
β¨ SYNOPSIS β¨
void * rhashtable_next_key (struct rhashtable *ht , const void *prev_key );
like, that's it. that's the signature. iconic π
π«Ά ARGUMENTS π«Ά
htβ the hash table. the main character, the table in question πprev_keyβ pointer to the previous key, orNULLfor the first element. so if you're passingNULL, you're basically saying "start me from the top bestie" π
π₯ DESCRIPTION π₯
β οΈ WARNING: this walk is highly unstable. like, unhinged levels of unstable, no cap. Unlike rhashtable_walk_*(), it cannot detect a concurrent resize or rehash, so a full iteration is NOT guaranteed to terminate under adversarial or sustained rehashing. You, the caller, MUST tolerate skipped and duplicated elements and SHOULD bound your loop externally. this is not a drill, fr fr π
so what does it actually do? it returns the next element in best-effort iteration order, walking the tbl chain (including any future_tbl in flight). caller must hold RCU. that part is non-negotiable, bestie π«‘
Pass prev_key == NULL to obtain the first element. To iterate, set prev_key to the key of the previously returned element on each call, and stop when NULL is returned. cute, simple loop energy πΈ
π Best-effort semantics π
this is the part where you sit down and pay attention, because the vibes are best-effort and bestie, best-effort is a whole personality:
- Across the
tbl->future_tblchain, an element being migrated may transiently appear in both tables and be observed twice. yes, twice. it's giving "she's in her migration era" π - Concurrent inserts may or may not be observed. literally may. or may not. no promises were made π¦
- Termination of a full iteration loop is NOT guaranteed under adversarial continuous rehash; callers MUST tolerate skips and repeats and SHOULD bound their loop externally. read that again. bound your loop. do it for me π
- Behavior on tables that contain duplicate keys is undefined: duplicates may be skipped, repeated, or trap the walk in a cycle. the way your walk could just... get stuck in a cycle forever π callers requiring duplicate-key iteration must use
rhashtable_walk_*()instead. that's the supported path, periodt π rhltableinstances are not supported and returnERR_PTR(-EOPNOTSUPP). not supported, not invited, not on the list π ββοΈ- If
prev_keywas concurrently deleted and is not present in any in-flight table, returnsERR_PTR(-ENOENT). she's gone, bestie, she left the chat π¨
so the return value situation is: entry of the next element, or NULL when iteration is exhausted, or ERR_PTR(-ENOENT) if prev_key is not found, or ERR_PTR(-EOPNOTSUPP) if ht is an rhltable. three error-ish outcomes, one success, and a partridge in a pear tree π
π SEE ALSO π
Kernel file ./lib/rhashtable.c and honestly the whole walk squad β go read these, they're the friend group:
rhashtable_shrink(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)rhashtable_free_and_destroy(9)
and that's the page, bestie π this little baby lives at ./lib, dated October 2026, and it's filed under rhashtable_next_key(9) β go forth, hold RCU, bound your loops, and don't say I didn't warn you πβ¨
π¦ 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