Memory Management
Memory Mappings
mmap and munmap
Supported functionality in SCML:
prot = PROT_NONE |
    PROT_EXEC |
    PROT_READ |
    PROT_WRITE;
opt_flags =
    MAP_ANONYMOUS |
    MAP_FIXED |
    MAP_FIXED_NOREPLACE |
    MAP_GROWSDOWN |
    MAP_HUGETLB |
    MAP_LOCKED |
    MAP_NONBLOCK |
    MAP_NORESERVE |
    MAP_POPULATE |
    MAP_SYNC;
// Create a private memory mapping
mmap(
    addr, length,
    prot = <prot>, 
    flags = MAP_PRIVATE | <opt_flags>
    fd, offset
);
    
// Create a shared memory mapping
mmap(
    addr, length,
    prot = <prot>, 
    flags = MAP_SHARED | MAP_SHARED_VALIDATE | <opt_flags>
    fd, offset
);
// Unmap a memory mapping
munmap(addr, length);
Silently-ignored flags:
MAP_HUGETLBMAP_GROWSDOWNMAP_LOCKEDMAP_NONBLOCKMAP_NORESERVEMAP_POPULATEMAP_SYNC
Partially supported flags:
MAP_FIXED_NOREPLACEis treated asMAP_FIXED
Unsupported flags:
MAP_32BITMAP_HUGE_1GBMAP_HUGE_2MBMAP_UNINITIALIZED
For more information, see the man page.
msync
Supported functionality in SCML:
// Flush memory region to disk asynchronously
msync(
    addr, length,
    flags = MS_ASYNC | MS_INVALIDATE
);
// Flush memory region to disk synchronously
msync(
    addr, length,
    flags = MS_SYNC | MS_INVALIDATE
);
Silently-ignored flags:
MS_INVALIDATEis ignored because all processes use the same page cache
For more information, see the man page.
mremap
Supported functionality in SCML:
// Resize an existing memory mapping. Relocation is allowed if given `MREMAP_MAYMOVE`.
mremap(
    old_address,
    old_size,
    new_size,
    flags = MREMAP_MAYMOVE
);
// Resize an existing memory mapping and force relocation to a specified location.
mremap(
    old_address,
    old_size,
    new_size,
    flags = MREMAP_MAYMOVE | MREMAP_FIXED,
    new_address
);
For more information, see the man page.
mprotect
Supported functionality in SCML:
// Set memory access permissions
mprotect(
    addr,
    len,
    prot = <prot>
);
Silently-ignored protection flags:
PROT_SEMPROT_SAOPROT_GROWSUPPROT_GROWSDOWN
For more information, see the man page.
madvise
Supported functionality in SCML:
// Apply the default memory access pattern with no special optimizations
madvise(addr, length, advice = MADV_NORMAL);
// Indicate sequential access to enable aggressive read-ahead and immediate page release
madvise(addr, length, advice = MADV_SEQUENTIAL);
// Prefetch pages for near-future access to reduce latency
madvise(addr, length, advice = MADV_WILLNEED);
Silently-ignored advice:
MADV_DONTNEED
Unsupported advice:
MADV_RANDOMMADV_REMOVEMADV_DONTFORKMADV_DOFORKMADV_HWPOISONMADV_MERGEABLEMADV_UNMERGEABLEMADV_SOFT_OFFLINEMADV_HUGEPAGEMADV_NOHUGEPAGEMADV_DONTDUMPMADV_DODUMPMADV_FREEMADV_WIPEONFORKMADV_KEEPONFORK
For more information, see the man page.