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 8A3BA2690EC for ; Wed, 19 Aug 2026 15:17:01 +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=1787152622; cv=none; b=h2bojXPuWCWaNVPPZizppkit9xbeogMNrDq4QjxMlhx/2C36oPCc801q/gI0YHZUD1tNKR8/wH9aXVQRVMPNQ7RZ1o8pGu8e80suHdjZJMP7TAsG2GIX2dIL7TyuLOFAUvR9ssq68Jh+n2UWWvE9K5z5XuraJP2lG4tcSCJdmCU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787152622; c=relaxed/simple; bh=piirS+xbfWjEDLKZsvFrwuqU6qrpA4tDRS9Bl3wSfQA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Pkp42qp8TxZRTYgist5PYIyndElBoIV4oeEvKeho9s8eWZ0xn+U26k6GfJZhE3Imnx2ppQpbJ6I+6xLR5vM9uvkZrcbpKrPmr3tgHtAs3Xu+FPAFk9Ieyt1yeH9r0Xw2+BjD6vqxZvaOkFHwMFU9AbcVxhhHvZSVmNGMphSY3ig= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bC38ATcj; 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="bC38ATcj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 234571F00A3D; Wed, 19 Aug 2026 15:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787152621; bh=TIJZ+Vnf9H1+s4n3J23U2JGF74uy2+otNg6jnrrxAo0=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=bC38ATcjWOx8ShaI9WOXsrEILRqTYSq3TXORn0kOmPAoBgYVsbf1f+IO29O5LCkGY 9d40XgNzqUKkPx+OANvdcnPs9BDO/UVwLLt7AFb+RhaVzNBNCMo+SF3+yuo7laiLfU WRhTnuaqmf2zMM76mu/9capqDUk5cWJ6Y8GLEgtQifNGN8opKrFCmSmRYg/MvSqMmC bFISV/QEJOXlti28RXcGlBswyrwN9XrqJQMdrDyyKkfiva8jr+8Tsl8IxlRw36ZKCK zJrByanjUWi3Acrunqn03PBmbQMzxmJsQwELhKVnKFp/m50nNhwAxqzjMJkzsFJCbF mq4me2j49/N2A== Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfauth.ams.internal (Postfix) with ESMTP id 55D661980045; Wed, 19 Aug 2026 11:16:53 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Wed, 19 Aug 2026 11:16:57 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFFAQcZD930YtWtoCMZ6vOXHN1s/JZZPiHZlmcWnnVTPS89T5ThnggZ/j1JZQrgY+ mfbzDzM/k5+b0KuvdZXgKBkmN5a6XSbon/TUIrGY9Cj2rhLJG7IXeceW08r9F3K052egp+ w4P4Dxj56kJ5eMHulVxcC9wt50/9fYRr1dzx9qH1RUpA7C25j8+4qXCEZkODRGJSWOFFM6 jMU2iIK63RNBoZy6so2dmyWmBMy/12VsGpBxLKHN+s6WNB/3HBxp7S+QeZzhhSfQypNpBP 14zTUjgq85k8Lkq0EyNGzDvkIJY6IPYEaNp+sgeUPbNvoOX8SLs+kk37/PGb1saa9CRfgd XZaQDuCE1MUQ59BwBccZA6dv4aOhR3Bwfmi0FJeb8UHJel0YMPSdkP315hT2mxeozV+WeU 2i+8oEA6KAahf0ZyUAUmkpNZtHRO5nwf7FbYL5VOtilLVb/OjwFLH6RQKAb9h8RJbZkwGb VnxNiYovji+Z9nO1/lYmaJK73AWhsajX3zIhaCq+Zza9ZjA4ShcFuaN1gv2z2atRyAaxTH zmKL8yI2yFKPrx8pLOnsfcEyH2TM5XgugHcS7qdMcNbOLsP88Qyyrijoko31N64nB4q76z GfhNJJ0mVsAPl424reFUAZUtaQlA8Vx2ONA+1soticZrLcpLyO3Yb/NtcQ5A X-ME-Proxy: Feedback-ID: i10464835:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 19 Aug 2026 11:16:51 -0400 (EDT) Date: Wed, 19 Aug 2026 16:16:51 +0100 From: Kiryl Shutsemau To: "David Hildenbrand (Arm)" Cc: Usama Arif , Andrew Morton , chrisl@kernel.org, kasong@tencent.com, ljs@kernel.org, ziy@nvidia.com, linux-mm@kvack.org, ying.huang@linux.alibaba.com, Baoquan He , willy@infradead.org, youngjun.park@lge.com, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, alex@ghiti.fr, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, Nico Pache , "Liam R. Howlett" , ryan.roberts@arm.com, Vlastimil Babka , lance.yang@linux.dev, linux-kernel@vger.kernel.org, nphamcs@gmail.com, shikemeng@huaweicloud.com, yosry@kernel.org, kernel-team@meta.com Subject: Re: [PATCH v6 03/12] mm: add PMD swap entry splitting support Message-ID: References: <20260818131202.494754-1-usama.arif@linux.dev> <20260818131202.494754-4-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: On Tue, Aug 18, 2026 at 07:53:48PM +0200, David Hildenbrand (Arm) wrote: > On 8/18/26 15:09, Usama Arif wrote: > > Add a swap branch in __split_huge_pmd_locked() that splits a PMD swap > > entry into 512 PTE swap entries. No folio reference is needed because > > swap entries point to swap slots rather than pages. Each PTE inherits > > the correct sub-slot offset and preserves soft_dirty, uffd_wp, and > > exclusive flags. > > > > The folio_remove_rmap_pmd() gate at the end must inspect old_pmd > > rather than *pmd: for a present THP split, *pmd has already been > > cleared by pmdp_invalidate(), and that invalidated bit pattern can > > decode as a plausible swap entry. > > > > This branch is reached from the explicit __split_huge_pmd() callers > > that hit a non-present PMD: partial-range mprotect / munmap, the > > wp_huge_pmd() PMD-COW fallback, and the swap-in / swapoff fallbacks > > added in later patches when the cached folio is no longer PMD-sized. > > page_vma_mapped_walk() does not iterate PMD swap entries, so > > try_to_unmap_one() and try_to_migrate_one() do not reach this branch > > and freeze=true cannot occur in this branch today. page and folio > > are therefore left uninitialized in the swap branch; a > > VM_WARN_ON_ONCE(freeze) catches any future caller that breaks this > > invariant before the freeze path dereferences page_to_pfn(page + i) > > or put_page(page). > > > > Signed-off-by: Usama Arif > > --- > > mm/huge_memory.c | 29 ++++++++++++++++++++++++++++- > > 1 file changed, 28 insertions(+), 1 deletion(-) > > > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > index 1b6b0aa2baa3b..a473e85d30f51 100644 > > --- a/mm/huge_memory.c > > +++ b/mm/huge_memory.c > > @@ -3252,6 +3252,14 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, > > folio_add_anon_rmap_ptes(folio, page, HPAGE_PMD_NR, > > vma, haddr, rmap_flags); > > } > > + } else if (pmd_is_swap_entry(*pmd)) { > > + VM_WARN_ON_ONCE(freeze); > > + /* Swap entries have no page for the migration freeze path. */ > > + freeze = false; > > It's odd to VM_WARN_ON_ONCE() and then set freeze=false; > > I'd just add the comment above the VM_WARN_ON_ONCE() and drop the =false. VM_WARN_ON_ONCE() is compiled out without DEBUG_VM. The freeze = false is what actually keeps the swap entry out of if (freeze || pmd_is_migration_entry(old_pmd)) { ... make_writable_migration_entry(page_to_pfn(page + i)); and out of the put_page(page) below it, where page is uninitialized in the swap branch. Dropping it leaves nothing on production builds. If freeze = false goes, folio and page must be set to NULL there (or something along the lines). -- Kiryl Shutsemau / Kirill A. Shutemov