20201013

@ShiKaiWi

Plan

  • reading malloc.go

Notes

hierachy

        +-----------------------------------------+
 mheap  |            A run of mspans.             |
        +-----------------------------------------+
                                                   
        +-----------------+     +-----------------+
mcentral|mspans for Size0 | *** |mspans for Size70|
        +-----------------+     +-----------------+
                                                   
        +------------------+   +------------------+
 mcache |mspans for thread0|***|mspans for thread0|
        +------------------+   +------------------+

Use mcache first and then use mcentral for lack of mspans in the mcache and use mheap finally if all miss when allocating small objects(<=32KB). Use mheap directly if allocation a large objects.

virtual memory layout

The heap consists of a set of arenas who consists of a heapArena and a set of mspan.

More

Q1: what does mspan.needzero do? Q2: How does mspan manage pages?