Re: [RFC PATCH] usb: host: xhci: allow __GFP_FS in dma allocation

Christoph Hellwig
2019-05-20T14:23:56Z

On Mon, May 20, 2019 at 10:16:57AM -0400, Alan Stern wrote:
> What if the allocation requires the kernel to swap some old pages out
> to the backing store, but the backing store is on the device that the
> driver is managing? The swap can't take place until the current I/O
> operation is complete (assuming the driver can handle only one I/O
> operation at a time), and the current operation can't complete until
> the old pages are swapped out. Result: deadlock.
>
> Isn't that the whole reason for using GFP_NOIO in the first place?

It is, or rather was. As it has been incredibly painful to wire
up the gfp_t argument through some callstacks, most notably the
vmalloc allocator which is used by a lot of the DMA allocators on
non-coherent platforms, we now have the memalloc_noio_save and
memalloc_nofs_save functions that mark a thread as not beeing to
go into I/O / FS reclaim. So even if you use GFP_KERNEL you will
not dip into reclaim with those flags set on the thread.