From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C27632B9B7 for ; Sat, 20 Jun 2026 07:27:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781940447; cv=none; b=n57aeC9gLvejXF1Cg8s0uTsi/kB5fFjnehcGBwitT/siqe7f57hQBwSoEFvFLCpq80q1onK+JjVVKUu4U9Jf8Tn5sjDwqweFhOJ4vpY199gQbz6Hy5nvh9mJck0+o/P0tsKipkkPlZl4H/uyTv4psN0vCUQctg3BnNtWPan1HF8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781940447; c=relaxed/simple; bh=cSY53JyBryQ+ziB4ehRzHn3TNnZrwYgvX50Cu1Fbjjc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z98rA/8OuV9+wCX9JBnl2rc4YzUdgLP0VXI+/Al62srDKjBJCPoi49STR1aFA6kXpENDlqexSgg70/t9CEbz5pvcNfZ+gVyydDqnn1OE8dfAj2huLK/Vsf7/z5K2pQpt63PmcZqfJpZKuFtx2A+V2WH+3Oe3x6GPqw9nlHw15/Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RGv3gto+; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RGv3gto+" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-68bd9fce347so5137335a12.2 for ; Sat, 20 Jun 2026 00:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781940444; x=1782545244; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=wtyVZd3PL2bC8+RUPOGOCXbPwJCCjKXM4wwmk6wBWyE=; b=RGv3gto+Cz+HEn7ovF2/HiIOl24t9AuuvYOucqsCVEVmY+Dy30OYQZ3WZC23r/jd0Z RP8T71IW2ezGIgbIJt/fMTkyn2jvAISq2qZ1RBa/+oj8nIa0pXSsQZVTtLDw7TBEnKU2 XxK+6Yp4h9AUZy3Q9KIxSR9riqjyXkJLk82rNBmzbgsW2jAIkYY3N7GB4sfqwHlsoRyC q6h5I4uMpHb9Hnf+5smfu4FJNkp9jQaWuI1ZK/ze4ASEs9ipnRKLRqN5pCPGoZDolg3Q mLLK4v1cYs4p8iTmwKYppUb6vUe/7o6kufz8IdyBe5Jf0JM158GaqoU9LgK6psVxdfQY ewJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781940444; x=1782545244; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wtyVZd3PL2bC8+RUPOGOCXbPwJCCjKXM4wwmk6wBWyE=; b=TY8pvnMe4SZrh9P7JA3QHwLBu1MW5Sx0H/DFt6VO2WwkDga7NIJHJQ1TIyFhJzMweC +PmeA0Jny0I2EtCUR0bzLGvtAczqFR/6tpDaTPKo+rvAAXNSzh8xxLjqn9IRCQ3bzDsO ckVeGnA8Ubfmt8RIQNuiD1SBrEw1VdAMmaq2DOhF55aAEsiP5ub8x0C0/iud04o7CO7C qB1Y5UGe8saIc1rpDhCx33HBEYyhymjYgoQblxwZWlfz2Bvgm4FsCUmkAMZ5oIgm2itN qcdt+rkXjM4G1AgVEY4gAY/9Hw4fEt1uB//ATXVj9Xib9SqmbPH9Ucd3t2bWMkGkl5BR JTNg== X-Forwarded-Encrypted: i=1; AFNElJ+pU/feqZ3dXglil6gi05QO3FSum+dYTBWHuMlcBt/2Bu0tpRnS+0Vnxu5a02OJEDyJ5MKl8LtMG5Cgat8=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6IUhoKngOY4ZIy2EF5a0/lc2++tSSpIWRz9+sEAptyxESJbOP kY8hLvCHBNzCjUBls44yfW8CQ+iy16d1AtdbolUElHlEe2KnkRHQoEV2 X-Gm-Gg: AfdE7clt2Tok7VE2FJa1WGtgu3O/Lgg6L00xDaa/GAVJ+e/A0ZSbTrDA8Yz7w6v4yYw 9YbM8xRM4Fcq7HH4frf8putxd+sfUOmOuJ2J4tw0WR2E9Aovo+exxmUry0gMfrF5tI2n6jctZjC grcAy4ArEmC+wlEo4+nk0wtfRmU0XcW5ctkXnPB4LMWEpuuc8W1Tc/+7jYx2iVMKhsWo7YfglZf orouaDbBX+fk9/2ri7+s0W6gIRebivHssdjhxl6YQdAA2AGR1LWG8soqEWEszTVS3t+FV8jZEFm ujIAQBL6wJR5UsBkzDmCuUyCaWYkMKPIWksOY2DMMp1R+5p7uWNvtzgdn5qnZKiobajc6L51A8h EjlzpifATB0a6svLYCNg0KcrhFqqg5WH//t4EyoQbpgCnc0NQzOLT5ipFHvZtwAq7oHi2WNZccS UsMiugDStJR5k= X-Received: by 2002:a05:6402:158e:b0:696:76d2:eee5 with SMTP id 4fb4d7f45d1cf-69775e95a2fmr891593a12.15.1781940444065; Sat, 20 Jun 2026 00:27:24 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6977b84f362sm428637a12.10.2026.06.20.00.27.21 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Jun 2026 00:27:22 -0700 (PDT) Date: Sat, 20 Jun 2026 07:27:21 +0000 From: Wei Yang To: Usama Arif Cc: Andrew Morton , npache@redhat.com, david@kernel.org, ziy@nvidia.com, willy@infradead.org, linux-mm@kvack.org, 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 Subject: Re: [PATCH v2] mm: migrate: requeue destination folio on deferred split queue Message-ID: <20260620072721.x4dfh6gy4wnjqre4@master> Reply-To: Wei Yang References: <20260310105419.3256755-1-usama.arif@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260310105419.3256755-1-usama.arif@linux.dev> User-Agent: NeoMutt/20170113 (1.7.2) On Tue, Mar 10, 2026 at 03:54:19AM -0700, 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 recording whether the source folio was on the deferred split >queue and its partially mapped state before move_to_new_folio() unqueues >it, and re-queuing the destination folio after a successful migration if >it was. > >By the time migrate_folio_move() runs, partially mapped folios without a >pin have already been split by migrate_pages_batch(). So only two cases >remain on the deferred list at this point: > 1. Partially mapped folios with a pin (split failed). > 2. Fully mapped but potentially underused folios. >The recorded partially_mapped state is forwarded to deferred_split_folio() >so that the destination folio is correctly re-queued in both cases. > >Reported-by: Johannes Weiner >Fixes: dafff3f4c850 ("mm: split underused THPs") >Signed-off-by: Usama Arif >--- >v1 -> v2: >- record whether source folio was on the deferred split queue before > move_to_folio() (David) >- record partially mapped state and update commit message (Zi) >--- > mm/migrate.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > >diff --git a/mm/migrate.c b/mm/migrate.c >index ece77ccb2ec0..61013d258eb4 100644 >--- a/mm/migrate.c >+++ b/mm/migrate.c >@@ -1360,6 +1360,8 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private, > int rc; > int old_page_state = 0; > struct anon_vma *anon_vma = NULL; >+ bool src_deferred_split = false; >+ bool src_partially_mapped = false; > struct list_head *prev; > > __migrate_folio_extract(dst, &old_page_state, &anon_vma); >@@ -1373,6 +1375,12 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private, > goto out_unlock_both; > } > >+ if (folio_test_large(src) && folio_test_large_rmappable(src) && >+ !data_race(list_empty(&src->_deferred_list))) { >+ src_deferred_split = true; >+ src_partially_mapped = folio_test_partially_mapped(src); >+ } Hi, Usama I am afraid there maybe a race between migration and defer_split. A B migrate_pages_batch deferred_split_scan migrate_folio_unmap list_del_init(&folio->_deferred_list) folio_lock/folio_trylock migrate_folios_move migrate_folio_move list_empty(&src->_deferred_list) folio_trylock() requeue: In case list_empty() check happens after folio removed from defer_list but before requeued, we will miss this folio. And the behavior is the same before commit fafaeceb89a5, IIUC. Do you thinks this will happen? >+ > rc = move_to_new_folio(dst, src, mode); > if (rc) > goto out; >@@ -1393,6 +1401,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 recorded the state from >+ * before move_to_new_folio(). >+ */ >+ if (src_deferred_split) >+ deferred_split_folio(dst, src_partially_mapped); >+ > out_unlock_both: > folio_unlock(dst); > folio_set_owner_migrate_reason(dst, reason); >-- >2.47.3 > -- Wei Yang Help you, Help me