Can we clear memory cache in Ubuntu

8,289

There is no need for this unless you are bench marking. It will slow the system for a few seconds while every resource is again loaded into the disk-cache.

To clear RAM Memory Cache (or page cache) ...

sudo -i
sync; echo 1 > /proc/sys/vm/drop_caches 

Page cache

The page cache contains any memory mappings to blocks on disk. That could be buffered I/O, memory mapped files, paged areas of executables.

Share:
8,289

Related videos on Youtube

Bawantha
Author by

Bawantha

I'm from Sri Lanka <3

Updated on September 18, 2022

Comments

  • Bawantha
    Bawantha over 1 year

    In my Ubuntu 20.04 I see 8.7 GB Memory cache in system monitor. Can I clear this, what is the best way to do so?

    enter image description here

    • 24601
      24601 almost 3 years
      You don't indicate what research you have done but does this reference answer your question?
    • HuHa
      HuHa almost 3 years
      Why would you want to clear that cache? Are you about to do benchmarks, or what other reason do you have?
    • Bawantha
      Bawantha almost 3 years
      @HuHa Actually I don't know whether I exactly needed or not. Months ago I had 8 GB RAM I upgrade it even that time I could work smoothly until my RAM gets full, now at this point I feel so much lag in my device I don't know why
    • HuHa
      HuHa almost 3 years
      Rest assured that the Linux kernel makes the best possible use of your RAM. Those caches and file buffers are what really gives your system a huge boost; it's very much like running things from a RAM disk. But if you need more RAM for large applications, the kernel frees as many of those caches and file buffers as needed to fulfill your memory demands. It's best not to tinker with this; you will be hard-pressed to get a better result than what the kernel does all by itself.
    • HuHa
      HuHa almost 3 years
      Most likely it's the kernel NOT having that many caches and file buffers available (as RAM is needed for other things) that makes you feel a slowdown. It's better to check what processes are running that use a lot of RAM.