当前位置:网站首页>What are the problems with traditional IO? Why is zero copy introduced?
What are the problems with traditional IO? Why is zero copy introduced?
2022-06-25 07:49:00 【Zhan sir (open source byte)】
Conventional IO What are the problems ? Why zero copy ?
If the server wants to provide the function of file transfer , The simplest way we can think of is : Read out the files on the disk , And then send it to the client through the network protocol .
Tradition I/O The way we work is , Data read and write are copied back and forth from user space to kernel space , And the kernel space data is through the operating system level I/O Interface to read or write from disk .
The code is usually as follows , Generally, two system calls are required :
read(file, tmp_buf, len); write(socket, tmp_buf, len);
The code is simple , Although only two lines of code , But there's a lot going on here .
First , A total of 4 Context switch between secondary user mode and kernel mode , Because there were two system calls , Once it was read() , Once it was write(), Every system call must first switch from user mode to kernel mode , After the kernel completes its task , Then switch from kernel mode to user mode .
The cost of context switching is not small , A switch takes tens of nanoseconds to microseconds , Although the time seems short , But in a high concurrency scenario , This kind of time is easy to accumulate and amplify , This will affect the performance of the system .
secondly , It also happened 4 Secondary data copy , among Twice DMA A copy of the , in addition Twice through CPU Copy Of , Let's talk about the process :
- The first copy , Copy the data on the disk into the buffer of the operating system kernel , The process of copying is through DMA Carrying .
- Second copy , Copy the data from the kernel buffer to the user's buffer , So our application can use this data , This copy to process is done by CPU Accomplished .
- The third copy , Just copy the data to the user's buffer , And then copy it to the kernel socket In the buffer of , The process is still by CPU Carrying .
- The fourth copy , Put the kernel of socket Data in the buffer , Copy to the network card buffer , This process is again caused by DMA Carrying .
Let's go back to the file transfer process , We're just carrying a piece of data , It turned out to be carrying 4 Time , Too many copies of data will no doubt consume CPU resources , Greatly reduces system performance .
This simple and traditional way of file transfer , There are redundant handoffs and data copies , It's very bad in a highly concurrent system , A lot of unnecessary expenses , Will seriously affect system performance .
therefore , To improve the performance of file transfer , You need to reduce 「 Context switch between user mode and kernel mode 」 and 「 Memory copy 」 The number of times .
If you reprint , Please indicate the source : Open source byte https://sourcebyte.cn/article/169.html
边栏推荐
猜你喜欢
"Spatial transformation" significantly improves the quality of ground point extraction of cliff point cloud
Tupu software digital twin 3D wind farm, offshore wind power of smart wind power
Find out what informatization is, and let enterprises embark on the right path of transformation and upgrading
navicat定时任务无效
Chuantu microelectronics 𞓜 subminiature package isolated half duplex 485 transceiver
Fairmot yolov5s to onnx
Construction of occupancy grid map
OAuth 2.0 one click login
[single chip microcomputer project training] multipoint temperature wireless acquisition system based on nRF905
一“石”二“鸟”,PCA有效改善机载LiDAR林下地面点部分缺失的困局
随机推荐
27. 移除元素
2265. 统计值等于子树平均值的节点数
VOCALOID笔记
力扣78:子集
npm install 报错 : gyp ERR! configure error
不同路径II[针对DFS的动态规划改进]
剑指 Offer II 027. 回文链表
PCB board design - automatic layout 2021-10-15
navicat定时任务无效
饮食干预减轻癌症治疗相关症状和毒性
[batch dos-cmd command - summary and summary] - file and directory operation commands (MD, RD, xcopy, dir, CD, set, move, copy, del, type, sort)
Advantages and differences of three kinds of vias in PCB 2021-10-27
lebel只想前面有星号,但是不想校验
Usememo simulation usecallback
Accès à la boîte aux lettres du nom de domaine Lead à l'étranger
c# winform panel自定义图片和文字
SSL证书免费获取教程
【视频】ffplay 使用mjpeg格式播放usb摄像头
Knowledge sharing 𞓜 conventional laminated structure of six layer PCB
Modular programming of oled12864 display controlled by single chip microcomputer