Skip to content

Commit

Permalink
tools/selftest/vm: allow choosing mem size and page size in map_hugetlb
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christophe Leroy authored and Michael Ellerman committed Feb 21, 2019
1 parent 6b9166f commit fa7b9a8
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions tools/testing/selftests/vm/map_hugetlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
#define MAP_HUGETLB 0x40000 /* arch specific */
#endif

#ifndef MAP_HUGE_SHIFT
#define MAP_HUGE_SHIFT 26
#endif

#ifndef MAP_HUGE_MASK
#define MAP_HUGE_MASK 0x3f
#endif

/* Only ia64 requires this */
#ifdef __ia64__
#define ADDR (void *)(0x8000000000000000UL)
Expand Down Expand Up @@ -58,12 +66,29 @@ static int read_bytes(char *addr)
return 0;
}

int main(void)
int main(int argc, char **argv)
{
void *addr;
int ret;
size_t length = LENGTH;
int flags = FLAGS;
int shift = 0;

if (argc > 1)
length = atol(argv[1]) << 20;
if (argc > 2) {
shift = atoi(argv[2]);
if (shift)
flags |= (shift & MAP_HUGE_MASK) << MAP_HUGE_SHIFT;
}

if (shift)
printf("%u kB hugepages\n", 1 << shift);
else
printf("Default size hugepages\n");
printf("Mapping %lu Mbytes\n", (unsigned long)length >> 20);

addr = mmap(ADDR, LENGTH, PROTECTION, FLAGS, -1, 0);
addr = mmap(ADDR, length, PROTECTION, flags, -1, 0);
if (addr == MAP_FAILED) {
perror("mmap");
exit(1);
Expand Down

0 comments on commit fa7b9a8

Please sign in to comment.