Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the thundering herd issue still exist in epoll of new Linux kernel?

I saw that fs/eventpoll.c in the kernel source code is written like this:

static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
           int maxevents, long timeout)
{
....
        init_waitqueue_entry(&wait, current);
        __add_wait_queue_exclusive(&ep->wq, &wait);    // *** NB
....
}

Does that "exclusive" mean that only one wait item (process or thread in userspace) will be waked up?

But when I wrote some test code, I saw that the thundering herd problem still exists.

And WHY can't it be solved? Thanks!

like image 710
user3744016 Avatar asked Oct 19 '25 07:10

user3744016


2 Answers

In the kernel code we can see in include/linux/wait.h that __add_wait_queue_exclusive() adds the entry to the head of the list:

 __add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
{
        wait->flags |= WQ_FLAG_EXCLUSIVE;
        __add_wait_queue(q, wait);
}

When it comes to waking up static void __wake_up_common() in sched/wait.c does wake only the first tasks that are not exclusive and the first exclusive one. So normally only one tasks gets woken up.

like image 68
krase Avatar answered Oct 21 '25 19:10

krase


It depends on whether you are using the same epfd. The flag WQ_FLAG_EXCLUSIVE is works only for the TASKs waiting on the same eventpoll.

If your testing code use different epfd monitor on the same socket, YES, the issue exists.

like image 23
chenju Avatar answered Oct 21 '25 20:10

chenju