60 likes | 166 Views
Assignment 4. Introduction. Typically when we think of analyzing file data we consider the use of system calls e.g ., open() , read() , write() Each file access requires a system call and disk access We can use virtual memory techniques to treat file I/O as routine memory accesses
E N D
Introduction • Typically when we think of analyzing file data we consider the use of system calls e.g ., open(), read(), write() • Each file access requires a system call and disk access • We can use virtual memory techniques to treat file I/O as routine memory accesses • This is known as memory mapping a file
Basic Mechanism • Memory mapping a file I accomplished by mapping a disk block to a page (or pages) in memory. • Initial access to the file proceeds through ordinary demand paging • However, a page-sized portion of the file is read from the file system into a physical page
Basic Mechanism • Subsequent reads and writes to the file are handled as routine memory accesses • Allows system to manipulate files through memory rather than incurring the overhead of of using the read() and write() system calls • Recall that the system calls involve disk I/O
Basic Mechanism • Writing to a file in mapped to main memory? What happens to file? • Could be immediate but high overhead • The OS periodically checks whether the page in memory has been modified • When the file is closed, all the memory mapped data are written back to disk and removed from the virtual memory of that process
mmap() System Call void * mmap (void *addr, size_tlen, intprot , int flags, intfd, off_t offset); Consult the following URL for more info: http://beej.us/guide/bgipc/output/html/multipage/mmap.html