Okay, let's break down what "reserved memory" could mean in the context of an Ubuntu server (or any Linux system) and how to check it, focusing on non-userland aspects.
The term "reserved memory" isn't a single, strictly defined metric in Linux like MemFree or MemAvailable. It usually refers to memory that the operating system kernel or the system firmware (BIOS/UEFI) has set aside and made unavailable for general-purpose dynamic allocation to applications or even the kernel's standard caches.
Here are the common interpretations and how to check them:
Memory Reserved by Firmware/Hardware (BIOS/UEFI):
What it is: During boot, the system firmware inventories physical memory and might reserve certain address ranges for specific hardware components (e.g., graphics card frame buffers, specific PCI devices). The kernel respects these reservations.
How to check: The /proc/iomem file provides a human-readable map of the system's memory regions and how they are allocated or reserved.
Command:
bash
cat /proc/iomem
Interpretation: Look for entries marked as reserved, especially those associated with specific devices or ranges flagged as "System ROM", "Uncached", or specific hardware mappings. The kernel itself also reserves memory for its own structures, which will appear here. You'll see ranges like 00000000-00000fff : Reserved or specific device ranges. Summing up the sizes of these reserved ranges gives you an idea of this type of reservation.
Kernel Memory Usage (Non-Cache/Buffer):
What it is: This includes the kernel code itself, kernel data structures, kernel stacks, memory allocated for drivers, and memory used for things like page tables. While much of this can be freed or reclaimed under extreme pressure (except core code/data), it's memory actively used by the OS core, not by user applications.
How to check: The /proc/meminfo file is the most detailed source.
MemAvailable: An estimate of how much memory is available for starting new applications, without swapping. This includes MemFree plus reclaimable cache/buffers.
Buffers, Cached: Memory used for block device caching and page cache. Generally reclaimable.
Slab: Kernel memory cache (often reclaimable). SReclaimable is the reclaimable part, SUnreclaim is the part the kernel prefers not to reclaim (more "reserved" in a sense).
KernelStack: Memory for kernel task stacks.
PageTables: Memory used for mapping virtual to physical memory addresses.
HardwareCorrupted: Memory pages detected as faulty by the kernel (often due to hardware issues).
Calculating "Reserved" Kernel Usage: A rough way to estimate memory not available for applications is MemTotal - MemAvailable. This difference represents memory used by the kernel, caches that might not be easily reclaimable, and potentially other system structures. You can further refine this by looking at SUnreclaim, KernelStack, PageTables, etc., but summing them precisely is complex as they overlap and interact.
Kernel Command Line Reservations:
What it is: Sometimes, specific memory ranges can be reserved or excluded from the kernel's general management using kernel command-line parameters (e.g., memmap= or efi=). This is less common for general use but might be done for specific hardware or debugging.
How to check: Examine the active kernel command line.
Command:
bash
cat /proc/cmdline
Interpretation: Look for parameters related to memory mapping or exclusion.
Systemd Services Memory (System Components):
What it is: While technically userland, the core system services managed by systemd (like systemd-journald, dbus, networkd, etc.) consume memory. This isn't "reserved" in the firmware sense, but it's memory used by essential system components rather than user-initiated applications.
How to check: You can use tools like top, htop, or specifically systemd-cgtop to see memory usage broken down by systemd control groups (slices/scopes).
Commands:
bash
# Shows systemd units and their resource usage
sudo systemd-cgtop
# Or use top/htop and filter/sort by memory
top
# Press 'M' to sort by memory usage
# Press 'c' to see the full command line
htop
# Press F6 to sort, choose PERCENT_MEM or M_RESIDENT
Interpretation: Identify the memory used by system services. This adds to the non-user-application memory footprint.
Summary Approach:
Overall Availability: Start with free -h. The available column shows what's realistically free for new processes. total minus available is a good measure of memory in use by the kernel, caches, and running processes (both system and user).
Hardware Reservations: Check cat /proc/iomem for ranges explicitly marked as reserved or mapped to hardware components. This is the closest to "firmware reserved" memory.
Kernel Internal Usage: Check /proc/meminfo. SUnreclaim, KernelStack, PageTables contribute to kernel memory usage that is less likely to be freed than Cached or Buffers.
There isn't one command that outputs a single "reserved memory" figure. You typically infer it by understanding what is accounted for (kernel structures, hardware mappings, system services) versus what is truly free (MemFree) or available (MemAvailable).