tools/testing/selftests/mm/thp_settings.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/thp_settings.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/thp_settings.c- Extension
.c- Size
- 8710 bytes
- Lines
- 373
- 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
fcntl.hlimits.hstdio.hstdlib.hstring.hunistd.hvm_util.hthp_settings.h
Detected Declarations
function read_filefunction read_numfunction write_numfunction thp_read_stringfunction thp_write_stringfunction thp_read_numfunction thp_write_numfunction thp_read_settingsfunction thp_write_settingsfunction thp_push_settingsfunction thp_pop_settingsfunction thp_restore_settingsfunction thp_save_settingsfunction thp_set_read_ahead_pathfunction __thp_supported_ordersfunction thp_supported_ordersfunction thp_shmem_supported_ordersfunction thp_availablefunction thp_is_enabled
Annotated Snippet
if (!((1 << i) & orders)) {
settings->hugepages[i].enabled = THP_NEVER;
continue;
}
snprintf(path, PATH_MAX, "hugepages-%ukB/enabled",
(getpagesize() >> 10) << i);
settings->hugepages[i].enabled =
thp_read_string(path, thp_enabled_strings);
}
for (i = 0; i < NR_ORDERS; i++) {
if (!((1 << i) & shmem_orders)) {
settings->shmem_hugepages[i].enabled = SHMEM_NEVER;
continue;
}
snprintf(path, PATH_MAX, "hugepages-%ukB/shmem_enabled",
(getpagesize() >> 10) << i);
settings->shmem_hugepages[i].enabled =
thp_read_string(path, shmem_enabled_strings);
}
}
void thp_write_settings(struct thp_settings *settings)
{
struct khugepaged_settings *khugepaged = &settings->khugepaged;
unsigned long orders = thp_supported_orders();
unsigned long shmem_orders = thp_shmem_supported_orders();
char path[PATH_MAX];
int enabled;
int i;
thp_write_string("enabled", thp_enabled_strings[settings->thp_enabled]);
thp_write_string("defrag", thp_defrag_strings[settings->thp_defrag]);
thp_write_string("shmem_enabled",
shmem_enabled_strings[settings->shmem_enabled]);
thp_write_num("use_zero_page", settings->use_zero_page);
thp_write_num("khugepaged/defrag", khugepaged->defrag);
thp_write_num("khugepaged/alloc_sleep_millisecs",
khugepaged->alloc_sleep_millisecs);
thp_write_num("khugepaged/scan_sleep_millisecs",
khugepaged->scan_sleep_millisecs);
thp_write_num("khugepaged/max_ptes_none", khugepaged->max_ptes_none);
thp_write_num("khugepaged/max_ptes_swap", khugepaged->max_ptes_swap);
thp_write_num("khugepaged/max_ptes_shared", khugepaged->max_ptes_shared);
thp_write_num("khugepaged/pages_to_scan", khugepaged->pages_to_scan);
if (dev_queue_read_ahead_path[0])
write_num(dev_queue_read_ahead_path, settings->read_ahead_kb);
for (i = 0; i < NR_ORDERS; i++) {
if (!((1 << i) & orders))
continue;
snprintf(path, PATH_MAX, "hugepages-%ukB/enabled",
(getpagesize() >> 10) << i);
enabled = settings->hugepages[i].enabled;
thp_write_string(path, thp_enabled_strings[enabled]);
}
for (i = 0; i < NR_ORDERS; i++) {
if (!((1 << i) & shmem_orders))
continue;
snprintf(path, PATH_MAX, "hugepages-%ukB/shmem_enabled",
(getpagesize() >> 10) << i);
enabled = settings->shmem_hugepages[i].enabled;
thp_write_string(path, shmem_enabled_strings[enabled]);
}
}
struct thp_settings *thp_current_settings(void)
{
if (!settings_index) {
printf("Fail: No settings set");
exit(EXIT_FAILURE);
}
return settings_stack + settings_index - 1;
}
void thp_push_settings(struct thp_settings *settings)
{
if (settings_index >= MAX_SETTINGS_DEPTH) {
printf("Fail: Settings stack exceeded");
exit(EXIT_FAILURE);
}
settings_stack[settings_index++] = *settings;
thp_write_settings(thp_current_settings());
}
void thp_pop_settings(void)
{
Annotation
- Immediate include surface: `fcntl.h`, `limits.h`, `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`, `vm_util.h`, `thp_settings.h`.
- Detected declarations: `function read_file`, `function read_num`, `function write_num`, `function thp_read_string`, `function thp_write_string`, `function thp_read_num`, `function thp_write_num`, `function thp_read_settings`, `function thp_write_settings`, `function thp_push_settings`.
- 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.