tools/testing/selftests/mm/ksm_tests.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/ksm_tests.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/ksm_tests.c- Extension
.c- Size
- 26382 bytes
- Lines
- 927
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/mman.hsys/prctl.hsys/wait.hstdbool.htime.hstring.hnuma.hunistd.hfcntl.hstdint.herr.hkselftest.hinclude/vdso/time64.hvm_util.hthp_settings.h
Detected Declarations
struct ksm_sysfsenum ksm_merge_typeenum ksm_test_namefunction ksm_write_sysfsfunction ksm_read_sysfsfunction ksm_print_sysfsfunction ksm_print_procfsfunction str_to_protfunction print_helpfunction ksm_do_scanfunction ksm_merge_pagesfunction ksm_unmerge_pagesfunction assert_ksm_pages_countfunction pagesfunction ksm_save_deffunction ksm_restorefunction check_ksm_mergefunction check_ksm_unmergefunction check_ksm_zero_page_mergefunction get_next_mem_nodefunction get_first_mem_nodefunction check_ksm_numa_mergefunction ksm_merge_hugepages_timefunction ksm_merge_timefunction ksm_unmerge_timefunction ksm_cow_timefunction main
Annotated Snippet
struct ksm_sysfs {
unsigned long max_page_sharing;
unsigned long merge_across_nodes;
unsigned long pages_to_scan;
unsigned long run;
unsigned long sleep_millisecs;
unsigned long stable_node_chains_prune_millisecs;
unsigned long use_zero_pages;
};
enum ksm_merge_type {
KSM_MERGE_MADVISE,
KSM_MERGE_PRCTL,
KSM_MERGE_LAST = KSM_MERGE_PRCTL
};
enum ksm_test_name {
CHECK_KSM_MERGE,
CHECK_KSM_UNMERGE,
CHECK_KSM_GET_MERGE_TYPE,
CHECK_KSM_ZERO_PAGE_MERGE,
CHECK_KSM_NUMA_MERGE,
KSM_MERGE_TIME,
KSM_MERGE_TIME_HUGE_PAGES,
KSM_UNMERGE_TIME,
KSM_COW_TIME
};
int debug;
static int ksm_write_sysfs(const char *file_path, unsigned long val)
{
return write_sysfs(file_path, val);
}
static int ksm_read_sysfs(const char *file_path, unsigned long *val)
{
return read_sysfs(file_path, val);
}
static void ksm_print_sysfs(void)
{
unsigned long max_page_sharing, pages_sharing, pages_shared;
unsigned long full_scans, pages_unshared, pages_volatile;
unsigned long stable_node_chains, stable_node_dups;
long general_profit;
if (ksm_read_sysfs(KSM_FP("pages_shared"), &pages_shared) ||
ksm_read_sysfs(KSM_FP("pages_sharing"), &pages_sharing) ||
ksm_read_sysfs(KSM_FP("max_page_sharing"), &max_page_sharing) ||
ksm_read_sysfs(KSM_FP("full_scans"), &full_scans) ||
ksm_read_sysfs(KSM_FP("pages_unshared"), &pages_unshared) ||
ksm_read_sysfs(KSM_FP("pages_volatile"), &pages_volatile) ||
ksm_read_sysfs(KSM_FP("stable_node_chains"), &stable_node_chains) ||
ksm_read_sysfs(KSM_FP("stable_node_dups"), &stable_node_dups) ||
ksm_read_sysfs(KSM_FP("general_profit"), (unsigned long *)&general_profit))
return;
printf("pages_shared : %lu\n", pages_shared);
printf("pages_sharing : %lu\n", pages_sharing);
printf("max_page_sharing : %lu\n", max_page_sharing);
printf("full_scans : %lu\n", full_scans);
printf("pages_unshared : %lu\n", pages_unshared);
printf("pages_volatile : %lu\n", pages_volatile);
printf("stable_node_chains: %lu\n", stable_node_chains);
printf("stable_node_dups : %lu\n", stable_node_dups);
printf("general_profit : %ld\n", general_profit);
}
static void ksm_print_procfs(void)
{
const char *file_name = "/proc/self/ksm_stat";
char buffer[512];
FILE *f = fopen(file_name, "r");
if (!f) {
fprintf(stderr, "f %s\n", file_name);
perror("fopen");
return;
}
while (fgets(buffer, sizeof(buffer), f))
printf("%s", buffer);
fclose(f);
}
static int str_to_prot(char *prot_str)
{
int prot = 0;
Annotation
- Immediate include surface: `sys/mman.h`, `sys/prctl.h`, `sys/wait.h`, `stdbool.h`, `time.h`, `string.h`, `numa.h`, `unistd.h`.
- Detected declarations: `struct ksm_sysfs`, `enum ksm_merge_type`, `enum ksm_test_name`, `function ksm_write_sysfs`, `function ksm_read_sysfs`, `function ksm_print_sysfs`, `function ksm_print_procfs`, `function str_to_prot`, `function print_help`, `function ksm_do_scan`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.