How can I see the number of transparent hugepages that are actually in use on the system (either globally or by individual processes)? How do I check transparent hugepage usage per process in Linux. How to check which application or process is using which amount of HugePages. How to find per-process hugepages utilization.

How to check transparent hugepage usage per process in Linux

 

In this article I will share the steps to check Transparent HugePage usage per process in Linux with examples.

 

First of all you must check if system is configured with hugepages:

# grep -i huge /proc/meminfo
AnonHugePages:    835584 kB
HugePages_Total:   12850
HugePages_Free:       13
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

Used hugepages can be calculated by below method.

HugePages_Total- HugePages_Free = HugePages_Used

 

Check system-wide Transparent HugePage Usage

Before we check transparent hugepage per process, let us check system wife THP usage. The number of anonymous transparent huge pages currently used by the system is available by reading the AnonHugePages field in /proc/meminfo.

# grep AnonHugePages /proc/meminfo
AnonHugePages:    835584 kB

 

Check Transparent HugePage usage per process

/proc/[pid]/smaps (since Linux 2.6.14) shows memory consumption for each of the process’s mappings. For each mapping there is a series of lines.

To identify what applications are using anonymous transparent huge pages, it is necessary to read /proc/PID/smaps and count the AnonHugePages fields for each mapping. “AnonHugePages” shows the amount of memory backed by transparent hugepage. If you already have the process information for which you wish to collect the THP usage

# grep -e AnonHugePages  /proc/10723/smaps | awk  '{ if($2>4) print $0} ' |  awk -F "/"  '{print $0; system("ps -fp 10723")} '
AnonHugePages:      2048 kB
UID        PID  PPID  C STIME TTY          TIME CMD
polkitd  10723     1  0 Jul29 ?        00:00:08 /usr/lib/polkit-1/polkitd --no-debug
AnonHugePages:      6144 kB
UID        PID  PPID  C STIME TTY          TIME CMD
polkitd  10723     1  0 Jul29 ?        00:00:08 /usr/lib/polkit-1/polkitd --no-debug

 
Here 10723 is the PID for which I wish to get the transparent hugepage usage. To get only limited (brief) information about the command we will use “-o comm="

# grep -e AnonHugePages  /proc/10723/smaps | awk  '{ if($2>4) print $0} ' |  awk -F "/"  '{print $0; system("ps -fp 10723 -o comm=")} '
AnonHugePages:      2048 kB
polkitd
AnonHugePages:      6144 kB
polkitd

So I see for two of the mappings for polkitd process, it is using transparent hugepage. Now to get the total amount of THP usage for this process you can run following command

# grep -e AnonHugePages  /proc/10709/smaps | awk  '{ if($2>4) print $0} ' | awk -F ":" '{print $2}' | awk '{Total+=$1} END {print "Total AnonHugePages: " Total" Kb -"}' | awk -F "/"  '{printf $0; system("ps -fp 10709 -o comm= ")} '
Total AnonHugePages: 6144 Kb -polkitd

 

To check transparent hugepage usage per process (for all the processes) on the system which is using THP

# grep -e AnonHugePages  /proc/*/smaps | awk  '{ if($2>4) print $0} ' |  awk -F "/"  '{print $0; system("ps -fp " $3)} '

 

Lastly I hope the steps from the article to check transparent hugepage usage per process on Linux was helpful. So, let me know your suggestions and feedback using the comment section.

 

References
Red Hat Knowledgebase

 

Leave a Reply

Your email address will not be published. Required fields are marked *