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 3848C37AA8B for ; Tue, 18 Aug 2026 22:59:34 +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=1787093976; cv=none; b=IolpfoviuD6ySmzBBT5cyX7lgDlE1DU46HXdzRamRXTJG0jh3Hjc6pXnXunfDYUSVfud0BNUrDGCcMGjXnmqEXDWEniFGlIIiV4rlTDDw83Ak5/i42pVD3bfAyD1Cod4NDU6U5bF1pUQUVL8NSfuRj045S8riNyXu7DBAzaMx5M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787093976; c=relaxed/simple; bh=bgJnNmMdOReYz84TpWPYu4ZsUV781gI1wfB3D7Gsqx0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ixnoexcjDmm5iBqNUv58zZBQJZNyn1alS09IXNV+AzPvchHiEiqnM2/kCTClRqoqVk9A0twq+cuBzQidFUS+IxbA4lITzj0C3UJqJhJEWwcF1vqLwiduGeP0O60swQ6g8GtKTomNYh4SQUIT7LjPlYHRkp9OcwhiI7tbyEu/pME= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Uf7uLp0G; 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="Uf7uLp0G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33D821F000E9; Tue, 18 Aug 2026 22:59:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787093974; bh=4aVhpGd68r1Svhk9UlnG+UFWV77hKbotB3T4QNwx1S8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Uf7uLp0GpZigC8Y5cRL6A8Gz8Jk/Vkjh8NM6RbMLIxU0PqW6ohlKIhZaD4ha3efb0 9S482ouY+T64y3pjTDdmXHkPSfspoY6PZrcU3GTpmEo1yA5Em9kwBhBgkAshDJl837 d8DZ+6ksTmIIkXvJlFXFA2cBfAiSLxziS0Owt2EFMGMhc/jszU9saDwWUWq4O+/AAz t6Sz87oictEI4wwBuolMSpL952R4tUXl9roESqZ5F56hRbE1fhHJwXzl2U0b1qbxK/ XR7r4/OliS3mh2ixRQfwFSH+m+rDb+i4CyrwXzdhKyKbEsx1b9jq7GcJaivvozpxkG cvrVpE5CZVfWg== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, david@kernel.org, dev.jain@arm.com, lance.yang@linux.dev, liam@infradead.org, linux-kernel@vger.kernel.org, ljs@kernel.org, mhocko@suse.com, npache@redhat.com, rppt@kernel.org, ryan.roberts@arm.com, surenb@google.com, vbabka@kernel.org, ziy@nvidia.com, hughd@google.com, ackerleytng@google.com, usama.arif@linux.dev, joannelkoong@gmail.com, hannes@cmpxchg.org, "Barry Song (Xiaomi)" Subject: [RFC PATCH v3 4/4] mm: batch lru_cache draining in deferred_split_scan Date: Wed, 19 Aug 2026 06:59:04 +0800 Message-Id: <20260818225904.55236-5-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260818225904.55236-1-baohua@kernel.org> References: <20260818225904.55236-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 deferred_split_scan() splits a batch of folios, so we only need to drain the lru_cache once for the entire batch. Signed-off-by: Barry Song (Xiaomi) --- mm/huge_memory.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 263ef9b6949d..e797f6d1837e 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -4085,6 +4085,8 @@ static int __folio_freeze_and_split_unmapped(struct folio *folio, unsigned int n * @lock_at: a page within @folio to be left locked to caller * @list: after-split folios will be put on it if non NULL * @split_type: perform uniform split or not (non-uniform split) + * @lru_cache_drained: whether lru_cache has been drained locally + * or on all CPUs for a batch of folios * * It calls __split_unmapped_folio() to perform uniform and non-uniform split. * It is in charge of checking whether the split is supported or not and @@ -4100,7 +4102,8 @@ static int __folio_freeze_and_split_unmapped(struct folio *folio, unsigned int n */ static int __folio_split(struct folio *folio, unsigned int new_order, struct page *split_at, struct page *lock_at, - struct list_head *list, enum split_type split_type) + struct list_head *list, enum split_type split_type, + enum lru_cache_drained *lru_cache_drained) { XA_STATE(xas, &folio->mapping->i_pages, folio->index); struct folio *end_folio = folio_next(folio); @@ -4203,7 +4206,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order, } if (folio_ref_count(folio) == folio_expected_ref_count(folio) + 1 + folio_may_be_lru_cached(folio)) - lru_cache_drain_for_folio(folio, 1, NULL); + lru_cache_drain_for_folio(folio, 1, lru_cache_drained); /* * Racy check if we can split the page, before unmap_folio() will @@ -4395,7 +4398,7 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list struct folio *folio = page_folio(page); return __folio_split(folio, new_order, &folio->page, page, list, - SPLIT_TYPE_UNIFORM); + SPLIT_TYPE_UNIFORM, NULL); } /** @@ -4426,7 +4429,7 @@ int folio_split(struct folio *folio, unsigned int new_order, struct page *split_at, struct list_head *list) { return __folio_split(folio, new_order, split_at, &folio->page, list, - SPLIT_TYPE_NON_UNIFORM); + SPLIT_TYPE_NON_UNIFORM, NULL); } /** @@ -4622,6 +4625,7 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, struct folio *folio, *next; int split = 0; unsigned long isolated; + enum lru_cache_drained drained = LRU_CACHE_NOT_DRAINED; isolated = list_lru_shrink_walk_irq(&deferred_split_lru, sc, deferred_split_isolate, &dispose); @@ -4646,7 +4650,8 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, } if (!folio_trylock(folio)) goto requeue; - if (!split_folio(folio)) { + if (!__folio_split(folio, 0, &folio->page, &folio->page, NULL, + SPLIT_TYPE_UNIFORM, &drained)) { did_split = true; if (underused) count_vm_event(THP_UNDERUSED_SPLIT_PAGE); -- 2.34.1