Skip to content

Commit 6d1bdc7

Browse files
author
Darrick J. Wong
committed
xfs: add helpers to compute log item overhead
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 <[email protected]> Reviewed-by: John Garry <[email protected]> Signed-off-by: John Garry <[email protected]>
1 parent 13c7c54 commit 6d1bdc7

12 files changed

+88
-3
lines changed

fs/xfs/xfs_bmap_item.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ xfs_bui_item_size(
7777
*nbytes += xfs_bui_log_format_sizeof(buip->bui_format.bui_nextents);
7878
}
7979

80+
unsigned int xfs_bui_log_space(unsigned int nr)
81+
{
82+
return xlog_item_space(1, xfs_bui_log_format_sizeof(nr));
83+
}
84+
8085
/*
8186
* This is called to fill in the vector of log iovecs for the
8287
* given bui log item. We use only 1 iovec, and we point that
@@ -168,6 +173,11 @@ xfs_bud_item_size(
168173
*nbytes += sizeof(struct xfs_bud_log_format);
169174
}
170175

176+
unsigned int xfs_bud_log_space(void)
177+
{
178+
return xlog_item_space(1, sizeof(struct xfs_bud_log_format));
179+
}
180+
171181
/*
172182
* This is called to fill in the vector of log iovecs for the
173183
* given bud log item. We use only 1 iovec, and we point that

fs/xfs/xfs_bmap_item.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,7 @@ struct xfs_bmap_intent;
7272

7373
void xfs_bmap_defer_add(struct xfs_trans *tp, struct xfs_bmap_intent *bi);
7474

75+
unsigned int xfs_bui_log_space(unsigned int nr);
76+
unsigned int xfs_bud_log_space(void);
77+
7578
#endif /* __XFS_BMAP_ITEM_H__ */

fs/xfs/xfs_buf_item.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ xfs_buf_item_size_segment(
103103
return;
104104
}
105105

106+
/*
107+
* Compute the worst case log item overhead for an invalidated buffer with the
108+
* given map count and block size.
109+
*/
110+
unsigned int
111+
xfs_buf_inval_log_space(
112+
unsigned int map_count,
113+
unsigned int blocksize)
114+
{
115+
unsigned int chunks = DIV_ROUND_UP(blocksize, XFS_BLF_CHUNK);
116+
unsigned int bitmap_size = DIV_ROUND_UP(chunks, NBWORD);
117+
unsigned int ret =
118+
offsetof(struct xfs_buf_log_format, blf_data_map) +
119+
(bitmap_size * sizeof_field(struct xfs_buf_log_format,
120+
blf_data_map[0]));
121+
122+
return ret * map_count;
123+
}
124+
106125
/*
107126
* Return the number of log iovecs and space needed to log the given buf log
108127
* item.

fs/xfs/xfs_buf_item.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ static inline void xfs_buf_dquot_iodone(struct xfs_buf *bp)
6464
void xfs_buf_iodone(struct xfs_buf *);
6565
bool xfs_buf_log_check_iovec(struct xfs_log_iovec *iovec);
6666

67+
unsigned int xfs_buf_inval_log_space(unsigned int map_count,
68+
unsigned int blocksize);
69+
6770
extern struct kmem_cache *xfs_buf_item_cache;
6871

6972
#endif /* __XFS_BUF_ITEM_H__ */

fs/xfs/xfs_extfree_item.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ xfs_efi_item_size(
8383
*nbytes += xfs_efi_log_format_sizeof(efip->efi_format.efi_nextents);
8484
}
8585

86+
unsigned int xfs_efi_log_space(unsigned int nr)
87+
{
88+
return xlog_item_space(1, xfs_efi_log_format_sizeof(nr));
89+
}
90+
8691
/*
8792
* This is called to fill in the vector of log iovecs for the
8893
* given efi log item. We use only 1 iovec, and we point that
@@ -254,6 +259,11 @@ xfs_efd_item_size(
254259
*nbytes += xfs_efd_log_format_sizeof(efdp->efd_format.efd_nextents);
255260
}
256261

262+
unsigned int xfs_efd_log_space(unsigned int nr)
263+
{
264+
return xlog_item_space(1, xfs_efd_log_format_sizeof(nr));
265+
}
266+
257267
/*
258268
* This is called to fill in the vector of log iovecs for the
259269
* given efd log item. We use only 1 iovec, and we point that

fs/xfs/xfs_extfree_item.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,7 @@ void xfs_extent_free_defer_add(struct xfs_trans *tp,
9494
struct xfs_extent_free_item *xefi,
9595
struct xfs_defer_pending **dfpp);
9696

97+
unsigned int xfs_efi_log_space(unsigned int nr);
98+
unsigned int xfs_efd_log_space(unsigned int nr);
99+
97100
#endif /* __XFS_EXTFREE_ITEM_H__ */

fs/xfs/xfs_log_cil.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,7 @@ xlog_cil_alloc_shadow_bufs(
309309
* Then round nbytes up to 64-bit alignment so that the initial
310310
* buffer alignment is easy to calculate and verify.
311311
*/
312-
nbytes += niovecs *
313-
(sizeof(uint64_t) + sizeof(struct xlog_op_header));
314-
nbytes = round_up(nbytes, sizeof(uint64_t));
312+
nbytes = xlog_item_space(niovecs, nbytes);
315313

316314
/*
317315
* The data buffer needs to start 64-bit aligned, so round up

fs/xfs/xfs_log_priv.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,4 +698,17 @@ xlog_kvmalloc(
698698
return p;
699699
}
700700

701+
/*
702+
* Given a count of iovecs and space for a log item, compute the space we need
703+
* in the log to store that data plus the log headers.
704+
*/
705+
static inline unsigned int
706+
xlog_item_space(
707+
unsigned int niovecs,
708+
unsigned int nbytes)
709+
{
710+
nbytes += niovecs * (sizeof(uint64_t) + sizeof(struct xlog_op_header));
711+
return round_up(nbytes, sizeof(uint64_t));
712+
}
713+
701714
#endif /* __XFS_LOG_PRIV_H__ */

fs/xfs/xfs_refcount_item.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ xfs_cui_item_size(
7878
*nbytes += xfs_cui_log_format_sizeof(cuip->cui_format.cui_nextents);
7979
}
8080

81+
unsigned int xfs_cui_log_space(unsigned int nr)
82+
{
83+
return xlog_item_space(1, xfs_cui_log_format_sizeof(nr));
84+
}
85+
8186
/*
8287
* This is called to fill in the vector of log iovecs for the
8388
* given cui log item. We use only 1 iovec, and we point that
@@ -179,6 +184,11 @@ xfs_cud_item_size(
179184
*nbytes += sizeof(struct xfs_cud_log_format);
180185
}
181186

187+
unsigned int xfs_cud_log_space(void)
188+
{
189+
return xlog_item_space(1, sizeof(struct xfs_cud_log_format));
190+
}
191+
182192
/*
183193
* This is called to fill in the vector of log iovecs for the
184194
* given cud log item. We use only 1 iovec, and we point that

fs/xfs/xfs_refcount_item.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,7 @@ struct xfs_refcount_intent;
7676
void xfs_refcount_defer_add(struct xfs_trans *tp,
7777
struct xfs_refcount_intent *ri);
7878

79+
unsigned int xfs_cui_log_space(unsigned int nr);
80+
unsigned int xfs_cud_log_space(void);
81+
7982
#endif /* __XFS_REFCOUNT_ITEM_H__ */

0 commit comments

Comments
 (0)