Tianxin Tianxin - 4 months ago 12
Linux Question

The detail function about epoll_insert

The

epoll_insert
function is called by
sys_epoll_ctl
.

There are some key steps in
epoll_insert
function :


  1. Initialize the poll table using the queue callback :
    ep_ptable_queue_proc

  2. And it will call the
    file->f_op->poll

  3. If the file is already "ready" , then we drop it inside the ready list

    /* If the file is already "ready" we drop it inside the ready list */
    if ((revents & event->events) && !ep_is_linked(&epi->rdllink)) {

    list_add_tail(&epi->rdllink, &ep->rdllist);

    /* Notify waiting tasks that events are available */
    if (waitqueue_active(&ep->wq))
    wake_up_locked(&ep->wq);
    if (waitqueue_active(&ep->poll_wait))
    pwake++;
    }



I don't understand why to check whether file is ready in
epoll_insert
function. Should we check it in
ep_poll_callback
function ?

Answer

ep_poll_callback is only called when the status of one of the file descriptors changes. If that were the only place that epoll descriptors were added to the read list, you could potentially miss events that occurred before you managed to add them to epoll. For instance, in a web server, you could miss a client's request if it was sent immediately after connecting.