Lecture recording here.
Lab recording here.
This week we are going to look at memory mapping. We will look at process memory some more, and we will look at virtual memory. We will look at the various memory mapping schemes across processes.
Memory Mapping | How to Map Files into Memory in C (mmap, memory mapped file io) |
CS 134 OS-7: Memory-Mapped Files | |
C++ Programming on Linux - Memory Mapped File (mmap system call) |
An overview of virtual memory can be seen at:
Locations of shared memory, memory mappings, and shared libraries can be seen below:
Two processes with a shared mapping of the same region of a file can be seen at:
Banking Application
Transaction Applications
Memory Mapping vs Shared Memory
Underneath it all, memory mapping and shared memory are basically the same. But memory mapping gives you much more flexibility.
In week 9 we looked at code that simulates 16 clients trying to write to a radio with four channels, with shared memory. To do the
same with memory mapping, we would make use of its many features to ensure the performance and operation are the same.
See:
We would use semaphores for synchronization. We would use msync to ensure our data writes are synchronized with the memory.
We would use mlock to ensure our memory is not swapped to disk. We would use mprotect to indicate read/write. We would use
madvise to advise the kernel that this memory region will be very busy.