When a process is ready to destroy a memory mapping, it invokes the munmap( ) system call, passing the following parameters to it:
• The address of the first location in the linear address interval to be removed
• The length of the linear address interval to be removed
Notice that the munmap( ) system call can be used to either remove or reduce the size of each kind of memory region. Indeed, the sys_munmap( ) service routine of the system call essentially invokes the do_munmap( ) function already described in Section 8.3.5. However, if the memory region maps a file, the following additional steps are performed for each memory region included in the range of linear addresses to be released:
1. Invokes remove_shared_vm_struct( ) to remove the memory region descriptor from the address space object list (either i mmap or i mmap shared).
2. When executing the unmap_fixup( ) function, decrements the file usage counter if an entire memory region is destroyed, and increments the file usage counter if a new memory region is created — that is, if the unmapping created a hole inside a region. If the region has just been shrunken, it leaves the file usage counter unchanged.
Notice that there is no need to flush to disk the contents of the pages included in a writable shared memory mapping to be destroyed. In fact, these pages continue to act as a disk cache because they are still included in the page cache (see the next section).
Was this article helpful?