tools/testing/selftests/mm/vm_util.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/vm_util.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/vm_util.c- Extension
.c- Size
- 17298 bytes
- Lines
- 791
- 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
string.herrno.hfcntl.hdirent.hinttypes.hsys/ioctl.hlinux/userfaultfd.hlinux/fs.hsys/syscall.hunistd.hkselftest.hvm_util.h
Detected Declarations
function pagemap_get_entryfunction __pagemap_scan_get_categoriesfunction pagemap_scan_get_categoriesfunction pagemap_scan_supportedfunction page_entry_isfunction pagemap_is_softdirtyfunction pagemap_is_swappedfunction pagemap_is_populatedfunction pagemap_get_pfnfunction clear_softdirtyfunction check_for_patternfunction read_pmd_pagesizefunction rss_anonfunction __check_hugefunction check_huge_anonfunction check_huge_filefunction check_huge_shmemfunction allocate_transhugefunction default_huge_page_sizefunction detect_hugetlb_page_sizesfunction pageflags_getfunction uffd_register_with_ioctlsfunction uffd_registerfunction uffd_unregisterfunction get_free_hugepagesfunction check_vmflagfunction check_vmflag_iofunction check_vmflag_pfnmapfunction check_vmflag_guardfunction softdirty_supportedfunction open_procmapfunction query_procmapfunction find_vma_procmapfunction close_procmapfunction write_sysfsfunction read_sysfsfunction detect_huge_zeropagefunction ksm_get_self_zero_pagesfunction ksm_get_self_merging_pagesfunction ksm_get_full_scansfunction ksm_use_zero_pagesfunction ksm_startfunction ksm_stopfunction get_hardware_corrupted_sizefunction unpoison_memoryfunction write_file
Annotated Snippet
if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) {
hps <<= 10;
break;
}
}
free(line);
fclose(f);
return hps;
}
int detect_hugetlb_page_sizes(size_t sizes[], int max)
{
DIR *dir = opendir("/sys/kernel/mm/hugepages/");
int count = 0;
if (!dir)
return 0;
while (count < max) {
struct dirent *entry = readdir(dir);
size_t kb;
if (!entry)
break;
if (entry->d_type != DT_DIR)
continue;
if (sscanf(entry->d_name, "hugepages-%zukB", &kb) != 1)
continue;
sizes[count++] = kb * 1024;
ksft_print_msg("[INFO] detected hugetlb page size: %zu KiB\n",
kb);
}
closedir(dir);
return count;
}
int pageflags_get(unsigned long pfn, int kpageflags_fd, uint64_t *flags)
{
size_t count;
count = pread(kpageflags_fd, flags, sizeof(*flags),
pfn * sizeof(*flags));
if (count != sizeof(*flags))
return -1;
return 0;
}
/* If `ioctls' non-NULL, the allowed ioctls will be returned into the var */
int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len,
bool miss, bool wp, bool minor, uint64_t *ioctls)
{
struct uffdio_register uffdio_register = { 0 };
uint64_t mode = 0;
int ret = 0;
if (miss)
mode |= UFFDIO_REGISTER_MODE_MISSING;
if (wp)
mode |= UFFDIO_REGISTER_MODE_WP;
if (minor)
mode |= UFFDIO_REGISTER_MODE_MINOR;
uffdio_register.range.start = (unsigned long)addr;
uffdio_register.range.len = len;
uffdio_register.mode = mode;
if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register) == -1)
ret = -errno;
else if (ioctls)
*ioctls = uffdio_register.ioctls;
return ret;
}
int uffd_register(int uffd, void *addr, uint64_t len,
bool miss, bool wp, bool minor)
{
return uffd_register_with_ioctls(uffd, addr, len,
miss, wp, minor, NULL);
}
int uffd_unregister(int uffd, void *addr, uint64_t len)
{
struct uffdio_range range = { .start = (uintptr_t)addr, .len = len };
int ret = 0;
if (ioctl(uffd, UFFDIO_UNREGISTER, &range) == -1)
Annotation
- Immediate include surface: `string.h`, `errno.h`, `fcntl.h`, `dirent.h`, `inttypes.h`, `sys/ioctl.h`, `linux/userfaultfd.h`, `linux/fs.h`.
- Detected declarations: `function pagemap_get_entry`, `function __pagemap_scan_get_categories`, `function pagemap_scan_get_categories`, `function pagemap_scan_supported`, `function page_entry_is`, `function pagemap_is_softdirty`, `function pagemap_is_swapped`, `function pagemap_is_populated`, `function pagemap_get_pfn`, `function clear_softdirty`.
- 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.