NOTE

select, poll, epoll

Select, poll, and epoll provide I/O multiplexing. These notes compare them starting with select's descriptor copying, scanning, and count limits.

Operating Systems / LinuxCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. select

  • Several major disadvantages of select:
    • Every time select is called, the fd set needs to be copied from user space to kernel space. This overhead becomes large when there are many fds.
    • At the same time, each select call requires the kernel to traverse all passed-in fds. This overhead also becomes large when there are many fds.
    • The number of file descriptors supported by select is too small; the default is 1024.
  • I/O Multiplexing - select

2. poll

  • Solves the third problem of select.
  • I/O Multiplexing - poll

3. epoll

  • Solves all three disadvantages of select.
  • I/O Multiplexing - epoll

3.1. LT

  • Level triggered: as long as the read buffer is not empty, read events continue to be triggered; as long as the write buffer is not full, write events continue to be triggered.
  • This is generally used because if an ET event is not handled properly after one trigger, there is no second chance.

3.2. ET

  • Edge triggered: triggers once when the read buffer changes from empty to nonempty; triggers once when the write buffer changes from full to non-full.
    • For example, a user sends a large file and fills the write buffer. Later, when the buffer becomes writable, a transition from full to non-full occurs once.

4. References

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub