Giant page
Why use giant pages?
When a process uses some memory, the CPU marks that portion of memory as being used by the process. To improve efficiency, the CPU allocates memory in 4K bytes, which is the default value on many platforms. These blocks are called pages. These pages can be swapped to disk, and so on.
Because the process address space is virtual, the CPU and the operating system have to remember which page belongs to which process and where it is stored. Obviously, the more pages you have, the more time you'll have to look for the places where the memory is mapped. If a process uses 1GB of memory, it has to look for 262144 (1gb/4k) entries. If a page table entry occupies 8 bytes, then you have to look for 2MB (262144*8).
Most of the current CPU architectures support larger pages (so Cpu/os to find fewer entries), which are called giant pages (Huge pages) on Linux and are called Super Pages in BSD, which is called a large page on Windows (Large Pages), they are all the same thing.
Directory
- Enable Hugetlbpage
- Limits.conf
- Multiple huge page size support
- Arm64
- x86_64
- Get information
- Giant Page Size
- Tools
- Apps that support giant pages
- Mysql
- Java (Sun, OpenJDK)
- Memcached
- PostgreSQL
- Virtualization of
- See
To learn more about Hugetlbpage, please read this document.
Enable Hugetlbpage
Currently, there is no standard way to enable HUGETLBFS, mainly because FHS (file system architecture standard) does not have the relevant provisions of this virtual file system. See 572733. (Fedora mounts it on/dev/hugepages, so don't be surprised if you see some examples of using this location on the Internet)
Debian has been supporting the "giant Page table" (hugetlb) from Debianlenny (in fact, from 2.6.23). Detailed large-page descriptions can be found on the ibm.com.
- Create a giant page user group, and get its GID (this is the example, 2021), and then add yourself to this group.
Note: Libvirt does not need to do this. (See/ETC/LIBVIRT/QEMU.CONF)
% groupadd my-hugetlbfsgetent Group my-hugetlbfsmy-hugetlbfs:x:2021:% AddUser Franklin my-hugetlbfsadding user ' Franklin ' to Group ' My-hugetlbfs' ... Adding user Franklin to group my-hugetlbfsdone.
- Edit/etc/sysctl.conf and add this text to specify the number of pages you want to reserve (see Pages-size).
the for # Members of the Group My-hugetlbfs (2021"huge" 2021
- Create a mount point for this file system.
mkdir /hugepages
- Add this line of code to/etc/fstab (mode=1770 allow anyone within the group to create files, but not to unlink or rename files between them).
Hugetlbfs/hugepages hugetlbfs mode=1770, gid=202100
- Reboot (This is the most reliable way to allocate giant pages before memory fragmentation.) Instead of having to reboot, you can try to execute sysctl-p to apply the changes. If grep "Huge"/proc/meminfo does not show all pages, you can try to perform sync; Echo 3 >/proc/sys/vm/drop_caches (3 means clear page cache, dentries and inodes) to free up the cache, and then try to execute sysctl-p again.
Limits.conf
You should configure the amount of memory a user can lock so that an application does not crash the operating system by locking all memory. Note that not only giant pages can be locked, but any page in memory can be locked. You should allow the process to lock a bit more memory (just the huge page space).
# # Get huge-page size:grep"hugepagesize:" /proc/ Meminfohugepagesize: 4096 kb##What's the currentlimit% ulimit-h- L - Do you want to allocate?)
See Limits (Memlock in Ulimit-l and/etc/security/limits.conf).
Multiple huge page size support
Some schemas, such as ia64, can have multiple and/or configurable (giant) page sizes.
(TODO)
See:
- The startup parameters and mount options in Hugetlbpage.txt in the file compilation.
Arm64
The Debian arm64 kernel (run with 4KB standard page_size) supports 2MB and 1GB hugetlb page sizes. One is to specify the parameters on the kernel command line so that the 1GB hugetlb page is pre-allocated at startup. The following text will be pre-allocated for 10*1GB's giant page.
hugepagesz=1g hugepages=
If someone decides to use config_arm64_64k_pages=y to build their own Debian arm64 kernel, then only the 512MB hugetlb (and THP) pages can be used. These are available at run time.
x86_64
Depending on the processor, there are at least two different giant page sizes on the x86_64 architecture: 2MB and 1GB. If the CPU supports 2MB pages, it will have the PSE flag in the Cpuinfo, and if the 1GB page is supported, it will have the PDPE1GB flag. The/proc/cpuinfo shows whether the two flags are set.
If the following command returns a non-empty string, the 2MB page is supported.
grep Uniq flags : [...] PSE [...]
If the following command returns a non-empty string, the 1GB page is supported.
grep Uniq flags : [...] PDPE1GB [...]
If you want both to be available, you may need to activate them at startup. The following kernel boot parameters enable 1GB pages and create a 1GB page pool.
HUGEPAGESZ=1GB hugepages=1
After startup, the giant page pool looks like this:
% hugeadm--pool-list Size Minimum current Maximum Default 2097152 0 0 0 *1073741824 1 1 1
Get information
You can use Hugeadm to get a list of available giant page sizes:
% Hugeadm--page-sizes-all20971521073741824
Hugeadm also displays the assigned quantity for each available size:
% hugeadm--pool-list Size Minimum current Maximum Default 2097152 0 0 0 *1073741824 1 1 1
Another way to get the currently available/used pages for the default giant page size is to view/proc/meminfo:
grep huge/proc/meminfo hugepages_total: hugepages_free: HUGEPAGES_RSVD: 0hugepages_surp :0hugepagesize: 4096 KB
(For more information on giant pages, please read the literature/vm/hugetlbpage.txt)
The standard Debian kernel has hugetlb enabled (Lenny?). Where's Xen? ):
grep hugetlb/boot/config-$ (uname -r) Config_hugetlbfs=yconfig_hugetlb_page=y
Various runtime settings (see documentation).
grep " " /sys/kernel/mm/hugepages//proc/sys/vm/*huge*/sys/kernel/mm/hugepages/hugepages-4096kb/ nr_hugepages:256/sys/kernel/mm/hugepages/hugepages-4096kb/nr_overcommit_hugepages:0/sys/kernel/mm/hugepages/ hugepages-4096kb/free_hugepages:256/sys/kernel/mm/hugepages/hugepages-4096kb/resv_hugepages:0/sys/kernel/mm/ Hugepages/hugepages-4096kb/surplus_hugepages:0/proc/sys/vm/hugepages_treat_as_movable:0/proc/sys/vm/hugetlb_ shm_group:0/proc/sys/vm/nr_hugepages:256/proc/sys/vm/nr_overcommit_hugepages:0
Big page Size
| System architecture |
Big page Size |
| Arm64 |
4 K, 2M, 1G (or 64K and 512M if you build your own kernel with config_arm64_64k_pages=y) |
| I386 |
4M, 4M (2M in PAE mode) |
| Ia64 |
4 K, 8K, 64K, 256K, 1M, 4M, 16M, 256M |
| Ppc64 |
4 K, 16M |
Tools
The LIBHUGETLBFS library provides a simple way to access huge pages of memory. It also includes a number of user space tools to enhance the ease of use of the giant pages, environment settings and controls, and more.
http://libhugetlbfs.ozlabs.org/
533708-ITP:LIBHUGETLBFS--Initial Package Request
Http://www.ibm.com/developerworks/wikis/display/LinuxP/libhuge+short+and+simple
The Hugetlb (and other applications) of PostgreSQL is informal
http://oss.linbit.com/hugetlb/
Applications that enable giant pages
An application can allocate/use Hugetlbpage in two different ways:
- With the appropriate permissions, after mounting the HUGETLBFS, use the system call mmap;
- Shared memory segments (using system calls in MAP_TLB environments Shmat/shmget or mmap) must be a group member, configured in/proc/sys/vm/hugetlb_shm_group.
| Application |
Hugetlbfs |
Shared memory |
| Qemu/kvm |
Is |
Whether |
| Mysql |
Whether |
Is |
| Java |
Whether |
Is |
Mysql
(TODO), see:
- Enable large page support:http://dev.mysql.com/doc/refman/5.1/en/large-page-support.html
Linux HUGETLBFS: Improving MySQL database application performance
Http://www.cyberciti.biz/tips/linux-hugetlbfs-and-mysql-performance.html (not tested)
Java (Sun, OpenJDK)
Sun and OpenJDK can use large pages.
- Sun-java6-bin-sun Java (TM) Runtime Environment (JRE) 6 (architecture-dependent files)
- OPENJDK-6-JRE-HEADLESS-OPENJDK Java runtime, using Hotspot JIT (headless)
(TODO)
In general, to enable giant pages, it seems like you have to run Java with the-xx:+uselargepages option. The upper-bound size of the Java heap (-XMX) should accommodate the huge pages you have reserved, using Memlock in Ulimit-l and/or/etc/security/limits.conf.
See:
- Java support for large memory pages-Sun:http://java.sun.com/javase/technologies/hotspot/largememory.jsp
- Configuration of large page memory allocations-IBM User Guide for Java V6 on Linux:http://publib.boulder.ibm.com/infocenter/javasdk/v6r0/index.jsp?topic=/ Com.ibm.java.doc.user.lnx.60/user/alloc_large_page.html
Possible errors:
- The/proc/sys/kernel/shmmax of the function is not complete?
- Not in a group but defined in/proc/sys/vm/hugetlb_shm_group
% java-xx:+1).
Memcached
Memcached can use giant pages, please read the man page:
Memcached-l
Try using a large memory page (if available). Increasing the memory page size can reduce the number of TLB misses and improve performance. In order to get large pages from the operating system, memcached will allocate all the item caches to a large page block. Only available when your operating system supports large pages.
PostgreSQL
PostgreSQL supports giant pages starting from version 9.4. For the previous version, see hugetlblib above.
Virtualization of
Some suggestions for giant page virtualization:
- Before you enable a giant page on a virtual machine, you must make sure that your virtualization tool can handle it;
- For a virtualization tool, whether its client supports giant pages, and whether it natively supports giant pages, can be two different aspects.
Kvm
(TODO), see:
- Http://fedoraproject.org/wiki/Features/KVM_Huge_Page_Backed_Memory
- Support your KVM customers with HUGETLBFS for improved performance:http://www.linux-kvm.com/content/ GET-PERFORMANCE-BOOST-BACKING-YOUR-KVM-GUEST-HUGETLBFS (not tested)
Xen
(TODO)
It's not clear which version of Xen is starting to support giant pages and how it is used.
- See also: Http://zhigang.org/wiki/XenHugePages
Description: This article is translated from Https://wiki.debian.org/Hugepages. Due to the limited level of English, the statement is not fluent, please understand.
"Debian Encyclopedia" giant page