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:
https://www.admon.org/uploads/howto/defrag_mem.c

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

4 thoughts on “Clean up buffer and cached memory by defrag_mem

  1. 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 comment

Your email address will not be published. Required fields are marked *