Filesystems
為什麼當管道已滿時喚醒作家?
https://elixir.bootlin.com/linux/v5.19/source/fs/pipe.c#L247
當管道已滿時,它不應該喚醒閱讀器讀取數據嗎?
/* * We only wake up writers if the pipe was full when we started * reading in order to avoid unnecessary wakeups. * * But when we do wake up writers, we do so using a sync wakeup * (WF_SYNC), because we want them to get going and generate more * data for us. */ was_full = pipe_full(pipe->head, pipe->tail, pipe->max_usage);
此程式碼在讀取管道時執行;由於正在讀取管道,讀取完成後它不會被填滿,因此會有更多寫入的空間。
如果在讀取開始之前管道已滿,則意味著可能有寫入器因管道已滿而阻塞;那些作家現在醒來以最大程度地減少等待時間很有用。如果管道未滿,那麼任何被阻塞的寫入器都不會因為管道已滿而被阻塞,因此釋放管道中的空間不會幫助他們,喚醒他們也沒有用。
當管道被寫入時,讀取器被喚醒。