Skip to content

Instantly share code, notes, and snippets.

@T-X
Created January 13, 2018 10:42
Show Gist options
  • Save T-X/a6cf0f1e33122904bc4ecf8cb2555707 to your computer and use it in GitHub Desktop.
Save T-X/a6cf0f1e33122904bc4ecf8cb2555707 to your computer and use it in GitHub Desktop.
#!/bin/sh
# License: CC0
MODULESFILE="$1"
MODULESDIR="/lib/modules/4.4.102"
NUMRUNS=30
drop_caches() {
/usr/lib/autoupdater/download.d/95drop_caches > /dev/null
}
get_normal_free() {
free | grep "^Mem:" | awk '{ print $4 }'
}
get_caches_free() {
free | grep "cache:" | awk '{ print $4 }'
}
[ ! -f "$MODULESFILE" ] && {
echo "Modules file $MODULESFILE does not exist"
exit 1
}
unload_modules() {
while read m; do
[ -z "$m" ] && continue
rmmod "$MODULESDIR/$m.ko" || echo "Unloading $m failed" >&2
done < $MODULESFILE
}
load_modules() {
__tac "$MODULESFILE" | while read m; do
[ -z "$m" ] && continue
insmod "$MODULESDIR/$m.ko" || echo "Loading $m failed" >&2
done
}
__tac() {
awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' "$1"
}
run() {
drop_caches
sleep 10
drop_caches
startnf=`get_normal_free`
startcf=`get_caches_free`
unload_modules
drop_caches
sleep 10
drop_caches
unloadnf=`get_normal_free`
unloadcf=`get_caches_free`
load_modules
drop_caches
sleep 10
drop_caches
loadnf=`get_normal_free`
loadcf=`get_caches_free`
diffnf1=$(($unloadnf-$startnf))
diffnf2=$(($unloadnf-$loadnf))
diffnf3=$((($diffnf1+$diffnf2)/2))
diffcf1=$(($unloadcf-$startcf))
diffcf2=$(($unloadcf-$loadcf))
diffcf3=$((($diffcf1+$diffcf2)/2))
diffsumnf=$(($diffsumnf+diffnf3))
diffsumcf=$(($diffsumcf+diffcf3))
echo "normal-free: $startnf $unloadnf $loadnf $diffnf1 $diffnf2 $diffnf3"
echo "cache-free: $startcf $unloadcf $loadcf $diffcf1 $diffcf2 $diffcf3"
}
diffsumnf=0
diffsumcf=0
load_modules 2> /dev/null
echo "# normal-free|caches-free: start unload load (unload-start) (unload-load) (((unload-start)+(unload-load)) / 2)"
sleep 15
for i in `seq 1 $NUMRUNS`; do
run
done
diffavenf=$(($diffsumnf/$NUMRUNS))
diffavecf=$(($diffsumcf/$NUMRUNS))
echo -e "\nAverage: $diffavenf/$diffavecf KB normal-free/caches-free diff"
ebt_802_3
ebt_among
ebt_arpreply
ebt_dnat
ebt_limit
ebt_mark
ebt_mark_m
ebt_pkttype
ebt_redirect
ebt_snat
ebt_stp
ebt_vlan
ebtable_broute
nf_conntrack_rtcache
nf_log_ipv4
nf_log_ipv6
nf_log_common
xt_CT
xt_LOG
xt_REDIRECT
xt_addrtype
xt_mac
xt_mark
xt_multiport
xt_physdev
xt_pkttype
xt_quota
xt_state
xt_time
nf_nat_redirect
br_netfilter
ip_tunnel
dummy
sch_codel
sch_dsmark
sch_fq
sch_gred
sch_hfsc
sch_htb
sch_ingress
sch_pie
sch_prio
sch_red
sch_sfq
sch_tbf
sch_teql
act_ipt
act_mirred
act_police
act_skbedit
cls_basic
cls_flow
cls_fw
cls_route
cls_tcindex
cls_u32
em_cmp
em_meta
em_nbyte
em_text
em_u32
usb-storage
usbserial
usbnet
ledtrig-usbport
ehci-platform
ehci-hcd
usbcore
usb-common
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment