mm/show_mem.c
Source file repositories/reference/linux-study-clean/mm/show_mem.c
File Facts
- System
- Linux kernel
- Corpus path
mm/show_mem.c- Extension
.c- Size
- 13204 bytes
- Lines
- 465
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/blkdev.hlinux/cma.hlinux/cpuset.hlinux/highmem.hlinux/hugetlb.hlinux/mm.hlinux/mmzone.hlinux/swap.hlinux/vmstat.hinternal.hswap.h
Detected Declarations
function show_nodefunction si_mem_availablefunction si_meminfofunction si_meminfo_nodefunction show_free_areasfunction show_migration_typesfunction node_has_managed_zonesfunction listfunction for_each_populated_zonefunction for_each_online_pgdatfunction for_each_populated_zonefunction for_each_populated_zonefunction for_each_online_nodefunction __show_memfunction for_each_populated_zoneexport _totalram_pagesexport si_mem_availableexport si_meminfo
Annotated Snippet
if (is_highmem(zone)) {
managed_highpages += zone_managed_pages(zone);
free_highpages += zone_page_state(zone, NR_FREE_PAGES);
}
}
val->totalram = managed_pages;
val->sharedram = node_page_state(pgdat, NR_SHMEM);
val->freeram = sum_zone_node_page_state(nid, NR_FREE_PAGES);
val->totalhigh = managed_highpages;
val->freehigh = free_highpages;
val->mem_unit = PAGE_SIZE;
}
#endif
/*
* Determine whether the node should be displayed or not, depending on whether
* SHOW_MEM_FILTER_NODES was passed to show_free_areas().
*/
static bool show_mem_node_skip(unsigned int flags, int nid, nodemask_t *nodemask)
{
if (!(flags & SHOW_MEM_FILTER_NODES))
return false;
/*
* no node mask - aka implicit memory numa policy. Do not bother with
* the synchronization - read_mems_allowed_begin - because we do not
* have to be precise here.
*/
if (!nodemask)
nodemask = &cpuset_current_mems_allowed;
return !node_isset(nid, *nodemask);
}
static void show_migration_types(unsigned char type)
{
static const char types[MIGRATE_TYPES] = {
[MIGRATE_UNMOVABLE] = 'U',
[MIGRATE_MOVABLE] = 'M',
[MIGRATE_RECLAIMABLE] = 'E',
[MIGRATE_HIGHATOMIC] = 'H',
#ifdef CONFIG_CMA
[MIGRATE_CMA] = 'C',
#endif
#ifdef CONFIG_MEMORY_ISOLATION
[MIGRATE_ISOLATE] = 'I',
#endif
};
char tmp[MIGRATE_TYPES + 1];
char *p = tmp;
int i;
for (i = 0; i < MIGRATE_TYPES; i++) {
if (type & (1 << i))
*p++ = types[i];
}
*p = '\0';
printk(KERN_CONT "(%s) ", tmp);
}
static bool node_has_managed_zones(pg_data_t *pgdat, int max_zone_idx)
{
int zone_idx;
for (zone_idx = 0; zone_idx <= max_zone_idx; zone_idx++)
if (zone_managed_pages(pgdat->node_zones + zone_idx))
return true;
return false;
}
/*
* Show free area list (used inside shift_scroll-lock stuff)
* We also calculate the percentage fragmentation. We do this by counting the
* memory on each free list with the exception of the first item on the list.
*
* Bits in @filter:
* SHOW_MEM_FILTER_NODES: suppress nodes that are not allowed by current's
* cpuset.
*/
static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_zone_idx)
{
unsigned long free_pcp = 0;
int cpu, nid;
struct zone *zone;
pg_data_t *pgdat;
for_each_populated_zone(zone) {
if (zone_idx(zone) > max_zone_idx)
continue;
Annotation
- Immediate include surface: `linux/blkdev.h`, `linux/cma.h`, `linux/cpuset.h`, `linux/highmem.h`, `linux/hugetlb.h`, `linux/mm.h`, `linux/mmzone.h`, `linux/swap.h`.
- Detected declarations: `function show_node`, `function si_mem_available`, `function si_meminfo`, `function si_meminfo_node`, `function show_free_areas`, `function show_migration_types`, `function node_has_managed_zones`, `function list`, `function for_each_populated_zone`, `function for_each_online_pgdat`.
- 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.