How to check Raspberry Pi RAM size and usage

A Raspberry Pi computer has a fixed amount of RAM built into the PC board. Since Raspberry Pi’s are micro sized, single board computers, the amount of memory is not upgradeable or expandable. Instead, you would need to purchase a more robust Raspberry Pi model or opt for one of the Pi’s that come with more RAM. Different Raspberry Pi models have various amounts of RAM that come installed. Some Raspberry Pi models can have varying amounts of RAM, along with different price points.

In this tutorial, we will cover the step by step instructions to check the RAM size for a Raspberry Pi. Then, we will see how to check the current amount of RAM usage with various tools.

In this tutorial you will learn:

  • How to check Raspberry Pi RAM size
  • How to check current RAM usage of Raspberry Pi
How to check Raspberry Pi RAM size and usage
How to check Raspberry Pi RAM size and usage
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Raspberry Pi
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to check Raspberry Pi RAM size

Since the Raspberry Pi runs a Linux operating system, we can determine the amount of installed RAM the same way we would on any other Linux system.

Check out some of the methods below to see various Linux commands that reveal the total amount of memory in a Raspberry Pi computer.

  1. The free command will give us information about current RAM usage, and break down how it is being utilized across our system. But it also gives us a clear indicator of exactly how much memory we have installed in our system. For best results, we recommend using the -g, -h, and -t options. This will tell free to display RAM amounts in Gigabytes, make the amounts human readable, and give us the totals, respectively.
    $ free -ght
    The first line shows our total installed memory
    The first line shows our total installed memory

    You can ignore the swap memory here since that is not physically installed RAM. The line you want to pay attention to is the very first one. In our example, we have 3.7 GiB (gibibytes), or 4 GB (gigabytes) of RAM installed.

  2. The next method is not actually a command, but a file. The meminfo file contains a lot of information about the RAM installed in our system, and is what many other commands query in order to display their data. You can just use cat or less to view the file:
    $ less /proc/meminfo

    The very first line displays what you need to see. But you may also be interested in the plethora of other information displayed by this file.

    Output from the /proc/meminfo file on Raspberry Pi
    Output from the /proc/meminfo file on Raspberry Pi
  3. The lshw command can detect the number of RAM slots used, speed, and size. You must execute this command with root permissions.

    $ sudo lshw -C memory -short

How to check current RAM usage on Raspberry Pi

Now we know how much RAM, total, is installed on our Raspberry Pi. But the next thing you will be wondering is how that memory is being utilized by your system. In other words, how much RAM is available or being used, and what programs or applications are currently using it? There are a few tools to determine this on the Raspberry Pi.

free command

We have already covered the free command in the section above, since it is a handy tool to see the total amount of RAM installed on a Raspberry Pi. But we can also use the free command to monitor RAM usage. When running the free command, it shows the current RAM utilization at that moment in time. But free also has some options for running continuously, in case you need to keep an eye on the usage for a while.

This is handy if you want to see how memory is impacted while performing certain tasks on your Raspberry Pi, such as opening a resource intensive program.

The -s (seconds) switch allows free to run continuously, issuing new output every specified number of seconds. For example, to run the free command every 3 seconds:

$ free -s 3

To stop free from running, just press Ctrl + C.

If you only want free to run a certain number of times, you can use the -c (count option). For example, this command would run free 3 times, before exiting the program:

$ free -c 3

With no -s option, the count option issues new output every second. But feel free to combine both switches to get the exact behavior you want. For example, to make free human readable and output memory usage every 5 seconds, 20 times:

$ free -h -s 5 -c 20

top command

Although the free command does a great job of showing us the overall RAM utilization on a Raspberry Pi, it does not tell us which tasks are consuming the memory. That is where the top command excels, displaying the memory utilization for every process on the system.

$ top

Pay attention to the %MEM column in your terminal:

Looking at current RAM usage of Raspberry Pi with top command
Looking at current RAM usage of Raspberry Pi with top command

To sort the programs in top by memory usage, press Shift + m while running top. This will allow you to see which processes are hogging the most memory at a quick glance, and you can continually monitor their usage. Just press q to exit top.

htop command

How about a program that combines the best of both worlds? The htop utility can show us overall RAM utilization in a clear way, continually update the statistics, as well as show us how much memory each process is using on your Raspberry Pi.

In case the program is not already installed on your Raspberry Pi, you can execute the following command to install it:

$ sudo apt install htop

Once it is installed, just type htop to run the program:

$ htop

Looking at current RAM usage of Raspberry Pi with htop command
Looking at current RAM usage of Raspberry Pi with htop command

RAM utilization across the whole Raspberry Pi is displayed at the top of the screen. To sort processes by memory usage, press F6 and then select %MEM using your keyboard’s arrow keys. Exit htop at any time by pressing q.

Closing Thoughts

In this tutorial, we saw how to check the total size of RAM installed in a Raspberry Pi. We also learned how to determine the current RAM usage, both by total and by sorting which programs are using the most memory. Although we can’t expand the amount of installed RAM in our Raspberry Pi, we can use the tools in this tutorial to manage it effectively.

Comments and Discussions
Linux Forum