How to check which applications are using hugepages

You can find how much is allocated and how much is actually used by HugePages by run the following command.

$ grep -i huge /proc/meminfo 
AnonHugePages:    776192 kB
HugePages_Total:     241
HugePages_Free:      113
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

But, there’s a time you also want to know which applications are actually used HugePages. You can check it by go through the /proc/ directory. In each PID directory, you can find smaps which shows you the memory allocation details. You can use below script to check if it uses HugePages and how much uses it.

#!/bin/bash

hugepage_size=`grep Hugepagesize: /proc/meminfo | awk '{print $2}'`

echo "HugePageSize : " $hugepage_size " kB"

for i in /proc/*/smaps; do
    if [[ $(grep '^KernelPageSize' $i | grep -v '4 kB$') ]]; then
        echo ""
        egrep -e "^KernelPageSize: [ ]*$hugepage_size kB$" $i -B 11 | egrep -e '^Size:' | awk 'BEGIN {sum = 0} { sum += $2 } END {print "Total HugePage used : " sum " kB"}'
    fi;
done

Output would be like below.

# ./checkhugepage.sh 
HugePageSize :  2048 kB

Total HugePage used : 262144 kB

Leave a Comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.