Linux's introduction of large page memory has a good effect on reducing the failure of TLB, especially for memory-intensive programs, such as database usage. Innodb engine supports large page memory, specific use can see http://www.cyberciti.biz/tips/linux-hugetlbfs-and-mysq...
Linux's introduction of large page memory has a good effect on reducing the failure of TLB, especially for memory-intensive programs, such as database usage. The innodb engine supports large page memory. For more information, see http://www.cyberciti.biz/tips/linux-hugetlbfs-and-mysql-performance.html.
For more details about the large page, refer to: Documentation/vm/hugetlbpage.
In the past, we used huge page memory to mount the file system to a certain point through hugetlbfs, which is inconvenient to deploy. we just wanted to try Anonymous Pages. is it so troublesome?
The new 2.6.32 kernel uses the memory by supporting the MAP_HUGETLB mode, which avoids the cumbersome mount operation and is more user-friendly.
See man mmap:
MAP_HUGETLB (since Linux 2.6.32)
Allocate the mapping using "huge pages." See the kernel source file Documentation/vm/hugetlbpage.txt for further information.
This is obviously more convenient, but the operations reserved for large memory pages are still required. Let's demonstrate how to prepare the environment first:
# Uname-
Linux dr4000 2.6.32-131.17.1.el6.x86 _ 64 #1 SMP Wed Oct 5 17:19:54 CDT 2011 x86_64 x86_64 x86_64 GNU/Linux
# Cat/proc/meminfo | grep-I huge
AnonHugePages: 2048 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
# Sysctl vm. nr_hugepages = 192
Vm. nr_hugepages = 192
# Cat/proc/meminfo | grep-I huge
AnonHugePages: 2048 kB
HugePages_Total: 192
HugePages_Free: 192
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
From the above output, we can see that our kernel is 2.6.32, I use the RHEL 6U2 release version, and the 192*2 M page is retained.
The demo code is as follows:
# Cat huge. c
# Include
# Include
# Include
Int main (int argc, char * argv []) {
Char * m;
Size_t s = (8UL * 1024*1024 );
M = mmap (NULL, s, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | 0x40000/* MAP_HUGETLB */,-1, 0 );
If (m = MAP_FAILED ){
Perror ("map mem ");
M = NULL;
Return 1;
}
Memset (m, 0, s );
Printf ("map_hugetlb OK, press ENTER to quit! \ N ");
Getchar ();
Munmap (m, s );
Return 0;
}
# Gcc huge. c
#./A. out
Map_hugetlb OK, press ENTER to quit!
We successfully applied 8 MB memory and 4 large pages with large pages, and successfully cleared them at the same time. before munmap, we need to confirm that the memory is actually used by us.
Okay. switch to another window to see the following:
# Cat/proc/meminfo | grep-I huge
AnonHugePages: 2048 kB
HugePages_Total: 192
HugePages_Free: 188
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Is it possible to succeed without any effort, which also shows that the kernel is improving every day.
Have a good time!
Post Footer automatically generated bywp-posturl pluginfor wordpress.
This article is from the IT blog