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!
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With