Merge: NFS: Fixup allocation flags for nfsiod's __GFP_NORETRY

MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7228

JIRA: https://issues.redhat.com/browse/RHEL-99742

commit 99765233ab42bf7a4950377ad7894dce8a5c0e60
Author: Benjamin Coddington <bcodding@redhat.com>
Date:   Wed Jul 9 21:47:43 2025 -0400

    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 <trondmy@kernel.org>
    Fixes: 0bae835b63c5 ("NFS: Avoid writeback threads getting stuck in mempool_alloc()")
    Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
    Reviewed-by: Laurence Oberman <loberman@redhat.com>
    Tested-by: Laurence Oberman <loberman@redhat.com>
    Reviewed-by: Jeff Layton <jlayton@kernel.org>
    Link: https://lore.kernel.org/r/f83ac1155a4bc670f2663959a7a068571e06afd9.1752111622.git.bcodding@redhat.com
    Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>

Approved-by: Olga Kornievskaia <okorniev@redhat.com>
Approved-by: Paulo Alcantara <paalcant@redhat.com>
Approved-by: Jay Shin <jaeshin@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Jarod Wilson <jarod@redhat.com>
This commit is contained in:
Jarod Wilson 2025-08-18 07:24:23 -07:00
commit d7deef2ca7
1 changed files with 6 additions and 3 deletions

View File

@ -618,9 +618,12 @@ nfs_write_match_verf(const struct nfs_writeverf *verf,
static inline gfp_t nfs_io_gfp_mask(void)
{
if (current->flags & PF_WQ_WORKER)
return GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN;
return GFP_KERNEL;
gfp_t ret = current_gfp_context(GFP_KERNEL);
/* For workers __GFP_NORETRY only with __GFP_IO or __GFP_FS */
if ((current->flags & PF_WQ_WORKER) && ret == GFP_KERNEL)
ret |= __GFP_NORETRY | __GFP_NOWARN;
return ret;
}
/*