Linux-mm Archive on
 help / color / Atom feed
* [patch 128/158] hugetlbfs: take read_lock on i_mmap for PMD sharing
@ 2019-12-01  1:56 akpm
  0 siblings, 0 replies; only message in thread
From: akpm @ 2019-12-01  1:56 UTC (permalink / raw)
  To: akpm, dave, linux-mm, longman, mike.kravetz, mingo, mm-commits,
	peterz, torvalds, will.deacon, willy

From: Waiman Long <>
Subject: hugetlbfs: take read_lock on i_mmap for PMD sharing

A customer with large SMP systems (up to 16 sockets) with application that
uses large amount of static hugepages (~500-1500GB) are experiencing
random multisecond delays.  These delays were caused by the long time it
took to scan the VMA interval tree with mmap_sem held.

The sharing of huge PMD does not require changes to the i_mmap at all. 
Therefore, we can just take the read lock and let other threads searching
for the right VMA share it in parallel.  Once the right VMA is found,
either the PMD lock (2M huge page for x86-64) or the mm->page_table_lock
will be acquired to perform the actual PMD sharing.

Lock contention, if present, will happen in the spinlock.  That is much
better than contention in the rwsem where the time needed to scan the the
interval tree is indeterminate.

With this patch applied, the customer is seeing significant performance
improvement over the unpatched kernel.

Signed-off-by: Waiman Long <>
Suggested-by: Mike Kravetz <>
Reviewed-by: Mike Kravetz <>
Cc: Davidlohr Bueso <>
Cc: Peter Zijlstra <>
Cc: Ingo Molnar <>
Cc: Will Deacon <>
Cc: Matthew Wilcox <>
Signed-off-by: Andrew Morton <>

 mm/hugetlb.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/mm/hugetlb.c~hugetlbfs-take-read_lock-on-i_mmap-for-pmd-sharing
+++ a/mm/hugetlb.c
@@ -4769,7 +4769,7 @@ pte_t *huge_pmd_share(struct mm_struct *
 	if (!vma_shareable(vma, addr))
 		return (pte_t *)pmd_alloc(mm, pud, addr);
-	i_mmap_lock_write(mapping);
+	i_mmap_lock_read(mapping);
 	vma_interval_tree_foreach(svma, &mapping->i_mmap, idx, idx) {
 		if (svma == vma)
@@ -4799,7 +4799,7 @@ pte_t *huge_pmd_share(struct mm_struct *
 	pte = (pte_t *)pmd_alloc(mm, pud, addr);
-	i_mmap_unlock_write(mapping);
+	i_mmap_unlock_read(mapping);
 	return pte;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-01  1:56 [patch 128/158] hugetlbfs: take read_lock on i_mmap for PMD sharing akpm

Linux-mm Archive on

Archives are clonable:
	git clone --mirror linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ \
	public-inbox-index linux-mm

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone