arch/s390/mm/vmem.c
Source file repositories/reference/linux-study-clean/arch/s390/mm/vmem.c
File Facts
- System
- Linux kernel
- Corpus path
arch/s390/mm/vmem.c- Extension
.c- Size
- 17277 bytes
- Lines
- 691
- Domain
- Architecture Layer
- Bucket
- arch/s390
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- 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/memory_hotplug.hlinux/cpufeature.hlinux/memblock.hlinux/pfn.hlinux/mm.hlinux/init.hlinux/list.hlinux/hugetlb.hlinux/slab.hlinux/sort.hasm/page-states.hasm/abs_lowcore.hasm/cacheflush.hasm/maccess.hasm/nospec-branch.hasm/ctlreg.hasm/pgalloc.hasm/setup.hasm/tlbflush.hasm/sections.hasm/set_memory.hasm/physmem_info.h
Detected Declarations
function vmem_free_pagesfunction vmem_pte_freefunction vmemmap_flush_unused_sub_pmdfunction vmemmap_mark_sub_pmd_usedfunction vmemmap_use_sub_pmdfunction vmemmap_use_new_sub_pmdfunction vmemmap_unuse_sub_pmdfunction modify_pte_tablefunction try_free_pte_tablefunction modify_pmd_tablefunction try_free_pmd_tablefunction modify_pud_tablefunction try_free_pud_tablefunction modify_p4d_tablefunction try_free_p4d_tablefunction modify_pagetablefunction add_pagetablefunction remove_pagetablefunction vmem_add_rangefunction vmem_remove_rangefunction vmemmap_populatefunction vmemmap_freefunction vmem_remove_mappingfunction arch_get_mappable_rangefunction vmem_add_mappingfunction __vmem_map_4k_pagefunction vmem_map_4k_pagefunction vmem_unmap_4k_pagefunction vmem_map_init
Annotated Snippet
if (!add) {
if (pte_none(entry))
continue;
if (!direct)
vmem_free_pages((unsigned long)pfn_to_virt(pte_pfn(entry)), get_order(PAGE_SIZE), altmap);
pte_clear(&init_mm, addr, pte);
} else if (pte_none(entry)) {
if (!direct) {
void *new_page = vmemmap_alloc_block_buf(PAGE_SIZE, NUMA_NO_NODE, altmap);
if (!new_page)
goto out;
set_pte(pte, __pte(__pa(new_page) | prot));
} else {
set_pte(pte, __pte(__pa(addr) | prot));
}
} else {
continue;
}
pages++;
}
ret = 0;
out:
if (direct)
update_page_count(PG_DIRECT_MAP_4K, add ? pages : -pages);
return ret;
}
static void try_free_pte_table(pmd_t *pmd, unsigned long start)
{
pte_t *pte;
int i;
/* We can safely assume this is fully in 1:1 mapping & vmemmap area */
pte = pte_offset_kernel(pmd, start);
for (i = 0; i < PTRS_PER_PTE; i++, pte++) {
if (!pte_none(ptep_get(pte)))
return;
}
vmem_pte_free((unsigned long *)pmd_deref(pmdp_get(pmd)));
pmd_clear(pmd);
}
/* __ref: we'll only call vmemmap_alloc_block() via vmemmap_populate() */
static int __ref modify_pmd_table(pud_t *pud, unsigned long addr,
unsigned long end, bool add, bool direct,
struct vmem_altmap *altmap)
{
unsigned long next, prot, pages = 0;
int ret = -ENOMEM;
pmd_t entry;
pmd_t *pmd;
pte_t *pte;
prot = pgprot_val(SEGMENT_KERNEL);
pmd = pmd_offset(pud, addr);
for (; addr < end; addr = next, pmd++) {
next = pmd_addr_end(addr, end);
entry = pmdp_get(pmd);
if (!add) {
if (pmd_none(entry))
continue;
if (pmd_leaf(entry)) {
if (IS_ALIGNED(addr, PMD_SIZE) &&
IS_ALIGNED(next, PMD_SIZE)) {
if (!direct)
vmem_free_pages(pmd_deref(entry), get_order(PMD_SIZE), altmap);
pmd_clear(pmd);
pages++;
} else if (!direct && vmemmap_unuse_sub_pmd(addr, next)) {
vmem_free_pages(pmd_deref(entry), get_order(PMD_SIZE), altmap);
pmd_clear(pmd);
}
continue;
}
} else if (pmd_none(entry)) {
if (IS_ALIGNED(addr, PMD_SIZE) &&
IS_ALIGNED(next, PMD_SIZE) &&
cpu_has_edat1() && direct &&
!debug_pagealloc_enabled()) {
set_pmd(pmd, __pmd(__pa(addr) | prot));
pages++;
continue;
} else if (!direct && cpu_has_edat1()) {
void *new_page;
/*
* Use 1MB frames for vmemmap if available. We
* always use large frames even if they are only
* partially used. Otherwise we would have also
Annotation
- Immediate include surface: `linux/memory_hotplug.h`, `linux/cpufeature.h`, `linux/memblock.h`, `linux/pfn.h`, `linux/mm.h`, `linux/init.h`, `linux/list.h`, `linux/hugetlb.h`.
- Detected declarations: `function vmem_free_pages`, `function vmem_pte_free`, `function vmemmap_flush_unused_sub_pmd`, `function vmemmap_mark_sub_pmd_used`, `function vmemmap_use_sub_pmd`, `function vmemmap_use_new_sub_pmd`, `function vmemmap_unuse_sub_pmd`, `function modify_pte_table`, `function try_free_pte_table`, `function modify_pmd_table`.
- Atlas domain: Architecture Layer / arch/s390.
- 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.