linux/tools/testing/selftests/damon/debugfs_target_ids_pid_leak.sh
SeongJae Park f08db42b1c selftests/damon: add a test for the pid leak of dbgfs_target_ids_write()
Commit ebb3f994dd ("mm/damon/dbgfs: fix 'struct pid' leaks in
'dbgfs_target_ids_write()'") fixes a pid leak bug in DAMON debugfs
interface, namely dbgfs_target_ids_write() function.  Add a selftest for
the issue to prevent the problem from mistakenly recurring.

Link: https://lkml.kernel.org/r/20240207203134.69976-8-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-02-22 10:24:56 -08:00

23 lines
527 B
Bash

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
before=$(grep "^pid " /proc/slabinfo | awk '{print $2}')
nr_leaks=$(./debugfs_target_ids_pid_leak 1000)
expected_after_max=$((before + nr_leaks / 2))
after=$(grep "^pid " /proc/slabinfo | awk '{print $2}')
echo > /sys/kernel/debug/damon/target_ids
echo "tried $nr_leaks pid leak"
echo "number of active pid slabs: $before -> $after"
echo "(up to $expected_after_max expected)"
if [ $after -gt $expected_after_max ]
then
echo "maybe pids are leaking"
exit 1
else
exit 0
fi