Add update_mmu_tlb_range() to simplify code
Subsystems (6)
cover Add update_mmu_tlb_range() to simplify code
This series of commits mainly adds the update_mmu_tlb_range() to batch update tlb in an address range.
After the commit 19eaf44954df ("mm: thp: support allocation of anonymous multi-size THP"), We may need to batch update tlb of a certain address range by calling update_mmu_tlb() in a loop. Using the update_mmu_tlb_range(), we can simplify the code and possibly reduce the execution of some unnecessary code in some architectures.
Bang Li (5):
LoongArch: Add update_mmu_tlb_range()
mips: Add update_mmu_tlb_range()
riscv: Add update_mmu_tlb_range()
xtensa: Add update_mmu_tlb_range()
mm: Add update_mmu_tlb_range()
arch/loongarch/include/asm/pgtable.h | 2 ++ arch/mips/include/asm/pgtable.h | 2 ++ arch/riscv/include/asm/pgtable.h | 2 ++ arch/xtensa/include/asm/pgtable.h | 2 ++ arch/xtensa/mm/tlb.c | 6 ++++++ include/linux/pgtable.h | 5 +++++ mm/memory.c | 4 +--- 7 files changed, 20 insertions(+), 3 deletions(-)
Signature · 1 line
2.19.1.6.gb485710b
PATCH 1/5 LoongArch: Add update_mmu_tlb_range()
Added update_mmu_tlb_range function, we can batch update tlb of an address range.
--- arch/loongarch/include/asm/pgtable.h | 2 ++ 1 file changed, 2 insertions(+)
arch/loongarch/include/asm/pgtable.h +2 -0
@@ -469,6 +469,8 @@ static inline void update_mmu_cache_range(struct vm_fault *vmf,#define __HAVE_ARCH_UPDATE_MMU_TLB#define update_mmu_tlb update_mmu_cache +#define update_mmu_tlb_range (vma, addr, ptep, nr) \ + update_mmu_cache_range(NULL, vma, addr, ptep, nr)static inline void update_mmu_cache_pmd (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp)
Signature · 1 line
2.19.1.6.gb485710b
PATCH 2/5 mips: Add update_mmu_tlb_range()
In reply to Bang LiAdded update_mmu_tlb_range function, we can batch update tlb of an address range.
--- arch/mips/include/asm/pgtable.h | 2 ++ 1 file changed, 2 insertions(+)
arch/mips/include/asm/pgtable.h +2 -0
@@ -596,6 +596,8 @@ static inline void update_mmu_cache_range(struct vm_fault *vmf,#define __HAVE_ARCH_UPDATE_MMU_TLB#define update_mmu_tlb update_mmu_cache +#define update_mmu_tlb_range (vma, address, ptep, nr) \ + update_mmu_cache_range(NULL, vma, address, ptep, nr)static inline void update_mmu_cache_pmd (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp)
Signature · 1 line
2.19.1.6.gb485710b
PATCH 3/5 riscv: Add update_mmu_tlb_range()
In reply to Bang LiAdded update_mmu_tlb_range function, we can batch update tlb of an address range.
--- arch/riscv/include/asm/pgtable.h | 2 ++ 1 file changed, 2 insertions(+)
arch/riscv/include/asm/pgtable.h +2 -0
@@ -488,6 +488,8 @@ static inline void update_mmu_cache_range(struct vm_fault *vmf,#define __HAVE_ARCH_UPDATE_MMU_TLB#define update_mmu_tlb update_mmu_cache +#define update_mmu_tlb_range (vma, addr, ptep, nr) \ + update_mmu_cache_range(NULL, vma, addr, ptep, nr)static inline void update_mmu_cache_pmd (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp)
Signature · 1 line
2.19.1.6.gb485710b
PATCH 4/5 xtensa: Add update_mmu_tlb_range()
In reply to Bang LiAdded update_mmu_tlb_range function, we can batch update tlb of an address range.
--- arch/xtensa/include/asm/pgtable.h | 2 ++ arch/xtensa/mm/tlb.c | 6 ++++++ 2 files changed, 8 insertions(+)
arch/xtensa/include/asm/pgtable.h +2 -0
@@ -412,6 +412,8 @@ typedef pte_t *pte_addr_t;void update_mmu_tlb (struct vm_area_struct *vma,unsigned long address,pte_t *ptep); +void update_mmu_tlb_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr);#define __HAVE_ARCH_UPDATE_MMU_TLB#endif /* !defined (__ASSEMBLY__) */
arch/xtensa/mm/tlb.c +6 -0
@@ -169,6 +169,12 @@ void update_mmu_tlb(struct vm_area_struct *vma,local_flush_tlb_page (vma, address); } +void update_mmu_tlb_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) +{ +local_flush_tlb_range (vma, address, address +PAGE_SIZE * nr); +} +#ifdef CONFIG_DEBUG_TLB_SANITY static unsigned get_pte_for_vaddr (unsigned vaddr)
Signature · 1 line
2.19.1.6.gb485710b
PATCH 5/5 mm: Add update_mmu_tlb_range()
In reply to Bang LiAfter the commit 19eaf44954df ("mm: thp: support allocation of anonymous multi-size THP"), it may need to batch update tlb of an address range through the update_mmu_tlb function. We can simplify this operation by adding the update_mmu_tlb_range function, which may also reduce the execution of some unnecessary code in some architectures.
--- include/linux/pgtable.h | 5 +++++ mm/memory.c | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-)
include/linux/pgtable.h +5 -0
@@ -734,6 +734,11 @@ static inline void update_mmu_tlb(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) { } + +static inline void update_mmu_tlb_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) +{ +}#define __HAVE_ARCH_UPDATE_MMU_TLB#endif
mm/memory.c +1 -3
@@ -4396,7 +4396,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)vm_fault_t ret =0 ;int nr_pages =1 ;pte_t entry; -int i;/* File mapping without ->vm_ops ? */ if (vma->vm_flags &VM_SHARED )
@@ -4465,8 +4464,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)update_mmu_tlb (vma, addr, vmf->pte); goto release; }else if (nr_pages >1 && !pte_range_none (vmf->pte, nr_pages)) { -for (i =0 ; i < nr_pages; i++) -update_mmu_tlb (vma, addr +PAGE_SIZE * i, vmf->pte + i); +update_mmu_tlb_range (vma, addr, vmf->pte, nr_pages); goto release; }
Signature · 1 line
2.19.1.6.gb485710b
Re: [PATCH v1 5/5] mm: Add update_mmu_tlb_range()
Hey Bang,
Quoted 18 lines · Bang Li
After the commit
19eaf44954df("mm: thp: support allocation of anonymous multi-size THP"), it may need to batch update tlb of an address range through theupdate_mmu_tlbfunction. We can simplify this operation by adding theupdate_mmu_tlb_rangefunction, which may also reduce the execution of some unnecessary code in some architectures.Signed-off-by Bang Li <[email protected]>--- include/linux/pgtable.h | 5 +++++ mm/memory.c | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-)include/linux/pgtable.h +0
-0
include/linux/pgtable.h static inline void update_mmu_tlb(struct vm_area_struct *vma, · line 743
Quoted 10 lines
include/linux/pgtable.h +5
-0@@ -734,6 +734,11 @@ static inline void update_mmu_tlb(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) { } + +static inline void update_mmu_tlb_range (struct vm_area_struct *vma, +unsigned long address,pte_t *ptep,unsigned int nr) +{ +}#define __HAVE_ARCH_UPDATE_MMU_TLB#endif
IMO, it might be better to use a separate definition to determine whether update_mmu_tlb_range() is overridden by a specific architecture.
Thanks,
Lance
Quoted 26 lines
mm/memory.c +1
-4@@ -4396,7 +4396,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)vm_fault_t ret =0 ;int nr_pages =1 ;pte_t entry; -int i;/* File mapping without ->vm_ops ? */ if (vma->vm_flags &VM_SHARED )@@ -4465,8 +4464,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)update_mmu_tlb (vma, addr, vmf->pte); goto release; }else if (nr_pages >1 && !pte_range_none (vmf->pte, nr_pages)) { -for (i =0 ; i < nr_pages; i++) -update_mmu_tlb (vma, addr +PAGE_SIZE * i, vmf->pte + i); +update_mmu_tlb_range (vma, addr, vmf->pte, nr_pages); goto release; } --2.19.1.6.gb485710b
Re: [PATCH v1 5/5] mm: Add update_mmu_tlb_range()
Hey Lance,
Thanks for taking time to review!
Quoted 26 lines · Lance Yang
Hey Bang,
Quoted 23 lines · Bang Li
After the commit
19eaf44954df("mm: thp: support allocation of anonymous multi-size THP"), it may need to batch update tlb of an address range through theupdate_mmu_tlbfunction. We can simplify this operation by adding theupdate_mmu_tlb_rangefunction, which may also reduce the execution of some unnecessary code in some architectures.Signed-off-by Bang Li <[email protected]>--- include/linux/pgtable.h | 5 +++++ mm/memory.c | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-)include/linux/pgtable.h +2
-0@@ -734,6 +734,11 @@ static inline void update_mmu_tlb(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) { } + +static inline void update_mmu_tlb_range(struct vm_area_struct *vma,
Quoted 8 lines
include/linux/pgtable.h static inline void update_mmu_tlb(struct vm_area_struct *vma, · line 743
Quoted 5 lines
include/linux/pgtable.h +3
-0+ unsigned long address, pte_t *ptep, unsigned int nr) +{ +} #define __HAVE_ARCH_UPDATE_MMU_TLB #endifIMO, it might be better to use a separate definition to determine whether
update_mmu_tlb_range()is overridden by a specific architecture.
I have also considered this, and I will modify it in the next version. thank you again for your review!
Thanks,
Bang
Quoted 30 lines
Thanks,
LanceQuoted 26 lines
mm/memory.c +1
-4@@ -4396,7 +4396,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)vm_fault_t ret =0 ;int nr_pages =1 ;pte_t entry; -int i;/* File mapping without ->vm_ops ? */ if (vma->vm_flags &VM_SHARED )@@ -4465,8 +4464,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)update_mmu_tlb (vma, addr, vmf->pte); goto release; }else if (nr_pages >1 && !pte_range_none (vmf->pte, nr_pages)) { -for (i =0 ; i < nr_pages; i++) -update_mmu_tlb (vma, addr +PAGE_SIZE * i, vmf->pte + i); +update_mmu_tlb_range (vma, addr, vmf->pte, nr_pages); goto release; } --2.19.1.6.gb485710b