Is systemstack still a relevant term?

25 views
Skip to first unread message

Nghĩa Nguyễn

unread,
Jun 7, 2025, 6:40:37 PM (13 hours ago) Jun 7
to golang-nuts

Hi Gophers!

The comment for the systemstack function states that it "runs fn on a system stack." My understanding is that fn is executed on the thread's g0 stack. However, g0 is allocated via the malg function, just like a regular goroutine's stack. That suggests the g0 stack is not implicitly created by the kernel (e.g., via a traditional thread stack), but explicitly by the Go runtime.

Given that, I'm wondering: if the g0 stack is runtime-allocated and not a kernel-managed stack, is the term “system” in systemstack still meaningful? 

Ian Lance Taylor

unread,
1:18 AM (6 hours ago) 1:18 AM
to Nghĩa Nguyễn, golang-nuts
On Sat, Jun 7, 2025 at 8:40 AM Nghĩa Nguyễn <nghia...@gmail.com> wrote:
>
> The comment for the systemstack function states that it "runs fn on a system stack." My understanding is that fn is executed on the thread's g0 stack. However, g0 is allocated via the malg function, just like a regular goroutine's stack. That suggests the g0 stack is not implicitly created by the kernel (e.g., via a traditional thread stack), but explicitly by the Go runtime.
>
> Given that, I'm wondering: if the g0 stack is runtime-allocated and not a kernel-managed stack, is the term “system” in systemstack still meaningful?

In a program that uses cgo, or for any program for which
mStackIsSystemAllocated reports true, the g0 stack is allocated by
pthread_create. So in those cases it is a system stack.

I suppose we could use a different name if we cared enough.

Ian
Reply all
Reply to author
Forward
0 new messages