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 7C7533EF64A for ; Tue, 18 Aug 2026 18:42:16 +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=1787078537; cv=none; b=TCKl5j95D88++NKQsRYg6c/cil7uVDtRdumFOq9zQxTu2tK7/HIsG4dZgM+9qi1ldh4bmRBk/uh1oJ7wkl71yGH6eGfuFHzIkbxD1mYDRT1XyBIRHcvQj96M73MMQgNk44ZXMTQbIzhgb/viLtW/yUADG4HHkZSUddy4g42Uotc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787078537; c=relaxed/simple; bh=OSp9bi+mi2299ANnBwwwXQnqQEd4Xgwdwp6Poos4aHA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qNBkT8ayY1Mebkb89ww+1yeSjNrwwmITkSGpy3byydVLYZa+LmKmOJAGnths8hUtzSjyXYt7LijOlXwU52F8ycPSmE1MGkWb9n8NHBHAzERSCuuFRW9fqL+8rGNyKS4R7YNhrg01c89aNB6lD5vfLsLAYlVoZRHf5d9qNiHDCLs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bjzkzA5c; 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="bjzkzA5c" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F17B1F000E9; Tue, 18 Aug 2026 18:42:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787078536; bh=DV5Xiy/AmYlLlBBUlANyFhMnUD/qJF7tkMdEBI76djE=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=bjzkzA5cyjcxb6jvIbL/KCjgThSfC4YBnQRMhTomD6xhGLADPUzVSD/wVbTSD7Qbn 2Igf6eAFgtxhjB2K4PDpnwl0C1Js4HyZiz6nnnyQT3DTYqQ3JGbppjmDzh4OrDIsVw 0NPBiGbZUr9HL/pia+wDl3eRS+uUgadkU4A6AvnJ38/63WPfTViWOydhKK8zRqvbS1 O5XVJVR6oE+KUYjcwJaqrQzJoLwyjKTCtMbNXQaeHUkmwwRvx+XDKq8sKuWmCtW/5O nWk6vEQx/5pAHpdfjuMPWXRUhh+3HLLLddrJk7nKVtFfT2Euc7yIFzGy/TiBhObUeP 5zNkANsCpk5ig== Date: Tue, 18 Aug 2026 19:42:07 +0100 From: "Lorenzo Stoakes (ARM)" To: "David Hildenbrand (Arm)" Cc: Usama Arif , Andrew Morton , chrisl@kernel.org, kasong@tencent.com, 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, kas@kernel.org, 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 02/12] mm: add PMD swap entry detection support Message-ID: References: <20260818131202.494754-1-usama.arif@linux.dev> <20260818131202.494754-3-usama.arif@linux.dev> <69e8469c-aa7f-4141-be3c-796c9cf11f2f@kernel.org> 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: <69e8469c-aa7f-4141-be3c-796c9cf11f2f@kernel.org> On Tue, Aug 18, 2026 at 04:40:25PM +0200, David Hildenbrand (Arm) wrote: > On 8/18/26 15:09, Usama Arif wrote: > > Currently when a PMD-mapped THP is swapped out, the PMD is always > > split into HPAGE_PMD_NR PTE-level swap entries. To preserve huge > > page information across swap cycles, later patches will install a > > single PMD-level swap entry instead. Add the infrastructure to detect > > those entries. > > > > Teach the softleaf layer to recognise PMD swap entries: > > pmd_is_swap_entry() detects them and softleaf_is_valid_pmd_entry() > > accepts them as a valid non-present type. Because swap entries do not > > encode a PFN, make pmd_softleaf_to_folio() warn and return NULL for them > > instead of passing the swap offset to softleaf_to_folio(). Clear the > > exclusive overlay bit in softleaf_from_pmd() before decoding, matching > > how soft_dirty and uffd bits are already stripped. > > > > Add pmd_swp_mkexclusive(), pmd_swp_exclusive(), and > > pmd_swp_clear_exclusive() helpers to each architecture that supports > > PMD softleaf entries (x86, arm64, s390, riscv, loongarch, powerpc), > > mirroring the existing PTE swap exclusive helpers in each arch's > > pgtable.h. > > Ah, for migration entries we still use a dedicated migratetype. I actually have > on my todo list to move to PTE bits as well. We do seem to have rather hacked in PMD level stuff across the board previously :) > > (likely the _swp_ part should then be renamed to indicate that this is for > softdirty entries, not just swap entries) You mean softleaf? > > > Provide generic no-op PMD swap exclusive fallbacks for > > architectures without PMD softleaf support, matching the generic PMD > > swap soft-dirty fallbacks. > > No softleaf implies to migration and no swap, so this would work. > > You should extend mm/debug_vm_pgtable.c in a separate commit to test what > pte_swap_exclusive_tests() tests for PMDs. BTW one thing I should maybe mention here is that I never quite _finished_ the softleaf thing, so there's some awkward overlap between swap stuff and softleaf stuff (swap entries _are_ softleaf entries, just a specific kind). Infinite TODO list etc. (maybe this is a hint/nudge to somebody else to do it ;) > > > > > Signed-off-by: Usama Arif > > --- > > arch/arm64/include/asm/pgtable.h | 6 +++++ > > arch/loongarch/include/asm/pgtable.h | 19 ++++++++++++++ > > arch/powerpc/include/asm/book3s/64/pgtable.h | 17 +++++++++++++ > > arch/riscv/include/asm/pgtable.h | 15 +++++++++++ > > arch/s390/include/asm/pgtable.h | 17 +++++++++++++ > > arch/x86/include/asm/pgtable.h | 17 +++++++++++++ > > I'm sorry for asking you to compete with Kiryll's series by creating one patch > for each architecture that directly jumps at arch maintainers :) > > [...] > > > #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY > > static inline pte_t pte_swp_mksoft_dirty(pte_t pte) > > { > > diff --git a/include/linux/leafops.h b/include/linux/leafops.h > > index 7c13c58a5e218..4a6c52974b305 100644 > > --- a/include/linux/leafops.h > > +++ b/include/linux/leafops.h > > @@ -102,6 +102,8 @@ static inline softleaf_t softleaf_from_pmd(pmd_t pmd) > > pmd = pmd_swp_clear_soft_dirty(pmd); > > if (pmd_swp_uffd(pmd)) > > pmd = pmd_swp_clear_uffd(pmd); > > + if (pmd_swp_exclusive(pmd)) > > + pmd = pmd_swp_clear_exclusive(pmd); > > Can't we just unconditionally clear these flags? > > pmd = pmd_swp_clear_uffd(pmd); > pmd = pmd_swp_clear_exclusive(pmd); > > Avoids these rather unnecessary conditionals unless I am missing something. > > > > arch_entry = __pmd_to_swp_entry(pmd); > > > > /* Temporary until swp_entry_t eliminated. */ > > @@ -634,18 +636,30 @@ static inline bool pmd_is_migration_entry(pmd_t pmd) > > */ > > static inline bool softleaf_is_valid_pmd_entry(softleaf_t entry) > > { > > - /* Only device private, migration entries valid for PMD. */ > > + /* Device private, migration, and swap entries valid for PMD. */ > > Can we just drop that comment? I mean, it's as clear as it gets in the code > immediately below :) > > > return softleaf_is_device_private(entry) || > > - softleaf_is_migration(entry); > > + softleaf_is_migration(entry) || > > + softleaf_is_swap(entry); > > +} > > + > > -- > Cheers, > > David -- Cheers, Lorenzo