Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1157922

[PATCHv6 31/36] thp, mm: split_huge_page(): caller need to lock page

From "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Newsgroups linux.kernel
Subject [PATCHv6 31/36] thp, mm: split_huge_page(): caller need to lock page
Date 2015-06-03 19:20 +0200
Message-ID <pxkuF-7Ey-77@gated-at.bofh.it> (permalink)
References <pxkkW-7sr-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


We're going to use migration entries instead of compound_lock() to
stabilize page refcounts. Setup and remove migration entries require
page to be locked.

Some of split_huge_page() callers already have the page locked. Let's
require everybody to lock the page before calling split_huge_page().

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Tested-by: Sasha Levin <sasha.levin@oracle.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
---
 mm/memory-failure.c | 10 ++++++++--
 mm/migrate.c        |  8 ++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 1cf7f2988422..0d9989a36d32 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1143,15 +1143,18 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
 				put_page(hpage);
 			return -EBUSY;
 		}
+		lock_page(hpage);
 		if (unlikely(split_huge_page(hpage))) {
 			pr_err("MCE: %#lx: thp split failed\n", pfn);
 			if (TestClearPageHWPoison(p))
 				atomic_long_sub(nr_pages, &num_poisoned_pages);
+			unlock_page(hpage);
 			put_page(p);
 			if (p != hpage)
 				put_page(hpage);
 			return -EBUSY;
 		}
+		unlock_page(hpage);
 		VM_BUG_ON_PAGE(!page_count(p), p);
 		hpage = compound_head(p);
 	}
@@ -1714,10 +1717,13 @@ int soft_offline_page(struct page *page, int flags)
 		return -EBUSY;
 	}
 	if (!PageHuge(page) && PageTransHuge(hpage)) {
-		if (PageAnon(hpage) && unlikely(split_huge_page(hpage))) {
+		lock_page(page);
+		ret = split_huge_page(hpage);
+		unlock_page(page);
+		if (unlikely(ret)) {
 			pr_info("soft offline: %#lx: failed to split THP\n",
 				pfn);
-			return -EBUSY;
+			return ret;
 		}
 	}
 
diff --git a/mm/migrate.c b/mm/migrate.c
index dfd24cb7afc6..8bb2107b8751 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -933,9 +933,13 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page,
 		goto out;
 	}
 
-	if (unlikely(PageTransHuge(page)))
-		if (unlikely(split_huge_page(page)))
+	if (unlikely(PageTransHuge(page))) {
+		lock_page(page);
+		rc = split_huge_page(page);
+		unlock_page(page);
+		if (rc)
 			goto out;
+	}
 
 	rc = __unmap_and_move(page, newpage, force, mode);
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCHv6 00/36] THP refcounting redesign "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:10 +0200
  [PATCHv6 12/36] thp: drop all split_huge_page()-related code "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:10 +0200
  [PATCHv6 18/36] arm, thp: remove infrastructure for handling splitting PMDs "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:10 +0200
  [PATCHv6 01/36] mm, proc: adjust PSS calculation "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:10 +0200
  [PATCHv6 28/36] mm, numa: skip PTE-mapped THP on numa fault "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:10 +0200
  [PATCHv6 02/36] rmap: add argument to charge compound page "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:10 +0200
  [PATCHv6 24/36] x86, thp: remove infrastructure for handling splitting PMDs "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 08/36] khugepaged: ignore pmd tables with THP mapped with ptes "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 19/36] mips, thp: remove infrastructure for handling splitting PMDs "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 33/36] migrate_pages: try to split pages on qeueuing "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 13/36] mm: drop tail page refcounting "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 27/36] mm: differentiate page_mapped() from page_mapcount() for compound pages "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 32/36] thp: reintroduce split_huge_page() "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 21/36] s390, thp: remove infrastructure for handling splitting PMDs "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 29/36] thp: implement split_huge_pmd() "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 20/36] powerpc, thp: remove infrastructure for handling splitting PMDs "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 17/36] arm64, thp: remove infrastructure for handling splitting PMDs "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 34/36] thp: introduce deferred_split_huge_page() "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 30/36] thp: add option to setup migration entiries during PMD split "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 10/36] mm, vmstats: new THP splitting event "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 23/36] tile, thp: remove infrastructure for handling splitting PMDs "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 06/36] mm: handle PTE-mapped tail pages in gerneric fast gup implementaiton "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 31/36] thp, mm: split_huge_page(): caller need to lock page "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 35/36] mm: re-enable THP "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200
  [PATCHv6 16/36] mm, thp: remove compound_lock "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2015-06-03 19:20 +0200

csiph-web