Pages

Sunday, February 4, 2018

Huge Pages and Oracle

=====================
What are HugePages
=====================
HugePages is a feature integrated into the Linux kernel 2.6. 
By default Linux memory page size is 4K
With HugePages, the memory page may be between 2Mb and 1024Mb - depending on OS version and HW.

=====================
HugePages and Oracle
=====================
For large SGA sizes, HugePages can give substantial benefits in virtual memory management. 

Without HugePages, the memory of the SGA is divided into 4K pages, which have to be managed by the Linux kernel.
With HugePages, the page size is increased, thereby reducing the total number of pages to be managed by the kernel. 

Therefore reducing the amount of memory required to hold the page table in memory. 
In addition to these changes, the memory associated with HugePages can not be swapped out, which forces the SGA to stay memory resident.
This maked HugePages pretty much standard for Oracle 11g systems running on Linux x86-64.

=====================
TLB and HugePages
=====================
TLB - Translation Lookaside Buffer hit ratio.
TLB is a memory cache that is used to reduce the time taken to access a user memory location
It is a part of the chip’s memory-management unit (MMU)
When using HugePages, the kernel has fewer pages whose lifecyle must be monitored.
It increases the TLB hit ratio, since operating system maintenance of page states is reduced. 

Oracle Documentation: Overview of HugePages




=====================
How see current settings
=====================
Current HugeSpaces usage:

New HugePages Metrics
AnonHugePagesThe number of pages that the newer Transparent Huge Page mechanism currently has in use.


Old HugePages mechanism metrics:
HugePages_Total - How many HugePages could be (MAX Value).
The HugePages_Free - How many pages are available for allocation.
The number of used HugePages is HugePages_Total–HugePagesFree.


>% grep -i HugePages /proc/meminfo
AnonHugePages:     81920 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

AnonHugePages - The AnonHugePages entry lists the number of pages that are currently has in use. In this example: 81920/2048=40 pages

Hugepagesize - The size of a single Huge Pages

Another option to see current HugePages usage:
>% less /proc/vmstat | grep trans
nr_anon_transparent_hugepages 40

Is HugePages enabled:
>% less /sys/kernel/mm/redhat_transparent_hugepage/enabled
always madvise [never]
always or madvise - used
never - not used


Linux Processes kswapd0 and khugepaged 
kswapd0
The process kswapd0 is the process than manages virtual memory. 
When you run low on memory, kswapd0 moves programs that are LRU to the SWAP.
This would causes extreme lag on those processes. 

khugepaged 
Huge page collapse operation.
It converts a set of normal-sized pages into a single huge page. 
It is desirable to have a range of addresses need fewer TLB entries, but the conversion process is expensive because the system needs to find a candidate set of pages to group together and then copy all the memory from the possibly scattered normal-sized pages into a single huge page. 
The khugepaged kernel thread searches for candidates pages to collapse into a single huge page. 
Even if khugepaged is not successful converting normal-sized pages into huge pages it may still be taking processor time to search for candidate pages. 
You can see if the khugepaged kernel thread is taking a significant amount of processor time with:
top -p `pidof khugepaged`

=====================
HugePages and SWAP 
=====================
When allocating space with HugePages enabled, and in case of a buggy application, which allocate memory, the server might run out of memory, including out of SWAP space.

No comments:

Post a Comment