RAM Visualizer with Space Filling Curves
Space-filling curves have often been used to make interesting visualizations of the IP address range, as they provide an elegant way to map one-dimensional data (IP addresses) to 2D space while keeping ranges that are close together in 1D space also close together in 2D space.
While searching for other data sources that might work well with this technique I had the idea to try it with RAM assignments, as RAM is a one-dimensional address space.
In Linux it's possible to check which portions of RAM are
assigned to which processes (haven't had time to write down the
details yet, see man proc_pid_pagemap and man
proc_iomem for the general idea) so I wrote up some
C code to save the RAM assignments to disk, processed those
assignments into images using Python, and used ffmpeg
to stich them together into a video.
The final video is a visualization of RAM assignments where each process is a different colour. The data was collected once every 5 seconds over the course of 2 hours, the snapshot timestamp is at the bottom right (of course it's not a true "snapshot" as the system is not frozen in the time it takes to save the RAM ranges to disk). The left two thirds of the image represent the assignments present in my laptop's 16GB of RAM, and the left third is the 8GB of swap.
Some interesting features:
- In hindsight, RAM being "Random Access" should mean that there's no reason to expect contiguous assignments. Unlike for IP addresses where it's easier to assign a range between two numbers, to a computer program it shouldn't matter if its assigned memory is a contiguous range or fragmented addresses. Despite that there are still distinct "chunks" that belong to the same process. Maybe logic of the the memory assignment algorithm is just simpler if things are mostly-contiguous ranges?
- The swap starts to get used at the end of the video, and that area does seem to get filled up in a far more contiguous, less fragmented manner than the RAM addresses. Since swap involves saving less-used portions of RAM to the disk, I think the less fragmented pattern is because it was much faster to load contiguous ranges from hard drive disks in the era before SSDs and this algorithm is a holdover from that time.