Introduction
The lsmem command is part of the util-linux package and is responsible for displaying detailed information about the system’s physical memory, including address ranges, the size of each block, and its state (online/offline). Unlike tools such as free or top, lsmem focuses on the low‑level view that the kernel exposes via sysfs, allowing the administrator to identify memory fragments that may be disabled by hardware or by boot configurations. This level of detail is especially useful in high‑availability servers, in systems with hot‑pluggable memory, and in virtualization environments where it is necessary to validate resource allocation. In the following article we will explore its operation, syntax, and the most common use cases.
What is lsmem
lsmem reads the information present in the /sys/devices/system/memory/ directory, where each memory block is represented as a subdirectory named memoryXXX. Each of these directories contains files such as state, removable, and size that indicate whether the block is active, whether it can be removed hot‑plug, and how many kilobytes it occupies. When lsmem is run without arguments, the tool aggregates this data and presents it in a readable table showing the start and end of each segment, its size, and its current state. This output allows you to quickly detect unused memory gaps or blocks marked as offline that could be brought back online via hot‑add operations.
Basic Syntax
The basic syntax of lsmem is very simple: lsmem [options]. If no options are specified, the command assumes the default behavior of listing all available memory ranges. Some of the most used options include -a or –all to also show blocks marked as removable, -b or –bytes to express sizes in bytes instead of the default unit (kilobytes), and -J or –json to generate output in JSON format that facilitates processing by scripts. Other options such as -h or –help and -V or –version are standard for obtaining help and the program version.
Most Useful Options
Among the most useful options are -p or –human, which adapts the presentation to readable units (KB, MB, GB) according to the size of each block, and -S or –summarize, which summarizes the total amount of online and offline memory instead of listing each segment individually. There is also the -o or –output option that allows selecting specific columns such as start, end, size, state, and removable, which is very practical when you need to feed other programs with precise data. Combining several options, for example lsmem -b -o start,size,state, provides a raw and detailed view ideal for hardware audits.
Practical Examples
Example 1: View memory in bytes and with custom columns. Running lsmem -b -o start,size,state yields a list where each line shows the start address, the exact size in bytes, and whether the block is online or offline. This is useful for scripts that need to validate that all memory ranges are active after a boot. Example 2: Summarize total online and offline memory. With lsmem -S it will print something like: total online memory: 32GB, total offline memory: 0GB, allowing a quick verification of available capacity without manually summing values. Another use case is combining lsmem with grep to filter removable blocks: lsmem -a | grep removable:1 helps identify which memory sections can be removed hot‑plug, critical information on platforms that support RAM hot‑plug.
Interpreting the Output
The output of lsmem is organized in columns that, by default, include the start address range (Start), the end address range (End), the size (Size), and the state (State). The State field can show online, indicating that the block is available to the kernel, or offline, indicating that it is deactivated, either due to missing hardware, BIOS configuration, or a prior hot‑remove action. When the -a option is used, an additional Removable column appears, with values 1 or 0, indicating whether the block can be added or removed while the system is running. Correctly interpreting this data helps plan memory upgrades, diagnose RAM detection failures, and validate the functionality of dynamic memory mechanisms in cloud and container environments.
Limitations and Alternatives
Although lsmem provides a precise view of physical memory, it has certain limitations: it does not show information about memory usage by processes, nor about caches, buffers, or swap; for those aspects tools such as free, vmstat, or /proc/meminfo should be used. Moreover, on systems where the kernel does not expose memory blocks via sysfs (for example, some very old embedded architectures), lsmem may return an empty output or an error. In those cases, alternatives such as dmidecode -t memory or lshw -class memory can provide data about the installed RAM modules, although at a less granular level than that provided by lsmem. Finally, in containers, lsmem’s view is limited to the memory
This post is also available in ESPAÑOL.