For total RAM, use free -h. For type and speed, use sudo dmidecode -t memory. For installed modules with sizes, use sudo lshw -C memory. The three commands answer three different questions, and the team that knows which one matches the question has the right answer in under five seconds.
Table of contents
- The three questions RAM info answers
- The free command: total, used, available
- The dmidecode command: type, speed, manufacturer
- The lshw command: physical layout
- Reading the difference between total and usable
- When to use /proc/meminfo directly
- FAQ
The three questions RAM info answers
There are three things you usually want to know about the memory in a Linux system. How much do I have in total? What type and speed is the RAM? Which physical slots are populated? The three commands map to the three questions.
For total RAM, free -h is the right tool. It is fast, does not need root, and the output is human-readable. For a quick sanity check, free -h | head -2 is the canonical one-liner. For type and speed, sudo dmidecode -t memory is the right tool. It reads the DMI (Desktop Management Interface) tables from the BIOS and prints every memory slot’s populated speed, type, and size. The output is verbose; pipe to less or grep for the answer. For the layout of physical slots, sudo lshw -C memory is the right tool. It shows every DIMM slot, whether it is populated, and the size of each module.
The free command: total, used, available
The free command is the right answer for “how much RAM does this box have.” The -h flag is for human-readable units (KB/MB/GB). The output is a single block:
total used free shared buff/cache available
Mem: 15Gi 3.2Gi 1.4Gi 312Mi 10Gi 11Gi
Swap: 4.0Gi 0B 4.0Gi
total is the total physical RAM. used is what the kernel and userspace have allocated. free is unused RAM. buff/cache is RAM the kernel is using for disk cache (reclaimable). available is the number you care about — it is free plus reclaimable cache, and it is the number that says “how much can a new process actually use.”
The free command reads from /proc/meminfo. If you want the raw numbers, cat /proc/meminfo shows them. The fields are the same; the output is less human-readable.
The dmidecode command: type, speed, manufacturer
The dmidecode command reads the DMI table from the system firmware. The -t memory flag filters to the memory section. The output looks like:
Memory Device
Total Width: 64 bits
Data Width: 64 bits
Size: 16 GB
Form Factor: DIMM
Locator: DIMM_A1
Type: DDR4
Type Detail: Synchronous Unbuffered (Unregistered)
Speed: 3200 MT/s
Manufacturer: Kingston
Serial Number: 12345678
Asset Tag: 9876543210
Part Number: KF3200C16D4/16GX
Rank: 2
The fields to look at: Size for the module size, Type for DDR3/DDR4/DDR5, Speed for the MT/s rating, Manufacturer for the brand. The Part Number is the exact SKU — useful for ordering replacements.
The dmidecode command needs root. The reason is that the DMI table is technically a privileged interface, and some BIOS vendors include information that is not safe to expose to unprivileged users. On most distros, the sudo prefix is sufficient.
The lshw command: physical layout
The lshw command is a hardware lister. The -C memory flag filters to the memory class. The output shows the physical layout of DIMM slots:
sudo lshw -C memory -short
The -short flag is the right call for a quick answer; without it, the output includes every child node and is verbose. The short output looks like:
H/W path Device Class Description
===========================================================
/0/0 memory 128KiB BIOS
/0/1 memory 128KiB L1 cache
/0/2 memory 1MiB L2 cache
/0/3 memory 12MiB L3 cache
/0/4 memory 16GiB System Memory
/0/4/0 memory 8GiB DIMM DDR4 Synchronous 3200 MHz (0.3 ns)
/0/4/1 memory 8GiB DIMM DDR4 Synchronous 3200 MHz (0.3 ns)
/0/5 memory 4GiB DIMM DDR4 Synchronous 2666 MHz (0.4 ns)
/0/5/0 memory 4GiB DIMM DDR4 Synchronous 2666 MHz (0.4 ns)
The right way to read this is to look for populated slots and what speed they are running at. If a slot is listed as populated with a speed, it has a module. If a slot is missing from the list, it is empty. Mixed speeds (the 3200 and 2666 in the example) are common in hand-built desktops where someone added mismatched modules — the whole bus downclocks to the slower module.
Reading the difference between total and usable
A common gotcha is that free -h reports less than the total physical RAM. On a 16 GB box, free might show 15.5 GB. The reason is that the kernel reserves a small portion of RAM at boot for the kernel itself — a few hundred MB on a typical x86 box, more on systems with extra hardware like GPUs that need reserved memory. The reserved memory is in /proc/iomem:
grep 'System RAM' /proc/iomem
The output is the physical memory map. The first range is the usable RAM, and any smaller ranges below it are reserved. The total reserved is typically 1-2% of physical RAM, not 5-10%.
Another common gotcha is that some motherboards report the maximum supported RAM but only populate half the slots. The lshw output makes this obvious — half the slots are listed, half are missing. The fix is to buy matching modules and populate the empty slots. Mixing speeds is fine for desktops but is a stability risk on production servers.
When to use /proc/meminfo directly
The free command is a frontend to /proc/meminfo. If you are scripting something — a monitor, a deployment tool, an alert — read /proc/meminfo directly. The fields you want are MemTotal (total physical), MemAvailable (what’s actually free for new processes), SwapTotal (total swap), and SwapFree (unused swap). The other fields are useful for debugging but are not what a monitor needs.
A common pattern in monitoring tools is to alert on MemAvailable falling below a threshold. The right threshold depends on the workload, but 10% of total is a reasonable starting point. A box with 5% or less MemAvailable is under memory pressure and will start using swap heavily, which is a sign of an OOM (out-of-memory) event coming soon.
FAQ
Do I need to install lshw?
On most distros, yes. sudo apt install lshw on Debian/Ubuntu, sudo dnf install lshw on Fedora/RHEL, sudo pacman -S lshw on Arch. The free and dmidecode commands ship with every distro by default.
Why does my box show 16 GB but the OS only sees 8 GB?
This is almost always a hardware issue. Either the modules are not fully seated, the BIOS is misconfigured (a single-channel vs dual-channel mismatch, or a maximum RAM limit set in firmware), or one of the modules is bad. The right debugging step is to reseat the modules and check the BIOS settings. The lshw output should match the physical slots populated.
Can I see the RAM speed in MHz or only MT/s?
Modern RAM is labeled in MT/s (mega-transfers per second), not MHz. DDR4-3200 runs at 1600 MHz but transfers at 3200 MT/s because DDR (double data rate) transfers twice per clock cycle. The dmidecode output uses MT/s. The lshw output may show MHz with the half-rate conversion. The two numbers refer to the same thing; the right one to use is whatever your vendor uses.
Is there a way to test RAM for errors from Linux?
Yes — memtest86+ is the canonical tool. It runs from a boot menu (GRUB includes it on most distros) and does a full pass over every byte. The runtime is hours for a 16 GB module. The right way to use it is to let it run overnight. A single pass with no errors is a good sign. A second pass catches errors that the first pass missed.
What is the difference between used and buff/cache in free?
used is RAM allocated to processes. buff/cache is RAM the kernel is using as a disk cache. The kernel can release the cache at any time when a process needs the memory, so the right number for “how much can a new process use” is available, not free. A box with 1% free and 80% buff/cache is fine. A box with 1% free and 80% used is in trouble.
What about NUMA systems?
On a multi-socket server, numactl --hardware shows the NUMA layout. Each CPU socket has its own memory, and the kernel tries to keep a process’s memory on the same socket. lscpu shows the topology. The right answer for NUMA tuning is to verify that high-bandwidth processes are pinned to the right socket, but the right answer for most workloads is to leave the default NUMA balancing on and let the kernel decide.
If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.
Useful related references: