How Do I Download More RAM?
It’s kinda like changing the blinker fluid in your car. You can’t. You shouldn’t. I mean… stuff like that doesn’t exist. But, if you’re finding yourself in a situation where you are running shy on your current installed amount of RAM, is there anything you can do without hitting up Newegg for a few more RAM sticks? Luckily, you can! Read on to learn how to add swap memory in Ubuntu 18.04.
Just recently, I tried rendering a complex Blender scene on my computer. Unfortunately it crashed before I ever saw the first tile start to render. Blender was all like, “ERROR: Out of Memory”. I tried rendering again, but this time I opened my system resources window and monitored the RAM usage. I have 16GB of RAM installed, and 2GB of swap. As the scene loaded, the RAM started climbing up to the top of the usage graph, hit the top, then the swap started filling up. They both hit the top, and Blender crashed again.
Fortunately, there’s a somewhat hacky thing called swap memory. So instead of purchasing extra RAM for your machine and going through all the trouble of installing it, you can add “virtual RAM” with just a few lines of code. This swap memory is designed as a sort of fail-safe should your machine demand more RAM memory than is physically installed. My problem was I was exceeding both my physical and my swap memory limitations. By default, Ubuntu was giving me 2GB of swap memory, and I had 16GB of RAM installed, but the Blender scene I was trying to render required more than my physical plus swap total of 18GB.
Step One: Check If You Have Swap Enabled
I’m using Ubuntu 18.04, so I can check my swap status by running this in the terminal:
sudo swapon --show
If there’s no output after running that command, you don’t have any swap memory enabled. If you do have swap enabled, you should get something like this:
NAME TYPE SIZE USED PRIO
/dev/sda2 partition 1.9G 0B -2
The swap information in Ubuntu (size and settings and all that) can be found in /swapfile. To enable the swap file, you’d run:
sudo swapon /swapfile
To learn more about the ‘swapon’ and ‘swapoff’ command, you can check out:
man swapon
Step Two: Disable Your Swapfile
Before you edit your swapfile, you need to disable it, otherwise you’ll get an error that’s something like “ERROR: file in use”. To do this, disable your swap file by running:
sudo swapoff /swapfile
Step Three: Edit Your Swapfile
You can edit your current swapfile (or add a new swapfile if you don’t have one) using the fallocate command. You can learn more by running “man fallocate”. To increase your swap memory, run the following command (and change the number of GB to your preference):
sudo fallocate -l 50GB /swapfile
Step Four: Re-Enable Your Swapfile
The -l flag stands for ‘length’ which essentially adjusts how much swap you’ve got. Next, you’ll need to reactivate your swap file by running
sudo swapon /swapfile
Step Five: Confirm Changes Were Applied
That should give your as many GB of swap as you need! You can double check your swap memory by running the Ubuntu System monitor by running:
gnome-system-monitor
and click the Resources tab at the top. You should see your swap memory reflect (not exactly, but pretty close) the amount of swap that you set using the fallocate command.
Now you should be able to render huge scenes in Blender without buying more RAM! Woot!
Just a disclaimer: This is more of a note for myself so I can go back and visit this later. If you spot anything wrong or catch some mistakes, feel free to let me know! Thanks.