Search This Blog

Thursday, May 27, 2010

Huge Page Setup On Linux

Contents [hide]
1 What is hugepages and What are its advantages?
2 What is required for an application or program to be able to take advantage of hugepages?
3 Follow the following steps to enable Oracle to start using Hugepage.
4 How do I set up hugepages in Red Hat Enterprise Linux 4?

[edit]
What is hugepages and What are its advantages?

Hugepages is a mechanism that allows the Linux kernel to utilise the multiple page size capabilities of modern hardware architectures. Linux uses pages as the basic unit of memory – physical memory is partitioned and accessed using the basic page unit. The default page size is 4096 Bytes in the x86 architecture.


Hugepages allows large amounts of memory to be utilised with a reduced overhead. Linux uses a mechanism in the CPU architecture called “Transaction Lookaside Buffers” (TLB). These buffers contain mappings of virtual memory to actual physical memory addresses. The TLB is a limited hardware resource, so utilising a huge amount of physical memory with the default page size consumes the TLB and adds processing overhead.


The Linux kernel is able to set aside a portion of physical memory to be able be addressed using a larger page size. Since the page size is higher, there will be less overhead managing the pages with the TLB.


In the Linux 2.6 series of kernels, hugepages is enabled using the CONFIG_HUGETLB_PAGE feature when the kernel is built. All kernels supplied by Red Hat for the Red Hat Enterprise Linux 4 release have the feature enabled.


Systems with large amount of memory can be configured to utilise the memory more efficiently by setting aside a portion dedicated for hugepages. The actual size of the page is dependent on the system architecture. A typical x86 system will have a Huge Page Size of 2048 kBytes. The huge page size may be found by looking at the /proc/meminfo :
# cat /proc/meminfo |grep Hugepagesize
Hugepagesize: 2048 kB


[edit]
What is required for an application or program to be able to take advantage of hugepages?

To take advantage of hugepages, an application needs to use the shmget() or shmat() type system calls. Examples of the use of the system call are available in the kernel-doc package in the file /usr/share/doc/kernel-doc-2.6.9/Documentation/vm/hugetlbpage.txt


An alternative of using shmget() type system calls is to mount a hugetlbfs file system at a mount point. With a hugetlbfs mounted, an application then utilities the mmap() system call to map memory to the mount point. Details on how this is done, including both specific mount commands, and code that illustrates the system calls in use are also in the file /usr/share/doc/kernel-doc-2.6.9/Documentation/vm/hugetlbpage.txt


[edit]
Follow the following steps to enable Oracle to start using Hugepage.

1.Hugepage counting formula
(SGA_SIZE/2M ) + 100

So for 10G SGA hugepage should be set to ,
((10*1024)M / 2M ) + 100 = 5220

You can find SGA size from show sga command on sqlplus prompt.

2.Please put following kernel parameter into /etc/sysctl.conf file.
vm.nr_hugepages = 5220

3.Run the following command.
#sysctl -p

4. Modify /etc/security/limits.conf file to have following entry.
oracle soft memlock 20086560
oracle hard memlock 20086560

Then Reboot the machine.

5.Check the Hugepage Total and Hugepage Free using following command.
#cat /proc/meminfo | grep -i huge

This should return like following.
HugePages_Total: 5220
HugePages_Free: 5220
HugePages_Rsvd: 00
Hugepagesize: 2048 kB


Also check the memlock setting using ulimit -a command.

6.Start the Oracle DB and check whether Hugepage is getting allocated or not by using following command.
#cat /proc/meminfo | grep -i huge


[edit]
How do I set up hugepages in Red Hat Enterprise Linux 4?

Hugepages can be allocated using the /proc/sys/vm/nr_hugepages entry, or by using the sysctl command.

To view the current setting using the /proc entry:
# cat /proc/sys/vm/nr_hugepages
0

To view the current setting using the sysctl command:
# sysctl vm.nr_hugepages
vm.nr_hugepages = 0

To set the number of huge pages using /proc entry:
# echo 5 > /proc/sys/vm/nr_hugepages

To set the number of hugepages using sysctl :
# sysctl -w vm.nr_hugepages=5
vm.nr_hugepages = 5

It may be necessary to reboot to be able to allocate all the hugepages that is needed. This is because hugepages requires large areas of contiguous physical memory. Over time, physical memory may be mapped and allocated to pages, thus the physical memory can become fragmented. If the hugepages are allocated early in the boot process, fragmentation is unlikely to have occurred.

It is recommended that the /etc/sysctl.conf file should be used to allocate hugepages at boot time. For example, to allocate 5 hugepages at boot time add the line below to the sysctl.conf file :
vm.nr_hugepages = 5

No comments: