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 C4E0A38D3EF for ; Thu, 2 Jul 2026 00:00:14 +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=1782950416; cv=none; b=jd1EpDHiVKdXDezq+jCRedaxv/MckwU38wHyZDOh89ZW2Rznac1FRbnoMPHZwjgwyMlLZZqfVtxgnMvsvuJSRHYbf94G1pAE2CtDrslF8/E6TE/VkihqAswkXVZj/KeiEr9kcKtImz/fiyhMzB0eXz/R0A7j9ZQbRWd+aoig1mE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782950416; c=relaxed/simple; bh=lNjoMBZzrqqt1JfL4eBVdxYgEcNx+GEz0xax6xOeu9o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z6d//VcARjlaJkPjjo75gGOda7VofPGqSY1ux0un2Bz3hw99TvE8Y8dXcXk9W9u78PSlfy1UBOIhfkmIw5kGx1I30p2wzWT3oJcSdww05xJ2hmxR0qguRQGUk9+w65v89+P3EzmCz5N1W41X9g1D31bnVqGg0U77ROCxzBf/cU0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HAGVtWO8; 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="HAGVtWO8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D7E61F000E9; Thu, 2 Jul 2026 00:00:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782950414; bh=qYk0TLb8Fek6e2oTciquFGNK/rI/VHMJUUZxOc7EuL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HAGVtWO8D03V41OVw5rERrMKFEsxEnB0f7rAiOhUaEZnVMxbvnBfkD+uaaGVfZ4// boUNOei8CdrfNb1gVtiBdmjUueP6wSXLUAQw0pVTjwBt9jcfUAaRNhtENokpBMJNbG RH1d+uayOvfKF1jt8noOSJ3ldkqHlKumI6tR4tepwvwuj9GU1zpq0gyWOMW1SN4QHG OynTOlDS/fdjinhhz6zg2SzIDHjCGexo7qzoifKlM9QG49eO6+irs7X+Grw3+UQSi5 hY3KThqA6z/PujoYPOwRfUI/zt5wa0om0WdVpBGe5hGp6Y2OZeWKwjO4niMUsGdCBa sdJ8vxkH7GQeQ== 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 3/4] mm: entirely remove lru_add_drain in do_swap_page Date: Thu, 2 Jul 2026 07:59:54 +0800 Message-Id: <20260701235955.36126-4-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 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. For a kernel build with a minimal configuration running in a 1 GB memcg, this patch skips more than 43,000 redundant local LRU drains. Acked-by: David Hildenbrand (Arm) Acked-by: Shakeel Butt Reviewed-by: Baoquan He 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 71e9d394816b..4665405ace5a 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4901,16 +4901,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)