On Fri, 30 Jul 2021 15:15:22 -0700 Mina Almasry <almasrymina@xxxxxxxxxx> wrote: > Support mremap() for hugepage backed vma segment by simply repositioning > page table entries. The page table entries are repositioned to the new > virtual address on mremap(). > > Hugetlb mremap() support is of course generic; my motivating use case > is a library (hugepage_text), which reloads the ELF text of executables > in hugepages. This significantly increases the execution performance of > said executables. > > Restricts the mremap operation on hugepages to up to the size of the > original mapping as the underlying hugetlb reservation is not yet > capable of handling remapping to a larger size. > > Tested with a simple mmap/mremap test case, roughly: > > void* haddr = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, > MAP_ANONYMOUS | MAP_SHARED, -1, 0); > > void* taddr = mmap(NULL, size, PROT_NONE, > MAP_HUGETLB | MAP_ANONYMOUS | MAP_SHARED, -1, 0); > > void* raddr = mremap(haddr, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, taddr); Could we please get testing for this added into tools/testing/selftests/?