ArticleslgStudy

computer science

Epoll

Epoll is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Epoll rather than just read about it. In short: epoll is a Linux kernel system call for a scalable I/O event notification mechanism, first introduced in version 2.5.45 of the Linux kernel in October, 2002. Its function is to monitor multiple file descriptors to see whether I/O is possible on any of them.

Key takeaways

  • Epoll belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Epoll to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Epoll from memory before moving on to harder problems.

Reference excerpt

epoll is a Linux kernel system call for a scalable I/O event notification mechanism, first introduced in version 2.5.45 of the Linux kernel in October, 2002. Its function is to monitor multiple file descriptors to see whether I/O is possible on any of them. It is meant to replace the older POSIX select(2) and poll(2) system calls, to achieve better performance in more demanding applications, where the number of watched file descriptors is large (unlike the older system calls, which operate in O(n) time, epoll operates in O(1) time). epoll is similar to FreeBSD's kqueue, in that it consists of a set of user-space functions, each taking a file descriptor argument denoting the configurable kernel object, against which they cooperatively operate. epoll uses a red–black tree (RB-tree) data structure to keep track of all file descriptors that are currently being monitored.

API

Creates an epoll object and returns its file descriptor. The flags parameter allows epoll behavior to be modified. It has only one valid value, EPOLL_CLOEXEC. epoll_create() is an older variant of epoll_create1() and is deprecated as of Linux kernel version 2.6.27 and glibc version 2.9.

Controls (configures) which file descriptors are watched by this object, and for which events. op can be ADD, MODIFY or DELETE.

Waits for any of the events registered for with epoll_ctl, until at least one occurs or the timeout elapses. Returns the occurred events in events, up to maxevents at once. maxevents is the maximum number of epoll_event/file descriptors to be monitored. In most case, maxevents is set to the value of the size of *events argument (struct epoll_event* events array).

Triggering modes epoll provides both edge-triggered and level-triggered modes. In edge-triggered mode, a call to epoll_wait will return only when a new event is enqueued with the epoll object, while in level-triggered mode, epoll_wait will return as long as the condition holds. For instance, if a pipe registered with epoll has received data, a call to epoll_wait will return, signaling the presence of data to be read. Suppose, the reader only consumed part of data from the buffer. In level-triggered mode, further calls to epoll_wait will return immediately, as long as the pipe's buffer contains data to be read. In edge-triggered mode, however, epoll_wait will return only once new data is written to the pipe.

Bugs Bryan Cantrill pointed out that epoll had mistakes that could have been avoided, had it learned from its predecessors: input/output completion ports, event ports (Solaris) and kqueue. However, a large part of his criticism was addressed by epoll's EPOLLONESHOT and EPOLLEXCLUSIVE options. EPOLLONESHOT was added in version 2.6.2 of the Linux kernel mainline, released in February 2004. EPOLLEXCLUSIVE was added in version 4.5, released in March 2016.

See also

Input/output completion port (IOCP) kqueue libevent

References

External links epoll manpage epoll patch

Worked examples

Example 1 — a first encounter with Epoll

Start with the simplest possible case. Write down what Epoll claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Epoll before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Epoll ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Epoll

In research
Epoll appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Epoll in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Epoll is common in secondary-school and first-year university syllabi. It links to neighbouring topics Events (computing), Input/output, Linux kernel features, so understanding it makes those chapters shorter.
In everyday life
Look for Epoll outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Epoll” →

How to study Epoll in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Epoll means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Epoll out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Epoll in simple terms?

epoll is a Linux kernel system call for a scalable I/O event notification mechanism, first introduced in version 2.5.45 of the Linux kernel in October, 2002. Its function is to monitor multiple file descriptors to see whether I/O is possible on any of them.

Why does Epoll matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Epoll?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Epoll.

Tags

  • Events (computing)
  • Input/output
  • Linux kernel features
  • System calls

Keep exploring