Optimizing Your Raspberry Pi: How to Check RAM Usage

1. Open the Terminal window on your Raspberry Pi.

2. Type in the command “free -m” and press enter.

3. This will display the amount of RAM that is currently being used, as well as the total amount of RAM available.

4. To get a more detailed view of RAM usage, type in the command “top” and press enter.

5. This will display a list of all the processes that are currently running on your Raspberry Pi, as well as the amount of RAM each process is using.

6. To exit the top command, press “q”.

One of the main limitations of Raspberry Pi boards is the amount of memory available. Recent models have options with up to 8 GB of RAM, but this isn’t the case for all models (most are limited to 1 GB or less). That’s why it’s important to keep an eye on your Raspberry Pi’s RAM usage.

With a desktop interface, the easiest way to check the current RAM usage is to use the task manager. In a terminal, the command line “free” can give you an overview of the memory status.

In this article, I will share 5 ways to check the RAM usage on your Raspberry Pi and explain how to analyze the results. I will then answer a few common questions about memory usage on Raspberry Pi.

If you’re looking to quickly progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.

5 Ways to Check RAM Usage on Raspberry Pi

Task manager

On Raspberry Pi OS with Desktop, a task manager is available under Accessories in the main menu. It’s the easiest way to check the current RAM usage on the Raspberry Pi.

Once open, you get a direct overview of the CPU and RAM usage on your Raspberry Pi.

The RAM usage is shown on the right, with the currently used amount of memory and how much RAM is available.

In this example, I’m using a Raspberry Pi 4 with 4 GB of RAM. A total of 3793 MB is detected as available on the system, and 441 MB is currently used. So, around 10% of RAM is being used, and I have plenty of margins.

Consider that any computer will start to slow down when the RAM used is over 80%, so try to keep it below this threshold. Above that, Linux will start using the swap partition on your disk, which is generally way slower than the RAM (more details about the swap here).

You can sort the tasks list by clicking on a column title. “RSS” stands for “Resident Set Size”, which is an indication of how much RAM is allocated to that process, so basically how much RAM the process uses.

RSS is not accurate. As you can see in my screenshot, the sum of the RSS values is greater than the total used RAM. That’s because it analyzes each process separately, even if they use the same libraries and it’s loaded in memory only once.

Anyway, in this tool, a few options are available under the “View” submenu. You can show or hide the tasks from the root and other users. These are disabled by default, but it might be essential to enable them to get a real overview of the RAM usage.

You can also choose to show the main command or the full command line with all the options to get a better idea of which application is using most of your RAM.

Command line: free

On Raspberry Pi OS Lite, there is no graphical tool. If you want to get the same information in command lines, the corresponding command is “free”. “Free” gives an overview of the memory and swap usage of a Linux system, detailing it in several columns: total, used, free, etc.

It looks like that by default:

There is one line for memory use and another line for swap use.

Then you have a bunch of columns, that aren’t necessarily easy to understand, so here are some definitions you need to know:

  • Total: how much memory is available.
  • Used: how much memory is used (total – free – buffers – cache).
  • Free: unused memory.
  • Shared: memory size used by several processes simultaneously.
  • Buffers/cache: both are used by your system to improve performance.
    Buffers are temporary memory used while transferring data from one storage to another.
    The cache is used to keep data frequently used by the system.
  • Available: Rough estimate of how much memory you have available for new tasks.

In general, the only thing you’ll look at are the “used” and “available” columns.

Also, note that “free” is the main command, but many options are available.
You can use the inline manual to get more details:
man free

For example, free shows the amount of memory in octets by default, but you can switch to megabytes with:
free -m
Or use -h to show all fields in the best format automatically:
free -h

This way, it’s a bit easier to read. As you can see, I get approximately the same results as in the task manager, with 10 to 15% of memory used on my Raspberry Pi.

Note: The “free” command won’t tell you the processes using the most memory. To get an idea, you can use the “ps” command, with these options:
ps ax -o comm,%mem,user,pid --sort=-%mem | head -10
It will give you a list like this:

Which is similar to what we get with the task manager on the desktop interface.

Are you a bit lost in the Linux command line? Check this article first for the most important commands to remember, and a free downloadable cheat sheet so you can have the commands at your fingertips.

A better command: htop

“Free” is the original command to check the memory on Linux but is not really user-friendly. “Htop” is a better way to keep an eye on RAM usage, with colors, graphics and a list of the processes taking the most resources.

I use this command all the time on Linux servers and Raspberry Pi. Even if you don’t have a graphic interface, it’s easy to read and understand. The values are refreshed automatically, and you can sort the table in a few clicks.

You may already know “top”, “htop” is just an improved version with colors and a better display overall.

It’s installed by default on Raspberry Pi OS, but if needed, you can install it with APT on any Debian-based distribution:
sudo apt update
sudo apt install htop

You can then start “htop” with:
htop

In the header section, you have an overview of the system usage. There is one line for each CPU core (my Raspberry Pi 4 has 4 cores, so there are 4 lines), and the current usage for each one. Then you have one line (“Mem”) with the current memory use and the same thing for the swap (“Swp”).

It looks like:

On the right, you get other useful information, like the number of tasks running, the load average and the uptime of the computer (how long the Raspberry Pi has been on).

Note: The load average is an interesting metric on Linux. There are three values (one-minute, five-minute and fifteen-minute averages). The higher the values are, the more overloaded the system is. Comparing them can give you an indication if the load is increasing or decreasing.
A simplified interpretation is that your system is running properly if the average values stay under the number of cores available.

The section below the header in “htop” gives you a list of the processes running on your system.
You get a table, refreshed in real-time with all the information:

You can click on a column (the “MEM%” for example) to sort the processes by memory usage. As with the desktop interface, we can see in this example that Chromium is the app taking most of my RAM.

I often use this command, even if I have a desktop environment available. I find it easy to read, with all the details I need to analyze the current resources usage or monitor a specific app or service.

Add a widget in the interface

If you are using Raspberry Pi OS with a desktop environment, it’s generally possible to customize the appearance, and especially add widgets in the top bar.

An applet is available to show the CPU and memory usage directly in the top panel.
Here is how to add this information to your system:

  • Right-click on the top bar of your screen.
  • Choose “Add / Remove Panel Items…”
  • In the pop-up window, click on the “Add” button, and then select “Resource monitors”:
  • It will add a new icon in the top-right corner.
    Right click on it to configure what you want to display in it:
  • You can check the “Display RAM usage” box to get it graphed here.
    It’s red by default, but you can change the color if you want (using hexadecimal colors).
  • Also, if you put your mouse over the icon, you’ll get the details:

It’s maybe not the best option to get details, but it can be useful if you want to quickly know what is going on when your system slows down. If an app is not responding anymore, you can directly check if the memory is fully used or if there is another issue.

Tracking RAM usage over time

All these solutions are great to get a quick overview of the RAM usage, and a short history of the RAM used in the last few minutes. But it won’t help if you need to see how much RAM your Raspberry Pi is using during the day or a more extended history of weeks or months.

The best way to monitor RAM usage for longer periods of time is to install a service that will keep track of the resources used over time.
Some will just show a graph with the history, others can be configured to send alerts when too much memory is used. It really depends on what you need.

For example, Cacti is a nice tool to keep a history of the usage of your server for years. It shows a graph for each monitored resource, and you can zoom in on a specific time of the day, or zoom out to get an overview of the evolution over a long period of time.

A graph example on Cacti

If you are interested in notifications, Nagios is probably a better solution.
I wrote a step-by-step guide to install Nagios on Raspberry Pi on this website if you want to give it a try.

These are pretty heavy solutions, that you’ll only use on servers or for specific needs when you need to understand the RAM usage while you are not available to check it. The previous options are probably enough for most people.

Want to chat with other Raspberry Pi enthusiasts? Join the community, share your current projects and ask for help directly in the forums.

Q&A: RAM Usage on Raspberry Pi

How much RAM do I need on my Raspberry Pi?

Raspberry Pi OS is built to run fine with only 1 GB of RAM. The more RAM you have, the more applications can run simultaneously. And some projects may also require more memory overall (virtualization, high-traffic servers, etc.).

For a long time, Raspberry Pi models were limited to 1 GB of memory or less. So, we wouldn’t really ask this question. But we now have more options, with Raspberry Pi 4 available with 2, 4 or 8 GB.

Don’t know which one to choose for your projects? Read this article: Raspberry Pi 4: Do you really need 8 GB? (vs 4 GB).

What is Swap on Raspberry Pi?

On Raspberry Pi and all Linux systems, the swap space is a buffer used when the system needs more memory, but the RAM is already full. The kernel will move some memory pages to a swap partition, located on the SD card.

On Raspberry Pi OS, the default swap partition is created with 100 MB of free space, which is pretty small. But SD cards are really slow compared to the memory, so having more swaps won’t really save you. Your system will become slower as soon as RPI OS needs to use the swap partition for running applications.

I wrote an article on this website explaining in more detail what swap is on Linux systems. You should read it to better understand this important concept.

How to find which process uses the most RAM?

On any desktop environment, the task manager shows a list of the processes taking the most resources. From a terminal, the command “htop” is the easiest way to get something similar. Processes can be sorted by RAM usage to quickly identify the one taking the most RAM.

If you are looking for additional help on how to optimize your Raspberry Pi, here are a few articles on this website you might be interested in:

Additional Resources

Not sure where to start?
Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.
Watch the Raspberry Pi Bootcamp course now.

Master your Raspberry Pi in 30 days
Don’t want the basic stuff only? If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.
Download the e-book.

VIP Community
If you just want to hang out with me and other Raspberry Pi fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.

Need help building something with Python?
Create, understand, and improve any Python script for your Raspberry Pi.
Learn the essentials step-by-step without losing time understanding useless concepts.
Get the e-book now.

You can also find all my recommendations for tools and hardware on this page.

Optimizing Your Raspberry Pi: How to Check RAM Usage

If you’re using a Raspberry Pi, you know that it’s a powerful and versatile device. But like any computer, it can slow down over time. One of the best ways to keep your Raspberry Pi running smoothly is to monitor its RAM usage. Here’s how to check RAM usage on your Raspberry Pi.

Step 1: Open the Terminal

The first step is to open the terminal. You can do this by clicking the Raspberry icon in the top left corner of the screen and selecting “Terminal” from the drop-down menu.

Step 2: Enter the Command

Once the terminal is open, enter the following command: free -m. This will display the amount of RAM that is currently being used by the Raspberry Pi.

Step 3: Interpret the Results

The output of the command will show the total amount of RAM, the amount of RAM that is being used, and the amount of RAM that is free. If the amount of RAM that is being used is close to the total amount of RAM, then it’s time to optimize your Raspberry Pi.

Step 4: Optimize Your Raspberry Pi

There are several ways to optimize your Raspberry Pi. You can disable unnecessary services, uninstall unused programs, and reduce the number of programs running in the background. You can also upgrade your Raspberry Pi’s RAM if necessary.

Conclusion

Monitoring your Raspberry Pi’s RAM usage is an important part of keeping it running smoothly. By following the steps outlined above, you can easily check your Raspberry Pi’s RAM usage and take the necessary steps to optimize it.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?