Re:Linux: What Can You Epoll?
by wtallis on Saturday October 22, 2022 @02:02PM
(#33300521)
That doesn't answer the question. Blocking isn't a matter of how much data is written, but a matter of when the system call completes. Other parts of that man page imply that write(2) may block, unless the fd was opened with O_NONBLOCK (in which case you'll get an EAGAIN error instead of it blocking).
[ Parent
| on HN ]
Re:Linux: What Can You Epoll?
by throwaway09223 on Saturday October 22, 2022 @02:51PM
(#33300989)
> (in which case you'll get an EAGAIN error instead of it blocking).
You won't. O_NONBLOCK cannot be used with regular files. That part of the manpage is discussing other non-socket file types.
Disk i/o via write(2) is always a blocking call. Always. 100% of the time, no exceptions.
"It's complicated." Generally, with a regular file, write(2) will complete as soon as the the data makes it to filesystem buffers/cache. The data is probably not on disk when the call completes. This depends on how the file was opened (O_FSYNC, O_DIRECT, etc.) and the underlying filesystem itself. There are many other details at work, like actual file system, memory pressure (there may not be enough buffers), cache in the physical disk device or controller, etc. So the write call itself is "blocking", but the physical writes are (generally) not synchronous with the call.
Yes, whether a write blocks is really about whether the application can do anything else while the write is processed; whether the application is told the write is done when it lands in a cache or when it is actually on stable storage is a separate question.