清空Linux缓冲与缓存

  • A+
所属分类:运维教程

有时我们需要通过free命令来查询系统内存使用情况,很多朋友会被第一行的数值吓到,used值巨高,free则所剩无几,其实这并非真正的内存占用。

Linux和Windows不一样,Linux的内存机制存在buffer和cache这两个功能:

  • cache(缓存):是指把读取出来的数据保存在内存当中,当再次读取时,不用读取硬盘而直接从内存当中读取,加速了数据的读取过程
  • buffer(缓冲):是指在写入数据时,先把分散的写入操作保存到内存当中,当达到一定程度再集中写入硬盘,减少了磁盘碎片和硬盘的反复寻道,加速了数据的写入过程

这两个功能同样会占用内存空间,但是这个空间是可以随时调用的,下面我们就来说下,如何清空Linux缓冲与缓存。

buffer缓冲清空命令sync,这个命令会迅速将buffer中数据写入硬盘,然后清空buffer中数据。

cache缓存清空命令有三个:

  • 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

切记缓存不要随意清空,清空cache命令最好在低负载时使用,不然可能会导致系统运行出问题!

  • 问答中心
  • 微信小程序扫一扫
  • weinxin
  • 微信公众
  • 微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:30   其中:访客  30   博主  0

    • avatar Blogs for SEO

      Hello there! This post could not be written any better! Looking at this article reminds me of my previous roommate! He continually kept preaching about this. I will send this information to him. Fairly certain he’ll have a good read. Many thanks for sharing!

      • avatar make money online

        Aw, this was a very nice post. Finding the time and actual effort to make a very good article… but what can I say… I put things off a whole lot and never manage to get nearly anything done.

        • avatar holiday weather guide

          Hi, I do believe this is an excellent blog. I stumbledupon it ;) I’m going to return once again since I book-marked it. Money and freedom is the greatest way to change, may you be rich and continue to guide others.

          • avatar Digital Marketing Course

            Leading Digital Marketing agency in India and Kolkata, Leading Web Design company. Providing web designing and Digital marketing services, Digital marketing course, and certification with an internship.

            • avatar Investments

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

              • avatar tax advisor near me

                A fascinating discussion is worth comment. I believe that you need to write more on this topic, it may not be a taboo matter but generally people don’t talk about these issues. To the next! Cheers!!

                • avatar cbd oil that works 2020

                  Do you have a spam issue on this blog; I also am a blogger, and
                  I was curious about your situation; we have
                  developed some nice methods and we are looking to trade methods with other folks, please shoot
                  me an e-mail if interested.

                  • avatar cbd oil that works 2020

                    Hello, its fastidious post regarding media print, we
                    all be familiar with media is a wonderful source of facts.

                    • avatar cbd oil that works 2020

                      Hi there to all, how is everything, I think every one is
                      getting more from this website, and your views are pleasant in favor of new users.

                      • avatar cbd oil that works 2020

                        Hello to every , since I am actually keen of reading this web site’s post to be updated on a regular basis.
                        It consists of good data.