2

I have a Tomcat instance running on a Windows 2008 Server with 4GB of RAM. The server is dedicated to this one application, so I would quite like to be able to dedicate most of the RAM to Tomcat. My Tomcat setup currently has the following java options:

-Xms256m

-Xmx1600m

I'd like to increase the amount of RAM, preferably up to about 3GB (obviously I know how to do that, just increase the -Xmx value). However, Tomcat refuses to start up if I increase the maximum heap space beyond 1600MB. Several websites that I have read say that Tomcat cannot use more than 40% of the available RAM, which seems consistent with what I'm seeing.

Is there a way of increasing the proportion of memory that Tomcat can use, so that I can increase the amount of memory that Tomcat can use?

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
RikSaunderson
  • 3,505
  • 6
  • 32
  • 50

2 Answers2

3

Your issue was probably OS related, not Tomcat / Java. The Windows OS limits the memory allocation of a 32-bit process to 2 GiB in total (by default).

The reason why it only allowed you to allocate around 1.5 GiB heap space is because there is also other memory allocated to the process (the JVM / library overhead, perm gen space etc.).

Why does 32-bit Windows impose a 2 GB process address space limit, but 64-bit Windows impose a 4GB limit?

Other modern operating systems [cough Linux] allow 32-bit processes to use all (or most) of the 4 GiB addressable space.

That said, 64-bit Windows OS's can be configured to increase the limit of 32-bit processes to 4 GiB (3 GiB on 32-bit):

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366778(v=vs.85).aspx

However, as you've rightly done, the best solution is to use a 64-bit JVM with your 64-bit OS. Terabyte heaps anyone:

Max memory for 64bit Java :D

Community
  • 1
  • 1
Michael
  • 7,348
  • 10
  • 49
  • 86
2

Despite having a 64 bit server I only had 32 bit Java/Tomcat installed. I uninstalled Java and Tomcat and installed 64 bit versions and everything worked fine. it seems that the issue was that 32 bit Java can only address 1.5 GB.

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
RikSaunderson
  • 3,505
  • 6
  • 32
  • 50
  • Your answer is incorrect, a 32-bit JVM is not limited to 1.5 GiB of heap space. The restriction is the process size of the OS. – Michael Mar 13 '12 at 12:47
  • @Mikaveli: can you provide evidence or a citation for that? Rik presents experimental evidence that seems to support his conclusion. I would like to know if he's right or mistaken. – LarsH Sep 20 '12 at 14:10
  • @LarsH Here you go: http://www.oracle.com/technetwork/java/hotspotfaq-138619.html#gc_heap_32bit Oracle state that a 32-bit JVM can address nearly 4 GiB on (64-bit) Solaris and usually up to 1.6 GiB on Windows. – Michael Sep 20 '12 at 15:54
  • @Mikaveli: Thanks. It doesn't say anything explicit about 32-bit JVM on 64-bit Windows, though it does say "On 64-bit operating systems running the 32-bit VM, the max heap size can be higher [than 1.6GB I guess]" and the bit about Solaris that you mentioned. – LarsH Sep 20 '12 at 16:36
  • @LarsH His answer states "32 bit Java can only address 1.5 GB" - I've proven that statement to be incorrect. A 32-bit _JVM_ can address nearly 4 GiB. Also, if you read my answer, you'll see that Windows is the limiting factor - where 32-bit processes are limited to 2 GiB, even on their 64-bit OS's (by default). – Michael Sep 21 '12 at 08:26
  • @Mikaveli - I partially agree, but (a) I think Rik was referring to his own context, and meant that "32 bit Java *on 32- or 64-bit Windows* can only address 1.5GB", though if he meant that he could have been more explicit; and (b) it's not clear that the OS by itself is the limiting factor, as opposed to the combination of OS and JVM. For example, I've read that JRockit JVM can grab more than 2GB, even on 32-bit Windows (I don't understand how). – LarsH Sep 21 '12 at 13:25
  • @LarsH 32-bit Java on 64-bit Windows can still address more than 1.5 GiB. Again, the OS process size is the limiting factor. If you artificially set your perm gen space very low, dedicating more of the 2 GiB process limit to heap, you can achieve a max heap way above 1.5 GiB. Conversely, if you set a very high perm gen, your 'heap limit' could be much lower than 1.5 GiB. Either way, it's simply a false statement. – Michael Sep 21 '12 at 13:45
  • Also, this question may help you to understand: http://stackoverflow.com/a/2457542/575766 – Michael Sep 21 '12 at 13:56