demand_paging: LRU eviction: add missing documentation

Document missing eviction algorithm interface functions, and mention LRU.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2024-08-21 21:36:02 -04:00 committed by Carles Cufí
commit 57b2eaa09b

View file

@ -118,12 +118,19 @@ Eviction Algorithm
The eviction algorithm is used to determine which data page and its
corresponding page frame can be paged out to free up a page frame
for the next page in operation. There are two functions which are
for the next page in operation. There are four functions which are
called from the kernel paging code:
* :c:func:`k_mem_paging_eviction_init()` is called to initialize
the eviction algorithm. This is called at ``POST_KERNEL``.
* :c:func:`k_mem_paging_eviction_add()` is called each time a data page becomes
eligible for future eviction.
* :c:func:`k_mem_paging_eviction_remove()` is called when a data page is no
longer eligible for eviction. This may happen if the given data page becomes
pinned, gets unmapped or is about to be evicted.
* :c:func:`k_mem_paging_eviction_select()` is called to select
a data page to evict. A function argument ``dirty`` is written to
signal the caller whether the selected data page has been modified
@ -133,12 +140,23 @@ called from the kernel paging code:
The function returns a pointer to the page frame corresponding to
the selected data page.
Currently, a NRU (Not-Recently-Used) eviction algorithm has been
implemented as a sample. This is a very simple algorithm which
ranks each data page on whether they have been accessed and modified.
The selection is based on this ranking.
There is one additional function which is called by the architecture's memory
management code to flag data pages when they trigger an access fault:
:c:func:`k_mem_paging_eviction_accessed()`. This is used by the LRU algorithm
to requeue "used" pages.
To implement a new eviction algorithm, the two functions mentioned
Two eviction algorithms are currently available:
* An NRU (Not-Recently-Used) eviction algorithm has been implemented as a
sample. This is a very simple algorithm which ranks data pages on whether
they have been accessed and modified. The selection is based on this ranking.
* An LRU (Least-Recently-Used) eviction algorithm is also available. It is
based on a sorted queue of data pages. The LRU code is more complex compared
to the NRU code but also considerably more efficient. This is recommended for
production use.
To implement a new eviction algorithm, the five functions mentioned
above must be implemented.
Backing Store