1

When I run free command on my computer, I see the following output:

$ free -m
             total       used       free     shared    buffers     cached
Mem:          1877       1802         74          0        125       1541
-/+ buffers/cache:        135       1742
Swap:         2047          0       2047

No matter how much I use memory, the free column in the 1st row always stays around 70 MB and doesn't drop below (I tried this by loading large files into memory, evident by cached being so high)

My understanding is that Linux reserves some memory for the root user always. Is this the reason why the free never drops below 70 MB?

EDIT: If this is the case, then loading the same files as root user should take up all free memory. Unfortunately, I've been unable to do this as well.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user3063877
  • 275
  • 1
  • 2
  • 8
  • Are you getting malloc failures or other out of memory errors? – lreeder Jan 27 '14 at 03:54
  • My motivation is to understand why the free memory never drops to 0. In reality, I'm able to produce `OutOfMemory` error in Java but the free memory doesn't drop to zero even with the error. I just want to understand is some of the available memory reserved for some purpose? – user3063877 Jan 27 '14 at 04:26
  • The Java JVM has it's own heap, with a default that can be overridden by the -Xmx option. You can run out of memory in a JVM without running out of RAM in the OS. If you really want your OS to run out of memory, it's better to use a small C program like the one described at http://www.linuxatemyram.com/play.html – lreeder Jan 27 '14 at 04:40
  • I set the Xmx to 6GB when I ran it and started adding random Strings to a List. The Swap was ultimately all used before I got `OutofMemory` but the free memory never dropped below 65. – user3063877 Jan 27 '14 at 06:13

1 Answers1

3

You still have lots of RAM available. You can tell that because:

  1. The free column shows 1742 meg free in cache.
  2. You are using 0% swap (assuming you haven't run swapoff to disable swapping)

See http://www.linuxatemyram.com/ for a good explanation of those columns.

lreeder
  • 12,047
  • 2
  • 56
  • 65
  • Yes but why doesn't free memory ever go to zero? – user3063877 Jan 27 '14 at 03:39
  • 3
    @user3063877: Because `vm.min_free_kbytes` is not zero. Try running `sysctl vm.min_free_kbytes` to see what it is set to. And if you want your cached memory back right away (no reason to except maybe benchmarking), try `system -w vm.drop_caches=3`. The latter requires root. – Nemo Jan 27 '14 at 05:29
  • 1
    Ah, this is it: `sysctl vm.min_free_kbytes`. Thank you. Wish you had answered the question so I could've accepted (Still would if you do :) ) – user3063877 Jan 27 '14 at 06:16