tools/testing/selftests/mm/ksft_kmemleak_dedup.sh
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/ksft_kmemleak_dedup.sh
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/ksft_kmemleak_dedup.sh- Extension
.sh- Size
- 8692 bytes
- Lines
- 223
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function flush_block
Annotated Snippet
function flush_block() {
if (in_block) {
# Skip empty backtraces: leaks with trace_handle == 0
# (early-boot allocations or stack_depot_save() failures
# under memory pressure) are intentionally not deduped,
# so multiple such reports in one scan are expected and
# must not be flagged as a regression.
if (bt != "")
seen[bt]++
in_block = 0
collecting = 0
bt = ""
}
}
function check_and_reset( b) {
for (b in seen)
if (seen[b] > 1)
printf("backtrace seen %d times in one scan:\n%s\n",
seen[b], b)
delete seen
}
# Scan boundary: the per-scan summary line.
/kmemleak: [0-9]+ new suspected memory leaks/ {
flush_block()
check_and_reset()
next
}
# Start of a new "unreferenced object" report.
/kmemleak: unreferenced object/ {
flush_block()
in_block = 1
next
}
# Inside a report, the "backtrace (crc ...):" line switches us to
# backtrace-collecting mode.
in_block && /kmemleak:[[:space:]]+backtrace \(crc/ {
collecting = 1
next
}
# Once collecting, capture only deeply-indented "kmemleak: " lines
# (stack frames have 4+ spaces of indentation under "kmemleak: ";
# headers and the "... and N more" tail line have less). This stops
# unrelated kmemleak warns landing between reports from being lumped
# into the backtrace key, which would mask a genuine duplicate.
in_block && collecting && /kmemleak:[[:space:]]{4,}/ {
bt = bt $0 "\n"
next
}
END {
flush_block()
check_and_reset()
}
')
if [ -n "$violations" ]; then
echo "$violations"
fail "kmemleak dedup regression: same backtrace reported more than once in a single scan"
fi
# Count the dedup summary lines so the report distinguishes "dedup
# actually fired" from "no same-backtrace leaks turned up to dedup".
dedup_lines=$(echo "$log" | grep -c 'more object(s) with the same backtrace')
if [ "$dedup_lines" -gt 0 ]; then
pass "no dedup violations across $SCAN_COUNT scans; dedup fired ($dedup_lines summary line(s) observed)"
else
pass "no dedup violations across $SCAN_COUNT scans; dedup had nothing to collapse"
fi
Annotation
- Detected declarations: `function flush_block`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.