Comparison between MMAP and read/write on File Access
We know that files accessed through MMAP or read/write must be cached in the kernel. When you need to read and write content from the file, the files are copied to the cache in the kernel for communication.
1. in read/write mode, the user must specify the number of reads to the kernel, and then copy the obtained content from the kernel cache to the user space. The write process also needs to be roughly the same.
2. MMAP maps a part of the file to the user space to map the previously described kernel cache to the user space, so that the content can be read and written directly through the kernel buffer pool, in this way, the back-and-forth copying between the kernel and the user space is reduced, so it is usually faster.
Therefore, the advantage of MMAP is that compared with read/write, it reduces the copy overhead of a kernel cache to the user space memory. However, when creating a ing, MMAP must specify a ing area, therefore, this method is only applicable to updating and reading a fixed size file area, rather than constantly writing content to the file in an increasing manner.