osx - How to empty file cache on Mac 10.9.3

08
2014-07
  • user3308082

    I have a macbook pro running osx 10.9.3 with 8 GB of RAM

    I use an app which monitors my RAM and displays it in the menu bar, and after copying several large files onto my mac from an external drive (totaling almost 5 GB), I only have anywhere from 250 mb to 400 mb of available RAM (the number fluctuates), usually this number is at least 3.5 GB. When I open the app, it tells me that most of the RAM (5.66 GB) is allocated to the file cache.

    http://i.imgur.com/4JQfDL8.jpg

    Is there any way I can get my RAM back without having to restart my computer? I would prefer if this could be done using an applescript file so I can easily run it in the future if I need to, but it's not necessary.

  • Answers
  • Wes Sayeed

    This is normal and doesn't represent a problem. People tend to think of RAM as being either occupied or free, but that isn't actually the case. A file cache is a perfect example of this.

    When you copied that data from the external drive, it had to read the contents into RAM first so it could then write it to the other drive. Copying 5 gigs of data into RAM is a computationally expensive operation. Now what if you wanted to use those files you just copied? The computer is betting that you will, so it kept the copy in RAM around so that it doesn't have pay that cost again if you do.

    Now here's the kicker that addresses the heart of your question: Does having 5.66 gigs of data in the file cache really only leave you with 250-400 MB of RAM available? Nope. That 5.66 GB is still free as far as the operating system is concerned. Why? Because the computer can dump that RAM in a nanosecond if it were needed for something else. It is more beneficial for you to have your RAM filled with cached copies of stuff than it is to have it sitting empty doing nothing. The smarter the operating system is about what to cache, the faster your computer is.

    Even though that program is telling you the truth about how much RAM is being used, at the same time it is misrepresenting the amount of RAM you have available.


  • Related Question

    osx - Ballooning Mac OS X kernel_task and Wired memory usage. How to diagnose / fix?
  • Questioner

    I have a very strange issue, which I'm having a hard time diagnosing as to the root cause.

    I have a Mac Pro (2008, 8-core 2.8 GHz, 8800GT) with 14 GB of RAM (recently upgraded because of this issue!).

    When I boot my system and log in, vm_stat / top / Activity Monitor will show that kernel_task has about 150 MB allocated, and the machine has about 800 MB of Wired memory being allocated.

    Even initially, 800 MB seems an awful lot of wired memory to be allocated with no applications running - but, it gets worse. (NB: Wired is locked, unswappable memory)

    After a very short time, sometimes triggered by something as simple as launching a terminal, kernel_task will balloon to 8-900 MB of Real Mem (RSIZE), and Wired Memory will accelerate to 1.6 GB (implying that all the extra memory requests are for wired RAM in the kernel).

    If I quit everything (I.E: no running applications, bar an activity monitor or terminal to view top), there is no appreciable reduction in either kernel_task RSIZE, or Wired Memory usage. Going the opposite way, and loading the system with tasks also shows that wired memory does not get reduced - and that importantly it is not reduced in preference to heavy swapping.

    If I log out and log back in again, it reduces a bit (450 MB kernel_task, 1.28 GB Wired), but not back to the start.

    I'm not running any wacky kexts - and futhermore, kextstat shows no huge memory allocations there; the largest being com.apple.nvidia.nv50hal at about 4 MB of Memory.

    The machine feels overall more sluggish when this has happened - unsurprisingly because such a huge amount of RAM has been marked as non-pageable.

    So I have a few questions:

    1) Is there a good way to diagnose what has allocated all of this wired memory? It's often over 2 times the kernel_task size, running no applications. The real memory total doesn't seem to add up - it seems that there is a bunch of RAM that isn't being accounted for anywhere.

    2) What is happening to cause the kernel to suddenly require 6 times as much memory?


  • Related Answers
  • Hasaan Chop

    Kernel extensions are just one of many, many, many code fragments that can be executed by the operating system without your knowledge. I have a small Python based utility that will help you find quite a few of them:

    http://khiltd.com/software/consultants_canary

    If that doesn't turn up any potential culprits, then I'd say boot from a clean installation and see if you can reproduce the problem there.