In-depth understanding of IO mode under LINUX (1) - some basic concepts

I have read a lot of IO and NIO texts on the Internet, and they are uneven. Each article is always missing one or two points, so here is a summary of my own understanding. Maybe there is something wrong.

 

 

1. Basic Concepts
1.1) Synchronous/Asynchronous, blocking/non-blocking
Synchronous and asynchronous are mainly aimed at the C side:
The so-called synchronization means that when a function call is issued on the c side, the call will not return until the result is obtained. That is to say, one thing must be done one by one, and the next thing can only be done after the previous one is completed.
The concept of asynchrony is the opposite of synchronization. When an asynchronous procedure call is issued on the c side, the caller cannot get the result immediately. The component that actually handles the call notifies the caller with status, notification, and callback when it's done.
 
Blocking and non-blocking are mainly for the S side:
A blocking call means that before the call result returns, the current thread will be suspended (the thread enters a non-executable state, in which the CPU will not allocate a time slice to the thread, that is, the thread is suspended). The function does not return until it has a result.
The concepts of non-blocking and blocking correspond to each other, which means that the function will not block the current thread until the result cannot be obtained immediately, but will return immediately.


 
1.2) Stream-oriented, buffer-oriented
Stream-oriented: Read one or more bytes from the stream at a time, until all bytes are read, they are not cached anywhere.
Buffer-oriented: Data is read into a buffer that it processes later, moving back and forth in the buffer as needed. This increases flexibility in processing.
 
1.3) Kernel mode and user mode
The kernel space can access the protected memory (the upper 1G of 32-bit is the kernel space), and the remaining 3G is the user space
The operating system restricts the user mode from directly accessing hardware devices, so two steps are required to move data from the hardware to the memory of the user process.
 

 
 
1.4) mmap (memory map)
Map a file or other object to the address space of the process, and realize the one-to-one mapping relationship between the file disk address and a virtual address in the virtual address space of the process


  

 
 
2. 5 IO models under linux


 
5 IO modes about synchronous, asynchronous, blocking and non-blocking relationships
  block non-blocking
Synchronize BIO nonblockingIO
multiplexing IO (NIO1.0)
asynchronous X AIO
 
1,BIO:
Block the current thread, waiting for data to be prepared


 
2,nonblockingIO:
It is equivalent to rotation training, cutting the waiting time of large pieces into small pieces,


 
3, Multiplexing IO (IO mulitplexing) NIO in JAVA
Monitor multiple sockets, return when any data is ready, and then call the read function to read the data in the user process. In extreme cases, if only one socket is monitored, it is the same as BIO. Only when there are many sockets to monitor, will the efficiency be highlighted .
Focus, detailed later


 
4. Signal-driven I/O
5, asynchronous IO


 At present, there are implementation solutions under Linux, but there are still bugs, and the operation efficiency is not higher than that of multiplexing. All JDK17 has always used multiplexing
 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326328248&siteId=291194637