I am reading about the GC, Chapter 21 in Real World OCaml, and have a few questions about the minor heap.
So it says:
The minor heap is a contiguous chunk of virtual memory that is usually a few megabytes in size so that it can be scanned quickly.
The runtime stores the boundaries of the minor heap in two pointers that delimit the start and end of the heap region (caml_young_start and caml_young_end, but we will drop the caml_young prefix for brevity). The base is the memory address returned by the system malloc, and start is aligned against the next nearest word boundary from base to make it easier to store OCaml values.
In a fresh minor heap, the limit equals the start, and the current ptr will equal the end. ptr decreases as blocks are allocated until it reaches limit, at which point a minor garbage collection is triggered.
You may wonder why limit is required at all, since it always seems to equal start. It's because the easiest way for the runtime to schedule a minor heap collection is by setting limit to equal end. The next allocation will never have enough space after this is done and will always trigger a garbage collection. There are various internal reasons for such early collections, such as handling pending UNIX signals, and they don't ordinarily matter for application code.
Q1: The relationship between minor heap and base
Basically, the runtime will try to allocate a chunk of memory, say, for size of 8 MB, as minor heap, using system malloc?
Then the address returned by malloc is base?
Q2: The relationship between base and start
What does it mean that start is aligned against the next nearest word boundary from base
?
Does the term aligned here mean start will seek for the next memory address that mods 4 equaling to 0?
I thought malloc anyway forces alignment, i.e., always return addresses that mod 4 = 0
Q3: What we use start while we have limit?
It explained that limit can be used to schedule a GC.
However, then what's the use of start?