-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
demand paging for low-memory MMU-based systems #26088
Comments
This won't land for 2.4 although I have started on this now that I have proper memory mapping implemented on x86. First thing is to establish the kernel's runtime ontology of virtual data pages and physical memory frames. Define what additional For physical frames take a cue from Linux and establish a page frame struct, one for every page frame.
For virtual data pages, we also need to set up an ontology:
Finally two interfaces: eviction algorithm and transport mechanism. Implement trivial random eviction. Implement a transport mechanism simulator in QEMU that just uses additional RAM past where the kernel thinks it stops. Complexities/annoyances
Clearly define how we are going to differ from Linux. For example mappings will be permanent once established. Memory domains are still around (for now anyway). |
We need to clearly separate the work needed to support basic demand paging without user mode or SMP, and later work to support with those configurations. So for the first version:
|
Updated to-do list:
2.6 stuff:
Future:
Things we will punt on:
|
PR: #30907 |
we had this for a while, closing. |
Is your enhancement proposal related to a problem? Please describe.
Some systems have more firmware than available RAM. Given a situation where 20% of the code runs 80% of the time (or thereabouts), it's not unheard-of to implement demand paging support in microcontroller operating system on targets that have an MMU. Nuttx, for example supports this.
Describe the solution you'd like
Any demand paging implementation ought to meet the following broad requirements:
This needs to be orthogonal to user mode or any other infrastructure which uses the MMU, including stack guards and boot-time memory permissions.
The kernel will need to be linked at some designated virtual base address for the kernel's memory space (for example,
0xC0000000
), with the physical-to-virtual relocation of the instruction pointer taking place very early in the boot process. (Google "higher half kernel" for examples)Page tables themselves use a nontrivial amount of memory, and we should allow such usage to be minimized. The bounds of the kernel's address space should be configurable. For example, on IA32, if the kernel's address space starts at 0xC0000000 and is capped at 4MB in size, then a single page directory and a single page table is sufficient for all memory mapping needs.
We will need support for mapping device driver MMIO ranges into the kernel's memory space. Drivers can't assume that physical MMIO addresses are directly writable. Any solution for this must not impose unnecessary footprint or performance overhead on systems that do not have an MMU. If done at runtime, we'll need a generic API for mapping physical memory into the kernel's address space.
We will need the capability to pin certain pages into memory, such that they are never evicted. Core kernel functionality, interrupt handling, MMU tables, CPU tables, etc go here. It should be well-understood the minimum set of pinned memory pages. We'll need macros such that application code can pin code/data as well.
There needs to be a layer of abstraction for the page replacement algorithm used (the "eviction algorithm"), so that the user can choose among any provided by Zephyr or roll their own. https://en.wikipedia.org/wiki/Page_replacement_algorithm
There needs to be a layer of abstraction (the "transport mechanism") for page-ins/page-outs to/from the backing store. It could be flash memory, a different type of RAM, a DMA transfer operation, the core kernel must not care.
We need a rich set of instrumentation points to capture performance metrics of the demand paging implementation and how much paging took place in any given time period.
Additional context
It may be possible to do some driver virtual mappings at build time, with page tables produced by the build system already mapping driver MMIO ranges exported by DTS appropriately and the drivers compiled to use the virtual addresses. This is nicer than setting this all up at runtime, at the expense of complexity/build-time voodoo. This will likely be a future enhancement not in the initial implementation.
The kernel will need accounting data structures for all physical memory pages, much like
struct page
in Linux.The initial implementation will be on 32-bit x86. We will provide a simple random eviction algorithm, and an emulated backing store that works in QEMU (probably just some reserved memory region)
We eventually want to support ARM Cortex-A, ARM, Xtensa, any device with an MMU. The next implementation after 32-bit x86 will likely be 64-bit x86 so that we can sort out SMP issues.
Initial implementation on 32-bit x86 may not support user mode. After this is complete, user mode on MMU-based systems will be re-architected to use virtual memory spaces.
Much later on when we implement virtual memory spaces, any virtual memory below the kernel's base virtual address will be "userspace".
The text was updated successfully, but these errors were encountered: