i use FreeNAS server which is built on OS version FreeBSD 8.2-RELEASE-p6. I use ZFS file system with 13TB HDD on my 8GB physical ram installed box. It almost uses all of RAM installed while proccessing some request. However, it still uses same amount of memory on idle times. So this is becoming a problem sometimes.

On my centos web server; i use following command to drop cached memory with a cronjob;

sync; echo 3 > /proc/sys/vm/drop_caches

However, this command does not work on my Freenas server. How can i drop cached memory on my FreeNAS box which is built on FreeBSD 8.2

Thank you

  • 1
    I would challenge the logic behind doing this on both the FreeNAS box, and your CentOS server. Why do you want free memory? – Kyle Smith Mar 25 '12 at 13:53
  • 2
    Are you having any actual performance issues or errors tied to memory usage? Because otherwise it's a bad idea to get rid of cache; the memory manager is using it to speed up your comparatively slow slow slow disk subsystem. – Bart Silverstrim Mar 25 '12 at 14:00

To start, CentOS is a Linux Operating System. Linux is completely different from FreeBSD.

You really don't need to free up that cached memory, likely you don't need to on your Cent box, but it does depend a bit on what you're running on it. You should only ever mess with memory management when you have a really specific and good reason to do so.

The one and only reason you would want to do this on a production box is if you have an application the bases it's own memory usage on the amount of free memory. I do not know of any *nix programs that do this, but it's possible they're out there. Even if this is the case, you should be employing intelligent memory limiting on the system caches, not flushing them manually or periodically.

The only other common reason to flush the caches is for benchmarking and testing purposes.

If one of the above two do not apply, do not flush your caches.

In addition to the comments below, let me hammer the performance difference home with a simple test.

dd if=/dev/zero of=/path/to/test.1g bs=1m count=1024
1073741824 bytes transferred in 20.998713 secs (51133697 bytes/sec)

dd if=/path/to/test.1g of=/dev/null bs=1m
1073741824 bytes transferred in 4.496601 secs (238789654 bytes/sec)

dd if=/path/to/test.1g of=/dev/null bs=1m
1073741824 bytes transferred in 1.071374 secs (1002210138 bytes/sec)

The first time reading the test file nothing was cached; the second time it was already in the cache, so the read operation completed four times faster. In a typical server 90% of the reads are to 1% of the files/data on disk. If most of that 1% can stay in cached memory, disks reads will generally be 4x faster (on my server at least).

  • Hi Chris, My centos box Cpanel installed, dedicated web server. I know messing up with memory management is not good however, it`s memory usage annoyes me. I made a cron job for it. As you said centos is linux os and i know FreeBSD unix based os. I just wanted to know command for bsd to dump cached memory like i did on linux. However, you said that you do not recommend memory management. – user1066698 Mar 25 '12 at 14:18
  • 2
    "it`s memory usage annoyes me" <-- This is NOT a good reason to screw with memory. Seriously, you shouldn't be doing this. FreeBSD is based on 4.4BSD, not Bell Labs' Unix. Wikipedia has a nice chart of the various *nix's heritage. – Chris S Mar 25 '12 at 14:21
  • :) So i think i should delete cronjob that drops cached memory. But i am just curious, why i should not drop cached memory manually. What this cause? – user1066698 Mar 25 '12 at 14:24
  • 2
    @user1066698 because cached memory helps your system run faster. Free memory is not good. – Kyle Smith Mar 25 '12 at 14:30
  • The system will only use "free" memory for caching, and will release the cache as soon as there is a demand for it by programs. Cache will contain a variety of things, from various optimized memory structures to disk read cache. Cache memory's only purpose is to make the computer faster. Dumping that will cause the computer to run slower; there's absolutely no gain unless the special circumstances apply (as in the Answer). See also the Update to my Answer. – Chris S Mar 25 '12 at 14:38

For those need dropping cache for testing reasons, it looks like there isn't a straight forward way for dropping caches in FreeBSD.

Usually os cache is cache of file system files (or mmaped files). Cache of this files can be cleared by unmounting the corresponding partition.

Source: http://unix.derkeiler.com/Mailing-Lists/FreeBSD/hackers/2010-03/msg00244.html


Just to clarify the unmount solution: an attempt to unmount the filesystem flushes and clears the cache for that filesystem, even though the unmount itself does NOT have to succeed.

cd /mnt
umount /mnt

The umount will fail since the current working directory keeps it busy, but any cached data from /mnt is anyway cleared.


root:/usr/home/user> dd if=test of=/dev/null bs=1048576 count=1000
1048576000 bytes transferred in 10.012924 secs (104722255 bytes/sec)

root:/usr/home/user> dd if=test of=/dev/null bs=1048576 count=1000
1048576000 bytes transferred in 0.290137 secs (3614071699 bytes/sec)

root:/usr/home/user> umount /usr
umount: unmount of /usr failed: Device busy

root:/usr/home/user> dd if=test of=/dev/null bs=1048576 count=1000
1048576000 bytes transferred in 10.149973 secs (103308253 bytes/sec)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.