arch/sparc/mm/hugetlbpage.c
Source file repositories/reference/linux-study-clean/arch/sparc/mm/hugetlbpage.c
File Facts
- System
- Linux kernel
- Corpus path
arch/sparc/mm/hugetlbpage.c- Extension
.c- Size
- 7102 bytes
- Lines
- 318
- Domain
- Architecture Layer
- Bucket
- arch/sparc
- 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/fs.hlinux/mm.hlinux/sched/mm.hlinux/hugetlb.hlinux/pagemap.hlinux/sysctl.hasm/mman.hasm/pgalloc.hasm/tlb.hasm/tlbflush.hasm/cacheflush.hasm/mmu_context.h
Detected Declarations
function Copyrightfunction sun4v_hugepage_shift_to_ttefunction hugepage_shift_to_ttefunction arch_make_huge_ptefunction sun4v_huge_tte_to_shiftfunction sun4u_huge_tte_to_shiftfunction tte_to_shiftfunction huge_tte_to_shiftfunction huge_tte_to_sizefunction pud_leaf_sizefunction pmd_leaf_sizefunction pte_leaf_sizefunction __set_huge_pte_atfunction set_huge_pte_atfunction huge_ptep_get_and_clear
Annotated Snippet
unsigned long pud_leaf_size(pud_t pud) { return 1UL << tte_to_shift(*(pte_t *)&pud); }
unsigned long pmd_leaf_size(pmd_t pmd) { return 1UL << tte_to_shift(*(pte_t *)&pmd); }
unsigned long pte_leaf_size(pte_t pte) { return 1UL << tte_to_shift(pte); }
pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
unsigned long addr, unsigned long sz)
{
pgd_t *pgd;
p4d_t *p4d;
pud_t *pud;
pmd_t *pmd;
pgd = pgd_offset(mm, addr);
p4d = p4d_offset(pgd, addr);
pud = pud_alloc(mm, p4d, addr);
if (!pud)
return NULL;
if (sz >= PUD_SIZE)
return (pte_t *)pud;
pmd = pmd_alloc(mm, pud, addr);
if (!pmd)
return NULL;
if (sz >= PMD_SIZE)
return (pte_t *)pmd;
return pte_alloc_huge(mm, pmd, addr);
}
pte_t *huge_pte_offset(struct mm_struct *mm,
unsigned long addr, unsigned long sz)
{
pgd_t *pgd;
p4d_t *p4d;
pud_t *pud;
pmd_t *pmd;
pgd = pgd_offset(mm, addr);
if (pgd_none(*pgd))
return NULL;
p4d = p4d_offset(pgd, addr);
if (p4d_none(*p4d))
return NULL;
pud = pud_offset(p4d, addr);
if (pud_none(*pud))
return NULL;
if (is_hugetlb_pud(*pud))
return (pte_t *)pud;
pmd = pmd_offset(pud, addr);
if (pmd_none(*pmd))
return NULL;
if (is_hugetlb_pmd(*pmd))
return (pte_t *)pmd;
return pte_offset_huge(pmd, addr);
}
void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
pte_t *ptep, pte_t entry)
{
unsigned int nptes, orig_shift, shift;
unsigned long i, size;
pte_t orig;
size = huge_tte_to_size(entry);
shift = PAGE_SHIFT;
if (size >= PUD_SIZE)
shift = PUD_SHIFT;
else if (size >= PMD_SIZE)
shift = PMD_SHIFT;
else
shift = PAGE_SHIFT;
nptes = size >> shift;
if (!pte_present(*ptep) && pte_present(entry))
mm->context.hugetlb_pte_count += nptes;
addr &= ~(size - 1);
orig = *ptep;
orig_shift = pte_none(orig) ? PAGE_SHIFT : huge_tte_to_shift(orig);
for (i = 0; i < nptes; i++)
ptep[i] = __pte(pte_val(entry) + (i << shift));
maybe_tlb_batch_add(mm, addr, ptep, orig, 0, orig_shift);
/* An HPAGE_SIZE'ed page is composed of two REAL_HPAGE_SIZE'ed pages */
if (size == HPAGE_SIZE)
maybe_tlb_batch_add(mm, addr + REAL_HPAGE_SIZE, ptep, orig, 0,
orig_shift);
}
Annotation
- Immediate include surface: `linux/fs.h`, `linux/mm.h`, `linux/sched/mm.h`, `linux/hugetlb.h`, `linux/pagemap.h`, `linux/sysctl.h`, `asm/mman.h`, `asm/pgalloc.h`.
- Detected declarations: `function Copyright`, `function sun4v_hugepage_shift_to_tte`, `function hugepage_shift_to_tte`, `function arch_make_huge_pte`, `function sun4v_huge_tte_to_shift`, `function sun4u_huge_tte_to_shift`, `function tte_to_shift`, `function huge_tte_to_shift`, `function huge_tte_to_size`, `function pud_leaf_size`.
- Atlas domain: Architecture Layer / arch/sparc.
- 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.