Skip to content

Commit 9976523

Browse files
bcodding-rhTrond Myklebust
authored andcommitted
NFS: Fixup allocation flags for nfsiod's __GFP_NORETRY
If the NFS client is doing writeback from a workqueue context, avoid using __GFP_NORETRY for allocations if the task has set PF_MEMALLOC_NOIO or PF_MEMALLOC_NOFS. The combination of these flags makes memory allocation failures much more likely. We've seen those allocation failures show up when the loopback driver is doing writeback from a workqueue to a file on NFS, where memory allocation failure results in errors or corruption within the loopback device's filesystem. Suggested-by: Trond Myklebust <[email protected]> Fixes: 0bae835 ("NFS: Avoid writeback threads getting stuck in mempool_alloc()") Signed-off-by: Benjamin Coddington <[email protected]> Reviewed-by: Laurence Oberman <[email protected]> Tested-by: Laurence Oberman <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Link: https://lore.kernel.org/r/f83ac1155a4bc670f2663959a7a068571e06afd9.1752111622.git.bcodding@redhat.com Signed-off-by: Trond Myklebust <[email protected]>
1 parent 9acb237 commit 9976523

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

fs/nfs/internal.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,12 @@ nfs_write_match_verf(const struct nfs_writeverf *verf,
670670

671671
static inline gfp_t nfs_io_gfp_mask(void)
672672
{
673-
if (current->flags & PF_WQ_WORKER)
674-
return GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN;
675-
return GFP_KERNEL;
673+
gfp_t ret = current_gfp_context(GFP_KERNEL);
674+
675+
/* For workers __GFP_NORETRY only with __GFP_IO or __GFP_FS */
676+
if ((current->flags & PF_WQ_WORKER) && ret == GFP_KERNEL)
677+
ret |= __GFP_NORETRY | __GFP_NOWARN;
678+
return ret;
676679
}
677680

678681
/*

0 commit comments

Comments
 (0)