CSCI 8530 Advanced Operating Systems Memory Locking Virtual Memory and Real Time Virtual memory is a useful feature in systems It provides Separation of memory spaces e g process A can t access process B s memory Protection for the OS from errant processes Apparent contiguous memory for things like arrays The major drawback to virtual memory is paging and or swapping 2 1 Paging Paging or more properly page replacement is the action taken by the system when a new page is needed in memory and insufficient empty page frames exist an empty must be created by copying the contents of an existing full page to disk Paging requires significant time for disk I O invalidation of cache entries and the cache misses that occur when a new page is brought into memory There is no reliable way a process can predict when paging will occur 3 Paging in Real Time Systems In non realtime systems the time spent on paging isn t a problem since the processes are not dependent on when they re executed That is they have functional but not temporal correctness requirements In realtime systems however the uncertainty associated with paging can result in failure to meet deadlines One approach to solving to this problem lies in locking pages in memory thus guaranteeing that paging will not occur for those locked pages 4 2 Locking All Pages in Memory The POSIX mlockall system call attempts to lock every page of memory accessibly by the calling process so they cannot be paged out returning 0 on success The single argument to mlockall specifies if only the current memory is to be locked MCL CURRENT or if only future memory allocations are to be locked MCL FUTURE or both MCL CURRENT MCL FUTURE POSIX does not specify what happens if a future memory allocation would exceed the available physical memory on the system it is your responsibility to avoid this situation mlockall isn t currently supported by QNX 5 Unlocking All Memory Pages The POSIX munlockall function undoes what mlockall did it unlocks the pages that were previously locked This does not mean the unlocked pages will be immediately paged out The function only informs the system that if necessary pages for the process may now be paged out Like mlockall munlockall isn t currently supported by QNX 6 3 Why Lock It All Locking all of the memory belonging to a process is usually overkill and might not be possible in some systems In most cases it is sufficient to lock down those pages that are critical to the current activities of the process The POSIX function mlock and munlock can be used to achieve locking of specified memory regions Neither is currently supported by QNX 7 mlock and munlock The mlock function takes two arguments A void pointer which specifies the lowest address in the memory to be locked An integer actually size t that specifies the number of bytes to be locked The munlock function takes the same arguments Both functions return 0 on success 8 4 Caveats Memory locking and unlocking is not cumulative If you lock the same region of memory twice and then unlock it once it s totally unlocked Thus a region of memory is either totally locked in physical memory or not locked at all This means that the design of a real time application that will run on a system that does paging must consider locking on a global application wide basis 9 5
View Full Document
Unlocking...