My test server has 4GB of memory. Or does it?

# free -m
              total        used        free      shared  buff/cache   available
Mem:           3791          85        3576          16         128        3512
Swap:             0           0           0

4GB is 4096MB, yet I only have 3791MB to use. Experienced linux administrators will point you to the kernel documentation:

MemTotal: Total usable ram (i.e. physical ram minus a few reserved bits and the kernel binary code)

Still, with 3791MB usable that means 305MB has been reserved - 7.5% seems like a lot to reserve.

There is a feature called "crashkernel" that is enabled by default on CentOS.  This feature reserves a significant amount of memory for its exclusive use; memory that is not usable by your applications. You can tell if this feature is enabled by checking dmesg after boot:

# dmesg | grep Reserving
[    0.000000] Reserving 161MB of memory at 656MB for crashkernel (System RAM: 4095MB)

So I have given up 161MB of memory for this feature.  If the kernel ever crashes, its state is copied into this reserved memory and after rebooting you can use a tool called "kdump" to copy that memory to a file and potentially get someone to debug the cause of the kernel crash.

At least that's the theory. For the vast majority of VPS users the kernel will never crash; and if it ever does most users will reboot and make sure the latest version is installed. If kernel crashes are rare and determining the exact cause of a crash is not important, then "crashkernel" is reserving memory for a feature that will never be utilised. So it makes sense to disable it:

# sed -i 's/crashkernel=auto/crashkernel=no/' /etc/default/grub

# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...

# reboot

After the reboot completes, check dmesg to confirm it is disabled:

# dmesg | grep Reserving
<no output>

And lastly, confirm that more memory is available:

# free -m
              total        used        free      shared  buff/cache   available
Mem:           3952          82        3746          16         123        3679
Swap:             0           0           0

As expected, a further 161MB of memory is available to use.