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

  1. Excellent goods from you, man. I have understand your stuff previous to and you’re just too wonderful. I actually like what you have acquired here, certainly like what you’re saying and the way in which you say it. You make it entertaining and you still take care of to keep it wise. I cant wait to read much more from you. This is actually a great web site.| а

    回复
  2. Very good information. Lucky me I found your blog by chance (stumbleupon). I’ve saved it for later!|

    回复
  3. What’s Going down i am new to this, I stumbled upon this I have found It absolutely helpful and it has aided me
    out loads. I hope to contribute & aid other customers like its helped me.
    Great job.

    回复
  4. Someone essentially lend a hand to make severely articles I’d state. This is the very first time I frequented your web page and up to now? I surprised with the analysis you made to create this actual post amazing. Great process!| а

    回复
  5. Pretty nice post. I just stumbled upon your blog and wished to mention that I’ve really enjoyed surfing around your weblog posts. In any case I will be subscribing to your feed and I hope you write again very soon!| а

    回复
  6. Hi there, this weekend is nice in favor of me, for the reason that this time i am reading this great informative article here at my residence.| а

    回复
  7. Appreciating the time and energy you put into your website and in depth information you present. It’s awesome to come across a blog every once in a while that isn’t the same out of date rehashed material. Great read! I’ve bookmarked your site and I’m adding your RSS feeds to my Google account.| а

    回复
  8. Thanks for sharing your thoughts. I truly appreciate your efforts and I am waiting for your further write ups thanks once again.| а

    回复
  9. Very good write-up. I definitely love this website. Continue the good work!| а

    回复
  10. Nice post. I was checking continuously this blog and I’m impressed! Very useful information particularly the last part 🙂 I care for such info a lot. I was seeking this particular information for a long time. Thank you and good luck.| а

    回复
  11. I think this is one of the most important info for me. And i’m glad reading your article. But want to remark on some general things, The website style is ideal, the articles is really excellent : D. Good job, cheers| а

    回复
  12. I was able to find good information from your blog articles.

    回复
  13. Hi there, I log on to your new stuff like every
    week. Your writing style is awesome, keep up the good work!

    回复
  14. [url=https://triamterenebenzathiazide.com/]triamterene 75mg hctz 50mg tablets[/url] [url=https://diflucanrx.com/]diflucan no prescription[/url] [url=https://accutanisotretinoin.com/]where can you get accutane[/url] [url=https://dapoxetine911.com/]dapoxetine 1mg[/url] [url=https://chydroxychloroquine.com/]plaquenil hives[/url] [url=https://gabapentin.us.com/]gabapentin canadian pharmacy[/url] [url=https://flagyl24.com/]flagyl 500mg[/url] [url=https://phenergan125.com/]12.5 mg phenergan[/url] [url=https://cephalexin911.com/]2 cephalexin[/url] [url=https://propranolol100.com/]30 mg propranolol[/url] [url=https://sildenafilv.com/]buy sildenafil pills[/url] [url=https://chloroquineav.com/]can i buy chloroquine over the counter[/url] [url=https://stromectol1.com/]ivermectin cost uk[/url] [url=https://albenzamed.com/]can you buy albenza over the counter[/url] [url=https://viagra2019.com/]price of viagra in canada[/url] [url=https://viagrasoftab.com/]buy generic viagra soft tabs[/url] [url=https://ampicillin24.com/]ampicillin 100 mg[/url] [url=https://medrol80.com/]medrol 4 pill[/url] [url=https://lexaporo.com/]how much is lexapro 20 mg[/url] [url=https://cytotec100.com/]where to buy cytotec over the counter[/url]

    回复
  15. I always spent my half an hour to read this webpage’s content everyday along with a mug of coffee.

    回复
  16. Write more, thats all I have to say. Literally, it
    seems as though you relied on the video to make your point.
    You definitely know what youre talking about, why waste your intelligence on just posting videos to your
    weblog when you could be giving us something
    enlightening to read?

    回复
  17. Nice post. I used to be checking constantly this weblog
    and I am impressed! Very helpful info specifically
    the closing section 🙂 I handle such info much. I was seeking this particular info for a long time.
    Thanks and best of luck.

    回复
  18. What’s up everyone, it’s my first go to see at
    this web page, and post is actually fruitful in favor of me, keep up posting these posts.

    回复
  19. Hey! I’m at work surfing around your blog from my new apple iphone! Just wanted to say I love reading through your blog and look forward to all your posts! Keep up the fantastic work!|

    回复
  20. I am not sure where you’re getting your information, but great
    topic. I needs to spend some time learning more or understanding more.
    Thanks for excellent info I was looking for this info for my mission.

    回复
  21. I love it when individuals come together and share thoughts. Great website, continue the good work!|

    回复
  22. Hi there, its nice post on the topic of media print, we all
    understand media is a great source of facts.

    回复
  23. I together with my friends were looking at the best tricks on your web site and at once developed a terrible feeling I had not thanked the website owner for those secrets. My women happened to be for that reason warmed to read through them and have in effect extremely been taking advantage of these things. I appreciate you for getting so kind and for choosing varieties of excellent subject matter most people are really needing to know about. My very own sincere regret for not expressing gratitude to earlier.

    回复

发表评论

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