如何在Linux中检查Transparent HugePage状态(禁用或者启用)?

时间:2020-01-09 10:37:40  来源:igfitidea点击:

如何检查"透明HugePage"状态(如果已在Linux(RHEL/CentOS 7)中启用或者禁用)。在Linux中验证"透明HugePages"的状态。检查是否启用了透明的大页面。检查透明的大页面是否已禁用。使用Linux中的示例检查透明大页面状态的步骤。

Transparent HugePage说明

与允许使用所有未使用的内存作为高速缓存或者其他可移动(或者什至不可移动的实体)的缓存方法相比,透明的Hugepage支持(与Hugelbfs的保留方法相比)最大程度地提高了可用内存的利用率。

不需要保留即可防止用户页面注意到巨大的页面分配失败。它允许在大页面上使用页面调度和所有其他高级VM功能。它不需要应用程序的修改就可以利用它。

HugePages的类型:

系统中可以有两种类型的HugePage

  • 显式大页面(nr_hugepages)由vm.nr_hugepages sysctl参数明确分配,即用作大页面的页面保留在内核内部,不能用于其他目的。

  • 内核自动分配的"透明大页面(AnonHugePages)"。

检查透明HugePage状态

/proc/meminfo文件提供有关内核巨大页面池中的持久化hugetlb页面总数的信息。它还显示默认的大页面大小以及有关默认大小的大页面池中空闲,保留和多余的大页面数量的信息。

# grep -i huge /proc/meminfo
AnonHugePages:    264192 kB
HugePages_Total:   50226
HugePages_Free:    50226
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

其中

HugePages_Total is the size of the pool of huge pages and is configured 
				using /proc/sys/vm/nr_hugepages
HugePages_Free  is the number of huge pages in the pool that are not yet
                allocated.
HugePages_Rsvd  is short for "reserved," and is the number of huge pages for
                which a commitment to allocate from the pool has been made,
                but no allocation has yet been made.  Reserved huge pages
                guarantee that an application will be able to allocate a
                huge page from the pool of huge pages at fault time.
HugePages_Surp  is short for "surplus," and is the number of huge pages in
                the pool above the value in /proc/sys/vm/nr_hugepages. The
                maximum number of surplus huge pages is controlled by
                /proc/sys/vm/nr_overcommit_hugepages.
Hugepagesize    is the default hugepage size (in Kb).

检查AnonHugePages的"透明HugePage"状态

要检查" AnonHugePages"的"透明HugePage状态",请使用以下文件

# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]

其中

"always" 	means that an application requesting THP will stall on allocation 
		failure and directly reclaim pages and compact memory in an effort
		to allocate a THP immediately. This Jan be desirable for virtual 
		machines that benefit heavily from THP use and are willing to 
		delay the VM start to utilise them.
"madvise" 	will enter direct reclaim like "always" but only for regions 
		that are have used madvise(MADV_HUGEPAGE). This is the default 
		behaviour.
"never" 	should be self-explanatory.

检查nr_hugepages的"透明HugePage"状态

检查nr_hugepages的"透明HugePage"状态。

  • 在下面的代码段中,我们看到的" HugePages_Total"和" nr_hugepages"的值为" 0",这意味着在我的系统上禁用了显式的大页面。

  • 如果我们在此处看到"非零"值,则意味着所提供的内存量已在内核中保留,用于显式的透明大页。

# cat /sys/devices/system/node/node*/meminfo | fgrep Huge
Node 0 AnonHugePages:         0 kB
Node 0 HugePages_Total:     0
Node 0 HugePages_Free:      0
Node 0 HugePages_Surp:      0
# grep -i huge /proc/meminfo
AnonHugePages:    174080 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
# sysctl -a | grep nr_hugepages
vm.nr_hugepages = 0