tools/testing/selftests/mm/mremap_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/mremap_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/mremap_test.c- Extension
.c- Size
- 36267 bytes
- Lines
- 1397
- 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
errno.hfcntl.hlinux/userfaultfd.hstdlib.hstdio.hstring.hsys/ioctl.hsys/mman.hsyscall.htime.hstdbool.hkselftest.h
Detected Declarations
struct configstruct testfunction mappingfunction get_mmap_min_addrfunction is_range_mappedfunction is_ptr_mappedfunction mremap_expand_mergefunction mremap_expand_mergefunction mremap_move_within_rangefunction is_multiple_vma_range_okfunction mremap_move_multiple_vmasfunction mremap_shrink_multiple_vmasfunction mremap_move_multiple_vmas_splitfunction mremap_move_multi_invalid_vmasfunction mremap_move_multi_invalid_vmasfunction remap_regionfunction memcmpfunction mremap_move_1mb_from_startfunction run_mremap_test_casefunction usagefunction parse_argsfunction main
Annotated Snippet
struct config {
unsigned long long src_alignment;
unsigned long long dest_alignment;
unsigned long long region_size;
int overlapping;
unsigned int dest_preamble_size;
};
struct test {
const char *name;
struct config config;
int expect_failure;
};
enum {
_1KB = 1ULL << 10, /* 1KB -> not page aligned */
_4KB = 4ULL << 10,
_8KB = 8ULL << 10,
_1MB = 1ULL << 20,
_2MB = 2ULL << 20,
_4MB = 4ULL << 20,
_5MB = 5ULL << 20,
_1GB = 1ULL << 30,
_2GB = 2ULL << 30,
PMD = _2MB,
PUD = _1GB,
};
#define PTE page_size
#define MAKE_TEST(source_align, destination_align, size, \
overlaps, should_fail, test_name) \
(struct test){ \
.name = test_name, \
.config = { \
.src_alignment = source_align, \
.dest_alignment = destination_align, \
.region_size = size, \
.overlapping = overlaps, \
}, \
.expect_failure = should_fail \
}
/*
* Returns false if the requested remap region overlaps with an
* existing mapping (e.g text, stack) else returns true.
*/
static bool is_remap_region_valid(void *addr, unsigned long long size)
{
void *remap_addr = NULL;
bool ret = true;
/* Use MAP_FIXED_NOREPLACE flag to ensure region is not mapped */
remap_addr = mmap(addr, size, PROT_READ | PROT_WRITE,
MAP_FIXED_NOREPLACE | MAP_ANONYMOUS | MAP_SHARED,
-1, 0);
if (remap_addr == MAP_FAILED) {
if (errno == EEXIST)
ret = false;
} else {
munmap(remap_addr, size);
}
return ret;
}
/* Returns mmap_min_addr sysctl tunable from procfs */
static unsigned long long get_mmap_min_addr(void)
{
FILE *fp;
int n_matched;
static unsigned long long addr;
if (addr)
return addr;
fp = fopen("/proc/sys/vm/mmap_min_addr", "r");
if (fp == NULL) {
ksft_print_msg("Failed to open /proc/sys/vm/mmap_min_addr: %s\n",
strerror(errno));
exit(KSFT_SKIP);
}
n_matched = fscanf(fp, "%llu", &addr);
if (n_matched != 1) {
ksft_print_msg("Failed to read /proc/sys/vm/mmap_min_addr: %s\n",
strerror(errno));
fclose(fp);
exit(KSFT_SKIP);
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `linux/userfaultfd.h`, `stdlib.h`, `stdio.h`, `string.h`, `sys/ioctl.h`, `sys/mman.h`.
- Detected declarations: `struct config`, `struct test`, `function mapping`, `function get_mmap_min_addr`, `function is_range_mapped`, `function is_ptr_mapped`, `function mremap_expand_merge`, `function mremap_expand_merge`, `function mremap_move_within_range`, `function is_multiple_vma_range_ok`.
- 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.