8 executable Linux/JVM failure labs
Chạy trong Linux VM/WSL/container lab với CPU, memory, PID và time limit. Mỗi lab phải lưu environment, workload, raw evidence, failure, mitigation, kết quả sau mitigation và cleanup.
8 labs
Lab 01 · fork/exec/wait, zombie và FD inheritance
Mục tiêu: quan sát process lifecycle và ownership của child/descriptor. Chuẩn bị: parent C/Python tạo child, một listening socket hoặc file descriptor, hai mode có/không có wait/CLOEXEC.
- Chụp process tree và
/proc/<pid>/fdtrước khi fork. - Tạo child exit nhưng giữ parent sống mà không reap; xác nhận trạng thái Z.
execchild và chứng minh descriptor bị giữ khi thiếu close-on-exec.- Bật reap + CLOEXEC, chạy lại cùng workload.
Failure: zombie accumulation hoặc port/file không release. Evidence: source, timestamps, ps, /proc/*/fd, lsof. Pass: không còn zombie/FD thừa và regression test fail nếu bỏ fix.
Lab 02 · Virtual memory, COW và accounting
Mục tiêu: phân biệt mapping, resident/private/shared pages và cgroup charge. Allocate chưa touch, touch theo page, mmap file, fork rồi write từng tỷ lệ page.
- Ghi baseline từ
maps,smaps_rollup, faults vàmemory.current. - So allocate-only với touched pages; giải thích VSZ/RSS/PSS.
- Đo trước/sau parent và child write để thấy COW.
- Thêm limit an toàn, tái hiện reclaim/OOM trong scope riêng rồi cleanup.
Pass: bảng per-phase giải thích anonymous/file, shared/private dirty, minor/major fault và OOM scope; không gọi VSZ là usage.
Lab 03 · Thread stacks, TLS và thread leak
Mục tiêu: lượng hóa platform-thread cost và ThreadLocal retention. Chạy C/Java workload với stack size, thread count, bounded pool và payload cấu hình được.
- Đo threads, virtual/RSS,
pids.current, heap và NMT. - Tăng concurrency theo nấc tới limit an toàn; ghi failure signature.
- Giữ ThreadLocal payload qua task completion, lấy heap evidence.
- Thêm bounded executor, cleanup và concurrency budget; chạy lại.
Pass: phân biệt stack reservation/commit, native-thread/PID limit và heap retention; mitigation giảm growth mà vẫn đạt throughput target.
Lab 04 · Scheduler, affinity, quota và lock contention
Mục tiêu: tách host saturation, cgroup throttling và synchronization bottleneck.
- Chạy baseline; ghi throughput/p50/p95/p99, CPU, run queue, context switches.
- Giới hạn
cpu.maxkhi host còn idle; correlatecpu.statvới latency. - Pin workers vào ít CPU rồi tăng lock hold time; lấy scheduler/lock profile.
- Giảm concurrency/critical section và kiểm tra p99 cùng secondary effects.
Evidence: pidstat, perf stat/sched, PSI, quota counters, app metrics. Pass: ba failure có signature khác nhau và fix cải thiện SLI với cùng workload.
Lab 05 · IPC và backpressure
Mục tiêu: so pipe, Unix socket và shared-memory ring buffer bằng cùng message contract.
- Định nghĩa message size, producer rate, queue bound và loss/order invariant.
- Đo throughput, CPU, latency distribution ở steady state.
- Làm consumer chậm/dừng; quan sát block, drop hoặc overwrite.
- Kill peer giữa message, restart và xác minh recovery.
Failure: short read/write, full buffer, peer crash, ordering và stale resource. Pass: xử lý partial I/O/backpressure/cleanup và nêu copy/isolation/complexity trade-off.
Lab 06 · FD, epoll, signals và PID 1
Mục tiêu: xây nonblocking echo server và chứng minh readiness không đồng nghĩa full I/O.
- Load baseline; đo FD, CPU, errors, latency.
- Bật mode không drain edge-trigger và leak accepted sockets; lưu
ss/lsof/syscalls. - Chạy shell-form và exec-form entrypoint, gửi TERM rồi KILL sau deadline.
- Sửa partial I/O, drain-to-EAGAIN, forwarding/reaping và graceful drain.
Pass: FD về baseline, không busy loop, policy in-flight rõ ràng và toàn process tree dừng trước deadline.
Lab 07 · Java/JVM sang OS mapping
Mục tiêu: correlate Java state, native TID, CPU time và native memory. Workload có hot loop, monitor contention, 200 parked virtual threads và 16 MiB direct buffer.
- Compile/chạy theo README với NMT.
- Lấy hai thread dump, per-thread CPU, process memory và NMT.
- Trên Linux, map decimal TID từ
top -H/ps -Lsang hexadecimalnid. - Bound downstream bằng semaphore và chứng minh virtual threads không tăng dependency capacity.
Pass: mỗi symptom có ít nhất hai nguồn evidence; giải thích RUNNABLE không đồng nghĩa dùng CPU và RSS không đồng nghĩa heap. Execution: Windows/JDK 21 evidence; Linux TID/cgroup gate pending.
Execution status và Linux gate
Labs 01–06 và 08 vẫn pending vì cần Linux semantics/fixtures. Lab 07 chỉ được đánh dấu executed cho Windows half. Trước khi chạy trên Linux, ghi kernel/distribution, cgroup v2 controllers, tool versions và CPU/memory/PID limits; không chạy OOM, PID exhaustion hoặc CPU quota trên host không bounded.
uname -a
cat /etc/os-release
stat -fc %T /sys/fs/cgroup
cat /sys/fs/cgroup/cgroup.controllers
command -v gcc python3 ps lsof perf strace
java -versionChỉ đổi status sang executed sau khi lưu commands, unedited output, timestamps, workload parameters, cleanup result và baseline → failure → mitigation comparison theo pass criteria.
Execution evidence · Windows / Oracle JDK 21.0.9
Audit ngày 2026-08-23 xác nhận hot thread tích lũy CPU trong khi monitor waiter không tích lũy CPU; NMT ghi nhận khoảng 16 MiB ở nhóm Other tương ứng direct-buffer allocation. Process working/private memory lớn hơn Java heap, nên RSS/process memory không được diễn giải như heap.
"lab-monitor-blocked" BLOCKED
"lab-cpu-hot" RUNNABLE, cpu=3125.00ms
Total: reserved=5728195KB, committed=363567KB
Other: reserved=16384KB, committed=16384KB
OS thread count: 37
Working set: 62,144,512 bytes
Private memory: 379,047,936 bytes
lab-completeValidation boundary: phần Java/JVM đã chạy trên Windows; Linux top -H/ps -L, cgroup accounting, perf và native TID mapping vẫn pending.
Lab 07 · Runbook và evidence đã kiểm chứng
Workload bounded tạo bốn điều kiện quan sát độc lập: một platform thread CPU-hot, một platform thread blocked trên Java monitor, 200 virtual threads parked và 16 MiB direct buffers ngoài Java heap.
javac RuntimePressureLab.java
java -XX:NativeMemoryTracking=summary RuntimePressureLab 45
# Windows bounded runner
.\Run-Lab07.ps1 -DurationSeconds 20Trong lúc chạy, thu jcmd <PID> Thread.print -l, jcmd <PID> VM.native_memory summary và process counters. Trên Linux, thêm ps -L -p PID -o pid,tid,pcpu,state,comm, rồi đổi TID decimal sang hexadecimal để đối chiếu nid.
Lab 08 · Incident game day
Mục tiêu: vận hành theo hypothesis. Facilitator bí mật chọn CPU spin, slow/D-state I/O, memory leak, FD leak, PID exhaustion hoặc cgroup OOM.
- Xác định impact, time window, scope và bảo toàn evidence.
- Lập ba hypothesis với expected signal và falsification test.
- Mitigate bounded/reversible, theo dõi SLI và rollback trigger.
- Viết postmortem, thêm regression drill và chạy lại action.
Pass: scope/root cause đúng, recovery được SLI xác nhận, không dựa một snapshot; action có owner, deadline và test evidence.
Evidence contract
| Field | Required |
|---|---|
| Environment | Kernel/OS, runtime/JDK/compiler, tool versions và CPU-memory-PID limits. |
| Workload | Arrival, concurrency, data, duration, seed và invariant. |
| Raw evidence | Commands, unedited outputs, timestamps, profiles/captures và privacy review. |
| Comparison | Baseline → failure → mitigation → after với cùng workload/threshold. |
| Boundary | Phần đã chạy và phần tabletop/pending; không suy rộng ngoài environment. |