Oracle Hugepages by Amanpandey
Oracle Hugepages by Amanpandey
Oracle
Memory
Management
Huge Pages, Swap and
Dynamic Memory
Aman Pandey
LinkedIn Profile
Introduction to Oracle's Dynamic Memory Management
• Oracle Database relies heavily on physical RAM to execute queries, manage data, and
perform background tasks efficiently. It dynamically adjusts its memory usage based on the
system's workload, which allows it to operate optimally under different conditions.
• The goal is to keep as much data and execution information in RAM as possible to avoid
slower disk I/O. This dynamic memory management includes handling critical components
such as the System Global Area (SGA) and Program Global Area (PGA), which allow Oracle
to process transactions swiftly by utilizing available physical memory.
Oracle uses two primary memory structures: the SGA and PGA.
o A shared memory region that stores data and control information for the entire
Oracle instance.
▪ Database Buffer Cache: Caches the most frequently accessed data blocks.
▪ Redo Log Buffer: Temporarily stores redo log entries before writing them to
disk.
• Example Output When Starting Oracle: When Oracle starts up, it allocates memory
dynamically based on predefined parameters. Here’s an example of the startup log showing
memory allocation:
• Explanation:
o Total System Global Area: The overall memory allocated to Oracle’s shared memory
structures (SGA).
o Variable Size: This is the dynamically managed portion of the SGA, which adjusts
based on workload (includes shared pool and buffer cache).
o Redo Buffers: Space for logging changes before they are written to disk.
This output shows that Oracle dynamically allocates memory for its internal components, ensuring
efficient handling of data and queries.
• Kernel-Level Memory Limits for Oracle: To prevent Oracle from over-consuming system
resources, administrators set certain limits at the kernel level, which governs how much
shared memory Oracle can use.
These parameters must be set properly in the Linux kernel to ensure Oracle can allocate the
necessary memory without hitting system limits. For example:
• Process Memory in Oracle (Stack, Heap, BSS, Data, Text) A process in Oracle, like any other
process in a Linux system, has various memory segments:
o Stack: This is the area of memory used for managing function calls, local variables,
and flow control. In Oracle, each process has its own stack.
o Heap: The heap is the memory dynamically allocated during runtime (e.g., for
queries or operations requiring large amounts of temporary memory).
o BSS (Block Started by Symbol): This section stores uninitialized global variables.
Out-of-Memory Scenario:
o In certain cases, particularly when there’s memory pressure, the heap and stack
segments can collide. This happens when both grow towards each other within the
same address space.
o In Oracle, if a process requests more memory than is available in the heap or stack,
this can lead to an Out of Memory (OOM) error. This is especially true in scenarios
with large, complex queries that demand extensive memory allocation (heap) and
deep recursion or function calls (stack).
Example: Suppose a large query in Oracle requires substantial memory allocation for joins or sorting
(heap), while at the same time, deep recursive PL/SQL function calls are being made, leading to
significant stack usage. As both memory segments expand, they may collide, resulting in an OOM
error if they exhaust the available process memory.
Oracle and Memory Management — Huge Pages, Swap, and
Dynamic Memory
Huge Pages is a feature of the Linux kernel that allows larger memory pages to be used for managing
memory instead of smaller default-sized pages (usually 4KB). Huge Pages are typically 2MB or larger,
depending on the hardware and kernel version. The key idea behind Huge Pages is to reduce the
overhead associated with managing large numbers of small pages, especially when dealing with large
memory areas like Oracle’s SGA (System Global Area).
For Oracle databases with large SGAs (starting from 2GB or more) or systems with many concurrent
sessions, the number of page table entries (PTEs) required to manage regular-sized pages becomes
unmanageable. This results in high overhead, increased memory consumption, and performance
degradation.
• Example Scenario:
Imagine an Oracle database with an SGA size of 25GB and 500 sessions. If regular 4KB pages
are used, the number of page table entries becomes enormous, causing memory
inefficiency. Huge Pages significantly reduce this overhead by consolidating multiple 4KB
pages into fewer, larger pages.
In a typical Linux system, memory is divided into small 4KB pages. These pages are tracked by the
operating system through page tables, which map virtual addresses to physical memory addresses.
When Oracle’s SGA grows large, managing these small 4KB pages leads to inefficient use of system
resources, especially in memory-intensive applications.
With Huge Pages, each page is much larger (e.g., 2MB or more). This means fewer pages and fewer
entries in the page table, leading to more efficient memory management.
o Huge Pages reduce the number of pages the operating system needs to manage.
This leads to a smaller page table, reducing the overhead involved in managing and
maintaining page entries. (shown in examples, sec5)
• Faster Memory Operations:
o Since the system has fewer pages to manage, operations like memory lookups and
TLB (Translation Lookaside Buffer) hits are faster, improving the overall performance
of the database.
• Pinned Memory:
o Huge Pages remain pinned in memory, meaning they are not swappable. This
eliminates the risk of slow page-in/page-out operations and reduces the CPU
workload that manages page swapping (i.e., kswapd).
Example:
For a database with an SGA of 25GB and 500 sessions, without Huge Pages, the memory usage can
grow significantly due to the size of the page tables. With Huge Pages, the same database will require
fewer PTEs, resulting in more efficient memory usage and improved performance.
To configure Huge Pages, several kernel parameters need to be set, and the database needs to be
restarted for changes to take effect.
o Reboot the system to apply the changes and allocate Huge Pages.
o After the system restarts, check if Huge Pages have been properly allocated:
o Oracle can throw ORA-4030 (out-of-memory) errors when page tables grow too
large and consume more memory than expected. Huge Pages reduce this overhead,
making more memory available for Oracle processes.
RAM 5.9GB
SWAP 6GB
Oracle DB Version 19.22
SGA – PGA 1315MB – 280MB
o Huge Pages are not compatible with Automatic Memory Management (AMM) in
Oracle. To use Huge Pages, you must disable AMM by setting the MEMORY_TARGET
and MEMORY_MAX_TARGET initialization parameters to 0.
o Regularly monitor your Huge Pages configuration to ensure that the number of pages
allocated matches the memory requirements of your database instances. If you
increase the SGA or add new instances, you may need to adjust the number of Huge
Pages allocated.
• No Swapping:
o While the non-swappable nature of Huge Pages is a benefit, it can also lead to
system memory exhaustion if not configured correctly. If the number of Huge Pages
allocated exceeds the required amount, memory reserved for Huge Pages becomes
unavailable for other system processes, leading to out-of-memory conditions for
non-Oracle applications.
• Requires Kernel Tuning:
o Configuring Huge Pages requires careful tuning of kernel parameters, which can be
complex for administrators unfamiliar with the Linux kernel or memory
management.