Where Does Go Runtime Fit?

The Go runtime is the orchestrator that manages G, M, and P. It's not a separate entity—it's the code that implements the scheduler, memory allocator, garbage collector, and all the machinery.

┌─────────────────────────────────────────────────────────────┐
│                       Go Runtime                            │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐         │
│  │  Scheduler  │  │     GC      │  │   Memory    │   ...   │
│  │  (GMP)      │  │             │  │  Allocator  │         │
│  └─────────────┘  └─────────────┘  └─────────────┘         │
│         │                                                   │
│         ▼                                                   │
│  ┌─────────────────────────────────────────────────┐       │
│  │              G-M-P Relationships                 │       │
│  │   P₀ ← M₀ ← G₁    P₁ ← M₁ ← G₂    ...          │       │
│  └─────────────────────────────────────────────────┘       │
└─────────────────────────────────────────────────────────────┘
                          │
                          ▼
┌─────────────────────────────────────────────────────────────┐
│                    Operating System                         │
│              (threads, memory, syscalls)                    │
└─────────────────────────────────────────────────────────────┘

Runtime Components

Component Responsibility
Scheduler Manages G-M-P: run queues, work stealing, preemption
Memory Allocator mcache (per-P), mcentral, mheap — fast allocation
Garbage Collector Concurrent, tri-color mark-and-sweep
Netpoller Integrates with epoll/kqueue for async I/O
System Monitor (sysmon) Background goroutine: preemption, GC triggers, netpoll

Runtime vs GMP

GMP = The data structures (Goroutine, Machine, Processor)

Runtime = The code that:


Key Runtime Functions

// You call this
go func() { ... }

// Runtime does this internally
runtime.newproc()      // create G
runtime.schedule()     // pick next G to run
runtime.park_m()       // block current G
runtime.ready()        // wake a G
runtime.morestack()    // grow stack
runtime.gcStart()      // trigger GC