drivers/md/dm-vdo/indexer/radix-sort.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-vdo/indexer/radix-sort.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-vdo/indexer/radix-sort.c- Extension
.c- Size
- 9389 bytes
- Lines
- 330
- Domain
- Driver Families
- Bucket
- drivers/md
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
radix-sort.hlinux/limits.hlinux/types.hmemory-alloc.hstring-utils.h
Detected Declarations
struct histogramstruct taskstruct radix_sorterfunction comparefunction insert_keyfunction insertion_sortfunction push_taskfunction swap_keysfunction measure_binsfunction push_binsfunction uds_make_radix_sorterfunction uds_free_radix_sorterfunction uds_radix_sort
Annotated Snippet
struct histogram {
/* The number of non-empty bins */
u16 used;
/* The index (key byte) of the first non-empty bin */
u16 first;
/* The index (key byte) of the last non-empty bin */
u16 last;
/* The number of occurrences of each specific byte */
u32 size[256];
};
/*
* Sub-tasks are manually managed on a stack, both for performance and to put a logarithmic bound
* on the stack space needed.
*/
struct task {
/* Pointer to the first key to sort. */
sort_key_t *first_key;
/* Pointer to the last key to sort. */
sort_key_t *last_key;
/* The offset into the key at which to continue sorting. */
u16 offset;
/* The number of bytes remaining in the sort keys. */
u16 length;
};
struct radix_sorter {
unsigned int count;
struct histogram bins;
sort_key_t *pile[256];
struct task *end_of_stack;
struct task insertion_list[256];
struct task stack[];
};
/* Compare a segment of two fixed-length keys starting at an offset. */
static inline int compare(sort_key_t key1, sort_key_t key2, u16 offset, u16 length)
{
return memcmp(&key1[offset], &key2[offset], length);
}
/* Insert the next unsorted key into an array of sorted keys. */
static inline void insert_key(const struct task task, sort_key_t *next)
{
/* Pull the unsorted key out, freeing up the array slot. */
sort_key_t unsorted = *next;
/* Compare the key to the preceding sorted entries, shifting down ones that are larger. */
while ((--next >= task.first_key) &&
(compare(unsorted, next[0], task.offset, task.length) < 0))
next[1] = next[0];
/* Insert the key into the last slot that was cleared, sorting it. */
next[1] = unsorted;
}
/*
* Sort a range of key segments using an insertion sort. This simple sort is faster than the
* 256-way radix sort when the number of keys to sort is small.
*/
static inline void insertion_sort(const struct task task)
{
sort_key_t *next;
for (next = task.first_key + 1; next <= task.last_key; next++)
insert_key(task, next);
}
/* Push a sorting task onto a task stack. */
static inline void push_task(struct task **stack_pointer, sort_key_t *first_key,
u32 count, u16 offset, u16 length)
{
struct task *task = (*stack_pointer)++;
task->first_key = first_key;
task->last_key = &first_key[count - 1];
task->offset = offset;
task->length = length;
}
static inline void swap_keys(sort_key_t *a, sort_key_t *b)
{
sort_key_t c = *a;
*a = *b;
*b = c;
}
/*
* Count the number of times each byte value appears in the arrays of keys to sort at the current
* offset, keeping track of the number of non-empty bins, and the index of the first and last
Annotation
- Immediate include surface: `radix-sort.h`, `linux/limits.h`, `linux/types.h`, `memory-alloc.h`, `string-utils.h`.
- Detected declarations: `struct histogram`, `struct task`, `struct radix_sorter`, `function compare`, `function insert_key`, `function insertion_sort`, `function push_task`, `function swap_keys`, `function measure_bins`, `function push_bins`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: source implementation candidate.
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.