linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Andrew Morton <akpm@linux-foundation.org>,
	David Rientjes <rientjes@google.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Vlastimil Babka <vbabka@suse.cz>,
	Minchan Kim <minchan@kernel.org>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Michal Nazarewicz <mina86@mina86.com>,
	Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
	Christoph Lameter <cl@linux.com>, Rik van Riel <riel@redhat.com>,
	Mel Gorman <mgorman@suse.de>,
	Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Subject: [PATCH v6 01/13] mm, THP: don't hold mmap_sem in khugepaged when allocating THP
Date: Mon,  4 Aug 2014 10:55:12 +0200	[thread overview]
Message-ID: <1407142524-2025-2-git-send-email-vbabka@suse.cz> (raw)
In-Reply-To: <1407142524-2025-1-git-send-email-vbabka@suse.cz>

When allocating huge page for collapsing, khugepaged currently holds mmap_sem
for reading on the mm where collapsing occurs. Afterwards the read lock is
dropped before write lock is taken on the same mmap_sem.

Holding mmap_sem during whole huge page allocation is therefore useless, the
vma needs to be rechecked after taking the write lock anyway. Furthemore, huge
page allocation might involve a rather long sync compaction, and thus block
any mmap_sem writers and i.e. affect workloads that perform frequent m(un)map
or mprotect oterations.

This patch simply releases the read lock before allocating a huge page. It
also deletes an outdated comment that assumed vma must be stable, as it was
using alloc_hugepage_vma(). This is no longer true since commit 9f1b868a13ac
("mm: thp: khugepaged: add policy for finding target node").

Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Minchan Kim <minchan@kernel.org>
Acked-by: Mel Gorman <mgorman@suse.de>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Rik van Riel <riel@redhat.com>
Acked-by: David Rientjes <rientjes@google.com>
---
 mm/huge_memory.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index d9a21d06..7cfc325 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2319,23 +2319,17 @@ static struct page
 		       int node)
 {
 	VM_BUG_ON_PAGE(*hpage, *hpage);
+
 	/*
-	 * Allocate the page while the vma is still valid and under
-	 * the mmap_sem read mode so there is no memory allocation
-	 * later when we take the mmap_sem in write mode. This is more
-	 * friendly behavior (OTOH it may actually hide bugs) to
-	 * filesystems in userland with daemons allocating memory in
-	 * the userland I/O paths.  Allocating memory with the
-	 * mmap_sem in read mode is good idea also to allow greater
-	 * scalability.
+	 * Before allocating the hugepage, release the mmap_sem read lock.
+	 * The allocation can take potentially a long time if it involves
+	 * sync compaction, and we do not need to hold the mmap_sem during
+	 * that. We will recheck the vma after taking it again in write mode.
 	 */
+	up_read(&mm->mmap_sem);
+
 	*hpage = alloc_pages_exact_node(node, alloc_hugepage_gfpmask(
 		khugepaged_defrag(), __GFP_OTHER_NODE), HPAGE_PMD_ORDER);
-	/*
-	 * After allocating the hugepage, release the mmap_sem read lock in
-	 * preparation for taking it in write mode.
-	 */
-	up_read(&mm->mmap_sem);
 	if (unlikely(!*hpage)) {
 		count_vm_event(THP_COLLAPSE_ALLOC_FAILED);
 		*hpage = ERR_PTR(-ENOMEM);
-- 
1.8.4.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2014-08-04  8:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-04  8:55 [PATCH v6 00/13] compaction: balancing overhead and success rates Vlastimil Babka
2014-08-04  8:55 ` Vlastimil Babka [this message]
2014-08-04  8:55 ` [PATCH v6 02/13] mm, compaction: defer each zone individually instead of preferred zone Vlastimil Babka
2014-08-04  8:55 ` [PATCH v6 03/13] mm, compaction: do not count compact_stall if all zones skipped compaction Vlastimil Babka
2014-08-04  8:55 ` [PATCH v6 04/13] mm, compaction: do not recheck suitable_migration_target under lock Vlastimil Babka
2014-08-04  8:55 ` [PATCH v6 05/13] mm, compaction: move pageblock checks up from isolate_migratepages_range() Vlastimil Babka
2014-09-29  7:50   ` Joonsoo Kim
2014-09-29  8:15     ` Vlastimil Babka
2014-08-04  8:55 ` [PATCH v6 06/13] mm, compaction: reduce zone checking frequency in the migration scanner Vlastimil Babka
2014-08-04  8:55 ` [PATCH v6 07/13] mm, compaction: khugepaged should not give up due to need_resched() Vlastimil Babka
2014-08-04  8:55 ` [PATCH v6 08/13] mm, compaction: periodically drop lock and restore IRQs in scanners Vlastimil Babka
2014-08-04  8:55 ` [PATCH v6 09/13] mm, compaction: skip rechecks when lock was already held Vlastimil Babka
2014-08-04  8:55 ` [PATCH v6 10/13] mm, compaction: remember position within pageblock in free pages scanner Vlastimil Babka
2014-08-04  8:55 ` [PATCH v6 11/13] mm, compaction: skip buddy pages by their order in the migrate scanner Vlastimil Babka
2014-08-21 22:11   ` Andrew Morton
2014-09-08  8:04     ` Vlastimil Babka
2014-08-04  8:55 ` [PATCH v6 12/13] mm: rename allocflags_to_migratetype for clarity Vlastimil Babka
2014-08-04  8:55 ` [PATCH v6 13/13] mm, compaction: pass gfp mask to compact_control Vlastimil Babka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1407142524-2025-2-git-send-email-vbabka@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mina86@mina86.com \
    --cc=minchan@kernel.org \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=riel@redhat.com \
    --cc=rientjes@google.com \
    --cc=zhangyanfei@cn.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox