From 713edb8a99569f2f7e83790f7365916e04eb2594 Mon Sep 17 00:00:00 2001 From: Jared Still Date: Mon, 18 Jul 2016 12:44:36 -0700 Subject: [PATCH] chk-anon-huge.sh prototype to check if Anonymous HugePages are configured and enabled --- chk-anon-huge.sh | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 chk-anon-huge.sh diff --git a/chk-anon-huge.sh b/chk-anon-huge.sh new file mode 100755 index 0000000..066173b --- /dev/null +++ b/chk-anon-huge.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +function chkAnonHuge () { + +: <<'PYTHDOC' + +check for anonymous huge pages +see Oracle Support Note: + ALERT: Disable Transparent HugePages on SLES11, RHEL6, RHEL7, OL6, OL7 and UEK2 Kernels (Doc ID 1557478.1) + +The note contains a recommendation to check /proc/meminfo as one method to detect Anonymous HugePages, +but that method is only reliable if some Anonymous HugePages have actually been allocated. + +PYTHDOC + + declare -a anonConfigFiles=( + [0]='/sys/kernel/mm/redhat_transparent_hugepage/enabled' + [1]='/sys/kernel/mm/transparent_hugepage/enabled' + ) + + fileCount=${#anonConfigFiles[@]} + + i=0 + + anonFileToChk='' + + while [[ $fileCount -gt $i ]] + do + #echo $i: ${anonConfigFiles[$i]} + [[ -r ${anonConfigFiles[$i]} ]] && { + anonFileToChk=${anonConfigFiles[$i]} + break + } + (( i++ )) + done + + #echo anonFileToChk: $anonFileToChk + +: <<'ANONCHK' + +check the contents of file anonFileToChk + +'[always] never': Anonymous HugePages should be disabled. + +'always [never]': Anonymous HugePages are configured in the kernel, but disabled. + +If the file does not even exist, that Anonymous HugePages are not configured and can be ignored. + +ANONCHK + + anonHugePagesConfigured=1 + [[ -z $anonFileToChk ]] && anonHugePagesConfigured=0 + + #echo anonHugePagesConfigured: $anonHugePagesConfigured + + anonHugePagesEnabled=0 + + if [[ $anonHugePagesConfigured -gt 0 ]]; then + grep '[always]' $anonFileToChk >/dev/null && { + #echo anonymous HugePages are enabled + anonHugePagesEnabled=1 + } + fi + + # return code - will be either 0 or 1 + echo $(( anonHugePagesConfigured * anonHugePagesEnabled )) + +} + +r=$(chkAnonHuge) + +echo "r: $r" + +