Emptying the buffers cache

Source: Internet
Author: User

Transferred from: Http://unix.stackexchange.com/questions/87908/how-do-you-empty-the-buffers-and-cache-on-a-linux-system

Emptying the buffers cache

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

# free && sync && echo 3 > /proc/sys/vm/drop_caches && free             total       used       free     shared    buffers     cachedMem:       1018916     980832      38084          0      46924     355764-/+ buffers/cache:     578144     440772Swap:      2064376        128    2064248             total       used       free     shared    buffers     cachedMem:       1018916     685008     333908          0        224     108252-/+ buffers/cache:     576532     442384Swap:      2064376        128    2064248

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

    • 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 is meant to be run as root. If you ' re trying to do them using and you'll need to change the sudo 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 to that:

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

Why the syntax? The program /bin/echo is running as root, because sudo of, and 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 ' s in the buffers and cache

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

Fincore

With this tool you can see what files is being cached within a give directory.

fincore [options] files...  --pages=false      Do not print pages  --summarize        When comparing multiple files, print a summary report  --only-cached      Only print stats for files that are actually in cache.

For example, /var/lib/mysql/blogindex :

[email protected]:/var/lib/mysql/blogindex# fincore--pages=false--summarize--only-cached * stats for CLUSTER_  LOG_2010_05_21.MYI:file size=93840384, Total pages=22910, cached Pages=1, cached size=4096, cached perc=0.004365 stats For CLUSTER_LOG_2010_05_22.MYI:file size=417792, total pages=102, cached Pages=1, cached size=4096, cached perc=0.980 392 stats for CLUSTER_LOG_2010_05_23.MYI:file size=826368, total pages=201, cached Pages=1, cached size=4096, cached p erc=0.497512 stats for CLUSTER_LOG_2010_05_24.MYI:file size=192512, total pages=47, cached Pages=1, cached size=4096, Cached perc=2.127660 stats for CLUSTER_LOG_2010_06_03.MYI:file size=345088, total pages=84, cached pages=43, cached Si ze=176128, cached perc=51.190476 stats for CLUSTER_LOG_2010_06_04.MYD:file size=1478552, total pages=360, cached pages= Cached size=397312, cached perc=26.944444 stats for CLUSTER_LOG_2010_06_04.MYI:file size=205824, Total pages=50, C ached pages=29, Cached size=118784, cached perc=58.000000 stats for COMMENT_CONTENT_2010_06_03.MYI:file size=100051968, Total pages=24426, cached p ages=10253, cached size=41996288, cached perc=41.975764 stats for COMMENT_CONTENT_2010_06_04.MYD:file size=716369644, t Otal pages=174894, Cached pages=79821, cached size=326946816, cached perc=45.639645 stats for comment_content_2010_06_04 . Myi:file size=56832000, Total pages=13875, cached pages=5365, cached size=21975040, cached perc=38.666667 stats for FE ED_CONTENT_2010_06_03.MYI:file size=1001518080, Total pages=244511, cached pages=98975, cached size=405401600, Cached perc=40.478751 stats for FEED_CONTENT_2010_06_04.MYD:file size=9206385684, total pages=2247652, cached pages=1018661, Cached size=4172435456, cached perc=45.321117 stats for FEED_CONTENT_2010_06_04.MYI:file size=638005248, Total pages=15 5763, cached pages=52912, cached size=216727552, cached perc=33.969556 stats for FEED_CONTENT_2010_06_04.frm:file size= 9840, Total pages=2, Cached pages=3, Cached size=12288, cached perc=150.000000 stats for PERMALINK_CONTENT_2010_06_03.MYI:file size=103529062 4, total pages=252756, cached pages=108563, cached size=444674048, cached perc=42.951700 stats for permalink_content_20 10_06_04.myd:file size=55619712720, Total pages=13579031, cached pages=6590322, cached size=26993958912, cached perc=4 8.533080 stats for PERMALINK_CONTENT_2010_06_04.MYI:file size=659397632, total pages=160985, cached pages=54304, cache D size=222429184, cached perc=33.732335 stats for PERMALINK_CONTENT_2010_06_04.frm:file size=10156, Total pages=2, Cach Ed pages=3, Cached size=12288, cached perc=150.000000---total cached size:32847278080

With the above output you can see that there is several *. MYD, *. MYI, and *.frm files that is currently being cached.

Swap

If you want to clear out your swap you can use the following commands.

$ free             total       used       free     shared    buffers     cachedMem:       7987492    7298164     689328          0      30416     457936-/+ buffers/cache:    6809812    1177680Swap:      5963772     609452    5354320

Then use the This command to disable swap:

$ swapoff -a

Can confirm that it's now empty:

$ free             total       used       free     shared    buffers     cachedMem:       7987492    7777912     209580          0      39332     489864-/+ buffers/cache:    7248716     738776Swap:            0          0          0

and to re-enable it:

$ swapon -a

And now reconfirm with free :

$ free             total       used       free     shared    buffers     cachedMem:       7987492    7785572     201920          0      41556     491508-/+ buffers/cache:    7252508     734984Swap:      5963772          0    5963772

Emptying the buffers cache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.