Showing posts with label cache. Show all posts
Showing posts with label cache. Show all posts

Sunday, 24 January 2021

How to clear cache on Linux

In this article, we will guide you how to clear the memory cache on Linux system by clearing PageCache, dentries, and inodes from the command line.

In linux system basically we have a three different type of caches that need to be clear from linux system.

PageCache is cached files. Files that were recently accessed are stored here so they will not need to be queried from the hard disk again, unless that file changes or the cache is cleared to make room for other data

Dentry, inode cache is directory and file attributes. This information goes hand in hand with PageCache, although it doesn't contain the actual contents of any files.

Please find the below commands to clear the cache from linux device

To clear PageCache only, use this command:-

[root@localhost:~]#sysctl vm.drop_caches=1

To clear dentries and inodes, use this command:-

[root@localhost:~]#sysctl vm.drop_caches=2

To clear PageCache, plus dentries and inodes, use this command:-

[root@localhost:~]#sysctl vm.drop_caches=3

Please use free command or top to check your system's RAM usage and verify that the cache has been cleared.

Also you can use the following commands to accomplish the same thing as the respective systemctl commands:

Clear PageCache:-

[root@localhost:~]# echo 1 > /proc/sys/vm/drop_caches 

Clear dentries and inodes:-

[root@localhost:~]# echo 2 > /proc/sys/vm/drop_caches 

Clear PageCache, dentries and inodes:-

[root@localhost:~]# echo 3 > /proc/sys/vm/drop_caches

Using above commands you can clear the cache from linux system. In case you have any query please comment on this post. Thanks!!

Tuesday, 16 January 2018

How to Flush Memory Cache and Buffer Cache on Linux Server

When you run the "free -m" command and get the below output, then you observe free memory section will be low value but comparatively buffers+cache value would be higher.

Now this is not a bad thing actually since your OS has reserved this memory to speed up your most used process by keeping them in the cache. But in case any new process is executed and your system is low on memory then these cache would be automatically released to make space for memory reservation of new processes.

[root@localhost]# free -m
             total       used       free     shared    buffers     cached
Mem:          2345       1234        1145          0         24        400
-/+ buffers/cache:        664        345
Swap:         4032          0       4032

if you want to clear or free cache/buffer memory then you need to run the below command.

[root@localhost]# echo 3 > /proc/sys/vm/drop_caches

These are the different values which you can use with the above command

echo 1 is clearing only page cache

[root@localhost]# echo 1 > /proc/sys/vm/drop_caches

echo 2 is to clear free dentries and inodes

[root@localhost]# echo 2 > /proc/sys/vm/drop_caches

echo 3 is clearing page cache, dentries and inodes

[root@localhost]# echo 3 > /proc/sys/vm/drop_caches

Thursday, 18 May 2017

How to limit ZFS arc cache size on Solaris server

If you are working on Solaris operating system then you normally facing the ZFS cache size issue while running multiple database on Solaris local zones.

As per oracle suggested if your physical Solaris server have 64 GB physical RAM then ZFS cache arc minimum size should be 2 GB, and if physical server have 128 GB RAM then ZFS arc cache size should be 4 GB. Minimum you can set the ZFS arc cache size to 512MB only.

In this post, I will show you how to limit the ZFS arc cache size on Solaris server operating system.

➤ Let's suppose your Solaris server have 128 GB physical RAM, in this case you need to set the ZFS arc cache size to 4 GB minimum.

Before doing that you must check the current cache size which are running on the server

!-[solaris]# kstat zfs:0:arcstats:size | grep size | awk '{printf "%2dMB\n",  $2/1024/1024+0.5}'
1024MB

If you see the above command output, you can see the current running cache arc size is around 1 GB.

➤ If you want to check current "zfs_arc_max" & "zfs_arc_min" cache size, then please run the below command to check this.

!-[solaris]# kstat -p zfs:0:arcstats | head -4
zfs:0:arcstats:buf_size  55652720
zfs:0:arcstats:c             1073741824
zfs:0:arcstats:c_max    1073741824
zfs:0:arcstats:c_min     268435456

If you see the current above command output the "zfs_arc_max" cache size is 1 GB approx and  zfs_zrc_min size is approx 256 MB.

➤ As in my above post, you can see, as per Oracle, the cache size should be minimum 4 GB if physical RAM of the server 128 GB. So in this step , we will change the parameter.

To set the new ZFS ARC parameter, you need to go "/etc/system" file where old cache parameter was written.

!-[solaris]# vi /etc/system

Please change the parameter according to 128 GB physical RAM, so in our case zfs_arc_max would be 6 GB and zfs_arc_min would be 4 GB.

set zfs:zfs_arc_max = 6442450944
set zfs:zfs_arc_min = 4294967296

You can set the above parameter in /etc/system file. The ZFS cache size max would be 8 GB but on my machine I used it to 6 GB only.

➤ Once you set the above step ZFS ARC parameter in the system file, you need to take a reboot of Solaris server to effect these new size permanently. 

Once the server is up , you can run the below command to check the new ZFS cache size.

!-[solaris]# kstat zfs:0:arcstats:size | grep size | awk '{printf "%2dMB\n",  $2/1024/1024+0.5}'
6144MB

If you see the above output, you can see the ZFS cache max size vary to 6 GB.

➤ You can  also use the below command to check the max. cache size on global zone.

!-[solaris]# kstat zfs::arcstats:size
module: zfs                              instance: 0
name:    arcstats                       class:    misc
              size                             6445232256
You can see the above command output, its clearly show you the new current ZFS arc cache size for 128 GB physical Sun Solaris server.

Please post the comment on this blog, if you have any query related to this topic.