include/linux/rhashtable.h
Source file repositories/reference/linux-study-clean/include/linux/rhashtable.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/rhashtable.h- Extension
.h- Size
- 40633 bytes
- Lines
- 1340
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/err.hlinux/errno.hlinux/irq_work.hlinux/jhash.hlinux/list_nulls.hlinux/workqueue.hlinux/rculist.hlinux/bit_spinlock.hlinux/rhashtable-types.h
Detected Declarations
struct rhash_lock_headstruct bucket_tableenum rht_lookup_freqfunction NULLS_MARKERfunction rht_bucket_indexfunction rht_key_get_hashfunction rht_key_hashfnfunction rht_head_hashfnfunction rht_grow_above_75function rht_shrink_below_30function rht_grow_above_100function rht_grow_above_maxfunction lockdep_rht_mutex_is_heldfunction lockdep_rht_bucket_is_heldfunction rhashtable_walk_startfunction BITfunction rht_lock_nestedfunction rht_unlockfunction rht_ptr_rcufunction rht_assign_lockedfunction rht_assign_unlockfunction rhashtable_comparefunction rht_for_each_rcu_fromfunction ERR_PTRfunction rht_for_each_fromfunction rhashtable_insert_fastfunction rhltable_insert_keyfunction rhltable_insertfunction tablefunction rhashtable_lookup_insert_fastfunction rhashtable_lookup_insert_keyfunction rhashtable_lookup_insert_keyfunction __rhashtable_remove_fast_onefunction rht_for_each_fromfunction __rhashtable_remove_fastfunction rhashtable_remove_fastfunction rhltable_removefunction __rhashtable_replace_fastfunction rht_for_each_fromfunction rhashtable_replace_fastfunction rhltable_walk_enterfunction rhltable_free_and_destroyfunction rhltable_destroy
Annotated Snippet
struct rhash_lock_head {};
/* Maximum chain length before rehash
*
* The maximum (not average) chain length grows with the size of the hash
* table, at a rate of (log N)/(log log N).
*
* The value of 16 is selected so that even if the hash table grew to
* 2^32 you would not expect the maximum chain length to exceed it
* unless we are under attack (or extremely unlucky).
*
* As this limit is only to detect attacks, we don't need to set it to a
* lower value as you'd need the chain length to vastly exceed 16 to have
* any real effect on the system.
*/
#define RHT_ELASTICITY 16u
/**
* struct bucket_table - Table of hash buckets
* @size: Number of hash buckets
* @nest: Number of bits of first-level nested table.
* @rehash: Current bucket being rehashed
* @hash_rnd: Random seed to fold into hash
* @walkers: List of active walkers
* @rcu: RCU structure for freeing the table
* @future_tbl: Table under construction during rehashing
* @ntbl: Nested table used when out of memory.
* @buckets: size * hash buckets
*/
struct bucket_table {
unsigned int size;
unsigned int nest;
u32 hash_rnd;
struct list_head walkers;
struct rcu_head rcu;
struct bucket_table __rcu *future_tbl;
struct lockdep_map dep_map;
struct rhash_lock_head __rcu *buckets[] ____cacheline_aligned_in_smp;
};
/*
* NULLS_MARKER() expects a hash value with the low
* bits mostly likely to be significant, and it discards
* the msb.
* We give it an address, in which the bottom bit is
* always 0, and the msb might be significant.
* So we shift the address down one bit to align with
* expectations and avoid losing a significant bit.
*
* We never store the NULLS_MARKER in the hash table
* itself as we need the lsb for locking.
* Instead we store a NULL
*/
#define RHT_NULLS_MARKER(ptr) \
((void *)NULLS_MARKER(((unsigned long) (ptr)) >> 1))
#define INIT_RHT_NULLS_HEAD(ptr) \
((ptr) = NULL)
static inline bool rht_is_a_nulls(const struct rhash_head *ptr)
{
return ((unsigned long) ptr & 1);
}
static inline void *rht_obj(const struct rhashtable *ht,
const struct rhash_head *he)
{
return (char *)he - ht->p.head_offset;
}
static inline unsigned int rht_bucket_index(const struct bucket_table *tbl,
unsigned int hash)
{
return hash & (tbl->size - 1);
}
static __always_inline unsigned int rht_key_get_hash(struct rhashtable *ht,
const void *key, const struct rhashtable_params params,
unsigned int hash_rnd)
{
unsigned int hash;
/* params must be equal to ht->p if it isn't constant. */
if (!__builtin_constant_p(params.key_len)) {
hash = ht->p.hashfn(key, ht->key_len, hash_rnd);
} else {
unsigned int key_len = params.key_len ? : ht->p.key_len;
Annotation
- Immediate include surface: `linux/err.h`, `linux/errno.h`, `linux/irq_work.h`, `linux/jhash.h`, `linux/list_nulls.h`, `linux/workqueue.h`, `linux/rculist.h`, `linux/bit_spinlock.h`.
- Detected declarations: `struct rhash_lock_head`, `struct bucket_table`, `enum rht_lookup_freq`, `function NULLS_MARKER`, `function rht_bucket_index`, `function rht_key_get_hash`, `function rht_key_hashfn`, `function rht_head_hashfn`, `function rht_grow_above_75`, `function rht_shrink_below_30`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source 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.