2020-09-13 13:38:47

by Wei Yang

[permalink] [raw]
Subject: [PATCH 1/2] mm/mmap: not necessary to check mapping separately

*root* with type of struct rb_root_cached is an element of *mapping*
with type of struct address_space. This implies when we have a valid
*root* it must be a part of valid *mapping*.

So we can merge these two checks together to make the code more easy to
read and to save some cpu cycles.

Signed-off-by: Wei Yang <[email protected]>
---
mm/mmap.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 1922e6fce9e7..30b155098606 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -895,10 +895,9 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
anon_vma_interval_tree_post_update_vma(next);
anon_vma_unlock_write(anon_vma);
}
- if (mapping)
- i_mmap_unlock_write(mapping);

if (root) {
+ i_mmap_unlock_write(mapping);
uprobe_mmap(vma);

if (adjust_next)
--
2.20.1 (Apple Git-117)


2020-09-13 13:40:04

by Wei Yang

[permalink] [raw]
Subject: [PATCH 2/2] mm/mmap: check on file instead of the rb_root_cached of its address_space

In __vma_adjust(), we do the check on *root* to decide whether to adjust
the address_space. While it seems to be more meaningful to do the check
on *file* itself. This means we are adjust some data because it is a
file backed vma.

Since we seems to assume the address_space is valid if it is a file
backed vma, let's just replace *root* with *file* here.

Signed-off-by: Wei Yang <[email protected]>
---
mm/mmap.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 30b155098606..829897646a9c 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -823,7 +823,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
anon_vma_interval_tree_pre_update_vma(next);
}

- if (root) {
+ if (file) {
flush_dcache_mmap_lock(mapping);
vma_interval_tree_remove(vma, root);
if (adjust_next)
@@ -844,7 +844,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
next->vm_pgoff += adjust_next >> PAGE_SHIFT;
}

- if (root) {
+ if (file) {
if (adjust_next)
vma_interval_tree_insert(next, root);
vma_interval_tree_insert(vma, root);
@@ -896,7 +896,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
anon_vma_unlock_write(anon_vma);
}

- if (root) {
+ if (file) {
i_mmap_unlock_write(mapping);
uprobe_mmap(vma);

--
2.20.1 (Apple Git-117)