From nobody Fri Apr 3 01:24:29 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9D01F378821 for ; Tue, 17 Feb 2026 20:06:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771358809; cv=none; b=cfXbRslW+NT+2QzkYn0a7n48FVcr0SipErK8zxI2tYnswVy23035YGRvSaS1yFwLB3g96MDIoI55vHOvKX/eDHHXlXACmB4HdlM56sqy1YEHWG82mVo2UXdKQ1EmajJf3Moopbn1pdGPSYc+uQtUlAFgpFaK9gJ6AHaaHKMFcSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771358809; c=relaxed/simple; bh=DehS9hTU793eie5l6tXoAIZr7SXja9yJwWlHHmA0Ahw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rWe5jHiYmNEpQJZxPMPDfqKQLE6BCahQISv7a6HDT/7JfmiMpSkUcxTbzXLBMRuEdAAgTPDZGer4NBkhL/yOHe371npK7f+SQNIzmakUy1f3BcSywm+7yWHlKM2roeByVrF9TMyzwiXF/+mKyKilnC9T1uMmS3IdiBZMl92INeA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rc93IAwz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rc93IAwz" Received: by smtp.kernel.org (Postfix) with ESMTPS id 8191EC2BC87; Tue, 17 Feb 2026 20:06:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771358809; bh=DehS9hTU793eie5l6tXoAIZr7SXja9yJwWlHHmA0Ahw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rc93IAwz3CIvEnaYF33A0YKpNSMZkQBQhsYNWhNFb6/OYtR3ELePrzfffPcSIeDMI d7+PPBqgWleL8F2oOvuYZHFAhR0KYP6TaLMm6x4afTLxtthXUk8MAbCwx7WS1ATcHW XglSWLfdw9FGwqDbCddIHI4QJQnQKafB67iHbU4RohFxeucxaM+DHdyECEf5ULr6I2 nbcuTqGB6EnzN+UYv5wbzUdTA/effu7HYTZbRbb5DbrwMIK26wlmUeTl155gzckIWL isOJtjg58vkCzKkG2v+6z9Hvx6h22XyaabLBMheuE0vxpW9iVTKsYoeITi8eobYzR1 Ie0w5StLHxIRg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AA61E9A041; Tue, 17 Feb 2026 20:06:49 +0000 (UTC) From: Kairui Song via B4 Relay Date: Wed, 18 Feb 2026 04:06:35 +0800 Subject: [PATCH v3 10/12] mm, swap: no need to truncate the scan border Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260218-swap-table-p3-v3-10-f4e34be021a7@tencent.com> References: <20260218-swap-table-p3-v3-0-f4e34be021a7@tencent.com> In-Reply-To: <20260218-swap-table-p3-v3-0-f4e34be021a7@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Johannes Weiner , David Hildenbrand , Lorenzo Stoakes , Youngjun Park , linux-kernel@vger.kernel.org, Chris Li , Kairui Song X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1771358806; l=1640; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=2+MOtDCYClcDw9TcgcSvHJeMem5KxDman/aSTNPnNu0=; b=JiApyFqhVexB0R2dK8YJdP7PMRcUBDYnG3jDQt7pwNUkIz80Oj0pUtxXTadmSQ1fbZjU9Abnv mDDgUzSRT8SCBo98cAzB0tTSBiD8cJzIXZ2lZ/iV5LkjyBVp6V5TlwY X-Developer-Key: i=kasong@tencent.com; a=ed25519; pk=kCdoBuwrYph+KrkJnrr7Sm1pwwhGDdZKcKrqiK8Y1mI= X-Endpoint-Received: by B4 Relay for kasong@tencent.com/kasong-sign-tencent with auth_id=562 X-Original-From: Kairui Song Reply-To: kasong@tencent.com From: Kairui Song swap_map had a static flexible size, so the last cluster won't be fully covered, hence the allocator needs to check the scan border to avoid OOB. But the swap table has a fixed-sized swap table for each cluster, and the slots beyond the device size are marked as bad slots. The allocator can simply scan all slots as usual, and any bad slots will be skipped. Signed-off-by: Kairui Song Acked-by: Chris Li --- mm/swap.h | 2 +- mm/swapfile.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/swap.h b/mm/swap.h index 0a91e21e92b1..cc410b94e91a 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -85,7 +85,7 @@ static inline struct swap_cluster_info *__swap_offset_to_= cluster( struct swap_info_struct *si, pgoff_t offset) { VM_WARN_ON_ONCE(percpu_ref_is_zero(&si->users)); /* race with swapoff */ - VM_WARN_ON_ONCE(offset >=3D si->max); + VM_WARN_ON_ONCE(offset >=3D roundup(si->max, SWAPFILE_CLUSTER)); return &si->cluster_info[offset / SWAPFILE_CLUSTER]; } =20 diff --git a/mm/swapfile.c b/mm/swapfile.c index 801d8092be51..df2b88c6c67b 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -945,8 +945,8 @@ static unsigned int alloc_swap_scan_cluster(struct swap= _info_struct *si, { unsigned int next =3D SWAP_ENTRY_INVALID, found =3D SWAP_ENTRY_INVALID; unsigned long start =3D ALIGN_DOWN(offset, SWAPFILE_CLUSTER); - unsigned long end =3D min(start + SWAPFILE_CLUSTER, si->max); unsigned int order =3D likely(folio) ? folio_order(folio) : 0; + unsigned long end =3D start + SWAPFILE_CLUSTER; unsigned int nr_pages =3D 1 << order; bool need_reclaim, ret, usable; =20 --=20 2.52.0