On Mon, May 17, 2021 at 11:57:09AM +0800, Wang Jianchao wrote: > Right now, discard is issued and waited to be completed in jbd2 > commit kthread context after the logs are committed. When large > amount of files are deleted and discard is flooding, jbd2 commit > kthread can be blocked for long time. Then all of the metadata > operations can be blocked to wait the log space. > > One case is the page fault path with read mm->mmap_sem held, which > wants to update the file time but has to wait for the log space. > When other threads in the task wants to do mmap, then write mmap_sem > is blocked. Finally all of the following read mmap_sem requirements > are blocked, even the ps command which need to read the /proc/pid/ > -cmdline. Our monitor service which needs to read /proc/pid/cmdline > used to be blocked for 5 mins. > > This patch moves the discard out of jbd2 kthread context and do it > in kworker. And drain the kwork when cannot get space in mb buddy. > This is done out of jbd2 handle and won't block the commit process. > After that, we could use blk-wbt or other method to throttle the > discard and needn't to worry it block the jbd2 commit kthread any > more. Wouldn't be much simpler to do something like this? if (discard_bio) { - submit_bio_wait(discard_bio); - bio_put(discard_bio); + submit_bio(discard_bio); } We're throwing away the return value from submit_bio_wait(), so there's no real need to wait for I/O to complete so we can fetch the I/O status. That way we don't need to move all of this to a kworker context. - Ted