next up previous contents index
Next: Allocation Algorithms Up: Mapping and Address Conversion Previous: Mapping and Address Conversion

mmap() system call

  

The mmap() system call is the POSIX standard programming interface for mapping a region of a file in main memory. The routine has the signature of

     void *mmap(void *start, size_t length, 
                int prot, int fd, int flags, 
                off_t offset);

The first parameter start is the starting address of the mapped region in main memory but it is strongly recommended for portability that this parameter should be set to 0, in which case the return value of this routine indicates the starting address. The second parameter length is the length of the mapped region in bytes. The third parameter prot is the protection mode for the region, which indicates reading, writing, and execution permission of the region. The fourth parameter flags indicates the mapping type which can be shared, private, or fixed. In the shared type, the same physical memory is used for mapping the same region of the file. In the private type, the memory is mapped as copy-on-write and modification in the region does not affect the other mappings of the same region of the file. In the fixed type, the memory is located at the specified logical address in main memory, which degrades portability of the program. The fifth parameter fd is the file descriptor of the file to be mapped. The last parameter offset is the starting offset of the region in the file. The mapping is performed page by page. In most operating systems, a page has the size of 4096 bytes. [Linux:mmap 96] [Vahalia 96]

There are some relatives of mmap() routine, such as munmap() for unmapping, msync() for synchronization with the file.


next up previous contents index
Next: Allocation Algorithms Up: Mapping and Address Conversion Previous: Mapping and Address Conversion
Mori Tetsuya / t2y3141592@gmail.com