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 37EE93D9DCD for ; Thu, 11 Jun 2026 10:51:42 +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=1781175104; cv=none; b=mtn0VccJE8Q/eyeEX8SzwseV/UazrKE2E+Tpyy1zVfu6EclTrccdVUGEtJbB5jLJPp+sxe37y2CF8fcP5X09ei5GizOo2uWMsoggTYC66wsE1OM/A2kPwo/knmmRhA0pUmT5mu/ki9rg3JpqFJUc8qWBwkHL9bdZxhDmqICl0Bo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781175104; c=relaxed/simple; bh=QgsXcplNtNjngzX77Y+uAPwBi+kz0YwxzkvNyfCCYL4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W5znpp/v/rFkb8dFBZECK3NOElmRzp35ZNx9AQ3rOklWCqIiEzFhorK/NqOtE8xeEmXclOYoWji4gy5eTvFzaLQCqow6BUHiwc2m8jH9e6X44S+HCccLUnZh54mkDKBNTdD9ng56wWEa9GmK1kTEVfxaSp3pS+NiWJ/ea7tie5c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WgZEtF18; 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="WgZEtF18" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32F4E1F00893; Thu, 11 Jun 2026 10:51:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781175102; bh=0xz7/1XNa5r8BniD/2N866DuyfD32Z4NZK3CokcixYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WgZEtF18f1MnI0Xd+bo2kF+iWwLij9SaxuFHznIM8SypLV1RU6RW2p0NLy81G9ZB0 Q3AZao7w7PbbsTMlMSMUakc8vIk5NW9snO6/QZV+/wKXX0Z/kdItHWoocB6ygmU8nl jDbiF02hKKG0DryqLCdEH5fvy1xgwaKxi+PmLcaHoaMzvajDZYrSIg1F97aBrwJjqL ayAO1TBN0JjCXmY2S0DyTa6+JwY/eYrmXbwDPEYd85U5uRgPPipuV6eig+3Zj6/iY2 +I3fa5U8uVBEcvniTqtDI7j1BCQdlPqCw0VKUsO2BfeQGhKmP7ucf8gqi2Pjr25HcI 53BnIOUKnFiqg== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, chrisl@kernel.org, kasong@tencent.com, shikemeng@huaweicloud.com, nphamcs@gmail.com, baoquan.he@linux.dev, youngjun.park@lge.com, jp.kobryn@linux.dev, usama.arif@linux.dev, shakeel.butt@linux.dev, "Barry Song (Xiaomi)" Subject: [RFC PATCH 2/3] mm: drop stale folio_ref_count()==1 check in do_swap_page reuse logic Date: Thu, 11 Jun 2026 18:51:23 +0800 Message-Id: <20260611105124.98668-3-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260611105124.98668-1-baohua@kernel.org> References: <20260611105124.98668-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/ 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 487a34377a7b..ce8ef27e7a54 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)