• Barry Song's avatar
    tools/mm: introduce a tool to assess swap entry allocation for thp_swapout · 95139d94
    Barry Song authored
    Both Ryan and Chris have been utilizing the small test program to aid in
    debugging and identifying issues with swap entry allocation.  While a real
    or intricate workload might be more suitable for assessing the correctness
    and effectiveness of the swap allocation policy, a small test program
    presents a simpler means of understanding the problem and initially
    verifying the improvements being made.
    
    Let's endeavor to integrate it into tools/mm.  Although it presently only
    accommodates 64KB and 4KB, I'm optimistic that we can expand its
    capabilities to support multiple sizes and simulate more complex systems
    in the future as required.
    
    Basically, we have
    
    1. Use MADV_PAGEPUT for rapid swap-out, putting the swap allocation
       code under high exercise in a short time.
    
    2. Use MADV_DONTNEED to simulate the behavior of libc and Java heap in
       freeing memory, as well as for munmap, app exits, or OOM killer
       scenarios.  This ensures new mTHP is always generated, released or
       swapped out, similar to the behavior on a PC or Android phone where
       many applications are frequently started and terminated.
    
    3. Swap in with or without the "-a" option to observe how fragments
       due to swap-in and the incoming swap-in of large folios will impact
       swap-out fallback.
    
    Due to 2, we ensure a certain proportion of mTHP.  Similarly, because of
    3, we maintain a certain proportion of small folios, as we don't support
    large folios swap-in, meaning any swap-in will immediately result in small
    folios.  Therefore, with both 2 and 3, we automatically achieve a system
    containing both mTHP and small folios.  Additionally, 1 provides the
    ability to continuously swap them out.
    
    We can also use "-s" to add a dedicated small folios memory area.
    
    [akpm@linux-foundation.org: thp_swap_allocator_test.c needs mman.h, per Kairui Song]
    Link: https://lkml.kernel.org/r/20240622071231.576056-2-21cnbao@gmail.comSigned-off-by: default avatarBarry Song <v-songbaohua@oppo.com>
    Acked-by: default avatarChris Li <chrisl@kernel.org>
    Tested-by: default avatarChris Li <chrisl@kernel.org>
    Reviewed-by: default avatarRyan Roberts <ryan.roberts@arm.com>
    Tested-by: default avatarRyan Roberts <ryan.roberts@arm.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: "Huang, Ying" <ying.huang@intel.com>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Kairui Song <kasong@tencent.com>
    Cc: Kalesh Singh <kaleshsingh@google.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    95139d94
Makefile 666 Bytes