#!/usr/bin/env python

# make a 20MB or so file on lustre, and pass in the filename as an arg to this script.
# have THP enabled - madvise or always.
# run this code at the same time on 2 nodes.

import os, sys, mmap, time

filename=sys.argv[1]
minsize=20433200

fd = os.open(filename, os.O_RDWR|os.O_CREAT|getattr(os, "O_DIRECT", 0))

if os.fstat(fd).st_size < minsize:
    print('no. please make the file size large-ish... say 20433200 or greater')
    sys.exit(1)

size = os.fstat(fd).st_size
mem = mmap.mmap(fd, size)
hp = getattr(mmap, "MADV_HUGEPAGE", None)
mem.madvise(hp)

o = mem.read()
print(len(o))
#time.sleep(5)
os.close(fd)
