From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 C793A3B2FFC for ; Tue, 23 Jun 2026 23:16:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782256613; cv=none; b=anR/SDnbcVTpfXEfCzpLWTip84en9B/P2UkrgtIsonhmJcCtlgfFb9IGyhGSWQF7Nmu/xdjmCDvLe5fuUaykNmv16y1229I+6QBD8PtJWaYw5mqekXGgs4ljs20nRYjzLpJRluvzpH3fbeXRPMQS5plFds0/PZZ0LZhxcxe/8D8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782256613; c=relaxed/simple; bh=r4hub1aEruDXSDguAhQyRmAvLPNRRE7le6kYkrzahBk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=frPAnwN7N0MIgaACRx6D63l0RnUby8AjNtWKNrTnL6p0ZdC4GNE82J4XQHxtg0ivClD28VweixBhz3r8o3R4XekvYLvZnfrwxS6IUiUW96kiXfjizmg11l7fx9GTMebQjdQdROp+a0/rXyXKzwoWLzbDhspwKm36ZE8RUr6x440= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CxraI1LU; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CxraI1LU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AE0C1F000E9; Tue, 23 Jun 2026 23:16:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782256612; bh=WYdK6sbj2tbaU6r5yGrNuJWJq/EwTAP2KOlRZqmz/6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CxraI1LUvFrK6wEz24Oe7ikK4UTNccyvnZayxVeY6vh/ClkmuKHn1XP7fvobJum/y l2P6tQki5T7bdI7OVkkNpr+ry5bUc5gX0yfqFGOpdwelA8C2JfEAfDGTt+iUxIrofr mZNJL+OjWGaXx518VIH8dYPviLI6UZmEdkP9pbnh/lHFr3yiOQVfkJXCGg8Y7kyoOS F4K0nQRQVoXw+D1n2RgkqjXcXrttnAPkS7IJM6ZFwG9xo9WHKw6qqxMkB1OTsngKG1 acoK62IvadUTzv0nlZ3G2q0zHF26sYIpYQyZ6zW2SDLJ1fvqtWLnihRsBUJbDngyPB 7mFWCf5AbEdOQ== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: baoquan.he@linux.dev, chrisl@kernel.org, david@kernel.org, jp.kobryn@linux.dev, kasong@tencent.com, liam@infradead.org, linux-kernel@vger.kernel.org, ljs@kernel.org, mhocko@suse.com, nphamcs@gmail.com, rppt@kernel.org, shakeel.butt@linux.dev, shikemeng@huaweicloud.com, surenb@google.com, usama.arif@linux.dev, vbabka@kernel.org, youngjun.park@lge.com, "Barry Song (Xiaomi)" Subject: [PATCH v2 2/4] mm: drop stale folio_ref_count()==1 check in do_swap_page reuse logic Date: Wed, 24 Jun 2026 07:16:33 +0800 Message-Id: <20260623231635.43086-3-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260623231635.43086-1-baohua@kernel.org> References: <20260623231635.43086-1-baohua@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The "we just allocated them without exposing them to the swapcache" case no longer exists, as Kairui has routed synchronous I/O through the swapcache as well in his series "unify swapin use swap cache and cleanup flags"[1]. As a result, folio_ref_count() should never be 1 in this path, since at least two references are held (base ref plus swapcache). Remove the folio_ref_count()==1 check and update the comment accordingly. [1] https://lore.kernel.org/all/20251220-swap-table-p2-v5-0-8862a265a033@tencent.com/ Acked-by: Usama Arif Reviewed-by: Kairui Song Reviewed-by: Baoquan He Acked-by: Shakeel Butt Signed-off-by: Barry Song (Xiaomi) --- mm/memory.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index f6848f4234a6..abd0adcf65f0 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5049,12 +5049,9 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) /* * Same logic as in do_wp_page(); however, optimize for pages that are - * certainly not shared either because we just allocated them without - * exposing them to the swapcache or because the swap entry indicates - * exclusivity. + * certainly not because the swap entry indicates exclusivity. */ - if (!folio_test_ksm(folio) && - (exclusive || folio_ref_count(folio) == 1)) { + if (!folio_test_ksm(folio) && exclusive) { if ((vma->vm_flags & VM_WRITE) && !userfaultfd_pte_wp(vma, pte) && !pte_needs_soft_dirty_wp(vma, pte)) { pte = pte_mkwrite(pte, vma); -- 2.39.3 (Apple Git-146)