Next: , Previous: , Up: objects memory   [Index]


13.3.2 Logic memory segments

Some memory for use by the Scheme program is allocated through mmap() in blocks called allocated segments. A segment’s size is a fixed constant which must be defined as an exact multiple of the memory allocation granularity used by mmap(); we define the preprocessor macro IK_SEGMENT_SIZE to be such constant.

On Unix platforms we expect mmap()’s allocation granularity to be 4096; on Windows platforms, under Cygwin, we expect mmap()’s allocation granularity to be 2^16 = 65536 = 16 * IK_PAGESIZE. So the allocation granularity is not always equal to the system page size, and not always equal to Vicare’s page size.

Remembering that we have defined the preprocessor constant IK_CHUNK_SIZE to be 4096, and assuming:

1 mebibyte = 1 MiB = 2^20 bytes = 1024 * 1024 bytes
           = 1048576 bytes

we want the segment size to be 4 MiB:

4 MiB = 4 * 1024 * 1024 = 64 * 2^16 = 64 * 65536
      = 4096 * 1024 = 4096 * (4096 / 4) = IK_CHUNK_SIZE * 1024
      = 2^22 = 4194304 bytes
      = #x400000
      = #b10000000000000000000000

notice how many zero bits there are in the binary representation of 4 MiB:

(number->string (* 4096 1024) 2)
⇒ #b10000000000000000000000
;;   21098765432109876543210

Vicare distinguishes between allocated segments and logic segments:

so, typically, allocated segments of size IK_SEGMENT_SIZE are displaced from logic segments:

       alloc segment  alloc segment  alloc segment
-----|--------------|--------------|--------------|----------

  logic segment  logic segment  logic segment  logic segment
|--------------|--------------|--------------|--------------|

 page page page page page page page page page page page page
|----|----|----|----|----|----|----|----|----|----|----|----|

logic segments are absolute portions of the memory seen by a running system process. It is natural to assign a zero–based index to each logic segment:

  logic segment  logic segment  logic segment  logic segment
|--------------|--------------|--------------|--------------|
 ^              ^              ^              ^
#x000000       #x400000       #x800000       #xC00000
index 0        index 1        index 2        index 3

IK_SEGMENT_SHIFT is the number of bits to right–shift a pointer or tagged pointer to obtain the index of the logic segment containing the pointer itself; it is the number for which:

IK_SEGMENT_SIZE >> IK_SEGMENT_SHIFT = 1
2^IK_SEGMENT_SHIFT = IK_SEGMENT_SIZE

When we want to determine the page index and logic segement index of the pointer X:

  logic segment  logic segment  logic segment
|--------------|--------------|--------------|
 page page page page page page page page page
|----|----|----|----|----|----|----|----|----|
                       ^
                       X
|----|----|----|----|----|----|----|----|----| page indexes
  P   P+1  P+2  P+3  P+4  P+5  P+6  P+7  P+7

|--------------|--------------|--------------| segment indexes
       S             S+1            S+2

we do:

X >> IK_PAGESHIFT     == IK_PAGE_INDEX(X)    == P+4
X >> IK_SEGMENT_SHIFT == IK_SEGMENT_INDEX(X) == S+1
C Preprocessor Macro: ikuword_t IK_SEGMENT_INDEX (ikuword_t X)

Given a tagged or untagged pointer X: return the index of the logic segment it belongs to.


Next: , Previous: , Up: objects memory   [Index]