mm/memory-tiers.c
Source file repositories/reference/linux-study-clean/mm/memory-tiers.c
File Facts
- System
- Linux kernel
- Corpus path
mm/memory-tiers.c- Extension
.c- Size
- 27841 bytes
- Lines
- 1010
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/slab.hlinux/lockdep.hlinux/sysfs.hlinux/kobject.hlinux/memory.hlinux/memory-tiers.hlinux/notifier.hlinux/sched/sysctl.hinternal.h
Detected Declarations
struct memory_tierstruct demotion_nodesstruct node_memory_type_mapfunction folio_use_access_timefunction get_memtier_nodemaskfunction memory_tier_device_releasefunction nodelist_showfunction list_for_each_entryfunction list_for_each_entryfunction node_is_toptierfunction node_get_allowed_targetsfunction next_demotion_nodefunction disable_all_demotion_targetsfunction for_each_node_statefunction dump_demotion_targetsfunction for_each_node_statefunction establish_demotion_targetsfunction for_each_node_statefunction establish_demotion_targetsfunction destroy_memory_tierfunction clear_node_memory_tierfunction release_memtypefunction put_memory_typefunction init_node_memory_typefunction clear_node_memory_typefunction mt_put_memory_typesfunction list_for_each_entry_safefunction memory_tier_late_initfunction dump_hmem_attrsfunction mt_set_default_dram_perffunction samefunction mt_perf_to_adistancefunction distancefunction unregister_mt_adistance_algorithmfunction mt_calc_adistancefunction memtier_hotplug_callbackfunction memory_tier_initfunction demotion_enabled_showfunction demotion_enabled_storefunction numa_init_sysfsmodule init memory_tier_initmodule init numa_init_sysfsexport alloc_memory_typeexport put_memory_typeexport init_node_memory_typeexport clear_node_memory_typeexport mt_find_alloc_memory_typeexport mt_put_memory_types
Annotated Snippet
static const struct bus_type memory_tier_subsys = {
.name = "memory_tiering",
.dev_name = "memory_tier",
};
#ifdef CONFIG_NUMA_BALANCING
/**
* folio_use_access_time - check if a folio reuses cpupid for page access time
* @folio: folio to check
*
* folio's _last_cpupid field is repurposed by memory tiering. In memory
* tiering mode, cpupid of slow memory folio (not toptier memory) is used to
* record page access time.
*
* Return: the folio _last_cpupid is used to record page access time
*/
bool folio_use_access_time(struct folio *folio)
{
return (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) &&
!node_is_toptier(folio_nid(folio));
}
#endif
#ifdef CONFIG_NUMA_MIGRATION
static int top_tier_adistance;
/*
* node_demotion[] examples:
*
* Example 1:
*
* Node 0 & 1 are CPU + DRAM nodes, node 2 & 3 are PMEM nodes.
*
* node distances:
* node 0 1 2 3
* 0 10 20 30 40
* 1 20 10 40 30
* 2 30 40 10 40
* 3 40 30 40 10
*
* memory_tiers0 = 0-1
* memory_tiers1 = 2-3
*
* node_demotion[0].preferred = 2
* node_demotion[1].preferred = 3
* node_demotion[2].preferred = <empty>
* node_demotion[3].preferred = <empty>
*
* Example 2:
*
* Node 0 & 1 are CPU + DRAM nodes, node 2 is memory-only DRAM node.
*
* node distances:
* node 0 1 2
* 0 10 20 30
* 1 20 10 30
* 2 30 30 10
*
* memory_tiers0 = 0-2
*
* node_demotion[0].preferred = <empty>
* node_demotion[1].preferred = <empty>
* node_demotion[2].preferred = <empty>
*
* Example 3:
*
* Node 0 is CPU + DRAM nodes, Node 1 is HBM node, node 2 is PMEM node.
*
* node distances:
* node 0 1 2
* 0 10 20 30
* 1 20 10 40
* 2 30 40 10
*
* memory_tiers0 = 1
* memory_tiers1 = 0
* memory_tiers2 = 2
*
* node_demotion[0].preferred = 2
* node_demotion[1].preferred = 0
* node_demotion[2].preferred = <empty>
*
*/
static struct demotion_nodes *node_demotion __read_mostly;
#endif /* CONFIG_NUMA_MIGRATION */
static BLOCKING_NOTIFIER_HEAD(mt_adistance_algorithms);
/* The lock is used to protect `default_dram_perf*` info and nid. */
static DEFINE_MUTEX(default_dram_perf_lock);
static bool default_dram_perf_error;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/lockdep.h`, `linux/sysfs.h`, `linux/kobject.h`, `linux/memory.h`, `linux/memory-tiers.h`, `linux/notifier.h`, `linux/sched/sysctl.h`.
- Detected declarations: `struct memory_tier`, `struct demotion_nodes`, `struct node_memory_type_map`, `function folio_use_access_time`, `function get_memtier_nodemask`, `function memory_tier_device_release`, `function nodelist_show`, `function list_for_each_entry`, `function list_for_each_entry`, `function node_is_toptier`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: pattern 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.