This commit is contained in:
Kaiwan N Billimoria
2023-12-18 07:39:18 +05:30
4 changed files with 214 additions and 9 deletions

View File

@@ -16,7 +16,7 @@ sudo dmesg -C
2. Now build the module and insmod it (it will fail at some point, that's fine)
../../lkm slab4_actualsz_wstg_plot
3. Run the helper script plot_graph.sh; f.e.:
3. Run the helper script plot_graph.sh:
(Recommended: Before running the script, pl check the data file; it should ONLY
have data of the form:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 KiB

After

Width:  |  Height:  |  Size: 153 KiB

View File

@@ -203,4 +203,208 @@
4137060,1
4157540,0
4178020,0
<intr>,ipv6:addrconf_verify_rtnl:4618:,IPv6:,now,=,4302957104,,schedule,=,4302987241,,rounded,schedule,=,4302987491,=>,4302987241
100,28
20580,59
41060,59
61540,6
82020,59
102500,27
122980,6
143460,82
163940,59
184420,42
204900,27
225380,16
245860,6
266340,96
286820,82
307300,70
327780,59
348260,50
368740,42
389220,34
409700,27
430180,21
450660,16
471140,11
491620,6
512100,2
532580,96
553060,89
573540,82
594020,76
614500,70
634980,65
655460,59
675940,55
696420,50
716900,46
737380,42
757860,38
778340,34
798820,31
819300,27
839780,24
860260,21
880740,19
901220,16
921700,13
942180,11
962660,8
983140,6
1003620,4
1024100,2
1044580,0
1065060,96
1085540,93
1106020,89
1126500,86
1146980,82
1167460,79
1187940,76
1208420,73
1228900,70
1249380,67
1269860,65
1290340,62
1310820,59
1331300,57
1351780,55
1372260,52
1392740,50
1413220,48
1433700,46
1454180,44
1474660,42
1495140,40
1515620,38
1536100,36
1556580,34
1577060,32
1597540,31
1618020,29
1638500,27
1658980,26
1679460,24
1699940,23
1720420,21
1740900,20
1761380,19
1781860,17
1802340,16
1822820,15
1843300,13
1863780,12
1884260,11
1904740,10
1925220,8
1945700,7
1966180,6
1986660,5
2007140,4
2027620,3
2048100,2
2068580,1
2089060,0
2109540,98
2130020,96
2150500,95
2170980,93
2191460,91
2211940,89
2232420,87
2252900,86
2273380,84
2293860,82
2314340,81
2334820,79
2355300,78
2375780,76
2396260,75
2416740,73
2437220,72
2457700,70
2478180,69
2498660,67
2519140,66
2539620,65
2560100,63
2580580,62
2601060,61
2621540,59
2642020,58
2662500,57
2682980,56
2703460,55
2723940,53
2744420,52
2764900,51
2785380,50
2805860,49
2826340,48
2846820,47
2867300,46
2887780,45
2908260,44
2928740,43
2949220,42
2969700,41
2990180,40
3010660,39
3031140,38
3051620,37
3072100,36
3092580,35
3113060,34
3133540,33
3154020,32
3174500,32
3194980,31
3215460,30
3235940,29
3256420,28
3276900,27
3297380,27
3317860,26
3338340,25
3358820,24
3379300,24
3399780,23
3420260,22
3440740,21
3461220,21
3481700,20
3502180,19
3522660,19
3543140,18
3563620,17
3584100,17
3604580,16
3625060,15
3645540,15
3666020,14
3686500,13
3706980,13
3727460,12
3747940,11
3768420,11
3788900,10
3809380,10
3829860,9
3850340,8
3870820,8
3891300,7
3911780,7
3932260,6
3952740,6
3973220,5
3993700,5
4014180,4
4034660,3
4055140,3
4075620,2
4096100,2
4116580,1
4137060,1
4157540,0
4178020,0

View File

@@ -31,20 +31,21 @@ do
# /sys/kernel/debug/slab/kmalloc-8/alloc_traces: 58 strndup_user+0x4a/0x70 waste=406/7 age=831078/831403/831933 pid=1-801 cpus=0-5 406
# -----kmalloc-<foo> slab----------------------: num-times-requested func+start/len waste=num_wasted_total/num_wasted_eachtime pid=<...> cpus=<...>
# Get the absolute wastage:
# Get the total wastage (the x in waste=x/y; y = # bytes wasted each time):
# Kernel modules contain an extra field, the module name [foo]
# So get the field# of the column having the string 'waste=' ...
waste_fieldnum=$(echo "${rec}" | awk '{for(i=1;i<=NF;i++) {if ($i ~ /waste=/) print i}}')
# ... and then extract the absolute number of wasted bytes based on it
# (of the form: waste=406/7, i.e., waste=num_wasted_total/num_wasted_eachtime)
wastage_abs=$(echo "${rec}" | awk -v fld=${waste_fieldnum} '{print $fld}'|cut -d= -f2|cut -d/ -f1)
echo "${rec} ${wastage_abs}" >> ${TMPF}
num_wasted_total=$(echo "${rec}" | awk -v fld=${waste_fieldnum} '{print $fld}'|cut -d= -f2|cut -d/ -f1)
#echo "wstg_abs= ${wastage_abs}"
echo "${rec} ${num_wasted_total}" >> ${TMPF}
let n=n+1
[[ $((n % 100)) -eq 0 ]] && echo -n "."
done
echo
# separate out kernel internal kmalloc-* slabs from kernel modules slabs
# Separate out kernel internal kmalloc-* slabs from kernel modules slabs
grep -v "\[.*\]" ${TMPF} > kint.waste || true
grep "\[.*\]" ${TMPF} > kmods.waste || true
@@ -52,9 +53,9 @@ echo "======== Wastage (highest-to-lowest with duplicate lines eliminated) =====
echo "--------------- kernel internal ----------------
Top 10 wasters (in desc order). (To see all, lookup the full report here: kint.waste)"
[[ -s kint.waste ]] && {
# kernel internal - the 8th fields is the number of 'waste' bytes
# kernel internal - the 8th fields is the total number of 'waste' bytes
# (As the abs number of wasted bytes is already there in the output, we use awk
# to eliminate the last col, the number of wasted bytes)
# to eliminate the last col, the total number of wasted bytes)
# Also, use uniq(1) to eliminate duplicate lines (?)
sort -k8nr kint.waste | awk 'NF{NF--};1' | uniq | head
} || echo "-none-"
@@ -62,7 +63,7 @@ sort -k8nr kint.waste | awk 'NF{NF--};1' | uniq | head
echo "
--------------- kernel modules ----------------
Top 10 wasters (in desc order). (To see all, lookup the full report here: kmods.waste)"
# kernel modules - the 9th fields is the number of 'waste' bytes
# kernel modules - the 9th fields is the total number of 'waste' bytes
[[ -s kmods.waste ]] && {
sort -k9nr kmods.waste | awk 'NF{NF--};1' | uniq | head
} || echo "-none-"