当前位置:网站首页>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
边栏推荐
- AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
- Microsoft Office Word 远程命令执行漏洞(CVE-2022-30190)分析与利用
- How to select lead-free and lead-free tin spraying for PCB? 2021-11-16
- This article uses pytorch to build Gan model!
- 50. Pow(x, n)-快速幂
- PCB board design - automatic layout 2021-10-15
- 饮食干预减轻癌症治疗相关症状和毒性
- ELK + filebeat日志解析、日志入库优化 、logstash过滤器配置属性
- Lebel only wants an asterisk in front of it, but doesn't want to verify it
- OpenCV每日函数 结构分析和形状描述符(8) fitLine函数 拟合直线
猜你喜欢

Ns32f103c8t6 can perfectly replace stm32f103c8t6

Modular programming of wireless transmission module nRF905 controlled by single chip microcomputer
![Insert and sort the linked list [dummy unified operation + broken chain core - passive node]](/img/2a/ccb1145d2b4f9fbd8d0812deace93b.png)
Insert and sort the linked list [dummy unified operation + broken chain core - passive node]

Function template_ Class template

微信小程序开通客服消息功能开发

Sichuan earth microelectronics high performance, high integration and low cost isolated 485 transceiver

Modular programming of digital light intensity sensor module gy-30 (main chip bh1750fvi) controlled by single chip microcomputer (under continuous updating)

Sichuan Tuwei ca-is3105w fully integrated DC-DC converter

Without "rice", you can cook "rice". Strategy for retrieving missing ground points under airborne lidar forest using "point cloud intelligent mapping"

navicat定时任务无效
随机推荐
用函数的递归来解决几道有趣的题
C Getting Started tutorial
[distillation] pointdistiller: structured knowledge distillationwards efficient and compact 3D detection
Chuantu microelectronics 𞓜 subminiature package isolated half duplex 485 transceiver
Elk + filebeat log parsing, log warehousing optimization, logstash filter configuration attribute
realsense d455 semantic_ Slam implements semantic octree mapping
饮食干预减轻癌症治疗相关症状和毒性
Six causes of PCB disconnection 2021-10-20
LeetCode_哈希表_中等_454.四数相加 II
神经网络与深度学习-3- 机器学习简单示例-PyTorch
Modular programming of digital light intensity sensor module gy-30 (main chip bh1750fvi) controlled by single chip microcomputer (under continuous updating)
Fairmot yolov5s to onnx
Runtime——methods成员变量,cache成员变量
Keil and Proteus joint commissioning
Four software 2021-10-14 suitable for beginners to draw PCB
php入门基础记录
Chuantu microelectronics ca-if1051 can-fd transceiver
"Spatial transformation" significantly improves the quality of ground point extraction of cliff point cloud
OpenCV每日函数 结构分析和形状描述符(8) fitLine函数 拟合直线
CPDA|数据分析师成长之路如何起步?