mm/memblock.c
Source file repositories/reference/linux-study-clean/mm/memblock.c
File Facts
- System
- Linux kernel
- Corpus path
mm/memblock.c- Extension
.c- Size
- 80912 bytes
- Lines
- 2899
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/kernel.hlinux/slab.hlinux/init.hlinux/bitops.hlinux/poison.hlinux/pfn.hlinux/debugfs.hlinux/kmemleak.hlinux/seq_file.hlinux/memblock.hlinux/mutex.hlinux/string_helpers.hlinux/libfdt.hlinux/kexec_handover.hlinux/kho/abi/memblock.hasm/sections.hlinux/io.hinternal.h
Detected Declarations
struct reserve_mem_tablefunction memblock_has_mirrorfunction choose_memblock_flagsfunction memblock_cap_sizefunction memblock_addrs_overlapfunction memblock_overlaps_regionfunction memblock_find_in_range_nodefunction for_each_free_mem_rangefunction memblock_find_in_range_nodefunction for_each_free_mem_range_reversefunction memblock_find_in_range_nodefunction memblock_find_in_rangefunction memblock_remove_regionfunction memblock_discardfunction memblock_double_arrayfunction memblock_merge_regionsfunction memblock_insert_regionfunction memblock_add_rangefunction for_each_memblock_typefunction memblock_add_nodefunction memblock_addfunction IDfunction memblock_isolate_rangefunction for_each_memblock_typefunction memblock_remove_rangefunction memblock_removefunction __free_reserved_areafunction for_each_valid_pfnfunction free_reserved_areafunction __pafunction memblock_alloc_xxfunction memblock_phys_alloc_xxfunction __memblock_reservefunction memblock_physmem_addfunction memblock_setclr_flagfunction memblock_mark_hotplugfunction memblock_clear_hotplugfunction memblock_mark_mirrorfunction PageReservedfunction memblock_clear_nomapfunction memblock_reserved_mark_noinitfunction memblock_reserved_mark_kernfunction memblock_mark_kho_scratchfunction memblock_clear_kho_scratchfunction should_skip_regionfunction __next_mem_rangefunction __next_mem_rangefunction for_each_mem_pfn_range
Annotated Snippet
struct reserve_mem_table {
char name[RESERVE_MEM_NAME_SIZE];
phys_addr_t start;
phys_addr_t size;
};
static struct reserve_mem_table reserved_mem_table[RESERVE_MEM_MAX_ENTRIES];
static int reserved_mem_count;
static DEFINE_MUTEX(reserve_mem_lock);
/* Add wildcard region with a lookup name */
static void __init reserved_mem_add(phys_addr_t start, phys_addr_t size,
const char *name)
{
struct reserve_mem_table *map;
map = &reserved_mem_table[reserved_mem_count++];
map->start = start;
map->size = size;
strscpy(map->name, name);
}
static struct reserve_mem_table *reserve_mem_find_by_name_nolock(const char *name)
{
struct reserve_mem_table *map;
int i;
for (i = 0; i < reserved_mem_count; i++) {
map = &reserved_mem_table[i];
if (!map->size)
continue;
if (strcmp(name, map->name) == 0)
return map;
}
return NULL;
}
/**
* reserve_mem_find_by_name - Find reserved memory region with a given name
* @name: The name that is attached to a reserved memory region
* @start: If found, holds the start address
* @size: If found, holds the size of the address.
*
* @start and @size are only updated if @name is found.
*
* Returns: 1 if found or 0 if not found.
*/
int reserve_mem_find_by_name(const char *name, phys_addr_t *start, phys_addr_t *size)
{
struct reserve_mem_table *map;
guard(mutex)(&reserve_mem_lock);
map = reserve_mem_find_by_name_nolock(name);
if (!map)
return 0;
*start = map->start;
*size = map->size;
return 1;
}
EXPORT_SYMBOL_GPL(reserve_mem_find_by_name);
/**
* reserve_mem_release_by_name - Release reserved memory region with a given name
* @name: The name that is attached to a reserved memory region
*
* Forcibly release the pages in the reserved memory region so that those memory
* can be used as free memory. After released the reserved region size becomes 0.
*
* Returns: 1 if released or 0 if not found.
*/
int reserve_mem_release_by_name(const char *name)
{
char buf[RESERVE_MEM_NAME_SIZE + 12];
struct reserve_mem_table *map;
void *start, *end;
guard(mutex)(&reserve_mem_lock);
map = reserve_mem_find_by_name_nolock(name);
if (!map)
return 0;
start = phys_to_virt(map->start);
end = start + map->size;
snprintf(buf, sizeof(buf), "reserve_mem:%s", name);
free_reserved_area(start, end, 0, buf);
map->size = 0;
return 1;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/slab.h`, `linux/init.h`, `linux/bitops.h`, `linux/poison.h`, `linux/pfn.h`, `linux/debugfs.h`, `linux/kmemleak.h`.
- Detected declarations: `struct reserve_mem_table`, `function memblock_has_mirror`, `function choose_memblock_flags`, `function memblock_cap_size`, `function memblock_addrs_overlap`, `function memblock_overlaps_region`, `function memblock_find_in_range_node`, `function for_each_free_mem_range`, `function memblock_find_in_range_node`, `function for_each_free_mem_range_reverse`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: integration 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.