What is the difference between direct IO and memory mapping?

does it seem that kernel cache has been removed from data replication?

Mar.16,2021

  1. normal read goes through two copies of disk-"kernel buffer -" user area;
  2. memory mapping is a virtual memory technology, which maps a file directly to virtual memory, thus accessing the file (including missing page interrupts) like memory without requiring two copies of read. The virtual memory and physical memory mapping operating system can help you solve the problem. In addition, memory mapping can also be used for IPC;
  3. .
  4. Direct IO omits the kernel buffer in 1 (because the kernel buffer is determined by the kernel, of course, users can show that sync), users can buffer themselves.

two are not the same concept.
Direct IO corresponds to Buffer IO.
Direct IO is to submit the IO request directly to the underlying IO device without caching.

Buffer IO means that the IO request is cached by the subsystem, such as the VFS Cache layer on Linux.
write data is first written to memory and then returned, without waiting for the data to be brushed to disk.
read data will first try to read from memory, if the memory hit, there is no need to read from disk.
Buffer IO brings a significant improvement in read and write performance, which is the same concept as adding a Memcached in front of the database.
, Buffer IO is the best choice in most scenarios.

We may need to consider Direct IO:

in the following cases
  1. requires high reliability for data writing, and you must ensure that the data falls on disk before the business logic can continue to execute.
  2. in specific scenarios, the efficiency of the system's own cache algorithm is not high, and the application layer implements a higher algorithm on its own.

and memory mapping is another big concept, expansion will have a lot of content; If you only look at the part of the file IO, accessing the file through Linux mmap is actually a piece of memory allocated by the application, which directly acts as the cache in the process of reading and writing the file, which can be accessed directly by the user mode, instead of copying the buffer of the user mode to the cache allocated by the kernel like the normal read/write mode, the essence of which is that buffer IO, only saves the copying overhead from the user mode to the kernel mode.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bde4d6-3140a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bde4d6-3140a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?