Inspect CPU and Memory Resources on Linux

Check CPU topology, available processing units, memory usage, DIMM hardware, NUMA layout, and container resource limits on Linux.

Linux exposes CPU and memory information through /proc, /sys, firmware tables, and command-line tools. Each source answers a different question: CPU topology describes the processors visible to the operating system, free reports current memory use, and dmidecode reports the memory devices described by system firmware.

Official references:

Install the Utilities

Most distributions install lscpu, nproc, and free by default. Install the packages below if any command is missing.

On Ubuntu or Debian:

sudo apt update
sudo apt install -y util-linux coreutils procps dmidecode

On Fedora, RHEL, or Rocky Linux:

sudo dnf install -y util-linux coreutils procps-ng dmidecode

Record the System Context

Before comparing hardware reports, record the operating system, kernel, architecture, hostname, and virtualization environment.

cat /etc/os-release
uname -a
hostnamectl
systemd-detect-virt

systemd-detect-virt prints a virtualization technology such as kvm, vmware, or wsl, or returns none on supported bare-metal systems. A virtual machine normally reports the virtual CPUs and memory assigned by the hypervisor rather than the host’s complete hardware.

Understand CPU Counts

CPU terminology is easy to mix up:

  • A socket is a physical processor package or a virtual topology presented by a hypervisor.
  • A core is an independent processing core within a socket.
  • A thread is a hardware thread within a core when simultaneous multithreading is enabled.
  • A logical CPU is one processor number that the Linux scheduler can use.

For a typical two-socket system with 8 cores per socket and 2 threads per core, Linux sees 32 logical CPUs.

Display CPU Architecture and Topology

Use lscpu for a readable summary. It gathers information from sysfs, /proc/cpuinfo, and architecture-specific sources.

lscpu

The most useful fields are:

Field Meaning
CPU(s) Logical CPUs visible to the operating system
On-line CPU(s) list Logical CPUs currently online
Thread(s) per core Hardware threads per core
Core(s) per socket Physical or virtual cores in each socket
Socket(s) Processor packages visible to the system
NUMA node(s) Non-uniform memory-access nodes
Model name Processor model reported by the platform

Display one row per logical CPU with its core, socket, NUMA node, state, and frequency range.

lscpu --extended=CPU,CORE,SOCKET,NODE,ONLINE,MAXMHZ,MINMHZ

Use parseable output when another command or script will consume the topology. The default human-readable format can change between util-linux versions.

lscpu --parse=CPU,CORE,SOCKET,NODE,ONLINE

Produce structured JSON when the installed lscpu version supports it.

lscpu --json

Virtual machines may report a synthetic socket and core layout. Confirm the host topology in the hypervisor when licensing, NUMA placement, or performance tuning depends on physical hardware.

Count Available Processing Units

nproc reports the number of processing units available to the current process. CPU affinity, OpenMP environment variables, and cgroup v2 quotas may make this smaller than the number installed in the system.

nproc

Show the number of installed processors without applying those process-level restrictions.

nproc --all

This distinction matters for containers and restricted services. Use nproc when choosing a safe level of parallel work, such as a build job, and use lscpu when inspecting the machine’s topology.

Read Raw CPU Information

/proc/cpuinfo contains architecture-dependent information for each logical CPU.

less /proc/cpuinfo

Count the processor records exposed by architectures that provide the standard processor field.

grep -c '^processor' /proc/cpuinfo

Display unique processor model strings on x86 systems.

grep '^model name' /proc/cpuinfo | sort -u

Fields such as physical id, cpu cores, and model name are architecture-dependent and may be absent or synthetic in virtual machines. Avoid using them as the primary source for portable scripts.

Check Current Memory Usage

Use free for a snapshot of physical memory and swap usage.

free -h

The available column is usually more useful than the free column. Linux uses otherwise idle memory for caches and can reclaim much of it for applications, so a small free value alone does not indicate memory pressure.

Display separate buffers and cache columns.

free -h --wide

Display values in mebibytes, where one MiB is 1,048,576 bytes.

free -m

Display values in decimal megabytes, where one MB is 1,000,000 bytes.

free --mega

Refresh the report every two seconds and stop after five samples.

free -h --seconds 2 --count 5

For a compact view of the kernel’s raw memory counters, inspect selected fields in /proc/meminfo.

grep -E '^(MemTotal|MemAvailable|SwapTotal|SwapFree|HugePages_Total|HugePages_Free):' /proc/meminfo

Observe Memory Pressure

vmstat shows runnable processes, swapping, block I/O, interrupts, context switches, and CPU time. The first row contains averages since boot; later rows represent each sampling interval.

vmstat 1 5

Sustained nonzero values in the si and so columns indicate swap-in and swap-out activity. High swap activity together with low available memory can indicate pressure, but interpret it with application behavior and storage latency.

List processes using the most resident memory.

ps -eo pid,user,comm,%cpu,%mem,rss --sort=-rss | head -n 15

Show active swap devices and files.

swapon --show --bytes

Inspect Physical Memory Devices

dmidecode reads SMBIOS or DMI data supplied by the system firmware. Root permission is normally required.

Show only Type 17 Memory Device records, which describe installed DIMMs and empty slots.

sudo dmidecode --type 17

Show all memory-related DMI record types.

sudo dmidecode --type memory

Common Type 17 fields include:

Field Meaning
Locator Motherboard slot label
Bank Locator Firmware bank name
Size Installed capacity or No Module Installed
Type DDR generation reported by firmware
Speed Module-rated speed
Configured Memory Speed Current configured speed
Manufacturer Vendor reported in the module data
Part Number Module part number
Serial Number Module serial number when available

dmidecode does not probe the DIMMs directly. It reports what the firmware provides, and the upstream project warns that DMI data can be incomplete or inaccurate. Virtual machines may expose synthetic memory-device records or none at all.

Inspect NUMA Layout

lscpu summarizes NUMA nodes and the logical CPUs assigned to each node.

lscpu

If numactl is installed, show CPUs, memory size, free memory, and distance information for each NUMA node.

numactl --hardware

On a multi-socket system, NUMA-aware placement can reduce remote-memory access. Do not force NUMA policies without measuring the workload because incorrect binding can reduce performance or exhaust one node while memory remains available elsewhere.

Check Container Resource Limits

Inside a container, hardware inventory tools may describe the host or the container namespace rather than the resources the workload can actually consume. nproc may account for a cgroup v2 CPU quota, while some versions of free can still show host memory.

On a cgroup v2 system, display current memory use and the hard memory limit for the current cgroup.

cat /sys/fs/cgroup/memory.current
cat /sys/fs/cgroup/memory.max

memory.max contains max when no hard limit is set; otherwise it contains a limit in bytes.

Display the CPU quota and period.

cat /sys/fs/cgroup/cpu.max

The value max 100000 means there is no CPU bandwidth limit. A value such as 200000 100000 permits up to two CPUs worth of execution time during each period. Container runtimes can also restrict CPU affinity, so compare the result with nproc.

Troubleshoot Memory and CPU Problems

The System Is Slow but free Shows Little Free Memory

Check MemAvailable, swap activity, and the largest resident processes rather than judging only the free column.

free -h --wide
vmstat 1 5
ps -eo pid,user,comm,%cpu,%mem,rss --sort=-rss | head -n 15

A Process Was Killed Unexpectedly

Search the current boot’s kernel journal for out-of-memory events.

sudo journalctl -k -b --grep='Out of memory|oom-kill|Killed process'

For a container, also inspect its memory.max, memory.current, and memory.events files.

cat /sys/fs/cgroup/memory.max
cat /sys/fs/cgroup/memory.current
cat /sys/fs/cgroup/memory.events

CPU Counts Do Not Agree

Compare physical topology, installed processors, and processing units available to the current process.

lscpu
nproc --all
nproc

Differences can result from offline CPUs, CPU affinity, cgroup quotas, virtual-machine topology, or OpenMP environment variables.

A DIMM Is Missing or Has the Wrong Speed

Compare the firmware table with kernel hardware messages, then verify the module in the system firmware interface.

sudo dmidecode --type 17
sudo journalctl -k -b --grep='memory|EDAC|ECC|MCE' --case-sensitive=no

Power down the machine and follow the hardware vendor’s service procedure before reseating or replacing physical memory.

Licensed under CC BY-NC-SA 4.0
Last updated on Thursday, September 24, 2026
comments powered by Disqus