user710818
user710818

Reputation: 24248

Why doesn't my Java application work with huge pages in Red Hat Linux?

I have tried this simple command:

 java -XX:+UseLargePages -Xms2g -version

I receive the error:

Java HotSpot(TM) 64-Bit Server VM warning: Failed to reserve 
shared memory (errno = 12).

But without large pages it works OK.

meminfo output:

HugePages_Total:     0
HugePages_Free:      0
HugePages_Rsvd:      0
Hugepagesize:     2048 kB

Upvotes: 3

Views: 4008

Answers (2)

user3745362
user3745362

Reputation: 229

There are two things required to get huge pages working on Linux (see Oracle's Documentation) 1) The max amount of shared memory available shmmax needs to be greater than the JVM heap size. 2) Huge pages need to be enabled and sufficiently available to support the JVM heap.

The runtime setting for shmmax is at /proc/sys/kernel/shmmax.

The runtime setting for number of hugepages is at /proc/sys/vm/nr_hugepages

If you want these settings to persist after a reboot they will need to be set via sysctl.

So if you specify a 4GB maximum heap, shmmax needs to be >= 4GB, and with 2MB pages nr_hugepages would need to be >= 2K.

Your command line should also specify the maximum heap size.

Upvotes: 4

Brett Okken
Brett Okken

Reputation: 6306

It does not work because your huge pages are only 2MB (2048 kB) and your heap size is a minimum of 2 GB.

Upvotes: -1

Related Questions