COSCUP2020
進階
TR214
歡迎來到 https://hackmd.io/@coscup/2020 共筆
Slides: Goroutine stack and local variable allocation in Go
以 linux 來說,有分成 kernel stack 和 user stack
之後會著重在 user stack
在執行程式時,user stack 會含有 stackframe
大概含有
有 heap
, stack
, data
, text
等
當產生一個新的 thread 後,會在 user stack 找一塊空間當作 stack
main program 預設的 stack size 是 8K
,可修改系統設定去修改
thread 是透過 clone
syscall 去設定新的 stack 空間
type stack struct {
lo uintptr
hi uintptr
}
type g struct {
stack stack
}
在 Processor
下有 mcache
,mcache
又有 stackcache
從 stackcache
去拿取新的 stack 空間
stackcache
會從 stack pool
(全域需加鎖) ,stack pool
又從 mhead
拿
在 GMP model 中的每個 M 會有一個 System stack
根據講者的圖,該 system stack 會對到 C 的 memory layout 中的 stack ?
預設大小也是 8K
當超過常數 StackSmall = 128
byte,才會觸發 stack extension
當超過常數 StackBig = 4096
byte
當直接分配新空間,並複製原本的內容到新空間,會遇到一個問題
因為原本有些變數是指到舊的 stack 空間,直接複製會有問題
go 透過另外一個 map 去解決
答案是: 會
直接失敗
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing