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方法 有 34 条回应

  1. Keep on working, great job!

    回复
  2. Appreciating the persistence you put into your site and detailed information you offer. It’s great to come across a blog every once in a while that isn’t the same outdated rehashed material. Great read! I’ve bookmarked your site and I’m including your RSS feeds to my Google account.| а

    回复
  3. Touche. Outstanding arguments. Keep up the amazing work.

    回复
  4. I really love your website.. Great colors & theme. Did you make
    this web site yourself? Please reply back as I’m trying to create my own blog and would
    love to know where you got this from or just what the theme is called.

    Thank you!

    回复
  5. Hi there, I enjoy reading all of your post. I wanted to write a little comment to support you.

    回复
  6. I always used to read article in news papers but now
    as I am a user of net therefore from now I am using net for content, thanks to web.

    回复
  7. Great delivery. Sound arguments. Keep up the good work.

    回复
  8. Attractive section of content. I just stumbled upon your
    website and in accession capital to assert that I acquire in fact enjoyed account your blog posts.
    Anyway I’ll be subscribing to your augment and even I achievement you access consistently quickly.

    回复
  9. I quite like looking through an article that
    can make men and women think. Also, many thanks for permitting me to comment!

    回复
  10. Hi! I know this is kind of off topic but I was wondering if you knew where I could locate
    a captcha plugin for my comment form? I’m using
    the same blog platform as yours and I’m having trouble finding one?
    Thanks a lot!

    回复
  11. That is a really good tip particularly to those fresh to the blogosphere.
    Brief but very accurate info… Thanks for sharing this one.

    A must read post!

    回复
  12. Excellent pieces. Keep posting such kind of information on your page.

    Im really impressed by your blog.
    Hello there, You’ve performed a great job. I will certainly digg it and personally suggest to my friends.
    I am sure they will be benefited from this website.

    回复
  13. I’m really loving the theme/design of your web site.
    Do you ever run into any web browser compatibility issues?

    A small number of my blog readers have complained about my site not working correctly in Explorer but looks great
    in Opera. Do you have any solutions to help fix this problem?

    回复
  14. Remarkable things here. I am very glad to see your post.
    Thank you a lot and I am looking forward to touch you.
    Will you please drop me a e-mail?

    回复
  15. Hello there, I found your blog by the use of Google at the same time as looking for a comparable
    matter, your web site got here up, it appears great.
    I have bookmarked it in my google bookmarks.
    Hi there, just became aware of your weblog through Google, and located that it is
    truly informative. I’m gonna watch out for brussels.
    I’ll be grateful when you continue this in future. Many people shall be benefited out of your writing.
    Cheers!

    回复
  16. Hi, I do believe this is an excellent site. I stumbledupon it 😉
    I may come back yet again since I book-marked it.
    Money and freedom is the best way to change,
    may you be rich and continue to guide other people.

    回复
  17. Hola! I’ve been following your weblog for a while now
    and finally got the courage to go ahead and give
    you a shout out from Porter Texas! Just wanted to say keep up the great job!

    回复
  18. I read this article fully about the comparison of hottest
    and previous technologies, it’s amazing article.

    回复
  19. Just desire to say your article is as surprising.
    The clearness in your publish is simply great and i could suppose you’re a professional in this subject.

    Fine together with your permission let me to grasp your RSS feed to stay up to date with forthcoming post.
    Thanks a million and please carry on the enjoyable work.

    回复
  20. Right now it looks like Drupal is the best blogging platform out there right now.
    (from what I’ve read) Is that what you’re using on your
    blog?

    回复
  21. Hi there, just wanted to mention, I enjoyed this post.
    It was practical. Keep on posting!

    回复
  22. Great post. I was checking continuously this blog and I am impressed!
    Extremely helpful info particularly the last part 🙂 I care for such information much.
    I was looking for this particular information for a very long time.
    Thank you and good luck.

    回复
  23. My brother recommended I may like this website.
    He was totally right. This publish truly made my day.
    You can not consider just how a lot time I had spent for this info!
    Thank you!

    回复
  24. This site definitely has all the information I
    needed concerning this subject and didn’t know who
    to ask.

    回复
  25. Amazing! This blog looks just like my old one!
    It’s on a totally different subject but it has pretty much the
    same layout and design. Great choice of colors!

    回复
  26. Hey there! Would you mind if I share your blog with my zynga
    group? There’s a lot of folks that I think would really appreciate your content.
    Please let me know. Thank you

    回复
  27. I constantly spent my half an hour to read this website’s articles all the time along
    with a cup of coffee.

    回复
  28. I’m gone to tell my little brother, that he should also pay a quick visit
    this webpage on regular basis to take updated from most recent
    news update.

    回复
  29. Hello There. I found your blog using msn. This is a really
    well written article. I will make sure to bookmark it and return to read more of your useful info.
    Thanks for the post. I’ll definitely return.

    回复
  30. Hey There. I found your weblog using msn. That is a very neatly written article.
    I will be sure to bookmark it and come back to learn extra of your useful info.
    Thanks for the post. I’ll certainly comeback.

    回复
  31. What a information of un-ambiguity and preserveness of precious know-how concerning unpredicted feelings.

    回复
  32. I blog often and I seriously appreciate your information. This article has really peaked my
    interest. I will bookmark your website and keep checking for new
    information about once per week. I opted in for
    your Feed too.

    回复
  33. Hello I am so happy I found your blog page, I really found
    you by accident, while I was searching on Bing for something else, Anyways
    I am here now and would just like to say thank you for a fantastic post and a
    all round entertaining blog (I also love the theme/design), I don’t have time to go
    through it all at the minute but I have saved it and also included your RSS feeds, so when I have time I will be back to
    read a great deal more, Please do keep up the fantastic work.

    回复
  34. Hi there, I would like to subscribe for this website to take newest updates, therefore where can i do it please help out.

    回复

发表评论

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