On Wed, Mar 23, 2022 at 4:11 AM Josef Bacik <josef@xxxxxxxxxxxxxx> wrote: > > On Mon, Dec 27, 2021 at 05:12:41PM +0800, Xie Yongji wrote: > > The rescuer thread might take over the works queued on > > the workqueue when the worker thread creation timed out. > > If this happens, we have no chance to create multiple > > recv threads which causes I/O hung on this nbd device. > > > > To fix it, we can not simply remove the WQ_MEM_RECLAIM > > flag since the recv work is in the memory reclaim path. > > So this patch tries to create kthreads directly to > > handle the recv work instead of using workqueue. > > > > I still don't understand why we can't drop WQ_MEM_RECLAIM. IIRC your argument > is that we need it because a reconnect could happen under memory pressure and we > need to be able to queue work for that. However your code makes it so we're > just doing a kthread_create(), which isn't coming out of some emergency pool, so > it's just as likely to fail as a !WQ_MEM_RECLAIM workqueue. Thanks, > I think the key point is the context in which the work thread is created. It's the context of the nbd process if using kthread_create() to create a workthread (might do some allocation). Then we can benefit from the PR_SET_IO_FLUSHER flag, so memory reclaim would never hit the page cache on the nbd device. But using queue_work() to create a workthread, the actual thread creation happens in the context of the work thread rather than the nbd process, so we can't rely on the PR_SET_IO_FLUSHER flag to avoid deadlock. Thanks, Yongji