Agenda
<aside> 📌 Reminders
Usually, we use system calls like read and write to interact with files on disk
Memory mapping gives us another way to interface with files; by mapping them directly to memory, we can interact with them using memory operations.
This has the advantage of reducing the amount of IO that is expected from the system, as we know, this is typically the most expensive part of most programs.
On the other hand, changes to the file are not immediately reflected, which can lead to unexpected outcomes, especially when multiple processes/threads map or modify the same file
Memory mapping in pintOS is accomplished through the mmap and munmap system calls:
mapid_t mmap(int fd, void *addr)
fd: the file descriptor of a file opened by the process, if there is no such open file, or if the corresponding file is stdin or stdout, return -1*addr : the virtual address of the region in memory to which the file will be mapped, must be:
mmaped file, or stack pagepg_ofs (const void *va))-1 if any of these checks failmapid_t that uniquely identifies the mapping within this processvoid munmap (mapid_t mapping)
mapping: a mapping ID previously returned by a call to mmap that has not been already un-mappedSome notes about mmap