]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: allow sysadmins to specify a maximum atomic write limit at mount time
authorDarrick J. Wong <djwong@kernel.org>
Tue, 1 Jul 2025 17:45:13 +0000 (10:45 -0700)
committerAndrey Albershteyn <aalbersh@kernel.org>
Fri, 18 Jul 2025 14:05:10 +0000 (16:05 +0200)
Source kernel commit: 4528b9052731f14c1a9be16b98e33c9401e6d1bc

Introduce a mount option to allow sysadmins to specify the maximum size
of an atomic write.  If the filesystem can work with the supplied value,
that becomes the new guaranteed maximum.

The value mustn't be too big for the existing filesystem geometry (max
write size, max AG/rtgroup size).  We dynamically recompute the
tr_atomic_write transaction reservation based on the given block size,
check that the current log size isn't less than the new minimum log size
constraints, and set a new maximum.

The actual software atomic write max is still computed based off of
tr_atomic_ioend the same way it has for the past few commits.  Note also
that xfs_calc_atomic_write_log_geometry is non-static because mkfs will
need that.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
include/platform_defs.h
include/xfs_trace.h
libxfs/xfs_trans_resv.c
libxfs/xfs_trans_resv.h

index 9af7b4318f8917f363fd3409e5257daca2e46a2a..74a00583ebd6cb4996d486ed17d79396f5380e52 100644 (file)
@@ -261,6 +261,20 @@ static inline bool __must_check __must_check_overflow(bool overflow)
        __builtin_add_overflow(__a, __b, __d);  \
 }))
 
+/**
+ * check_mul_overflow() - Calculate multiplication with overflow checking
+ * @a: first factor
+ * @b: second factor
+ * @d: pointer to store product
+ *
+ * Returns true on wrap-around, false otherwise.
+ *
+ * *@d holds the results of the attempted multiplication, regardless of whether
+ * wrap-around occurred.
+ */
+#define check_mul_overflow(a, b, d)    \
+       __must_check_overflow(__builtin_mul_overflow(a, b, d))
+
 /**
  * abs_diff - return absolute value of the difference between the arguments
  * @a: the first argument
index 965c109cc1941ab5516481f09e725c6fe9c191b0..6bbf4007cbbbd9fd3f05a4612968718db207bb71 100644 (file)
@@ -65,6 +65,7 @@
 #define trace_xfs_attr_rmtval_remove_return(...) ((void) 0)
 
 #define trace_xfs_calc_max_atomic_write_fsblocks(...) ((void) 0)
+#define trace_xfs_calc_max_atomic_write_log_geometry(...) ((void) 0)
 
 #define trace_xfs_log_recover_item_add_cont(a,b,c,d)   ((void) 0)
 #define trace_xfs_log_recover_item_add(a,b,c,d)        ((void) 0)
index ec61ddfba44601797d6d3fbbb3e1f392843c5f6b..b3b9d22b54515d6ffe94f99a4ae5009cad18fc96 100644 (file)
@@ -1481,3 +1481,72 @@ xfs_calc_max_atomic_write_fsblocks(
 
        return ret;
 }
+
+/*
+ * Compute the log blocks and transaction reservation needed to complete an
+ * atomic write of a given number of blocks.  Worst case, each block requires
+ * separate handling.  A return value of 0 means something went wrong.
+ */
+xfs_extlen_t
+xfs_calc_atomic_write_log_geometry(
+       struct xfs_mount        *mp,
+       xfs_extlen_t            blockcount,
+       unsigned int            *new_logres)
+{
+       struct xfs_trans_res    *curr_res = &M_RES(mp)->tr_atomic_ioend;
+       uint                    old_logres = curr_res->tr_logres;
+       unsigned int            per_intent, step_size;
+       unsigned int            logres;
+       xfs_extlen_t            min_logblocks;
+
+       ASSERT(blockcount > 0);
+
+       xfs_calc_default_atomic_ioend_reservation(mp, M_RES(mp));
+
+       per_intent = xfs_calc_atomic_write_ioend_geometry(mp, &step_size);
+
+       /* Check for overflows */
+       if (check_mul_overflow(blockcount, per_intent, &logres) ||
+           check_add_overflow(logres, step_size, &logres))
+               return 0;
+
+       curr_res->tr_logres = logres;
+       min_logblocks = xfs_log_calc_minimum_size(mp);
+       curr_res->tr_logres = old_logres;
+
+       trace_xfs_calc_max_atomic_write_log_geometry(mp, per_intent, step_size,
+                       blockcount, min_logblocks, logres);
+
+       *new_logres = logres;
+       return min_logblocks;
+}
+
+/*
+ * Compute the transaction reservation needed to complete an out of place
+ * atomic write of a given number of blocks.
+ */
+int
+xfs_calc_atomic_write_reservation(
+       struct xfs_mount        *mp,
+       xfs_extlen_t            blockcount)
+{
+       unsigned int            new_logres;
+       xfs_extlen_t            min_logblocks;
+
+       /*
+        * If the caller doesn't ask for a specific atomic write size, then
+        * use the defaults.
+        */
+       if (blockcount == 0) {
+               xfs_calc_default_atomic_ioend_reservation(mp, M_RES(mp));
+               return 0;
+       }
+
+       min_logblocks = xfs_calc_atomic_write_log_geometry(mp, blockcount,
+                       &new_logres);
+       if (!min_logblocks || min_logblocks > mp->m_sb.sb_logblocks)
+               return -EINVAL;
+
+       M_RES(mp)->tr_atomic_ioend.tr_logres = new_logres;
+       return 0;
+}
index a6d303b836883feead0db7536006d327eb9218e8..336279e0fc61371ea469e8b66b0143af3362d18c 100644 (file)
@@ -122,5 +122,9 @@ unsigned int xfs_calc_write_reservation_minlogsize(struct xfs_mount *mp);
 unsigned int xfs_calc_qm_dqalloc_reservation_minlogsize(struct xfs_mount *mp);
 
 xfs_extlen_t xfs_calc_max_atomic_write_fsblocks(struct xfs_mount *mp);
+xfs_extlen_t xfs_calc_atomic_write_log_geometry(struct xfs_mount *mp,
+               xfs_extlen_t blockcount, unsigned int *new_logres);
+int xfs_calc_atomic_write_reservation(struct xfs_mount *mp,
+               xfs_extlen_t blockcount);
 
 #endif /* __XFS_TRANS_RESV_H__ */