Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to guarantee allotment of particular GB as off heap memory for a JVM

-Xmx10g guarantees that the JVM gets 10G from OS for the process. Similarly, I want to guarantee particular amount of memory (say 4g) for my off heap usage.

If the RAM of my machine is 8GB and Xmx for my java process is 2G. Now, there may be other processes that may eat some memory. So, when I want to start my JVM, i want to specify the amount of off heap memory that i want to use inside my JVM.

-XX:MaxDirectMemorySize specifies only max direct memory size.

How can I ensure guaranteed availability of particular size of off-heap memory? Is there any parameter for that.

like image 502
K Adithyan Avatar asked Dec 30 '25 21:12

K Adithyan


2 Answers

Your understanding of the parameter -Xmx10g isn't quite correct. It allows the JVM to ask the operating system for up to 10GB of memory for its heap. It doesn't guarantee that the JVM will get it. Indeed, if your system doesn't have sufficient memory (physical and paging), the JVM won't get it.

For other memory (other than the heap), the JVM will ask for it and get it if there is sufficient. But again, there are no guarantees and there is no parameter for guarantees.

like image 153
Codo Avatar answered Jan 01 '26 09:01

Codo


I suggest using memory mapped files for off heap as these are more flexible in handling over committed sizes.

In your case, you may need a startup program or script to choose the heap size, unless you can make the heap size 2 GB always given you have decided this is enough.

like image 44
Peter Lawrey Avatar answered Jan 01 '26 11:01

Peter Lawrey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!