In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the example analysis of using and disabling transparent pages in Linux. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Introduction
With the increasing scale of computing requirements, applications have an increasing demand for memory. In order to realize the virtual memory management mechanism, the operating system manages the memory by page. Since the introduction of the memory "paging mechanism", the default size of memory pages has been set to 4096 bytes (4KB). Although the memory page size is configurable in principle, most operating system implementations still use the default 4KB pages. 4KB-sized pages were reasonable when the "paging mechanism" was proposed, because the memory size at that time was only a few tens of megabytes, but when the physical memory capacity increased to a few gigabytes or even tens of gigabytes, is it still reasonable for the operating system to take 4KB size as the basic unit of the page?
When running applications with large memory requirements on the Linux operating system, because the default page size is 4KB, there will be more TLB Miss and page fault interrupts, which will greatly affect the performance of the application. When the operating system uses 2MB or more as the paging unit, the number of TLB Miss and page fault interrupts will be greatly reduced, and the performance of the application will be significantly improved. This is the direct reason why the Linux kernel introduced large page support. The benefit is obvious, assuming that the application needs 2MB memory, and if the operating system uses 4KB as the paging unit, it needs 512 pages, which in turn requires 512 table items in TLB and 512 page table items. The operating system needs at least 512 TLB Miss and 512 page fault interruptions to map all 2MB application space to physical memory. However, when the operating system uses 2MB as the basic unit of paging, only one TLB Miss and one paging interrupt are needed to establish a virtual-real mapping for the application space of 2MB, and there is no need to experience TLB Miss and paging interruptions during operation (assuming no TLB item replacement and Swap occurs).
In order to realize large page support with minimum cost, Linux operating system adopts 2m byte large page support based on hugetlbfs special file system. This way of supporting large pages in the form of a special file system allows applications to flexibly choose the virtual page size as needed without being forced to use 2MB large pages.
When Redis starts in Linux, it usually sends a "WARNING you have Transparent Huge Pages (THP) support enabled in your kernel" warning message, which means: you are using a large transparent page, which may cause redis latency and memory usage problems.
For the big transparent page, let's take a look at the official introduction.
Transparent Huge Pages (THP) are enabled by default in RHEL 6 for all applications. The kernel attempts to allocate hugepages whenever possible and any Linux process will receive 2MB pages if the mmap region is 2MB naturally aligned. The main kernel address space itself is mapped with hugepages, reducing TLB pressure from kernel code. For general information on Hugepages, see: What are Huge Pages and what are the advantages of using them?
The kernel will always attempt to satisfy a memory allocation using hugepages. If no hugepages are available (due to non availability of physically continuous memory for example) the kernel will fall back to the regular 4KB pages. THP are also swappable (unlike hugetlbfs). This is achieved by breaking the huge page to smaller 4KB pages, which are then swapped out normally.
But to use hugepages effectively, the kernel must find physically continuous areas of memory big enough to satisfy the request, and also properly aligned. For this, a khugepaged kernel thread has been added. This thread will occasionally attempt to substitute smaller pages being used currently with a hugepage allocation, thus maximizing THP usage.
In userland, no modifications to the applications are necessary (hence transparent). But there are ways to optimize its use. For applications that want to use hugepages, use of posix_memalign () can also help ensure that large allocations are aligned to hugepage (2MB) boundaries.
Also, THP is only enabled for anonymous memory regions. There are plans to add support for tmpfs and page cache. THP tunables are found in the / sys tree under / sys/kernel/mm/redhat_transparent_hugepage.
Check if transparent large pages are enabled
1: command cat / sys/kernel/mm/redhat_transparent_hugepage/enabled this command applies to Red Hat Enterprise Linux systems
[root@getlnx06 ~] # more / etc/issue Red Hat Enterprise Linux Server release 6.6 (Santiago) Kernel\ r on an\ m [root@getlnx06 ~] # cat / sys/kernel/mm/redhat_transparent_hugepage/enabled [always] madvise never
2: command cat / sys/kernel/mm/transparent_hugepage/enabled this command applies to other Linux systems
[root@getlnx06 ~] # cat / sys/kernel/mm/transparent_hugepage/enabled always madvise [never] [root@getlnx06 ~] #
When viewing with the command, if the output is [always], the transparent large page is enabled. [never] indicates that transparent large pages are disabled, and [madvise] indicates that
3: how HugePages_Total returns 0 also means that transparent large pages are disabled
[root@getlnx06 ~] # grep-I HugePages_Total / proc/meminfo HugePages_Total: 0
A return of 0 for 4:cat / proc/sys/vm/nr_hugepages also means that transparent large pages are disabled.
[root@getlnx06 ~] # cat / proc/sys/vm/nr_hugepages 0
Disable and enable transparent large pages
Method 1: set the / etc/grub.conf file, which is disabled at system startup.
[root@getlnx06] # vi / etc/grub.conf# grub.conf generated by anaconda## Note that you do not have to rerun grub after making changes to this file# NOTICE: You have a / boot partition. This means that# all kernel and initrd paths are relative to / boot/ Eg.# root (hd0,0) # kernel / vmlinuz-version ro root=/dev/mapper/VolGroup--LogVol0-LogVol01# initrd / initrd- [generic-] version.img#boot=/dev/sdadefault=0timeout=5splashimage= (hd0,0) / grub/splash.xpm.gzhiddenmenutitle Red Hat Enterprise Linux 6 (2.6.32-504.el6.x86_64) root (hd0,0) kernel / vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/mapper/VolGroup--LogVol0-LogVol01 rd _ NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup-LogVol0/LogVol01 rd_LVM_LV=VolGroup-LogVol0/LogVol00 KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd / initramfs-2.6.32-504.el6.x86_64.imgtransparent_hugepage=never
Method 2: set / etc/rc.local file
[root@getlnx06 ~] # vi / ETC _ sys/kernel/mm/redhat_transparent_hugepage/enabledfi rc.localcharts _
After using the above configuration, you must restart the operating system to take effect, you can also run the following command without rebooting the operating system.
[root@getlnx06 ~] # echo never > / sys/kernel/mm/redhat_transparent_hugepage/ enabled [root @ getlnx06 ~] # cat / sys/kernel/mm/redhat_transparent_hugepage/enabledalways madvise [never] [root@getlnx06 ~] #
Small knowledge points:
1: starting with RedHat 6, OEL 6, SLES 11 and UEK2 kernels, Transparent HugePages is enabled by default: transparent large pages (Transparent HugePages) used to improve memory management are similar to large pages in previous versions. The main difference is that Transparent HugePages can be configured in real time and does not require a restart to take effect.
2:Transparent Huge Pages is not supported in 32-bit RHEL 6.
3: ORACLE officials do not recommend that we use open transparent large pages (Transparent HugePages) when using RedHat 6, OEL 6, SLES 11 and UEK2 kernels, because there are some problems with transparent large pages (Transparent HugePages):
Transparent large pages (Transparent HugePages) in RAC can cause abnormal node restarts and performance problems.
In a stand-alone environment, transparent large pages (Transparent HugePages) can also cause some abnormal performance problems
This is the end of this article on "sample Analysis of using and disabling transparent pages in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.