From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 8CDE037883C for ; Mon, 22 Jun 2026 13:43:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782135816; cv=none; b=rQpoDDuLdpPhLtU8Rq3XY1x9tpRy27s7879KQL3o+R01rFa4E1d2Icl91qcllbRRR1SLRqgCrdTfomPywpAfv/j3a0F3LJTAx55SYucRuySpagBahrNCxEIyS1TxMwBCc6JuYy+jn8xUSOCtVOLCgmQB/n7dSsSuaCdgD9+xwso= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782135816; c=relaxed/simple; bh=WQuvc1JsFNvQFm1EJudxg74jSa0Nk+TQA1vRJnOW6Zw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GP0C4i2rk1/J7rAkuglKANoebOuDqbRYzwUAAa9cVpTHG17pujf8eutYqZUHlVOBdq2ThCToa0M84e+03KpmBYqeFRXQXcEyQdgPzwKcG3gPF5KCd2yuA6SdmoiHzD9VJmesQx6hGe+5Bs26mubKVDHkJbAT3XCOBYmua+gmEOc= 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=AJCOJoeJ; arc=none smtp.client-ip=209.85.218.45 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="AJCOJoeJ" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-bec423a5265so779916666b.1 for ; Mon, 22 Jun 2026 06:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782135813; x=1782740613; 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=gapKFppUXnPp8khihX/tbiyvBsky81sBAkI/bVrBroQ=; b=AJCOJoeJAxevX042jOEovpJgHl3wXggSGJ9ld9qofTNGRA05bBP7OIkRLUVsVYqVJq AaJIY8hb27OTzszlhwvtreuOgr096z13bBdGLHHICgDdMGQkDBjzHKoPSdl95efX4u7E dPF0nTC+qVrPj+RCXIEuoj1Mu3TtqDRBs64JG+t7Y6YobfNPoSATeWqGhhtFzMbLWTwM 6hUiy/aqwl0QEwpLoh1x0a/sc0n2rLd17P/fpw7jB4nJYH/vm9aV1XlZmokSjY97ifA4 PmKascZqsjrUvkc7yfmAD8gugQFdGuC9xm16ktNm1nTYSUkJe/Kny4XIIDz9VL576r5J 0e5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782135813; x=1782740613; 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=gapKFppUXnPp8khihX/tbiyvBsky81sBAkI/bVrBroQ=; b=aNHvHKgGlE6s1/O2vk8nQSoSj+KXDqE/L6cZ1hmneOFumvIGxfg2jwSMHHASE4eQZF Wamz0gVkcljzZtEy6yRipndliF1QX21uuIMxu/1zfs0HW+0PkZcSpFjfYKxfSJL+1egh eNQcE1euh2XrAPHDQNWKmYCAqTPY9EDO5xv71Nt4LerF5TZXiQ6NucWohvAoWcJvMRza q9Lhr4gaRog5P99ZSv6mBf5UTGPN30ypOjn9OiX+9leyIk3nPsFolSKUba8POiqTlj42 bGyNGRBdlQLZ2R4+0wRqvyJBj6tbpAsQMk4RhvIhCmPLDl7lC6srRiVzSRa0/6zmZmq4 TKrw== X-Forwarded-Encrypted: i=1; AFNElJ/3ZPC98sLHCt3r16UMn1hO/UvIuLgl421Qhhx3HfKL01zEfP01N43g9OEThhFZyWFDKAVinKrkU+k61AM=@vger.kernel.org X-Gm-Message-State: AOJu0YwxF3PDVOL7dglNhKzwWQ/OJRNM0Rkipxp4Fym4g4OcKfKtFBBY fXTTp1pBYQNyMlmaIfKpeK2kDN1Z8/0Ybjs5nR+IrVa9si/eR7J41iLd X-Gm-Gg: AfdE7cn6KIXbRT4Fd72twcI/BqqrhyUjXM9UP7QhHElU9YBQcSTW4MW8aaRZbZmZAWl wd1XpDyjBjORDdSExn3IsK220yu+5U6RktJRXg5KpjtuI1G+TnNZvo5qA/Why2d8MAzoidy00Ab F7TCHpB2pY1q849bSc+4z2+zUHy531XJ0amDBVgMLCJOfQe4WlMdwd2634CM1hgGEBO+KVqf6Ok UaEmEWB5p9RfPWHqJc5vBKH9r/QvanKqmj2IRLemEoVsHd42J4mGyJcqvZ7wpAG6ogUbv3nKmMV 04ELHjvXh5i5sJqd0MCEyU3Jv5mQpivznp80Y+WNu043QCQRIPfDejbJChXSddkPIPhOd5Y7OpD 8QLybDrM5omJ4/c5EWu5lfU0YV1aizoY7uyyNAYBeJ/1IAZPZdueZtR9Kk9eqUjsYIImxI0F+09 8JhM3pSYsGHXk= X-Received: by 2002:a17:907:60cc:b0:c0d:5466:ce4c with SMTP id a640c23a62f3a-c0d5466d9dcmr453345266b.1.1782135812718; Mon, 22 Jun 2026 06:43:32 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c0c5e497fc3sm363612366b.8.2026.06.22.06.43.32 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Jun 2026 06:43:32 -0700 (PDT) Date: Mon, 22 Jun 2026 13:43:31 +0000 From: Wei Yang To: "David Hildenbrand (Arm)" Cc: Wei Yang , Usama Arif , Andrew Morton , npache@redhat.com, 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: <20260622134331.xvbpu6edwml65myp@master> Reply-To: Wei Yang References: <20260310105419.3256755-1-usama.arif@linux.dev> <20260620072721.x4dfh6gy4wnjqre4@master> 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: User-Agent: NeoMutt/20170113 (1.7.2) On Mon, Jun 22, 2026 at 11:16:39AM +0200, David Hildenbrand (Arm) wrote: >On 6/20/26 09:27, Wei Yang wrote: >> 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. > >deferred_split_isolate() would grab a reference through folio_try_get(). > >How can we migrate a folio with a raised refcount? > Thanks, I missed expected_refcount check in __migrate_folio(). >-- >Cheers, > >David -- Wei Yang Help you, Help me