aspose file tools*
The moose likes Linux / UNIX and the fly likes JVM Memory on Linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "JVM Memory on Linux" Watch "JVM Memory on Linux" New topic
Author

JVM Memory on Linux

Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
I have two computers that I use as servers.
They both have the same hardware.
They are kind of old but they both work. :-)

Both have 512MB RAM

One has Linux kernel 2.4 with Java 1.4.1

I recently upgraded the other machine to kernel 2.6 with Java 1.4.2

I seem to be having a problem with the JVM using virtual memory instead of RAM on the "upgraded" computer.

After I start my Java application server (Resin) there is hard drive activity every 5 seconds and the performance is slower on the computer with the newer kernel. The top command shows about half of the real memory is being used on this computer.

The computer without the upgrade shows almost all of the memory is being used by the system and I don't get the hard drive activity every 5 seconds.

Does anyone know what's going on here?
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
Have a look at this article on Tuning Swappiness (and swapping behaviour). It may or may not help (post back and let us know).

512MB is not a lot of RAM for a Java EE server under load though. I generally recommend at least 1GB for any server these days, with RAM being so cheap. How large is your swap?
[ December 16, 2008: Message edited by: Charles Lyons ]

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
It is also possible that your server isn't set to overcommit (seems unlikely given you say not much RAM is in use). A JVM allocates a lot more memory than it ever uses, so that can be a problem. Here's a quote about this 2.6 kernel feature:
Memory overcommit is a Linux kernel feature that lets applications allocate more memory than is actually available. The idea behind this feature is that some applications allocate large amounts of memory "just in case", but never actually use it. Thus, memory overcommit allows you to run more applications than actually fit in your memory, provided the applications don't actually use the memory they've allocated. If they do, then the kernel terminates the application.
There's more advice in this article on Linux Memory Overcommit.
Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
Originally posted by Charles Lyons:
Have a look at this article on Tuning Swappiness (and swapping behaviour). It may or may not help (post back and let us know).

512MB is not a lot of RAM for a Java EE server under load though. I generally recommend at least 1GB for any server these days, with RAM being so cheap. How large is your swap?

[ December 16, 2008: Message edited by: Charles Lyons ]


I set the swappiness to 0 but I'm not seeing any dif.

I hear you about the RAM, but this is a very old computer and it's not so cheap - not worth investing more money into but it's been such a workhorse it's hard to give it up. :-)

The swap size is 458MB and I don't even see it getting used when I run top!

I don't know...maybe I should go back to the 2.4 kernel for this old dog.

Any idea why it's only using half of the RAM? The computer with the 2.4 kernel is using almost all of the RAM in the computer.
Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
Originally posted by Charles Lyons:
It is also possible that your server isn't set to overcommit (seems unlikely given you say not much RAM is in use). A JVM allocates a lot more memory than it ever uses, so that can be a problem. Here's a quote about this 2.6 kernel feature: There's more advice in this article on Linux Memory Overcommit.


Overcommit sounds like it might be whats happening.

I'm not sure how I set this and make it stick?

There is definitely some differences in memory management with the 2.6 kernel.

When I look at top, the VIRT heading show 353m for Java. The top manual says VIRT is the amount of Virtual memory for the task.

How do I tell linux not to use virtual memory for this task?
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
Any idea why it's only using half of the RAM? The computer with the 2.4 kernel is using almost all of the RAM in the computer.
It may be due to 2.6's pre-emptive swapping, where (using swappiness), it tries to swap ahead of time to avoid delays when a new process actually needs RAM.

What is the output of "cat /proc/meminfo"? That should profile your system's memory usage for us, all in one place.

BTW, what distro are you using?
Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
I'm using Yellow Dog Linux 4.0 on an old Mac.

cat /proc/meminfo
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
So this is saying that you have ~530MiB RAM and 450MiB swap. None of the swap is used (it is all free). Roughly half the RAM is being used.

The "free" command should also confirm this... so the process isn't being swapped!

Top is misleading you because VSIZE includes allocated but unused pages of memory. RSS is all the pages of your process in RAM (and since you're using no swap, the entire amount of memory being used by Resin). Overcommit means VSIZE != used memory; in fact:

VSIZE = (used RAM) + (used swap) + (allocated but unused)
RES = (used RAM)

This should mean the 2.6 kernel has more memory available for other processes, whereas in your 2.4 kernel some memory is being reserved by Resin when it needn't be. Far from being less efficient, 2.6 will make your old server go further!
[ December 16, 2008: Message edited by: Charles Lyons ]
Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
Well, okay...

But why am I getting hard drive access every 4-5 seconds?

Also, it's taking quite a bit longer to compile java files.

It just seems to be a little less peppy overall.
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
Drive access every 5 seconds doesn't sound too much of a problem. It could be writing log files, or doing file system caching. Obviously if it's doing that on a completely idle machine, that might be a bit concerning. Does the regular drive access stop if you stop Resin? How often is your Resin server accessed and how much processing does it do? How do you know it's accessing---is it just that you can hear it, or are you using some other utility?

I'm surprised it doesn't perform equally as well---there shouldn't be any immediate reason why that is. I guess it's just a case of narrowing down what is different, like which extra processes might be running. Are the JVMs from the same provider too (e.g. both Sun, or both GCJ or what)?
Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
The hard drive activity mostly stops when I shut down resin. I would say it sounds normal when resin is not running. I wish I knew what it was doing because it's not in production and nothing much is running on it. I'm not using any utility to check it but I can see the green light go on every 4-5 seconds. That sucker is a loud SCSI drive too!

I suppose the other difference is that I've got resin 2.x on the other machine and resin 3.x on the one with the newer kernel.

The JVM's are from IBM and are quite good.

In fact, I just installed the Java 5 SDK so I'll try that now.

Is there any way to tell what the heck that hard drive is doing?
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
Is there any way to tell what the heck that hard drive is doing?
As with everything Linux, yep... this should do the trick:
If the last command doesn't work (and it may block if you have "klogd" active for example), you can get the data via "dmesg" command too. It'll log all reads and writes to your disks. You should then be able to work out what process is causing all the activity.
Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
Cool!

Kjournald? Journaling file system? Can I turn it off?

Also, what is dirtied inode?

Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
Okay, this seems to be working:

/etc/fstab


/etc/sysctl.conf


Let me know if you see any problems with that.

Thanks for your help!
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
Setting the commit time higher than the default (5 seconds) would seem sensible if that's what's causing the problem. I guess your other machine doesn't have a journalling system like ext3, or its commit is longer too?
Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
Originally posted by Charles Lyons:
Setting the commit time higher than the default (5 seconds) would seem sensible if that's what's causing the problem. I guess your other machine doesn't have a journalling system like ext3, or its commit is longer too?


Hmm...I just checked this.

The other system is using ext3 and the commit time is set to 5 seconds also but it's certainly a lot quieter.

I just ran fsck and it found some problems and dropped me into a shell, so I did it again and it came up clean.

Perhaps there was a corrupt file in one of my java apps?

Or it could be that my hard drive is going south...

However, it seems fine now and I got the performance up a bit by using the correct Apache module for Resin. Seems to be on par with the other system now.
Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
Just found this is dmesg:


What does that mean?
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
Or it could be that my hard drive is going south...
That's always a possibility, though if it has now stopped making the noises, it was more likely a corrupt block or set of blocks on the disk. Glad it's all sorted now though! I have had no real problems with the 2.6 kernels; quite the reverse, they seem to perform better for me (on reasonable spec. machines at least).

Oh, and the error you mention is nothing to worry about really (it's reasonably common). "scsi_unique_id is using a deprecated SCSI ioctl" means the scsi_unique_id program isn't the latest version, so is using an old and deprecated API. Upgrade to the latest version of the program to get rid of this message.
[ December 17, 2008: Message edited by: Charles Lyons ]
Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
Okay. I better leave it alone now. :-)

Thanks again!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JVM Memory on Linux
 
Similar Threads
How do I copy a file?
System information
Problem to run Oracle9i after installed in Windows2000 professional?
Application deployed on JBoss 6.1 crashes
Changing JVM's Memory Allocation On The Fly