A Couple Of Ways To Monitor Swap Usage

Today’s article will be nice and easy, as we cover just a couple of ways to monitor swap usage. There are several ways to monitor swap usage, so we’ll just cover a couple of them. One of ’em is bound to work.

So, this only applies to those people who use swap. If you use the search feature, you’ll see that I’ve addressed this before and that I tend to use swap – because it’s more than just a place the kernel sticks stuff when you’ve run out of RAM.

swap is still used with plenty of RAM
See? The system happily uses swap with plenty of free rams.

As you can see, on a system with plenty of RAM – and plenty of free RAM – the system still uses swap. I figure that the kernel is smarter than I am. You do you, but I will continue using swap.

But, enough about that. If you don’t use swap, just accept that this article isn’t meant for you and move along. Tomorrow’s article might just have something useful for you. You never know!

So then, I will assume readers know enough about what swap is and will have made their own choices. This article is for those who want to monitor swap usage.

Let’s Monitor Swap Usage:

You guessed it. You’re going to need an open terminal. So, open your favorite terminal emulator. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, you can try the following command:

(You can just use ‘free‘ but the -m flag makes it easier to read. You can also use ‘free -h‘ if you prefer that output.)

That command should be fairly universal. You can also use the following command if you’d prefer. It’s just:

That command is pretty handy and pretty much is the same as you’d get if you just run’cat /proc/swaps‘ which is, I suppose, yet another way for you to monitor swap usage. Think of it as a bonus way to check swap usage. After all, you can’t have too many ways and one of ’em is bound to stick with you if you use it often enough.

Closure:

And there you have it. You have another article. This time, we’ve discussed how to monitor swap usage (in the terminal, of course). It’s a handy tool for those who do use swap (be it partition or swapfile). If you don’t use swap, you probably won’t get much use from this article. Maybe tomorrow will be more interesting for you?

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Let’s Have A Look At The free Command

If the title wasn’t enough, today’s article has us taking a look at the free command. Once again, this will be a nice and easy article. I wanted to write a witty title, but Google doesn’t like witty titles for stuff like this and Google has been mad at me for a couple of months! Either way, it’s a good time for an easy article.

If  you’ve somehow never used the free command, you’re in luck! That’s what this article is going to be about! It should be relatively short, as there’s really only a few ways you’ll want to use the command.

What is the free command? Well, it’s an application that you run in the terminal (like oh so many of my articles) and it gives you some needed information about memory usage. It’s not fine-grained information, it’s about total usage. 

You can get this information all sorts of ways. Both top and htop will happily spit this information out. There are any number of GUI ways to get this information, such as your task and process manager may have a tab to tell you about memory usage. 

Us? No, we’ll be using the free command. The man page happily describes the free command as:

free – Display amount of free and used memory in the system

See? It’s another one of those terminal applications that does exactly what it says it’s going to do! Imagine that!

The Free Command:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

You can just run the command with nothing else:

That’s the same as you’d get if you ran free -w, by the way.

You can pick the display units as flags. Just look into man free to learn how to do that, but the easiest output for most people to read will be to display the units in megabytes or in ‘human readable’ form. You do those with:

Or the human-readable format:

Or if you prefer base ten:

Next, as you can see there’s a swap and regular memory section. If you have swap enabled, you can get some small benefit from seeing the total memory used. To do that, try this:

Finally, you can run the command periodically and get a running output so that you can monitor memory usage over time. That one’s pretty simple. The -s means seconds, so the following will refresh every ten seconds:

There’s more that can be done with the free command, so be sure to run man free in the terminal. However, those are the most common ways I use the command, so it’s likely to be fairly similar usage needs for you.

Closure:

There you have it, we have an article about the free command. It’s a good way to monitor memory usage, unless you need something more fine grained. If you want, there are are tools for that – including top and htop. But, those are fine article ideas for another time.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Check Memory Usage With ‘free’ In Linux

In today’s article, we’ll chec memory usage with the free command. We’ve touched on the ‘free’ command before, but this is a whole article about the free command. This should be a pretty quick and easy article, as it’s not a complex command.

There have been a few other articles about RAM.

How To: Find The RAM Total In The Terminal
Check Your Memory In The Terminal: Part II
Let’s Determine The Number of RAM Slots Without Opening The Case

And, in the discussions of those articles, we often refer to free -m as our go-to tool for quickly checking memory usage. It’s a handy tool used by most, and it’s a good tool to have in your toolbox. On top of that, it does a bit more than just check memory usage.

The free command has been around forever and describes itself like this:

Display amount of free and used memory in the system

Which is exactly what it does. It’s a pretty useful command if you want to see how much RAM you’re using, how much is free, how much is reserved for buffers, and even more if you’re interested in your swap stats.

So, folks are generally already familiar with the free command, but there are indeed more options and it’s worth an article to explain a few of those choices. Like always, you can also run man free to get a bunch of information that may not be included in this fairly brief article.

Check Memory Usage:

Yeah, this is yet another article that insists on the terminal. That’s not a bad thing, if you check the byline. The goal here at Linux-Tips is to get you more comfortable with Linux – and that includes getting comfortable in the terminal. So, open one up by pressing CTRL + ALT + T on your keyboard, and your default terminal should pop right up.

With that done, let’s go ahead and try the command that everyone uses:

The output from that will look a little something like this:

output from free -m
Those columns should be reasonably easy to understand. You can figure it out, I’m sure of it!

You can see by the column titles what the columns mean. Like I said, it’s relatively easy to understand – which is why it makes a pretty great tool. There’s actually a pretty good description of those terms, if you don’t already know them, in the man page.

But, you can use it in other ways. See, the -m stands for megabytes (obviously). Well, you can use other flags, like -b, -k, and -g. That’s bytes, kilobytes, and gigabytes – where the -m is megabytes as previously mentioned.

If you want a nice human-readable format, you can try this:

The output of that may vary the units but it will also show you which units are in use. It’s a pretty handy way to use the free command to check memory usage in Linux.

Sure, there’s a wide format and you can even use units as large as pebibytes. I don’t actually have anything where that’d make sense, but it’s an option if you happen to have such a system. (If you have access to a system with pebibytes of RAM, call me!)

But, did you know that you can run the command over and over again with just a single command? To do that, you use the -s flag followed by the number of seconds you want it to wait before refreshing. So, if you want it to run every 10 seconds, the command would look like this:

You can combine that with a count – like how many times you want it to run. So, something like this:

That will run the free command (you could add other modifiers) every five seconds and will do so three times in a row.

There are other options, but those are the most common. You can have it output the low and high numbers (when run over a period of time), display column totals, and even opt for a wider display. Personally, I don’t really find those options all that interesting and don’t bother with them, but they’re a man page away from being a part of your toolbox.

Closure:

And there you have it, an article teaching you how to check memory usage with the free command. The free tool is a pretty handy tool and one everyone should be familiar with. If your system is slowing down, it’s nice to know things like how much RAM is being used. If you work in application development, it’s nice to know how much more RAM your application adds to the system. There are any number of reasons why you’d want this information.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.