• Kairui Song's avatar
    mm: swap: add a fragment cluster list · 477cb7ba
    Kairui Song authored
    Now swap cluster allocator arranges the clusters in LRU style, so the
    "cold" cluster stay at the head of nonfull lists are the ones that were
    used for allocation long time ago and still partially occupied.  So if
    allocator can't find enough contiguous slots to satisfy an high order
    allocation, it's unlikely there will be slot being free on them to satisfy
    the allocation, at least in a short period.
    
    As a result, nonfull cluster scanning will waste time repeatly scanning
    the unusable head of the list.
    
    Also, multiple CPUs could content on the same head cluster of nonfull
    list.  Unlike free clusters which are removed from the list when any CPU
    starts using it, nonfull cluster stays on the head.
    
    So introduce a new list frag list, all scanned nonfull clusters will be
    moved to this list.  Both for avoiding repeated scanning and contention.
    
    Frag list is still used as fallback for allocations, so if one CPU failed
    to allocate one order of slots, it can still steal other CPU's clusters. 
    And order 0 will favor the fragmented clusters to better protect nonfull
    clusters
    
    If any slots on a fragment list are being freed, move the fragment list
    back to nonfull list indicating it worth another scan on the cluster. 
    Compared to scan upon freeing a slot, this keep the scanning lazy and save
    some CPU if there are still other clusters to use.
    
    It may seems unneccessay to keep the fragmented cluster on list at all if
    they can't be used for specific order allocation.  But this will start to
    make sense once reclaim dring scanning is ready.
    
    Link: https://lkml.kernel.org/r/20240730-swap-allocator-v5-7-cb9c148b9297@kernel.orgSigned-off-by: default avatarKairui Song <kasong@tencent.com>
    Reported-by: default avatarBarry Song <21cnbao@gmail.com>
    Cc: Chris Li <chrisl@kernel.org>
    Cc: "Huang, Ying" <ying.huang@intel.com>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Kalesh Singh <kaleshsingh@google.com>
    Cc: Ryan Roberts <ryan.roberts@arm.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    477cb7ba
swapfile.c 96.5 KB