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.

  1. Chụp process tree và /proc/<pid>/fd trước khi fork.
  2. Tạo child exit nhưng giữ parent sống mà không reap; xác nhận trạng thái Z.
  3. exec child và chứng minh descriptor bị giữ khi thiếu close-on-exec.
  4. 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.

  1. Ghi baseline từ maps, smaps_rollup, faults và memory.current.
  2. So allocate-only với touched pages; giải thích VSZ/RSS/PSS.
  3. Đo trước/sau parent và child write để thấy COW.
  4. 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.

  1. Đo threads, virtual/RSS, pids.current, heap và NMT.
  2. Tăng concurrency theo nấc tới limit an toàn; ghi failure signature.
  3. Giữ ThreadLocal payload qua task completion, lấy heap evidence.
  4. 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.

  1. Chạy baseline; ghi throughput/p50/p95/p99, CPU, run queue, context switches.
  2. Giới hạn cpu.max khi host còn idle; correlate cpu.stat với latency.
  3. Pin workers vào ít CPU rồi tăng lock hold time; lấy scheduler/lock profile.
  4. 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.

  1. Định nghĩa message size, producer rate, queue bound và loss/order invariant.
  2. Đo throughput, CPU, latency distribution ở steady state.
  3. Làm consumer chậm/dừng; quan sát block, drop hoặc overwrite.
  4. 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.

  1. Load baseline; đo FD, CPU, errors, latency.
  2. Bật mode không drain edge-trigger và leak accepted sockets; lưu ss/lsof/syscalls.
  3. Chạy shell-form và exec-form entrypoint, gửi TERM rồi KILL sau deadline.
  4. 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.

  1. Compile/chạy theo README với NMT.
  2. Lấy hai thread dump, per-thread CPU, process memory và NMT.
  3. Trên Linux, map decimal TID từ top -H/ps -L sang hexadecimal nid.
  4. 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 -version

Chỉ đổ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-complete

Validation 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 20

Trong 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.

  1. Xác định impact, time window, scope và bảo toàn evidence.
  2. Lập ba hypothesis với expected signal và falsification test.
  3. Mitigate bounded/reversible, theo dõi SLI và rollback trigger.
  4. 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

FieldRequired
EnvironmentKernel/OS, runtime/JDK/compiler, tool versions và CPU-memory-PID limits.
WorkloadArrival, concurrency, data, duration, seed và invariant.
Raw evidenceCommands, unedited outputs, timestamps, profiles/captures và privacy review.
ComparisonBaseline → failure → mitigation → after với cùng workload/threshold.
BoundaryPhần đã chạy và phần tabletop/pending; không suy rộng ngoài environment.
Execution audit: hiện chỉ phần Windows/JDK 21 của Lab 07 đã chạy và được tái kiểm chứng. Labs 01–06, 08 cùng Linux TID/cgroup của Lab 07 vẫn pending; xem status và environment gate.
← Câu hỏiChecklist →