Home Database Mysql Tutorial Hugepages你用了吗?--原理概念篇

Hugepages你用了吗?--原理概念篇

Jun 07, 2016 pm 05:41 PM
oracle

Hugepages你用了吗?----原理概念篇Hugepages你用了吗?----测试案例篇引子系统进程是通过虚拟地址访问内存,但是CPU必须把它转换程物理内存地址才能真正访问内


Hugepages你用了吗?----原理概念篇

     引子

     系统进程是通过虚拟地址访问内存,但是CPU必须把它转换程物理内存地址才能真正访问内存。为了提高这个转换效率,CPU会缓存最近的虚拟内存地址和物理内存地址的映射关系,并保存在一个由CPU维护的映射表中。为了尽量提高内存的访问速度,需要在映射表中保存尽量多的映射关系。
    而在Linux中,内存都是以页的形式划分的,默认情况下每页是4K,这就意味着如果物理内存很大,则映射表的条目将会非常多,会影响CPU的检索效率。因为内存大小是固定的,为了减少映射表的条目,可采取的办法只有增加页的尺寸。

一、hugepages及相关概念

    hugepage是在Linux2.6内核被引入的,主要提供4k的page和比较大的page的选择。

    有一些显示的概念需要澄清,香港虚拟主机,在我们继续讨论Hugepages之前, 如hugetlb, hugetlbfs

page table(页表)是操作系统上的虚拟内存系统的数据结构模型,用于存储虚拟地址与物理地址的对应关系。

当我们访问内存时,首先访问”page table“,然后Linux在通过“page table”的mapping来访问真实物理内存(ram+swap)

TLB: A Translation Lookaside Buffer (TLB)

TLB是在cpu中分配的一个固定大小的buffer(or cache),用于保存“page table”的部分内容,使CPU更快的访问并进行地址转换。

hugetlb: hugetlb 是记录在TLB 中条目并指向到Hugepage。所以HugePages 通过 hugetlb entries来调用的。

hugetlbfs: 这是一个新的基于2.6 kernel之上的内存文件系统,如同tmpfs。

在TLB中通过hugetlb来指向hugepage。这些被分配的hugepage作为内存文件系统hugetlbfs(类似tmpfs)提供给进程使用。

二、“regular page”和“huge page“的请求过程

当一个进程请求内存时,它需要访问文件系统的“页表”(Pagetable)去调用一个实际的物理内存地址

clip_image002

当Hugepage部署后,依然是调用普通的页表。 最大的不同是process pagetable和system pagetable增加了Hugepage属性。所以任何页表中的page条目可以是“regular page” 或者是“huge page”

clip_image004

HugePage 的尺寸根据内核版本和硬件架构从 2MB 到 256MB , 如下表

HW Platform

Source Code Tree

Kernel 2.4

Kernel 2.6

Linux x86 (IA32)

i386

4 MB

4 MB *

Linux x86-64 (AMD64, EM64T)

x86_64

2 MB

2 MB

Linux Itanium (IA64)

ia64

256 MB

256 MB

IBM Power Based Linux (PPC64)

ppc64/powerpc

N/A **

16 MB

IBM zSeries Based Linux

s390

N/A

N/A

IBM S/390 Based Linux

s390

N/A

N/A

三、 hugepage 优点

1. HugePages 会在系统启动时,直接分配并保留对应大小的内存区域

2. HugePages 在开机之后,如果没有管理员的介入,是不会释放和改变的。

3. Not swappable: HugePages 是不会swap.也就是没有page-in/page-out。HugePages一直被pin在内存中

4. Relief of TLB pressure:

在purge TLB的时候,减少了事物条目的加载,提高了性能。

使用Hugepages后TLB能覆盖更大的内存地址空间,加快地址转换的时间

更少的TLB条目,意味着有更大空间用来记录其他的地址空间

 

四. 如何配置Hugepages

   根据下面的步骤来配置Hugepages,修改Hugepages需要重启机器,使用请计划停机时间。

Step 1: 需要在/etc/security/limits.conf 中设置memlock值(单位KB),该值小于内存大小,例如你的内存大小是64G,有可以设置以下的值

*   soft   memlock    60397977
*   hard   memlock    60397977

这个值大于SGA需求并没有什么害处。

如果是Exadata机器,参数要求请参考文档1284261.1


Step 2: 重新登录root和oracle用户,检查memlock  limit

$ ulimit -l
60397977

Step 3: 如果你使用11G及以后的版本,AMM已经默认开启,但是AMM与Hugepages是不兼容的,必须先disable AMM。
-----------------------------------------------------------------

禁用memory_max_target和memory_target参数方法

这里注意,官方文档说的是“unset” ,直接alter system set memory_target=0 scope=spfile;是更改不成功的。直接设置为‘0’,就抱如下的错误

ORA-00843: Parameter not taking MEMORY_MAX_TARGET into account
ORA-00849: SGA_TARGET 35433480192 cannot be set to more than MEMORY_MAX_TARGET 0.
ORA-01078: failure in processing system parameters

通过创建pfile.ora文件,然后在文件里删除两个参数"MEMORY_TARGET/MEMORY_MAX_TARGET"。然后再创建spfile就可以了。

-----------------------------------------------------------------

Step 4:

确保你的全部实例都已经启动(包括ASM) ,然后根据Document 401749.1 的hugepages_settings.sh去评估需要设置的Hugepages的大小。

$ ./hugepages_settings.sh
...
Recommended setting: vm.nr_hugepages = 1496

注:也可以自己计算需要的Hugepages大小,其实就是Hugepages size> all of the SGA size
Step 5: 编辑/etc/sysctl.conf 设置 vm.nr_hugepages参数:

...
vm.nr_hugepages = 1496
...

Step 6: 停止实例并重启OS系统

Step 7:检查设置是否生效

系统重启后,启动全部的数据库,通过以下命令检查

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How long will Oracle database logs be kept? How long will Oracle database logs be kept? May 10, 2024 am 03:27 AM

The retention period of Oracle database logs depends on the log type and configuration, including: Redo logs: determined by the maximum size configured with the "LOG_ARCHIVE_DEST" parameter. Archived redo logs: Determined by the maximum size configured by the "DB_RECOVERY_FILE_DEST_SIZE" parameter. Online redo logs: not archived, lost when the database is restarted, and the retention period is consistent with the instance running time. Audit log: Configured by the "AUDIT_TRAIL" parameter, retained for 30 days by default.

Function to calculate the number of days between two dates in oracle Function to calculate the number of days between two dates in oracle May 08, 2024 pm 07:45 PM

The function in Oracle to calculate the number of days between two dates is DATEDIFF(). The specific usage is as follows: Specify the time interval unit: interval (such as day, month, year) Specify two date values: date1 and date2DATEDIFF(interval, date1, date2) Return the difference in days

The order of the oracle database startup steps is The order of the oracle database startup steps is May 10, 2024 am 01:48 AM

The Oracle database startup sequence is: 1. Check the preconditions; 2. Start the listener; 3. Start the database instance; 4. Wait for the database to open; 5. Connect to the database; 6. Verify the database status; 7. Enable the service (if necessary ); 8. Test the connection.

How to use interval in oracle How to use interval in oracle May 08, 2024 pm 07:54 PM

The INTERVAL data type in Oracle is used to represent time intervals. The syntax is INTERVAL <precision> <unit>. You can use addition, subtraction, multiplication and division operations to operate INTERVAL, which is suitable for scenarios such as storing time data and calculating date differences.

How to see the number of occurrences of a certain character in Oracle How to see the number of occurrences of a certain character in Oracle May 09, 2024 pm 09:33 PM

To find the number of occurrences of a character in Oracle, perform the following steps: Get the total length of a string; Get the length of the substring in which a character occurs; Count the number of occurrences of a character by subtracting the substring length from the total length.

How much memory does oracle require? How much memory does oracle require? May 10, 2024 am 04:12 AM

The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

How to replace string in oracle How to replace string in oracle May 08, 2024 pm 07:24 PM

The method of replacing strings in Oracle is to use the REPLACE function. The syntax of this function is: REPLACE(string, search_string, replace_string). Usage steps: 1. Identify the substring to be replaced; 2. Determine the new string to replace the substring; 3. Use the REPLACE function to replace. Advanced usage includes: multiple replacements, case sensitivity, special character replacement, etc.

Oracle database server hardware configuration requirements Oracle database server hardware configuration requirements May 10, 2024 am 04:00 AM

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.

See all articles