42
• Line 125: As in the previous Linux example, we write a string to the
beginning of the file, accessing the file like memory.
• Line 132: We flush the modified memory page to the backing storage.
• Line 139: We flush the full file to backing storage, including any
additional file metadata maintained by Windows.
• Line 146-157: We unmap the file, close the file, then exit the program.
Figure 3-4 shows what happens inside the operating system when an application
calls mmap() on Linux or CreateFileMapping() on Windows. The operating system
allocates memory from its memory page cache, maps that memory into the application’s
address space, and creates the association with the file through a storage device driver.
As the application reads pages of the file in memory, and if those pages are not
present in memory, a page fault exception is raised to the operating system which will
then read that page into main memory through storage I/O operations. The operating
Figure 3-4. Memory-mapped files with storage
Chapter 3 Operating SyStem SuppOrt fOr perSiStent memOry
Précédent

- 71/457

Suivant