This patch addresses a longstanding TODO comment in the userfaultfd tests,
'/linux/tools/testing/selftests/mm/uffd-common.c'
("/* Use a static addr is ugly */") by replacing hardcoded 1GB addresses
with dynamic allocation. I'd appreciate your review.
The Problem
------------
The current static address approach:
- Causes test failures when other mappings occupy the 1GB region
- Prevents parallel test execution (critical for modern CI/CD systems)
- Breaks on systems with unusual memory layouts
The Solution
------------
I implemented a find_suitable_area() helper that:
- Asks the kernel for suggested addresses via mmap(NULL)
- Automatically aligns for huge pages when needed
- Uses MAP_FIXED_NOREPLACE where available (graceful fallback otherwise)
- Adds guard pages between mappings to prevent VMA merging
Validation
----------
I did multiple tests on my implementation to make sure it worked like:
- Multiple parallel test runs
- Memory pressure scenarios
- Edge cases (unusual alignments, sizes, etc.)
- Race conditions and concurrent access
Performance impact is minimal , about 1.2x overhead compared to the static
approach in benchmarks.
Why This Matters
----------------
- Removes longstanding TODO from the codebase
- Enables safe parallel testing
- Makes tests portable to different environments and memory layouts
- Improves overall test reliability
This is my first PR for the Linux Kernel and I would be
grateful for your feedback!
Signed-off-by: MrMartyK <martykareem@xxxxxxxxxxx>
|