5

Most often when I see examples on setting the Java heap size using -Xms and -xmx JVM parameters people use powers of two:

128m, 512m, 1024m, etc.

Is there actually a reason for this? Is this beneficial to the JVM performance in some way? Or is this simply done because programmers tend to like powers of 2? (Or because the default value is 64m?)

P.S. Of course I know that you can use essentially any number you want (-Xmx666). But people tend to use powers of 2.

3
  • Just habits from when those sizes mattered... Commented Jul 31, 2014 at 11:39
  • 2
    See stackoverflow.com/questions/11465609/jvm-heap-setting-pattern Commented Jul 31, 2014 at 11:40
  • 1
    There are 10 kind of people in this world, those who understand binary and those who not !!! :p Commented Jul 31, 2014 at 11:43

2 Answers 2

3

I can't tell why other people do it but for me, it's a) convention to give RAM sizes in powers of two since the memory modules use that and b) I know all the powers of two up to 65536 from memory, so it's not an extra effort to do it.

But from a OS / memory point of view, using powers of two for allocating megabytes doesn't have any impact. If we were talking about smaller sizes (like 511 or 512 bytes), then the memory management subsystem of the OS will round those values. But no OS rounds for megabytes.

Sign up to request clarification or add additional context in comments.

Comments

2

No you can use any value. No need to be power of 2.

Eg:

 -Xms4043m -Xmx8303m

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.