How to Benchmark Memory Bandwidth in Linux Terminal Using mbw

When auditing high-performance computing clusters, virtual machine hypervisors, or multi-channel RAM upgrades on a Linux server, understanding raw memory bandwidth is as critical as assessing CPU clock speeds. While tools like sysbench or dd measure composite CPU and storage performance, they frequently conflate processor caching and disk I/O with system bus capacity. The mbw (Memory Bandwidth Benchmark) utility determines available physical memory copy bandwidth by transferring large memory arrays using standard C library and pointer mechanisms directly in the Linux terminal.

What Is mbw and How Does It Test RAM?

mbw allocates an in-memory buffer of a user-defined size and measures the transfer speed of copying data between memory blocks. To prevent the CPU’s high-speed L1/L2/L3 hardware caches from masking true RAM bus speeds, the benchmark array must be configured larger than your CPU’s total cache capacity. mbw executes three distinct benchmarking methods:

  • MEMCPY: Copies memory blocks using the standard C library memcpy() function, which typically utilises hand-optimised SIMD assembly instructions (such as AVX or SSE).
  • DUMB: Copies memory using a basic array loop indexing one element at a time (a[i] = b[i]), representing unoptimised application memory access.
  • MCBLOCK: Allocates a smaller intermediary buffer and copies data chunk by chunk, evaluating cache-friendly chunking throughput.

Installing mbw on Linux

mbw is available in official package repositories across most major distributions:

# On Debian, Ubuntu, and Linux Mint
sudo apt update && sudo apt install mbw -y

# On Fedora and Red Hat Enterprise Linux (via EPEL)
sudo dnf install mbw -y

# On Arch Linux
sudo pacman -S mbw

How to Run a Memory Bandwidth Benchmark

The standard syntax for mbw requires specifying the test array size in megabytes (MB):

# Basic syntax (e.g. 512 MB array, 3 test loops)
mbw -n 3 512

In this command:

  • -n 3 sets the number of measurement loops (runs three test passes to calculate an accurate average).
  • 512 defines the array size in megabytes. For accurate results on modern servers with 32 MB to 128 MB of L3 cache, set the array size to at least 512 MB or 1024 MB (1 GB) to force memory transfers directly across physical RAM channels.

Restricting Tests to Specific Benchmark Methods

By default, mbw runs all three tests sequentially. If you only want to measure standard optimised memcpy performance, disable unnecessary tests using target flags:

# Run only the MEMCPY test on a 1024 MB buffer
mbw -n 5 -t 0 1024

# Run only the DUMB array loop test
mbw -n 5 -t 1 1024

# Run only the MCBLOCK chunked test
mbw -n 5 -t 2 1024

Interpreting Benchmark Results

Upon completion, mbw outputs individual loop timings followed by calculated average throughput in mebibytes per second (MiB/s):

Using standard memcpy()
0	Method: MEMCPY	Elapsed: 0.04512	MiB: 512.00000	Copy: 11347.518 MiB/s
1	Method: MEMCPY	Elapsed: 0.04498	MiB: 512.00000	Copy: 11382.837 MiB/s
2	Method: MEMCPY	Elapsed: 0.04505	MiB: 512.00000	Copy: 11365.150 MiB/s
AVG	Method: MEMCPY	Elapsed: 0.04505	MiB: 512.00000	Copy: 11365.168 MiB/s

Multiply MiB/s by 0.001048576 to convert the output into standard gigabytes per second (GB/s). In the example above, 11365 MiB/s represents roughly 11.9 GB/s of sustained memory copy bandwidth.

Notice the stark difference between methods:

  • MEMCPY will show the highest speed due to vectorized processor instructions.
  • DUMB typically achieves roughly half the speed of MEMCPY, demonstrating the performance penalty of non-vectorized code.

Benchmarking Multi-Channel RAM and NUMA Nodes

On high-end multi-socket servers with NUMA (Non-Uniform Memory Access) architecture, memory bandwidth varies drastically depending on whether a CPU core accesses local RAM or remote RAM attached to an adjacent CPU socket. You can pair mbw with numactl to evaluate memory latency penalties:

# Benchmark memory bandwidth exclusively on local NUMA node 0
numactl --cpunodebind=0 --membind=0 mbw -n 3 1024

# Benchmark cross-node memory bandwidth (CPU 0 accessing Node 1 RAM)
numactl --cpunodebind=0 --membind=1 mbw -n 3 1024

Comparing these two commands reveals the interconnect penalty incurred when threads access foreign memory banks, allowing you to fine-tune container pinning and process affinity.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.