mm/hugetlb_cma.c
Source file repositories/reference/linux-study-clean/mm/hugetlb_cma.c
File Facts
- System
- Linux kernel
- Corpus path
mm/hugetlb_cma.c- Extension
.c- Size
- 6209 bytes
- Lines
- 279
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/mm.hlinux/cma.hlinux/compiler.hlinux/mm_inline.hasm/page.hasm/setup.hlinux/hugetlb.hinternal.hhugetlb_cma.h
Detected Declarations
function hugetlb_cma_free_frozen_foliofunction hugetlb_cma_alloc_bootmemfunction for_each_node_maskfunction cmdline_parse_hugetlb_cmafunction cmdline_parse_hugetlb_cma_onlyfunction arch_hugetlb_cma_orderfunction hugetlb_cma_reservefunction hugetlb_cma_exclusive_allocfunction hugetlb_cma_total_sizefunction hugetlb_cma_validate_paramsfunction hugetlb_early_cma
Annotated Snippet
for_each_node_mask(node, *nodemask) {
if (node == nid || !hugetlb_cma[node])
continue;
page = cma_alloc_frozen_compound(hugetlb_cma[node], order);
if (page)
break;
}
}
if (!page)
return NULL;
folio = page_folio(page);
folio_set_hugetlb_cma(folio);
return folio;
}
struct huge_bootmem_page * __init
hugetlb_cma_alloc_bootmem(struct hstate *h, int *nid, bool node_exact)
{
struct cma *cma;
struct huge_bootmem_page *m;
int node = *nid;
cma = hugetlb_cma[*nid];
m = cma_reserve_early(cma, huge_page_size(h));
if (!m) {
if (node_exact)
return NULL;
for_each_node_mask(node, hugetlb_bootmem_nodes) {
cma = hugetlb_cma[node];
if (!cma || node == *nid)
continue;
m = cma_reserve_early(cma, huge_page_size(h));
if (m) {
*nid = node;
break;
}
}
}
if (m) {
m->flags = HUGE_BOOTMEM_CMA;
m->cma = cma;
}
return m;
}
static int __init cmdline_parse_hugetlb_cma(char *p)
{
int nid, count = 0;
unsigned long tmp;
char *s = p;
while (*s) {
if (sscanf(s, "%lu%n", &tmp, &count) != 1)
break;
if (s[count] == ':') {
if (tmp >= MAX_NUMNODES)
break;
nid = array_index_nospec(tmp, MAX_NUMNODES);
s += count + 1;
tmp = memparse(s, &s);
hugetlb_cma_size_in_node[nid] = tmp;
hugetlb_cma_size += tmp;
/*
* Skip the separator if have one, otherwise
* break the parsing.
*/
if (*s == ',')
s++;
else
break;
} else {
hugetlb_cma_size = memparse(p, &p);
break;
}
}
return 0;
}
early_param("hugetlb_cma", cmdline_parse_hugetlb_cma);
Annotation
- Immediate include surface: `linux/mm.h`, `linux/cma.h`, `linux/compiler.h`, `linux/mm_inline.h`, `asm/page.h`, `asm/setup.h`, `linux/hugetlb.h`, `internal.h`.
- Detected declarations: `function hugetlb_cma_free_frozen_folio`, `function hugetlb_cma_alloc_bootmem`, `function for_each_node_mask`, `function cmdline_parse_hugetlb_cma`, `function cmdline_parse_hugetlb_cma_only`, `function arch_hugetlb_cma_order`, `function hugetlb_cma_reserve`, `function hugetlb_cma_exclusive_alloc`, `function hugetlb_cma_total_size`, `function hugetlb_cma_validate_params`.
- Atlas domain: Core OS / Memory Management.
- 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.