drivers/md/dm-vdo/memory-alloc.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-vdo/memory-alloc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-vdo/memory-alloc.c- Extension
.c- Size
- 13654 bytes
- Lines
- 441
- 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.
- 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/delay.hlinux/mm.hlinux/sched/mm.hlinux/slab.hlinux/vmalloc.hlogger.hmemory-alloc.hpermassert.h
Detected Declarations
struct vmalloc_block_infofunction allocations_allowedfunction vdo_register_allocating_threadfunction vdo_unregister_allocating_threadfunction update_peak_usagefunction add_kmalloc_blockfunction remove_kmalloc_blockfunction add_vmalloc_blockfunction remove_vmalloc_blockfunction use_kmallocfunction vdo_allocate_memoryfunction vdo_freefunction vdo_reallocate_memoryfunction vdo_duplicate_stringfunction vdo_memory_initfunction vdo_memory_exitfunction vdo_get_memory_statsfunction bytes
Annotated Snippet
struct vmalloc_block_info {
void *ptr;
size_t size;
struct vmalloc_block_info *next;
};
static struct {
spinlock_t lock;
size_t kmalloc_blocks;
size_t kmalloc_bytes;
size_t vmalloc_blocks;
size_t vmalloc_bytes;
size_t peak_bytes;
struct vmalloc_block_info *vmalloc_list;
} memory_stats __cacheline_aligned;
static void update_peak_usage(void)
{
size_t total_bytes = memory_stats.kmalloc_bytes + memory_stats.vmalloc_bytes;
if (total_bytes > memory_stats.peak_bytes)
memory_stats.peak_bytes = total_bytes;
}
static void add_kmalloc_block(size_t size)
{
unsigned long flags;
spin_lock_irqsave(&memory_stats.lock, flags);
memory_stats.kmalloc_blocks++;
memory_stats.kmalloc_bytes += size;
update_peak_usage();
spin_unlock_irqrestore(&memory_stats.lock, flags);
}
static void remove_kmalloc_block(size_t size)
{
unsigned long flags;
spin_lock_irqsave(&memory_stats.lock, flags);
memory_stats.kmalloc_blocks--;
memory_stats.kmalloc_bytes -= size;
spin_unlock_irqrestore(&memory_stats.lock, flags);
}
static void add_vmalloc_block(struct vmalloc_block_info *block)
{
unsigned long flags;
spin_lock_irqsave(&memory_stats.lock, flags);
block->next = memory_stats.vmalloc_list;
memory_stats.vmalloc_list = block;
memory_stats.vmalloc_blocks++;
memory_stats.vmalloc_bytes += block->size;
update_peak_usage();
spin_unlock_irqrestore(&memory_stats.lock, flags);
}
static void remove_vmalloc_block(void *ptr)
{
struct vmalloc_block_info *block;
struct vmalloc_block_info **block_ptr;
unsigned long flags;
spin_lock_irqsave(&memory_stats.lock, flags);
for (block_ptr = &memory_stats.vmalloc_list;
(block = *block_ptr) != NULL;
block_ptr = &block->next) {
if (block->ptr == ptr) {
*block_ptr = block->next;
memory_stats.vmalloc_blocks--;
memory_stats.vmalloc_bytes -= block->size;
break;
}
}
spin_unlock_irqrestore(&memory_stats.lock, flags);
if (block != NULL)
vdo_free(block);
else
vdo_log_info("attempting to remove ptr %px not found in vmalloc list", ptr);
}
/*
* Determine whether allocating a memory block should use kmalloc or __vmalloc.
*
* vmalloc can allocate any integral number of pages.
*
* kmalloc can allocate any number of bytes up to a configured limit, which defaults to 8 megabytes
* on some systems. kmalloc is especially good when memory is being both allocated and freed, and
Annotation
- Immediate include surface: `linux/delay.h`, `linux/mm.h`, `linux/sched/mm.h`, `linux/slab.h`, `linux/vmalloc.h`, `logger.h`, `memory-alloc.h`, `permassert.h`.
- Detected declarations: `struct vmalloc_block_info`, `function allocations_allowed`, `function vdo_register_allocating_thread`, `function vdo_unregister_allocating_thread`, `function update_peak_usage`, `function add_kmalloc_block`, `function remove_kmalloc_block`, `function add_vmalloc_block`, `function remove_vmalloc_block`, `function use_kmalloc`.
- Atlas domain: Driver Families / drivers/md.
- 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.