• Huang Ying's avatar
    mm,swap: fix a theoretical underflow in readahead window calculation · 653ea80e
    Huang Ying authored
    Patch series "mm,swap: cleanup VMA based swap readahead window
    calculation".
    
    When VMA based swap readahead is introduced in commit ec560175 ("mm,
    swap: VMA based swap readahead"), "struct vma_swap_readahead" is defined
    to describe the readahead window.  Because we wanted to save the PTE
    entries in the struct at that time.  But after commit 4f8fcf4c
    ("mm/swap: swap_vma_readahead() do the pte_offset_map()"), we no longer
    save PTE entries in the struct.  The size of the struct becomes so small,
    that it's better to use the fields of the struct directly.  This can
    simplify the code to improve the code readability.  The line number of
    source code reduces too.
    
    A theoretical underflow issue and some related code cleanup is done in the
    series too.
    
    
    This patch (of 3):
    
    In swap readahead window calculation, if the fault PFN is smaller than the
    readahead window size, underflow may occurs.  This is only possible in
    theory, because the start of the virtual address space will not be used
    for anonymous pages in practice.  Even if underflow occurs, there will be
    no functional bugs.  In the worst cases, some swap entries may be swapped
    in incorrectly and some pages may be allocate on the wrong nodes.
    
    Anyway, we still needs to fix the issue via some underflow checking.
    
    Link: https://lkml.kernel.org/r/20240531081230.310128-1-ying.huang@intel.com
    Link: https://lkml.kernel.org/r/20240531081230.310128-2-ying.huang@intel.com
    Fixes: ec560175 ("mm, swap: VMA based swap readahead")
    Signed-off-by: default avatar"Huang, Ying" <ying.huang@intel.com>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Alistair Popple <apopple@nvidia.com>
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: Mel Gorman <mgorman@techsingularity.net>
    Cc: Miaohe Lin <linmiaohe@huawei.com>
    Cc: Minchan Kim <minchan@kernel.org>
    Cc: Ryan Roberts <ryan.roberts@arm.com>
    Cc: Yang Shi <shy828301@gmail.com>
    Cc: Yu Zhao <yuzhao@google.com>
    Cc: Kairui Song <kasong@tencent.com>
    Cc: Barry Song <v-songbaohua@oppo.com>
    Cc: Chris Li <chrisl@kernel.org>
    Cc: Yosry Ahmed <yosryahmed@google.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    653ea80e
swap_state.c 25.9 KB