From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 D7CA63C4141 for ; Tue, 16 Jun 2026 03:38:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781581128; cv=none; b=EmsSAYHG2otjduVbIUMexWDQmyZTmssXLPA3bkwsyrFnS/oKbpyiUJdyZrOW3XDiaYrrZzpeiNMZgNRWFAe9U4LX/HioKurtwGVQZpTg4Gf0ifVKgTWN2gr7teYtKc0Ck8otJ2uTTcVpLRE0uFTZAl61FgWDlRIJ1abhnZ7hzX4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781581128; c=relaxed/simple; bh=4YugNqzpU/MUU8LPDCZyOxYQnpDvya+z7cWnHsiF4do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e2AH0BBgBh5RfbLEYplZ6+bZrEdz2TefQ7N5mR8VK2D7fFcnDFEC8a7KnkTwcAs6s7qHeimgr9vkCJFoNopmkBHOZdUqjfyAs04in1/ZqKlFqye9UT38+CbCkueF46r3dqbQ0+/ulX4wS3BOSIpRAUnvj9J9QO6Yt0Y4En7rK6Q= 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=B6nX7kAw; arc=none smtp.client-ip=209.85.215.173 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="B6nX7kAw" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-c8585cd8400so1261666a12.3 for ; Mon, 15 Jun 2026 20:38:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781581126; x=1782185926; 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=B6nX7kAwps9xUaZM5wXjMYlU+74/npn7BSHkUWhiC01V0ZXNkgC6cIXyryoDAVN7Tp dQP2PmB7rI7pgRk1oHBSSIcDbgBAx+sufddGlKJiVs5CYnN2ZHOxvG121lL+vDodZNIk Yb5xJGw+PcODgwHQGujw2tUTwZCxLgV11N4XiwcaGtNxiILnjTp0Ww57z2l8JdjIf5eE T1WeKzpaKAtKn4GsUB1KWoDmvn69LZne2jQ8Qjm5CW3SrXrgmZAlJGDqpcxKgN2EYqmK eNaEdze/XUR3kBYbj4suiQwMJfp8qeS1MVR9bWdM34Had8GtS4/c2EgidpBaRm5GposD yU5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781581126; x=1782185926; 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=Cp6KgcAHpLbu/b+nUFSKseNXkTFOyNxPBm7FY7DfmEIZRhfk4A+JDh+QdkvVuMMUiO ST+R4vchFFmHDrVKxhs9l9oWKgC6XC8nO9rWQ46DccYEIc60OVl5aHR5p/UJJ0b4A+AI Rylj93JnM9TK1NdzdsPlpPdyBbdRaB9S8tgVMKUuusPoGkiRWuBzgWYEFLLnehDaUgh+ GEGpsDhqEA3DALhSw/v/cyUayeUGqUR+ualvFXDqJfjiqesho5WBw+1J3mspX/ru0Gkw oF7gJIF2BUbmVqo3UJy9ZqU1Dunwx/HGoEWcPVClgiiY+HF0l1W1tW3HECXwQX+pCEbl 4MdA== X-Forwarded-Encrypted: i=1; AFNElJ+NYtMENxrY+s56A8H2b6RY0KZUOwp1NI9npmhTOtM/fNiPx8jAeTyhks9OiPD9hnsTC54kpomw+j8h5co=@vger.kernel.org X-Gm-Message-State: AOJu0YzVb23usyUD/JL+pub0PCyKVXnb3nuoA4C7o5qbFuvwQyP0LZus V6LD/Q66PI2VG5i4jRH7HB+ylWVs9k21W1V2BnTzoNohodBN2fRG9ey+ X-Gm-Gg: Acq92OHGHZOd2nrZt44slkY3DtQCjBMuUSBvei9Df/gfi79P9e4xuhzWJlahWRQhsdX cPbSARyrR03URpayyu/GULQwnZfUyjIjmSgLM/PUAQR1+5p2XwKa6WaEX3hxOu6xFxWXLg8rl9W qowXj3Y/EfZ2HR59uOeUZ/q8qrPlLaa3FMouudt/852uqA/2mmtP/p5AqgX4HS8ohwrFQVX/Lij reJhZC7JF7K/OUrY+zazswuSX7GZ5Xpqq0AooiaQBoHM1EjJ8lRBVwod/22XrH9jqe4u5uTSk2r 1LUeqwurh7n+N3RWUJnAl5x5SbA8z8aMTNO9c+pttZewpIeZA6euhMDUDCu+w12fbKDscuNbRVn VjoEAU7Xk5wlhwu4/XqhsvghqDWb5s7ESaTpgXp1ri7f/4on6FXMyZiExjksD5XLH67M8Szq5H/ sSDpgRqv8SAD9JZRqUhj7wTqMaLp5xXpjR2HSoW7Fexw2bAiEay0auSv41XzzjtWNSpR54AvXEc BIqmSwwmbkWaS/7QTep9r/6Fj5pc9R6+HiSUFLL7+SXFD7dGWDwcxhNlZij/85T9v7s3iSMpXTW 14keIQAZj3tCAlCJjHF5feCEkNJbeHSZJ/2Fy1Znm8Di8Dc= X-Received: by 2002:a05:6300:408d:b0:3b4:b26e:bab2 with SMTP id adf61e73a8af0-3b7e4951a26mr2018884637.2.1781581126219; Mon, 15 Jun 2026 20:38:46 -0700 (PDT) Received: from cs-1047136853211-default.asia-southeast1-b.c.d33bddc1d573818c7-tp.internal (229.231.21.34.bc.googleusercontent.com. [34.21.231.229]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c866325d156sm10304173a12.13.2026.06.15.20.38.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2026 20:38:45 -0700 (PDT) From: Aditya Srivastava To: Carlos Maiolino , Christoph Hellwig Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, Aditya Prakash Srivastava Subject: [PATCH v4 1/2] xfs: add a XFS_TRANS_WRITECOUNT_TRYLOCK flag Date: Tue, 16 Jun 2026 03:38:19 +0000 Message-ID: <20260616033821.2238-2-aditya.ansh182@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260616033821.2238-1-aditya.ansh182@gmail.com> References: <20260616033821.2238-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