tools/testing/selftests/mm/khugepaged.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/khugepaged.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/khugepaged.c- Extension
.c- Size
- 33133 bytes
- Lines
- 1303
- 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
ctype.herrno.hfcntl.hlimits.hdirent.hsignal.hstdio.hstdlib.hstdbool.hstring.hunistd.hlinux/mman.hsys/mman.hsys/wait.hsys/types.hsys/stat.hsys/sysmacros.hsys/vfs.hlinux/magic.hvm_util.hthp_settings.h
Detected Declarations
struct mem_opsstruct collapse_contextstruct file_infoenum vma_typefunction successfunction failfunction skipfunction restore_settings_atexitfunction restore_settingsfunction save_settingsfunction get_finfofunction majorfunction check_swapfunction fill_memoryfunction madvise_collapse_retryfunction validate_memoryfunction validate_memoryfunction anon_cleanup_areafunction anon_faultfunction anon_check_hugefunction file_cleanup_areafunction file_faultfunction file_check_hugefunction shmem_cleanup_areafunction shmem_check_hugefunction __madvise_collapsefunction madvise_collapsefunction wait_for_scanfunction khugepaged_collapsefunction is_tmpfsfunction is_anonfunction alloc_at_faultfunction collapse_fullfunction collapse_emptyfunction collapse_single_pte_entryfunction collapse_max_ptes_nonefunction collapse_swapin_single_ptefunction collapse_max_ptes_swapfunction collapse_single_pte_entry_compoundfunction collapse_full_of_compoundfunction collapse_compound_extremefunction collapse_forkfunction collapse_fork_compoundfunction collapse_max_ptes_sharedfunction madvise_collapse_existing_thpsfunction madvise_retracted_page_tablesfunction usagefunction parse_test_type
Annotated Snippet
struct mem_ops {
void *(*setup_area)(int nr_hpages);
void (*cleanup_area)(void *p, unsigned long size);
void (*fault)(void *p, unsigned long start, unsigned long end);
bool (*check_huge)(void *addr, int nr_hpages);
const char *name;
};
static struct mem_ops *file_ops;
static struct mem_ops *anon_ops;
static struct mem_ops *shmem_ops;
struct collapse_context {
void (*collapse)(const char *msg, char *p, int nr_hpages,
struct mem_ops *ops, bool expect);
bool enforce_pte_scan_limits;
const char *name;
};
static struct collapse_context *khugepaged_context;
static struct collapse_context *madvise_context;
struct file_info {
const char *dir;
char path[PATH_MAX];
enum vma_type type;
int fd;
char dev_queue_read_ahead_path[PATH_MAX];
};
static struct file_info finfo;
static bool skip_settings_restore;
static int exit_status;
static void success(const char *msg)
{
printf(" \e[32m%s\e[0m\n", msg);
}
static void fail(const char *msg)
{
printf(" \e[31m%s\e[0m\n", msg);
exit_status++;
}
static void skip(const char *msg)
{
printf(" \e[33m%s\e[0m\n", msg);
}
static void restore_settings_atexit(void)
{
if (skip_settings_restore)
return;
printf("Restore THP and khugepaged settings...");
thp_restore_settings();
success("OK");
skip_settings_restore = true;
}
static void restore_settings(int sig)
{
/* exit() will invoke the restore_settings_atexit handler. */
exit(sig ? EXIT_FAILURE : exit_status);
}
static void save_settings(void)
{
printf("Save THP and khugepaged settings...");
if (file_ops && finfo.type == VMA_FILE)
thp_set_read_ahead_path(finfo.dev_queue_read_ahead_path);
thp_save_settings();
success("OK");
atexit(restore_settings_atexit);
signal(SIGTERM, restore_settings);
signal(SIGINT, restore_settings);
signal(SIGHUP, restore_settings);
signal(SIGQUIT, restore_settings);
}
static void get_finfo(const char *dir)
{
struct stat path_stat;
struct statfs fs;
char buf[1 << 10];
char path[PATH_MAX];
Annotation
- Immediate include surface: `ctype.h`, `errno.h`, `fcntl.h`, `limits.h`, `dirent.h`, `signal.h`, `stdio.h`, `stdlib.h`.
- Detected declarations: `struct mem_ops`, `struct collapse_context`, `struct file_info`, `enum vma_type`, `function success`, `function fail`, `function skip`, `function restore_settings_atexit`, `function restore_settings`, `function save_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.