Clear Cache Ram Ubuntu



  • Clean and dirty caches. When you run something on a Linux system or server, Kernel will try to cache the response for a period of time so that the next time the same request is made, instead of running a complex lookup in disk/process, it can just fetch that info directly from Memory/RAM and send back a response.
  • How do you clear the apt cache? You simply use this apt-get command option: sudo apt-get clean. But there is more to cleaning apt cache than just running the above command. In this tutorial, I’ll explain what is apt cache, why is it used, why you would want to clean it and what other things you should know about purging apt cache.
Cache

Swap is a virtual memory concept that allows your system to use a portion of your hard drive as the physical memory (RAM). Your system swaps the inactive pages in memory in RAM to this swap space on the hard disk. This way, your system has more free RAM available for other programs.

How To CLEAR RAM MEMORY CACHE, BUFFER AND SWAP SPACE ON UBUNTU 20.04,12.04,17.04,18.04 Linux,Kubuntu, Kalilinux, MintHow To CLEAR RAM MEMORY CACHE.

How to Clear RAM Memory Cache, Buffer and Swap Space on Linux Like any other operating system, GNU/Linux has implemented a memory management efficiently and even more than that. But if any process is eating away your memory and you want to clear it, Linux provides a way to flush or clear ram cache. In Windows, they have very easy process to clean up the temp files or system cache. In Ubuntu, we can clean our system cache with few commands. Clear Ubuntu Sytem Cache. Download and install a tool called Ubuntu Cleaner with the following commands.

I have shown you to check RAM in Linux and I have also discussed how to check swap usage on Linux. In this quick tip, I’ll show you how to clear swap memory in Linux.

Clear Cache Ram Ubuntu

Clear swap in Linux

But first, why would you want to clear swap at all? There could be various reasons. Some time your system will use a lot of swap even when plenty of RAM is available.

This may or may not be associated with swappiness of your system. Sometimes it happens that the RAM doesn’t swap back the pages from swap space to RAM. In such cases, you’ll have to manually clear the swap.

Attention

Before clearing the swap, check that you have enough free RAM available to take all the pages from swap. In other words, you should have more free RAM available than the current swap in use.

You can see the state of RAM and swap using the free command in Linux:

Once you are sure that the size of free RAM is bigger than the swap memory in use, you can clear the swap memory by turning it off and on again.

Pun aside, that’s the way to do it. Disable all the swap using this command:

Now turn the swap back on:

That’s it. This simple exercise will clear the swap in your Linux system. I hope you find this little tip helpful. Any questions or suggestions are always welcome.

Become a Member for FREE
Become a member to get the regular Linux newsletter (2-4 times a month) and access member-only contents.

Join the conversation.

You can write to /proc/sys/vm/drop_caches file to instruct kernel to drop clean caches, as well as reclaimable slab objects like dentries and inodes. Once dropped, their memory becomes free.

This is not recommended to clear memory cache on Linux systems, but it is safe. But clearing cache may cause performance issue with system. Since it discards cached objects from memory, it may cost a significant amount of I/O and CPU to recreate the dropped objects.

This tutorial will help you to clear memory cache on Linux/Unix system via command line.

How to Clear Cache in Linux System

There are three options available to clear cache in Linux system memory. Use one of below as per your requirements.

  • Clear PageCache, dentries and inodes in cache memory
  • Clear dentries and inodes only in cache memory
  • Clear pagecache only in cache memory

Here the sync command is used to increase the number of objects freed by the drop cache. Using this a user can claim more memory by clearing more dirty objects on the system.

How to Schedule Clear Memory Cache

If you have to clear buffer cache regularly, use the cronjob do it. Schedule the following in system crontab to automatically flush cache memory on a regular interval.

Open a terminal and execute ‘crontab -e’ command to edit crontab:

Append below entry to the file:

The above cron will execute on every hour and flushes the memory cache on your system.

How to find Cache Memory in Linux

Clear Cache Ram Ubuntu Windows 7

Use free command to find out cache memory uses by Linux system. Output of free command is like below

Ubuntu Clear Apt Cache

Output:

Here the last column is showing cached memory (12953 MB) on Linux system. The -m option is used to show output MB’s.