diff --git a/ch10-00-swap-overview.html b/ch10-00-swap-overview.html index 94a1461..cdf0930 100644 --- a/ch10-00-swap-overview.html +++ b/ch10-00-swap-overview.html @@ -279,6 +279,7 @@

Kernel Runtime<
  • ReadFromSwap: a memory message that retrieves & decrypts a page from swap, and copies it to the lent page. The offset & valid fields encode the original PID and virtual address.
  • AllocateAdvisory: a scalar message that informs the swapper that a page in free RAM was allocated to a given PID and virtual address
  • Trim: a request from the kernel to free up N pages. Normally the kernel would not call this, as the swapper should be pre-emptively clearing space, but it is provided as a last-ditch method in case of an OOM.
  • +
  • Free: a scalar message that informs the swapper that a page was de-allocated by a process.
  • Flags and States

    When swap is enabled, the flags have the following meaning:

    @@ -296,11 +297,14 @@

    Flags and S

    From the standpoint of memory management, a page can only have the following states:

    +

    Pages go from Allocated to Swapped based on the swapper observing that the kernel is low on memory, and calling a series of EvictPage calls to free up memory. It is always assumed that the kernel can allocate memory when necessary; as a last ditch the kernel can attempt to call Trim on the swapper, but this should only happen in extreme cases of memory pressure.

    +

    Pages go from Allocated to Reserved when a process unmaps memory.

    +

    When the swapper runs out of space, WriteToSwap panics with an OOM.

    RegisterSwapper Syscall

    The swapper registers with the kernel on a TOFU basis. The kernel reserves a single 128-bit sid with the target of the swapper, and it will trust the first process to use the RegisterSwapper syscall with its 128-bit random ID.

    After registration, the kernel sends a message to the swapper with the location of the SPT/SMT regions as created by the bootloader, as well as the base and bounds of the free memory pool. The free memory pool is the region remaining after boot, after the loader has marked all the necessary RAM pages as wired.

    @@ -308,7 +312,7 @@

    EvictPage

    EvictPage is a syscall that only the swapper is allowed to call. It is a scalar send message, which contains the PID and address of the page to evict. Upon receipt, the kernel will:

    Flags and States

    When swap is enabled, the flags have the following meaning:

    @@ -3846,11 +3847,14 @@

    Flags and S

    From the standpoint of memory management, a page can only have the following states:

    +

    Pages go from Allocated to Swapped based on the swapper observing that the kernel is low on memory, and calling a series of EvictPage calls to free up memory. It is always assumed that the kernel can allocate memory when necessary; as a last ditch the kernel can attempt to call Trim on the swapper, but this should only happen in extreme cases of memory pressure.

    +

    Pages go from Allocated to Reserved when a process unmaps memory.

    +

    When the swapper runs out of space, WriteToSwap panics with an OOM.

    RegisterSwapper Syscall

    The swapper registers with the kernel on a TOFU basis. The kernel reserves a single 128-bit sid with the target of the swapper, and it will trust the first process to use the RegisterSwapper syscall with its 128-bit random ID.

    After registration, the kernel sends a message to the swapper with the location of the SPT/SMT regions as created by the bootloader, as well as the base and bounds of the free memory pool. The free memory pool is the region remaining after boot, after the loader has marked all the necessary RAM pages as wired.

    @@ -3858,7 +3862,7 @@

    EvictPage

    EvictPage is a syscall that only the swapper is allowed to call. It is a scalar send message, which contains the PID and address of the page to evict. Upon receipt, the kernel will: