FDD-book/examples/part-05/ch23-debug/labs/lab23_4_leak.sh
Edson Brandi 6e6dac94fe Add book companion files under examples/
Organize companion code and materials by book part:

  part-01/      Foundations
  part-02/      Kernel & driver fundamentals
  part-03/      Character & block devices
  part-04/      Networking & storage
  part-05/      Buses & advanced topics
  part-06/      Debugging & performance
  part-07/      Real-world drivers
  appendices/   Supplementary material
  README.md     Overview and build instructions
2026-04-25 16:51:00 +00:00

31 lines
1,014 B
Bash
Executable file

#!/bin/sh
#
# lab23_4_leak.sh - Lab 23.4: Finding a Memory Leak with vmstat -m
#
# This script does not automatically modify source files. It runs the
# workload and checks vmstat -m, but the lab expects the reader to
# introduce the deliberate leak in myfirst_open() themselves, reload,
# run this script, fix the leak in myfirst_close(), reload, and run
# again.
set -e
echo "=== Lab 23.4: Finding a Memory Leak with vmstat -m ==="
echo
echo "Snapshot 1: baseline memory pool state for myfirst"
vmstat -m | grep -E 'Type|myfirst' || echo "(no myfirst pool - is the driver loaded?)"
echo
echo "Running workload: 1000 open/read/close cycles..."
for i in $(seq 1 1000); do
cat /dev/myfirst0 > /dev/null
done
sync
echo
echo "Snapshot 2: memory pool state after workload"
vmstat -m | grep -E 'Type|myfirst'
echo
echo "Expected behaviour:"
echo " - If the leak is present, InUse grew by ~1000 since snapshot 1."
echo " - If the leak is fixed, InUse is essentially unchanged."
echo
echo "=== End of Lab 23.4 ==="