[Devel] [PATCH RHEL7 COMMIT] ms/mm/nommu: share the i_mmap_rwsem

Vasily Averin vvs at virtuozzo.com
Thu Dec 3 11:41:22 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1160.6.1.vz7.171.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1160.6.1.vz7.171.1
------>
commit 3d55a1d283429203342c88e5e0ab2ab5343da67e
Author: Davidlohr Bueso <dave at stgolabs.net>
Date:   Thu Dec 3 11:41:22 2020 +0300

    ms/mm/nommu: share the i_mmap_rwsem
    
    Shrinking/truncate logic can call nommu_shrink_inode_mappings() to verify
    that any shared mappings of the inode in question aren't broken (dead
    zone).  afaict the only user being ramfs to handle the size change
    attribute.
    
    Pretty much a no-brainer to share the lock.
    
    Signed-off-by: Davidlohr Bueso <dbueso at suse.de>
    Acked-by: "Kirill A. Shutemov" <kirill at shutemov.name>
    Acked-by: Hugh Dickins <hughd at google.com>
    Cc: Oleg Nesterov <oleg at redhat.com>
    Acked-by: Peter Zijlstra (Intel) <peterz at infradead.org>
    Cc: Rik van Riel <riel at redhat.com>
    Cc: Srikar Dronamraju <srikar at linux.vnet.ibm.com>
    Acked-by: Mel Gorman <mgorman at suse.de>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
    
    https://jira.sw.ru/browse/PSBM-122663
    (cherry picked from commit 1acf2e040721564d579297646862b8ea3dd4511b)
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/nommu.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/mm/nommu.c b/mm/nommu.c
index f994621..290fe30 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -2134,14 +2134,14 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size,
 	high = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
 	down_write(&nommu_region_sem);
-	i_mmap_lock_write(inode->i_mapping);
+	i_mmap_lock_read(inode->i_mapping);
 
 	/* search for VMAs that fall within the dead zone */
 	vma_interval_tree_foreach(vma, &inode->i_mapping->i_mmap, low, high) {
 		/* found one - only interested if it's shared out of the page
 		 * cache */
 		if (vma->vm_flags & VM_SHARED) {
-			i_mmap_unlock_write(inode->i_mapping);
+			i_mmap_unlock_read(inode->i_mapping);
 			up_write(&nommu_region_sem);
 			return -ETXTBSY; /* not quite true, but near enough */
 		}
@@ -2153,8 +2153,7 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size,
 	 * we don't check for any regions that start beyond the EOF as there
 	 * shouldn't be any
 	 */
-	vma_interval_tree_foreach(vma, &inode->i_mapping->i_mmap,
-				  0, ULONG_MAX) {
+	vma_interval_tree_foreach(vma, &inode->i_mapping->i_mmap, 0, ULONG_MAX) {
 		if (!(vma->vm_flags & VM_SHARED))
 			continue;
 
@@ -2169,7 +2168,7 @@ int nommu_shrink_inode_mappings(struct inode *inode, size_t size,
 		}
 	}
 
-	i_mmap_unlock_write(inode->i_mapping);
+	i_mmap_unlock_read(inode->i_mapping);
 	up_write(&nommu_region_sem);
 	return 0;
 }


More information about the Devel mailing list