【问题标题】:Does the thundering herd issue still exist in epoll of new Linux kernel?新Linux内核的epoll是否还存在牛群问题?
【发布时间】:2014-06-16 08:12:43
【问题描述】:

我看到内核源码中fs/eventpoll.c是这样写的:

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
....
}

“独占”是否意味着只有一个等待项(用户空间中的进程或线程)会被唤醒?

但是当我写一些测试代码时,我看到thundering herd problem仍然存在。

为什么不能解决?谢谢!

【问题讨论】:

    标签: c linux concurrency


    【解决方案1】:

    在内核代码中,我们可以在include/linux/wait.h 中看到__add_wait_queue_exclusive() 将条目添加到列表的头部:

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

    在唤醒 sched/wait.c 中的静态 void __wake_up_common() 时,只会唤醒第一个非独占任务和第一个独占任务。 所以通常只有一个任务被唤醒。

    【讨论】:

      【解决方案2】:

      这取决于您是否使用相同的epfd。 WQ_FLAG_EXCLUSIVE 标志仅适用于等待同一个 eventpoll 的 TASK。

      如果您的测试代码在同一个套接字上使用不同的 epfd 监视器,是的,问题存在。

      【讨论】:

        猜你喜欢
        • 2011-01-13
        • 1970-01-01
        • 2013-10-20
        • 1970-01-01
        • 2014-04-26
        • 1970-01-01
        • 1970-01-01
        • 2011-10-17
        • 1970-01-01
        相关资源
        最近更新 更多