automated: linux: modules: add configurable memory tolerance for leak detection
Add configurable memory leak detection tolerance to reduce false positives
from MemAvailable measurement variations due to kernel memory management
artifacts like page cache changes, buffer allocations, and memory fragmentation.
Changes:
- Add MEMORY_TOLERANCE variable (default: 512KB)
- Add -t option to configure tolerance from command line
- Update usage help to document the new option
- Change leak detection from strict (diff < 0) to tolerance-based (diff < -tolerance)
This allows filtering out small memory variations that are not actual leaks
while still detecting significant memory leaks. The default 100KB tolerance
provides a good balance between sensitivity and false positive reduction.
Usage: ./modules.sh -t 512 # Set 512KB tolerance
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
diff --git a/automated/linux/modules/modules.sh b/automated/linux/modules/modules.sh
index 68bd89a..97cac2b 100755
--- a/automated/linux/modules/modules.sh
+++ b/automated/linux/modules/modules.sh
@@ -14,6 +14,7 @@
SKIPLIST=""
SHARD_NUMBER=1
SHARD_INDEX=1
+MEMORY_TOLERANCE=512
usage() {
echo "Usage: $0 [-d <subdir of the modules directory> ]
@@ -22,11 +23,12 @@
[-i <sharding bucket to run> ]
[-n <number of shard buckets to create> ]
[-s <skiplist modules to skip> ]
+ [-t <memory tolerance in KB for leak detection> ]
[-h ]" 1>&2
exit 0
}
-while getopts "c:d:i:l:n:s:h" o; do
+while getopts "c:d:i:l:n:s:t:h" o; do
case "$o" in
d) MODULES_SUBDIRS="${OPTARG}" ;;
l) MODULES_LIST="${OPTARG}" ;;
@@ -34,6 +36,7 @@
i) SHARD_INDEX="${OPTARG}" ;;
n) SHARD_NUMBER="${OPTARG}" ;;
s) SKIPLIST="${OPTARG}" ;;
+ t) MEMORY_TOLERANCE="${OPTARG}" ;;
h|*) usage ;;
esac
done
@@ -49,7 +52,7 @@
local diff_kb
diff_kb=$((before_kb - after_kb))
echo "memcheck: before ${before_kb}, after ${after_kb}, diff ${diff_kb}"
- if [ "$diff_kb" -lt 0 ]; then
+ if [ "$diff_kb" -lt "-${MEMORY_TOLERANCE}" ]; then
report_fail "memcheck_${module}"
else
report_pass "memcheck_${module}"
diff --git a/automated/linux/modules/modules.yaml b/automated/linux/modules/modules.yaml
index 44f3e00..153e092 100644
--- a/automated/linux/modules/modules.yaml
+++ b/automated/linux/modules/modules.yaml
@@ -37,8 +37,11 @@
# Which bucket to run, default '1' which is the same as no sharding, run
# all modules in the MODULES_SUBDIRS list.
SHARD_INDEX: 1
+
+ # memory tolerance in KB for leak detection
+ MEMORY_TOLERANCE: 512
run:
steps:
- cd ./automated/linux/modules/
- - ./modules.sh -d "${MODULES_SUBDIRS}" -l "${MODULES_LIST}" -c "${MODULE_MODPROBE_NUMBER}" -n "${SHARD_NUMBER}" -i "${SHARD_INDEX}" -s "${SKIPLIST}"
+ - ./modules.sh -d "${MODULES_SUBDIRS}" -l "${MODULES_LIST}" -c "${MODULE_MODPROBE_NUMBER}" -n "${SHARD_NUMBER}" -i "${SHARD_INDEX}" -s "${SKIPLIST}" -t "${MEMORY_TOLERANCE}"
- ../../utils/send-to-lava.sh ./output/result.txt