Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
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
add comment

2 Answers 2

up vote 5 down vote accepted

To start, CentOS is a Linux Operating System. Linux is completely different from FreeBSD (except for the bits Linux borrowed from BSD, to make a complete OS, and hasn't yet replaced with their own code).

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.

Update:
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).

share|improve this answer
    
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
1  
"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
show 3 more comments

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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