arch/riscv/mm/hugetlbpage.c
Source file repositories/reference/linux-study-clean/arch/riscv/mm/hugetlbpage.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/mm/hugetlbpage.c- Extension
.c- Size
- 9650 bytes
- Lines
- 458
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/hugetlb.hlinux/err.h
Detected Declarations
function huge_ptep_getfunction for_each_napot_orderfunction for_each_napot_orderfunction hugetlb_mask_last_pagefunction get_clear_contigfunction get_clear_contig_flushfunction arch_make_huge_ptefunction for_each_napot_orderfunction clear_flushfunction num_contig_ptes_from_sizefunction set_huge_pte_atfunction huge_ptep_set_access_flagsfunction huge_ptep_get_and_clearfunction huge_ptep_set_wrprotectfunction huge_ptep_clear_flushfunction huge_pte_clearfunction is_napot_sizefunction for_each_napot_orderfunction napot_hugetlbpages_initfunction is_napot_sizefunction __hugetlb_valid_sizefunction arch_hugetlb_valid_sizefunction arch_hugetlb_migration_supportedfunction gigantic_pages_initfunction arch_hugetlb_cma_order
Annotated Snippet
if (napot_cont_size(order) == sz) {
pte = pte_alloc_huge(mm, pmd, addr & napot_cont_mask(order));
break;
}
}
out:
if (pte) {
pte_t pteval = ptep_get_lockless(pte);
WARN_ON_ONCE(pte_present(pteval) && !pte_huge(pteval));
}
return pte;
}
pte_t *huge_pte_offset(struct mm_struct *mm,
unsigned long addr,
unsigned long sz)
{
unsigned long order;
pte_t *pte = NULL;
pgd_t *pgd;
p4d_t *p4d;
pud_t *pud;
pmd_t *pmd;
pgd = pgd_offset(mm, addr);
if (!pgd_present(pgdp_get(pgd)))
return NULL;
p4d = p4d_offset(pgd, addr);
if (!p4d_present(p4dp_get(p4d)))
return NULL;
pud = pud_offset(p4d, addr);
if (sz == PUD_SIZE)
/* must be pud huge, non-present or none */
return (pte_t *)pud;
if (!pud_present(pudp_get(pud)))
return NULL;
pmd = pmd_offset(pud, addr);
if (sz == PMD_SIZE)
/* must be pmd huge, non-present or none */
return (pte_t *)pmd;
if (!pmd_present(pmdp_get(pmd)))
return NULL;
for_each_napot_order(order) {
if (napot_cont_size(order) == sz) {
pte = pte_offset_huge(pmd, addr & napot_cont_mask(order));
break;
}
}
return pte;
}
unsigned long hugetlb_mask_last_page(struct hstate *h)
{
unsigned long hp_size = huge_page_size(h);
switch (hp_size) {
#ifndef __PAGETABLE_PMD_FOLDED
case PUD_SIZE:
return P4D_SIZE - PUD_SIZE;
#endif
case PMD_SIZE:
return PUD_SIZE - PMD_SIZE;
case napot_cont_size(NAPOT_CONT64KB_ORDER):
return PMD_SIZE - napot_cont_size(NAPOT_CONT64KB_ORDER);
default:
break;
}
return 0UL;
}
static pte_t get_clear_contig(struct mm_struct *mm,
unsigned long addr,
pte_t *ptep,
unsigned long ncontig)
{
pte_t pte, tmp_pte;
bool present;
pte = ptep_get_and_clear(mm, addr, ptep);
present = pte_present(pte);
while (--ncontig) {
Annotation
- Immediate include surface: `linux/hugetlb.h`, `linux/err.h`.
- Detected declarations: `function huge_ptep_get`, `function for_each_napot_order`, `function for_each_napot_order`, `function hugetlb_mask_last_page`, `function get_clear_contig`, `function get_clear_contig_flush`, `function arch_make_huge_pte`, `function for_each_napot_order`, `function clear_flush`, `function num_contig_ptes_from_size`.
- Atlas domain: Architecture Layer / arch/riscv.
- Implementation status: source 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.