thpcompact: can not punch holes
I want use thpcompact in mmtests to test the performance of memory compaction of Linux kernel. However, I have found that there may be some issues with thpcompact: thpcompact can not punch holes in kernel 5.10.
The detailed description is as follows:
The following code snippet is from thpcompact.c,its purpose is to use mmap to allocate a large amount of physical memory and then punch holes in it, thereby creating memory fragmentation. However, during testing, I found that this code did not create memory fragmentation because munmap did not deallocate memory. I found that the reason is using the madvise system call to indicate that the first_mapping needs to allocate huge pages when allocating physical memory. When I commented out the madvise system call, the following code snippet can punch holes to create memory fragmentation. So should we modify the code to remove the madvise system call here?
/* Create a large mapping */
first_mapping = mmap(NULL, anon_thread_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
if (first_mapping == MAP_FAILED) {
perror("First mapping");
exit(EXIT_FAILURE);
}
madvise(first_mapping, anon_thread_size, MADV_HUGEPAGE);
memset(first_mapping, 1, anon_thread_size);
/* Align index to huge page boundary */
end_mapping = first_mapping + anon_thread_size;
aligned = HPAGE_ALIGN(first_mapping);
i = aligned - first_mapping;
/* Punch holes */
for (; aligned + HPAGESIZE/2 < end_mapping; aligned += HPAGESIZE) {
munmap(aligned, HPAGESIZE/2);
}