I am working with apache2+php and other web server apps.

I have monitor as session connecting to a web server. RAM memory is full.

But when disconnecting a session, it does not free the RAM memory.

I have monitor via free -m, and it show unreleased memory even with no session now connected.

Is there a solution?

  • Be careful with free -m . The first line shows the memory usage including the buffers and caches. The second line shows the used memory less the buffers and cache, which is the actual available memory. You should also try something like htop for monitoring purposes. It is much more intuitive and available in the official repos. If you are really running out of memory, give us more info like the type of web application you are running, the quantity of RAM you have, what is used and all. Paste the output of free -m and stuff like that.
    – Johnride
    Aug 6 '14 at 16:46
  • 3
    There is no solution, because there is no problem. Linux uses available RAM as a buffer for files.
    – Run CMD
    Aug 6 '14 at 17:05
  • But here after fire command: sudo sync && sudo sysctl -w vm.drop_caches=3 It shows me right free available memory and also apps works better. Aug 27 '14 at 17:45
  • linuxatemyram.com
    – muru
    May 7 '15 at 15:31
  • I am most expeirenced with VPS server and founded recently debian 9.0 working perfect with memory management. Sep 14 '17 at 5:35

You can free up unused memory using this command:

sudo sync && sudo sysctl -w vm.drop_caches=3

This command synchronize cached data and then writes an OS parameter at runtime, located at /proc/sys/vm/drop_caches. This parameter is read by kernel once, then free up the unused memory.

Basically, the kernel reserves three sections in cache, that could increase memory usage:

  • pagecache
  • dentries
  • inodes

Writing to this parameter will cause the kernel to drop clean pagecaches, dentries and inodes from RAM, causing that memory to become free. There are three values that can be assigned:

  1. vm.drop_caches=1 free pagecaches.
  2. vm.drop_caches=2 free dentries and inodes.
  3. vm.drop_caches=3 free pagecaches, dentries and inodes.

Important: After execution this will return to normal state which means start caching pagecaches, dentries and inodes again. Use it depending on your server configuration and application.

  • 1
    Can you please explain a little more detail?
    – A.B.
    May 7 '15 at 15:52
  • This command only useful when weekly or daily at end of day want to release all unused memory, also 3 or 2 or 1 each with different purpose. Do not try this on session loaded server. May 12 '15 at 6:32
  • 1
    Edit your answer, not as comment.
    – A.B.
    May 13 '15 at 12:47
  • sudo sync & sudo sysctl -w vm.drop_caches=3
    – Nyxynyx
    Jan 31 '20 at 21:56
  • 1
    @GuillermoGarcia Using bash in Ubuntu 18.04.3. I needed to include sudo a second time. Otherwise I get the error sysctl: permission denied on key 'vm.drop_caches'
    – Nyxynyx
    Feb 4 '20 at 16:18

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.