How To Clean Swap Memory In Linux



How to Clear RAM Memory Cache, Buffer and Swap Space on Linux

  1. How To Clean Swap Memory In Linux Windows 10
  2. Linux Swap File
  3. Linux Swap Memory Full
  4. How To Clean Swap Memory In Linux Windows 10
  5. How Do I Clear Swap Memory In Linux
  6. Linux Swap Memory Usage

We’ll use the mkswap command to make our file swap-consumable for the Linux kernel. Again as root, carefully type: mkswap /extraswap To turn on our swap file, we run swapon /extraswap. Now when we run swapon -s we should see our existing swap partition and our new swapfile. Also, the free command should show an increase in total swap space.

  • How to clear Swap Memory in Linux / CentOS / RHEL ubuntu, debian, kali linux. Ubuntu Quick Tip: Clean Ubuntu Using The Terminal - Duration: 3:16. Charlie Henson 14,861 views.
  • Feb 25, 2020 To clear the swap memory on your system, you simply need to cycle off the swap. This moves all data from swap memory back into RAM. It also means that you need to be sure you have the RAM to support this operation. An easy way to do this is to run 'free -m' to see what is being used in swap and in RAM.

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

1. Clear PageCache only.

How To Clean Swap Memory In Linux Windows 10

Linux

2. Clear dentries and inodes.

3. Clear PageCache, dentries and inodes.

Explanation of above command.

How To Clean Swap Memory In Linux

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.

Linux Swap 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 and inodes.

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.

How To Clean Swap Memory In Linux

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

Linux swap memory usageMemory

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 Swap Memory Full

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

article source: http://www.tecmint.com/clear-ram-memory-cache-buffer-and-swap-space-on-linux/

How To Clean Swap Memory In Linux Windows 10

2

How Do I Clear Swap Memory In Linux

Tell us how can we improve this post?

Linux Swap Memory Usage

Related Knowledge Base Posts -





Comments are closed.