Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thpcompact: can not punch holes #27

Open
csbo98 opened this issue Jul 24, 2024 · 0 comments
Open

thpcompact: can not punch holes #27

csbo98 opened this issue Jul 24, 2024 · 0 comments

Comments

@csbo98
Copy link

csbo98 commented Jul 24, 2024

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);
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant