mm/bootmem_info.c
Source file repositories/reference/linux-study-clean/mm/bootmem_info.c
File Facts
- System
- Linux kernel
- Corpus path
mm/bootmem_info.c- Extension
.c- Size
- 1855 bytes
- Lines
- 73
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mm.hlinux/compiler.hlinux/memblock.hlinux/bootmem_info.hlinux/memory_hotplug.hlinux/kmemleak.h
Detected Declarations
function Copyrightfunction put_page_bootmemfunction register_page_bootmem_info_sectionfunction register_page_bootmem_info_node
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Bootmem core functions.
*
* Copyright (c) 2020, Bytedance.
*
* Author: Muchun Song <songmuchun@bytedance.com>
*
*/
#include <linux/mm.h>
#include <linux/compiler.h>
#include <linux/memblock.h>
#include <linux/bootmem_info.h>
#include <linux/memory_hotplug.h>
#include <linux/kmemleak.h>
void get_page_bootmem(unsigned long info, struct page *page,
enum bootmem_type type)
{
BUG_ON(type > 0xf);
BUG_ON(info > (ULONG_MAX >> 4));
set_page_private(page, info << 4 | type);
page_ref_inc(page);
}
void put_page_bootmem(struct page *page)
{
enum bootmem_type type = bootmem_type(page);
BUG_ON(type < MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE ||
type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE);
if (page_ref_dec_return(page) == 1) {
set_page_private(page, 0);
free_reserved_page(page);
}
}
static void __init register_page_bootmem_info_section(unsigned long start_pfn)
{
unsigned long section_nr;
struct mem_section *ms;
start_pfn = SECTION_ALIGN_DOWN(start_pfn);
section_nr = pfn_to_section_nr(start_pfn);
ms = __nr_to_section(section_nr);
if (!preinited_vmemmap_section(ms))
register_page_bootmem_memmap(section_nr, pfn_to_page(start_pfn),
PAGES_PER_SECTION);
}
void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
{
unsigned long pfn, end_pfn;
int node = pgdat->node_id;
pfn = pgdat->node_start_pfn;
end_pfn = pgdat_end_pfn(pgdat);
/* register section info */
for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
/*
* Some platforms can assign the same pfn to multiple nodes - on
* node0 as well as nodeN. To avoid registering a pfn against
* multiple nodes we check that this pfn does not already
* reside in some other nodes.
*/
if (pfn_valid(pfn) && (early_pfn_to_nid(pfn) == node))
register_page_bootmem_info_section(pfn);
}
}
Annotation
- Immediate include surface: `linux/mm.h`, `linux/compiler.h`, `linux/memblock.h`, `linux/bootmem_info.h`, `linux/memory_hotplug.h`, `linux/kmemleak.h`.
- Detected declarations: `function Copyright`, `function put_page_bootmem`, `function register_page_bootmem_info_section`, `function register_page_bootmem_info_node`.
- 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.