简体   繁体   English

Syscall开销

[英]Syscall overhead

How big is (approximately) an I/O syscall overhead on Linux from C program, I mean how bad is running eg many small read / write operations compared with read / write on large buffers (on regular files or network sockets)? 有多大(大约)的I / O系统调用在Linux上从头顶C程序,我的意思是多么糟糕运行如很多小read / write相比操作read / write的大容量缓存(在普通文件或网络套接字)? App is strongly multithreaded. 应用程序是强多线程的。

Syscalls take at least 1-2 microseconds on most modern machines just for the syscall overhead , and much more time if they're doing anything complex that could block or sleep. Syscalls在大多数现代机器上至少需要1-2微秒, 仅用于系统调用开销 ,如果他们做任何可能阻塞或睡眠的复杂事件,则需要更多时间。 Expect at least 20 microseconds and up to the order of milliseconds for IO. 预计IO至少需要20微秒,最高可达毫秒级。 Compare this with a tiny function call or macro that reads a byte from a userspace buffer, which is likely to complete in a matter of nanoseconds (maybe 200 ns on a bad day). 比较一个微小的函数调用或宏从用户空间缓冲区读取一个字节,这可能在几纳秒内完成(在糟糕的一天可能是200 ns)。

You can measure this yourself. 你可以自己测量一下。 Just open /dev/zero and do some reading and writing while measuring the time. 只需打开/dev/zero并在测量时间时进行一些读写操作。 Also vary the number of bytes you put into each call - eg 1 bytes, 2 bytes, 128 bytes, .. 4096bytes. 还可以改变每次调用的字节数 - 例如1个字节,2个字节,128个字节,4096个字节。 Also take care to use the read(2) and write(2) syscalls and not anything using internal buffers. 还要注意使用read(2)write(2)系统调用,而不是使用内部缓冲区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM