Skip to content

Commit 0440796

Browse files
committed
add pic for bitmap, arena, spans
1 parent 7eaa247 commit 0440796

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

memory.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,16 @@ func sysMap(v unsafe.Pointer, n uintptr, sysStat *uint64) {
304304

305305
## 内存分配器初始化
306306

307+
初始化时,会直接要三个区域。
308+
309+
```
310+
┌─────────────────┬──────────────────┬────────────────────────────────┐
311+
│ │ │ │
312+
│ span (512 MB) │ bitmap (16 GB) │ arena (512 GB) │
313+
│ │ │ │
314+
└─────────────────┴──────────────────┴────────────────────────────────┘
315+
```
316+
307317
```go
308318
func mallocinit() {
309319
if class_to_size[_TinySizeClass] != _TinySize {
@@ -456,6 +466,35 @@ func mallocinit() {
456466
}
457467
```
458468

469+
```go
470+
// initialize new P's
471+
for i := int32(0); i < nprocs; i++ {
472+
pp := allp[i]
473+
if pp == nil {
474+
pp = new(p)
475+
pp.id = i
476+
pp.status = _Pgcstop
477+
pp.sudogcache = pp.sudogbuf[:0]
478+
for i := range pp.deferpool {
479+
pp.deferpool[i] = pp.deferpoolbuf[i][:0]
480+
}
481+
pp.wbBuf.reset()
482+
atomicstorep(unsafe.Pointer(&allp[i]), unsafe.Pointer(pp))
483+
}
484+
if pp.mcache == nil {
485+
if old == 0 && i == 0 {
486+
if getg().m.mcache == nil {
487+
throw("missing mcache?")
488+
}
489+
pp.mcache = getg().m.mcache // bootstrap
490+
} else {
491+
pp.mcache = allocmcache()
492+
}
493+
}
494+
}
495+
496+
```
497+
459498
## 堆内存分配流程
460499

461500
```mermaid

0 commit comments

Comments
 (0)