tools/testing/selftests/mm/vm_util.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/vm_util.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/vm_util.h- Extension
.h- Size
- 5644 bytes
- Lines
- 171
- 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
stdint.hstdbool.hsys/mman.herr.hstdarg.hstrings.hunistd.hkselftest.hlinux/fs.h
Detected Declarations
struct procmap_fdfunction psizefunction pshiftfunction force_read_pagesfunction bugsfunction open_self_procmapfunction log_test_startfunction log_test_resultfunction sz2ord
Annotated Snippet
struct procmap_fd {
int fd;
struct procmap_query query;
};
static inline unsigned int psize(void)
{
if (!__page_size)
__page_size = sysconf(_SC_PAGESIZE);
return __page_size;
}
static inline unsigned int pshift(void)
{
if (!__page_shift)
__page_shift = (ffsl(psize()) - 1);
return __page_shift;
}
static inline void force_read_pages(char *addr, unsigned int nr_pages,
size_t pagesize)
{
for (unsigned int i = 0; i < nr_pages; i++)
FORCE_READ(addr[i * pagesize]);
}
bool detect_huge_zeropage(void);
/*
* Plan 9 FS has bugs (at least on QEMU) where certain operations fail with
* ENOENT on unlinked files. See
* https://gitlab.com/qemu-project/qemu/-/issues/103 for some info about such
* bugs. There are rumours of NFS implementations with similar bugs.
*
* Ideally, tests should just detect filesystems known to have such issues and
* bail early. But 9pfs has the additional "feature" that it causes fstatfs to
* pass through the f_type field from the host filesystem. To avoid having to
* scrape /proc/mounts or some other hackery, tests can call this function when
* it seems such a bug might have been encountered.
*/
static inline void skip_test_dodgy_fs(const char *op_name)
{
ksft_test_result_skip("%s failed with ENOENT. Filesystem might be buggy (9pfs?)\n", op_name);
}
uint64_t pagemap_get_entry(int fd, char *start);
bool pagemap_is_softdirty(int fd, char *start);
bool pagemap_is_swapped(int fd, char *start);
bool pagemap_is_populated(int fd, char *start);
unsigned long pagemap_get_pfn(int fd, char *start);
void clear_softdirty(void);
bool check_for_pattern(FILE *fp, const char *pattern, char *buf, size_t len);
uint64_t read_pmd_pagesize(void);
unsigned long rss_anon(void);
bool check_huge_anon(void *addr, int nr_hpages, uint64_t hpage_size);
bool check_huge_file(void *addr, int nr_hpages, uint64_t hpage_size);
bool check_huge_shmem(void *addr, int nr_hpages, uint64_t hpage_size);
int64_t allocate_transhuge(void *ptr, int pagemap_fd);
unsigned long default_huge_page_size(void);
int detect_hugetlb_page_sizes(size_t sizes[], int max);
int pageflags_get(unsigned long pfn, int kpageflags_fd, uint64_t *flags);
int uffd_register(int uffd, void *addr, uint64_t len,
bool miss, bool wp, bool minor);
int uffd_unregister(int uffd, void *addr, uint64_t len);
int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len,
bool miss, bool wp, bool minor, uint64_t *ioctls);
unsigned long get_free_hugepages(void);
bool check_vmflag_io(void *addr);
bool check_vmflag_pfnmap(void *addr);
bool check_vmflag_guard(void *addr);
int open_procmap(pid_t pid, struct procmap_fd *procmap_out);
int query_procmap(struct procmap_fd *procmap);
bool find_vma_procmap(struct procmap_fd *procmap, void *address);
int close_procmap(struct procmap_fd *procmap);
int write_sysfs(const char *file_path, unsigned long val);
int read_sysfs(const char *file_path, unsigned long *val);
bool softdirty_supported(void);
static inline int open_self_procmap(struct procmap_fd *procmap_out)
{
pid_t pid = getpid();
return open_procmap(pid, procmap_out);
}
/* These helpers need to be inline to match the kselftest.h idiom. */
static char test_name[1024];
static inline void log_test_start(const char *name, ...)
Annotation
- Immediate include surface: `stdint.h`, `stdbool.h`, `sys/mman.h`, `err.h`, `stdarg.h`, `strings.h`, `unistd.h`, `kselftest.h`.
- Detected declarations: `struct procmap_fd`, `function psize`, `function pshift`, `function force_read_pages`, `function bugs`, `function open_self_procmap`, `function log_test_start`, `function log_test_result`, `function sz2ord`.
- 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.