mm/khugepaged: unify pmd folio installation with map_anon_folio_pmd()
Subsystems (2)
PATCH v2 1/1 mm/khugepaged: unify pmd folio installation with map_anon_folio_pmd()
Currently we install pmd folio with map_anon_folio_pmd() in __do_huge_pmd_anonymous_page() and do_huge_zero_wp_pmd(). While in collapse_huge_page(), it is done with identical code except statistics adjustment.
Unify the process with map_anon_folio_pmd() to install pmd folio. Split it to map_anon_folio_pmd_pf() and map_anon_folio_pmd_nopf() to be used in page fault or not respectively.
No functional change is intended.
---
v2:
* split to map_anon_folio_pmd_[no]pf() suggested by Matthew
--- include/linux/huge_mm.h | 6 ++++++ mm/huge_memory.c | 14 ++++++++++---- mm/khugepaged.c | 9 +-------- 3 files changed, 17 insertions(+), 12 deletions(-)
include/linux/huge_mm.h +6 -0
@@ -539,6 +539,8 @@ void split_huge_pmd_locked(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd, bool freeze);bool unmap_huge_pmd_locked (struct vm_area_struct *vma,unsigned long addr,pmd_t *pmdp,struct folio *folio); +void map_anon_folio_pmd_nopf (struct folio *folio,pmd_t *pmd, +struct vm_area_struct *vma,unsigned long haddr);#else /* CONFIG_TRANSPARENT_HUGEPAGE */
@@ -629,6 +631,10 @@ static inline bool unmap_huge_pmd_locked(struct vm_area_struct *vma,return false; } +void map_anon_folio_pmd_nopf (struct folio *folio,pmd_t *pmd, +struct vm_area_struct *vma,unsigned long haddr) +{} +#define split_huge_pud (__vma, __pmd, __address) \ do { } while (0)
mm/huge_memory.c +10 -4
@@ -1217,7 +1217,7 @@ static struct folio *vma_alloc_anon_folio_pmd(struct vm_area_struct *vma,return folio; } -static void map_anon_folio_pmd (struct folio *folio,pmd_t *pmd, +void map_anon_folio_pmd_nopf (struct folio *folio,pmd_t *pmd,struct vm_area_struct *vma,unsigned long haddr) {pmd_t entry;
@@ -1228,11 +1228,17 @@ static void map_anon_folio_pmd(struct folio *folio, pmd_t *pmd,folio_add_lru_vma (folio, vma);set_pmd_at (vma->vm_mm, haddr, pmd, entry);update_mmu_cache_pmd (vma, haddr, pmd); +deferred_split_folio (folio, false); +} + +static void map_anon_folio_pmd_pf (struct folio *folio,pmd_t *pmd, +struct vm_area_struct *vma,unsigned long haddr) +{ +map_anon_folio_pmd_nopf (folio, pmd, vma, haddr);add_mm_counter (vma->vm_mm,MM_ANONPAGES ,HPAGE_PMD_NR );count_vm_event (THP_FAULT_ALLOC );count_mthp_stat (HPAGE_PMD_ORDER ,MTHP_STAT_ANON_FAULT_ALLOC );count_memcg_event_mm (vma->vm_mm,THP_FAULT_ALLOC ); -deferred_split_folio (folio, false); }static vm_fault_t __do_huge_pmd_anonymous_page (struct vm_fault *vmf)
@@ -1271,7 +1277,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf)return ret; }pgtable_trans_huge_deposit (vma->vm_mm, vmf->pmd, pgtable); -map_anon_folio_pmd (folio, vmf->pmd, vma, haddr); +map_anon_folio_pmd_pf (folio, vmf->pmd, vma, haddr);mm_inc_nr_ptes (vma->vm_mm);spin_unlock (vmf->ptl); }
@@ -1877,7 +1883,7 @@ static vm_fault_t do_huge_zero_wp_pmd(struct vm_fault *vmf)if (ret) goto release; (void )pmdp_huge_clear_flush (vma, haddr, vmf->pmd); -map_anon_folio_pmd (folio, vmf->pmd, vma, haddr); +map_anon_folio_pmd_pf (folio, vmf->pmd, vma, haddr); goto unlock; release:folio_put (folio);
mm/khugepaged.c +1 -8
@@ -1224,17 +1224,10 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address,__folio_mark_uptodate (folio); pgtable =pmd_pgtable (_pmd); - _pmd =folio_mk_pmd (folio, vma->vm_page_prot); - _pmd =maybe_pmd_mkwrite (pmd_mkdirty (_pmd), vma); -spin_lock (pmd_ptl);BUG_ON (!pmd_none (*pmd)); -folio_add_new_anon_rmap (folio, vma, address,RMAP_EXCLUSIVE ); -folio_add_lru_vma (folio, vma);pgtable_trans_huge_deposit (mm, pmd, pgtable); -set_pmd_at (mm, address, pmd, _pmd); -update_mmu_cache_pmd (vma, address, pmd); -deferred_split_folio (folio, false); +map_anon_folio_pmd_nopf (folio, pmd, vma, address);spin_unlock (pmd_ptl); folio =NULL ;
Signature · 1 line
2.34.1
Quoted 11 lines · Wei Yang
Currently we install pmd folio with
map_anon_folio_pmd()in__do_huge_pmd_anonymous_page()anddo_huge_zero_wp_pmd(). While incollapse_huge_page(), it is done with identical code except statistics adjustment.Unify the process with
map_anon_folio_pmd()to install pmd folio. Split it tomap_anon_folio_pmd_pf()andmap_anon_folio_pmd_nopf()to be used in page fault or not respectively.No functional change is intended.
Quoted 7 lines
Signed-off-by Wei Yang <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lance Yang <[email protected]>Cc Dev Jain <[email protected]>Cc Zi Yan <[email protected]>Cc Usama Arif <[email protected]>Cc Matthew Wilcox <[email protected]>
Nice cleanup!
But one nit below.
Quoted 24 lines
---
v2:
* split to map_anon_folio_pmd_[no]pf() suggested by Matthew--- include/linux/huge_mm.h | 6 ++++++ mm/huge_memory.c | 14 ++++++++++---- mm/khugepaged.c | 9 +-------- 3 files changed, 17 insertions(+), 12 deletions(-)include/linux/huge_mm.h +2
-0@@ -539,6 +539,8 @@ void split_huge_pmd_locked(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd, bool freeze);bool unmap_huge_pmd_locked (struct vm_area_struct *vma,unsigned long addr,pmd_t *pmdp,struct folio *folio); +void map_anon_folio_pmd_nopf (struct folio *folio,pmd_t *pmd, +struct vm_area_struct *vma,unsigned long haddr);#else /* CONFIG_TRANSPARENT_HUGEPAGE */
include/linux/huge_mm.h static inline bool unmap_huge_pmd_locked(struct vm_area_struct *vma, · line 636
Quoted 6 lines
include/linux/huge_mm.h +3
-0@@ -629,6 +631,10 @@ static inline bool unmap_huge_pmd_locked(struct vm_area_struct *vma,return false; } +void map_anon_folio_pmd_nopf (struct folio *folio,pmd_t *pmd, +struct vm_area_struct *vma,unsigned long haddr) +{}
Nit: can you put the braces on separate lines?
+void map_anon_folio_pmd_nopf(struct folio *folio, pmd_t *pmd,
+ struct vm_area_struct *vma, unsigned long haddr)
+{
+}
AFAIK, this is the preferred style in kernel for empty function bodies.
Quoted 77 lines
include/linux/huge_mm.h +1
-0+#define split_huge_pud (__vma, __pmd, __address) \ do { } while (0)mm/huge_memory.c +10
-4@@ -1217,7 +1217,7 @@ static struct folio *vma_alloc_anon_folio_pmd(struct vm_area_struct *vma,return folio; } -static void map_anon_folio_pmd (struct folio *folio,pmd_t *pmd, +void map_anon_folio_pmd_nopf (struct folio *folio,pmd_t *pmd,struct vm_area_struct *vma,unsigned long haddr) {pmd_t entry;@@ -1228,11 +1228,17 @@ static void map_anon_folio_pmd(struct folio *folio, pmd_t *pmd,folio_add_lru_vma (folio, vma);set_pmd_at (vma->vm_mm, haddr, pmd, entry);update_mmu_cache_pmd (vma, haddr, pmd); +deferred_split_folio (folio, false); +} + +static void map_anon_folio_pmd_pf (struct folio *folio,pmd_t *pmd, +struct vm_area_struct *vma,unsigned long haddr) +{ +map_anon_folio_pmd_nopf (folio, pmd, vma, haddr);add_mm_counter (vma->vm_mm,MM_ANONPAGES ,HPAGE_PMD_NR );count_vm_event (THP_FAULT_ALLOC );count_mthp_stat (HPAGE_PMD_ORDER ,MTHP_STAT_ANON_FAULT_ALLOC );count_memcg_event_mm (vma->vm_mm,THP_FAULT_ALLOC ); -deferred_split_folio (folio, false); }static vm_fault_t __do_huge_pmd_anonymous_page (struct vm_fault *vmf)@@ -1271,7 +1277,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf)return ret; }pgtable_trans_huge_deposit (vma->vm_mm, vmf->pmd, pgtable); -map_anon_folio_pmd (folio, vmf->pmd, vma, haddr); +map_anon_folio_pmd_pf (folio, vmf->pmd, vma, haddr);mm_inc_nr_ptes (vma->vm_mm);spin_unlock (vmf->ptl); }@@ -1877,7 +1883,7 @@ static vm_fault_t do_huge_zero_wp_pmd(struct vm_fault *vmf)if (ret) goto release; (void )pmdp_huge_clear_flush (vma, haddr, vmf->pmd); -map_anon_folio_pmd (folio, vmf->pmd, vma, haddr); +map_anon_folio_pmd_pf (folio, vmf->pmd, vma, haddr); goto unlock; release:folio_put (folio);mm/khugepaged.c +1
-8@@ -1224,17 +1224,10 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address,__folio_mark_uptodate (folio); pgtable =pmd_pgtable (_pmd); - _pmd =folio_mk_pmd (folio, vma->vm_page_prot); - _pmd =maybe_pmd_mkwrite (pmd_mkdirty (_pmd), vma); -spin_lock (pmd_ptl);BUG_ON (!pmd_none (*pmd)); -folio_add_new_anon_rmap (folio, vma, address,RMAP_EXCLUSIVE ); -folio_add_lru_vma (folio, vma);pgtable_trans_huge_deposit (mm, pmd, pgtable); -set_pmd_at (mm, address, pmd, _pmd); -update_mmu_cache_pmd (vma, address, pmd); -deferred_split_folio (folio, false); +map_anon_folio_pmd_nopf (folio, pmd, vma, address);spin_unlock (pmd_ptl); folio =NULL ;
Quoted 19 lines · Wei Yang
Currently we install pmd folio with
map_anon_folio_pmd()in__do_huge_pmd_anonymous_page()anddo_huge_zero_wp_pmd(). While incollapse_huge_page(), it is done with identical code except statistics adjustment.Unify the process with
map_anon_folio_pmd()to install pmd folio. Split it tomap_anon_folio_pmd_pf()andmap_anon_folio_pmd_nopf()to be used in page fault or not respectively.No functional change is intended.
Signed-off-by Wei Yang <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lance Yang <[email protected]>Cc Dev Jain <[email protected]>Cc Zi Yan <[email protected]>Cc Usama Arif <[email protected]>Cc Matthew Wilcox <[email protected]>
Quoted 3 lines
---
v2:
* split to map_anon_folio_pmd_[no]pf() suggested by Matthew
On which branch this patch applies against ?
Dev Jain
reviewerQuoted 21 lines · Anshuman Khandual
Quoted 19 lines · Wei Yang
Currently we install pmd folio with
map_anon_folio_pmd()in__do_huge_pmd_anonymous_page()anddo_huge_zero_wp_pmd(). While incollapse_huge_page(), it is done with identical code except statistics adjustment.Unify the process with
map_anon_folio_pmd()to install pmd folio. Split it tomap_anon_folio_pmd_pf()andmap_anon_folio_pmd_nopf()to be used in page fault or not respectively.No functional change is intended.
Signed-off-by Wei Yang <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lance Yang <[email protected]>Cc Dev Jain <[email protected]>Cc Zi Yan <[email protected]>Cc Usama Arif <[email protected]>Cc Matthew Wilcox <[email protected]>
Quoted 4 lines
Quoted 3 lines
---
v2:
* split to map_anon_folio_pmd_[no]pf() suggested by MatthewOn which branch this patch applies against ?
+1, does not apply on mm-new for me. There have been multiple patches changing the same file so it will be beneficial to say what commit it applies against.
Quoted 1 line
Lance Yang
reviewerQuoted 23 lines · Dev Jain
Quoted 21 lines · Anshuman Khandual
Quoted 19 lines · Wei Yang
Currently we install pmd folio with
map_anon_folio_pmd()in__do_huge_pmd_anonymous_page()anddo_huge_zero_wp_pmd(). While incollapse_huge_page(), it is done with identical code except statistics adjustment.Unify the process with
map_anon_folio_pmd()to install pmd folio. Split it tomap_anon_folio_pmd_pf()andmap_anon_folio_pmd_nopf()to be used in page fault or not respectively.No functional change is intended.
Signed-off-by Wei Yang <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lance Yang <[email protected]>Cc Dev Jain <[email protected]>Cc Zi Yan <[email protected]>Cc Usama Arif <[email protected]>Cc Matthew Wilcox <[email protected]>
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
---
v2:
* split to map_anon_folio_pmd_[no]pf() suggested by MatthewOn which branch this patch applies against ?
+1, does not apply on mm-new for me. There have been multiple patches changing the same file so it will be beneficial to say what commit it applies against.
I think this patch applies on top of the patch[1], which is based on mm-new.
Dev Jain
reviewerQuoted 31 lines · Lance Yang
Quoted 28 lines · Dev Jain
Quoted 25 lines · Anshuman Khandual
Quoted 19 lines · Wei Yang
Currently we install pmd folio with
map_anon_folio_pmd()in__do_huge_pmd_anonymous_page()anddo_huge_zero_wp_pmd(). While incollapse_huge_page(), it is done with identical code except statistics adjustment.Unify the process with
map_anon_folio_pmd()to install pmd folio. Split it tomap_anon_folio_pmd_pf()andmap_anon_folio_pmd_nopf()to be used in page fault or not respectively.No functional change is intended.
Signed-off-by Wei Yang <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lance Yang <[email protected]>Cc Dev Jain <[email protected]>Cc Zi Yan <[email protected]>Cc Usama Arif <[email protected]>Cc Matthew Wilcox <[email protected]>Quoted 3 lines
---
v2:
* split to map_anon_folio_pmd_[no]pf() suggested by MatthewOn which branch this patch applies against ?
Quoted 8 lines
Quoted 3 lines
+1, does not apply on mm-new for me. There have been multiple patches changing the same file so it will be beneficial to say what commit it applies against.
I think this patch applies on top of the patch[1], which is based on mm-new.
Thanks, but this is not yet in mm-new. There are some unaddressed comments there.
Wei, please resend this patch based on mm-new. I would urge you to hold off sending
multiple patches all of which change the same file and have close dependency, till the
first one gets merged.
Quoted 2 lines
Zi Yan
reviewerQuoted 40 lines · Dev Jain
Quoted 31 lines · Lance Yang
Quoted 28 lines · Dev Jain
Quoted 25 lines · Anshuman Khandual
Quoted 19 lines · Wei Yang
Currently we install pmd folio with
map_anon_folio_pmd()in__do_huge_pmd_anonymous_page()anddo_huge_zero_wp_pmd(). While incollapse_huge_page(), it is done with identical code except statistics adjustment.Unify the process with
map_anon_folio_pmd()to install pmd folio. Split it tomap_anon_folio_pmd_pf()andmap_anon_folio_pmd_nopf()to be used in page fault or not respectively.No functional change is intended.
Signed-off-by Wei Yang <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lance Yang <[email protected]>Cc Dev Jain <[email protected]>Cc Zi Yan <[email protected]>Cc Usama Arif <[email protected]>Cc Matthew Wilcox <[email protected]>Quoted 3 lines
---
v2:
* split to map_anon_folio_pmd_[no]pf() suggested by MatthewOn which branch this patch applies against ?
Quoted 7 lines
Quoted 3 lines
+1, does not apply on mm-new for me. There have been multiple patches changing the same file so it will be beneficial to say what commit it applies against.
I think this patch applies on top of the patch[1], which is based on mm-new.
Quoted 7 lines
Thanks, but this is not yet in mm-new. There are some unaddressed comments there.
Wei, please resend this patch based on mm-new. I would urge you to hold off sending
multiple patches all of which change the same file and have close dependency, till the
first one gets merged.
Or just send both patches in a series to show the dependency. That makes reviewers’ lives much easier.
Best Regards,
Yan, Zi
Quoted 42 lines · Zi Yan
Quoted 40 lines · Dev Jain
Quoted 38 lines · Lance Yang
Quoted 23 lines · Dev Jain
Quoted 21 lines · Anshuman Khandual
Quoted 19 lines · Wei Yang
Currently we install pmd folio with
map_anon_folio_pmd()in__do_huge_pmd_anonymous_page()anddo_huge_zero_wp_pmd(). While incollapse_huge_page(), it is done with identical code except statistics adjustment.Unify the process with
map_anon_folio_pmd()to install pmd folio. Split it tomap_anon_folio_pmd_pf()andmap_anon_folio_pmd_nopf()to be used in page fault or not respectively.No functional change is intended.
Signed-off-by Wei Yang <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lance Yang <[email protected]>Cc Dev Jain <[email protected]>Cc Zi Yan <[email protected]>Cc Usama Arif <[email protected]>Cc Matthew Wilcox <[email protected]>Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
---
v2:
* split to map_anon_folio_pmd_[no]pf() suggested by MatthewOn which branch this patch applies against ?
+1, does not apply on mm-new for me. There have been multiple patches changing the same file so it will be beneficial to say what commit it applies against.
I think this patch applies on top of the patch[1], which is based on mm-new.
Quoted 7 lines
Quoted 7 lines
Thanks, but this is not yet in mm-new. There are some unaddressed comments there.
Wei, please resend this patch based on mm-new. I would urge you to hold off sending
multiple patches all of which change the same file and have close dependency, till the
first one gets merged.
Sorry for the unconvenience.
Quoted 4 lines
Or just send both patches in a series to show the dependency. That makes reviewers’ lives much easier.
Thanks, this is a good suggestion. Will resend them together.
Quoted 2 lines
Best Regards,
Yan, Zi
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 42 lines · Wei Yang
Currently we install pmd folio with
map_anon_folio_pmd()in__do_huge_pmd_anonymous_page()anddo_huge_zero_wp_pmd(). While incollapse_huge_page(), it is done with identical code except statistics adjustment.Unify the process with
map_anon_folio_pmd()to install pmd folio. Split it tomap_anon_folio_pmd_pf()andmap_anon_folio_pmd_nopf()to be used in page fault or not respectively.No functional change is intended.
Signed-off-by Wei Yang <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lance Yang <[email protected]>Cc Dev Jain <[email protected]>Cc Zi Yan <[email protected]>Cc Usama Arif <[email protected]>Cc Matthew Wilcox <[email protected]>---
v2:
* split to map_anon_folio_pmd_[no]pf() suggested by Matthew--- include/linux/huge_mm.h | 6 ++++++ mm/huge_memory.c | 14 ++++++++++---- mm/khugepaged.c | 9 +-------- 3 files changed, 17 insertions(+), 12 deletions(-)include/linux/huge_mm.h +2
-0@@ -539,6 +539,8 @@ void split_huge_pmd_locked(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd, bool freeze);bool unmap_huge_pmd_locked (struct vm_area_struct *vma,unsigned long addr,pmd_t *pmdp,struct folio *folio); +void map_anon_folio_pmd_nopf (struct folio *folio,pmd_t *pmd, +struct vm_area_struct *vma,unsigned long haddr);#else /* CONFIG_TRANSPARENT_HUGEPAGE */
include/linux/huge_mm.h static inline bool unmap_huge_pmd_locked(struct vm_area_struct *vma, · line 636
Quoted 6 lines
include/linux/huge_mm.h +3
-0@@ -629,6 +631,10 @@ static inline bool unmap_huge_pmd_locked(struct vm_area_struct *vma,return false; } +void map_anon_folio_pmd_nopf (struct folio *folio,pmd_t *pmd, +struct vm_area_struct *vma,unsigned long haddr) +{}
static inline void ...
And as Lance mentioned, put {} on separate lines.
Nothing else jumped at me, thanks!
Signature · 3 lines
Cheers David / dhildenb
Quoted 19 lines · Wei Yang
Currently we install pmd folio with
map_anon_folio_pmd()in__do_huge_pmd_anonymous_page()anddo_huge_zero_wp_pmd(). While incollapse_huge_page(), it is done with identical code except statistics adjustment.Unify the process with
map_anon_folio_pmd()to install pmd folio. Split it tomap_anon_folio_pmd_pf()andmap_anon_folio_pmd_nopf()to be used in page fault or not respectively.No functional change is intended.
Signed-off-by Wei Yang <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lance Yang <[email protected]>Cc Dev Jain <[email protected]>Cc Zi Yan <[email protected]>Cc Usama Arif <[email protected]>Cc Matthew Wilcox <[email protected]>
Quoted 8 lines
---
v2:
* split to map_anon_folio_pmd_[no]pf() suggested by Matthew--- include/linux/huge_mm.h | 6 ++++++ mm/huge_memory.c | 14 ++++++++++---- mm/khugepaged.c | 9 +-------- 3 files changed, 17 insertions(+), 12 deletions(-)
After addressing Lance’s and David’s comments, feel free to add:
Best Regards,
Yan, Zi