2
free -m
             total       used       free     shared    buffers     cached
Mem:         24055      22439       1615       8969         16       9096
-/+ buffers/cache:      13326      10728
Swap:            0          0          0

So i'm here initially, i'd like a little extra ram space so my spotify stops crashing out or so I can start another java server or whatever.

I try echo 3 > /proc/sys/vm/drop_caches but no dice. readout is the same afterwards. Even after closing down chrome and all of the memory intensive stuff the page cache is still holding on, until restart really.

What causes this ?

  • 3
    I doubt it's caching. Linux frees up cache on demand. If spotify needs more ram and ram is occupied by cache, spotify will get that ram. – muru Apr 14 '15 at 15:39
  • 2
    the command should be echo "3" | sudo tee /proc/sys/vm/drop_caches. By the way, I agree with the comment from muru. – Doug Smythies Apr 14 '15 at 15:47
  • Just to be clear, regardless of whether the cache is the problem or not, echo 3 > /proc/sys/vm/drop_caches (as root) should or should not bring the cached down to 0 ? – MikePatel Apr 14 '15 at 16:08
  • No. The flush command will truly free up any and all memory that isn't really in use, but there is no guarantee that there isn't some cached currently in use. – Doug Smythies Apr 14 '15 at 17:34
2

I've always done:

echo 3 | sudo tee /proc/sys/vm/drop_caches
| improve this answer | |
  • It works on my Ubuntu 14.04. – gorgoth Apr 29 '16 at 1:02
1

From a sudo prompt, here's a one-liner you can use:

# free -m  && sync && echo 3 > /proc/sys/vm/drop_caches && free -m
              total        used        free      shared  buff/cache   available
Mem:           7840        1958        2775         739        3106        4795
Swap:          7999           0        7999
              total        used        free      shared  buff/cache   available
Mem:           7840        1958        4698         734        1183        4860
Swap:          7999           0        7999

This freed up 2 GiB of buffer/cache. It went from 3.1 GB to 1.2 GB.

So it works as it should, however in your case you didn't have buffered storage in RAM that could be flushed out.

| improve this answer | |
1

Linux (kernel) makes use of unused memory for page cache (and buffer cache - it still exists) to for performance.

free -> not used for anything

echo 3 > /proc/sys/vm/drop_caches frees pagecache, dentries and inodes which will return page cache / buffer cache to "free".

Ubuntu 14.04

# free -m
             total       used       free     shared    buffers     cached
Mem:          1375       1289         85          5        112        302
-/+ buffers/cache:        875        500
Swap:            0          0          0

# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0  87660 115120 309500    0    0     1     9    4   18  0  0 100  0  0
# echo 3 > /proc/sys/vm/drop_caches
# vmstat
fprocs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 512720   2236  25756    0    0     1     9    4   18  0  0 100  0  0
# free -m
             total       used       free     shared    buffers     cached
Mem:          1375        874        500          5          2         25
-/+ buffers/cache:        847        528
Swap:            0          0          0

buffers and cached will drop and free will increase but that doesn't mean you have more memory available for applications.

In your case, looking at + buffers/cache which is 10728MB, this was the current available memory for applications.

For more information, check Linux ate my RAM!

BTW: Fedora and Arch Linux use free from procps-ng output is different.

The output combines buff/cache and removed the somewhat confusing -/+ buffers/cache.

We can clearly see buff/cache dropped but available didn't change. I personally think it is a better implementation/interpretation.

# free -m
              total        used        free      shared  buff/cache   available
Mem:           1874         117          18           1        1737        1708
Swap:             0           0           0
# echo 3 > /proc/sys/vm/drop_caches
# free -m
              total        used        free      shared  buff/cache   available
Mem:           1874         117        1654           1         102        1708
Swap:             0   
| improve this answer | |
  • Thanks for the explanation and all, but hitting echo 3 > /proc/sys/vm/drop_caches wasn't returning the memory to free, hence the question. I'm %100 certain I didnt have 10GB free because the OS was destroying applications left right and centre for running out of memory. – MikePatel Nov 30 '15 at 14:32
0

Consider adding some swap space. When your system starts to run out of memory, the OOM (Out Of Memory) killer will start killing applications to free up resources. A lot of times it kills applications you need running.

dd if=/dev/zero of=/mnt/swapfile bs=1024 count=1048576

will give you a 1GB swap file in your /mnt directory. Then turn it in to actual swap space with:

mkswap /mnt/swapfile

and then turn it on:

swapon /mnt/swapfile

you'll also want to make it persist through a reboot so edit your /etc/fstab file to include:

/mnt/swapfile   none            swap    sw              0       0
| improve this answer | |

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.