当前位置:网站首页>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
边栏推荐
- 双三次差值bicubic
- PCB board design - automatic layout 2021-10-15
- 差点被这波Handler 面试连环炮带走~
- 微信小程序开通客服消息功能开发
- How much do you know about electronic components on PCB?
- 2265. 统计值等于子树平均值的节点数
- Share the process requirements for single-layer flexible circuit board
- The method of judging whether triode can amplify AC signal
- 搞清信息化是什么,让企业转型升级走上正确的道路
- Knowledge sharing 𞓜 conventional laminated structure of six layer PCB
猜你喜欢
realsense d455 semantic_slam实现语义八叉树建图
Four software 2021-10-14 suitable for beginners to draw PCB
Sichuan earth microelectronics high performance, high integration and low cost isolated 485 transceiver
Requirements for Power PCB circuit board design 2021-11-09
Modular programming of LCD1602 LCD controlled by single chip microcomputer
[little knowledge] PCB proofing process
Knowledge sharing 𞓜 conventional laminated structure of six layer PCB
NPM install reports an error: gyp err! configure error
OpenCV每日函数 结构分析和形状描述符(8) fitLine函数 拟合直线
【蒸馏】PointDistiller: Structured Knowledge DistillationTowards Efficient and Compact 3D Detection
随机推荐
函数模板_类模板
How to use printf of 51 single chip microcomputer
如何用svn新建属于自己的分支
力扣76题,最小覆盖字串
El input to add words to the tail
Hisilicon 3559 sample parsing: Vio
Sichuan Tuwei ca-is3105w fully integrated DC-DC converter
opencv最小值滤波(不局限于图像)
2265. 统计值等于子树平均值的节点数
Modular programming of LCD1602 LCD controlled by single chip microcomputer
Static bit rate (CBR) and dynamic bit rate (VBR)
Bicubic difference
Chuantu microelectronics ca-if1051 can-fd transceiver
OAuth 2.0一键登录那些事
Shell tips (134) simple keyboard input recorder
NSIS 静默安装vs2013运行时
c# winform panel自定义图片和文字
个人域名和企业域名的区别
Cglib dynamic proxy
test