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

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
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
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

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 Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.