We have 4GB on our linux server but we can currently use only ~1.8GB for our java-server, which is the first java process listed below. (200 MB are free so we can maximal use 1.6GB + 0.2GB)

The machine crashes when we are using more. So we specified -Xmx1600m and -XX:MaxPermSize=200m to limit the server RAM to 1.8GB. But we need more RAM! Where is the remaining RAM gone?

Here is the program output of top sorted against memory usage (via big 'M'):

Mem:   4083952k total,  3857856k used,   226096k free,   169320k buffers
Swap:  2104504k total,      176k used,  2104328k free,  1939080k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                           
28155 root      16   0 1835m 1.6g 7848 S    2 40.5  47:36.26 java                                                                                              
19609 root      16   0 45996 7052 3148 S    0  0.2  14:35.97 httpd2-prefork                                                                                    
 6802 root      16   0 46132 5916 1932 S    0  0.1   0:00.09 httpd2-prefork                                                                                    
 6866 root      15   0 46132 5916 1932 S    0  0.1   0:00.07 httpd2-prefork    

As you can see there are a lot (and even more) httpd2-prefork processes. But even if I accumulate the bytes (25* ~46KB = ~1MB) it will never get that big.

free -m prints:

             total       used       free     shared    buffers     cached
Mem:          3988       3768        219          0        165       1894
-/+ buffers/cache:       1708       2279
Swap:         2055          0       2055

Where is my mistake? Can I tune the server to give the java process more RAM?

BTW: we are not using a virtual machine like here


As it was pointed out in the comments: it is a 32bit kernel only :-( (via uname -a). So I can use only 3GB at least? But the server itself seems to be 64 bit? Because of the lm (long mode) in the output?

grep flags /proc/cpuinfo
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid cx16 xtpr

Here is another very similar question.

  • 2
    Is this a 32 or 64 bit machine? – coredump Jul 29 '10 at 23:18
  • Thanks! You are the man! "uname -a" shows it is a 32bit! Oh no. How much memory I can use with that? – Karussell Jul 30 '10 at 9:46
  • A 32bit machine can access up to 64GiB of physical memory, if it has a PAE-enabled kernel. – Hubert Kario Jun 17 '12 at 18:10

Ah, I see you have mistaken how to calculate free RAM in Linux.

Linux tends to heavily utilize all the RAM by caching stuff. Instead of reading directory listing from the disk every time, it caches the directory entries in RAM. It caches the frequently used files, so they don't need to be loaded from the disk every time. In case some process actually needs the RAM for its use, the cache will be immediately evicted.

So the formula for calculating the actually used RAM is total - (free + buffers + cached), in your case 3988 - (219 + 165 + 1894) or in other words 3988 - 2278. That is 1710 megabytes of RAM in use and 2278 megabytes of RAM for you still to consume.

Don't believe me? See, your server doesn't even have any swap in use. :)

But of course, a machine crash -- if you mean a hard lock up -- is a strange thing. That really should not happen. I suspect a faulty RAM stick which only gets accessed in case of >2 GB of RAM in use.

| improve this answer | |
  • ## "" See, your server doesn't even have any swap in use. :) "" Thanks a lot that makes sense that I have to add the buffer to the free mem. But why 1710m to consume? did you mean 2278m free to consume? ## "" But of course, a machine crash -- if you mean a hard lock up -- is a strange thing "" Yes, without any exception the java server died if we gave him the whole memory. Now it dies with OutOfMemory Exception, because we limited the mem to 1.8GB – Karussell Jul 30 '10 at 9:41
  • Err, yeah. I meant to say that 1710 MB of RAM is actually in use and 2278 MB is free. Fixed that. – Janne Pikkarainen Jul 30 '10 at 9:48
  • Ok. thanks a lot! It was a nice explanation! otherwise I wouldn't have found this minor mistake :-) Now I have to solve why I cannot use the rest of the RAM. Could this be because of a RAM stick defect or because of the 32 bit kernel? – Karussell Jul 30 '10 at 10:02
  • 32 bit kernel should not matter, it should support 4 GB without PAE enabled and with PAE up to 64 GB, and no matter what it should not crash. – Janne Pikkarainen Jul 30 '10 at 10:09
  • ok, thanks a lot! I will investigate this further! If you have another idea: feel free to comment :-) – Karussell Jul 30 '10 at 10:15

I only see older cpu options, so I suspect you have only a 32 bit cpu, but you should be able to use all 4GB, though you may need to investigate how to make that work the way you want (might need to enable PAE, for instance).

And do you mean the java app crashes, or the whole machine? The machine should not crash (though it may become unresponsive for a bit).

| improve this answer | |
  • only the java app crashed. How can I enable PAE ? Is this possible without having access to the BIOS? – Karussell Jul 30 '10 at 20:08
  • it can be a command line flag, if the kernel has it enabled. Google is your friend. – Ronald Pottol Aug 5 '10 at 0:05

Just a note - there's a mistake in the maths.

(25* ~46KB = ~1MB) should be read as (25* ~46000KB = ~1150MB).

Resource size is more important though as it gives a more realistic memory reading per process.

(25*~5000KB = ~125MB)

| improve this answer | |
  • thanks for pointing this out. According to this: linux.die.net/man/1/top you are right! That are really KB! But this doesn't fully explain where the memory is gone ... – Karussell Aug 1 '10 at 16:32

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.