• Mel Gorman's avatar
    mm/page_alloc: avoid conflating IRQs disabled with zone->lock · df1acc85
    Mel Gorman authored
    Historically when freeing pages, free_one_page() assumed that callers had
    IRQs disabled and the zone->lock could be acquired with spin_lock().  This
    confuses the scope of what local_lock_irq is protecting and what
    zone->lock is protecting in free_unref_page_list in particular.
    
    This patch uses spin_lock_irqsave() for the zone->lock in free_one_page()
    instead of relying on callers to have disabled IRQs.
    free_unref_page_commit() is changed to only deal with PCP pages protected
    by the local lock.  free_unref_page_list() then first frees isolated pages
    to the buddy lists with free_one_page() and frees the rest of the pages to
    the PCP via free_unref_page_commit().  The end result is that
    free_one_page() is no longer depending on side-effects of local_lock to be
    correct.
    
    Note that this may incur a performance penalty while memory hot-remove is
    running but that is not a common operation.
    
    [lkp@intel.com: Ensure CMA pages get addded to correct pcp list]
    
    Link: https://lkml.kernel.org/r/20210512095458.30632-9-mgorman@techsingularity.netSigned-off-by: default avatarMel Gorman <mgorman@techsingularity.net>
    Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
    Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: Chuck Lever <chuck.lever@oracle.com>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Jesper Dangaard Brouer <brouer@redhat.com>
    Cc: Michal Hocko <mhocko@kernel.org>
    Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    df1acc85
page_alloc.c 258 KB