The Backend Engineering Show with Hussein Nasser

The Cost of Memory Fragmentation

The Backend Engineering Show with Hussein Nasser

Show Notes

Fragmentation is a very interesting topic to me, especially when it comes to memory.

While virtually memory does solve external fragmentation (you can still allocate logically contiguous memory in non-contiguous physical memory) it does however introduce performance delays as we jump all over the physical memory to read what appears to us for example as contiguous array in virtual memory.

You see, DDR RAM consists of banks, rows and columns. Each row has around 1024 columns and each column has 64 bits which makes a row around 8kib. The cost of accessing the RAM is the cost of “opening” a row and all its columns (around 50-100 ns) once the row is opened all the columns are opened and the 8 kib is cached in the row buffer in the RAM.

The CPU can ask for an address and transfer 64 bytes at a time (called bursts) so if the CPU (or the MMU to be exact) asks for the next 64 bytes next to it, it comes at no cost because the entire row is cached in the RAM. However if the CPU sends a different address in a different row the old row must be closed and a new row should be opened taking an additional 50 ns hit. So spatial access of bytes ensures efficiency,

So fragmentation does hurt performance if the data you are accessing are not contiguous in physical memory (of course it doesn’t matter if it is contiguous in virtual memory). This kind of remind me of the old days of HDD and how the disk needle physically travels across the disk to read one file which prompted the need of “defragmentation” , although RAM access (and SSD NAND for that matter) isn’t as bad.

Moreover, virtual memory introduces internal fragmentation because of the use of fixed-size blocks (called pages and often 4kib in size), and those are mapped to frames in physical memory.

So if you want to allocate a 32bit integer (4 bytes) you get a 4 kib worth of memory, leaving a whopping 4092 allocated for the process but unused, which cannot be used by the OS. These little pockets of memory can add up as many processes. Another reason developers should take care when allocating memory for efficiency.

More from The Backend Engineering Show with Hussein Nasser

Oct 22, 2026

I discuss the state of what will be happening in the coming few years and why I encourage the 3 of you who want to be elite engineers to keep their critical thinking sharp. To pause and think before prompting.

Oct 15, 2026

This is a conversation with Rashed Hasan, a PhD Candidate from the University of Nebraska. We chatted about databases, ORMs and how to use AI without losing yourself. Rashed pagehttps://www.mdrashedulhasan.me/homepage

Sep 25, 2026

I discuss loops engineering and how it will numb creative thinking and critical system design for engineers.

Sep 18, 2026

I like SQL but the standard should have included ways to hint instead of the abstraction of "let me do it for you"

Sep 11, 2026

In this episode I explore why you should take some time to examine the operation you are caching before doing so. And why caching is a cop-out

See all episodes →