mm/mmap: introduce vma_set_range()
Subsystems (3)
PATCH v2 1/1 mm/mmap: introduce vma_set_range()
There is a lot of code needs to set the range of vma in mmap.c, introduce vma_set_range() to simplify the code.
---
v2: use vma_set_range and put it to mm/internal.h.
v1: https://lore.kernel.org/all/[email protected]/
--- mm/internal.h | 9 +++++++++ mm/mmap.c | 29 +++++++---------------------- 2 files changed, 16 insertions(+), 22 deletions(-)
mm/internal.h +9 -0
@@ -1114,6 +1114,15 @@ static inline bool gup_must_unshare(struct vm_area_struct *vma,extern bool mirrored_kernelcore;extern bool memblock_has_mirror (void ); +static __always_inline void vma_set_range(struct vm_area_struct *vma, +unsigned long start,unsigned long end, +pgoff_t pgoff) +{ + vma->vm_start = start; + vma->vm_end = end; + vma->vm_pgoff = pgoff; +} +static inline bool vma_soft_dirty_enabled (struct vm_area_struct *vma) {/*
mm/mmap.c +7 -22
@@ -663,9 +663,7 @@ int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma,vma_prepare (&vp);vma_adjust_trans_huge (vma, start, end,0 ); - vma->vm_start = start; - vma->vm_end = end; - vma->vm_pgoff = pgoff; +vma_set_range (vma, start, end, pgoff);vma_iter_store (vmi, vma);vma_complete (&vp, vmi, vma->vm_mm);
@@ -708,9 +706,7 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma,vma_adjust_trans_huge (vma, start, end,0 );vma_iter_clear (vmi); - vma->vm_start = start; - vma->vm_end = end; - vma->vm_pgoff = pgoff; +vma_set_range (vma, start, end, pgoff);vma_complete (&vp, vmi, vma->vm_mm);return 0 ; }
@@ -1015,10 +1011,7 @@ static struct vm_area_structvma_prepare (&vp);vma_adjust_trans_huge (vma, vma_start, vma_end, adj_start); - - vma->vm_start = vma_start; - vma->vm_end = vma_end; - vma->vm_pgoff = vma_pgoff; +vma_set_range (vma, vma_start, vma_end, vma_pgoff);if (vma_expanded)vma_iter_store (vmi, vma);
@@ -2809,11 +2802,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, }vma_iter_config (&vmi, addr, end); - vma->vm_start = addr; - vma->vm_end = end; +vma_set_range (vma, addr, end, pgoff);vm_flags_init (vma, vm_flags); vma->vm_page_prot =vm_get_page_prot (vm_flags); - vma->vm_pgoff = pgoff;if (file) { vma->vm_file =get_file (file);
@@ -3163,9 +3154,7 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma, goto unacct_fail;vma_set_anonymous (vma); - vma->vm_start = addr; - vma->vm_end = addr + len; - vma->vm_pgoff = addr >>PAGE_SHIFT ; +vma_set_range (vma, addr, addr + len, addr >>PAGE_SHIFT );vm_flags_init (vma, flags); vma->vm_page_prot =vm_get_page_prot (flags);vma_start_write (vma);
@@ -3402,9 +3391,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, new_vma =vm_area_dup (vma);if (!new_vma) goto out; - new_vma->vm_start = addr; - new_vma->vm_end = addr + len; - new_vma->vm_pgoff = pgoff; +vma_set_range (new_vma, addr, addr + len, pgoff);if (vma_dup_policy (vma, new_vma)) goto out_free_vma;if (anon_vma_clone (new_vma, vma))
@@ -3572,9 +3559,7 @@ static struct vm_area_struct *__install_special_mapping(if (unlikely (vma ==NULL ))return ERR_PTR (-ENOMEM ); - vma->vm_start = addr; - vma->vm_end = addr + len; - +vma_set_range (vma, addr, addr + len,0 );vm_flags_init (vma, (vm_flags | mm->def_flags |VM_DONTEXPAND |VM_SOFTDIRTY ) & ~VM_LOCKED_MASK ); vma->vm_page_prot =vm_get_page_prot (vma->vm_flags);
Signature · 1 line
2.25.1
Quoted 4 lines · Yajun Deng
There is a lot of code needs to set the range of vma in
mmap.c, introducevma_set_range()to simplify the code.Signed-off-by Yajun Deng <[email protected]>
Thank you for making the suggested changes, I have one small comment but you don't need to re-spin the patch for it. This looks good.
Quoted 13 lines
---
v2: usevma_set_rangeand put it tomm/internal.h.
v1: https://lore.kernel.org/all/[email protected]/--- mm/internal.h | 9 +++++++++ mm/mmap.c | 29 +++++++---------------------- 2 files changed, 16 insertions(+), 22 deletions(-)mm/internal.h +0
-0
mm/internal.h static inline bool gup_must_unshare(struct vm_area_struct *vma, · line 1119
Quoted 6 lines
mm/internal.h +3
-0@@ -1114,6 +1114,15 @@ static inline bool gup_must_unshare(struct vm_area_struct *vma,extern bool mirrored_kernelcore;extern bool memblock_has_mirror (void ); +static __always_inline void vma_set_range(struct vm_area_struct *vma, +unsigned long start,unsigned long end, +pgoff_t pgoff)
Nit: This isn't part of the style guide, but if you just indent with two tabs for arguments then it is easier to expand the list without more lines. It also allows changing the function prototype without re-indenting all the other lines, so future changes can be smaller. I think you would save a line here without affecting readability.
Quoted 96 lines
mm/internal.h +6
-0+{ + vma->vm_start = start; + vma->vm_end = end; + vma->vm_pgoff = pgoff; +} +static inline bool vma_soft_dirty_enabled (struct vm_area_struct *vma) {/* mm/mmap.c +7
-22@@ -663,9 +663,7 @@ int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma,vma_prepare (&vp);vma_adjust_trans_huge (vma, start, end,0 ); - vma->vm_start = start; - vma->vm_end = end; - vma->vm_pgoff = pgoff; +vma_set_range (vma, start, end, pgoff);vma_iter_store (vmi, vma);vma_complete (&vp, vmi, vma->vm_mm);@@ -708,9 +706,7 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma,vma_adjust_trans_huge (vma, start, end,0 );vma_iter_clear (vmi); - vma->vm_start = start; - vma->vm_end = end; - vma->vm_pgoff = pgoff; +vma_set_range (vma, start, end, pgoff);vma_complete (&vp, vmi, vma->vm_mm);return 0 ; }@@ -1015,10 +1011,7 @@ static struct vm_area_structvma_prepare (&vp);vma_adjust_trans_huge (vma, vma_start, vma_end, adj_start); - - vma->vm_start = vma_start; - vma->vm_end = vma_end; - vma->vm_pgoff = vma_pgoff; +vma_set_range (vma, vma_start, vma_end, vma_pgoff);if (vma_expanded)vma_iter_store (vmi, vma);@@ -2809,11 +2802,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, }vma_iter_config (&vmi, addr, end); - vma->vm_start = addr; - vma->vm_end = end; +vma_set_range (vma, addr, end, pgoff);vm_flags_init (vma, vm_flags); vma->vm_page_prot =vm_get_page_prot (vm_flags); - vma->vm_pgoff = pgoff;if (file) { vma->vm_file =get_file (file);@@ -3163,9 +3154,7 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma, goto unacct_fail;vma_set_anonymous (vma); - vma->vm_start = addr; - vma->vm_end = addr + len; - vma->vm_pgoff = addr >>PAGE_SHIFT ; +vma_set_range (vma, addr, addr + len, addr >>PAGE_SHIFT );vm_flags_init (vma, flags); vma->vm_page_prot =vm_get_page_prot (flags);vma_start_write (vma);@@ -3402,9 +3391,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, new_vma =vm_area_dup (vma);if (!new_vma) goto out; - new_vma->vm_start = addr; - new_vma->vm_end = addr + len; - new_vma->vm_pgoff = pgoff; +vma_set_range (new_vma, addr, addr + len, pgoff);if (vma_dup_policy (vma, new_vma)) goto out_free_vma;if (anon_vma_clone (new_vma, vma))@@ -3572,9 +3559,7 @@ static struct vm_area_struct *__install_special_mapping(if (unlikely (vma ==NULL ))return ERR_PTR (-ENOMEM ); - vma->vm_start = addr; - vma->vm_end = addr + len; - +vma_set_range (vma, addr, addr + len,0 );vm_flags_init (vma, (vm_flags | mm->def_flags |VM_DONTEXPAND |VM_SOFTDIRTY ) & ~VM_LOCKED_MASK ); vma->vm_page_prot =vm_get_page_prot (vma->vm_flags);Signature · 1 line
2.25.1
Quoted 26 lines · Liam R. Howlett
Quoted 4 lines · Yajun Deng
There is a lot of code needs to set the range of vma in
mmap.c, introducevma_set_range()to simplify the code.Signed-off-by Yajun Deng <[email protected]>Thank you for making the suggested changes, I have one small comment but you don't need to re-spin the patch for it. This looks good.
Reviewed-by Liam R. Howlett <[email protected]>Quoted 16 lines
---
v2: usevma_set_rangeand put it tomm/internal.h.
v1: https://lore.kernel.org/all/[email protected]/--- mm/internal.h | 9 +++++++++ mm/mmap.c | 29 +++++++---------------------- 2 files changed, 16 insertions(+), 22 deletions(-)mm/internal.h +0
-0@@ -1114,6 +1114,15 @@ static inline bool gup_must_unshare(struct vm_area_struct *vma,extern bool mirrored_kernelcore;extern bool memblock_has_mirror (void );
Quoted 8 lines
mm/internal.h static inline bool gup_must_unshare(struct vm_area_struct *vma, · line 1119
Quoted 3 lines
mm/internal.h +3
-0+static __always_inline void vma_set_range(struct vm_area_struct *vma, +unsigned long start,unsigned long end, +pgoff_t pgoff)Nit: This isn't part of the style guide, but if you just indent with two tabs for arguments then it is easier to expand the list without more lines. It also allows changing the function prototype without re-indenting all the other lines, so future changes can be smaller. I think you would save a line here without affecting readability.
Thank you. I thought the parameters needed to be aligned.
Quoted 97 lines
Quoted 97 lines
mm/internal.h +6
-0+{ + vma->vm_start = start; + vma->vm_end = end; + vma->vm_pgoff = pgoff; +} +static inline bool vma_soft_dirty_enabled (struct vm_area_struct *vma) {/* mm/mmap.c +7
-22@@ -663,9 +663,7 @@ int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma,vma_prepare (&vp);vma_adjust_trans_huge (vma, start, end,0 ); - vma->vm_start = start; - vma->vm_end = end; - vma->vm_pgoff = pgoff; +vma_set_range (vma, start, end, pgoff);vma_iter_store (vmi, vma);vma_complete (&vp, vmi, vma->vm_mm);@@ -708,9 +706,7 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma,vma_adjust_trans_huge (vma, start, end,0 );vma_iter_clear (vmi); - vma->vm_start = start; - vma->vm_end = end; - vma->vm_pgoff = pgoff; +vma_set_range (vma, start, end, pgoff);vma_complete (&vp, vmi, vma->vm_mm);return 0 ; }@@ -1015,10 +1011,7 @@ static struct vm_area_structvma_prepare (&vp);vma_adjust_trans_huge (vma, vma_start, vma_end, adj_start); - - vma->vm_start = vma_start; - vma->vm_end = vma_end; - vma->vm_pgoff = vma_pgoff; +vma_set_range (vma, vma_start, vma_end, vma_pgoff);if (vma_expanded)vma_iter_store (vmi, vma);@@ -2809,11 +2802,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, }vma_iter_config (&vmi, addr, end); - vma->vm_start = addr; - vma->vm_end = end; +vma_set_range (vma, addr, end, pgoff);vm_flags_init (vma, vm_flags); vma->vm_page_prot =vm_get_page_prot (vm_flags); - vma->vm_pgoff = pgoff;if (file) { vma->vm_file =get_file (file);@@ -3163,9 +3154,7 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma, goto unacct_fail;vma_set_anonymous (vma); - vma->vm_start = addr; - vma->vm_end = addr + len; - vma->vm_pgoff = addr >>PAGE_SHIFT ; +vma_set_range (vma, addr, addr + len, addr >>PAGE_SHIFT );vm_flags_init (vma, flags); vma->vm_page_prot =vm_get_page_prot (flags);vma_start_write (vma);@@ -3402,9 +3391,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, new_vma =vm_area_dup (vma);if (!new_vma) goto out; - new_vma->vm_start = addr; - new_vma->vm_end = addr + len; - new_vma->vm_pgoff = pgoff; +vma_set_range (new_vma, addr, addr + len, pgoff);if (vma_dup_policy (vma, new_vma)) goto out_free_vma;if (anon_vma_clone (new_vma, vma))@@ -3572,9 +3559,7 @@ static struct vm_area_struct *__install_special_mapping(if (unlikely (vma ==NULL ))return ERR_PTR (-ENOMEM ); - vma->vm_start = addr; - vma->vm_end = addr + len; - +vma_set_range (vma, addr, addr + len,0 );vm_flags_init (vma, (vm_flags | mm->def_flags |VM_DONTEXPAND |VM_SOFTDIRTY ) & ~VM_LOCKED_MASK ); vma->vm_page_prot =vm_get_page_prot (vma->vm_flags);Signature · 1 line
2.25.1