Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tracing the Proportional Set Size (PSS) of a process

148 views
Skip to first unread message

CelalD

unread,
May 3, 2021, 2:17:03 PM5/3/21
to
Hi Group,

I've here (Red Hat EL 7.9) the issue to calculate the real memory usage of a process - actual and trace
Background: some Nagios-like monitoring tool reports "memory full" although there is still memory free, which triggers false positives.

During my research, I found that the common ps command estimates the memory size not right:

"Resident Set Size (RSS) : The standard measure of physical memory (it typically shared among multiple applications) usage known as resident set size (RSS) will significantly overestimate memory usage."
(https://www.2daygeek.com/smem-linux-memory-usage-statistics-reporting-tool/)

As an alternative, the above site suggest to use smem instead. Unfortunately, smem is not included in the standard RHEL repository.
In EPEL smem is available but unfortunately not allowed to use due restrictions set by company.

Thus, I'm looking for alternatives how to measure the PSS value of a process; the best would be using shells own capabilities or Perl (v5.16.3 is installed) or Python (v2.7).

==> has someone an idea or already programmed such a solution?

For the sake of completeness, below I have put the tries (which have nothing with PSS) of my ancestor to solve the problem; just if you have comments on them.

Thanks,
Celal


memchecker.sh
#!/bin/bash

echo -e "USER Memory(%) Process TOTALUSEDMEMORY(MB) TOTALFREEMEMORY(MB) TOTALMEMORY(MB)" |sed 's/ /\| /g'
for i in {1..50};do
echo `ps aux|egrep 'app1adm|app2adm'|sort -rnk 4 |head -$i|tail -1|awk '{print $1,$4,$11}'` `free -m |grep ^M|awk '{print $3,$4,$2}'` |sed 's/ /\| /g'
done

---

memtest.sh
#!/bin/bash
function report_utilisation {
echo
echo Memory eaters :

cat /tmp/mem_usage.$$ |
awk '
{ process[$1]+=$2; }
END{
for(i in process)
{
printf("%-20s %sn",i, process[i]) ;
}

}' | sort -nrk 2 | head

rm /tmp/mem_usage.$$
exit 0
}

trap 'report_utilisation' INT

SECS=900
UNIT_TIME=10

STEPS=$(( $SECS / $UNIT_TIME ))

echo Watching Memory usage... ;

# Collect data in temp file
for((i=0;i<$STEPS;i++)); do
ps -eocomm,pmem | egrep -v '(0.0)|(%MEM)' >> /tmp/mem_usage.$$
sleep $UNIT_TIME
done

report_utilisation

----

memmap.sh
!/bin/bash

printf "%-10s%-15s%-15s%s\n" "PID" "OWNER" "MEMORY" "COMMAND"


function sys_main {
RAWIN=$(ps -o pid,user,%mem,command ax | grep -v PID |grep -v root| sort -bnr -k3 |
awk '/[0-9]*/{print $1 ":" $2 ":" $4}')

for i in $RAWIN
do
PID=$(echo $i | cut -d: -f1)
OWNER=$(echo $i | cut -d: -f2)
COMMAND=$(echo $i |cut -d: -f3)
MEMORY=$(pmap $PID |tail -n 1 |awk '/[0-9]K/{print $2}')


printf "%-10s%-15s%-15s%s\n" "$PID" "$OWNER" "$MEMORY" "$COMMAND"
done
}
sys_main | sort -bnr -k3 |head -n 50




0 new messages