Releasing Reserved Memory on a VPS

By default, the Linux kernel reserves a block of memory for kdump, and its size is controlled by the crashkernel parameter. Most application developers rarely trigger kernel panics, so you can recover this memory by editing /etc/default/grub.

If you do not need kdump, set the crashkernel parameter to
0M-1G:0M,1G-4G:0M,4G-128G:0M,128G-:512M; this releases the reserved memory.

Check current value: cat /etc/default/grub

Typical default:

GRUB_CMDLINE_LINUX=" vga=792 console=tty0 console=ttyS0,115200n8 net.ifnames=0 noibrs nvme_core.io_timeout=4294967295 nvme_core.admin_timeout=4294967295 iommu=pt crashkernel=0M-1G:0M,1G-4G:192M,4G-128G:384M,128G-:512M crash_kexec_post_notifiers=1"

crashkernel above means
• 0–1 GB hosts: 0 MB reserved
• 1–4 GB hosts: 192 MB reserved
• 4–128 GB hosts: 384 MB reserved
• ≥128 GB hosts: 512 MB reserved

For example, a 1 GB host falls into the 1–4 GB bracket, so 192 MB is reserved; a 4 GB host falls into the 4–128 GB bracket, reserving 384 MB.

Apply change:

sudo sed -i 's/crashkernel=0M-1G:0M,1G-4G:192M,4G-128G:384M,128G-:512M/crashkernel=0M-1G:0M,1G-4G:0M,4G-128G:0M,128G-:512M/' /etc/default/grub
sudo update-grub && sudo reboot

For a typical beginner VPS (2 vCPU + 1 GB RAM):

# Before
root@iZj6c0otki9ho421eewyczZ:~# free
               total        used        free      shared  buff/cache   available
Mem:          707180      340772      123400        2624      358872      366408
Swap:              0           0           0

# After
root@iZj6c0otki9ho421eewyczZ:~# free
               total        used        free      shared  buff/cache   available
Mem:          903788      341656      451380        2616      251032      562132
Swap:              0           0           0

For a 2 vCPU + 4 GB VPS:

# Before
root@iZj6c1prxn78ilvd2inku1Z:~# free
               total        used        free      shared  buff/cache   available
Mem:         3512696      377672     2870944        1260      415116     3135024
Swap:              0           0           0

# After
root@iZj6c1prxn78ilvd2inku1Z:~# free
               total        used        free      shared  buff/cache   available
Mem:         3905912      374468     3408304        1252      270508     3531444
Swap:              0           0           0

More about kdump

Kdump is a Linux kernel crash-dumping mechanism. It relies on the kexec facility, which allows one kernel to load another kernel without BIOS initialization. When a fatal error triggers a panic, the running “production” kernel uses kexec to boot a small “capture” kernel that has exclusive use of the reserved memory. The capture kernel then writes the entire memory image (vmcore or kdump file) to disk, a network server, or another storage target. Later, the vmcore can be analyzed to determine the crash cause.