Skip to content

Commit a0715cc

Browse files
Alex Thorltontorvalds
authored andcommitted
mm, thp: add VM_INIT_DEF_MASK and PRCTL_THP_DISABLE
Add VM_INIT_DEF_MASK, to allow us to set the default flags for VMs. It also adds a prctl control which allows us to set the THP disable bit in mm->def_flags so that VMs will pick up the setting as they are created. Signed-off-by: Alex Thorlton <athorlton@sgi.com> Suggested-by: Oleg Nesterov <oleg@redhat.com> Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Mel Gorman <mgorman@suse.de> Acked-by: Rik van Riel <riel@redhat.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: David Rientjes <rientjes@google.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1e1836e commit a0715cc

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

‎include/linux/mm.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ extern unsigned int kobjsize(const void *objp);
177177
*/
178178
#define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP)
179179

180+
/* This mask defines which mm->def_flags a process can inherit its parent */
181+
#define VM_INIT_DEF_MASK VM_NOHUGEPAGE
182+
180183
/*
181184
* mapping from the currently active vm_flags protection bits (the
182185
* low four bits) to a page protection mask..

‎include/uapi/linux/prctl.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,7 @@
149149

150150
#define PR_GET_TID_ADDRESS 40
151151

152+
#define PR_SET_THP_DISABLE 41
153+
#define PR_GET_THP_DISABLE 42
154+
152155
#endif /* _LINUX_PRCTL_H */

‎kernel/fork.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,6 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p)
530530
atomic_set(&mm->mm_count, 1);
531531
init_rwsem(&mm->mmap_sem);
532532
INIT_LIST_HEAD(&mm->mmlist);
533-
mm->flags = (current->mm) ?
534-
(current->mm->flags & MMF_INIT_MASK) : default_dump_filter;
535533
mm->core_state = NULL;
536534
atomic_long_set(&mm->nr_ptes, 0);
537535
memset(&mm->rss_stat, 0, sizeof(mm->rss_stat));
@@ -540,8 +538,15 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p)
540538
mm_init_owner(mm, p);
541539
clear_tlb_flush_pending(mm);
542540

543-
if (likely(!mm_alloc_pgd(mm))) {
541+
if (current->mm) {
542+
mm->flags = current->mm->flags & MMF_INIT_MASK;
543+
mm->def_flags = current->mm->def_flags & VM_INIT_DEF_MASK;
544+
} else {
545+
mm->flags = default_dump_filter;
544546
mm->def_flags = 0;
547+
}
548+
549+
if (likely(!mm_alloc_pgd(mm))) {
545550
mmu_notifier_mm_init(mm);
546551
return mm;
547552
}

‎kernel/sys.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,21 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
19961996
if (arg2 || arg3 || arg4 || arg5)
19971997
return -EINVAL;
19981998
return current->no_new_privs ? 1 : 0;
1999+
case PR_GET_THP_DISABLE:
2000+
if (arg2 || arg3 || arg4 || arg5)
2001+
return -EINVAL;
2002+
error = !!(me->mm->def_flags & VM_NOHUGEPAGE);
2003+
break;
2004+
case PR_SET_THP_DISABLE:
2005+
if (arg3 || arg4 || arg5)
2006+
return -EINVAL;
2007+
down_write(&me->mm->mmap_sem);
2008+
if (arg2)
2009+
me->mm->def_flags |= VM_NOHUGEPAGE;
2010+
else
2011+
me->mm->def_flags &= ~VM_NOHUGEPAGE;
2012+
up_write(&me->mm->mmap_sem);
2013+
break;
19992014
default:
20002015
error = -EINVAL;
20012016
break;

0 commit comments

Comments
 (0)