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 @@
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 addressTrim
: 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.When swap
is enabled, the flags have the following meaning:
From the standpoint of memory management, a page can only have the following states:
V
set, P
may not be setS
is set and V
is not setP
is set. V
is not set. S
may also not be set.V
is not set, and at least one other flag is set except for S
Allocated
: V
set, P
may not be setFault
: No flags are set, or S
is set and V
is not setSwapped
: P
is set. V
is not set. S
may also not be set. Upon access to this page, the kernel allocates a resident page and calls ReadFromSwap
to fill it. The page will move to the Allocated
state on conclusion.Reserved
: V
is not set, P
is not set, and at least one other flag is set except for S
. A kernel allocates a resident page and zeros it. The page will move to the Allocated
state on conclusion.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.
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
.
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:
V
bit and set the P
bit of the evicted page's PTEWriteToSwap
messageReadFromSwap
: 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 addressTrim
: 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.When swap
is enabled, the flags have the following meaning:
From the standpoint of memory management, a page can only have the following states:
V
set, P
may not be setS
is set and V
is not setP
is set. V
is not set. S
may also not be set.V
is not set, and at least one other flag is set except for S
Allocated
: V
set, P
may not be setFault
: No flags are set, or S
is set and V
is not setSwapped
: P
is set. V
is not set. S
may also not be set. Upon access to this page, the kernel allocates a resident page and calls ReadFromSwap
to fill it. The page will move to the Allocated
state on conclusion.Reserved
: V
is not set, P
is not set, and at least one other flag is set except for S
. A kernel allocates a resident page and zeros it. The page will move to the Allocated
state on conclusion.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.
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
.
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:
V
bit and set the P
bit of the evicted page's PTEWriteToSwap
message