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 BFD643DA5A5 for ; Thu, 11 Jun 2026 10:51:46 +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=1781175107; cv=none; b=FAHEVNaHAY2S3wCpBx1sbes1pdIonL4EIiQBa6jUYMSQO6jp3ATIiamHj3ZDb5LOfBRG3XE3S8VV0S2sTcQ4vyPptl8HVaScajWbWBwujSOU9GAT3vmtFMi3Kwh8jTwiCPQT04MaxcOv+xCy3c8i62aF3p7fAwl3Hp5NkLqt6T4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781175107; c=relaxed/simple; bh=b9lOzzftQRC4bjXGv8uT1vlhAotF2qJ1PQoy2EogxE4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=k9Xk639+Hivs6iUvQ9Ko2M9m75JWbNCkEhTdL7YgxfKT9IubIKiCVBepkUCB/ZvoZMXmUWMUQuqQHV0t12bzGufDFRK0Rf/v8QZLcUTShSEKHDfEFkfpRaI8Y3pzZFhJb4o8n++X3fn92lFv/X0R1KcP3/Htz7P02zMa4KYaEyg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=olqx5g2t; 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="olqx5g2t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09F8E1F00899; Thu, 11 Jun 2026 10:51:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781175106; bh=Daz2QfOWf/vQwHvERTl8P7zu3X8BbDfgjfcWXtlrYHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=olqx5g2thmz3pld3Q7jFbx2ndbz9i6fwyVTfR+AQ6Rzb1j50Mgv48OaXuQ1K3EV3v 5Q3t20cNEy9SFZKKy0VAIxfEh5LYaTpcSjqrpPHvyh9tDUZ8cRfmHDeMw6H8msogmk 7oob3s1OHFpEIhO5kXu+tvEs0mPC0hYnDECqTTFUNeLR6h/pmm7heAhOc732X5CjMf 8q8AH8i9DUXWjZq+W/mjFNTyTkeWnw5CBE1xSFSeg7DktaD6q2F8yVdR7edeZALK/K j8GGn8HUWWvpcvOD+PEAnpInd0nFSgpQXwS48cO+IiawrtSk6/yMpDuRC1qGMih4ZU wXv13/+Gcj5Zw== 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 3/3] mm: entirely remove lru_add_drain in do_swap_page Date: Thu, 11 Jun 2026 18:51:24 +0800 Message-Id: <20260611105124.98668-4-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 We are doing a lot of redundant lru_add_drain() calls in do_swap_page(), especially for synchronous I/O devices. For example, the test program below currently ends up draining lru_cache 100% of the time: int main(int argc, char *argv[]) { int i; #define SIZE 100*1024*1024 while(1) { volatile int *p = mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); for (int i = 0; i < SIZE/sizeof(int); i++) p[i] = i%64; madvise((void *)p, SIZE, MADV_PAGEOUT); for (int i = 0; i < SIZE/sizeof(int); i++) p[i] = i%64; munmap(p, SIZE); } return 0; } Folio reuse now relies primarily on the exclusive hint, making lru_cache draining to drop the refcount in lru_cache largely irrelevant. Signed-off-by: Barry Song (Xiaomi) --- mm/memory.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index ce8ef27e7a54..b5a78670bcc8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4903,16 +4903,6 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) } else if (folio != swapcache) page = folio_page(folio, 0); - /* - * If we want to map a page that's in the swapcache writable, we - * have to detect via the refcount if we're really the exclusive - * owner. Try removing the extra reference from the local LRU - * caches if required. - */ - if ((vmf->flags & FAULT_FLAG_WRITE) && - !folio_test_ksm(folio) && !folio_test_lru(folio)) - lru_add_drain(); - folio_throttle_swaprate(folio, GFP_KERNEL); /* -- 2.39.3 (Apple Git-146)