Why do we need to block the process address space in RAM?

http://linux.die.net/man/2/mlockall

mlockall () blocks the entire virtual address space of the calling process in RAM, preventing memory from being sent to the swap space.

Why is this important in real-time systems?

+4
source share
3 answers

This ensures that the memory is always in RAM and never moves to the swap disk. This greatly speeds up access to these memory locations significantly , since disks are extremely slow compared to RAM.

On a real-time system (linux is not RTS btw!) You need extremely low latency, so memory access resulting in disk access is generally not acceptable in temporary critical code.

+4
source

It can be used, for example, in real-time applications or data processing with a high degree of protection. This is a quote from mlockall () documentation:

Real-time applications require deterministic time and, for example, planning, paging - one of the main reasons for unexpected delays in program execution. Real-time applications usually also switch to the real-time scheduler with sched_setscheduler (2). Cryptographic graphical security software often treats critical bytes, such as passwords or private keys, as data structures. As a result of paging, these secrets can be transferred to in which they can be accessed by the enemy, after the security software has destroyed the secrets in RAM and completed. (But keep in mind that suspend mode is on laptops, and some desktop computers save a copy of system RAM to disk, regardless of memory lock.)

Real-time processes that use mlockall () to prevent delays in page errors must reserve enough blocked pages on the stack before entering a critical section, so no page error can be caused by function calls. This can be achieved by calling a function that allocates a sufficiently large automatic variable (array) and writing to memories occupied by this array to touch these pages of the stack. Thus, enough pages will be displayed for the stack and can be locked in RAM. A dummy record ensures that even copying errors on a page can occur in a critical section.

+2
source

In real-time processing, the key component is the real-time component, i.e. you cannot afford to wait from memory to swap places.

+1
source

Source: https://habr.com/ru/post/1402832/


All Articles