Week 12

Lecture recording here.

Lab recording here.

Introduction

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.

Videos

Memory MappingHow 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)

Quiz

Lecture Material

Labs

Assignment

Assignment 2.

Additional Lecture Material

An overview of virtual memory can be seen at:
Virtual Memory

Locations of shared memory, memory mappings, and shared libraries can be seen below:
Shared Memory, Memory Mappings, Shared Libraries

Two processes with a shared mapping of the same region of a file can be seen at:
Shared Mapping

Sample Code

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:

Memory mapping with a 4-channel Radio

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.