From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (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 81689342177 for ; Fri, 6 Mar 2026 14:12:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772806366; cv=none; b=mNUaP/SPKxJEMLeLE8FM53xBCFUDTlEiHN4lybgkR7Wl69wA7cQuBKhbPkcyX9zdB3GgMKlwYd20mss8eGjxQbWX7I5Myy9XRuebpIBZfHfeyc4c+y6UnQP4ytP2qbv0cZ3BHtKq1loemq3cs1OCB4Co0+cnRgycMhN511yo7gY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772806366; c=relaxed/simple; bh=yWWr7fgXXlHfYSOpjW4Z/YWcRRpMT6AMK3LDw+7Hvw8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=SGmtImpoS88J0VxvnUoOwpyilhjxspmgEG/hZwT4eqO28+0ajrLLgbaFT2GnvQ85Q4B9neBjSkUHtza6uk/f0WlS0lxgqr7JZV6WF/uwbGqTcEgKJc/btSuFz7E6uDROg8K6k13SdNx0frO1E6titRcjZlH7EqVzOScM4ci6aXI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=rqoyaOT5; arc=none smtp.client-ip=91.218.175.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="rqoyaOT5" Message-ID: <64051a59-680f-40ae-b291-b884aeb7c77b@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772806362; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MAP4Rjii6xkTggMoAmMDYz72FvziKWhbp6xINy4uGD8=; b=rqoyaOT5KbnqR2SnrcRvZAOSoLhGhaPKpaJ1Ui7JbYfNxtQIM3ismlBjssvTQVI1RQuCrN c0baD+bcREKWiBdE5V7ZeWpLATpSAEBkpBVH+eY2Gdhq+xpVZ9vtOgdItWaSy6io+hiw/a 7q0MXI/cUS9F91jrNug7DOPDOXJTNMU= Date: Fri, 6 Mar 2026 17:12:38 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm: migrate: requeue destination folio on deferred split queue Content-Language: en-GB To: "David Hildenbrand (Arm)" , Andrew Morton , npache@redhat.com, ziy@nvidia.com, linux-mm@kvack.org Cc: matthew.brost@intel.com, joshua.hahnjy@gmail.com, hannes@cmpxchg.org, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, apopple@nvidia.com, linux-kernel@vger.kernel.org, kernel-team@meta.com References: <20260306133556.2051251-1-usama.arif@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Usama Arif In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 06/03/2026 13:49, David Hildenbrand (Arm) wrote: > On 3/6/26 14:35, Usama Arif wrote: >> During folio migration, __folio_migrate_mapping() removes the source >> folio from the deferred split queue, but the destination folio is never >> re-queued. This causes underutilized THPs to escape the shrinker after >> NUMA migration, since they silently drop off the deferred split list. >> >> Fix this by calling deferred_split_folio() on the destination folio >> after a successful migration, for large rmappable folios. >> >> Reported-by: Johannes Weiner >> Fixes: dafff3f4c850 ("mm: split underused THPs") >> Signed-off-by: Usama Arif >> --- >> mm/migrate.c | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >> >> diff --git a/mm/migrate.c b/mm/migrate.c >> index ece77ccb2ec0..98d0a594f7b7 100644 >> --- a/mm/migrate.c >> +++ b/mm/migrate.c >> @@ -1393,6 +1393,17 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private, >> if (old_page_state & PAGE_WAS_MAPPED) >> remove_migration_ptes(src, dst, 0); >> >> + /* >> + * Requeue the destination folio on the deferred split queue if >> + * the source was a large folio that was on the queue. Without >> + * this, NUMA migration causes underutilized THPs to escape >> + * the shrinker since the source is unqueued in >> + * __folio_migrate_mapping() and the destination is never >> + * re-queued. >> + */ >> + if (folio_test_large(dst) && folio_test_large_rmappable(dst)) >> + deferred_split_folio(dst, false); > > Doesn't that mean that you will readd any large folios, even if already > previously taken off the list after scanning? > > So I am not sure if your "if the source was a large folio that was on > the queue." comment is accurate? > Yes you are right. How about something like below? We also won't need to check for anon and non-device folios with this as we only set the the flag if it was already on deferred_split list. diff --git a/mm/migrate.c b/mm/migrate.c index ece77ccb2ec0..9e0780d380e4 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1137,7 +1137,9 @@ static int move_to_new_folio(struct folio *dst, struct folio *src, enum { PAGE_WAS_MAPPED = BIT(0), PAGE_WAS_MLOCKED = BIT(1), - PAGE_OLD_STATES = PAGE_WAS_MAPPED | PAGE_WAS_MLOCKED, + PAGE_WAS_ON_DEFERRED_SPLIT = BIT(2), + PAGE_OLD_STATES = PAGE_WAS_MAPPED | PAGE_WAS_MLOCKED | + PAGE_WAS_ON_DEFERRED_SPLIT, }; static void __migrate_folio_record(struct folio *dst, @@ -1373,6 +1375,15 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private, goto out_unlock_both; } + /* + * Record whether the source folio is on the deferred split queue + * before move_to_new_folio(), which unqueues it via + * __folio_migrate_mapping(). + */ + if (folio_test_large(src) && folio_test_large_rmappable(src) && + !data_race(list_empty(&src->_deferred_list))) + old_page_state |= PAGE_WAS_ON_DEFERRED_SPLIT; + rc = move_to_new_folio(dst, src, mode); if (rc) goto out; @@ -1393,6 +1404,15 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private, if (old_page_state & PAGE_WAS_MAPPED) remove_migration_ptes(src, dst, 0); + /* + * Requeue the destination folio on the deferred split queue if + * the source was on the queue. The source is unqueued in + * __folio_migrate_mapping(), so we record and check the state + * from before move_to_new_folio(). + */ + if (old_page_state & PAGE_WAS_ON_DEFERRED_SPLIT) + deferred_split_folio(dst, false); + out_unlock_both: folio_unlock(dst); folio_set_owner_migrate_reason(dst, reason);