Thursday 12 April 2012

Understanding Linux Hugepages

Hugepages can be extremely useful for systems having bigger RAM.
$ grep Huge /proc/meminfo
HugePages_Total:         0
HugePages_Free:          0
HugePages_Rsvd:          0
HugePages_Surp:          0
Hugepagesize:         2048 kB

Hugepagesize is the size of one Hugepage, on most x86 or x86_64 machines,  it's set to 2048 kB.
HugePages_Total is the number of Hugepages configured on the machine. In Redhat Linux, we can change this value by updating /etc/sysctl.conf
echo "vm.nr_hugepages = 200" >> /etc/sysctl.conf
 After updating, /sbin/sysctl -p may make the setting take effect, but it's better to restart the machine.

To confirm Hugepages is configured after rebooting,
$ grep Huge /proc/meminfo
HugePages_Total:       200
HugePages_Free:        200
HugePages_Rsvd:          0
HugePages_Surp:          0
Hugepagesize:         2048 kB

By setting Hugepages to 200, we are telling linux to reserve 200 Hugepages. So the memory associated with Hugepages is: HugePages_Total x Huagepagesize = 200 x 2048kB = 400M.
The memory associated with Hugepages is always allocated, and it cannot be swapped out.

Before setting Hugepages,
$ grep Mem /proc/meminfo
MemTotal:                1030940 kB
MemFree:                  861852 kB
After setting Hugepages, check memory usage again:
$ grep Mem /proc/meminfo
MemTotal:                1030940 kB
MemFree:                  452252 kB
We can see that the free memory dropped from 841M to 441M, after setting HugePages_Total to 200. The 400M memory is the associated to Hugepages, and it will always be allocated.

We can use Hugepages to lock some memory for oracle SGA, so the SGA will never be paged out, thus improving the database performance.

No comments:

Post a Comment