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 8AA5C376A08 for ; Tue, 23 Jun 2026 23:16:45 +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=1782256606; cv=none; b=G84lcjoti34HrcTcTZTfk3aF53M8mH+cA+df731f11AhnfzXAJChRvSDD5l3L5hfUdjqbuSVFk/KJq7YBH8BAsHUzjVDknF6a8kdKCob1nO+1Z5xjJ2VsUu8LrMb6nQgoTfQ5/vFv9tTXrtA89garNA/HI8d+L1kNlZcre0Dh7E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782256606; c=relaxed/simple; bh=SSKdkgMXDondjnkM9kM3+2iXE3yt8E8yDbghx+0P1Rg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=D+jhLcXsTuxvDdwsxPXUibjL61Yt08xRv+hTmgbh1NvzVnqhODzNKL9Pk4qjcs11ZEC3xBrGIeEmxaYvuzc6S7zD5I+GYEv8M1dHolz23XxOBRT+5zFAnhbxRH5YOLTOO6SwfqS9NXzVVC1MD/9aT8LMZeRkX6zMf2FJ9joDLqA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ar7WtGLz; 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="Ar7WtGLz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCED31F000E9; Tue, 23 Jun 2026 23:16:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782256605; bh=/mBkNkspwnl0TWFRqFnXvj0MUzFsNuEOmr7fCwDzmCc=; h=From:To:Cc:Subject:Date; b=Ar7WtGLz95wUxCr24uMlO9CXa4A91PAbdsp20PUqQtifbtts8scECRMP6+4cq7S4R 9wYrH5mQWmrsU9A6B/oJNj+S/pC2kcWBgtUHvQUxaX2NxlwCi9n6vY9PBB2USaBk9r qYNyALM7YpIrb2i2ueCdHI0PYFSAuLXbSjrCkk8XjjNbk65bUnEqPyd17+AnfDFVyj AiSfn/TlV1koORKe+wHGweDKqnAknPH7dfEB+fjfKRgNUNNduO2V3zZ3Cg7RdLgfrL m/G5OBR51USrR2XxSl4x64R0t1XOgiWustzkCROhO4Jlq2eyHwvcL6lh2M4Zm0paeu /2HQ8TuZyAf/A== 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 v2 0/4] mm: drop redundant lru_add_drain in anon folio reuse paths Date: Wed, 24 Jun 2026 07:16:31 +0800 Message-Id: <20260623231635.43086-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 1GB memcg using 20 threads with zRAM swap. The number of lru_add_drain() calls is reduced from 276,787 to 230,283, while sys time decreases slightly from 3m40.125s to 3m37.128s. Build the kernel within an 800MB memcg using 20 threads with zRAM swap. The number of lru_add_drain() calls is reduced from 796,661 to 537,262, while sys time decreases slightly from 6m25.981s to 6m22.678s. -v2: * 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: try to free swapcache for non-LRU folios mm/memory.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) -- 2.39.3 (Apple Git-146)