From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out199-11.us.a.mail.aliyun.com (out199-11.us.a.mail.aliyun.com [47.90.199.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09A5A188713 for ; Mon, 8 Sep 2025 03:09:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=47.90.199.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757300949; cv=none; b=nh/Sco9o+LKpvV3y511/AvLW6kWkv1Rmbnz/b5YC/NnNyQEd58sLq75mzDS5IG/UTcKP0r3ryZGENlXvigx7dSj6TyDG9pDDczJ3mL79j5i5vP6IhkHBXReTYxZShKuVEGp/aKsr0+AYWtV1M2RLoV78JZotLa/MKtzIAv6HWcM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757300949; c=relaxed/simple; bh=Xu1ylK93WNSaZBtxACzTqgWi2Pr1dvVj42ia55A6zi4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=e4Y2no4tbjYs/bXfbVC1mihjKYydsr78AJ0GpM/vS81ez8BMnfXAUA3JAEKPZsGYaas3m5gjkusgtBmRCs+5/3N2fBwkRIIpBh6BFTQePUGgciPuhtriBqLQuYUZvcTn3zjh+hgdmizrVqhCGPCxSUrfssob6PaLfK8cAs50dPc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=rTzwgXpu; arc=none smtp.client-ip=47.90.199.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="rTzwgXpu" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1757300929; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=EKxx/lX3Bp4VW+ItJ7z/ma4EcEpYpmczHseAhd+atyg=; b=rTzwgXpuF6wQ6jCQ7lvKPIPDg2fLAGyHaXZFUNv6JipJz5CzRhPf6kq4goHKupdG6G396MxwFY1fccJMq/gc8djTZubrVpBUka+/G31Ii+LH1DkuMiTb2aWcvS7TKh76uN5y+27oxtSQezDob1jQCW64PVhJ4Z1DFw6mroqTdwc= Received: from 30.74.144.132(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WnQW09W_1757300926 cluster:ay36) by smtp.aliyun-inc.com; Mon, 08 Sep 2025 11:08:47 +0800 Message-ID: Date: Mon, 8 Sep 2025 11:08:46 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 03/15] mm, swap: fix swap cahe index error when retrying reclaim To: Kairui Song , linux-mm@kvack.org Cc: Andrew Morton , Matthew Wilcox , Hugh Dickins , Chris Li , Barry Song , Baoquan He , Nhat Pham , Kemeng Shi , Ying Huang , Johannes Weiner , David Hildenbrand , Yosry Ahmed , Lorenzo Stoakes , Zi Yan , linux-kernel@vger.kernel.org References: <20250905191357.78298-1-ryncsn@gmail.com> <20250905191357.78298-4-ryncsn@gmail.com> From: Baolin Wang In-Reply-To: <20250905191357.78298-4-ryncsn@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2025/9/6 03:13, Kairui Song wrote: > From: Kairui Song > > The allocator will reclaim cached slots while scanning. Currently, it > will try again if the reclaim found a folio that is already removed from > the swap cache due to a race. But the following lookup will be using the > wrong index. It won't cause any OOB issue since the swap cache index is > truncated upon lookup, but it may lead to reclaiming of an irrelevant > folio. > > This should not cause a measurable issue, but we should fix it. > > Fixes: fae8595505313 ("mm, swap: avoid reclaiming irrelevant swap cache") > Signed-off-by: Kairui Song > --- Good catch. LGTM. Reviewed-by: Baolin Wang > mm/swapfile.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 4b8ab2cb49ca..4c63fc62f4cb 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -240,13 +240,13 @@ static int __try_to_reclaim_swap(struct swap_info_struct *si, > * Offset could point to the middle of a large folio, or folio > * may no longer point to the expected offset before it's locked. > */ > - entry = folio->swap; > - if (offset < swp_offset(entry) || offset >= swp_offset(entry) + nr_pages) { > + if (offset < swp_offset(folio->swap) || > + offset >= swp_offset(folio->swap) + nr_pages) { > folio_unlock(folio); > folio_put(folio); > goto again; > } > - offset = swp_offset(entry); > + offset = swp_offset(folio->swap); > > need_reclaim = ((flags & TTRS_ANYWAY) || > ((flags & TTRS_UNMAPPED) && !folio_mapped(folio)) ||