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 0EA732EA48F for ; Thu, 2 Jul 2026 00:00:10 +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=1782950412; cv=none; b=Auk6HzAVGEAKDrvsIulZr8VhmtcR+dSqFvRUiaCDodnOCcxswye7qZIPxBQ7v6vjSN0AsAtbKqoLGOu4LRqethSKze0mQbDCcHbQdpYa4gACjvNkzv/3Ji3rY/FiIo6+lbFsOI93LswEceqa4ClnrlVE6DnVsfwloepmIEdp5vU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782950412; c=relaxed/simple; bh=m8eMz6STNU6bQ3/LUNhaxj2Bwhkut5ULSdG2y/sENg4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=phBqYfChcuwo4RZjTa8iE5lR80tQa3ahVzhGEkkYNBy5LMah3UTkEymgrc7tqqXMJZOtUwv+c1no/ixQvHDvnd99GIVl98W7nxY25LEAG00dMxfUieygh52nnRwkmS3KmTyIuL2g4jGRg/6bFGLNZwN5iw6m/D1mVm+2gjBJCcY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PrKM2Nn2; 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="PrKM2Nn2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27E531F00A3D; Thu, 2 Jul 2026 00:00:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782950410; bh=f4vh+ePh5YOVljKP2TbgiOGF/LKF/nWl4c5vnE5lkvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PrKM2Nn2ma1mLWEyS3ameveFMxgjb/yazVLOGZQ8HBSNtZjrVdzCAhKJutiXdSR19 jaUkWFDVjA1YGXUmNSftWGzdeE/cJMblDW6gFhoBFsK0Cx/OQzo28KoCfE/xgIdtzL IPy4WaKQGro69gPIT1zg+5DD5ksj2HrDMqLc/AhGUzzYXjNXBaeQRTs9hYlYBwqW7P 0YqhBV6OSuAfLjB3n9zINagicka/JMk0TjJIXIP8DKufoglAVvUHFr15b7ztgn5vqV DrblJlIlCHEOoLqIH7EBcwfmeW74PiiM109e0pqAKFoarLJ5CmFSjFqkikNQ5J4eiq MCPgNtnSv2qBQ== 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 v3 2/4] mm: drop stale folio_ref_count()==1 check in do_swap_page reuse logic Date: Thu, 2 Jul 2026 07:59:53 +0800 Message-Id: <20260701235955.36126-3-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260701235955.36126-1-baohua@kernel.org> References: <20260701235955.36126-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 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 87da78eb1abd..71e9d394816b 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5046,13 +5046,10 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) pte = pte_mkuffd_wp(pte); /* - * 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. + * Similar logic as in do_wp_page(); however, optimize for pages that are + * certainly not because the swap entry indicates exclusivity. */ - if (!folio_test_ksm(folio) && - (exclusive || folio_ref_count(folio) == 1)) { + if (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)