Creating a Swapfile in Ubuntu for the NVIDIA Jetson TK1

The NVIDIA Jetson TK1 has a relatively small main memory for running memory hungry applications like Chromium and compiling large programs. By creating a Swapfile, the Jetson will seem much snappier when a bunch of memory is being consumed. Here’s the video on how to create a Swapfile:

You can read more about Swap Files here: Ubuntu SwapFaq.

I’ve created a Gist which is a Shell file that will create the swapfile for you. First, navigate to the directory where you want to place the swapfile, and then run the script.

The Gist is here: createSwapfile.sh gist

Make sure you set the permission for createSwapFile.sh (Properties->Permissions->Execute: Allow executing file a programON) to execute. Then in a Terminal window run:

sudo ./createSwapFile.sh

This should create a file named swapfile that is 4GB. 4GB is a good size for the 2GB of main memory on the Jetson. You should place the swapfile on a fast device, such as a SATA SSD if available. The main benefit that you will notice is that the system will run much more smoothly when there are a bunch of windows open, especially web browsers.

If you are compiling really big programs, like ROS (Robot Operating System) you’ll need swap memory just to get the programs to compile. The stock 2GB is not enough memory for compiling the beast.

In order to have the swapfile available immediately after booting, you will have to edit the file /etc/fstab. You can edit the file like this:

$ sudo gedit /etc/fstab

Here’s a sample line like you would add:

/media/ubuntu/JetsonSSD/swapfile none swap sw 0 0

where first entry is the full path to the swapfile. Make sure that you save the file after editing. In this example, swapfile is on the root directory of the volume JetsonSSD. You must make sure that the volume is mounted before setting the swapfile. Look here for some hints on how to do that if you’re using an external drive.

I’ve found that having an SSD and a Swapfile makes the entire development experience much more pleasant and is highly recommended.

2 Comments

  1. Hi. I have a question for you. Does increasing the swap memory and installing a ssd hard drive increase the performance in terms of data logging to disk?

    I’m trying to log data at 60 frames per second from a camera (640×480). But, it doesn’t go more than 20-25 frames per second even though the camera supports it and the program supports it.

  2. Hi Rahul,
    Although it’s hard to tell for any given application without actually testing it out, the installation of the SSD will definitely make your disk access and writing much faster. For a data acquisition program, the swap memory probably won’t get you much more performance, since the machine is actually writing to disk when it’s swapping memory in and out. Swapping memory introduces a little bit of a performance hit as the pages get swapped in and out of RAM.

    With that said, the first thing to test in your application is to see if you are actually getting the requested frame rates. Request a few seconds of video saving it to memory, then save it to a file. Uncompressed, one second of 640×480 60 fps stream is about 74MB. Examine the file to make sure that it is actually saving 60 fps.

    SATA is currently level II on the Jetson, 2.5 Gbs, which is about 400-500 MBs give or take, so you can certainly fit the stream through the pipe. The SSD is build for Sata III, so it shouldn’t have any trouble keeping up with the writing.

    However, remember that you may have to thread the program properly to write to disk while you are capturing, so that you use more than one CPU core.

    Hope this helps

Leave a Reply

Your email address will not be published.


*