Limit usable memory size in Linux grub
In one case, I need to limit the usable memory size to 128GB from a system which has 1TB memory.
$ cat /proc/meminfo | grep MemTotal
MemTotal: 1056493068 kB
Edit /etc/default/grub file
Add “mem=128G” to the end of line “GRUB_CMDLINE_LINUX”.
$ cat /etc/default/grub
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 spectre_v2=retpoline rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet mem=128G"
GRUB_DISABLE_RECOVERY="true"
Generate new grub.cfg file
$ grub2-mkconfig -o /boot/grub2/grub.cfg
$ reboot
Verify the usable memory
$ cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-5.7.12-1.el7.elrepo.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto spectre_v2=retpoline rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8 mem=128G
$ cat /proc/meminfo | grep MemTotal
MemTotal: 129486812 kB