Clean up buffer and cached memory by defrag_mem

This command is very useful to free buffers when you face lack of memory issue. Free memory can be seen from the output of common linux command “free”:

[root@leaseweb ~]# free
total       used       free     shared    buffers     cached
Mem:       1033972     987192      46780          0     159204     309176
-/+ buffers/cache:     518812     515160
Swap:      4192956         68    4192888

Here we can see that free memory calculation formula is:
Real free memory = free + buffers + cached

To clean up buffers and cached memory, use defrag_mem:

[root@leaseweb ~]# gcc -o defrag_mem defrag_mem.c
[root@leaseweb ~]# ./defrag_mem 500M

[root@leaseweb ~]# free
total       used       free     shared    buffers     cached
Mem:       1033972     482504     551468          0        612       7760
-/+ buffers/cache:     474132     559840
Swap:      4192956     112964    4079992

Defrag_mem is available here:
http://admon.org/uploads/howto/defrag_mem.c

This document is forwarded from http://os-drive.com here with some tiny modifications.  Zhigang is the creator for defrag_mem.c

Related posts:

  1. Compiling eAccelerator from source code
  2. RAMFS SYSFS and TMPFS on Linux
Tags: , ,


Joseph chen is a system administrator from south China. He has a keen interest in Open Source and system administration solutions.

4 Responses to “Clean up buffer and cached memory by defrag_mem”

  1. [...] a former post, we know that with the help of defrag_mem we can clean up buffers / cached memory to gain more real “free” memory. Defrag_mem [...]

  2. [...] a former post, we know that with the help of defrag_mem we can clean up buffers / cached memory to gain more real “free” memory. Defrag_mem [...]

  3. John fish says:

    Great site, I have added this page to my social bookmarks

  4. Lauretta says:

    Nice!, discovered your blog on Ask.Glad I finally tried it out. Unsure if its my Safari browser,but sometimes when I visit your site, the fonts are really tiny? However, love your page and will return.See Ya

Leave a Reply

© 2006-2009 Admon Home. All rights reserved.