mm/migrate_device.c
Source file repositories/reference/linux-study-clean/mm/migrate_device.c
File Facts
- System
- Linux kernel
- Corpus path
mm/migrate_device.c- Extension
.c- Size
- 41056 bytes
- Lines
- 1489
- 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.
- 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/memremap.hlinux/migrate.hlinux/mm.hlinux/mm_inline.hlinux/mmu_notifier.hlinux/oom.hlinux/pagewalk.hlinux/rmap.hlinux/leafops.hlinux/pgalloc.hasm/tlbflush.hinternal.h
Detected Declarations
function migrate_vma_collect_skipfunction migrate_vma_collect_holefunction migrate_vma_split_foliofunction migrate_vma_collect_huge_pmdfunction migrate_vma_collect_pmdfunction folio_trylockfunction migrate_vma_collectfunction migrate_vma_check_pagefunction migrate_device_unmapfunction migrate_vma_unmapfunction migrate_vma_setupfunction __do_huge_pmd_anonymous_pagefunction migrate_vma_split_unmapped_foliofunction migrate_vma_insert_huge_pmd_pagefunction migrate_vma_split_unmapped_foliofunction migrate_vma_nr_pagesfunction __handle_mm_faultfunction __migrate_device_pagesfunction migrate_device_pagesfunction migrate_vma_pagesfunction __migrate_device_finalizefunction migrate_device_finalizefunction migrate_vma_finalizefunction migrate_device_pfn_lockfunction migrate_device_rangefunction migrate_device_pfnsfunction migrate_device_coherent_folioexport migrate_vma_setupexport migrate_device_pagesexport migrate_vma_pagesexport migrate_device_finalizeexport migrate_vma_finalizeexport migrate_device_rangeexport migrate_device_pfns
Annotated Snippet
IS_ALIGNED(end, HPAGE_PMD_SIZE))) {
migrate->src[migrate->npages] = MIGRATE_PFN_MIGRATE |
MIGRATE_PFN_COMPOUND;
migrate->dst[migrate->npages] = 0;
migrate->npages++;
migrate->cpages++;
/*
* Collect the remaining entries as holes, in case we
* need to split later
*/
return migrate_vma_collect_skip(start + PAGE_SIZE, end, walk);
}
for (addr = start; addr < end; addr += PAGE_SIZE) {
migrate->src[migrate->npages] = MIGRATE_PFN_MIGRATE;
migrate->dst[migrate->npages] = 0;
migrate->npages++;
migrate->cpages++;
}
return 0;
}
/**
* migrate_vma_split_folio() - Helper function to split a THP folio
* @folio: the folio to split
* @fault_page: struct page associated with the fault if any
*
* Returns 0 on success
*/
static int migrate_vma_split_folio(struct folio *folio,
struct page *fault_page)
{
int ret;
struct folio *fault_folio = fault_page ? page_folio(fault_page) : NULL;
struct folio *new_fault_folio = NULL;
if (folio != fault_folio) {
folio_get(folio);
folio_lock(folio);
}
ret = split_folio(folio);
if (ret) {
if (folio != fault_folio) {
folio_unlock(folio);
folio_put(folio);
}
return ret;
}
new_fault_folio = fault_page ? page_folio(fault_page) : NULL;
/*
* Ensure the lock is held on the correct
* folio after the split
*/
if (!new_fault_folio) {
folio_unlock(folio);
folio_put(folio);
} else if (folio != new_fault_folio) {
if (new_fault_folio != fault_folio) {
folio_get(new_fault_folio);
folio_lock(new_fault_folio);
}
folio_unlock(folio);
folio_put(folio);
}
return 0;
}
/** migrate_vma_collect_huge_pmd - collect THP pages without splitting the
* folio for device private pages.
* @pmdp: pointer to pmd entry
* @start: start address of the range for migration
* @end: end address of the range for migration
* @walk: mm_walk callback structure
* @fault_folio: folio associated with the fault if any
*
* Collect the huge pmd entry at @pmdp for migration and set the
* MIGRATE_PFN_COMPOUND flag in the migrate src entry to indicate that
* migration will occur at HPAGE_PMD granularity
*/
static int migrate_vma_collect_huge_pmd(pmd_t *pmdp, unsigned long start,
unsigned long end, struct mm_walk *walk,
struct folio *fault_folio)
{
struct mm_struct *mm = walk->mm;
Annotation
- Immediate include surface: `linux/export.h`, `linux/memremap.h`, `linux/migrate.h`, `linux/mm.h`, `linux/mm_inline.h`, `linux/mmu_notifier.h`, `linux/oom.h`, `linux/pagewalk.h`.
- Detected declarations: `function migrate_vma_collect_skip`, `function migrate_vma_collect_hole`, `function migrate_vma_split_folio`, `function migrate_vma_collect_huge_pmd`, `function migrate_vma_collect_pmd`, `function folio_trylock`, `function migrate_vma_collect`, `function migrate_vma_check_page`, `function migrate_device_unmap`, `function migrate_vma_unmap`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: integration 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.