]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: add helpers to compute log item overhead
authorDarrick J. Wong <djwong@kernel.org>
Wed, 7 May 2025 21:18:25 +0000 (14:18 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 7 May 2025 21:25:30 +0000 (14:25 -0700)
Add selected helpers to estimate the transaction reservation required to
write various log intent and buffer items to the log.  These helpers
will be used by the online repair code for more precise estimations of
how much work can be done in a single transaction.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Signed-off-by: John Garry <john.g.garry@oracle.com>
12 files changed:
fs/xfs/xfs_bmap_item.c
fs/xfs/xfs_bmap_item.h
fs/xfs/xfs_buf_item.c
fs/xfs/xfs_buf_item.h
fs/xfs/xfs_extfree_item.c
fs/xfs/xfs_extfree_item.h
fs/xfs/xfs_log_cil.c
fs/xfs/xfs_log_priv.h
fs/xfs/xfs_refcount_item.c
fs/xfs/xfs_refcount_item.h
fs/xfs/xfs_rmap_item.c
fs/xfs/xfs_rmap_item.h

index 3d52e9d7ad571a75e80df8046388d89786f3c754..646c515ee35518289f645bd28a621439e5eae2a1 100644 (file)
@@ -77,6 +77,11 @@ xfs_bui_item_size(
        *nbytes += xfs_bui_log_format_sizeof(buip->bui_format.bui_nextents);
 }
 
+unsigned int xfs_bui_log_space(unsigned int nr)
+{
+       return xlog_item_space(1, xfs_bui_log_format_sizeof(nr));
+}
+
 /*
  * This is called to fill in the vector of log iovecs for the
  * given bui log item. We use only 1 iovec, and we point that
@@ -168,6 +173,11 @@ xfs_bud_item_size(
        *nbytes += sizeof(struct xfs_bud_log_format);
 }
 
+unsigned int xfs_bud_log_space(void)
+{
+       return xlog_item_space(1, sizeof(struct xfs_bud_log_format));
+}
+
 /*
  * This is called to fill in the vector of log iovecs for the
  * given bud log item. We use only 1 iovec, and we point that
index 6fee6a5083436b83a2dc5d92566b47ff57ca1a93..b42fee06899df6693a4812331cca5363dbbfb38e 100644 (file)
@@ -72,4 +72,7 @@ struct xfs_bmap_intent;
 
 void xfs_bmap_defer_add(struct xfs_trans *tp, struct xfs_bmap_intent *bi);
 
+unsigned int xfs_bui_log_space(unsigned int nr);
+unsigned int xfs_bud_log_space(void);
+
 #endif /* __XFS_BMAP_ITEM_H__ */
index 19eb0b7a3e58d9c43a4ce25f4ebb7f7dbb771061..90139e0f32719214b8ef1bf3117fdbf7545e88d8 100644 (file)
@@ -103,6 +103,25 @@ xfs_buf_item_size_segment(
        return;
 }
 
+/*
+ * Compute the worst case log item overhead for an invalidated buffer with the
+ * given map count and block size.
+ */
+unsigned int
+xfs_buf_inval_log_space(
+       unsigned int    map_count,
+       unsigned int    blocksize)
+{
+       unsigned int    chunks = DIV_ROUND_UP(blocksize, XFS_BLF_CHUNK);
+       unsigned int    bitmap_size = DIV_ROUND_UP(chunks, NBWORD);
+       unsigned int    ret =
+               offsetof(struct xfs_buf_log_format, blf_data_map) +
+                       (bitmap_size * sizeof_field(struct xfs_buf_log_format,
+                                                   blf_data_map[0]));
+
+       return ret * map_count;
+}
+
 /*
  * Return the number of log iovecs and space needed to log the given buf log
  * item.
index 8cde85259a586d5049260f92727d72664bcad7a8..e10e324cd24504e3135acd1383ec769a7ce405de 100644 (file)
@@ -64,6 +64,9 @@ static inline void xfs_buf_dquot_iodone(struct xfs_buf *bp)
 void   xfs_buf_iodone(struct xfs_buf *);
 bool   xfs_buf_log_check_iovec(struct xfs_log_iovec *iovec);
 
+unsigned int xfs_buf_inval_log_space(unsigned int map_count,
+               unsigned int blocksize);
+
 extern struct kmem_cache       *xfs_buf_item_cache;
 
 #endif /* __XFS_BUF_ITEM_H__ */
index 777438b853da0a206c48d307238f9e652a54305a..d574f5f639fa3670b449e7d612090fcca0d07325 100644 (file)
@@ -83,6 +83,11 @@ xfs_efi_item_size(
        *nbytes += xfs_efi_log_format_sizeof(efip->efi_format.efi_nextents);
 }
 
+unsigned int xfs_efi_log_space(unsigned int nr)
+{
+       return xlog_item_space(1, xfs_efi_log_format_sizeof(nr));
+}
+
 /*
  * This is called to fill in the vector of log iovecs for the
  * given efi log item. We use only 1 iovec, and we point that
@@ -254,6 +259,11 @@ xfs_efd_item_size(
        *nbytes += xfs_efd_log_format_sizeof(efdp->efd_format.efd_nextents);
 }
 
+unsigned int xfs_efd_log_space(unsigned int nr)
+{
+       return xlog_item_space(1, xfs_efd_log_format_sizeof(nr));
+}
+
 /*
  * This is called to fill in the vector of log iovecs for the
  * given efd log item. We use only 1 iovec, and we point that
index 41b7c43060799b3a91ec67e85046a9f3a1210880..c8402040410b5489e4df0ff6ff5b736634ebb4af 100644 (file)
@@ -94,4 +94,7 @@ void xfs_extent_free_defer_add(struct xfs_trans *tp,
                struct xfs_extent_free_item *xefi,
                struct xfs_defer_pending **dfpp);
 
+unsigned int xfs_efi_log_space(unsigned int nr);
+unsigned int xfs_efd_log_space(unsigned int nr);
+
 #endif /* __XFS_EXTFREE_ITEM_H__ */
index 1ca406ec1b40b324e31ebaab49c9d38d87aa1adc..f66d2d430e4f375f658ed2a39348359625b0bdee 100644 (file)
@@ -309,9 +309,7 @@ xlog_cil_alloc_shadow_bufs(
                 * Then round nbytes up to 64-bit alignment so that the initial
                 * buffer alignment is easy to calculate and verify.
                 */
-               nbytes += niovecs *
-                       (sizeof(uint64_t) + sizeof(struct xlog_op_header));
-               nbytes = round_up(nbytes, sizeof(uint64_t));
+               nbytes = xlog_item_space(niovecs, nbytes);
 
                /*
                 * The data buffer needs to start 64-bit aligned, so round up
index f3d78869e5e5a3c6c51839fd1244dd0d5b72e2d3..39a102cc1b43e657e3c97665940bf5abba989c68 100644 (file)
@@ -698,4 +698,17 @@ xlog_kvmalloc(
        return p;
 }
 
+/*
+ * Given a count of iovecs and space for a log item, compute the space we need
+ * in the log to store that data plus the log headers.
+ */
+static inline unsigned int
+xlog_item_space(
+       unsigned int    niovecs,
+       unsigned int    nbytes)
+{
+       nbytes += niovecs * (sizeof(uint64_t) + sizeof(struct xlog_op_header));
+       return round_up(nbytes, sizeof(uint64_t));
+}
+
 #endif /* __XFS_LOG_PRIV_H__ */
index fe2d7aab8554fcfa01d39be75174436914ff919d..076501123d89f0e3337fe27744e858619d4a884d 100644 (file)
@@ -78,6 +78,11 @@ xfs_cui_item_size(
        *nbytes += xfs_cui_log_format_sizeof(cuip->cui_format.cui_nextents);
 }
 
+unsigned int xfs_cui_log_space(unsigned int nr)
+{
+       return xlog_item_space(1, xfs_cui_log_format_sizeof(nr));
+}
+
 /*
  * This is called to fill in the vector of log iovecs for the
  * given cui log item. We use only 1 iovec, and we point that
@@ -179,6 +184,11 @@ xfs_cud_item_size(
        *nbytes += sizeof(struct xfs_cud_log_format);
 }
 
+unsigned int xfs_cud_log_space(void)
+{
+       return xlog_item_space(1, sizeof(struct xfs_cud_log_format));
+}
+
 /*
  * This is called to fill in the vector of log iovecs for the
  * given cud log item. We use only 1 iovec, and we point that
index bfee8f30c63ce9ceaec935b969d7f42ed2e3efaf..0fc3f493342bbdfb7bdefa3908e3cedee83fb5e2 100644 (file)
@@ -76,4 +76,7 @@ struct xfs_refcount_intent;
 void xfs_refcount_defer_add(struct xfs_trans *tp,
                struct xfs_refcount_intent *ri);
 
+unsigned int xfs_cui_log_space(unsigned int nr);
+unsigned int xfs_cud_log_space(void);
+
 #endif /* __XFS_REFCOUNT_ITEM_H__ */
index 89decffe76c8b530f9445614c2f771dbb3436153..c99700318ec24bc9764aaf7a81af2d137fda837b 100644 (file)
@@ -77,6 +77,11 @@ xfs_rui_item_size(
        *nbytes += xfs_rui_log_format_sizeof(ruip->rui_format.rui_nextents);
 }
 
+unsigned int xfs_rui_log_space(unsigned int nr)
+{
+       return xlog_item_space(1, xfs_rui_log_format_sizeof(nr));
+}
+
 /*
  * This is called to fill in the vector of log iovecs for the
  * given rui log item. We use only 1 iovec, and we point that
@@ -180,6 +185,11 @@ xfs_rud_item_size(
        *nbytes += sizeof(struct xfs_rud_log_format);
 }
 
+unsigned int xfs_rud_log_space(void)
+{
+       return xlog_item_space(1, sizeof(struct xfs_rud_log_format));
+}
+
 /*
  * This is called to fill in the vector of log iovecs for the
  * given rud log item. We use only 1 iovec, and we point that
index 40d331555675ba348c60fa117db990f02ca249c5..3a99f0117f2d8a6d9efb635e3e7741bdb31315f3 100644 (file)
@@ -75,4 +75,7 @@ struct xfs_rmap_intent;
 
 void xfs_rmap_defer_add(struct xfs_trans *tp, struct xfs_rmap_intent *ri);
 
+unsigned int xfs_rui_log_space(unsigned int nr);
+unsigned int xfs_rud_log_space(void);
+
 #endif /* __XFS_RMAP_ITEM_H__ */