Sep 29, 2020

[Go] memory allocation

Memory allocation:

1. <32KB, from local cache mcache's mspan for each P
Those mspan has 70 different sizes, from 8 bytes to 32k bytes
Each size has 2 mspan, one for object contains pointers, one
for object contains no pointers(for GC purpose design)

While local mcache is all used, there's mcentral cache.
Each size in mcentral contains 2 list, non-empty and empty list.
By empty means all memory slots are used.

The basic unit is mspan. Thus local cache shall borrow 1 mspan
from mcentral if local cache is all used.

If memory in mcentral were all used, allocates heap memory from
mheap to mcentral.

mheap is chunked with arena(s), arena is mapped with virtual memory pages.
mspan is allotted from arena.


2. >32KB are rounded up to page size directly allotted from mheap


This design idea is from Google's TCMalloc library.




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.