LSX-blog

Feed Rss

【收录】Linux下清理内存和Cache方法

04.22.2013, Linux, by .

频繁的文件访问会导致系统的Cache使用量大增

$ free –m

total used free shared buffers cached

Mem: 3955 3926 28 0 55 3459

-/+ buffers/cache: 411 3544

Swap: 5726 0 5726

free内存减少到几十兆,系统运行缓慢

运行sync将dirty的内容写回硬盘

$sync

通过修改proc系统的drop_caches清理free的cache

$echo 3 > /proc/sys/vm/drop_caches

drop_caches的详细文档如下:

Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.

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

As this is a non-destructive operation, and dirty objects are notfreeable, the user should run “sync” first in order to make sure allcached objects are freed.

This tunable was added in 2.6.16.

修改/etc/sysctl.conf 添加如下选项后就不会内存持续增加

vm.dirty_ratio = 1

vm.dirty_background_ratio=1

vm.dirty_writeback_centisecs=2

vm.dirty_expire_centisecs=3

vm.drop_caches=3

vm.swappiness =100

vm.vfs_cache_pressure=163

vm.overcommit_memory=2

vm.lowmem_reserve_ratio=32 32 8

kern.maxvnodes=3

上面的设置比较粗暴,使cache的作用基本无法发挥。需要根据机器的状况进行适当的调节寻找最佳的折衷

【收录】Linux下清理内存和Cache方法 有 262 条回应

  1. It’s going to be ending of mine day, except before finish I am reading this great piece of writing to improve my experience.| а

    回复
  2. I’m extremely impressed with your writing skills and also with the structure to your weblog. Is that this a paid theme or did you customize it your self? Anyway stay up the nice high quality writing, it is rare to see a great weblog like this one nowadays..| а

    回复
  3. naturally like your web site however you have to take a look at the spelling on several of your posts. A number of them are rife with spelling problems and I to find it very troublesome to tell the reality on the other hand I will surely come again again.| а

    回复
  4. I am sure this paragraph has touched all the internet visitors, its really really fastidious paragraph on building up new weblog.| а

    回复
  5. Hi mates, its impressive paragraph concerning cultureand entirely explained, keep it up all the time.| а

    回复
  6. Painter And Decorator Gloucester
    38 Bruton Way
    Gloucester GL1 1DA, United Kingdom
    01452 223268

    回复
  7. That is really fascinating, You are an excessively professional blogger. I have joined your rss feed and sit up for in the hunt for more of your magnificent post. Additionally, I have shared your web site in my social networks| а

    回复
  8. I simply want to mention I am just very new to weblog and actually savored your web page. Most likely I’m want to bookmark your site . You absolutely have perfect writings. Cheers for sharing with us your web-site.

    回复
  9. A fascinating discussion is definitely worth comment. I believe that you should publish more on this topic, it may not be a taboo matter but generally people do not speak about such subjects. To the next! All the best!!| а

    回复
  10. I’m really impressed with your writing talents as smartly as with the layout on your blog. Is this a paid subject or did you modify it your self? Anyway keep up the nice high quality writing, it is uncommon to see a great weblog like this one these days..| а

    回复
  11. I just want to say I am just newbie to blogs and honestly liked this web site. Very likely I’m going to bookmark your site . You certainly come with beneficial article content. Thank you for sharing with us your webpage.

    回复
  12. Greetings! I know this is somewhat off topic but I was wondering which blog platform are you using for this website? I’m getting sick and tired of WordPress because I’ve had problems with hackers and I’m looking at options for another platform. I would be fantastic if you could point me in the direction of a good platform.| а

    回复

发表评论

电子邮件地址不会被公开。 必填项已用*标注