Clear Cache, Buffer, And Swap Space

Many Windows users will want to clear cache, buffer, and swap space. It’s a holdover from their Windows days, and it’s possible to do those things with Linux. This article will explain how to clear your RAM cache, buffer, and swap space.

One of the first questions we should be asking is, “Will this help?” The answer is, like many things, “Well, it depends…” It depends on a number of variables, like how much RAM you have, and how aggressively the kernel is paging, or what your swap preferences are. For example, quite a few people have decided to forgo swap entirely. Cleaning swap space is not going to help them out one bit.

The second question should be, “What exactly are we cleaning, anyhow?” The answer to that is a bit clearer, thankfully. The things we’ll be dealing with are:

  1. PageCache/Page Cache; The Linux kernel stores data in unused sections of memory in case it needs it again. Since kernel 2.2, Buffer Cache and Page Cache have been combined and there’s just PageCache.
  2. Dentries; They’re “the in-memory representation of a directory entry” and include things like meta data.
  3. Inodes; Meta data about all the files on your mounted file systems.

Those things build up in RAM and they can be cleaned out. The Linux kernel is really good at managing these things and unused RAM is wasted RAM (within reasonable limitations), but they can be cleaned out and this article explains how.

Clear Cache, Buffer, And Swap Space:

This article requires an open terminal. To open one, you can just use your keyboard – press CTRL + ALT + T and your default terminal should open right up!

I took the time to explain what you’ll be cleaning in the article’s opening. That’ll make this section easier!

To clear PageCache by itself:

Or you can clear Dentries and Inodes:

Or even clear PageCache, Dentries, and Inodes at once:

NOTE: These work as advertised. Before you run one of these commands, run free -m before and after running the command. By doing that, you can see what the results are and what the results will probably look like in the future.

Frankly, I’d only see this as a very valuable tool if you have little RAM, or want to free up some resources before opening something that is resource-intensive. Other than that, just let Linux do its job – managing cache, memory, and other resources.

But, if you’re a Windows user and want the comfort of some familiarity, this won’t harm anything and could provide the very slightest of benefit. You could even alias it to an easier-to-type command and run it as often as you want. It’s your computer, you do what you want with it!

Closure:

There it is, another article! We’re rapidly approaching the 6 month mark and so far things have gone well. This time, you get an article letting you know how to clear cache, buffer, and swap. Who knows what the next article will be?

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.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.