drivers/gpu/drm/ttm/ttm_pool.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/ttm/ttm_pool.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/ttm/ttm_pool.c- Extension
.c- Size
- 39884 bytes
- Lines
- 1459
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- 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/export.hlinux/module.hlinux/dma-mapping.hlinux/debugfs.hlinux/highmem.hlinux/sched/mm.hasm/set_memory.hdrm/ttm/ttm_backup.hdrm/ttm/ttm_pool.hdrm/ttm/ttm_tt.hdrm/ttm/ttm_bo.httm_module.httm_pool_internal.hlinux/fault-inject.h
Detected Declarations
struct ttm_pool_dmastruct ttm_pool_alloc_statestruct ttm_pool_tt_restorefunction ttm_pool_nidfunction __free_pages_gpu_accountfunction ttm_pool_free_pagefunction ttm_pool_apply_cachingfunction ttm_pool_mapfunction ttm_pool_unmapfunction ttm_pool_type_givefunction take_one_from_lrufunction ttm_pool_type_initfunction pool_move_to_dispose_listfunction ttm_pool_dispose_listfunction ttm_pool_type_finifunction ttm_pool_shrinkfunction ttm_pool_page_orderfunction ttm_pool_split_for_swapfunction ttm_backup_backup_pagefunction ttm_pool_unmap_and_freefunction ttm_pool_allocated_page_commitfunction ttm_pool_restore_commitfunction ttm_pool_page_allocated_restorefunction ttm_pool_page_allocatedfunction ttm_pool_free_rangefunction ttm_pool_alloc_state_initfunction ttm_pool_alloc_find_orderfunction __ttm_pool_allocfunction ttm_pool_allocfunction ttm_pool_restore_and_allocfunction ttm_pool_freefunction ttm_pool_drop_backed_upfunction ttm_pool_backupfunction ttm_pool_initfunction ttm_pool_synchronize_shrinkersfunction ttm_pool_finifunction ttm_pool_shrinker_scanfunction ttm_pool_shrinker_countfunction ttm_pool_type_countfunction ttm_pool_debugfs_headerfunction ttm_pool_debugfs_ordersfunction ttm_pool_debugfs_footerfunction for_each_nodefunction ttm_pool_debugfs_globals_showfunction ttm_pool_debugfsfunction ttm_pool_debugfs_shrink_showfunction ttm_get_node_memory_sizefunction ttm_pool_mgr_init
Annotated Snippet
struct ttm_pool_dma {
dma_addr_t addr;
unsigned long vaddr;
};
/**
* struct ttm_pool_alloc_state - Current state of the tt page allocation process
* @pages: Pointer to the next tt page pointer to populate.
* @caching_divide: Pointer to the first page pointer whose page has a staged but
* not committed caching transition from write-back to @tt_caching.
* @dma_addr: Pointer to the next tt dma_address entry to populate if any.
* @remaining_pages: Remaining pages to populate.
* @tt_caching: The requested cpu-caching for the pages allocated.
*/
struct ttm_pool_alloc_state {
struct page **pages;
struct page **caching_divide;
dma_addr_t *dma_addr;
pgoff_t remaining_pages;
enum ttm_caching tt_caching;
};
/**
* struct ttm_pool_tt_restore - State representing restore from backup
* @pool: The pool used for page allocation while restoring.
* @snapshot_alloc: A snapshot of the most recent struct ttm_pool_alloc_state.
* @alloced_page: Pointer to the page most recently allocated from a pool or system.
* @first_dma: The dma address corresponding to @alloced_page if dma_mapping
* is requested.
* @alloced_pages: The number of allocated pages present in the struct ttm_tt
* page vector from this restore session.
* @restored_pages: The number of 4K pages restored for @alloced_page (which
* is typically a multi-order page).
* @page_caching: The struct ttm_tt requested caching
* @order: The order of @alloced_page.
*
* Recovery from backup might fail when we've recovered less than the
* full ttm_tt. In order not to loose any data (yet), keep information
* around that allows us to restart a failed ttm backup recovery.
*/
struct ttm_pool_tt_restore {
struct ttm_pool *pool;
struct ttm_pool_alloc_state snapshot_alloc;
struct page *alloced_page;
dma_addr_t first_dma;
pgoff_t alloced_pages;
pgoff_t restored_pages;
enum ttm_caching page_caching;
unsigned int order;
};
static unsigned long page_pool_size;
MODULE_PARM_DESC(page_pool_size, "Number of pages in the WC/UC/DMA pool per NUMA node");
module_param(page_pool_size, ulong, 0644);
static unsigned long pool_node_limit[MAX_NUMNODES];
static atomic_long_t allocated_pages[MAX_NUMNODES];
static struct ttm_pool_type global_write_combined[NR_PAGE_ORDERS];
static struct ttm_pool_type global_uncached[NR_PAGE_ORDERS];
static struct ttm_pool_type global_dma32_write_combined[NR_PAGE_ORDERS];
static struct ttm_pool_type global_dma32_uncached[NR_PAGE_ORDERS];
static spinlock_t shrinker_lock;
static struct list_head shrinker_list;
static struct shrinker *mm_shrinker;
static DECLARE_RWSEM(pool_shrink_rwsem);
static int ttm_pool_nid(struct ttm_pool *pool)
{
int nid = NUMA_NO_NODE;
if (pool)
nid = pool->nid;
if (nid == NUMA_NO_NODE)
nid = numa_node_id();
return nid;
}
/* Allocate pages of size 1 << order with the given gfp_flags */
static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags,
unsigned int order)
{
const unsigned int beneficial_order = ttm_pool_beneficial_order(pool);
unsigned long attr = DMA_ATTR_FORCE_CONTIGUOUS;
struct ttm_pool_dma *dma;
struct page *p;
void *vaddr;
Annotation
- Immediate include surface: `linux/export.h`, `linux/module.h`, `linux/dma-mapping.h`, `linux/debugfs.h`, `linux/highmem.h`, `linux/sched/mm.h`, `asm/set_memory.h`, `drm/ttm/ttm_backup.h`.
- Detected declarations: `struct ttm_pool_dma`, `struct ttm_pool_alloc_state`, `struct ttm_pool_tt_restore`, `function ttm_pool_nid`, `function __free_pages_gpu_account`, `function ttm_pool_free_page`, `function ttm_pool_apply_caching`, `function ttm_pool_map`, `function ttm_pool_unmap`, `function ttm_pool_type_give`.
- Atlas domain: Driver Families / drivers/gpu.
- 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.