On Mon, Aug 30, 2021 at 03:52:45PM +0800, Wang Jianchao wrote: > From: Wang Jianchao <wangjianchao@xxxxxxxxxxxx> > > 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 frees the blocks back to buddy after commit and then do > discard in a async kworker context in fstrim fashion, namely, > - mark blocks to be discarded as used if they have not been allocated > - do discard > - mark them free > After this, jbd2 commit kthread won't be blocked any more by discard > and we won't get NOSPC even if the discard is slow or throttled. > > Link: https://marc.info/?l=linux-kernel&m=162143690731901&w=2 > Suggested-by: Theodore Ts'o <tytso@xxxxxxx> > Reviewed-by: Jan Kara <jack@xxxxxxx> > Signed-off-by: Wang Jianchao <wangjianchao@xxxxxxxxxxxx> I had applied the V3 version of this patch series for testing purposes, and then accidentally included in the dev branch. So an earlier version of this patch series has been in the ext4 git tree for a while. I've done a comparison between the V3 and V4 patches, and aside from a minor whitespace change in patch #1, the only patch that had any real changes was this one (#4). Patch #5 was also added in the V4 series. So I've edited the ext4 git tree using rebase magic, replacing patch #4 and adding patch #5. In other words, this is a slightly more complicated, "Thanks, applied". :-) - Ted