On Wed, Dec 18, 2019 at 11:56 PM David Howells <dhowells@xxxxxxxxxx> wrote: > > I looked at splitting the waitqueue in to two, but it makes poll tricky. No, it's actually trivial for poll. The thing is, poll can happily just add two wait-queues to the poll_table. In my conversion, I just did - poll_wait(filp, &pipe->wait, wait); + if (filp->f_mode & FMODE_READ) + poll_wait(filp, &pipe->rd_wait, wait); + if (filp->f_mode & FMODE_WRITE) + poll_wait(filp, &pipe->wr_wait, wait); which changes the unconditional "add one" to two conditional adds. They _could_ have been unconditional too, but why add unnecessary wakeups? So it only really does it twice on named pipes (if opened for reading and writing). It's _unusual_ to add two wait-queues for a single poll, but it's not wrong. The tty layer has always done it - exactly because it has separate wait queues for reading and writing. Some other drivers do too. Sometimes there's a separate wait queue for errors, sometimes there are multiple wait-queues because there are events from the "subsystem" and there are other events from the "device". I think sound does the latter, for example. And no, I don't particularly like the FMODE_READ/WRITE testing above - it would be better to pass in the polling mask and ask "are we waiting for polling for reading or writing?" instead of asking whether the file descriptor was opened for read or write, but hey, it is what it is. Sadly, "poll()" doesn't really get passed the bitmask of what is being waited on (it's there in the poll_tabvle "_key" field, but I don't want to have the pipe code look into those kinds of details. So the named pipe case could be improved, but it's not like anybody really cares. Nobody uses named pipes any more (and few people ever did). So I didn't worry about it. Linus