MindMap Gallery LinuxIO
This is a mind map about Linux IO, which mainly includes: synchronization and asynchronous, blocking and non-blocking, what exactly IO is doing, asynchronous IO, signal driver IO, IO multiplexing, synchronous non-blocking IO model, and synchronous blocking IO model.
Edited at 2025-03-06 02:05:47Rumi: 10 dimensions of spiritual awakening. When you stop looking for yourself, you will find the entire universe because what you are looking for is also looking for you. Anything you do persevere every day can open a door to the depths of your spirit. In silence, I slipped into the secret realm, and I enjoyed everything to observe the magic around me, and didn't make any noise. Why do you like to crawl when you are born with wings? The soul has its own ears and can hear things that the mind cannot understand. Seek inward for the answer to everything, everything in the universe is in you. Lovers do not end up meeting somewhere, and there is no parting in this world. A wound is where light enters your heart.
Chronic heart failure is not just a problem of the speed of heart rate! It is caused by the decrease in myocardial contraction and diastolic function, which leads to insufficient cardiac output, which in turn causes congestion in the pulmonary circulation and congestion in the systemic circulation. From causes, inducement to compensation mechanisms, the pathophysiological processes of heart failure are complex and diverse. By controlling edema, reducing the heart's front and afterload, improving cardiac comfort function, and preventing and treating basic causes, we can effectively respond to this challenge. Only by understanding the mechanisms and clinical manifestations of heart failure and mastering prevention and treatment strategies can we better protect heart health.
Ischemia-reperfusion injury is a phenomenon that cellular function and metabolic disorders and structural damage will worsen after organs or tissues restore blood supply. Its main mechanisms include increased free radical generation, calcium overload, and the role of microvascular and leukocytes. The heart and brain are common damaged organs, manifested as changes in myocardial metabolism and ultrastructural changes, decreased cardiac function, etc. Prevention and control measures include removing free radicals, reducing calcium overload, improving metabolism and controlling reperfusion conditions, such as low sodium, low temperature, low pressure, etc. Understanding these mechanisms can help develop effective treatment options and alleviate ischemic injury.
Rumi: 10 dimensions of spiritual awakening. When you stop looking for yourself, you will find the entire universe because what you are looking for is also looking for you. Anything you do persevere every day can open a door to the depths of your spirit. In silence, I slipped into the secret realm, and I enjoyed everything to observe the magic around me, and didn't make any noise. Why do you like to crawl when you are born with wings? The soul has its own ears and can hear things that the mind cannot understand. Seek inward for the answer to everything, everything in the universe is in you. Lovers do not end up meeting somewhere, and there is no parting in this world. A wound is where light enters your heart.
Chronic heart failure is not just a problem of the speed of heart rate! It is caused by the decrease in myocardial contraction and diastolic function, which leads to insufficient cardiac output, which in turn causes congestion in the pulmonary circulation and congestion in the systemic circulation. From causes, inducement to compensation mechanisms, the pathophysiological processes of heart failure are complex and diverse. By controlling edema, reducing the heart's front and afterload, improving cardiac comfort function, and preventing and treating basic causes, we can effectively respond to this challenge. Only by understanding the mechanisms and clinical manifestations of heart failure and mastering prevention and treatment strategies can we better protect heart health.
Ischemia-reperfusion injury is a phenomenon that cellular function and metabolic disorders and structural damage will worsen after organs or tissues restore blood supply. Its main mechanisms include increased free radical generation, calcium overload, and the role of microvascular and leukocytes. The heart and brain are common damaged organs, manifested as changes in myocardial metabolism and ultrastructural changes, decreased cardiac function, etc. Prevention and control measures include removing free radicals, reducing calcium overload, improving metabolism and controlling reperfusion conditions, such as low sodium, low temperature, low pressure, etc. Understanding these mechanisms can help develop effective treatment options and alleviate ischemic injury.
LinuxIO
What exactly is IO doing
When a user makes a file read request
1. Disk data is directly written to the kernel buffer through DMA (no CPU participation is required)
2. Copy the file from the memory buffer to the user buffer (requires CPU participation)
The kernel needs to copy the data twice and perform 2 user-state/kernel-state switching conversions.
Synchronous and asynchronous, blocking and non-blocking
block
After the caller initiates an IO request, he must wait for the IO operation to complete or an error occurs before the subsequent code can be executed. During this period, the caller will be suspended and is in a waiting state until the data transmission is completed.
Non-blocking
After the caller initiates an IO request, the non-blocking IO will not suspend the caller if the IO condition is not ready. It will immediately return to the eagin state so that the caller can decide on subsequent processing.
Blocking/non-blocking: It is concerned whether the caller is waiting for the I/O to complete (whether it is suspended)
synchronous
It means that the execution process of the IO operation is included in this IO call. The caller gets the final data, whether it is successful data or the error returned.
asynchronous
The triggered IO call does not contain the IO execution process. The IO request initiated by the caller is just an IO submission process. The call function returns not the IO operation. However, when I execute IO asynchronously, the execution result of this IO is obtained at a certain moment in the future through a certain mechanism, such as a callback function, etc.
Synchronous/asynchronous: Focus on how I/O operations are executed
Synchronous blocking IO model
When the user program makes an IO request, the process is blocked and the subsequent logic cannot be executed. The subsequent logic can be performed after the IO is completed.
A process/thread can only handle one IO
Most of the file readings of Linux are synchronous blocking IO models
Advantages: Simple model and easy to implement Disadvantages: In high concurrency scenarios, a large number of threads/processes need to be created, resulting in waste of resources
Synchronous non-blocking IO model
When the user program makes an IO request, the kernel immediately returns to the eagin state. The user can poll the area to query the kernel's status until it is successful. During this process, the user will not stop doing so, and the subsequent logic is still executed
Advantages: The program does not need to be blocked, and the user program can execute other logic while waiting. Disadvantages: Frequent polling will take up a lot of CPU resources.
IO multiplexing
A process/thread can only process one IO. Users can listen to multiple IO events at the same time through IO multiplexing. When the IO event is ready, IO processing can be performed. Although only one can be processed at the same time, multiple can be processed within a period of time, achieving the effect of concurrency.
A process/thread can handle multiple IOs
Advantages: Improves the IO capability of the machine, and a process can handle more IO Disadvantages: The implementation is more complicated
Signal drive IO
Let the kernel send signals to the user program when the data of the file descriptor is ready, thus avoiding the process's continuous waiting for IO data preparation.
The user program registers a signal processing function through a sigaction system call and associates it with the file descriptor. When the file descriptor IO event is ready, the kernel sends a signal to the user program, and the user program performs IO operations in the signal processing function.
Advantages: The program does not need to be blocked, and the user program can execute other logic while waiting. Disadvantages: The implementation is complex, the user needs to implement the signal reception logic by himself, and when a large amount of IO occurs, signal processing will cause performance problems.
Asynchronous IO
When the user program makes an IO request, it only submits an IO task to the kernel, without blocking and polling and querying. When the kernel IO operation is completed, the callback function is triggered to notify the user program that the IO has completed
Advantages: Asynchronous IO can achieve IO request aggregation and then batch handed over to the kernel for processing, greatly improving concurrency capabilities. Disadvantages: Asynchronous I/O implementation in some systems (such as early Linux) is not perfect and requires relying on thread pool simulation.