Commit a0715cc22601e8830ace98366c0c2bd8da52af52

Authored by Alex Thorlton
Committed by Linus Torvalds
1 parent 1e1836e84f

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>

Showing 4 changed files with 29 additions and 3 deletions Side-by-side Diff

... ... @@ -177,6 +177,9 @@
177 177 */
178 178 #define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP)
179 179  
  180 +/* This mask defines which mm->def_flags a process can inherit its parent */
  181 +#define VM_INIT_DEF_MASK VM_NOHUGEPAGE
  182 +
180 183 /*
181 184 * mapping from the currently active vm_flags protection bits (the
182 185 * low four bits) to a page protection mask..
include/uapi/linux/prctl.h
... ... @@ -149,5 +149,8 @@
149 149  
150 150 #define PR_GET_TID_ADDRESS 40
151 151  
  152 +#define PR_SET_THP_DISABLE 41
  153 +#define PR_GET_THP_DISABLE 42
  154 +
152 155 #endif /* _LINUX_PRCTL_H */
... ... @@ -530,8 +530,6 @@
530 530 atomic_set(&mm->mm_count, 1);
531 531 init_rwsem(&mm->mmap_sem);
532 532 INIT_LIST_HEAD(&mm->mmlist);
533   - mm->flags = (current->mm) ?
534   - (current->mm->flags & MMF_INIT_MASK) : default_dump_filter;
535 533 mm->core_state = NULL;
536 534 atomic_long_set(&mm->nr_ptes, 0);
537 535 memset(&mm->rss_stat, 0, sizeof(mm->rss_stat));
538 536  
... ... @@ -540,8 +538,15 @@
540 538 mm_init_owner(mm, p);
541 539 clear_tlb_flush_pending(mm);
542 540  
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;
544 546 mm->def_flags = 0;
  547 + }
  548 +
  549 + if (likely(!mm_alloc_pgd(mm))) {
545 550 mmu_notifier_mm_init(mm);
546 551 return mm;
547 552 }
... ... @@ -1996,6 +1996,21 @@
1996 1996 if (arg2 || arg3 || arg4 || arg5)
1997 1997 return -EINVAL;
1998 1998 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;
1999 2014 default:
2000 2015 error = -EINVAL;
2001 2016 break;