[PATCH v2 08/14] mm/khugepaged: Remove redundant pmd_devmap() check

Alistair Popple posted 14 patches 3 months, 3 weeks ago
There is a newer version of this series
[PATCH v2 08/14] mm/khugepaged: Remove redundant pmd_devmap() check
Posted by Alistair Popple 3 months, 3 weeks ago
The only users of pmd_devmap were device dax and fs dax. The check for
pmd_devmap() in check_pmd_state() is therefore redundant as callers
explicitly check for is_zone_device_page(), so this check can be dropped.

Signed-off-by: Alistair Popple <apopple@nvidia.com>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
 mm/khugepaged.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 15203ea..d45d08b 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -945,8 +945,6 @@ static inline int check_pmd_state(pmd_t *pmd)
 		return SCAN_PMD_NULL;
 	if (pmd_trans_huge(pmde))
 		return SCAN_PMD_MAPPED;
-	if (pmd_devmap(pmde))
-		return SCAN_PMD_NULL;
 	if (pmd_bad(pmde))
 		return SCAN_PMD_NULL;
 	return SCAN_SUCCEED;
-- 
git-series 0.9.1
Re: [PATCH v2 08/14] mm/khugepaged: Remove redundant pmd_devmap() check
Posted by David Hildenbrand 3 months, 3 weeks ago
On 16.06.25 13:58, Alistair Popple wrote:
> The only users of pmd_devmap were device dax and fs dax. The check for
> pmd_devmap() in check_pmd_state() is therefore redundant as callers
> explicitly check for is_zone_device_page(), so this check can be dropped.
> 

Looking again, is this true?

If we return "SCAN_SUCCEED", we assume there is a page table there that 
we can map and walk.

But I assume we can drop that check because nobody will ever set 
pmd_devmap() anymore?

So likely just the description+sibject of this patch should be adjusted.

FWIW, I think check_pmd_state() should be changed to work on pmd_leaf() 
etc, but that's something for another day.

-- 
Cheers,

David / dhildenb
Re: [PATCH v2 08/14] mm/khugepaged: Remove redundant pmd_devmap() check
Posted by Alistair Popple 3 months, 3 weeks ago
On Tue, Jun 17, 2025 at 11:44:30AM +0200, David Hildenbrand wrote:
> On 16.06.25 13:58, Alistair Popple wrote:
> > The only users of pmd_devmap were device dax and fs dax. The check for
> > pmd_devmap() in check_pmd_state() is therefore redundant as callers
> > explicitly check for is_zone_device_page(), so this check can be dropped.
> > 
> 
> Looking again, is this true?
> 
> If we return "SCAN_SUCCEED", we assume there is a page table there that we
> can map and walk.
> 
> But I assume we can drop that check because nobody will ever set
> pmd_devmap() anymore?
> 
> So likely just the description+sibject of this patch should be adjusted.

Ugh. I wish I had've documented this better because it's all very "obvious",
but I think the description is still accurate. These devmap checks could never
have been hit and were therefore redundant, because in practice all callers call
thp_vma_allowable_order() either before or after check_pmd_state() (or both).

thp_vma_allowable_order() will eventually (in __thp_vma_allowable_orders())
check for a DAX VMA and bail. But yes, I should call that out in the patch
subject so I don't have to keep relearning this obvious fact :-)

> FWIW, I think check_pmd_state() should be changed to work on pmd_leaf() etc,
> but that's something for another day.

Sure, and I do appreciate these kind of remarks because sometimes I get bored
enough to come back and actually do them. Not very often ... but sometimes.

> -- 
> Cheers,
> 
> David / dhildenb
>