Monday, July 30, 2012

How to acquire large pages for Java heap

Although there is a similar blog entry on this topic, I’d rather to blog it anyway for my own reference.

If the WebLogic Server was installed on Linux and when starting, you might see the following message:





What happened is the default JRockit JVM prefers to uses large pages for Java heap but the Linux OS is not setup yet for this option.

HugePages is a feature integrated into the Linux kernel 2.6. It’s a method to have larger page size that is useful for working with large memory. HugePages is userful for both 32-bit and 64-bit configurations. Its size varies from 2MB to 256MB, depending on the kernel version and the hardware architecture. Using HugePages reduces the OS maintenance of page states, and increases Translation Lookaside Buffer (TLB) hit ratio.

Run the following will show a filesystem of type hugetlbfs configured in the kernel:
cat /proc/filesystems





















First, we need to create the hugepages directory and mount it on the ‘hugetlbfs type filesystem. 
Using root,
mkdir hugepages
chmod 777 hugepages

Using root, add the line into /etc/fstab for auto-mount in future restarts:
nodev /mnt/hugepages  hugetlbfs  rw,auto,uid=500,user,sync 0 0

To make it effective without restart, do the following:
mount –a

Next, we need to configure the hugepages size

To check the huge pages configuration on the OS:
cat /proc/meminfo|grep Huge







The ‘Hugepagesize’ is the size of hugepages the system allocates which is 2Mb. 2MB size of HugePages is available with Linux x86-64 and Linux x86. 256 MB size of HugePages is available only with Linux Itanium.
Because it’s a virtual memory to physical memory mapping, it’s mounted under /mnt/ directory.

To set the huge page size at run time (for example to set 1024), use the following:
sysctl –w vm.nr_hugepages=1024

The following line is doing the same:
echo 1024 > /proc/sys/vm/nr_hugepages

When set to 1024, actually the allocated memory would be:
1024 * 2M = 2 G

To make the setting permanent and effective on future OS restarts, add the following line into the /etc/sysctl.conf file:
vm.nr_hugepages=1024

Restart WebLogic server and the “cannot acquire large pages for Java heap” will be gone.

Run the following line again to check how is the hugepages is used:
cat /proc/meminfo|grep Huge




1 comment:

Anonymous said...

I just a way to clarify, you don't need to do chmod 777 /mnt/hugepages as long as when you mount you give the user and group.

For example:
nodev /mnt/hugepages hugetlbfs rw,uid=150,gid=151

These are all the options you need since you want to avoid for this set up nodev, nosuid, and noexec parameters when mounting.

Max
WebAdminInc