大页内存

Centos 开启大页内存

系统:CentOS Linux release 7.7.1908 (Core)

编辑 /etc/default/grub ,在 GRUB_CMDLINE_LINUX 字段增加如下:

  • default_hugepagesz :默认大页每页大小
  • hugepagesz :大页每页大小,可选值:4K、2M(默认)、1G
  • hugepages :大页数量
1
2
3
4
5
6
7
8
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos_centos/root rd.lvm.lv=centos_centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet intel_iommu=off default_hugepagesz=1G hugepagesz=1G hugepages=40"

重新生成grub文件,重启host

1
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg

Ubuntu 开启大页内存

系统:Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-112-generic x86_64)

编辑 /etc/default/grub ,在 GRUB_CMDLINE_LINUX 字段增加如下:

  • default_hugepagesz :默认大页每页大小
  • hugepagesz :大页每页大小,可选值:4K、2M(默认)、1G
  • hugepages :大页数量
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX="default_hugepagesz=1G hugepagesz=1G hugepages=2"

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

执行 update-grub ,生效配置

验证

查看系统大页内存,HugePages_Total = hugepagesz * hugepages

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# CentOS
[root@k134 ~]# cat /proc/meminfo | grep -i huge
HugePages_Total: 100
HugePages_Free: 83
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 1048576 kB

# Ubuntu
root@inspur:~# cat /proc/meminfo | grep -i huge
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
HugePages_Total: 15
HugePages_Free: 15
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 1048576 kB

参考文档