Raspberry Pi

How to Increase Memory on Raspberry Pi

The low memory issue is one of the significant problems for Raspberry Pi users who use the Raspberry Pi model with 2GB or 4GB RAM. The low memory issue directly slows down the performance of the applications running on the Raspberry Pi system. The ideal way to overcome this issue is to increase the system memory, but the Raspberry Pi device doesn’t allow installing additional RAM.

If you are looking for a solution to increase memory on your Raspberry Pi system, follow this article’s guidelines to find out how you can increase memory without installing additional RAM with the device.

How To Increase Memory on Raspberry Pi

The Swap file on your system works as virtual memory, allowing users to use the swap space for your device to overcome the low memory issue. The Raspberry Pi system uses around 100MB of swap space by default and you can confirm it by executing the following command:

$ free --mega

Afterward, you can perform the following steps on the Raspberry Pi terminal to increase the system’s memory.

Step 1: Turn Off the Swap File on Raspberry Pi

First, you must turn off the swap file on your system because, without it, you won’t be able to perform the configuration. To turn off the swap file on your system, use the following command:

$ sudo dphys-swapfile swapoff

Step 2: Open Swap Configuration File

Now, you will need to open the swap configuration file on your Raspberry Pi system using the following command:

$ sudo nano /etc/dphys-swapfile

Inside the file, you will find the option “CONF_SWAPSIZE”, which is set to 100 by default, as shown in the above file.

You only must change this value to any number that should be greater than 100 but doesn’t exceed the amount of space available on your Raspberry Pi SD card. It would help if you also kept in mind that the Swap file size is MB.

Suppose we are increasing this swap size to 500MB and then saving the file using CTRL+X.

Step 3: Turn on Swap File

You should need to turn on the swap file again using the following command after editing the configuration file.

$ sudo dphys-swapfile swapon

After applying the changes, we should reboot the device using the “reboot” command. When your device turns on again, hit the following command to check the swap space.

$ free --mega

The above command confirms that the swap file is successfully increased on your system. If that size doesn’t solve your problem, you can increase it further.

Final Remarks

Although adding the swap file is beneficial in case your system is running low on memory because this boosts the performance of your Raspberry Pi system. It also increases the compilation speed of the packages. However, this process slows down the file access speed because the read and write speed of file accessing on swap files is slow compared to built-in physical memory.

In addition, doing this for a longer time may decrease the lifespan of your SD card. So, you should be careful in doing that; if you need it for some specific purpose, you are allowed to do it for a specific period. Otherwise, you can avoid this type of process.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.