Skip to content

Commit 2c86599

Browse files
Hugh Dickinstorvalds
Hugh Dickins
authored andcommitted
mm: unmap_mapping_range_tree() with i_mmap_rwsem shared
Revert 48ec833 ("Revert "mm/memory.c: share the i_mmap_rwsem"") to reinstate c8475d1 ("mm/memory.c: share the i_mmap_rwsem"): the unmap_mapping_range family of functions do the unmapping of user pages (ultimately via zap_page_range_single) without modifying the interval tree itself, and unmapping races are necessarily guarded by page table lock, thus the i_mmap_rwsem should be shared in unmap_mapping_pages() and unmap_mapping_folio(). Commit 48ec833 was intended as a short-term measure, allowing the other shared lock changes into 3.19 final, before investigating three trinity crashes, one of which had been bisected to commit c8475d1: [1] https://lkml.org/lkml/2014/11/14/342 https://lore.kernel.org/lkml/[email protected]/ [2] https://lkml.org/lkml/2014/12/22/213 https://lore.kernel.org/lkml/[email protected]/ [3] https://lkml.org/lkml/2014/12/9/741 https://lore.kernel.org/lkml/[email protected]/ Two of those were Bad page states: free_pages_prepare() found PG_mlocked still set - almost certain to have been fixed by 4.4 commit b87537d ("mm: rmap use pte lock not mmap_sem to set PageMlocked"). The NULL deref on rwsem in [2]: unclear, only happened once, not bisected to c8475d1. No change to the i_mmap_lock_write() around __unmap_hugepage_range_final() in unmap_single_vma(): IIRC that's a special usage, helping to serialize hugetlbfs page table sharing, not to be dabbled with lightly. No change to other uses of i_mmap_lock_write() by hugetlbfs. I am not aware of any significant gains from the concurrency allowed by this commit: it is submitted more to resolve an ancient misunderstanding. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Hugh Dickins <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Sasha Levin <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Mike Kravetz <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 566d336 commit 2c86599

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mm/memory.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,11 +3388,11 @@ void unmap_mapping_folio(struct folio *folio)
33883388
details.even_cows = false;
33893389
details.single_folio = folio;
33903390

3391-
i_mmap_lock_write(mapping);
3391+
i_mmap_lock_read(mapping);
33923392
if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root)))
33933393
unmap_mapping_range_tree(&mapping->i_mmap, first_index,
33943394
last_index, &details);
3395-
i_mmap_unlock_write(mapping);
3395+
i_mmap_unlock_read(mapping);
33963396
}
33973397

33983398
/**
@@ -3418,11 +3418,11 @@ void unmap_mapping_pages(struct address_space *mapping, pgoff_t start,
34183418
if (last_index < first_index)
34193419
last_index = ULONG_MAX;
34203420

3421-
i_mmap_lock_write(mapping);
3421+
i_mmap_lock_read(mapping);
34223422
if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root)))
34233423
unmap_mapping_range_tree(&mapping->i_mmap, first_index,
34243424
last_index, &details);
3425-
i_mmap_unlock_write(mapping);
3425+
i_mmap_unlock_read(mapping);
34263426
}
34273427
EXPORT_SYMBOL_GPL(unmap_mapping_pages);
34283428

0 commit comments

Comments
 (0)