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

tools/selftest/vm: allow choosing mem size and page size in map_hugetlb

map_hugetlb maps 256Mbytes of memory with default hugepage size.

This patch allows the user to pass the size and page shift as an
argument in order to use different size and page size.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Christophe Leroy and committed by
Michael Ellerman
fa7b9a80 6b9166f0

+27 -2
+27 -2
tools/testing/selftests/vm/map_hugetlb.c
··· 23 23 #define MAP_HUGETLB 0x40000 /* arch specific */ 24 24 #endif 25 25 26 + #ifndef MAP_HUGE_SHIFT 27 + #define MAP_HUGE_SHIFT 26 28 + #endif 29 + 30 + #ifndef MAP_HUGE_MASK 31 + #define MAP_HUGE_MASK 0x3f 32 + #endif 33 + 26 34 /* Only ia64 requires this */ 27 35 #ifdef __ia64__ 28 36 #define ADDR (void *)(0x8000000000000000UL) ··· 66 58 return 0; 67 59 } 68 60 69 - int main(void) 61 + int main(int argc, char **argv) 70 62 { 71 63 void *addr; 72 64 int ret; 65 + size_t length = LENGTH; 66 + int flags = FLAGS; 67 + int shift = 0; 73 68 74 - addr = mmap(ADDR, LENGTH, PROTECTION, FLAGS, -1, 0); 69 + if (argc > 1) 70 + length = atol(argv[1]) << 20; 71 + if (argc > 2) { 72 + shift = atoi(argv[2]); 73 + if (shift) 74 + flags |= (shift & MAP_HUGE_MASK) << MAP_HUGE_SHIFT; 75 + } 76 + 77 + if (shift) 78 + printf("%u kB hugepages\n", 1 << shift); 79 + else 80 + printf("Default size hugepages\n"); 81 + printf("Mapping %lu Mbytes\n", (unsigned long)length >> 20); 82 + 83 + addr = mmap(ADDR, length, PROTECTION, flags, -1, 0); 75 84 if (addr == MAP_FAILED) { 76 85 perror("mmap"); 77 86 exit(1);