Select Page

Swap Memory: It’s Like Downloading More RAM

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.

Swap = 46.6 GB

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.

Check out more articles

Create a Custom API Endpoint in WordPress

Creating a custom endpoint in WordPress to check for plugin updates involves several steps. This process includes setting up a custom REST API endpoint, creating a function to handle requests to this endpoint, and ensuring that the response contains the necessary...

Deploy WordPress Updates from a Private Repository

To push code to a private repository and trigger a pending WordPress update badge, you need to follow a systematic approach involving version control, continuous integration/deployment, and the appropriate use of WordPress hooks and filters. Here’s a step-by-step...

How to Generate a Ranger Config File

ranger --copy-config=all This will copy all the default config files from /usr/local/lib so you can make edits without messing anything up. Huge shout out to https://dquinton.github.io/debian-install/config/ranger.html for explaining this and so much more. Took me a...

First Open Source Contribution

Surprise! I genuinely did not plan on making my first ever open source contribution today. In fact, I didn't plan on a lot of things happening this week at all. I recently got an awesome opportunity to work on a site that is being hosted on a platform called Pantheon,...

How to Exclude Specific Posts and Pages from WP_QUERY

For the sake of having something to work with, let's suppose we've got the following query:In this query, inside the $args array, there's a special parameter that allows you to exclude specific posts and pages from the query. This parameter is called post__not_in and...

Configure SSH For Password-less Connections

Preamble I'm slightly embarrassed to admit this, but it was a long time before I figured out how amazing this little file is and how exactly to put it to good use. The file I'm talking about is the SSH config file. By default, when you first connect to a server via...

WordPress Site Stuck in Maintenance Mode

Plugin Error Code 500 During Update While I was updating a WordPress plugin locally, something happened on my local server to trigger a 500 error code as the plugin was updating. On the frontend, I refreshed the page and was greeted with "Briefly Unavailable for...

Creating a WordPress Plugin Downloader

How it Started I was recently tasked with the challenge of creating a WordPress theme generator. The idea being, instead of writing your style.css file from scratch, you'd be able to just answer a few simple questions about how you'd like your theme set up, and those...

Fix Audio on XFCE Chromebook

The Problem After moving from GalliumOS to Xubuntu, I noticed that playing YouTube videos on both Firefox and Chromium would result in decent playback for a few minutes, but suddenly the audio would turn into a solid beeping tone while the YouTube video displayed the...

Adjust Trackpad Sensitivity XFCE

xinput set-prop "Elan Touchpad" "Synaptics Finger" 1 1 1 What are the values 1 1 1? This sets the sensitivity as close to the original ChromeOS as possible. Larger numbers will decrease sensitivity of various aspects. I never looked into which individual value...

Looking for a place to host your next project or design?

Use this link to get your first 4 months of WP Engine for free: WP Engine – Plans (With 4 months free)