Using mapped files as external memory is not cheap. Disk accesses are much slower than memory, and using a normal filesystem to do swapping is even slower than normal swap space. Virtual memory files (VM files for short) should only be used when necessary, i.e. when normal memory is exhausted.
To ease the paging task for the operating system, the size of VM files should always be a multiple of the system's memory page size.
VM files should be deleted as soon as the pointer is released (by free()). If memory leaks occur, the module should make sure that all extra VM files are deleted when the process ends (with a possible warning about the leak).
The munmap() call requires the file handle and the allocated size to perform deallocation of the file. It means that these informations need to be stored together with the allocated pointer for the free() function to do its job.