drivers/md/dm-vdo/priority-table.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-vdo/priority-table.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-vdo/priority-table.c- Extension
.c- Size
- 6565 bytes
- Lines
- 224
- 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
priority-table.hlinux/log2.herrors.hmemory-alloc.hpermassert.hstatus-codes.h
Detected Declarations
struct bucketstruct priority_tablefunction vdo_make_priority_tablefunction vdo_free_priority_tablefunction vdo_reset_priority_tablefunction vdo_priority_table_enqueuefunction mark_bucket_emptyfunction vdo_priority_table_dequeuefunction vdo_priority_table_removefunction vdo_is_priority_table_empty
Annotated Snippet
struct bucket {
/*
* The head of a queue of table entries, all having the same priority
*/
struct list_head queue;
/* The priority of all the entries in this bucket */
unsigned int priority;
};
/*
* A priority table is an array of buckets, indexed by priority. New entries are added to the end
* of the queue in the appropriate bucket. The dequeue operation finds the highest-priority
* non-empty bucket by searching a bit vector represented as a single 8-byte word, which is very
* fast with compiler and CPU support.
*/
struct priority_table {
/* The maximum priority of entries that may be stored in this table */
unsigned int max_priority;
/* A bit vector flagging all buckets that are currently non-empty */
u64 search_vector;
/* The array of all buckets, indexed by priority */
struct bucket buckets[];
};
/**
* vdo_make_priority_table() - Allocate and initialize a new priority_table.
* @max_priority: The maximum priority value for table entries.
* @table_ptr: A pointer to hold the new table.
*
* Return: VDO_SUCCESS or an error code.
*/
int vdo_make_priority_table(unsigned int max_priority, struct priority_table **table_ptr)
{
struct priority_table *table;
int result;
unsigned int priority;
if (max_priority > MAX_PRIORITY)
return UDS_INVALID_ARGUMENT;
result = vdo_allocate_extended(max_priority + 1, buckets, __func__, &table);
if (result != VDO_SUCCESS)
return result;
for (priority = 0; priority <= max_priority; priority++) {
struct bucket *bucket = &table->buckets[priority];
bucket->priority = priority;
INIT_LIST_HEAD(&bucket->queue);
}
table->max_priority = max_priority;
table->search_vector = 0;
*table_ptr = table;
return VDO_SUCCESS;
}
/**
* vdo_free_priority_table() - Free a priority_table.
* @table: The table to free.
*
* The table does not own the entries stored in it and they are not freed by this call.
*/
void vdo_free_priority_table(struct priority_table *table)
{
if (table == NULL)
return;
/*
* Unlink the buckets from any entries still in the table so the entries won't be left with
* dangling pointers to freed memory.
*/
vdo_reset_priority_table(table);
vdo_free(table);
}
/**
* vdo_reset_priority_table() - Reset a priority table, leaving it in the same empty state as when
* newly constructed.
* @table: The table to reset.
*
* The table does not own the entries stored in it and they are not freed (or even unlinked from
* each other) by this call.
*/
void vdo_reset_priority_table(struct priority_table *table)
{
unsigned int priority;
Annotation
- Immediate include surface: `priority-table.h`, `linux/log2.h`, `errors.h`, `memory-alloc.h`, `permassert.h`, `status-codes.h`.
- Detected declarations: `struct bucket`, `struct priority_table`, `function vdo_make_priority_table`, `function vdo_free_priority_table`, `function vdo_reset_priority_table`, `function vdo_priority_table_enqueue`, `function mark_bucket_empty`, `function vdo_priority_table_dequeue`, `function vdo_priority_table_remove`, `function vdo_is_priority_table_empty`.
- 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.