Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796406139; b=vM/fyjOP5+RPDVResUy70ZwtGhs9zXdUKJVyUzGpmLAyHtrKs0S6Nb3ZDuH3glmZmqnX PMNaldiuZu/JFFOWDtpgLZcZgBsZBQmhV4LnVA6mUDMvj9J2rJw6qq0Efa8HRN1be2b+z RUeMTOiArkuLi0RRyBuH5pnJYOpjU2NcrcyMPadj0ylmokPwAFffmNh/oty2X2fZL9f0c YzzA9Xv9y4MiYcTDclJ9Yep/1LxvdxdSf/pvIPHWGyxWHZiGhQDulctrXQr0Hogwet2Pi cZPKdPDW24G+dBFluKwey7OvjUxmuVb1IBlCWhgI4NwHlLl2TSApoH0VuJJvrXHer2Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796406139; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=cIBoCgKGbVSgQCvVXiDLtczKrjxC67f7McWJ4hnCP5k=; b=LnlrAeM+PN1zPiWP+aPBXSBMBBIAWNH4E7BoNgrjuciAON5lAd09QRHuErWgBkqIvhEr rJis6aRT/qh1jaux2NffL+PaWdVcX+YK0842x9BJDUWK9SKLrN/UwM0zFimLjY3reiRqH WF8lJ3ozlYhEn+6mhOI1N+N9vmCCUmRmUTSqrQQ4f/M/wIHisBTsz4UsUQ873zH53ons6 vK6qaG07fn5Hoo9ZIQVrLBO1N9KOLXsXAw7p4RRMr1fUx9F3WmmO6unFG1FcoAN4lIeoo hUlOGyCnxB90IoaIHcR5FKt05tq5lTIM2RLnS+GszF180c0a6nskj5QdV9qx97vnlzg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=hammerspace.com; spf=pass smtp.mailfrom=hammerspace.com; dkim=pass header.d=hammerspace.com header.i=@hammerspace.com header.a=rsa-sha256 header.s=google header.b=XO283ams; arc=none smtp.remote-ip=209.85.161.44 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E9D3606A338 for ; Fri, 4 Dec 2026 17:42:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6E9D3606A338 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hammerspace.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hammerspace.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hammerspace.com header.i=@hammerspace.com header.a=rsa-sha256 header.s=google header.b=XO283ams Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-71ac9e15640so696412eaf.3 for ; Fri, 04 Dec 2026 09:42:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hammerspace.com; s=google; t=1796406138; x=1797010938; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=cIBoCgKGbVSgQCvVXiDLtczKrjxC67f7McWJ4hnCP5k=; b=XO283amsGWEeAWVQyTZVGF3FvV5em5iXjJEIa7YDO+iB0YVLQ+ahUCTG36SxvC/GoT qab201Ci17g7aJQkJUYygeLjBEOqdhxqfQxUm6mPum9FvMlI+EUkcOeMzNyEHiTl2y52 bGNB4Pv7nfg3CI73Tki5bKO5Tc7UuMte3INmHIaNWvB7x8froS7WEBJVO1hU8Re1GUG6 74p+PV2nMK+yA5td2yWMZEPIg3h5MfOXkdIQ4y0LlReYBZyu7avGCkc8ZqleXRpT4DDj QcN06+F4diiUU+pc0dRNS37s8M1u69Hg80fHMuN+DXoLA8acpORJLVLnrT8gWsVtcT4y Q16A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796406138; x=1797010938; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=cIBoCgKGbVSgQCvVXiDLtczKrjxC67f7McWJ4hnCP5k=; b=y4bzPqiPVkSTSXrfWw9JpPQsfKDrMY8UHNbvlLIYlVBu4j3Gz+1FQ1GzUK7dm66dFX 7EcD59CgorlIY4skS63x99La9aeQqHHfWhYYMaMfhmniDfL81RiwQOAnjH1zLVJaxgjt VWq1Ozb7RHGzPFcAvfJy3Wz7J0ZCvtrhYAJGdSmmDfNqU/ULWjSH5WlrTM2UwXGl/c4t y6GVLZrOyp446A+t13X3K9dY+M+lYkBGccO91dBQ9ePDxhdXRPmJlt+1BoE0i6bZokhJ YmcCliFJ8PCrhk/pWRG8gJ9JkunXFms4e7kYrKi5KXFxESZly1M8r7knrL4OZfCsWt4L jGCA== X-Forwarded-Encrypted: i=1; AL+hErENR0Xw4+ZZL8XypybudEmIWR/I/SZlvVWMh9kM4TtAgQQFSmZUwEkcD4k/SfjGAslk7G9eqZH46FQ=@vger.kernel.org X-Gm-Message-State: APuU4Z/Jfj5ux8nQMJdLNrCf7oKnK/FnkJuNw1T3kiqCbny3JrRTUf6F AECDvYM2pQaZf5nx17Dlkr33YBpP4gLzveef9JM+3aVwcnckSl8wAsHDFfVX/fLa5tk= X-Gm-Gg: AZFdTZcxfARpbFZ0v6BwWt5wN6NuQ+iFVSjpTqktcNm9DrT6EKy4aYy6pgeFfhpy6Na 3dJtHAjyrIamdyOW4YS2DJMtnyC1EkOhoDwy7cHJU9erpdIOFieY1iu+ExMd565Oi6ro+Yu27aj FJbpwKVG5kHgrICOG/ZwqQ0onBc3QiRtBzW3bxM2EI7YXfuzGScurrVWDgQiP/2jLY+3JMz8AGV 28tm7jbeG1klGjn9Tuojf0o4SrnZOKsU5cQ6emCP0kPOk3Nu8aMJwrz6pOr9ehjvpqCDbckj18+ TPxnSPPUYrlt9t47Rlz3wi7ALy4pTJ7gQl21IQGgNViDLjZMWbqh48M1b3duvKMQwf8E2NxRxlo mcOeQe78rxlsxJFl0I5Nb+OsrxkX6pH+u3o7DcJBKDMSFWpEl7beFJTtEapLthjdQp1f0/Owve0 1mtH67KNH0Ha+fvkCSX0W3coV8k8tWojq7FlWyHU+kbEJRt8i5cFZloB885N+KLYL1s5U70uvYw 4UHHYfpZ2MBB2vWjvko2GlW5c9EQaqquH7Ltk9+6nf9MvjaLIrQtfEZ3sA6VLVcR0oXYJJ+Q9nL LzSwN4ZBrfPYtUQliC8a2ZBIQvw8GvBCgJ7UlTzjHsGeFzwLXXt8RSMme41ouVRGnCL+2ASt X-Received: by 2002:a05:6820:16a0:b0:71b:c1a8:d822 with SMTP id 006d021491bc7-71bf2074829mr2550656eaf.53.1796406138251; Fri, 04 Dec 2026 09:42:18 -0800 (PST) Received: from bcodding.csb.hammerspace.com ([66.97.168.37]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71bef0cd34asm3035398eaf.3.2026.12.04.09.42.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 09:42:17 -0800 (PST) From: Benjamin Coddington To: Trond Myklebust , Anna Schumaker , Mike Snitzer Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v5 11/12] NFS: wait and resend a folio refused with -EAGAIN in nfs_wb_folio() Date: Fri, 4 Dec 2026 12:42:02 -0500 Message-ID: <09f61b9bf5ec68fbd78c307ead3ad41e94c20548.1796405840.git.bcodding@hammerspace.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Benjamin Coddington A pNFS layout driver can refuse a write with -EAGAIN so that it is resent. Flexfiles does so from ff_layout_pg_init_write() when the layout segment's mirror count no longer matches the descriptor's, and from ff_layout_pg_get_mirror_count_write() when there is no layout segment and the file's layouts carry FF_FLAGS_NO_IO_THRU_MDS. nfs_do_writepage() redirties the folio and returns the -EAGAIN. nfs_writepages() resends it, but nfs_wb_folio() returns it to its callers: nfs_update_folio() through nfs_try_to_update_request(), nfs_flush_incompatible(), nfs_read_folio(), nfs_invalidate_folio() and nfs_launder_folio(). A read(2) or write(2) on a blocking file then fails with EAGAIN, for example when the folio is dirty while a layout is being recalled. Resend the folio from nfs_wb_folio(), and wait a second before every resend after the first. The caller holds the folio lock throughout. That used to be unsafe: writeback kept its layout segment in use while it waited for that folio, so a recall, and with it the layout this resend needs, could wait on the folio. A pageio descriptor no longer keeps its segment in use. A fatal signal ends the wait, and a softerr mount still gets the -EAGAIN, as it does from nfs_writepages(). nfs_migrate_folio() doesn't resend: it ignores the result and returns -EBUSY while the folio still has requests, and resending would hold up compaction. nfs_launder_folio() doesn't resend from an exiting task or a kernel thread, where a file can be released and no signal ends the wait. Fixes: 1d62e659c0bf ("NFSv4/flexfiles: honor FF_FLAGS_NO_IO_THRU_MDS in pg_get_mirror_count_write") Signed-off-by: Benjamin Coddington --- fs/nfs/file.c | 6 +++++- fs/nfs/write.c | 44 ++++++++++++++++++++++++++++++++---------- include/linux/nfs_fs.h | 1 + 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index b377c16c92fe..e90073b955cb 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -571,7 +571,11 @@ static int nfs_launder_folio(struct folio *folio) inode->i_ino, folio_pos(folio)); folio_wait_private_2(folio); /* [DEPRECATED] */ - ret = nfs_wb_folio(inode, folio); + /* No signal ends a wait to resend in an exiting task or a kthread */ + if (nfs_current_task_exiting() || (current->flags & PF_KTHREAD)) + ret = nfs_wb_folio_noresend(inode, folio); + else + ret = nfs_wb_folio(inode, folio); trace_nfs_launder_folio_done(inode, folio_pos(folio), folio_size(folio), ret); return ret; diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 7967487e026c..9e2dd04c7179 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -2073,15 +2073,8 @@ int nfs_wb_folio_reclaim(struct inode *inode, struct folio *folio) return 0; } -/** - * nfs_wb_folio - Write back all requests on one page - * @inode: pointer to page - * @folio: pointer to folio - * - * Assumes that the folio has been locked by the caller, and will - * not unlock it. - */ -int nfs_wb_folio(struct inode *inode, struct folio *folio) +static int __nfs_wb_folio(struct inode *inode, struct folio *folio, + bool resend) { loff_t range_start = folio_pos(folio); size_t len = folio_size(folio); @@ -2091,6 +2084,7 @@ int nfs_wb_folio(struct inode *inode, struct folio *folio) .range_start = range_start, .range_end = range_start + len - 1, }; + bool resent = false; int ret; trace_nfs_writeback_folio(inode, range_start, len); @@ -2099,6 +2093,17 @@ int nfs_wb_folio(struct inode *inode, struct folio *folio) folio_wait_writeback(folio); if (folio_clear_dirty_for_io(folio)) { ret = nfs_writepage_locked(folio, &wbc); + if (ret == -EAGAIN && resend && + !(NFS_SERVER(inode)->flags & NFS_MOUNT_SOFTERR)) { + if (resent) + schedule_timeout_killable(HZ); + if (fatal_signal_pending(current)) { + ret = -ERESTARTSYS; + goto out_error; + } + resent = true; + continue; + } if (ret < 0) goto out_error; continue; @@ -2115,6 +2120,25 @@ int nfs_wb_folio(struct inode *inode, struct folio *folio) return ret; } +/** + * nfs_wb_folio - Write back all requests on one page + * @inode: pointer to page + * @folio: pointer to folio + * + * Assumes that the folio has been locked by the caller, and will + * not unlock it. + */ +int nfs_wb_folio(struct inode *inode, struct folio *folio) +{ + return __nfs_wb_folio(inode, folio, true); +} + +/* As nfs_wb_folio(), but a folio refused with -EAGAIN isn't resent */ +int nfs_wb_folio_noresend(struct inode *inode, struct folio *folio) +{ + return __nfs_wb_folio(inode, folio, false); +} + #ifdef CONFIG_MIGRATION int nfs_migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, enum migrate_mode mode) @@ -2129,7 +2153,7 @@ int nfs_migrate_folio(struct address_space *mapping, struct folio *dst, */ if (folio_test_private(src)) { if (mode == MIGRATE_SYNC) - nfs_wb_folio(src->mapping->host, src); + __nfs_wb_folio(src->mapping->host, src, false); if (folio_test_private(src)) return -EBUSY; } diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index 29f59796ed57..da8931814516 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -627,6 +627,7 @@ extern int nfs_update_folio(struct file *file, struct folio *folio, extern int nfs_sync_inode(struct inode *inode); extern int nfs_wb_all(struct inode *inode); extern int nfs_wb_folio(struct inode *inode, struct folio *folio); +int nfs_wb_folio_noresend(struct inode *inode, struct folio *folio); extern int nfs_wb_folio_reclaim(struct inode *inode, struct folio *folio); int nfs_wb_folio_cancel(struct inode *inode, struct folio *folio); extern int nfs_commit_inode(struct inode *, int); -- 2.53.0