Most of us worry about paging to disk (swap), but if you are running a transaction intensive application the paging that happens in RAM also starts to impact the application performance. This happens due to the size of the “block” that is used to store data in memory. Hugepages allows you to store the data in bigger blocks, hence reducing the need to page while interacting with the data.
Here is how you can enable hugepages and configure jboss (actually any Java app) to use hugepages on a RHEL/CentoOS system.
OS CONFIGURATION
Check if your system is capable of supporting hugepages by running
grep HUGETLB /boot/config-`uname -r`If you see the response as below, you should be good
CONFIG_HUGETLBFS=y
CONFIG_HUGETLB_PAGE=yNext check if huge pages are already being used by running
cat /proc/sys/vm/nr_hugepages- If the response is anything other than 0, that means hugepages have already been configured.
- Calculate the amount of memory you want to dedicate to hugepages. (note: memory allocated to hugepages cannot be used by other processes in the system, unless they are configured to use it)
Find the block size for hugepages by running
cat /proc/meminfo | grep -i hugepagesizeFor example, I want to dedicate 3GB of RAM for hugepages. So the number of hugepages would be
(3*1024*1024)/2048Restart the server and check if hugepages has been enabled by running
cat /proc/meminfo | grep -i hugeConfigure the number of hugepages on the system by editing the /etc/sysctl.conf and adding the option
vm.nr_hugepages = 1536(note: I put in 1536 since that was the value I got from the above example)
You should see something like this
AnonHugePages: 839680 kB
HugePages_Total: 1500
HugePages_Free: 1500
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kBJBOSS CONFIGURATION
- At this point your system is configured with hugepages and any application that is configured to use them can leverage them. In this example, we want to configure Jboss to utilize these hugepages
- Restart Jboss and you are good to go
Finally add the following to the Jboss startup parameters. I edited the $JBOSS_HOME/bin/run.sh file. (note: the startup file can be different based on your config) with the option
-XX:+UseLargePagesNext allocate the memory to the user by editing /etc/security/limits.conf and allocating the memory. Again, in my case, I added the following to /etc/security/limits.conf
# Allocate memory for Jboss user to take advantage of hugepages
jboss soft memlock 1500
jboss hard memlock 1500Add the groupid of the user that Jboss is running under to the /etc/sysctl.conf file. In my case, the jboss user group had a GID of 505, so I added this line to /etc/sysctl.conf
vm.hugetlb_shm_group = 505note : A lot articles that I read online say that hugepages are effective when you are allocating large amounts of RAM to the application. The use case of just using 3GB above was just that.. a use case.
While I cannot personally vouch for it, a lot of users have noted that they saw >2 fold increase in performance.
HOW TO : Configure Jboss to use hugepages in RHEL/CentOS
Most of us worry about paging to disk (swap), but if you are running a transaction intensive application the paging that happens in RAM also starts...