Predictable paging in real-time systems: a compiler approach
Isabelle Puaut Damien Hardy Universit´e Europ´eenne de Bretagne / IRISA, Rennes, France
Abstract ics (IMA) systems or for the automotive industry. Such sys- tems need spatial separation between processes, which can Conventionally, the use of virtual memory in real-time be easily implemented via the use of the Memory Manage- systems has been avoided, the main reason being the diffi- ment Unit (MMU) of commercial processors. Moreover, culties it provides to timing analysis. However, there is a cost constraints may limit the amount of physical memory trend towards systems where different functions are imple- available. mented by concurrent processes. Such systems need spa- Virtual memory consists in using hardware support tial separation between processes, which can be easily im- (MMU, Memory Management Unit) to compute at run-time plemented via the use of the Memory Management Unit where an address (called virtual address) is located in phys- (MMU) of commercial processors. In addition, some sys- ical memory. The virtual address space of a program is di- tems have a limited amount of physical memory available. vided up into fixed-size units called pages. The mapping So far, attempts to provide real-time address spaces have between virtual pages and physical pages is stored in data focused on the predictability of virtual to physical address structures scanned by the MMU at every memory access translation and do not implement demand-paging. (page tables stored in RAM and a fully-associative cache In this paper we propose a compiler approach to intro- named TLB, for Translation Look-aside Buffer to speed-up duce a predictable form of paging, in which page-in and accesses to page tables). When a program attempts to refer- page-out points are selected at compile-time. The problem ence an unmapped page, the MMU notices that the page is under study can be formulated as a graph coloring prob- unmapped and traps to the operating system; such a trap is lem, as in register allocation within compilers. Since the called a page fault. Upon a page fault, the operating system graph coloring problem is NP-complete for more than three loads the page from disk (page-in). Symmetrically, when colors, we define a heuristic, which in contrast to those used there is no free physical page anymore, a replacement pol- for register allocation, aim at minimizing worst-case perfor- icy implemented by the operating system selects one phys- mance instead of average-case performance. Experimental ical page to evict from main memory (page-out). Modified results applied on tasks code show that predictability does pages have to be copied back to disk before being evicted; not come at the price of performance loss as compared to this is done either in the page fault handler or by an inde- standard (dynamic) demand paging. pendent process depending on the operating system. The interests of virtual memory are twofold: (i) it provides spa- tial protection between processes, since each process has a 1 Introduction private page table; (ii) it allows to execute tasks whose ad- dress space is larger than the capacity of physical memory, Memory management is a major concern when devel- since pages are paged-in and out on demand, in a transpar- oping real-time and embedded applications. Predictabil- ent manner to the programmer. ity issues have resulted in real-time systems being most In real-time systems, it is crucial to prove that tasks will of the times strictly static, avoiding dynamic alloca- meet their temporal constraints in all situations, including tion/deallocation and virtual memory. However, as these the worst-case situation. Therefore, predictability of perfor- systems are getting increasingly large and complex, there is mance is as important as average-case performance. One now a need to escape from this strictly static memory man- should be able to predict the Worst-Case Execution Time agement. (WCET) of pieces of software for the system timing valida- In particular, a recent trend towards systems where dif- tion [13]. Virtual memory raises predictability issues at two ferent functions are implemented by concurrent processes levels: can be observed, for instance in Integrated Modular Avion-