1
0
Fork 0
alistair23-linux/arch
Roman Gushchin cf11e85fc0 mm: hugetlb: optionally allocate gigantic hugepages using cma
Commit 944d9fec8d ("hugetlb: add support for gigantic page allocation
at runtime") has added the run-time allocation of gigantic pages.

However it actually works only at early stages of the system loading,
when the majority of memory is free.  After some time the memory gets
fragmented by non-movable pages, so the chances to find a contiguous 1GB
block are getting close to zero.  Even dropping caches manually doesn't
help a lot.

At large scale rebooting servers in order to allocate gigantic hugepages
is quite expensive and complex.  At the same time keeping some constant
percentage of memory in reserved hugepages even if the workload isn't
using it is a big waste: not all workloads can benefit from using 1 GB
pages.

The following solution can solve the problem:
1) On boot time a dedicated cma area* is reserved. The size is passed
   as a kernel argument.
2) Run-time allocations of gigantic hugepages are performed using the
   cma allocator and the dedicated cma area

In this case gigantic hugepages can be allocated successfully with a
high probability, however the memory isn't completely wasted if nobody
is using 1GB hugepages: it can be used for pagecache, anon memory, THPs,
etc.

* On a multi-node machine a per-node cma area is allocated on each node.
  Following gigantic hugetlb allocation are using the first available
  numa node if the mask isn't specified by a user.

Usage:
1) configure the kernel to allocate a cma area for hugetlb allocations:
   pass hugetlb_cma=10G as a kernel argument

2) allocate hugetlb pages as usual, e.g.
   echo 10 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages

If the option isn't enabled or the allocation of the cma area failed,
the current behavior of the system is preserved.

x86 and arm-64 are covered by this patch, other architectures can be
trivially added later.

The patch contains clean-ups and fixes proposed and implemented by Aslan
Bakirov and Randy Dunlap.  It also contains ideas and suggestions
proposed by Rik van Riel, Michal Hocko and Mike Kravetz.  Thanks!

Signed-off-by: Roman Gushchin <guro@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Tested-by: Andreas Schaufler <andreas.schaufler@gmx.de>
Acked-by: Mike Kravetz <mike.kravetz@oracle.com>
Acked-by: Michal Hocko <mhocko@kernel.org>
Cc: Aslan Bakirov <aslan@fb.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: Joonsoo Kim <js1304@gmail.com>
Link: http://lkml.kernel.org/r/20200407163840.92263-3-guro@fb.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-04-10 15:36:21 -07:00
..
alpha asm-generic: fix unistd_32.h generation format 2020-04-07 10:43:42 -07:00
arc ARC updates for 5.7-rc1 2020-04-03 15:28:42 -07:00
arm - Fix-ups 2020-04-07 19:44:52 -07:00
arm64 mm: hugetlb: optionally allocate gigantic hugepages using cma 2020-04-10 15:36:21 -07:00
c6x SCSI misc on 20200402 2020-04-02 17:03:53 -07:00
csky mm/vma: append unlikely() while testing VMA access permissions 2020-04-07 10:43:38 -07:00
h8300 asm-generic: make more kernel-space headers mandatory 2020-04-02 09:35:25 -07:00
hexagon mm: allow VM_FAULT_RETRY for multiple times 2020-04-02 09:35:30 -07:00
ia64 kasan: stackdepot: move filter_irq_stacks() to stackdepot.c 2020-04-07 10:43:43 -07:00
m68k Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu 2020-04-09 10:59:56 -07:00
microblaze asm-generic: fix unistd_32.h generation format 2020-04-07 10:43:42 -07:00
mips virtio: fixes, vdpa 2020-04-08 10:51:53 -07:00
nds32 kasan: stackdepot: move filter_irq_stacks() to stackdepot.c 2020-04-07 10:43:43 -07:00
nios2 dma-mapping updates for 5.7 2020-04-04 10:12:47 -07:00
openrisc OpenRISC updates for 5.6 2020-04-07 12:33:37 -07:00
parisc Merge branch 'akpm' (patches from Andrew) 2020-04-07 14:11:54 -07:00
powerpc powerpc updates for 5.7 #2 2020-04-09 11:01:42 -07:00
riscv RISC-V Patches for the 5.7 Merge Window, Part 1 2020-04-09 10:51:30 -07:00
s390 s390: 2020-04-08 10:56:50 -07:00
sh asm-generic: fix unistd_32.h generation format 2020-04-07 10:43:42 -07:00
sparc Merge branch 'akpm' (patches from Andrew) 2020-04-07 14:11:54 -07:00
um This pull request contains the following changes for UML: 2020-04-07 12:36:09 -07:00
unicore32 - Fix-ups 2020-04-07 19:44:52 -07:00
x86 mm: hugetlb: optionally allocate gigantic hugepages using cma 2020-04-10 15:36:21 -07:00
xtensa asm-generic: fix unistd_32.h generation format 2020-04-07 10:43:42 -07:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
Kconfig dma-mapping updates for 5.7 2020-04-04 10:12:47 -07:00