Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796055087; b=Fgmq+0G1E/YQ0WMeFiOxMDIAalO0f9OznZVV1kwWVoYnwYAqroKkwLBgfrpztcuMbgeZ qkZsSp/7NHobhZsvGy9/M0uo83yjWy3R48kSoEzwd+fNyi8BXPB6nzBA3/71kjUR0zsMW HLGiwPS8KIOzrrV06VW6ODzlAsmYQCk+4mBEtf676JdcsSzeNtpJUQQqBlEWWvb3olOik eSzuvEax9uUE3eBsiAzNRD9ABn/qMBB9IXHlmx86wJqt0I2yqZwfjd4/3+8AzBz94l6Ev eqH8dCVYTNkqgtk1j3fCTkWD50CnDlspQHveahkfVixlTmvrZMkyobXOmU80HRwVKbw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796055087; 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=IFRECzHJF+BwRQm07NM7ACWjldrDB2SLFc/TfgFP4eM=; b=5rheXq4XvkayBj8jf9LekcFYos4A77T+g4buXyUb1dlVsecZCAdkF05bMqg46pxLSIEU cpXFVLA60iRKO4FO0FQqa1MNX0qt2FgVT5/Ei9U04GHsETE+hlmmTeMmCj1KiM9y+CnUj RLw+PBZd2wKqBHRzOZGS6mS9PKXeu7G2JdO926E1Nd8p7QyURHKWf5YfzuVGJPCjmQUtb hTKL3E2aU/LfBqm6U4bsXMr1ZQcWP1KyEHNYf57hjeXIeaHKpQHpEHZ1yioBCxu/qXJ4X Dz2epnyL8S5fa395rxSooEmzyYy1L3HKd2vZ8bQz1gADvo1wE+uEojwieT2buAysD/w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=lists.scylladb.com; spf=pass smtp.mailfrom=scylladb.com; dkim=pass header.d=lists.scylladb.com header.i=@lists.scylladb.com header.a=rsa-sha256 header.s=google header.b=fsNtlqxf; arc=none smtp.remote-ip=209.85.218.50 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 BB013606A325 for ; Mon, 30 Nov 2026 16:11:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BB013606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lists.scylladb.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=scylladb.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.scylladb.com header.i=@lists.scylladb.com header.a=rsa-sha256 header.s=google header.b=fsNtlqxf Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-c505b2e1cb9so1894520066b.2 for ; Mon, 30 Nov 2026 08:11:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.scylladb.com; s=google; t=1796055085; x=1796659885; 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=IFRECzHJF+BwRQm07NM7ACWjldrDB2SLFc/TfgFP4eM=; b=fsNtlqxfoKjIvvotzPLGBoyhi8bDVeW1Rm7YzjASKmjB2o6zVtlJOhDGqvdFCyIq5y V7rDh7/HPbPOvnemxSohW+RdEAM7cvMiGHZZSQ6STtbq71yeT2CnSh/99Ge8nTYqyNTe 28xvxLtHTpZWpS3wDQeBcF69de39NGdgBo0r1/qyrQPyr4831QjEspJDRlBPrlvbOMuz gHqV9wfieiQwE4Ys6UDnNWDWNztGpIvET+O7IzG4vqRvfKO42y6LyZM+ZJFQkoItm/3F ihS+Zj06najNT8NJFbGKQ2+56Y7QkDG9EMtOVVKU25awEyYwWLOniHDhkDgOtJEo0zr5 LxyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796055085; x=1796659885; 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=IFRECzHJF+BwRQm07NM7ACWjldrDB2SLFc/TfgFP4eM=; b=ilM3+wrXpDfB+34uKsAFMe+pzGQdOABNDVbvPnv4dKe6BN4Brf4NVrGYZJchDvnf4b BEzWU/djC6Hk3qx0NXTIjH5jSHV3VIkel28otrl2AKHBwSv84M5oUtjulg4os1FhDzBl H14J7PJnl+eIBidWh8202VV/isO6H5tUC4cakoRsE1ZCIvwceT9NXrDIFT5MpZANjDBW cneyjaSQsdhLw6WyeCi9jyWlS/KVzrQcxouEkoTVr5M2XdqS76EvCKypvNRsyiTOHNJo 2wLrkNlAr+y5IMySFKB6KCCpYZXoRbjhJmGkHizMCgy3H8QzqLri70m4WIhe7V7H94wn Z27g== X-Forwarded-Encrypted: i=1; AL+hErFNA8IGF+SNqU+0gSVphSDttzf3IziC1RIdTWWFUHuFoV1jEtlD+9NyaXj6VNAKlCclyUraAISIiA==@vger.kernel.org X-Gm-Message-State: APuU4Z/PQb6fxIMnJiYsaFqedLSGYt+IL/lgQeTs2ZVKgQgnEssav0SU gL+a8hR5oCjKpkhp2KPvO8aMHF1G3xp10KztIUeJLjdzpCxhoihvD9qecwijfTaEE0k= X-Gm-Gg: AZFdTZcl9jlJcIXb2wRsB1Llyr1mmQDt2KVf9qbKaZCc+7eHGkU3AiFHTBov5OnAzE2 clg3PSh4LXHLNia2adR7xxo8s+dMBKKgYPyK/GUVfsA/h3wGszNgJsMrp4Ys2oloLR8Zv0LnkfA PYneB9wIR/bsbSiHSDoEES1mVzHqjy5C/D1A8NF4we8As9H2KF9O+deDpEgfzY9clfQiqIcHusS oKdDjJIEcfJSEWsGQbjU2Uv3qHRJdHOHefqNkUzlE8HWynHZyK4CnSFhkvqEXEgBKYb+zgwoh/I 3HYtgtqPiwE9RcNqBiHXvw0siXhpf+bDSDu00QxQC+sgKuQfy3Zq3hafbvgfEhif3s1xFd+ak0Q wcLntu9hQZr6XiHtWdRv7TEVjdHueY1/ASUjJ9wPn2y046RvoaokwmD27XzzLs+xtmJooyPEV6c oTp6bGntLoTZcXC2Iw9u5YuAzpOtUid+BmHLb/R5JALuswJ6pKxQ6e7+iBmr5fwswYg7zLTHix5 M6fnau5DzAJvIsbT3Pazj8HZWn0E8zN93FDSLn8s5/QLvrEJhJpEA7U1IpZWU+R/PofM9dClhWJ vXogaklTyOxeM6Q2BToiPvTAeV5bgjthjYQRazf2Q+hHejI0/jvUYRgu3J/INYFrFS1CJUc8qNs mgk4= X-Received: by 2002:a17:907:9408:b0:c49:8f1e:af0a with SMTP id a640c23a62f3a-c513a52bef3mr2803280566b.7.1796055084973; Mon, 30 Nov 2026 08:11:24 -0800 (PST) Received: from avi.scylladb.com ([2a09:bac6:3ac2:1137::1b7:18]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4abbd84e661sm61188151f8f.18.2026.11.30.08.11.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 08:11:24 -0800 (PST) From: Avi Kivity To: linux-nfs@vger.kernel.org, io-uring@vger.kernel.org Cc: Avi Kivity Subject: [PATCH v1 1/5] nfs: complete direct writes inline when nothing is left to do Date: Mon, 30 Nov 2026 18:09:42 +0200 Message-ID: <20261130161103.1972677-2-avi@lists.scylladb.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261130161103.1972677-1-avi@lists.scylladb.com> References: <20261130161103.1972677-1-avi@lists.scylladb.com> X-Mailing-List: io-uring@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: Avi Kivity nfs_direct_write_complete() unconditionally hands the tail of every direct write to nfsiod, costing a workqueue wakeup per request. The detour is only needed when there is real work left: a COMMIT to send or writes to resend. Both of those need a sleepable context, but the terminal case does not - it only zaps the mapping and runs the completion, neither of which can block. Split the tail out of the workqueue callback as nfs_direct_write_finish() and take the short cut when dreq->flags is zero and the commit lists are empty. Since the RPC completion already runs in process context this finishes the request on the spot. The commit list check keeps us honest: dreq->flags can be left at zero on an error path that still marked requests for commit, and skipping nfs_direct_write_clear_reqs() there would leak them. For aio this removes workqueue involvement from direct writes entirely, as aio_complete_rw() is happy to post the event from any context. Assisted-by: Claude:claude-opus-5 Signed-off-by: Avi Kivity --- fs/nfs/direct.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- fs/nfs/pnfs.h | 14 ++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index a3c6e8f4ea06a..9531bb1a00b8b 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c @@ -735,13 +735,17 @@ static void nfs_direct_write_clear_reqs(struct nfs_direct_req *dreq) nfs_release_request(req); nfs_unlock_and_release_request(req); } } -static void nfs_direct_write_schedule_work(struct work_struct *work) +/* + * Tail of a direct write. Must run in a context that may sleep, since it can + * take the commit mutex and issue further RPC calls. It does not wait for + * those calls to complete. + */ +static void nfs_direct_write_finish(struct nfs_direct_req *dreq) { - struct nfs_direct_req *dreq = container_of(work, struct nfs_direct_req, work); int flags = dreq->flags; dreq->flags = 0; switch (flags) { case NFS_ODIRECT_DO_COMMIT: @@ -755,13 +759,52 @@ static void nfs_direct_write_schedule_work(struct work_struct *work) nfs_zap_mapping(dreq->inode, dreq->inode->i_mapping); nfs_direct_complete(dreq); } } +static void nfs_direct_write_schedule_work(struct work_struct *work) +{ + struct nfs_direct_req *dreq = container_of(work, struct nfs_direct_req, work); + + nfs_direct_write_finish(dreq); +} + +/* + * Is anything still sitting on this request's commit lists? Only called once + * the final reference has been dropped, so the counters cannot change under us + * and no locking is needed. + */ +static bool nfs_direct_has_commit_reqs(struct nfs_direct_req *dreq) +{ + struct nfs_commit_info cinfo; + + if (atomic_long_read(&dreq->mds_cinfo.ncommit) != 0) + return true; + nfs_init_cinfo_from_dreq(&cinfo, dreq); + return pnfs_ds_has_commit_reqs(&cinfo); +} + static void nfs_direct_write_complete(struct nfs_direct_req *dreq) { trace_nfs_direct_write_complete(dreq); + + /* + * dreq->flags is stable here: this is the final reference, so no other + * I/O against this request is outstanding. + * + * A zero value means there is no COMMIT to send and no write to + * resend. If the commit lists are empty as well then nothing is left + * that can block, so finish in the RPC completion context rather than + * paying for a round trip through nfsiod. This is the common case for + * a direct write. + */ + if (dreq->flags == 0 && !nfs_direct_has_commit_reqs(dreq)) { + nfs_zap_mapping(dreq->inode, dreq->inode->i_mapping); + nfs_direct_complete(dreq); + return; + } + queue_work(nfsiod_workqueue, &dreq->work); /* Calls nfs_direct_write_schedule_work */ } static void nfs_direct_write_completion(struct nfs_pgio_header *hdr) { diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h index 2774d4adf4c31..ce98fe5264acd 100644 --- a/fs/nfs/pnfs.h +++ b/fs/nfs/pnfs.h @@ -653,10 +653,18 @@ pnfs_recover_commit_reqs(struct list_head *head, struct nfs_commit_info *cinfo) if (fl_cinfo && fl_cinfo->nwritten != 0) fl_cinfo->ops->recover_commit_reqs(head, cinfo); } +static inline bool +pnfs_ds_has_commit_reqs(struct nfs_commit_info *cinfo) +{ + struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds; + + return fl_cinfo && fl_cinfo->nwritten != 0; +} + /* Should the pNFS client commit and return the layout upon a setattr */ static inline bool pnfs_ld_layoutret_on_setattr(struct inode *inode) { if (!pnfs_enabled_sb(NFS_SERVER(inode))) @@ -953,10 +961,16 @@ pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo, static inline void pnfs_recover_commit_reqs(struct list_head *head, struct nfs_commit_info *cinfo) { } +static inline bool +pnfs_ds_has_commit_reqs(struct nfs_commit_info *cinfo) +{ + return false; +} + static inline int pnfs_layoutcommit_inode(struct inode *inode, bool sync) { return 0; } -- 2.56.1