Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm completely new to Linux and I'm just trying to understand where all my RAM is going. I've got a pretty fresh install of Xubuntu running as a VMWare guest, and I've given it 1.5GB RAM to play with.

After only running two apps starting up Tomcat servers and also running Firefox, I've got hardly anything left. 160MB according to free -m.

Looking at the output from Top, I see Java appearing twice, each stealing about 1/2 Gig resident memory. Both Tomcat instances use the same jdk, I would have thought I'd only see Java there once.

What's the story?


The free -m output requested:

             total     used     free    shared    buffers    cached
Mem:          1419     1380       39         0          8       111
-/+ buffers/cache:     1259      160       
Swap:          509       68      441


   74764   36m  6032    2.6   Xorg
    750m  500m  3436   35.5   java
    881m  408m   10m   28.8   java
    6128  1876  1588    0.1   vmtoolsd
   26156  3408  2672    0.2   vmware-user-load
    409m  104m   15m    7.4   firefox-bin
    2632  1060   776    0.1   top
    3032  1264   812    0.1   init
    All zeroes after here.
share|improve this question
Do you mean you ran 'free -m', not 'mem -f'? I'm not familiar with the 'mem' command. – Flimzy Jun 24 '11 at 8:13
I was just changing that - you read my post too quickly :) – jontyc Jun 24 '11 at 8:14
okay, thanks. Can you show the output of 'free -m', and maybe the first 5 lines or so of 'top'? Not as an image, just as text. – Flimzy Jun 24 '11 at 8:16
up vote 3 down vote accepted

This is not a Linux issue, it's a Java issue (and completely normal behaviour). The same will happen on Windows, though I guess it may be more eager in swapping out part of those Tomcat processes.

First of all, two instances of Tomcat are going to start two instances of the JVM in two separate processes. The question is whether you actually need two instances of Tomcat. You can easily run two different webapps in the same instance.

Second, Java as a language based on garbace collection likes to have a lot of memory to play in and tends to use a large percentage of the maximum heap it's allowed to use, because that way it does lesss work overall in garbage collection. It also doesn't tend to give unused memory back to the OS because it might need it again soon.

If you are certain your webapps need a lot less than half a gig memory, you can start Tomcat with a smaller maximum heap by setting the environment variable CATALINA_OPTS to "-Xmx256m" in to give it a maximum heap of 256MB. If your app sometimes needs more memory but you want it to shrink down its heap more quickly, set it to "-XX:MaxHeapFreeRatio=20 -XX:MinHeapFreeRatio=10" - this will give back memory to the OS if more than 20% of the heap is free after garbage collection, and expand the heap if less than 10% is free. But this may reduce performance by making Java spend a lot of time allocating memory from the OS and freeing it again soon after.

share|improve this answer
I see... Absolutely ridiculous and now I understand why my previous Windows environment ground to a halt. These apps (Atlassian) furthermore are documented to not work running in the same container. 1/2 Gig RAM for each app, and I'm yet to install the other three in the suite. What has happened in the programming world? – jontyc Jun 24 '11 at 9:11
@steboo: rational behaviour in the face of a resource (memory) being available in large quantities. However, webapps not being able to run in the same container, that's just poor engineering. – Michael Borgwardt Jun 24 '11 at 9:26
I guess my embedded background just can't get over the waste. – jontyc Jun 24 '11 at 9:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .