"Rearrange your RAM"

Ah, this was my first 'real' public speaking experience. It wasn't recorded, unfortunately. Well, that's a lie... ;-).

It was the very last hour of Polycloud 2024, an event in Montpellier, France, at Polytech Montpellier — an engineering school that I had been attending.

I was a newbie in everything. It had not been 6 months that I'd been using Linux on a daily basis (we were made to install it on the first day of class), and proof of the curiosity that forever plagues me, I had recently switched to Arch Linux.

The organisers had just announced that this last hour was open for short talks, an open mic! At this instant, a grandiose impulse came over me: I had to do one. It had to happen, as in my mind and on my keyboard I was already writing the future that lay before me: a recent curiosity, no slides, a quick piece of code, and a few shell scripts.

I was not listening to the first short talks, though I do remember who came before me. I was writing a small piece of code, in C, that would continuously run `malloc` to try and fill its virtual memory with 1's. It seemed to work well enough.

Next step — I thought of a way to present my curious idea. A path through a humorous story... And there I had it! Though, in testing my piece of code, I realised there was some waiting to do at some point. Just a minute or two, as the program filled my virtual memory and swap (which was quite large, I mean very large, as my plaguing curiosity, again, led me to conduct some strange experiments). Nothing much, but long enough that it needed... What? Filler?

So to fill in the waiting part, I devised a cunning plan: I'd show the audience some amusing and curious things that I found while surfing the Interwebs, during some boring class earlier in the week. I adjusted a couple of shell scripts and voilà! That was the last thing I needed.

Hoping that'd be enough, I raised my hand and announced I had one short talk I could do. My friends around me started cheering, and it's a little bit embarrassed but no less determined that rushed down the flight of stairs to the amphitheater stage, laptop in hand and setup at the ready.

The organisers were fellow students of the grade above, and though I didn't know them much, that certainly played a part in my comfort and confidence.

Hastily getting behind the row of tables that fronted the stage, I plugged the projector's cable to my computer. The image took some time to show on screen — and when it did, people saw the colourful interface of a running `btop`, a program that a classmate of mine had recently introduced to me. At the time, this program felt quite impressive to me. Especially on that big screen behind me. So much data, everywhere, all at once. And it all moves!

"This is `btop`", says I (in vernacular French).
"It shows a quantity of stuff like CPU load, running programs, and RAM usage, which is what we're interested in today."

To the left of the huge screen laid the total RAM usage metric. It kept moving. Hurrying to the screen, I placed myself under the red bar as it evolved steadily at a flat constant, filling its space. The screen was too big, and the bar was too high for me to point to it. Thus I attempted a pathetic jump, arm stretched, pointing at the red bar, stating: "this, is the total RAM usage."

That little jump produced laughter from the audience, which was already getting far from calm, being so suddenly waken by a screen of shifting colours, after an excruciatingly long and hot summer day of looking at slides that were too full of texts, and listening to one-too-many middle-aged white man ramble about Web development and production failures, entertaining as that may be.

Back to my seat, I followed with an explanation of the events that were about to unfold.

"We are going to fill my RAM." The audience is agitated. My friends laugh at my apparent lunacy. "I have here a program that will `malloc` in a loop, filling its memory with 1's." Laughter erupts. The audience is relaxed and amused — I am not. I am focused, and a little embarrassed, though mostly eager to demonstrate my invention. The large projected screen shifts to a black shell, as I execute the program.

Switching back to `btop`, I narrate as we observe the total RAM usage climb up, and up, in a constant slope — until it slows down as the RAM is full and the swap space gets nibbled away slowly. "You may notice I have a LOT of swap space. 32 gigs. Don't ask." More laughter, this time at the obscene amount. "Thus it will take a while to fill in, however for your pleasure I have prepared a couple fun things to show you."

I switch to a TTY I had prepared, but the projector takes a while to switch the screen. "Don't worry, it's coming". The room stares impatiently at the pitch black screen. It appears. One command waits for execution. I state: "This dumps /dev/random to the screen". I press enter, and it does. The screen gets filled with random characters at high-speed. It's amusing, but there's more. I stop the loop and restore another command from history: "This one dumps /dev/random to the speakers!"

A faint, low rumbling sound emerges from the laptop, that only the first rows can hear. "Now, we're probably close to the RAM being filled, so let's switch back."

Indeed we were, as the entertaining time-out timed itself unexpectedly well. The `btop` interface is back on screen: swiftly evaluating the constant speed at which the swap space was getting filled, I start counting down from 10, soon joined by the audience. As the red bar reaches the maximum, every shifting colour, every movement once taken for granted, unexpectedly grinds down to a halt. The `btop` interface is completely frozen. Suprise and laughter from the room and I, and more as I try to bring the terminal back to life, only to realise that `btop` had died, and left only the last print of its UI on the dark drop of the shell.

Now for the final act, I explain the events to the best of my understanding: the Linux kernel took the extreme measure of calling its "OOM Killer" ("Out-Of-Memory Killer") on programs of lesser importance, such as `btop`, until it hunted down the offending program, our yet unnamed `malloc`-loop of death. The ultimate revelation appears as I open a new instance of `btop`: the RAM is "squeaky clean": All that can be cached, is cached. Whether it is in the swap, or the RAM. Unused background programs are dead, some others were freshly run again. "I've cleaned the RAM! Our program is a RAM cleaner".

This funny tale ends triumphantly in laughter. No boring slides, lots of colours, a couple funny asides, and a new program that I still have to this day, years later, laptop after laptop, still in its place in `~/.local/bin/`, and earnestly titled "RAMVacuum".

A screenshot of `ls`, listing the RAMVacuum program.

I have yet to run it again on a computer that I'm not about to brick.