summaryrefslogtreecommitdiffstats
path: root/core/modules/bwlp-stage4-tweaks
diff options
context:
space:
mode:
authorSimon Rettberg2023-02-13 14:19:39 +0100
committerSimon Rettberg2023-02-13 14:19:39 +0100
commit0b428f104b9c0709f218d08c9d9298ddd078f3d9 (patch)
tree545e83d660f43d80b2a4ffa047c23adf55756c79 /core/modules/bwlp-stage4-tweaks
parent[run-virt] Give dnbd3-fuse more time for connecting (diff)
downloadmltk-0b428f104b9c0709f218d08c9d9298ddd078f3d9.tar.gz
mltk-0b428f104b9c0709f218d08c9d9298ddd078f3d9.tar.xz
mltk-0b428f104b9c0709f218d08c9d9298ddd078f3d9.zip
[bwlp-stage4-tweaks] Speed up pswap
Diffstat (limited to 'core/modules/bwlp-stage4-tweaks')
-rwxr-xr-xcore/modules/bwlp-stage4-tweaks/data/opt/openslx/bin/pswap24
1 files changed, 13 insertions, 11 deletions
diff --git a/core/modules/bwlp-stage4-tweaks/data/opt/openslx/bin/pswap b/core/modules/bwlp-stage4-tweaks/data/opt/openslx/bin/pswap
index 42e4fac1..5a3347b2 100755
--- a/core/modules/bwlp-stage4-tweaks/data/opt/openslx/bin/pswap
+++ b/core/modules/bwlp-stage4-tweaks/data/opt/openslx/bin/pswap
@@ -1,20 +1,22 @@
-#!/bin/sh
+#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
+# Sped up and ported to bash Simon Rettberg 13/02/2023
OVERALL=0
-for PID in `find /proc/ -maxdepth 1 -type d -regex "/proc/[0-9]+" | cut -d / -f 3`; do
- SUM=0
+for PID in $( find /proc/ -maxdepth 1 -type d -regex "/proc/[0-9]+" | cut -d / -f 3 ); do
DIR="/proc/$PID"
- PROGNAME=`ps -p $PID -o comm --no-headers`
- for SWAP in `grep ^Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`; do
- SUM=$(( $SUM + $SWAP ))
- done
- SUM=$(( $SUM / 1024 ))
- [ "$SUM" -eq "0" ] && continue
+ SUM=$( < "$DIR/smaps" awk -v sum=0 '$1 == "Swap:" || $1 == "SwapPss:" {sum += $2} END {print sum}' )
+ (( SUM /= 1024 ))
+ (( SUM == 0 )) && continue
+ PROGNAME=$( readlink "$DIR/exe" )
echo "$SUM MiB by PID=$PID - ($PROGNAME)"
- OVERALL=$(( $OVERALL + $SUM ))
-done
+ (( OVERALL += SUM ))
+done 2> "/tmp/pswap.$$"
+other=$( grep -cF "/smaps" "/tmp/pswap.$$" ) \
+ && echo "" && echo "$other process(es) of other users could not be accounted for"
+
+echo ""
echo "Overall swap used: $OVERALL MiB"