mm/dmapool.c
Source file repositories/reference/linux-study-clean/mm/dmapool.c
File Facts
- System
- Linux kernel
- Corpus path
mm/dmapool.c- Extension
.c- Size
- 13512 bytes
- Lines
- 528
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/device.hlinux/dma-mapping.hlinux/dmapool.hlinux/kernel.hlinux/list.hlinux/export.hlinux/mutex.hlinux/poison.hlinux/sched.hlinux/sched/mm.hlinux/slab.hlinux/stat.hlinux/spinlock.hlinux/string.hlinux/types.hlinux/wait.h
Detected Declarations
struct dma_blockstruct dma_poolstruct dma_pagefunction pools_showfunction pool_check_blockfunction list_for_each_entryfunction pool_block_errfunction pool_init_pagefunction pool_check_blockfunction pool_init_pagefunction pool_block_pushfunction pool_initialise_pagefunction dma_pool_destroyfunction list_for_each_entry_safefunction dma_pool_freefunction dmam_pool_releasefunction dmam_pool_matchfunction dma_pool_createfunction dma_pool_destroyexport dma_pool_create_nodeexport dma_pool_destroyexport dma_pool_allocexport dma_pool_freeexport dmam_pool_createexport dmam_pool_destroy
Annotated Snippet
struct dma_block {
struct dma_block *next_block;
dma_addr_t dma;
};
struct dma_pool { /* the pool */
struct list_head page_list;
spinlock_t lock;
struct dma_block *next_block;
size_t nr_blocks;
size_t nr_active;
size_t nr_pages;
struct device *dev;
unsigned int size;
unsigned int allocation;
unsigned int boundary;
int node;
char name[32];
struct list_head pools;
};
struct dma_page { /* cacheable header for 'allocation' bytes */
struct list_head page_list;
void *vaddr;
dma_addr_t dma;
};
static DEFINE_MUTEX(pools_lock);
static DEFINE_MUTEX(pools_reg_lock);
static ssize_t pools_show(struct device *dev, struct device_attribute *attr, char *buf)
{
struct dma_pool *pool;
unsigned size;
size = sysfs_emit(buf, "poolinfo - 0.1\n");
mutex_lock(&pools_lock);
list_for_each_entry(pool, &dev->dma_pools, pools) {
/* per-pool info, no real statistics yet */
size += sysfs_emit_at(buf, size, "%-16s %4zu %4zu %4u %2zu\n",
pool->name, pool->nr_active,
pool->nr_blocks, pool->size,
pool->nr_pages);
}
mutex_unlock(&pools_lock);
return size;
}
static DEVICE_ATTR_RO(pools);
#ifdef DMAPOOL_DEBUG
static void pool_check_block(struct dma_pool *pool, struct dma_block *block,
gfp_t mem_flags)
{
u8 *data = (void *)block;
int i;
for (i = sizeof(struct dma_block); i < pool->size; i++) {
if (data[i] == POOL_POISON_FREED)
continue;
dev_err(pool->dev, "%s %s, %p (corrupted)\n", __func__,
pool->name, block);
/*
* Dump the first 4 bytes even if they are not
* POOL_POISON_FREED
*/
print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1,
data, pool->size, 1);
break;
}
if (!want_init_on_alloc(mem_flags))
memset(block, POOL_POISON_ALLOCATED, pool->size);
}
static struct dma_page *pool_find_page(struct dma_pool *pool, dma_addr_t dma)
{
struct dma_page *page;
list_for_each_entry(page, &pool->page_list, page_list) {
if (dma < page->dma)
continue;
if ((dma - page->dma) < pool->allocation)
return page;
}
return NULL;
}
Annotation
- Immediate include surface: `linux/device.h`, `linux/dma-mapping.h`, `linux/dmapool.h`, `linux/kernel.h`, `linux/list.h`, `linux/export.h`, `linux/mutex.h`, `linux/poison.h`.
- Detected declarations: `struct dma_block`, `struct dma_pool`, `struct dma_page`, `function pools_show`, `function pool_check_block`, `function list_for_each_entry`, `function pool_block_err`, `function pool_init_page`, `function pool_check_block`, `function pool_init_page`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.