pub struct MemoryImageSlot { /* private fields */ }
Expand description

Slot management of a copy-on-write image which can be reused for the pooling allocator.

This data structure manages a slot of linear memory, primarily in the pooling allocator, which optionally has a contiguous memory image in the middle of it. Pictorially this data structure manages a virtual memory region that looks like:

  +--------------------+-------------------+--------------+--------------+
  |   anonymous        |      optional     |   anonymous  |    PROT_NONE |
  |     zero           |       memory      |     zero     |     memory   |
  |    memory          |       image       |    memory    |              |
  +--------------------+-------------------+--------------+--------------+
  |                     <------+---------->
  |<-----+------------>         \
  |      \                   image.len
  |       \
  |  image.linear_memory_offset
  |
  \
 self.base is this virtual address

   <------------------+------------------------------------------------>
                       \
                     static_size

   <------------------+---------------------------------->
                       \
                     accessible

When a MemoryImageSlot is created it’s told what the static_size and accessible limits are. Initially there is assumed to be no image in linear memory.

When MemoryImageSlot::instantiate is called then the method will perform a “synchronization” to take the image from its prior state to the new state for the image specified. The first instantiation for example will mmap the heap image into place. Upon reuse of a slot nothing happens except possibly shrinking self.accessible. When a new image is used then the old image is mapped to anonymous zero memory and then the new image is mapped in place.

A MemoryImageSlot is either dirty or it isn’t. When a MemoryImageSlot is dirty then it is assumed that any memory beneath self.accessible could have any value. Instantiation cannot happen into a dirty slot, however, so the MemoryImageSlot::clear_and_remain_ready returns this memory back to its original state to mark dirty = false. This is done by resetting all anonymous memory back to zero and the image itself back to its initial contents.

On Linux this is achieved with the madvise(MADV_DONTNEED) syscall. This syscall will release the physical pages back to the OS but retain the original mappings, effectively resetting everything back to its initial state. Non-linux platforms will replace all memory below self.accessible with a fresh zero’d mmap, meaning that reuse is effectively not supported.

Trait Implementations§

Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.