Kennisbank › Linux › Linux process and memory management
linux gevorderd 26 August 2026

Linux process and memory management

Linux process and memory management: kernel mechanisms, tools and allocators

Linux process and memory management: kernel mechanisms, tools, and allocators

This article explains how the Linux memory management subsystem works — from paging to allocators — and shows the commands to monitor processes and memory usage. Aimed at system administrators and DevOps engineers working with Linux kernels version 5.x and 6.x.

Prerequisites

- A Linux system with kernel version 5.13 or higher (for vmalloc huge page support) or 6.12+ (for vrealloc) - Root access or sudo privileges to view kernel documentation and install tools - `procps` package (contains `vmstat`) — present by default on most distributions - Install the `smem` tool: `sudo apt install smem` (Debian/Ubuntu) or `sudo dnf install smem` (Fedora/RHEL)

Steps

1. Check your kernel version

Run:

uname -r

Note the version number. Memory management features vary by kernel version — vrealloc, for example, has only existed since v6.12 (2024).

2. Understand the basics: paging and page tables

Each Linux process has its own page table. That table maps virtual memory addresses to physical memory locations. Memory is divided into equal blocks: virtual "pages" are assigned to physical "page frames". This is the core of memory isolation between processes — a process cannot read or write another process's memory.

View the official kernel documentation:

man 9 memory

or online: the "Memory Management" section in the Linux Kernel documentation (updated on August 24, 2026) and the separate "Memory Management Documentation" page (updated on August 18, 2026).

3. View active memory usage with vmstat

`vmstat` displays processes, memory, paging, block I/O, context switches, and CPU activity. The first report shows averages since the last reboot; subsequent reports show a sampling period.

vmstat 2 5

This runs 5 reports at 2-second intervals. Look at the `si` (swap in) and `so` (swap out) columns — high values indicate memory pressure.

4. Measure memory usage per process with smem

`smem` reports memory usage per process, including USS (Unique Set Size) — the memory used exclusively by one process, without overlap with other processes. This is more accurate than `top` or `ps` for systems with many concurrent processes.

smem -rs uss

The `-r` flag sorts, `-s uss` sorts by the USS column. Install the package first if it is missing (see Prerequisites).

5. Configure swap memory

Swap is virtual memory on disk used when RAM becomes full. It prevents an immediate crash but is slower than RAM. View the current swap status:

swapon --show

To create a 2 GB swapfile:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Add `/swapfile none swap sw 0 0` to `/etc/fstab` to make this permanent.

6. Limit resources with cgroups

cgroups (control groups) limit memory and other resources per group of processes. This is essential in multi-user environments and containers. Create a cgroup with a memory limit of 512 MB:

sudo mkdir /sys/fs/cgroup/memory/mygroup
echo 536870912 | sudo tee /sys/fs/cgroup/memory/mygroup/memory.limit_in_bytes

Place a process in the group by writing its PID to the tasks file:

echo <PID> | sudo tee /sys/fs/cgroup/memory/mygroup/tasks

7. Know the OOM killer

The Out-of-Memory killer automatically terminates one or more processes when the system runs critically low on memory. It is a last resort to keep the kernel stable. View the OOM killer log:

dmesg | grep -i "out of memory"

You can influence OOM behavior per process with `oom_score_adj`:

echo -1000 | sudo tee /proc/<PID>/oom_score_adj

A value of -1000 makes a process immune to the OOM killer; +1000 makes it a prime candidate.

8. Know the allocator history (for context)

The kernel has used different allocators over time. This knowledge helps in interpreting kernel documentation and choosing optimizations:

- 1991: buddy allocator for memory pages - 1996: SLAB allocator for kernel objects - 2007: SLUB becomes standard (better performance, simpler maintenance) - 2021 (v5.13): vmalloc huge page support - 2023: SLOB removed (was for very small systems) - 2024 (v6.12): vrealloc — more flexible rearrangement of virtual memory

Verification

Check that everything works:

vmstat 1 3
smem -rs uss | head -20
swapon --show
cat /sys/fs/cgroup/memory/mygroup/memory.usage_in_bytes

You should see: swap activity in the `si`/`so` columns, a list of processes sorted by USS, your swapfile in the swapon output, and memory usage below 536870912 bytes for the cgroup.

Frequently asked problems

Problem 1: `smem` command not found Install the package: `sudo apt install smem` or `sudo dnf install smem`. On some systems, the package is named `smemstat`.

Problem 2: OOM killer terminates processes despite sufficient swap Check that `vm.swappiness` is set low. Otherwise, the kernel swaps too aggressively. Set it with:

sudo sysctl vm.swappiness=10

Make this permanent in `/etc/sysctl.conf`.

Problem 3: cgroup-map not present under /sys/fs/cgroup On systems with cgroups v2 (kernel 4.5+), you use a different interface. Check the mount:

mount | grep cgroup

With cgroups v2, use `echo "max" > /sys/fs/cgroup//memory.max` instead of `memory.limit_in_bytes`.

The kernel evolves — today's allocator will be different in five years. Keep following the documentation pages; the next change is already in the changelog of kernel v6.13.

← Back to knowledge base
← Terug naar kennisbank