How to Reclaim RAM from the System Reserve with AlmaLinux 9

AlmaLinux 9, like any operating system, at times may exhibit high memory consumption even without much applications running on it, leaving only a limited amount of available memory. This guide explores methods to optimize RAM usage on AlmaLinux 9, ensuring a more efficient utilization of resources.

Crashkernel Configuration

In EL8, crashkernel is set to auto, but in EL9, a more explicit approach is taken with the following configuration:

  • 1G-4G: 192M
  • 4G-64G: 256M
  • 64G-: 512M

This guide will show you how to adjust this configuration to potentially recover more physical RAM.

Method 1: Modifying Crashkernel Values

  1. Check RAM Usage

    Run the following command to check the current RAM usage:

    free -m

    Output:

    [root@vps ~]# free -m
                   total        used        free      shared  buff/cache   available
    Mem:            3647         352        3334          16         171        3295
    Swap:            511           0         511
    [root@vps ~]#
  2. Locate Crashkernel Information.

    Use the following command to identify the "crashkernel" line in the GRUB configuration,

    dmesg | grep "crashkernel"

    Output:

    [root@vps ~]# dmesg | grep "crashkernel"
    [    0.000000] Command line: BOOT_IMAGE=(hd0,gpt2)/boot/vmlinuz-5.14.0-362.8.1.el9_3.x86_64 root=UUID=e5fe4ae3-f750-4286-a1f8-eceb3e5d7633 ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=UUID=e1aef783-c5b4-4e3a-9aef-83cafcc5a9c6
    [    0.013852] Reserving 256MB of memory at 2688MB for crashkernel (System RAM: 4095MB)
    [    0.073641] Kernel command line: BOOT_IMAGE=(hd0,gpt2)/boot/vmlinuz-5.14.0-362.8.1.el9_3.x86_64 root=UUID=e5fe4ae3-f750-4286-a1f8-eceb3e5d7633 ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=UUID=e1aef783-c5b4-4e3a-9aef-83cafcc5a9c6
    [root@vps ~]# 
  3. Apply New Crashkernel Configuration

    Run the following command to apply the modified crashkernel value,

    grubby --update-kernel=ALL --args="crashkernel=1G-4G:128M,4G-64G:192M,64G-:256M"
  4. Reboot the Server

    After applying the changes, reboot the server and check the RAM usage again,

    reboot

    Chet the RAM usage again using below command,

    free -m

    Output:

    [root@vps ~]# free -m
                   total        used        free      shared  buff/cache   available
    Mem:            3711         361        3389          16         170        3349
    Swap:            511           0         511
    [root@vps ~]#

Method 2: Disabling kdump for RAM Reclamation

  1. Check kdump Status

    Determine the status of the kdump service using the following command,

    systemctl status kdump

    Output:

    [root@vps ~]# systemctl status kdump
    ● kdump.service - Crash recovery kernel arming
         Loaded: loaded (/usr/lib/systemd/system/kdump.service; enabled; preset: enabled)
         Active: active (exited) since Fri 2024-01-19 16:42:59 UTC; 58s ago
        Process: 721 ExecStart=/usr/bin/kdumpctl start (code=exited, status=0/SUCCESS)
       Main PID: 721 (code=exited, status=0/SUCCESS)
            CPU: 1.940s
    
    Jan 19 16:42:57 vps.server.com systemd[1]: Starting Crash recovery kernel arming...
    Jan 19 16:42:59 vps.server.com kdumpctl[740]: kdump: kexec: loaded kdump kernel
    Jan 19 16:42:59 vps.server.com kdumpctl[740]: kdump: Starting kdump: [OK]
    Jan 19 16:42:59 vps.server.com systemd[1]: Finished Crash recovery kernel arming.
    [root@vps ~]# 
  2. Stop and Disable kdump

    Stop the kdump service and prevent it from starting automatically,

    systemctl stop kdump && systemctl disable kdump
  3. Change Crashkernel Setting

    Change the GRUB_CMDLINE_LINUX setting from crashkernel=auto to crashkernel=no using below command,

    grubby --update-kernel=ALL --args="crashkernel=no"
  4. Update GRUB

    Update the GRUB configuration with the following command,

    grub2-mkconfig -o /boot/grub2/grub.cfg
  5. Reboot the Server

    After updating GRUB, reboot the server and check the RAM usage,

    reboot

    Once rebooted check the RAM usage using below command,

    free -m

    Output:

    [root@vps ~]# free -m
               total        used        free      shared  buff/cache   available
    Mem:            3903         337        3627          16         126        3565
    Swap:            511           0         511
    [root@vps ~]# 
    

By following these methods, users can tailor the memory allocation settings on AlmaLinux 9, optimizing the system's RAM usage for enhanced performance and responsiveness.


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS