Commit Graph

3 Commits

Author SHA1 Message Date
Nicolas Pitre be119d7d8c demand_paging: LRU eviction: avoid ping pong deadlock loop
If only 2 page frames are queued and code executing in one frame is
making an access to memory in the second frame then the access will trap
and k_mem_paging_eviction_accessed() will be called to move that frame
to the end of the queue ... marking the new head frame unaccessible.
But that newly unaccessible frame contains the code that has yet to be
resumed to perform its memory access. Since it is now unaccessible, a
trap is triggered, the frame is moved to the end of the queue and the
new head frame (the one we trapped for initially) is marked unaccessible.
Execution is resumed with the memory access which is unaccessible again
and the cycle repeats infinitely.

Fix this by not marking the new head unaccessible if there is only one
queued frame left in the queue.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2024-08-06 17:15:15 -04:00
Nicolas Pitre 0c1301e728 demand_paging: LRU eviction: remove restriction on PF index 0
The first page frame index was reserved for head and tail ^pointers.
However there are cases where the first frame is actually made
evictable and would trigger the assertion guarding against that.

Fix this by applying an offset to actual frame indexes.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2024-07-03 15:07:03 -04:00
Nicolas Pitre 92bc0cd0da demand_paging: Least Recently Used (LRU) eviction algorithm
This is a O(1) LRU eviction algorithm. A bit more complex but way more
scalable than the NRU algorithm.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2024-06-14 18:58:02 -04:00