Lab 01: Go Scheduler — GMP Model
Overview
Step 1: The GMP Model
GMP (Goroutine / Machine / Processor):
G (Goroutine) — lightweight thread, ~2KB initial stack, grows as needed
M (Machine) — OS thread, usually GOMAXPROCS threads active
P (Processor) — scheduling context, has a run queue of goroutines
Run Queue:
Global queue (fallback)
Per-P local queue (max 256 goroutines)
States (goroutine):
Runnable — ready to run, waiting for P
Running — executing on an M
Syscall — blocked in OS syscall (M detaches from P)
Waiting — blocked on channel/mutex/timer/IO
Dead — finishedStep 2: GOMAXPROCS Tuning
Step 3: runtime.LockOSThread()
Step 4: Work Stealing Algorithm
Step 5: runtime/trace
Step 6: Goroutine Leak Detection
Step 7: MemStats and GC Tuning
Step 8: Capstone — Scheduler Demo
Summary
Component
Role
Tuning
Last updated
