Java Memory Limit -Xmx suffix: upper vs lower case m/M and g/G [duplicate]
Asked Answered
Z

3

30

It is commonly known that it is possible to limit the Java heap size with -Xmx<amount><unit>, where unit is the data amount unit like Gigabyte, Megabyte, etc. I know that -Xmx128M means 128 Mebibytes (= 128 * 1024 * 1024 bytes).

But is it true, that it is also possible to use decimal units like megabytes using -Xmx100m (which would be 100 * 1000 * 1000 bytes)?

So is it possible to use this decimal units by using lower-case unit suffixes like k, m, g instead of K, M, G?

Zoology answered 16/5, 2014 at 16:19 Comment(2)
BTW The case generally matters, it's just that javac doesn't care. Note: there is no need to wonder whether g/G means 100^3 or 1024^3 because it won't be exactly either. ;) On my system running System.out.println(Runtime.getRuntime().maxMemory()); with -Xmx1g prints 954728448Highwrought
@PeterLawrey That's interesting to know.Zoology
C
42

There is no difference between k and K both means kibibyte and so does m/M = mebibyte & g/G = gibibyte. you can set 100m as the value and it will be 100 * 1024 * 1024 bytes. generally it is advised to use this value in powers of 2.

Hope it helps.

Checkrow answered 16/5, 2014 at 16:33 Comment(2)
why is it advisable to use in powers of two ? I would question that. If you want to add 1g to an 8g server, that should be no issue.Robbert
Until a few years ago it was a popular convention, in my opinion there is no advantage in using powers of twoDialytic
L
3

Why don't you just try -Xmx100m and -Xmx100M and check if there is any difference.
k, m, g work exactly like K, M, G - they all mean binary units.

Lowlife answered 16/5, 2014 at 16:27 Comment(0)
P
2

All memory sizes used by the JVM command line arguments are specified in binary units (Kibibyte, Mebibyte, etc.) regardless of unit capitalization; where a 'kilobyte' is 1024 bytes, and the others are increasing powers of 1024.

This answer goes into a more complete technical answer to the question.

Permute answered 11/4, 2017 at 21:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.