All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add per-process flag to control thp
@ 2013-08-02 19:46 Alex Thorlton
  2013-08-02 19:53 ` Dave Jones
                   ` (3 more replies)
  0 siblings, 4 replies; 77+ messages in thread
From: Alex Thorlton @ 2013-08-02 19:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ingo Molnar, Peter Zijlstra, Andrew Morton, Mel Gorman,
	Kirill A. Shutemov, Rik van Riel, Johannes Weiner,
	Eric W. Biederman, Sedat Dilek, Frederic Weisbecker, Dave Jones,
	Michael Kerrisk, Paul E. McKenney, David Howells,
	Thomas Gleixner, Al Viro, Oleg Nesterov, Srikar Dronamraju,
	Kees Cook, Robin Holt, linux-kernel

This patch implements functionality to allow processes to disable the use of
transparent hugepages through the prctl syscall.

We've determined that some jobs perform significantly better with thp disabled,
and we need a way to control thp on a per-process basis, without relying on
madvise.

---
 include/linux/huge_mm.h    | 14 +++++++++++++-
 include/linux/init_task.h  |  8 ++++++++
 include/linux/sched.h      |  3 +++
 include/uapi/linux/prctl.h |  3 +++
 kernel/fork.c              |  4 ++++
 kernel/sys.c               | 31 +++++++++++++++++++++++++++++++
 6 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index b60de92..53af3ca 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -1,6 +1,8 @@
 #ifndef _LINUX_HUGE_MM_H
 #define _LINUX_HUGE_MM_H
 
+#include <linux/sched.h>
+
 extern int do_huge_pmd_anonymous_page(struct mm_struct *mm,
 				      struct vm_area_struct *vma,
 				      unsigned long address, pmd_t *pmd,
@@ -66,7 +68,7 @@ extern pmd_t *page_check_address_pmd(struct page *page,
 
 extern bool is_vma_temporary_stack(struct vm_area_struct *vma);
 
-#define transparent_hugepage_enabled(__vma)				\
+#define _transparent_hugepage_enabled(__vma)				\
 	((transparent_hugepage_flags &					\
 	  (1<<TRANSPARENT_HUGEPAGE_FLAG) ||				\
 	  (transparent_hugepage_flags &					\
@@ -177,6 +179,11 @@ static inline struct page *compound_trans_head(struct page *page)
 	return page;
 }
 
+static inline int transparent_hugepage_enabled(struct vm_area_struct *vma)
+{
+	return !current->thp_disabled & _transparent_hugepage_enabled(vma);
+}
+
 extern int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
 				unsigned long addr, pmd_t pmd, pmd_t *pmdp);
 
@@ -230,6 +237,11 @@ static inline int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_str
 	return 0;
 }
 
+static inline int transparent_hugepage_enabled(struct vm_area_struct *vma)
+{
+	return _transparent_hugepage_enabled(vma);
+}
+
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
 #endif /* _LINUX_HUGE_MM_H */
diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index 5cd0f09..aae74fd 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -152,6 +152,13 @@ extern struct task_group root_task_group;
 # define INIT_VTIME(tsk)
 #endif
 
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+# define INIT_THP_DISABLED						\
+	.thp_disabled = 0,
+#else
+# define INIT_THP_DISABLED
+#endif
+
 #define INIT_TASK_COMM "swapper"
 
 /*
@@ -222,6 +229,7 @@ extern struct task_group root_task_group;
 	INIT_TASK_RCU_PREEMPT(tsk)					\
 	INIT_CPUSET_SEQ							\
 	INIT_VTIME(tsk)							\
+	INIT_THP_DISABLED						\
 }
 
 
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 50d04b9..f084c76 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1406,6 +1406,9 @@ struct task_struct {
 	unsigned int	sequential_io;
 	unsigned int	sequential_io_avg;
 #endif
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+	int thp_disabled;
+#endif
 };
 
 /* Future-safe accessor for struct task_struct's cpus_allowed. */
diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h
index 289760f..f69780d 100644
--- a/include/uapi/linux/prctl.h
+++ b/include/uapi/linux/prctl.h
@@ -149,4 +149,7 @@
 
 #define PR_GET_TID_ADDRESS	40
 
+#define PR_SET_THP_DISABLED	41
+#define PR_GET_THP_DISABLED	42
+
 #endif /* _LINUX_PRCTL_H */
diff --git a/kernel/fork.c b/kernel/fork.c
index 403d2bb..0b4afb5 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1311,6 +1311,10 @@ static struct task_struct *copy_process(unsigned long clone_flags,
 	p->sequential_io_avg	= 0;
 #endif
 
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+	p->thp_disabled = current->thp_disabled;
+#endif
+
 	/* Perform scheduler related setup. Assign this task to a CPU. */
 	sched_fork(p);
 
diff --git a/kernel/sys.c b/kernel/sys.c
index 771129b..416c8a6 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1836,6 +1836,31 @@ static int prctl_get_tid_address(struct task_struct *me, int __user **tid_addr)
 }
 #endif
 
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+static int prctl_set_thp_disabled(struct task_struct *me)
+{
+	me->thp_disabled = 1;
+	return 0;
+}
+
+static int prctl_get_thp_disabled(struct task_struct *me,
+				  int __user *thp_disabled)
+{
+	return put_user(me->thp_disabled, thp_disabled);
+}
+#else
+static int prctl_set_thp_disabled(struct task_struct *me)
+{
+	return -EINVAL;
+}
+
+static int prctl_get_thp_disabled(struct task_struct *me,
+				  int __user *thp_disabled)
+{
+	return -EINVAL;
+}
+#endif
+
 SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 		unsigned long, arg4, unsigned long, arg5)
 {
@@ -1999,6 +2024,12 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 		if (arg2 || arg3 || arg4 || arg5)
 			return -EINVAL;
 		return current->no_new_privs ? 1 : 0;
+	case PR_SET_THP_DISABLED:
+		error = prctl_set_thp_disabled(me);
+		break;
+	case PR_GET_THP_DISABLED:
+		error = prctl_get_thp_disabled(me, (int __user *) arg2);
+		break;
 	default:
 		error = -EINVAL;
 		break;
-- 
1.7.12.4


^ permalink raw reply related	[flat|nested] 77+ messages in thread

end of thread, other threads:[~2013-09-13 19:58 UTC | newest]

Thread overview: 77+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-02 19:46 [PATCH] Add per-process flag to control thp Alex Thorlton
2013-08-02 19:53 ` Dave Jones
2013-08-02 20:00   ` Alex Thorlton
2013-08-02 20:13 ` Kirill A. Shutemov
2013-08-02 20:34   ` Alex Thorlton
2013-08-02 23:59     ` Kirill A. Shutemov
2013-08-03 19:35     ` Kees Cook
2013-08-04 14:19       ` Oleg Nesterov
2013-08-05  2:36     ` Andi Kleen
2013-08-05 15:07       ` Alex Thorlton
2013-08-16 14:33       ` [PATCH 0/8] " Alex Thorlton
2013-08-16 14:33         ` [PATCH 1/8] THP: Use real address for NUMA policy Alex Thorlton
2013-08-16 17:53           ` Dave Hansen
2013-08-16 18:17             ` Alex Thorlton
2013-08-16 18:52               ` Kirill A. Shutemov
2013-08-27 16:50                 ` Alex Thorlton
2013-08-27 17:01                   ` Robin Holt
2013-09-04 15:43                     ` Alex Thorlton
2013-09-04 17:15                       ` Alex Thorlton
2013-09-05 11:15                         ` Ingo Molnar
2013-09-09 16:48                           ` Alex Thorlton
2013-09-10  7:47                             ` [benchmark] THP performance testcase Ingo Molnar
2013-09-13 13:06                               ` [PATCH 0/9] split page table lock for PMD tables Kirill A. Shutemov
2013-09-13 13:06                                 ` Kirill A. Shutemov
2013-09-13 13:06                                 ` [PATCH 1/9] mm: rename SPLIT_PTLOCKS to SPLIT_PTE_PTLOCKS Kirill A. Shutemov
2013-09-13 13:06                                   ` Kirill A. Shutemov
2013-09-13 15:20                                   ` Dave Hansen
2013-09-13 15:20                                     ` Dave Hansen
2013-09-13 13:06                                 ` [PATCH 2/9] mm: convert mm->nr_ptes to atomic_t Kirill A. Shutemov
2013-09-13 13:06                                   ` Kirill A. Shutemov
2013-09-13 13:06                                 ` [PATCH 3/9] mm: introduce api for split page table lock for PMD level Kirill A. Shutemov
2013-09-13 13:06                                   ` Kirill A. Shutemov
2013-09-13 13:19                                   ` Peter Zijlstra
2013-09-13 13:19                                     ` Peter Zijlstra
2013-09-13 14:22                                     ` Kirill A. Shutemov
2013-09-13 14:22                                       ` Kirill A. Shutemov
2013-09-13 13:06                                 ` [PATCH 4/9] mm, thp: change pmd_trans_huge_lock() to return taken lock Kirill A. Shutemov
2013-09-13 13:06                                   ` Kirill A. Shutemov
2013-09-13 13:06                                 ` [PATCH 5/9] mm, thp: move ptl taking inside page_check_address_pmd() Kirill A. Shutemov
2013-09-13 13:06                                   ` Kirill A. Shutemov
2013-09-13 13:06                                 ` [PATCH 6/9] mm, thp: do not access mm->pmd_huge_pte directly Kirill A. Shutemov
2013-09-13 13:06                                   ` Kirill A. Shutemov
2013-09-13 13:06                                 ` [PATCH 7/9] mm: convent the rest to new page table lock api Kirill A. Shutemov
2013-09-13 13:06                                   ` Kirill A. Shutemov
2013-09-13 13:06                                 ` [PATCH 8/9] mm: implement split page table lock for PMD level Kirill A. Shutemov
2013-09-13 13:06                                   ` Kirill A. Shutemov
2013-09-13 13:24                                   ` Peter Zijlstra
2013-09-13 13:24                                     ` Peter Zijlstra
2013-09-13 14:25                                     ` Kirill A. Shutemov
2013-09-13 14:25                                       ` Kirill A. Shutemov
2013-09-13 14:52                                       ` Peter Zijlstra
2013-09-13 14:52                                         ` Peter Zijlstra
2013-09-13 13:36                                   ` Peter Zijlstra
2013-09-13 13:36                                     ` Peter Zijlstra
2013-09-13 14:25                                     ` Kirill A. Shutemov
2013-09-13 14:25                                       ` Kirill A. Shutemov
2013-09-13 15:45                                   ` Naoya Horiguchi
2013-09-13 15:45                                     ` Naoya Horiguchi
2013-09-13 19:57                                   ` Dave Hansen
2013-09-13 19:57                                     ` Dave Hansen
2013-09-13 13:06                                 ` [PATCH 9/9] x86, mm: enable " Kirill A. Shutemov
2013-09-13 13:06                                   ` Kirill A. Shutemov
     [not found]                   ` <20130828091814.GA13681@gmail.com>
2013-08-28  9:32                     ` [PATCH 1/8] THP: Use real address for NUMA policy Peter Zijlstra
2013-08-16 19:46               ` Peter Zijlstra
2013-08-16 19:49                 ` Alex Thorlton
2013-08-16 14:33         ` [PATCH 2/8] mm: make clear_huge_page tolerate non aligned address Alex Thorlton
2013-08-16 14:33         ` [PATCH 3/8] THP: Pass real, not rounded, address to clear_huge_page Alex Thorlton
2013-08-16 14:34         ` [PATCH 4/8] x86: Add clear_page_nocache Alex Thorlton
2013-08-16 14:34         ` [PATCH 5/8] mm: make clear_huge_page cache clear only around the fault address Alex Thorlton
2013-08-16 18:02           ` Dave Hansen
2013-08-16 14:34         ` [PATCH 6/8] x86: switch the 64bit uncached page clear to SSE/AVX v2 Alex Thorlton
2013-08-16 14:34         ` [PATCH 7/8] remove KM_USER0 from kmap_atomic call Alex Thorlton
2013-08-16 14:34         ` [PATCH 8/8] fix up references to kernel_fpu_begin/end Alex Thorlton
2013-08-16 14:47         ` [PATCH 0/8] Re: [PATCH] Add per-process flag to control thp Peter Zijlstra
2013-08-16 15:04           ` Alex Thorlton
2013-08-04 14:44 ` Rasmus Villemoes
2013-08-28 13:56 ` Andrea Arcangeli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.