29-04-2021



But now, let’s look at the different techniques you can use in the terminal window to see the RAM usage on your Linux computer. The free Command. The free command gives you a table of the total, used, free, shared, buffer/cache, and available RAM on your computer. It also shows you the total amount of swap space configured, and how much is. /+ buffers/cache: 771 7056 Swap: 49. You will find difference between used and cache memory before and after clearing cache. In case of heavy memory consumption, you will set cron job to clear memory in hourly basis OR as per your convenience.

Technologists often talk about “cache” when discussing CPUs, disk drives, and computer systems. But what is it and why should you care?

A disk cache is RAM built into your hard disk. It evens out the flow of data between the relatively slow disk drive and the rest of the computer by accepting data faster than it can be written to or read from the disk. To help the cache do its job, the disk normally includes logic to analyze disk usage and pre-fetch data, that is likely to be needed soon.

As long as the cache isn’t full, the disk drive’s data transfer rate is a good deal higher than its actual read/write speed.

Don’t confuse cache with the size of the disk drive or your system RAM. Cache is a separate entity; in fact, it’s normally memory chips that are installed in the casing that houses your disk drive. Often, when you read the specifications for a disk drive, it will include the amount of on-board cache.

This built-in cache is also different from setting aside a portion of the system RAM to use as a disk buffer, even though this is occasionally referred to as “disk cache” as well.

The disk cache is important because it has a major impact on how well your system performs on>The benefit of cache only lasts until the cache is full. If the system trying to send or receive data faster than the disk can read or write it, the cache will fill up eventually and the disk’s performance will fall off significantly. But since disk activity on desktop systems is usually bursty, that is, it comes in bursts rather than as a steady stream of data, it is possible to put enough cache memory on a disk to stay ahead of the write requests most of the time.

The exact meaning of “most of the time” depends in large part on how much cache the disk has. Ideally the disk cache would be so large it would never fill up. Since RAM is relatively expensive compared to other components in a disk drive (prices vary based on the type of RAM used) it isn’t very practical.

Disks differ widely in the size of the cache. The standard today is a minimum of 2 Mb cache, although many”high-performance” commodity drives available at retail include 8 Mb of cache. A drive with 16 Mb will give significant performance improvements, but these are unusual and result in a more expensive disk drive.

Arch Linux Clear Ram Cache

All other things being equal, the disk with the most cache will give you the best performance. You’ll pay more, but your system will perform better.

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.

How to Clear Cache in Linux?

Clear cache ram linux download

Every Linux System has three options to clear cache without interrupting any processes or services.

Clear cache ram linux windows 7

1. Clear PageCache only.

Linux

2. Clear dentries and inodes.

3. Clear PageCache, dentries and inodes.

Explanation of above command.

sync will flush the file system buffer. Command Separated by “;” run sequentially. The shell wait for each command to terminate before executing the next command in the sequence. As mentioned in kernel documentation, writing to drop_cache will clean cache without killing any application/service, command echo is doing the job of writing to file.

If you have to clear the disk cache, the first command is safest in enterprise and production as“...echo 1 > ….” will clear the PageCache only. It is not recommended to use third option above“...echo 3 >” in production until you know what you are doing, as it will clear PageCache, dentries andinodes.

Windows
Is it a good idea to free Buffer and Cache in Linux that might be used by Linux Kernel?

When you are applying various settings and want to check, if it is actually implemented specially on I/O-extensive benchmark, then you may need to clear buffer cache. You can drop cache as explained above without rebooting the System i.e., no downtime required.

Linux is designed in such a way that it looks into disk cache before looking onto the disk. If it finds the resource in the cache, then the request doesn’t reach the disk. If we clean the cache, the disk cache will be less useful as the OS will look for the resource on the disk.

Moreover it will also slow the system for a few seconds while the cache is cleaned and every resource required by OS is loaded again in the disk-cache.

Now we will be creating a shell script to auto clear RAM cache daily at 2PM via a cron scheduler task. Create a shell script clearcache.sh and add the following lines.

Set execute permission on the clearcache.sh file.

Now you may call the script whenever you required to clear ram cache.

Now set a cron to clear RAM cache everyday at 2PM. Open crontab for editing.

Append the below line, save and exit to run it at 2PM daily.

For more details on how to cron a job you may like to check our article on 11 Cron Scheduling Jobs.

Is it good idea to auto clear RAM cache on production server?

No! it is not. Think of a situation when you have scheduled the script to clear ram cache everyday at 2PM. Everyday at 2PM the script is executed and it flushes your RAM cache. One day for whatsoever reason, may be more than expected users are online on your website and seeking resource from your server.

At the same time scheduled script run and clears everything in cache. Now all the user are fetching data from disk. It will result in server crash and corrupt the database. So clear ram-cache only when required,and known your foot steps, else you are a Cargo Cult System Administrator.

How to Clear Swap Space in Linux?

If you want to clear Swap space, you may like to run the below command.

Also you may add above command to a cron script above, after understanding all the associated risk.

Now we will be combining both above commands into one single command to make a proper script to clear RAM Cache and Swap Space.

Linux Clear Dns Cache

After testing both above command, we will run command “free -h” before and after running the script and will check cache.