• Miaohe Lin's avatar
    mm/swapfile: use percpu_ref to serialize against concurrent swapoff · 63d8620e
    Miaohe Lin authored
    Patch series "close various race windows for swap", v6.
    
    When I was investigating the swap code, I found some possible race
    windows.  This series aims to fix all these races.  But using current
    get/put_swap_device() to guard against concurrent swapoff for
    swap_readpage() looks terrible because swap_readpage() may take really
    long time.  And to reduce the performance overhead on the hot-path as much
    as possible, it appears we can use the percpu_ref to close this race
    window(as suggested by Huang, Ying).  The patch 1 adds percpu_ref support
    for swap and most of the remaining patches try to use this to close
    various race windows.  More details can be found in the respective
    changelogs.
    
    This patch (of 4):
    
    Using current get/put_swap_device() to guard against concurrent swapoff
    for some swap ops, e.g.  swap_readpage(), looks terrible because they
    might take really long time.  This patch adds the percpu_ref support to
    serialize against concurrent swapoff(as suggested by Huang, Ying).  Also
    we remove the SWP_VALID flag because it's used together with RCU solution.
    
    Link: https://lkml.kernel.org/r/20210426123316.806267-1-linmiaohe@huawei.com
    Link: https://lkml.kernel.org/r/20210426123316.806267-2-linmiaohe@huawei.comSigned-off-by: default avatarMiaohe Lin <linmiaohe@huawei.com>
    Reviewed-by: default avatar"Huang, Ying" <ying.huang@intel.com>
    Cc: Alex Shi <alexs@kernel.org>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: Dennis Zhou <dennis@kernel.org>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Michal Hocko <mhocko@suse.com>
    Cc: Minchan Kim <minchan@kernel.org>
    Cc: Tim Chen <tim.c.chen@linux.intel.com>
    Cc: Wei Yang <richard.weiyang@gmail.com>
    Cc: Yang Shi <shy828301@gmail.com>
    Cc: Yu Zhao <yuzhao@google.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    63d8620e
swapfile.c 96.7 KB