4

On one of my Debian machines I'm running a service on a JVM and a MySQL instance. I have enable the HugePages following various online guides but I'm having a problem.

Here is my configuration:

vm.nr_hugepages = 2816
vm.nr_overcommit_hugepages = 128
vm.hugetlb_shm_group = 1002
kernel.shmmax = 5905580032
kernel.shmall = 1441792

UPDATE: My machine is a guest VM on top of VMWare ESX, with assigned 2 CPUs and 6GB of RAM. I reserved 512MB or RAM for the system and the remaining (5.5GB, 5905580032bytes as seen in kernel.shmmax) is assigned 3GB to the JVM and 2.5GB to MySQL. Therefore I reserved 5.5GB / 2MB = 2816 number of huge pages

The access to the memory is allowed for the group "services" (gid=1002). MySQL and the JVM run with different users that are both members of this group "services", as primary group:

uid=106(mysql) gid=1002(services) groups=1002(services),111(mysql)
uid=1001(java) gid=1002(services) groups=1002(services),1003(java)

HugePages are enabled and they work. The problem is that only one application at the time seems to be able to use them! If I first start mysql, then the jvm will not be able to use it and vice versa.

service mysql start -> OK
service java start -> Fallback to normal memory

or

# service java start -> OK
# service mysql start -> Failure, can't allocate memory

How can I do it? Am I mistaken somewhere? Can it even be done?

There are no requirements to create a separate machine for Java and for MySQL, therefore I'm keen to keep both services on the same machine.

UPDATE: At the moment I'm doing some memory profiling to decide if it'd better to allocate the HugePages to the JVM or to MySQL. Or is there a quick answer to this?

Thank you

ColOfAbRiX
  • 1,080
  • 2
  • 12
  • 23

1 Answers1

2

You dont mention your distro/kernel version, but it may be worth noting that recent kernels (2.6.38+) have a feature called transparent hugepages.

You can tell if it is enabled using:

cat /sys/kernel/mm/transparent_hugepage/enabled

It pretty much takes all this burden managing and preallocating hugepages of you.

You can see how much memory is allocated using which page size by running

cat /proc/meminfo | grep AnonHugePages

or

egrep 'trans|thp' /proc/vmstat

per process usage

grep -e AnonHugePages  /proc/*/smaps | awk  '{ if($2>4) print $0} ' |  awk -F "/"  '{print $0; system("ps -fp " $3)} '

Last three commands taken from RHEL6 support

Interesting info on Transparent HugePages and JVM.

Fox
  • 3,977
  • 18
  • 23
  • HugePages are enabled and they work. But they work only for one service at the time. I'd like to have both MySQL and the JVM using it, but at the moment only one can use it and I don't know the reason – ColOfAbRiX Apr 29 '15 at 16:45
  • What I am suggesting is - modern kernel does not need any tuning and tweaking to use hugepages. You just need `transparent_hugepages` enabled. That way you can forget about permissions, services or whatever. It automagically works.;-) – Fox Apr 29 '15 at 16:52
  • Great then! I'll have a look asap – ColOfAbRiX Apr 29 '15 at 16:53
  • Transparent hugepage is now enabled and set to "always": `DirectMap2M: 6244352 kB`. Is there a way to know if my services are actually using it? – ColOfAbRiX Apr 29 '15 at 17:25
  • This may help https://access.redhat.com/solutions/46111 – Fox Apr 29 '15 at 18:21
  • @ColOfAbRiX And just looking at your original problem - do you have enough hugepages to support both JVM and MySQL? MySQL should [log](https://github.com/ottok/mariadb-10.0/blob/master/mysys/my_largepage.c#L130) the reason, why it could not use hugepages. – Fox Apr 29 '15 at 19:56
  • Yes. I'll update my initial answer – ColOfAbRiX Apr 29 '15 at 20:55
  • 1
    I confirm the processes are using the hugepages. Thanks! – ColOfAbRiX Apr 29 '15 at 21:49