Memory depletion on server running Tomcat; can't find the cause
Due to a ton of research I believe I now understand the output of ps, top, and free better than ever, and also have a relatively decent grasp on memory management (virtual address space, etc.) than I ever did before. With that being said, my server is super low on available memory and I can't make 1+1=2 on why it is. I suspect it's Tomcat/JVM (which I admittedly know precious little about). I am rebuilding this server (for a number of reasons) and plan to install 8GB but solving this mystery is key to supporting/promoting my design plans.
Relevant info: OS= Ubuntu 8.10, 2.6.27-14-generic, 32-bit Physical RAM installed= 4GB Primary running apps: Apache 2.2.9, Tomcat5.5, Java version 1.6 Free -m Code:
total used free shared buffers cached Code:
top - 13:18:43 up 24 days, 22:07, 1 user, load average: 0.00, 0.00, 0.00 Code:
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- Tomcat runs in a number of private instances, so there's a separate startup script for each project. The default values were kept for the JVM heap sizes: Xms512M Xmx1536M If I understand correctly, this means that when each Tomcat instance starts, it will grab 512MB of its allocated address space, and get up to 1.5GB or so more as the need arises. So at jump there are 512MB x however many instances I have installed sitting in virtual memory, but not mapped to physical memory. The mapping only begins when someone actually accesses one of the instances by using the associated webapp. Am I right so far? So, I have very little memory left, I am swapping pretty hardcore, and even though I suspect it's the Tomcat/JVM stuff, it sure doesn't look like it from the memory tools. For that matter though it looks like "nothing" is using memory, or certainly not enough to cause such a low memory problem. The server was rebooted 24 days or so ago because it actually ran out of all virtual memory. How do I solve this mystery? Am I using the wrong tools? Am I misunderstanding my tools? What can I do to track down the processes depleting my memory? |
Sort your top(1) display by %MEM for a better answer to your question. After launching top:
(Note that 'h' displays help in top.) |
Ah, okay. See, I missed something. The results are:
Code:
Tasks: 278 total, 1 running, 277 sleeping, 0 stopped, 0 zombie |
Maybe have a read of this thread.
And post your /proc/meminfo. |
In some cases the page cache or the number of cached filesystem inodes or dentries may grow too large. When a previously idling process becomes active, and requires actual memory pages, the kernel must first evict dirty data to disk. To see if this is what happens for you, clear the caches and see what changes it makes to the memory use, and to the time it takes for a dormant Java activation to respond.
To flush all caches, run Code:
sudo sh -c 'sync ; echo 3 > /proc/sys/vm/drop_caches' If you run into this often, consider reducing dirty_background_ratio and dirty_ratio, via e.g. Code:
sudo sh -c 'echo 1 > /proc/sys/vm/dirty_background_ratio' Nominal Animal |
I took a look at the linked thread (and another thread on memory management linked off of that one). So, based on the lessons from those posts (that top's reporting on individual process memory utilization is not completely accurate) it seems like I'm supposed to understand that in fact the java process memory usage is actually likely to be less than shown above because top is including shared libraries. This makes even less sense to me.
Here is /proc/meminfo: Quote:
Quote:
Nominal Animal, I appreciate the suggestion to flush caches. I did some reading from a couple of other posts and forums (including http://www.scottklarr.com/topic/134/...e-from-memory/ and am a little nervous about performing this on a live system. Plus, isn't the cache in this case the same as the one reported in free -m? If so, I only have 89MB kept in cache, so it doesn't seem like I would gain much from this. Am I misunderstanding what this does? Thanks! |
All times are GMT -5. The time now is 07:34 PM. |