#!/bin/bash
# 大页内存大小(单位 kB)
HUGE_PAGE_SIZE=1048576 # 1048576KB=1024MB=1GB
# 系统所有进程总HUGE_PAGE
TOTAL_HUGE_PAGE_SIZE=0
#KEYWORDS=Kernel
KEYWORDS=Hugetlb
for PID in /proc/[0-9]*; do
PID=${PID##*/}
# 单个进程总HUGE_PAGE
PROCESS_HUGE_PAGE_TOTAL=0
PROCESS_HUGE_PAGE_INFO=$(cat /proc/${PID}/smaps | grep -v " 0 kB" | grep ${KEYWORDS})
while read line; do
# 占用HUGE_PAGE
PROCESS_HUGE_PAGE_USED=$(echo "$line" | awk '{print $2}')
PROCESS_HUGE_PAGE_TOTAL=$((PROCESS_HUGE_PAGE_TOTAL + PROCESS_HUGE_PAGE_USED))
done <<<$PROCESS_HUGE_PAGE_INFO
if [[ $PROCESS_HUGE_PAGE_TOTAL -gt 0 ]]; then
echo "PID ${PID} is using $PROCESS_HUGE_PAGE_TOTAL kB HugePages."
TOTAL_HUGE_PAGE_SIZE=$((TOTAL_HUGE_PAGE_SIZE + PROCESS_HUGE_PAGE_TOTAL))
fi
done
echo "Total HugePages used by all processes: $TOTAL_HUGE_PAGE_SIZE kB"
标签:HUGE,大页,PROCESS,PID,内存,KEYWORDS,TOTAL,PAGE,统计
From: https://www.cnblogs.com/wanghongwei-dev/p/18436505