From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 403E63E9C07 for ; Fri, 12 Jun 2026 11:50:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781265005; cv=none; b=E3ovNZbxcofFaTjiO6CWOxNSlvKH00I85AeT6F1ofR3ucD0DDFwmpLgG+gQh27cur1DitCvS7x1AI9iuV7XUDaA4Cbe4qZnGTPebz8fT8OZiXHmVNnGau51z/mMeVSFdGALTVPf842roBqYsHEtHJn90aQMCMKHRkB4Fez+Y8yE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781265005; c=relaxed/simple; bh=4YugNqzpU/MUU8LPDCZyOxYQnpDvya+z7cWnHsiF4do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m/xi7c71vfC467fsLq4MskX83nOGzLe/yTk99xdJZLAlVntvZLscuTklFj7mStK2qIaSLMTPlg7J6PPUUEtn+Hg19vd68trBUztEalMcZLMTDaPVUYTqt3pKYrxyC4MPuySVOVh1u/g2Jsde7JJdU0BLW1iLZcIsrF734Yrs58g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GeePiQKb; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GeePiQKb" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2c168baac83so4266345ad.2 for ; Fri, 12 Jun 2026 04:50:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781265003; x=1781869803; 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; bh=iIvjY/yXmZebAH6dkGtl5V3Mcnn9oZGqccC0KLbuVys=; b=GeePiQKbBUDZMrMJV8Sa305TmMLskzmE0dzbVtM0P4oZEU1QCbLjLlVwcU3qXA2LiG ecqIw+VmUP25ezUeOxMeYO1cvdNh8SW0X0+1Ru2J4JJ6lZPDcLndpwb4ckugir+pEkYF FJyuO2we3cV1CaqOp17y4dIC6eF+v4n769MegsM1MsDBeDjNhfvQ+eQ+UKZqZDM8NDLC N0+zPIdjaokhqAoHKuvmnrWSw9cA/ZaE+zbhSPCTxpN7MmSH21cBqSsqrj7qyxv0Il+0 JyaqeXMr5J1+S63/vR1a4KxJOS8GC4yKogH5iqRC8XDDYT4mZDtK/WVs89txFr9NNKWS lhMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781265003; x=1781869803; 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; bh=iIvjY/yXmZebAH6dkGtl5V3Mcnn9oZGqccC0KLbuVys=; b=r9nExr8IuMq6xKaqsiHSBniikW69R5rWvbWL7eHxTmOptxOWfsh9wqHCyutqIipKTf +WtweN+Mu0mSctOyR1GnMac/FCSSe71sc6CyaOCdyzED/6EQiaPTxnO98MXwh/GkKYJa nWfWlnRcha4K0FeG8UWpCAPFf6x2NdMIWZBavI7ckrTdUp/9fOzd5Fp4fiRL/4vYtOKr jKoQXpnp9orn+fw5pLtFDkqOcfR/A2TQMYpLrdFuIXMPU4rbiBIEFijTosD969vMO4RI TAE1AYI2pNbuMhZjplD/ieIQ7vPPDrZiKVV/wFN9v6y5TvN93AT0aV436n9cECkGm5JY fidw== X-Forwarded-Encrypted: i=1; AFNElJ+fp5t/fM67HroZ4clvnL+10rYZ0AkttFqjRz5lE6lvYwP3sk9v7ImTB05OMVGhqRrBNIS0wygfn/wy/GI=@vger.kernel.org X-Gm-Message-State: AOJu0Yxmxw8GaGAQubXQdyiaYM6CvbpbgvcDbbwhNqC7KR2+t6ldNpRU DDkQfuf/9TfqUrBKZY9HF51mCYKEaTMRU2O/XSeW91hJJBjMgJDIiwPR X-Gm-Gg: Acq92OFK8wYpAj688N5XC/hcU7kjHZAZjhIanv/KhVJfhK5YA8jwKo1vBdfyHgbn1c+ eFmUO8LpbszOBFZ1WG5NEMEDZtzcygZMPreKYpfZodr/KknZZ6of8FzmrflvDoMr/Wio9PkTfr5 u89mQpYDaIDOfrHhBplN9wEVQ3QD++XCaMp9e4q5lhI8IvHyV2icGQ+rFhkFb5ktMIyxdYYoBco TGo7wQdN8fYldvc+apBtzcZa4R1b4irTksrAo51+T+ubcJfgOf0RU2tZkLZjyWSRsAiwOIeoNZn uKzqDtsHhr+bd7LMf7t5u+HSTvByPKh+IFi8vkP+ETE+EGcV5it772R0D7YaaLXPQ2jjX5W4Ucz zuq+lqb6vPLB9yxsiG6duDqXx7P6j9wZsHbmVmeFKTxiMcxEJc2wlUV+fUt5VHZjxcEL7uBTQh5 QXcpi5KI7LE4orldh3QbVKoWs4Qbhni4S4N32B+cuNSsZvPxRO53QKLtl8lfEsBxBXHFo+64BGZ EUQ0OmpHmGHWbnNuB45ggOP4WHEsYYX1qHw4xspH4tP26ny1LVmKPxApKsKAkNfo4GAXpVSj2K9 rFo/Zwt6eED6WIJCS0dq5325Gcm0tjF/PPVi X-Received: by 2002:a17:903:19eb:b0:2c1:ee75:56bb with SMTP id d9443c01a7336-2c41188b334mr29525215ad.20.1781265003541; Fri, 12 Jun 2026 04:50:03 -0700 (PDT) Received: from cs-1047136853211-default.asia-southeast1-a.c.d33bddc1d573818c7-tp.internal (139.104.87.34.bc.googleusercontent.com. [34.87.104.139]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c43307a259sm19993085ad.68.2026.06.12.04.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2026 04:50:03 -0700 (PDT) From: Aditya Srivastava To: Carlos Maiolino Cc: Christoph Hellwig , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, Aditya Prakash Srivastava Subject: [PATCH v2 1/2] xfs: add a XFS_TRANS_WRITECOUNT_TRYLOCK flag Date: Fri, 12 Jun 2026 11:49:16 +0000 Message-ID: <20260612114917.2192-2-aditya.ansh182@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260612114917.2192-1-aditya.ansh182@gmail.com> References: <20260612114917.2192-1-aditya.ansh182@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Aditya Prakash Srivastava Introduce a new transaction allocation flag, XFS_TRANS_WRITECOUNT_TRYLOCK. When this flag is specified, __xfs_trans_alloc() attempts to obtain freeze protection using sb_start_intwrite_trylock() instead of blocking indefinitely on sb_start_intwrite(). If the trylock fails, the allocation is aborted gracefully: the freshly allocated transaction handle is freed, and the function returns the appropriate error pointer ERR_PTR(-EAGAIN), which is then propagated to the caller by xfs_trans_alloc(). Also add an assertion in __xfs_trans_alloc() to ensure that both XFS_TRANS_NO_WRITECOUNT and XFS_TRANS_WRITECOUNT_TRYLOCK are never specified at the same time, as they are mutually exclusive. Suggested-by: Christoph Hellwig Signed-off-by: Aditya Prakash Srivastava --- fs/xfs/libxfs/xfs_shared.h | 3 +++ fs/xfs/xfs_trans.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_shared.h b/fs/xfs/libxfs/xfs_shared.h index b1e0d9bc1f7d..68d22b6cddd3 100644 --- a/fs/xfs/libxfs/xfs_shared.h +++ b/fs/xfs/libxfs/xfs_shared.h @@ -164,6 +164,9 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp, /* Transaction has locked the rtbitmap and rtsum inodes */ #define XFS_TRANS_RTBITMAP_LOCKED (1u << 9) +/* Try lock filesystem superblock for freeze protection */ +#define XFS_TRANS_WRITECOUNT_TRYLOCK (1u << 10) + /* * Field values for xfs_trans_mod_sb. */ diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 148cc32449c1..3860e44d6439 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -216,10 +216,18 @@ __xfs_trans_alloc( struct xfs_trans *tp; ASSERT(!(flags & XFS_TRANS_RES_FDBLKS) || xfs_has_lazysbcount(mp)); + ASSERT(!((flags & XFS_TRANS_NO_WRITECOUNT) && + (flags & XFS_TRANS_WRITECOUNT_TRYLOCK))); tp = kmem_cache_zalloc(xfs_trans_cache, GFP_KERNEL | __GFP_NOFAIL); - if (!(flags & XFS_TRANS_NO_WRITECOUNT)) + if (flags & XFS_TRANS_WRITECOUNT_TRYLOCK) { + if (!sb_start_intwrite_trylock(mp->m_super)) { + kmem_cache_free(xfs_trans_cache, tp); + return ERR_PTR(-EAGAIN); + } + } else if (!(flags & XFS_TRANS_NO_WRITECOUNT)) { sb_start_intwrite(mp->m_super); + } xfs_trans_set_context(tp); tp->t_flags = flags; tp->t_mountp = mp; @@ -252,6 +260,8 @@ xfs_trans_alloc( */ retry: tp = __xfs_trans_alloc(mp, flags); + if (IS_ERR(tp)) + return PTR_ERR(tp); WARN_ON(mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE); error = xfs_trans_reserve(tp, resp, blocks, rtextents); if (error == -ENOSPC && want_retry) { -- 2.47.3