• Mel Gorman's avatar
    mm/page_alloc: do not prefetch buddies during bulk free · 2a791f44
    Mel Gorman authored
    free_pcppages_bulk() has taken two passes through the pcp lists since
    commit 0a5f4e5b ("mm/free_pcppages_bulk: do not hold lock when
    picking pages to free") due to deferring the cost of selecting PCP lists
    until the zone lock is held.
    
    As the list processing now takes place under the zone lock, it's less
    clear that this will always benefit for two reasons.
    
    1. There is a guaranteed cost to calculating the buddy which definitely
       has to be calculated again. However, as the zone lock is held and
       there is no deferring of buddy merging, there is no guarantee that the
       prefetch will have completed when the second buddy calculation takes
       place and buddies are being merged.  With or without the prefetch, there
       may be further stalls depending on how many pages get merged. In other
       words, a stall due to merging is inevitable and at best only one stall
       might be avoided at the cost of calculating the buddy location twice.
    
    2. As the zone lock is held, prefetch_nr makes less sense as once
       prefetch_nr expires, the cache lines of interest have already been
       merged.
    
    The main concern is that there is a definite cost to calculating the
    buddy location early for the prefetch and it is a "maybe win" depending
    on whether the CPU prefetch logic and memory is fast enough.  Remove the
    prefetch logic on the basis that reduced instructions in a path is
    always a saving where as the prefetch might save one memory stall
    depending on the CPU and memory.
    
    In most cases, this has marginal benefit as the calculations are a small
    part of the overall freeing of pages.  However, it was detectable on at
    least one machine.
    
                                  5.17.0-rc3             5.17.0-rc3
                        mm-highpcplimit-v2r1     mm-noprefetch-v1r1
    Min       elapsed      630.00 (   0.00%)      610.00 (   3.17%)
    Amean     elapsed      639.00 (   0.00%)      623.00 *   2.50%*
    Max       elapsed      660.00 (   0.00%)      660.00 (   0.00%)
    
    Link: https://lkml.kernel.org/r/20220221094119.15282-2-mgorman@techsingularity.netSigned-off-by: default avatarMel Gorman <mgorman@techsingularity.net>
    Suggested-by: default avatarAaron Lu <aaron.lu@intel.com>
    Reviewed-by: default avatarVlastimil Babka <vbabka@suse.cz>
    Reviewed-by: default avatarAaron Lu <aaron.lu@intel.com>
    Cc: Dave Hansen <dave.hansen@linux.intel.com>
    Cc: Michal Hocko <mhocko@kernel.org>
    Cc: Jesper Dangaard Brouer <brouer@redhat.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    2a791f44
page_alloc.c 264 KB