Memory is one of the core parts of the operating system which store the data however the memory is always volatile but still it helps to reduce to provide lower latency and high throughput while reading the data because memory IO is always faster than the Disk IO.
How Kernel Manages Memory
The kernel manages the memory in the form of pages or alternatively we can say that the storage unit in memory is pages and the default size of each page is 4KB which is suitable for most of the software to run without any issue and those pages are manage by the memory management unit of CPU.
How MMU Manage Pages
The MMU basically uses the
page table inside the CPU where it stores the page table’s entries to store the
page addresses however if the memory size is huge then in that case the overhead
of managing page table entries will get increase and in that case the server performance
will start degrading.
For e.g.
2 TB Memory
= 2*10^9/4KB = 50 million pages, what
about the situation when the memory is in several TB and MMU has to manage all
those pages size and in addition to that what about the software which actually
requires more than 4KB of page size to run properly.
Can We Configure More Than 4KB Of Page Size
Yes, we can configure the
page’s size of more than 4KB like 8kb,16kb etc. however there is also a
disadvantage of configuring the page’s size of greater than the default size, for
e.g. if any software is running under the O/S which require only 4kb of pages
size to run then in that case there will be a wastage of memory. So, configuring
the pages greater than the standard size depends upon requirement to
requirement within the organization.
Whenever we enable the
huge pages then the kernel will create a separate memory structure inside the physical
available memory and the software which require the pages size of greater than
4KB they start using that separate memory structure in the form of huge pages. For
e.g. in oracle Exadata system where the memory is in several TB and also the default
block size is 8KB which is greater than the standard block size of O/S.
What Happen If We Don’t Use Huge Pages In Oracle
The default block size in
oracle is 8KB which means that a single block will not get fit into a single
page due to which MMU also has to manage the multiple page entries for a single
database block which eventually lead to degrading the database performance and even
when Exadata system comes into role where the memory is in several Terabytes then
it can also become more challenging for O/S to
manage the database block information , so to overcome this issue Linux kernel
provide the feature of huge pages so that the databases running inside Exadata machine
can use that huge pages to manage the database block.
Points To Consider While Configuring HugePages
The most important point
that any DBA and system admin must have to consider while configuring the huge
pages is that the total size of the SGA for all the databases running in a
server collectively must not exceed the total no. of huge pages available, otherwise
the database will fail to start due to the lack of huge pages availability
still it depends upon the parameter that we’ve set inside the database system
to use huge pages configuration. For E.g. if the collective size of SGA for all
the database available in the server will be 100GB then the availability of
huge pages should be 102400/2MB=51200 huge
pages must be available into the server.
The usage of huge pages by
the database system always depends upon the parameter use_large_pages
however there are several values that can be set for this parameter and
on the basis of that the database’s system decides how to use available huge
pages.
FALSE: setting the value to false means that the database will not use huge pages and this is not recommended by the oracle especially in the case of large SGA size to achieve better performance.
TRUE: setting the parameter value to true instruct the
database to allocate the memory from the huge pages first prior to allocate the
memory from the standard page size.
AUTO: setting this parameter value to auto instruct the
database to automatically configure the require huge pages for the database and
then start using O/S page if the huge page is not sufficiently available. Setting
this value is not recommended however this value is use to eliminate the coordination
between DBA and system admin.
ONLY: This is the most recommended value by the oracle to
use huge page by the database system because setting the parameter value to
ONLY will instruct database to use only the pages resides inside the huge pages
and if the sufficient huge page will not be available then the database system
will fail to start.
AUTO_ONLY: setting the parameter value to AUTO_ONLY
automatically determine huge page required for database to start and it also
only uses the huge pages resides inside the available huge pages.
How
To Configure HugePages
Huge pages usually require
server bounce if we’re not doing either from super user or from root, however
if we’re executing it from root user then we can run systemctl
-p after configuring the huge pages and the value will start get
reflecting.
[root@ORATEST ~]# echo "vm.nr_hugepages=2048" >>
/etc/sysctl.conf
[root@ORATEST ~]# cat
/etc/sysctl.conf
vm.nr_hugepages=2048
[root@ORATEST ~]# sysctl -p
vm.nr_hugepages = 2048
AnonHugePages: 178176 kB
ShmemHugePages: 0 kB
FileHugePages: 0 kB
HugePages_Total: 753
HugePages_Free: 753
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 1542144 kB
753 *2M = 1506MB of huge pages will be available for SGA.