mm/memtest.c
Source file repositories/reference/linux-study-clean/mm/memtest.c
File Facts
- System
- Linux kernel
- Corpus path
mm/memtest.c- Extension
.c- Size
- 3592 bytes
- Lines
- 140
- 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/kernel.hlinux/types.hlinux/init.hlinux/memblock.hlinux/seq_file.h
Detected Declarations
function reserve_bad_memfunction memtestfunction do_one_passfunction for_each_free_mem_rangefunction parse_memtestfunction early_memtestfunction memtest_report_meminfo
Annotated Snippet
if (start_phys_aligned == last_bad + incr) {
last_bad += incr;
continue;
}
if (start_bad)
reserve_bad_mem(pattern, start_bad, last_bad + incr);
start_bad = last_bad = start_phys_aligned;
}
if (start_bad)
reserve_bad_mem(pattern, start_bad, last_bad + incr);
early_memtest_done = true;
}
static void __init do_one_pass(u64 pattern, phys_addr_t start, phys_addr_t end)
{
u64 i;
phys_addr_t this_start, this_end;
for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &this_start,
&this_end, NULL) {
this_start = clamp(this_start, start, end);
this_end = clamp(this_end, start, end);
if (this_start < this_end) {
pr_info(" %pa - %pa pattern %016llx\n",
&this_start, &this_end, cpu_to_be64(pattern));
memtest(pattern, this_start, this_end - this_start);
}
}
}
/* default is disabled */
static unsigned int memtest_pattern __initdata;
static int __init parse_memtest(char *arg)
{
int ret = 0;
if (arg)
ret = kstrtouint(arg, 0, &memtest_pattern);
else
memtest_pattern = ARRAY_SIZE(patterns);
return ret;
}
early_param("memtest", parse_memtest);
void __init early_memtest(phys_addr_t start, phys_addr_t end)
{
unsigned int i;
unsigned int idx = 0;
if (!memtest_pattern)
return;
pr_info("early_memtest: # of tests: %u\n", memtest_pattern);
for (i = memtest_pattern-1; i < UINT_MAX; --i) {
idx = i % ARRAY_SIZE(patterns);
do_one_pass(patterns[idx], start, end);
}
}
void memtest_report_meminfo(struct seq_file *m)
{
unsigned long early_memtest_bad_size_kb;
if (!IS_ENABLED(CONFIG_PROC_FS))
return;
if (!early_memtest_done)
return;
early_memtest_bad_size_kb = early_memtest_bad_size >> 10;
if (early_memtest_bad_size && !early_memtest_bad_size_kb)
early_memtest_bad_size_kb = 1;
/* When 0 is reported, it means there actually was a successful test */
seq_printf(m, "EarlyMemtestBad: %5lu kB\n", early_memtest_bad_size_kb);
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/init.h`, `linux/memblock.h`, `linux/seq_file.h`.
- Detected declarations: `function reserve_bad_mem`, `function memtest`, `function do_one_pass`, `function for_each_free_mem_range`, `function parse_memtest`, `function early_memtest`, `function memtest_report_meminfo`.
- 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.