include/linux/sbitmap.h
Source file repositories/reference/linux-study-clean/include/linux/sbitmap.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/sbitmap.h- Extension
.h- Size
- 17463 bytes
- Lines
- 630
- 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/atomic.hlinux/bitops.hlinux/cache.hlinux/list.hlinux/log2.hlinux/minmax.hlinux/percpu.hlinux/slab.hlinux/smp.hlinux/types.hlinux/wait.h
Detected Declarations
struct seq_filestruct sbitmap_wordstruct sbitmapstruct sbq_wait_statestruct sbitmap_queuestruct sbq_waitfunction __map_depthfunction sbitmap_freefunction __sbitmap_for_each_setfunction sbitmap_for_each_setfunction sbitmap_set_bitfunction sbitmap_clear_bitfunction sbitmap_deferred_clearfunction sbitmap_putfunction sbitmap_test_bitfunction sbitmap_calculate_shiftfunction sbitmap_queue_freefunction sbitmap_queue_clearfunction sbq_index_incfunction sbq_index_atomic_incfunction sbq_wait_ptr
Annotated Snippet
struct sbitmap_word {
/**
* @word: word holding free bits
*/
unsigned long word;
/**
* @cleared: word holding cleared bits
*/
unsigned long cleared ____cacheline_aligned_in_smp;
/**
* @swap_lock: serializes simultaneous updates of ->word and ->cleared
*/
raw_spinlock_t swap_lock;
} ____cacheline_aligned_in_smp;
/**
* struct sbitmap - Scalable bitmap.
*
* A &struct sbitmap is spread over multiple cachelines to avoid ping-pong. This
* trades off higher memory usage for better scalability.
*/
struct sbitmap {
/**
* @depth: Number of bits used in the whole bitmap.
*/
unsigned int depth;
/**
* @shift: log2(number of bits used per word)
*/
unsigned int shift;
/**
* @map_nr: Number of words (cachelines) being used for the bitmap.
*/
unsigned int map_nr;
/**
* @round_robin: Allocate bits in strict round-robin order.
*/
bool round_robin;
/**
* @map: Allocated bitmap.
*/
struct sbitmap_word *map;
/**
* @alloc_hint: Cache of last successfully allocated or freed bit.
*
* This is per-cpu, which allows multiple users to stick to different
* cachelines until the map is exhausted.
*/
unsigned int __percpu *alloc_hint;
};
#define SBQ_WAIT_QUEUES 8
#define SBQ_WAKE_BATCH 8
/**
* struct sbq_wait_state - Wait queue in a &struct sbitmap_queue.
*/
struct sbq_wait_state {
/**
* @wait: Wait queue.
*/
wait_queue_head_t wait;
} ____cacheline_aligned_in_smp;
/**
* struct sbitmap_queue - Scalable bitmap with the added ability to wait on free
* bits.
*
* A &struct sbitmap_queue uses multiple wait queues and rolling wakeups to
* avoid contention on the wait queue spinlock. This ensures that we don't hit a
* scalability wall when we run out of free bits and have to start putting tasks
* to sleep.
*/
struct sbitmap_queue {
/**
* @sb: Scalable bitmap.
*/
struct sbitmap sb;
/**
* @wake_batch: Number of bits which must be freed before we wake up any
* waiters.
*/
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/bitops.h`, `linux/cache.h`, `linux/list.h`, `linux/log2.h`, `linux/minmax.h`, `linux/percpu.h`, `linux/slab.h`.
- Detected declarations: `struct seq_file`, `struct sbitmap_word`, `struct sbitmap`, `struct sbq_wait_state`, `struct sbitmap_queue`, `struct sbq_wait`, `function __map_depth`, `function sbitmap_free`, `function __sbitmap_for_each_set`, `function sbitmap_for_each_set`.
- 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.