lib/rhashtable.c
Source file repositories/reference/linux-study-clean/lib/rhashtable.c
File Facts
- System
- Linux kernel
- Corpus path
lib/rhashtable.c- Extension
.c- Size
- 36281 bytes
- Lines
- 1407
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/atomic.hlinux/kernel.hlinux/init.hlinux/log2.hlinux/sched.hlinux/rculist.hlinux/slab.hlinux/vmalloc.hlinux/mm.hlinux/jhash.hlinux/random.hlinux/rhashtable.hlinux/err.hlinux/export.h
Detected Declarations
function head_hashfnfunction lockdep_rht_mutex_is_heldfunction lockdep_rht_bucket_is_heldfunction nested_table_freefunction nested_bucket_table_freefunction bucket_table_freefunction bucket_table_free_atomicfunction bucket_table_free_rcufunction rhashtable_rehash_onefunction rht_for_each_fromfunction rhashtable_rehash_chainfunction rhashtable_rehash_attachfunction rhashtable_rehash_tablefunction rhashtable_rehash_allocfunction rhashtable_shrinkfunction rht_deferred_workerfunction schedule_workfunction rhashtable_insert_rehashfunction rht_for_each_rcufunction ERR_PTRfunction rhashtable_walk_enterfunction rhashtable_walk_exitfunction rhashtable_walk_start_checkfunction rht_for_each_rcufunction rht_for_each_rcufunction rht_for_each_rcufunction rhashtable_walk_stopfunction rounded_hashtable_sizefunction rhashtable_jhash2function __rhashtable_init_noproffunction __rhltable_init_noproffunction rhashtable_free_onefunction cancel_work_syncfunction rhashtable_destroyexport lockdep_rht_mutex_is_heldexport lockdep_rht_bucket_is_heldexport rhashtable_insert_slowexport rhashtable_next_keyexport rhashtable_walk_enterexport rhashtable_walk_exitexport rhashtable_walk_start_checkexport rhashtable_walk_nextexport rhashtable_walk_peekexport rhashtable_walk_stopexport __rhashtable_init_noprofexport __rhltable_init_noprofexport rhashtable_free_and_destroyexport rhashtable_destroy
Annotated Snippet
rhashtable_compare(&arg, rht_obj(ht, head)))) {
pprev = &head->next;
continue;
}
if (!ht->rhlist)
return rht_obj(ht, head);
list = container_of(obj, struct rhlist_head, rhead);
plist = container_of(head, struct rhlist_head, rhead);
RCU_INIT_POINTER(list->next, plist);
head = rht_dereference_bucket(head->next, tbl, hash);
RCU_INIT_POINTER(list->rhead.next, head);
if (pprev)
rcu_assign_pointer(*pprev, obj);
else
/* Need to preserve the bit lock */
rht_assign_locked(bkt, obj);
return NULL;
}
if (elasticity <= 0 && !ht->p.insecure_elasticity)
return ERR_PTR(-EAGAIN);
return ERR_PTR(-ENOENT);
}
static struct bucket_table *rhashtable_insert_one(
struct rhashtable *ht, struct rhash_lock_head __rcu **bkt,
struct bucket_table *tbl, unsigned int hash, struct rhash_head *obj,
void *data)
{
struct bucket_table *new_tbl;
struct rhash_head *head;
if (!IS_ERR_OR_NULL(data))
return ERR_PTR(-EEXIST);
if (PTR_ERR(data) != -EAGAIN && PTR_ERR(data) != -ENOENT)
return ERR_CAST(data);
new_tbl = rht_dereference_rcu(tbl->future_tbl, ht);
if (new_tbl)
return new_tbl;
if (PTR_ERR(data) != -ENOENT)
return ERR_CAST(data);
if (unlikely(rht_grow_above_max(ht, tbl)))
return ERR_PTR(-E2BIG);
if (unlikely(rht_grow_above_100(ht, tbl)) &&
!ht->p.insecure_elasticity)
return ERR_PTR(-EAGAIN);
head = rht_ptr(bkt, tbl, hash);
RCU_INIT_POINTER(obj->next, head);
if (ht->rhlist) {
struct rhlist_head *list;
list = container_of(obj, struct rhlist_head, rhead);
RCU_INIT_POINTER(list->next, NULL);
}
/* bkt is always the head of the list, so it holds
* the lock, which we need to preserve
*/
rht_assign_locked(bkt, obj);
return NULL;
}
static void *rhashtable_try_insert(struct rhashtable *ht, const void *key,
struct rhash_head *obj)
{
struct bucket_table *new_tbl;
struct bucket_table *tbl;
struct rhash_lock_head __rcu **bkt;
unsigned long flags;
unsigned int hash;
void *data;
new_tbl = rcu_dereference(ht->tbl);
do {
tbl = new_tbl;
hash = rht_head_hashfn(ht, tbl, obj, ht->p);
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/kernel.h`, `linux/init.h`, `linux/log2.h`, `linux/sched.h`, `linux/rculist.h`, `linux/slab.h`, `linux/vmalloc.h`.
- Detected declarations: `function head_hashfn`, `function lockdep_rht_mutex_is_held`, `function lockdep_rht_bucket_is_held`, `function nested_table_free`, `function nested_bucket_table_free`, `function bucket_table_free`, `function bucket_table_free_atomic`, `function bucket_table_free_rcu`, `function rhashtable_rehash_one`, `function rht_for_each_from`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.