Operations 6 min read

How to Exhaust System Memory Instantly with tmpfs and dd on Linux

This guide shows how to use Linux's tmpfs file system together with simple commands like mount, dd, and taskset to allocate large amounts of RAM, simulate OOM conditions, and even target specific NUMA nodes without writing custom code.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Exhaust System Memory Instantly with tmpfs and dd on Linux

Overview

tmpfs

is a temporary, memory‑backed filesystem that Linux mounts by default at /dev/shm. It uses RAM first and can fall back to swap, but unlike a traditional ramdisk it is not a block device; it becomes usable simply by mounting it.

Allocate a specific amount of RAM

1. Create a mount point and mount tmpfs

mkdir -p /tmp/memory
mount -t tmpfs -o size=10240M tmpfs /tmp/memory

2. Fill the filesystem to reserve the memory

# Write zeros until the filesystem is full. The block size and count are optional; the default block size is 512 bytes.
# Using a larger block size makes the command finish faster.

dd if=/dev/zero of=/tmp/memory/block bs=1M count=10240 status=none

3. Verify the consumption

free -h

The free output will show roughly 10 GB less available memory.

Allocate the entire physical memory

Replace size=10240M with the total RAM size (e.g., size=64G on a 64 GB machine). Be aware that filling the whole RAM can make the system unresponsive or cause the OOM killer to terminate processes.

Allocate memory on a specific NUMA node

On systems with multiple NUMA nodes you can restrict the allocation to a single node.

1. Determine the CPUs belonging to the target node

node0_cpus=$(lscpu | grep "NUMA node0" | awk '{print $NF}')

2. Create a short script that mounts tmpfs and runs dd

cat > /root/mem_alloc.sh <<'EOF'
#!/bin/bash
# Create a temporary directory for the mount point
tmpdir=$(mktemp -d)
# Mount a 1 GB tmpfs instance (adjust size as needed)
mount -t tmpfs -o size=1024M tmpfs "$tmpdir"
# Consume the memory
dd if=/dev/zero of="$tmpdir/block" bs=1M count=1024 status=none
EOF
chmod +x /root/mem_alloc.sh

3. Run the script bound to the node’s CPUs

taskset -c "$node0_cpus" /root/mem_alloc.sh

After execution, numactl --hardware or numastat will show that the allocated pages reside on NUMA node 0, provided the requested size does not exceed that node’s local memory.

Important notes

Use a reasonable block size (e.g., bs=1M) with dd to speed up the write.

The size mount option limits the maximum amount of memory tmpfs can consume; it does not pre‑allocate the memory until data is written.

When allocating close to or beyond the available RAM, the kernel may start swapping or invoke the OOM killer.

Binding the process with taskset only restricts CPU execution; the actual memory locality is enforced by the kernel when the pages are faulted in, which can be observed with numactl or numastat.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

tmpfsmemory allocationMountddOOM simulation
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.