Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftest/mremap_test: update the test to handle pagesize other than 4K

Patch series "mrermap fixes", v2.

This patch (of 6):

Instead of hardcoding 4K page size fetch it using sysconf(). For the
performance measurements test still assume 2M and 1G are hugepage sizes.

Link: https://lkml.kernel.org/r/20210616045239.370802-1-aneesh.kumar@linux.ibm.com
Link: https://lkml.kernel.org/r/20210616045239.370802-2-aneesh.kumar@linux.ibm.com
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Reviewed-by: Kalesh Singh <kaleshsingh@google.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Hugh Dickins <hughd@google.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Aneesh Kumar K.V and committed by
Linus Torvalds
f27a5c93 dc4875f0

+56 -47
+56 -47
tools/testing/selftests/vm/mremap_test.c
··· 45 45 _4MB = 4ULL << 20, 46 46 _1GB = 1ULL << 30, 47 47 _2GB = 2ULL << 30, 48 - PTE = _4KB, 49 48 PMD = _2MB, 50 49 PUD = _1GB, 51 50 }; 52 51 52 + #define PTE page_size 53 + 53 54 #define MAKE_TEST(source_align, destination_align, size, \ 54 55 overlaps, should_fail, test_name) \ 55 - { \ 56 + (struct test){ \ 56 57 .name = test_name, \ 57 58 .config = { \ 58 59 .src_alignment = source_align, \ ··· 253 252 return 0; 254 253 } 255 254 255 + #define MAX_TEST 13 256 + #define MAX_PERF_TEST 3 256 257 int main(int argc, char **argv) 257 258 { 258 259 int failures = 0; 259 260 int i, run_perf_tests; 260 261 unsigned int threshold_mb = VALIDATION_DEFAULT_THRESHOLD; 261 262 unsigned int pattern_seed; 263 + struct test test_cases[MAX_TEST]; 264 + struct test perf_test_cases[MAX_PERF_TEST]; 265 + int page_size; 262 266 time_t t; 263 267 264 268 pattern_seed = (unsigned int) time(&t); ··· 274 268 ksft_print_msg("Test configs:\n\tthreshold_mb=%u\n\tpattern_seed=%u\n\n", 275 269 threshold_mb, pattern_seed); 276 270 277 - struct test test_cases[] = { 278 - /* Expected mremap failures */ 279 - MAKE_TEST(_4KB, _4KB, _4KB, OVERLAPPING, EXPECT_FAILURE, 280 - "mremap - Source and Destination Regions Overlapping"), 281 - MAKE_TEST(_4KB, _1KB, _4KB, NON_OVERLAPPING, EXPECT_FAILURE, 282 - "mremap - Destination Address Misaligned (1KB-aligned)"), 283 - MAKE_TEST(_1KB, _4KB, _4KB, NON_OVERLAPPING, EXPECT_FAILURE, 284 - "mremap - Source Address Misaligned (1KB-aligned)"), 271 + page_size = sysconf(_SC_PAGESIZE); 285 272 286 - /* Src addr PTE aligned */ 287 - MAKE_TEST(PTE, PTE, _8KB, NON_OVERLAPPING, EXPECT_SUCCESS, 288 - "8KB mremap - Source PTE-aligned, Destination PTE-aligned"), 273 + /* Expected mremap failures */ 274 + test_cases[0] = MAKE_TEST(page_size, page_size, page_size, 275 + OVERLAPPING, EXPECT_FAILURE, 276 + "mremap - Source and Destination Regions Overlapping"); 289 277 290 - /* Src addr 1MB aligned */ 291 - MAKE_TEST(_1MB, PTE, _2MB, NON_OVERLAPPING, EXPECT_SUCCESS, 292 - "2MB mremap - Source 1MB-aligned, Destination PTE-aligned"), 293 - MAKE_TEST(_1MB, _1MB, _2MB, NON_OVERLAPPING, EXPECT_SUCCESS, 294 - "2MB mremap - Source 1MB-aligned, Destination 1MB-aligned"), 278 + test_cases[1] = MAKE_TEST(page_size, page_size/4, page_size, 279 + NON_OVERLAPPING, EXPECT_FAILURE, 280 + "mremap - Destination Address Misaligned (1KB-aligned)"); 281 + test_cases[2] = MAKE_TEST(page_size/4, page_size, page_size, 282 + NON_OVERLAPPING, EXPECT_FAILURE, 283 + "mremap - Source Address Misaligned (1KB-aligned)"); 295 284 296 - /* Src addr PMD aligned */ 297 - MAKE_TEST(PMD, PTE, _4MB, NON_OVERLAPPING, EXPECT_SUCCESS, 298 - "4MB mremap - Source PMD-aligned, Destination PTE-aligned"), 299 - MAKE_TEST(PMD, _1MB, _4MB, NON_OVERLAPPING, EXPECT_SUCCESS, 300 - "4MB mremap - Source PMD-aligned, Destination 1MB-aligned"), 301 - MAKE_TEST(PMD, PMD, _4MB, NON_OVERLAPPING, EXPECT_SUCCESS, 302 - "4MB mremap - Source PMD-aligned, Destination PMD-aligned"), 285 + /* Src addr PTE aligned */ 286 + test_cases[3] = MAKE_TEST(PTE, PTE, PTE * 2, 287 + NON_OVERLAPPING, EXPECT_SUCCESS, 288 + "8KB mremap - Source PTE-aligned, Destination PTE-aligned"); 303 289 304 - /* Src addr PUD aligned */ 305 - MAKE_TEST(PUD, PTE, _2GB, NON_OVERLAPPING, EXPECT_SUCCESS, 306 - "2GB mremap - Source PUD-aligned, Destination PTE-aligned"), 307 - MAKE_TEST(PUD, _1MB, _2GB, NON_OVERLAPPING, EXPECT_SUCCESS, 308 - "2GB mremap - Source PUD-aligned, Destination 1MB-aligned"), 309 - MAKE_TEST(PUD, PMD, _2GB, NON_OVERLAPPING, EXPECT_SUCCESS, 310 - "2GB mremap - Source PUD-aligned, Destination PMD-aligned"), 311 - MAKE_TEST(PUD, PUD, _2GB, NON_OVERLAPPING, EXPECT_SUCCESS, 312 - "2GB mremap - Source PUD-aligned, Destination PUD-aligned"), 313 - }; 290 + /* Src addr 1MB aligned */ 291 + test_cases[4] = MAKE_TEST(_1MB, PTE, _2MB, NON_OVERLAPPING, EXPECT_SUCCESS, 292 + "2MB mremap - Source 1MB-aligned, Destination PTE-aligned"); 293 + test_cases[5] = MAKE_TEST(_1MB, _1MB, _2MB, NON_OVERLAPPING, EXPECT_SUCCESS, 294 + "2MB mremap - Source 1MB-aligned, Destination 1MB-aligned"); 314 295 315 - struct test perf_test_cases[] = { 316 - /* 317 - * mremap 1GB region - Page table level aligned time 318 - * comparison. 319 - */ 320 - MAKE_TEST(PTE, PTE, _1GB, NON_OVERLAPPING, EXPECT_SUCCESS, 321 - "1GB mremap - Source PTE-aligned, Destination PTE-aligned"), 322 - MAKE_TEST(PMD, PMD, _1GB, NON_OVERLAPPING, EXPECT_SUCCESS, 323 - "1GB mremap - Source PMD-aligned, Destination PMD-aligned"), 324 - MAKE_TEST(PUD, PUD, _1GB, NON_OVERLAPPING, EXPECT_SUCCESS, 325 - "1GB mremap - Source PUD-aligned, Destination PUD-aligned"), 326 - }; 296 + /* Src addr PMD aligned */ 297 + test_cases[6] = MAKE_TEST(PMD, PTE, _4MB, NON_OVERLAPPING, EXPECT_SUCCESS, 298 + "4MB mremap - Source PMD-aligned, Destination PTE-aligned"); 299 + test_cases[7] = MAKE_TEST(PMD, _1MB, _4MB, NON_OVERLAPPING, EXPECT_SUCCESS, 300 + "4MB mremap - Source PMD-aligned, Destination 1MB-aligned"); 301 + test_cases[8] = MAKE_TEST(PMD, PMD, _4MB, NON_OVERLAPPING, EXPECT_SUCCESS, 302 + "4MB mremap - Source PMD-aligned, Destination PMD-aligned"); 303 + 304 + /* Src addr PUD aligned */ 305 + test_cases[9] = MAKE_TEST(PUD, PTE, _2GB, NON_OVERLAPPING, EXPECT_SUCCESS, 306 + "2GB mremap - Source PUD-aligned, Destination PTE-aligned"); 307 + test_cases[10] = MAKE_TEST(PUD, _1MB, _2GB, NON_OVERLAPPING, EXPECT_SUCCESS, 308 + "2GB mremap - Source PUD-aligned, Destination 1MB-aligned"); 309 + test_cases[11] = MAKE_TEST(PUD, PMD, _2GB, NON_OVERLAPPING, EXPECT_SUCCESS, 310 + "2GB mremap - Source PUD-aligned, Destination PMD-aligned"); 311 + test_cases[12] = MAKE_TEST(PUD, PUD, _2GB, NON_OVERLAPPING, EXPECT_SUCCESS, 312 + "2GB mremap - Source PUD-aligned, Destination PUD-aligned"); 313 + 314 + perf_test_cases[0] = MAKE_TEST(page_size, page_size, _1GB, NON_OVERLAPPING, EXPECT_SUCCESS, 315 + "1GB mremap - Source PTE-aligned, Destination PTE-aligned"); 316 + /* 317 + * mremap 1GB region - Page table level aligned time 318 + * comparison. 319 + */ 320 + perf_test_cases[1] = MAKE_TEST(PMD, PMD, _1GB, NON_OVERLAPPING, EXPECT_SUCCESS, 321 + "1GB mremap - Source PMD-aligned, Destination PMD-aligned"); 322 + perf_test_cases[2] = MAKE_TEST(PUD, PUD, _1GB, NON_OVERLAPPING, EXPECT_SUCCESS, 323 + "1GB mremap - Source PUD-aligned, Destination PUD-aligned"); 327 324 328 325 run_perf_tests = (threshold_mb == VALIDATION_NO_THRESHOLD) || 329 326 (threshold_mb * _1MB >= _1GB);