Skip to content

Commit e009bb3

Browse files
kiryltorvalds
authored andcommitted
mm: implement split page table lock for PMD level
The basic idea is the same as with PTE level: the lock is embedded into struct page of table's page. We can't use mm->pmd_huge_pte to store pgtables for THP, since we don't take mm->page_table_lock anymore. Let's reuse page->lru of table's page for that. pgtable_pmd_page_ctor() returns true, if initialization is successful and false otherwise. Current implementation never fails, but assumption that constructor can fail will help to port it to -rt where spinlock_t is rather huge and cannot be embedded into struct page -- dynamic allocation is required. Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Tested-by: Alex Thorlton <athorlton@sgi.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: "Eric W . Biederman" <ebiederm@xmission.com> Cc: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Dave Jones <davej@redhat.com> Cc: David Howells <dhowells@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Kees Cook <keescook@chromium.org> Cc: Mel Gorman <mgorman@suse.de> Cc: Michael Kerrisk <mtk.manpages@gmail.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Robin Holt <robinmholt@gmail.com> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Hugh Dickins <hughd@google.com> Reviewed-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c4088eb commit e009bb3

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

‎include/linux/mm.h‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,13 +1378,45 @@ static inline void pgtable_page_dtor(struct page *page)
13781378
((unlikely(pmd_none(*(pmd))) && __pte_alloc_kernel(pmd, address))? \
13791379
NULL: pte_offset_kernel(pmd, address))
13801380

1381+
#if USE_SPLIT_PMD_PTLOCKS
1382+
1383+
static inline spinlock_t *pmd_lockptr(struct mm_struct *mm, pmd_t *pmd)
1384+
{
1385+
return &virt_to_page(pmd)->ptl;
1386+
}
1387+
1388+
static inline bool pgtable_pmd_page_ctor(struct page *page)
1389+
{
1390+
spin_lock_init(&page->ptl);
1391+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
1392+
page->pmd_huge_pte = NULL;
1393+
#endif
1394+
return true;
1395+
}
1396+
1397+
static inline void pgtable_pmd_page_dtor(struct page *page)
1398+
{
1399+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
1400+
VM_BUG_ON(page->pmd_huge_pte);
1401+
#endif
1402+
}
1403+
1404+
#define pmd_huge_pte(mm, pmd) (virt_to_page(pmd)->pmd_huge_pte)
1405+
1406+
#else
1407+
13811408
static inline spinlock_t *pmd_lockptr(struct mm_struct *mm, pmd_t *pmd)
13821409
{
13831410
return &mm->page_table_lock;
13841411
}
13851412

1413+
static inline bool pgtable_pmd_page_ctor(struct page *page) { return true; }
1414+
static inline void pgtable_pmd_page_dtor(struct page *page) {}
1415+
13861416
#define pmd_huge_pte(mm, pmd) ((mm)->pmd_huge_pte)
13871417

1418+
#endif
1419+
13881420
static inline spinlock_t *pmd_lock(struct mm_struct *mm, pmd_t *pmd)
13891421
{
13901422
spinlock_t *ptl = pmd_lockptr(mm, pmd);

‎include/linux/mm_types.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
struct address_space;
2525

2626
#define USE_SPLIT_PTE_PTLOCKS (NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS)
27+
#define USE_SPLIT_PMD_PTLOCKS (USE_SPLIT_PTE_PTLOCKS && \
28+
IS_ENABLED(CONFIG_ARCH_ENABLE_SPLIT_PMD_PTLOCK))
2729

2830
/*
2931
* Each physical page in the system has a struct page associated with
@@ -63,6 +65,9 @@ struct page {
6365
* this page is only used to
6466
* free other pages.
6567
*/
68+
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && USE_SPLIT_PMD_PTLOCKS
69+
pgtable_t pmd_huge_pte; /* protected by page->ptl */
70+
#endif
6671
};
6772

6873
union {
@@ -406,7 +411,7 @@ struct mm_struct {
406411
#ifdef CONFIG_MMU_NOTIFIER
407412
struct mmu_notifier_mm *mmu_notifier_mm;
408413
#endif
409-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
414+
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
410415
pgtable_t pmd_huge_pte; /* protected by page_table_lock */
411416
#endif
412417
#ifdef CONFIG_CPUMASK_OFFSTACK

‎kernel/fork.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ static void check_mm(struct mm_struct *mm)
560560
"mm:%p idx:%d val:%ld\n", mm, i, x);
561561
}
562562

563-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
563+
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
564564
VM_BUG_ON(mm->pmd_huge_pte);
565565
#endif
566566
}
@@ -814,7 +814,7 @@ struct mm_struct *dup_mm(struct task_struct *tsk)
814814
memcpy(mm, oldmm, sizeof(*mm));
815815
mm_init_cpumask(mm);
816816

817-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
817+
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
818818
mm->pmd_huge_pte = NULL;
819819
#endif
820820
if (!mm_init(mm, tsk))

‎mm/Kconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ config SPLIT_PTLOCK_CPUS
222222
default "999999" if !64BIT && GENERIC_LOCKBREAK
223223
default "4"
224224

225+
config ARCH_ENABLE_SPLIT_PMD_PTLOCK
226+
boolean
227+
225228
#
226229
# support for memory balloon compaction
227230
config BALLOON_COMPACTION

0 commit comments

Comments
 (0)