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 1C89F376BF2 for ; Thu, 2 Jul 2026 00:00:03 +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=1782950404; cv=none; b=RCEDQwhYU556ktqwR1t/uyBzr31dcaLD36EObGfWu/6f+aRB9wubSc+Ir3gnbW3IDvYoW7uk7NpDR80tXMMpIBjFly1Ddy9UP3pVAKY4m/t8psMfJUrcjQHUKLXVB2DPvw3DuqQ+5jMwhQcXF93XXF/Ib+J3u1XT/NTQYkjuU0c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782950404; c=relaxed/simple; bh=6kP2O9/YUIozok+5cfvwl5l+56ZRpdljFBKljSm73Bw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=m9Q7Ni3Oqe1IeoYDqQ+ZPwxulVsrjkvI+dCunVDUu7Gv9vMDviVudU8/YLD+bxgfGp9m/JaiEuhcvjNsiYeNMaydvpa0waFRVBSXtMvgc+TLKLrB9Em4+lu3F7803lP7chmKgoL9fX/isCKNZ3m6q2NNtuD05lZEauce+/jdV0M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E3uUUZ4m; 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="E3uUUZ4m" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBB811F000E9; Wed, 1 Jul 2026 23:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782950403; bh=/FC51hWVvS+33lA6esxssw+SdZnhxCyShxLHARIeyb0=; h=From:To:Cc:Subject:Date; b=E3uUUZ4mDYo9WCVtchgoH9XZYMBkXabRUSiitGk4S6ci4HslAtpdjPmURUlOiYNX7 MxdgL8IarPcjkNPPVVOBrILsh89jLkJrKb+OZYFUCHn4P14bUCdLeZwK8k6PCI+z1R qpxD/oGHLQx743A3hWaLF9V4eA+NNv7K0myGFzH5kilJ4Lg24JQw0EKpWZ4BXnLSWj x5CJev5CqM05YZUDuio6KJMke1OlFwy+LcAmt35/3CX+k6T4wuMfaureB30yM7O3m1 hOsmOfbxhgutCulJGNudX7jkG3N0oUggjoZJpzPc8YUOnIA8LqRvLviyroG844Teil cIKWKJ/oWh3wg== 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 0/4] mm: drop redundant lru_add_drain in anon folio reuse paths Date: Thu, 2 Jul 2026 07:59:51 +0800 Message-Id: <20260701235955.36126-1-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) 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 large number of redundant lru_add_drain() calls in both wp_can_reuse_anon_folio() and do_swap_page(), leading to LRU lock contention and unnecessary overhead. In wp_can_reuse_anon_folio(), we can check the refcount against the lru_cache before deciding to drain. In do_swap_page(), the drain is now entirely redundant after Kairui's work to route SYNC I/O through the swapcache in the same way as ASYNC I/O. Build the kernel within a 1 GB memcg using 20 threads with zRAM swap. The number of lru_add_drain() calls is reduced from 276,278 to 226,318, a reduction of about 18%. Build the kernel within an 800 MB memcg using 20 threads with zRAM swap. The number of lru_add_drain() calls is reduced from 778,950 to 541,149, a reduction of 30.5%. -v3: * code improvements for patch1/4 and patch2/4 as suggested by David; * improve changelog as suggested by Shakeel and David; * collect the reviewed-by and acked-by tags; * for patch4, remove all dependency for refcount regarding swapcache free in do_swap_page, as suggested by David -v2: https://lore.kernel.org/linux-mm/20260623231635.43086-1-baohua@kernel.org/ * collect the reviewed-by and acked-by tags from Usama, Baoquan, Shakeel, Kairui, thanks! * add patch4 to free swapcache for non-LRU folios, as suggested by Kairui, thanks! -RFC: https://lore.kernel.org/linux-mm/20260611105124.98668-1-baohua@kernel.org/ Barry Song (Xiaomi) (4): mm: avoid unnecessary lru drain for wp_can_reuse_anon_folio() mm: drop stale folio_ref_count()==1 check in do_swap_page reuse logic mm: entirely remove lru_add_drain in do_swap_page mm: clarify the folio_free_swap() for do_swap_page() mm/memory.c | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) -- 2.39.3 (Apple Git-146)