Skip to main content

Emptying the buffers cache in linux


If you ever want to empty it you can use this chain of commands.

# free && sync && echo 3 > /proc/sys/vm/drop_caches && free


             total       used       free     shared    buffers     cached

Mem:       1018916     980832      38084          0      46924     355764

-/+ buffers/cache:     578144     440772

Swap:      2064376        128    2064248

             total       used       free     shared    buffers     cached

Mem:       1018916     685008     333908          0        224     108252

-/+ buffers/cache:     576532     442384

Swap:      2064376        128    2064248

You can signal the Linux Kernel to drop various aspects of cached items by changing the numeric argument to the above command.

·         To free pagecache:

·         # echo 1 > /proc/sys/vm/drop_caches

·         To free dentries and inodes:

·         # echo 2 > /proc/sys/vm/drop_caches

·         To free pagecache, dentries and inodes:

·         # echo 3 > /proc/sys/vm/drop_caches

The above are meant to be run as root. If you're trying to do them using sudo then you'll need to change the syntax slightly to something like these:

$ sudo sh -c 'echo 1 >/proc/sys/vm/drop_caches'

$ sudo sh -c 'echo 2 >/proc/sys/vm/drop_caches'

$ sudo sh -c 'echo 3 >/proc/sys/vm/drop_caches'

NOTE: There's a more esoteric version of the above command if you're into that:

$ echo "echo 1 > /proc/sys/vm/drop_caches" | sudo sh

Why the change in syntax? The /bin/echo program is running as root, because of sudo, but the shell that's redirecting echo's output to the root-only file is still running as you. Your current shell does the redirection before sudo starts.

Seeing what's in the buffers and cache

Take a look at linux-ftools if you'd like to analyze the contents of the buffers & cache. Specifically if you'd like to see what files are currently being cached.


hands-on


[root@rhel51 ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1632       1550         81          0         89        542

-/+ buffers/cache:        918        713

Swap:         4000          0       4000

[root@rhel51 ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1632       1550         81          0         89        542

-/+ buffers/cache:        917        714

Swap:         4000          0       4000

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

[root@rhel51 ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1632       1278        353          0          0        360

-/+ buffers/cache:        917        714

Swap:         4000          0       4000

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

[root@rhel51 ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1632       1142        489          0          1        422

-/+ buffers/cache:        718        913

Swap:         4000          0       4000

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

[root@rhel51 ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1632        976        655          0          0        394

-/+ buffers/cache:        580       1051

Swap:         4000          0       4000

[root@rhel51 ~]# sudo sh -c 'echo 1 >/proc/sys/vm/drop_caches'

[root@rhel51 ~]# sudo sh -c 'echo 2 >/proc/sys/vm/drop_caches'

[root@rhel51 ~]# sudo sh -c 'echo 3 >/proc/sys/vm/drop_caches'

[root@rhel51 ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1632        846        785          0          0        177

-/+ buffers/cache:        668        963

Swap:         4000          0       4000

[root@rhel51 ~]# echo "echo 1 > /proc/sys/vm/drop_caches" | sudo sh

[root@rhel51 ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1632        834        797          0          0        165

-/+ buffers/cache:        668        963

Swap:         4000          0       4000

[root@rhel51 ~]# swapoff -a

[root@rhel51 ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1632        833        798          0          0        166

-/+ buffers/cache:        666        965

Swap:            0          0          0

[root@rhel51 ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1632        834        797          0          0        166

-/+ buffers/cache:        666        965

Swap:            0          0          0

[root@rhel51 ~]# swapon -a

[root@rhel51 ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1632        836        795          0          0        166

-/+ buffers/cache:        668        963

Swap:         4000          0       4000

[root@rhel51 ~]#

Comments

Popular posts from this blog

Hard dependency with ip address Oracle RAC Cluster.

Command error out due to hard dependency with ip address [-Node1]/app/grid/oracle/product/11.2.0/grid/bin>./crsctl relocate resource RDBMS_DB -n Node2 CRS-2527: Unable to start 'RDBMS_DB' because it has a 'hard' dependency on 'sDB' CRS-2525: All instances of the resource 'sDB' are already running; relocate is not allowed because the force option was not specified CRS-4000: Command Relocate failed, or completed with errors. [-Node1]/app/grid/oracle/product/11.2.0/grid/bin>./crsctl relocate resource sDB  -n Node2 CRS-2529: Unable to act on 'DB' because that would require stopping or relocating 'LISTENER_DB', but the force option was not specified CRS-4000: Command Relocate failed, or completed with errors. [-Node1]/app/grid/oracle/product/11.2.0/grid/bin>./crsctl relocate resource LISTENER_DB  -n Node2 CRS-2527: Unable to start 'LISTENER_DB' because it has a 'hard' dependency on 'sD...

19C NID ( Rename Database)

 [oracle@localhost ~]$ nid DBNEWID: Release 19.0.0.0.0 - Production on Thu Dec 23 00:05:36 2021 Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved. Keyword     Description                    (Default) ---------------------------------------------------- TARGET      Username/Password              (NONE) DBNAME      New database name              (NONE) LOGFILE     Output Log                     (NONE) REVERT      Revert failed change           NO SETNAME     Set a new database name only   NO APPEND      Append to output log           NO HELP        Displays these messages    ...

ORA-01017/ORA-28000 with AUDIT_TRAIL

With default profile in Oracle 11g, accounts are automatically locked 1 day ( PASSWORD_LOCK_TIME ) after 10 failed login attempt ( FAILED_LOGIN_ATTEMPTS ): SQL > SET lines 200 SQL > SET pages 200 SQL > SELECT * FROM dba_profiles WHERE PROFILE = 'DEFAULT' ORDER BY resource_name; PROFILE                         RESOURCE_NAME                      RESOURCE LIMIT ------------------------------ -------------------------------- -------- ---------------------------------------- DEFAULT                         COMPOSITE_LIMIT                 ...