handle ophdr formatting entirely in xlog_write
Hi all,
for historic reasons, generating of the log ophdrs is split over the log item formatting and the core log write in somewhat awkward ways. This less to subtle extra code, extra (small) memory usage for keeping the headers in memory when they are not needed. This series refactors the log vec formatting a bit and the xlog_write code a lot so that the ophdrs are formatted when writing to the iclog, and the no memory for the ophdrs is allocated for logvecs in the CIL.
Diffstat:
xfs_log.c | 298 ++++++++++++++++++++++++++------------------------------- xfs_log_cil.c | 258 ++++++++++++++++--------------------------------- xfs_log_priv.h | 19 +++ 3 files changed, 238 insertions(+), 337 deletions(-)
PATCH 1/15 xfs: don't bother setting oh_tid in callers of xlog_write
xlog_write always stamps oh_tid into the ophdr written to the log, so don't bother setting in the callers as those values will always be overwritten.
--- fs/xfs/xfs_log.c | 1 - fs/xfs/xfs_log_cil.c | 4 ---- 2 files changed, 5 deletions(-)
fs/xfs/xfs_log.c +0 -1
@@ -841,7 +841,6 @@ xlog_write_unmount_record( } unmount_rec = { .ophdr = { .oh_clientid = XFS_LOG, - .oh_tid = cpu_to_be32(ticket->t_tid), .oh_flags = XLOG_UNMOUNT_TRANS, }, .ulf = {
fs/xfs/xfs_log_cil.c +0 -4
@@ -1189,7 +1189,6 @@ xlog_cil_write_commit_record(struct xlog *log = ctx->cil->xc_log;struct xlog_op_header ophdr = { .oh_clientid =XFS_TRANSACTION , - .oh_tid =cpu_to_be32 (ctx->ticket->t_tid), .oh_flags =XLOG_COMMIT_TRANS , };struct xfs_log_iovec reg = {
@@ -1237,12 +1236,10 @@ xlog_cil_build_trans_hdr( int num_iovecs) {struct xlog_ticket *tic = ctx->ticket; -__be32 tid =cpu_to_be32 (tic->t_tid);memset (hdr,0 ,sizeof (*hdr));/* Log start record */ - hdr->oph[0 ].oh_tid = tid; hdr->oph[0 ].oh_clientid =XFS_TRANSACTION ; hdr->oph[0 ].oh_flags =XLOG_START_TRANS ;
@@ -1252,7 +1249,6 @@ xlog_cil_build_trans_hdr( hdr->lhdr[0 ].i_type =XLOG_REG_TYPE_LRHEADER ;/* log opheader */ - hdr->oph[1 ].oh_tid = tid; hdr->oph[1 ].oh_clientid =XFS_TRANSACTION ; hdr->oph[1 ].oh_len =cpu_to_be32 (sizeof (struct xfs_trans_header ));
Signature · 1 line
2.53.0
Re: [PATCH 01/15] xfs: don't bother setting oh_tid in callers of xlog_write
Quoted 5 lines · Christoph Hellwig
xlog_writealways stampsoh_tidinto the ophdr written to the log, so don't bother setting in the callers as those values will always be overwritten.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 53 lines
--- fs/xfs/xfs_log.c | 1 - fs/xfs/xfs_log_cil.c | 4 ---- 2 files changed, 5 deletions(-)fs/xfs/xfs_log.c +0
-1@@ -841,7 +841,6 @@ xlog_write_unmount_record( } unmount_rec = { .ophdr = { .oh_clientid = XFS_LOG, - .oh_tid = cpu_to_be32(ticket->t_tid), .oh_flags = XLOG_UNMOUNT_TRANS, }, .ulf = {fs/xfs/xfs_log_cil.c +0
-4@@ -1189,7 +1189,6 @@ xlog_cil_write_commit_record(struct xlog *log = ctx->cil->xc_log;struct xlog_op_header ophdr = { .oh_clientid =XFS_TRANSACTION , - .oh_tid =cpu_to_be32 (ctx->ticket->t_tid), .oh_flags =XLOG_COMMIT_TRANS , };struct xfs_log_iovec reg = {@@ -1237,12 +1236,10 @@ xlog_cil_build_trans_hdr( int num_iovecs) {struct xlog_ticket *tic = ctx->ticket; -__be32 tid =cpu_to_be32 (tic->t_tid);memset (hdr,0 ,sizeof (*hdr));/* Log start record */ - hdr->oph[0 ].oh_tid = tid; hdr->oph[0 ].oh_clientid =XFS_TRANSACTION ; hdr->oph[0 ].oh_flags =XLOG_START_TRANS ;@@ -1252,7 +1249,6 @@ xlog_cil_build_trans_hdr( hdr->lhdr[0 ].i_type =XLOG_REG_TYPE_LRHEADER ;/* log opheader */ - hdr->oph[1 ].oh_tid = tid; hdr->oph[1 ].oh_clientid =XFS_TRANSACTION ; hdr->oph[1 ].oh_len =cpu_to_be32 (sizeof (struct xfs_trans_header ));Signature · 1 line
2.53.0
PATCH 2/15 xfs: always set oh_len in xlog_write
In reply to Christoph Hellwigxlog_write_partial already updates oh_len to match the split regions. Also set oh_len based on the log iovec in xlog_write_full so that the callers don't have to also set the length.
--- fs/xfs/xfs_log.c | 2 ++ fs/xfs/xfs_log_cil.c | 9 --------- 2 files changed, 2 insertions(+), 9 deletions(-)
fs/xfs/xfs_log.c +2 -0
@@ -2025,6 +2025,8 @@ xlog_write_full(struct xlog_op_header *ophdr = reg->i_addr; ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); + ophdr->oh_len = +cpu_to_be32 (reg->i_len -sizeof (struct xlog_op_header ));xlog_write_iovec (data, reg->i_addr, reg->i_len); } }
fs/xfs/xfs_log_cil.c +0 -9
@@ -470,7 +470,6 @@ xlog_format_commit( {struct xfs_log_vec *lv = lfb->lv;struct xfs_log_iovec *vec = &lv->lv_iovecp[lfb->idx]; -struct xlog_op_header *oph = vec->i_addr;int len;/*
@@ -486,13 +485,6 @@ xlog_format_commit(memset (buf + data_len,0 , len - data_len); } - -/* -* The opheader tracks aligned payload length, whilst the logvec tracks -* the overall region length. -*/ - oph->oh_len =cpu_to_be32 (len); - len +=sizeof (struct xlog_op_header ); lv->lv_buf_used += len; lv->lv_bytes += len;
@@ -1250,7 +1242,6 @@ xlog_cil_build_trans_hdr(/* log opheader */ hdr->oph[1 ].oh_clientid =XFS_TRANSACTION ; - hdr->oph[1 ].oh_len =cpu_to_be32 (sizeof (struct xfs_trans_header ));/* transaction header in host byte order format */ hdr->thdr.th_magic =XFS_TRANS_HEADER_MAGIC ;
Signature · 1 line
2.53.0
Re: [PATCH 02/15] xfs: always set oh_len in xlog_write
Quoted 5 lines · Christoph Hellwig
xlog_write_partialalready updatesoh_lento match the split regions. Also setoh_lenbased on the log iovec inxlog_write_fullso that the callers don't have to also set the length.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 55 lines
--- fs/xfs/xfs_log.c | 2 ++ fs/xfs/xfs_log_cil.c | 9 --------- 2 files changed, 2 insertions(+), 9 deletions(-)fs/xfs/xfs_log.c +2
-0@@ -2025,6 +2025,8 @@ xlog_write_full(struct xlog_op_header *ophdr = reg->i_addr; ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); + ophdr->oh_len = +cpu_to_be32 (reg->i_len -sizeof (struct xlog_op_header ));xlog_write_iovec (data, reg->i_addr, reg->i_len); } }fs/xfs/xfs_log_cil.c +0
-9@@ -470,7 +470,6 @@ xlog_format_commit( {struct xfs_log_vec *lv = lfb->lv;struct xfs_log_iovec *vec = &lv->lv_iovecp[lfb->idx]; -struct xlog_op_header *oph = vec->i_addr;int len;/* @@ -486,13 +485,6 @@ xlog_format_commit(memset (buf + data_len,0 , len - data_len); } - -/* -* The opheader tracks aligned payload length, whilst the logvec tracks -* the overall region length. -*/ - oph->oh_len =cpu_to_be32 (len); - len +=sizeof (struct xlog_op_header ); lv->lv_buf_used += len; lv->lv_bytes += len;@@ -1250,7 +1242,6 @@ xlog_cil_build_trans_hdr(/* log opheader */ hdr->oph[1 ].oh_clientid =XFS_TRANSACTION ; - hdr->oph[1 ].oh_len =cpu_to_be32 (sizeof (struct xfs_trans_header ));/* transaction header in host byte order format */ hdr->thdr.th_magic =XFS_TRANS_HEADER_MAGIC ;Signature · 1 line
2.53.0
PATCH 3/15 xfs: refactor the continuation loop in xlog_write_partial
In reply to Christoph HellwigLooping on a flag that is the effect of the size calculations is a bit unintuitive. Switch to a for loop that loops over the length of the region instead, which has the same result but clearly documents what we are looping for.
--- fs/xfs/xfs_log.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
fs/xfs/xfs_log.c +12 -15
@@ -2074,7 +2074,7 @@ xlog_write_partial(/* walk the logvec, copying until we run out of space in the iclog */ for (index =0 ; index < lv->lv_niovecs; index++) {struct xfs_log_iovec *reg = &lv->lv_iovecp[index]; -uint32_t reg_offset =0 ; +uint32_t offset;/* * The first region of a continuation must have a non-zero
@@ -2104,16 +2104,14 @@ xlog_write_partial(xlog_write_iovec (data, reg->i_addr, rlen); -/* If we wrote the whole region, move to the next. */ -if (rlen == reg->i_len) -continue ; -/* -* We now have a partially written iovec, but it can span -* multiple iclogs so we loop here. First we release the iclog -* we currently have, then we get a new iclog and add a new -* opheader. Then we continue copying from where we were until -* we either complete the iovec or fill the iclog. If we +* If we wrote the whole region, move to the next region. +* +* Otherwise we now have a partially written iovec, but it can +* span multiple iclogs so we loop here. First we release the +* iclog we currently have, then we get a new iclog and add a +* new opheader. Then we continue copying from where we were +* until we either complete the iovec or fill the iclog. If we * complete the iovec, then we increment the index and go right * back to the top of the outer loop. if we fill the iclog, we * run the inner loop again.
@@ -2128,7 +2126,7 @@ xlog_write_partial(* space left in the current iclog, and check for the end of the * continuation after getting a new iclog. */ - do { +for (offset = rlen; offset < reg->i_len; offset += rlen) {/* * Ensure we include the continuation opheader in the * space we need in the new iclog by adding that size
@@ -2156,8 +2154,7 @@ xlog_write_partial(* If rlen fits in the iclog, then end the region * continuation. Otherwise we're going around again. */ - reg_offset += rlen; - rlen = reg->i_len - reg_offset; + rlen = reg->i_len - offset;if (rlen <=xlog_write_space_left (data)) ophdr->oh_flags |=XLOG_END_TRANS ;else
@@ -2167,8 +2164,8 @@ xlog_write_partial( xlog_write_space_left(data)); ophdr->oh_len =cpu_to_be32 (rlen); -xlog_write_iovec (data, reg->i_addr + reg_offset, rlen); - }while (ophdr->oh_flags &XLOG_CONTINUE_TRANS ); +xlog_write_iovec (data, reg->i_addr + offset, rlen); + } }return 0 ;
Signature · 1 line
2.53.0
Re: [PATCH 03/15] xfs: refactor the continuation loop in xlog_write_partial
Quoted 7 lines · Christoph Hellwig
Looping on a flag that is the effect of the size calculations is a bit unintuitive. Switch to a for loop that loops over the length of the region instead, which has the same result but clearly documents what we are looping for.
Signed-off-by Christoph Hellwig <[email protected]>---
Quoted 66 lines
fs/xfs/xfs_log.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)fs/xfs/xfs_log.c +10
-10@@ -2074,7 +2074,7 @@ xlog_write_partial(/* walk the logvec, copying until we run out of space in the iclog */ for (index =0 ; index < lv->lv_niovecs; index++) {struct xfs_log_iovec *reg = &lv->lv_iovecp[index]; -uint32_t reg_offset =0 ; +uint32_t offset;/* * The first region of a continuation must have a non-zero @@ -2104,16 +2104,14 @@ xlog_write_partial(xlog_write_iovec (data, reg->i_addr, rlen); -/* If we wrote the whole region, move to the next. */ -if (rlen == reg->i_len) -continue ; -/* +* Otherwise we now have a partially written iovec, but it can +* span multiple iclogs so we loop here. First we release the +* iclog we currently have, then we get a new iclog and add a +* new opheader. Then we continue copying from where we were +* until we either complete the iovec or fill the iclog. If we * complete the iovec, then we increment the index and go right * back to the top of the outer loop. if we fill the iclog, we * run the inner loop again. @@ -2128,7 +2126,7 @@ xlog_write_partial(* space left in the current iclog, and check for the end of the * continuation after getting a new iclog. */ - do { +for (offset = rlen; offset < reg->i_len; offset += rlen) {/* * Ensure we include the continuation opheader in the * space we need in the new iclog by adding that size @@ -2156,8 +2154,7 @@ xlog_write_partial(* If rlen fits in the iclog, then end the region * continuation. Otherwise we're going around again. */ - reg_offset += rlen; - rlen = reg->i_len - reg_offset; + rlen = reg->i_len - offset;if (rlen <=xlog_write_space_left (data)) ophdr->oh_flags |=XLOG_END_TRANS ;else @@ -2167,8 +2164,8 @@ xlog_write_partial( xlog_write_space_left(data)); ophdr->oh_len =cpu_to_be32 (rlen); -xlog_write_iovec (data, reg->i_addr + reg_offset, rlen); - }while (ophdr->oh_flags &XLOG_CONTINUE_TRANS ); +xlog_write_iovec (data, reg->i_addr + offset, rlen); + } }return 0 ;Signature · 1 line
2.53.0
PATCH 4/15 xfs: factor out a xlog_write_ophdr helper
In reply to Christoph HellwigAdd a helper to format common bits of the opheader into a helper function to prepare for moving the opheader construction to common code.
--- fs/xfs/xfs_log.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
fs/xfs/xfs_log.c +16 -10
@@ -1992,6 +1992,20 @@ xlog_write_space_advance(return p; } +static void +xlog_write_ophdr ( +struct xlog_write_data *data, +struct xfs_log_iovec *reg, +unsigned int rlen) +{ +struct xlog_op_header *ophdr = reg->i_addr; + + ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); + ophdr->oh_len =cpu_to_be32 (rlen -sizeof (struct xlog_op_header )); +if (rlen != reg->i_len) + ophdr->oh_flags |=XLOG_CONTINUE_TRANS ; +} + static inline void xlog_write_iovec( struct xlog_write_data *data,
@@ -2022,11 +2036,8 @@ xlog_write_full(*/ for (index =0 ; index < lv->lv_niovecs; index++) {struct xfs_log_iovec *reg = &lv->lv_iovecp[index]; -struct xlog_op_header *ophdr = reg->i_addr; - ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); - ophdr->oh_len = -cpu_to_be32 (reg->i_len -sizeof (struct xlog_op_header )); +xlog_write_ophdr (data, reg, reg->i_len);xlog_write_iovec (data, reg->i_addr, reg->i_len); } }
@@ -2094,14 +2105,9 @@ xlog_write_partial(return error; } - ophdr = reg->i_addr; rlen =min_t (uint32_t, reg->i_len,xlog_write_space_left (data)); - ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); - ophdr->oh_len =cpu_to_be32 (rlen -sizeof (struct xlog_op_header )); -if (rlen != reg->i_len) - ophdr->oh_flags |=XLOG_CONTINUE_TRANS ; - +xlog_write_ophdr (data, reg, rlen);xlog_write_iovec (data, reg->i_addr, rlen);/*
Signature · 1 line
2.53.0
Re: [PATCH 04/15] xfs: factor out a xlog_write_ophdr helper
Quoted 6 lines · Christoph Hellwig
Add a helper to format common bits of the opheader into a helper function to prepare for moving the opheader construction to common code.
Signed-off-by Christoph Hellwig <[email protected]>---
Quoted 60 lines
fs/xfs/xfs_log.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)fs/xfs/xfs_log.c +16
-10@@ -1992,6 +1992,20 @@ xlog_write_space_advance(return p; } +static void +xlog_write_ophdr ( +struct xlog_write_data *data, +struct xfs_log_iovec *reg, +unsigned int rlen) +{ +struct xlog_op_header *ophdr = reg->i_addr; + + ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); + ophdr->oh_len =cpu_to_be32 (rlen -sizeof (struct xlog_op_header )); +if (rlen != reg->i_len) + ophdr->oh_flags |=XLOG_CONTINUE_TRANS ; +} + static inline void xlog_write_iovec( struct xlog_write_data *data,@@ -2022,11 +2036,8 @@ xlog_write_full(*/ for (index =0 ; index < lv->lv_niovecs; index++) {struct xfs_log_iovec *reg = &lv->lv_iovecp[index]; -struct xlog_op_header *ophdr = reg->i_addr; - ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); - ophdr->oh_len = -cpu_to_be32 (reg->i_len -sizeof (struct xlog_op_header )); +xlog_write_ophdr (data, reg, reg->i_len);xlog_write_iovec (data, reg->i_addr, reg->i_len); } }@@ -2094,14 +2105,9 @@ xlog_write_partial(return error; } - ophdr = reg->i_addr; rlen =min_t (uint32_t, reg->i_len,xlog_write_space_left (data)); - ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); - ophdr->oh_len =cpu_to_be32 (rlen -sizeof (struct xlog_op_header )); -if (rlen != reg->i_len) - ophdr->oh_flags |=XLOG_CONTINUE_TRANS ; - +xlog_write_ophdr (data, reg, rlen);xlog_write_iovec (data, reg->i_addr, rlen);/* Signature · 1 line
2.53.0
PATCH 5/15 xfs: factor out a xlog_write_cont_ophdr helper
In reply to Christoph HellwigFactor out the continuation opheader formatting code into a helper so that the formatting logic is separate from the processing loop in xlog_write_partial. This prepares for generating the opheaders on the fly, but also helps the code structure as-is.
--- fs/xfs/xfs_log.c | 54 +++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 26 deletions(-)
fs/xfs/xfs_log.c +28 -26
@@ -2006,6 +2006,33 @@ xlog_write_ophdr( ophdr->oh_flags |=XLOG_CONTINUE_TRANS ; } +static uint32_t +xlog_write_cont_ophdr ( +struct xlog_write_data *data, +uint32_t rlen) +{ +struct xlog_op_header *ophdr; + + ophdr =xlog_write_space_advance (data,sizeof (struct xlog_op_header )); + ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); + ophdr->oh_clientid =XFS_TRANSACTION ; + ophdr->oh_flags =XLOG_WAS_CONT_TRANS ; + ophdr->oh_res2 =0 ; + +/* +* If rlen fits in the iclog, then end the region continuation. +* Otherwise we're going around again. +*/ +if (rlen <=xlog_write_space_left (data)) { + ophdr->oh_flags |=XLOG_END_TRANS ; + }else { + ophdr->oh_flags |=XLOG_CONTINUE_TRANS ; + rlen =xlog_write_space_left (data); + } + ophdr->oh_len =cpu_to_be32 (rlen); +return rlen; +} + static inline void xlog_write_iovec( struct xlog_write_data *data,
@@ -2077,7 +2104,6 @@ xlog_write_partial(struct xfs_log_vec *lv, struct xlog_write_data *data) { - struct xlog_op_header *ophdr; int index = 0;uint32_t rlen;int error;
@@ -2145,31 +2171,7 @@ xlog_write_partial( error =xlog_write_get_more_iclog_space (data);if (error)return error; - - ophdr =xlog_write_space_advance (data, -sizeof (struct xlog_op_header )); - ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); - ophdr->oh_clientid =XFS_TRANSACTION ; - ophdr->oh_res2 =0 ; - ophdr->oh_flags =XLOG_WAS_CONT_TRANS ; - - data->ticket->t_curr_res -= -sizeof (struct xlog_op_header ); - -/* -* If rlen fits in the iclog, then end the region -* continuation. Otherwise we're going around again. -*/ - rlen = reg->i_len - offset; -if (rlen <=xlog_write_space_left (data)) - ophdr->oh_flags |=XLOG_END_TRANS ; -else - ophdr->oh_flags |=XLOG_CONTINUE_TRANS ; - - rlen =min_t (uint32_t, rlen, -xlog_write_space_left (data)); - ophdr->oh_len =cpu_to_be32 (rlen); - + rlen =xlog_write_cont_ophdr (data, reg->i_len - offset);xlog_write_iovec (data, reg->i_addr + offset, rlen); } }
Signature · 1 line
2.53.0
Carlos Maiolino
maintainerRe: [PATCH 05/15] xfs: factor out a xlog_write_cont_ophdr helper
Quoted 21 lines · Christoph Hellwig
Factor out the continuation opheader formatting code into a helper so that the formatting logic is separate from the processing loop in
xlog_write_partial. This prepares for generating the opheaders on the fly, but also helps the code structure as-is.Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/xfs_log.c | 54 +++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 26 deletions(-)fs/xfs/xfs_log.c +3
-0@@ -2006,6 +2006,33 @@ xlog_write_ophdr( ophdr->oh_flags |=XLOG_CONTINUE_TRANS ; } +static uint32_t +xlog_write_cont_ophdr( + struct xlog_write_data *data,
fs/xfs/xfs_log.c xlog_write_ophdr( · line 2021
Quoted 10 lines
fs/xfs/xfs_log.c +10
-0+ uint32_t rlen) +{ +struct xlog_op_header *ophdr; + + ophdr =xlog_write_space_advance (data,sizeof (struct xlog_op_header )); + ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); + ophdr->oh_clientid =XFS_TRANSACTION ; + ophdr->oh_flags =XLOG_WAS_CONT_TRANS ; + ophdr->oh_res2 =0 ; +
Shouldn't the new helper also update the ticket reservation?
Quoted 61 lines
fs/xfs/xfs_log.c +15
-26+/* +* If rlen fits in the iclog, then end the region continuation. +* Otherwise we're going around again. +*/ +if (rlen <=xlog_write_space_left (data)) { + ophdr->oh_flags |=XLOG_END_TRANS ; + }else { + ophdr->oh_flags |=XLOG_CONTINUE_TRANS ; + rlen =xlog_write_space_left (data); + } + ophdr->oh_len =cpu_to_be32 (rlen); +return rlen; +} + static inline void xlog_write_iovec( struct xlog_write_data *data,@@ -2077,7 +2104,6 @@ xlog_write_partial(struct xfs_log_vec *lv, struct xlog_write_data *data) { - struct xlog_op_header *ophdr; int index = 0;uint32_t rlen;int error;@@ -2145,31 +2171,7 @@ xlog_write_partial( error =xlog_write_get_more_iclog_space (data);if (error)return error; - - ophdr =xlog_write_space_advance (data, -sizeof (struct xlog_op_header )); - ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); - ophdr->oh_clientid =XFS_TRANSACTION ; - ophdr->oh_res2 =0 ; - ophdr->oh_flags =XLOG_WAS_CONT_TRANS ; - - data->ticket->t_curr_res -= -sizeof (struct xlog_op_header ); - -/* -* If rlen fits in the iclog, then end the region -* continuation. Otherwise we're going around again. -*/ - rlen = reg->i_len - offset; -if (rlen <=xlog_write_space_left (data)) - ophdr->oh_flags |=XLOG_END_TRANS ; -else - ophdr->oh_flags |=XLOG_CONTINUE_TRANS ; - - rlen =min_t (uint32_t, rlen, -xlog_write_space_left (data)); - ophdr->oh_len =cpu_to_be32 (rlen); - + rlen =xlog_write_cont_ophdr (data, reg->i_len - offset);xlog_write_iovec (data, reg->i_addr + offset, rlen); } }Signature · 1 line
2.53.0
PATCH 6/15 xfs: factor out a xlog_write_region helper
In reply to Christoph HellwigSplit out the body of the main loop of xlog_write_partial into a separate function to keep the code compact.
--- fs/xfs/xfs_log.c | 143 ++++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 69 deletions(-)
fs/xfs/xfs_log.c +74 -69
@@ -2094,86 +2094,91 @@ xlog_write_get_more_iclog_space( }/* -* Write log vectors into a single iclog which is smaller than the current chain -* length. We write until we cannot fit a full record into the remaining space -* and then stop. We return the log vector that is to be written that cannot -* wholly fit in the iclog. +* Write a single log vector into one or more iclogs. If the initial iclog is +* smaller than the current chain length, get a new iclog and write a +* continuation record. */ static int -xlog_write_partial ( -struct xfs_log_vec *lv, -struct xlog_write_data *data) +xlog_write_region ( +struct xlog_write_data *data, +struct xfs_log_iovec *reg) { -int index =0 ; -uint32_t rlen; +uint32_t rlen, offset;int error; -/* walk the logvec, copying until we run out of space in the iclog */ -for (index =0 ; index < lv->lv_niovecs; index++) { -struct xfs_log_iovec *reg = &lv->lv_iovecp[index]; -uint32_t offset; +/* +* The first region of a continuation must have a non-zero length, +* otherwise log recovery will just skip over it and start recovering +* from the next opheader it finds. Because we mark the next opheader +* as a continuation, recovery will then incorrectly add the +* continuation to the previous region and that breaks stuff. +* +* Hence if there isn't space for region data after the opheader, then +* we need to start afresh with a new iclog. +*/ +if (xlog_write_space_left (data) <=sizeof (struct xlog_op_header )) { + error =xlog_write_get_more_iclog_space (data); +if (error) +return error; + } + + rlen =min_t (uint32_t, reg->i_len,xlog_write_space_left (data)); + +xlog_write_ophdr (data, reg, rlen); +xlog_write_iovec (data, reg->i_addr, rlen); +/* +* If we wrote the whole region, move to the next region. +* +* Otherwise we now have a partially written iovec, but it can span +* multiple iclogs so we loop here. First we release the iclog we +* currently have, then we get a new iclog and add a new opheader. Then +* we continue copying from where we were until we either complete the +* iovec or fill the iclog. If we complete the iovec, then we increment +* the index and go right back to the top of the outer loop. If we fill +* the iclog, we run the inner loop again. +* +* This is complicated by the tail of a region using all the space in an +* iclog and hence requiring us to release the iclog and get a new one +* before returning to the outer loop. We must always guarantee that we +* exit this inner loop with at least space for log transaction +* opheaders left in the current iclog, hence we cannot just terminate +* the loop at the end of the of the continuation. So we loop while +* there is no space left in the current iclog, and check for the end of +* the continuation after getting a new iclog. +*/ +for (offset = rlen; offset < reg->i_len; offset += rlen) {/* -* The first region of a continuation must have a non-zero -* length otherwise log recovery will just skip over it and -* start recovering from the next opheader it finds. Because we -* mark the next opheader as a continuation, recovery will then -* incorrectly add the continuation to the previous region and -* that breaks stuff. -* -* Hence if there isn't space for region data after the -* opheader, then we need to start afresh with a new iclog. +* Ensure we include the continuation opheader in the space we +* need in the new iclog by adding that size to the length we +* require. This continuation opheader needs to be accounted to +* the ticket as the space it consumes hasn't been accounted to +* the lv we are writing. */ -if (xlog_write_space_left (data) <= -sizeof (struct xlog_op_header )) { - error =xlog_write_get_more_iclog_space (data); -if (error) -return error; - } + data->bytes_left +=sizeof (struct xlog_op_header ); + error =xlog_write_get_more_iclog_space (data); +if (error) +return error; + rlen =xlog_write_cont_ophdr (data, reg->i_len - offset); +xlog_write_iovec (data, reg->i_addr + offset, rlen); + } - rlen =min_t (uint32_t, reg->i_len,xlog_write_space_left (data)); +return 0 ; +} -xlog_write_ophdr (data, reg, rlen); -xlog_write_iovec (data, reg->i_addr, rlen); +static int +xlog_write_partial ( +struct xfs_log_vec *lv, +struct xlog_write_data *data) +{ +int index; -/* -* If we wrote the whole region, move to the next region. -* -* Otherwise we now have a partially written iovec, but it can -* span multiple iclogs so we loop here. First we release the -* iclog we currently have, then we get a new iclog and add a -* new opheader. Then we continue copying from where we were -* until we either complete the iovec or fill the iclog. If we -* complete the iovec, then we increment the index and go right -* back to the top of the outer loop. if we fill the iclog, we -* run the inner loop again. -* -* This is complicated by the tail of a region using all the -* space in an iclog and hence requiring us to release the iclog -* and get a new one before returning to the outer loop. We must -* always guarantee that we exit this inner loop with at least -* space for log transaction opheaders left in the current -* iclog, hence we cannot just terminate the loop at the end -* of the of the continuation. So we loop while there is no -* space left in the current iclog, and check for the end of the -* continuation after getting a new iclog. -*/ -for (offset = rlen; offset < reg->i_len; offset += rlen) { -/* -* Ensure we include the continuation opheader in the -* space we need in the new iclog by adding that size -* to the length we require. This continuation opheader -* needs to be accounted to the ticket as the space it -* consumes hasn't been accounted to the lv we are -* writing. -*/ - data->bytes_left +=sizeof (struct xlog_op_header ); - error =xlog_write_get_more_iclog_space (data); -if (error) -return error; - rlen =xlog_write_cont_ophdr (data, reg->i_len - offset); -xlog_write_iovec (data, reg->i_addr + offset, rlen); - } +for (index =0 ; index < lv->lv_niovecs; index++) { +int error; + + error =xlog_write_region (data, &lv->lv_iovecp[index]); +if (error) +return error; }return 0 ;
Signature · 1 line
2.53.0
PATCH 7/15 xfs: remove xlog_write_{partial,full}
In reply to Christoph HellwigNow that the partial iclog writing has been cleaned up to be easy to read, stop having a separate full iclog write path that just saves a tiny number of branches while adding a separate code path, and merge the trivial loop left in xlog_write_partial into xlog_write.
--- fs/xfs/xfs_log.c | 64 ++++-------------------------------------------- 1 file changed, 5 insertions(+), 59 deletions(-)
fs/xfs/xfs_log.c +5 -59
@@ -2043,32 +2043,6 @@ xlog_write_iovec( data->record_cnt++; } -/* -* Write log vectors into a single iclog which is guaranteed by the caller -* to have enough space to write the entire log vector into. -*/ -static void -xlog_write_full ( -struct xfs_log_vec *lv, -struct xlog_write_data *data) -{ -int index; - -ASSERT (data->bytes_left <=xlog_write_space_left (data) || - data->iclog->ic_state ==XLOG_STATE_WANT_SYNC ); - -/* -* Ordered log vectors have no regions to write so this -* loop will naturally skip them. -*/ -for (index =0 ; index < lv->lv_niovecs; index++) { -struct xfs_log_iovec *reg = &lv->lv_iovecp[index]; - -xlog_write_ophdr (data, reg, reg->i_len); -xlog_write_iovec (data, reg->i_addr, reg->i_len); - } -} -static int xlog_write_get_more_iclog_space (struct xlog_write_data *data)
@@ -2166,24 +2140,6 @@ xlog_write_region(return 0 ; } -static int -xlog_write_partial ( -struct xfs_log_vec *lv, -struct xlog_write_data *data) -{ -int index; - -for (index =0 ; index < lv->lv_niovecs; index++) { -int error; - - error =xlog_write_region (data, &lv->lv_iovecp[index]); -if (error) -return error; - } - -return 0 ; -} -/* * Write some region out to in-core log *
@@ -2262,22 +2218,12 @@ xlog_write(xlog_cil_set_ctx_write_state (ctx, data.iclog);list_for_each_entry (lv, lv_chain, lv_list) { -/* -* If the entire log vec does not fit in the iclog, punt it to -* the partial copy loop which can handle this case. -*/ -if (lv->lv_niovecs && - lv->lv_bytes >xlog_write_space_left (&data)) { - error =xlog_write_partial (lv, &data); -if (error) { -/* -* We have no iclog to release, so just return -* the error immediately. -*/ +int i; + +for (i =0 ; i < lv->lv_niovecs; i++) { + error =xlog_write_region (&data, &lv->lv_iovecp[i]); +if (error)return error; - } - }else { -xlog_write_full (lv, &data); } }ASSERT (data.bytes_left ==0 );
Signature · 1 line
2.53.0
PATCH 8/15 xfs: build the entire ophdr in xlog_write_ophdr
In reply to Christoph Hellwigxlog_write_ophdr already builds most of the ophr, but still passes through the oh_clientid value set by the caller, and seeds oh_flags with the caller provided value. Derive the oh_clientid and initial oh_flags values from the i_flags value provided by the caller, and thus build the ophr entirely inside of xlog_write_ophdr. This matches what xlog_write_cont_ophdr does for the continuation header.
--- fs/xfs/xfs_log.c | 27 +++++++++++++++++++++++---- fs/xfs/xfs_log_cil.c | 16 ---------------- 2 files changed, 23 insertions(+), 20 deletions(-)
fs/xfs/xfs_log.c +23 -4
@@ -839,10 +839,6 @@ xlog_write_unmount_record(struct xlog_op_header ophdr;struct xfs_unmount_log_format ulf; } unmount_rec = { - .ophdr = { - .oh_clientid = XFS_LOG, - .oh_flags = XLOG_UNMOUNT_TRANS, - }, .ulf = { .magic = XLOG_UNMOUNT_TYPE, },
@@ -1992,6 +1988,22 @@ xlog_write_space_advance(return p; } +static uint8_t +xlog_ophdr_flag ( +struct xfs_log_iovec *reg) +{ +switch (reg->i_type) { +case XLOG_REG_TYPE_LRHEADER : +return XLOG_START_TRANS ; +case XLOG_REG_TYPE_UNMOUNT : +return XLOG_UNMOUNT_TRANS ; +case XLOG_REG_TYPE_COMMIT : +return XLOG_COMMIT_TRANS ; +default : +return 0 ; + } +} + static void xlog_write_ophdr( struct xlog_write_data *data,
@@ -2002,8 +2014,15 @@ xlog_write_ophdr( ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); ophdr->oh_len =cpu_to_be32 (rlen -sizeof (struct xlog_op_header )); + ophdr->oh_clientid =XFS_TRANSACTION ; + ophdr->oh_flags =xlog_ophdr_flag (reg);if (rlen != reg->i_len) ophdr->oh_flags |=XLOG_CONTINUE_TRANS ; + ophdr->oh_res2 =0 ; + +/* for historic reasons unmount uses a non-standard clientid */ +if (unlikely (reg->i_type ==XLOG_REG_TYPE_UNMOUNT )) + ophdr->oh_clientid =XFS_LOG ; } static uint32_t
fs/xfs/xfs_log_cil.c +0 -16
@@ -438,7 +438,6 @@ xlog_format_start( {struct xfs_log_vec *lv = lfb->lv;struct xfs_log_iovec *vec = &lv->lv_iovecp[lfb->idx]; -struct xlog_op_header *oph;uint32_t len;void *buf;
@@ -453,11 +452,6 @@ xlog_format_start( vec->i_type = type; vec->i_addr = lv->lv_buf + lv->lv_buf_used; - oph = vec->i_addr; - oph->oh_clientid =XFS_TRANSACTION ; - oph->oh_res2 =0 ; - oph->oh_flags =0 ; - buf = vec->i_addr +sizeof (struct xlog_op_header );ASSERT (IS_ALIGNED ((unsigned long )buf,sizeof (uint64_t )));return buf;
@@ -1180,8 +1174,6 @@ xlog_cil_write_commit_record( {struct xlog *log = ctx->cil->xc_log;struct xlog_op_header ophdr = { - .oh_clientid =XFS_TRANSACTION , - .oh_flags =XLOG_COMMIT_TRANS , };struct xfs_log_iovec reg = { .i_addr = &ophdr,
@@ -1232,24 +1224,16 @@ xlog_cil_build_trans_hdr(memset (hdr,0 ,sizeof (*hdr));/* Log start record */ - hdr->oph[0 ].oh_clientid =XFS_TRANSACTION ; - hdr->oph[0 ].oh_flags =XLOG_START_TRANS ; - -/* log iovec region pointer */ hdr->lhdr[0 ].i_addr = &hdr->oph[0 ]; hdr->lhdr[0 ].i_len =sizeof (struct xlog_op_header ); hdr->lhdr[0 ].i_type =XLOG_REG_TYPE_LRHEADER ; -/* log opheader */ - hdr->oph[1 ].oh_clientid =XFS_TRANSACTION ; -/* transaction header in host byte order format */ hdr->thdr.th_magic =XFS_TRANS_HEADER_MAGIC ; hdr->thdr.th_type =XFS_TRANS_CHECKPOINT ; hdr->thdr.th_tid = tic->t_tid; hdr->thdr.th_num_items = num_iovecs; -/* log iovec region pointer */ hdr->lhdr[1 ].i_addr = &hdr->oph[1 ]; hdr->lhdr[1 ].i_len =sizeof (struct xlog_op_header ) +sizeof (struct xfs_trans_header );
Signature · 1 line
2.53.0
PATCH 9/15 xfs: directly format ophdrs into the iclog
In reply to Christoph HellwigNow that xlog xlog_write_ophdr formats the entire ophdr, there is no reason to "bounce buffer" it through the region passed in by the xlog_write caller. Directly format the regular ophdrs into the iclog. This is very similar to how the continuation ophdrs are handled in xlog_write_cont_ophdr already. As there are log vectors that contain nothing but an ophdr, the payload copy can now be skipped in some cases, and the accounting of the number of written records has to move to the ophdr writing routines.
For now the space allocated in the log vectors still includes that for the ophdr, but this wasted space will be removed subsequently.
--- fs/xfs/xfs_log.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
fs/xfs/xfs_log.c +11 -3
@@ -2010,8 +2010,11 @@ xlog_write_ophdr( struct xfs_log_iovec *reg, unsigned int rlen) { -struct xlog_op_header *ophdr = reg->i_addr; +struct xlog_op_header *ophdr; + + data->record_cnt++; + ophdr =xlog_write_space_advance (data,sizeof (struct xlog_op_header )); ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); ophdr->oh_len =cpu_to_be32 (rlen -sizeof (struct xlog_op_header )); ophdr->oh_clientid =XFS_TRANSACTION ;
@@ -2032,6 +2035,8 @@ xlog_write_cont_ophdr( {struct xlog_op_header *ophdr; + data->record_cnt++; + ophdr =xlog_write_space_advance (data,sizeof (struct xlog_op_header )); ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); ophdr->oh_clientid =XFS_TRANSACTION ;
@@ -2059,7 +2064,6 @@ xlog_write_iovec( uint32_t buf_len) {memcpy (xlog_write_space_advance (data, buf_len), buf, buf_len); - data->record_cnt++; } static int
@@ -2118,7 +2122,11 @@ xlog_write_region( rlen =min_t (uint32_t, reg->i_len,xlog_write_space_left (data));xlog_write_ophdr (data, reg, rlen); -xlog_write_iovec (data, reg->i_addr, rlen); +if (rlen >sizeof (struct xlog_op_header )) { +xlog_write_iovec (data, + reg->i_addr +sizeof (struct xlog_op_header ), + rlen -sizeof (struct xlog_op_header )); + }/* * If we wrote the whole region, move to the next region.
Signature · 1 line
2.53.0
PATCH 10/15 xfs: make the i_len field in xfs_log_iovec an uint32_t
In reply to Christoph HellwigThe log region length has to be unsigned, so use an explicit type for it.
--- fs/xfs/xfs_log_priv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_log_priv.h +1 -1
@@ -15,7 +15,7 @@ struct xfs_mount;struct xfs_log_iovec {void *i_addr;/* beginning address of region */ -int i_len;/* length in bytes of region */ +uint32_t i_len;/* length in bytes of region */ uint i_type;/* type of region */ };
Signature · 1 line
2.53.0
PATCH 11/15 xfs: improve an assert in xlog_format_commit
In reply to Christoph HellwigBuffer usage in the log vec is tracked by lv_buf_used, so assert on that. lv_bytes can be slightly smaller due to rounding, so this makes the assert more exact.
--- fs/xfs/xfs_log_cil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_log_cil.c +1 -1
@@ -485,7 +485,7 @@ xlog_format_commit( vec->i_len = len;/* Catch buffer overruns */ -ASSERT ((void *)lv->lv_buf + lv->lv_bytes <= +ASSERT ((void *)lv->lv_buf + lv->lv_buf_used <= (void *)lv + lv->lv_alloc_size); lfb->idx++;
Signature · 1 line
2.53.0
PATCH 12/15 xfs: remove the lv_bytes field from struct xfs_log_vec
In reply to Christoph Hellwiglv_bytes is the sum of i_len in all log iovecs. Replace it with a new xfs_log_vec_bytes helper that iterators over the iovecs to prepare for an accounting change in i_len. Factor a few callers to calculate the value once instead of multiple times to avoid extra work even if it is fairly minimal.
--- fs/xfs/xfs_log.c | 8 ++++---- fs/xfs/xfs_log_cil.c | 24 +++++++++++------------- fs/xfs/xfs_log_priv.h | 10 +++++++++- 3 files changed, 24 insertions(+), 18 deletions(-)
fs/xfs/xfs_log.c +4 -4
@@ -814,15 +814,15 @@ xlog_write_one_vec(struct xfs_log_vec lv = { .lv_niovecs =1 , .lv_iovecp = reg, - .lv_bytes = reg->i_len, };LIST_HEAD (lv_chain); +unsigned int bytes =xfs_log_vec_bytes (&lv);/* account for space used by record data */ - ticket->t_curr_res -= lv.lv_bytes; + ticket->t_curr_res -= bytes;list_add (&lv.lv_list, &lv_chain); -return xlog_write (log, ctx, &lv_chain, ticket, lv.lv_bytes); +return xlog_write (log, ctx, &lv_chain, ticket, bytes); }/*
@@ -1947,7 +1947,7 @@ xlog_print_trans(continue ;xfs_warn (mp," niovecs = %d" , lv->lv_niovecs);xfs_warn (mp," alloc_size = %d" , lv->lv_alloc_size); -xfs_warn (mp," bytes = %d" , lv->lv_bytes); +xfs_warn (mp," bytes = %u" ,xfs_log_vec_bytes (lv));xfs_warn (mp," buf used= %d" , lv->lv_buf_used);/* dump each iovec for the log item */
fs/xfs/xfs_log_cil.c +11 -13
@@ -351,7 +351,6 @@ xlog_cil_alloc_shadow_bufs( lv->lv_buf_used =XFS_LOG_VEC_ORDERED ; else lv->lv_buf_used = 0; - lv->lv_bytes =0 ; }/* Ensure the lv is set up according to ->iop_size */
@@ -376,7 +375,7 @@ xfs_cil_prepare_item( {/* Account for the new LV being passed in */ if (lv->lv_buf_used !=XFS_LOG_VEC_ORDERED ) - *diff_len += lv->lv_bytes; + *diff_len +=xfs_log_vec_bytes (lv);/* * If there is no old LV, this is the first time we've seen the item in
@@ -392,7 +391,7 @@ xfs_cil_prepare_item( }else if (lip->li_lv != lv) {ASSERT (lv->lv_buf_used !=XFS_LOG_VEC_ORDERED ); - *diff_len -= lip->li_lv->lv_bytes; + *diff_len -=xfs_log_vec_bytes (lip->li_lv); lv->lv_item->li_lv_shadow = lip->li_lv; }
@@ -481,7 +480,6 @@ xlog_format_commit( } len +=sizeof (struct xlog_op_header ); lv->lv_buf_used += len; - lv->lv_bytes += len; vec->i_len = len;/* Catch buffer overruns */
@@ -568,14 +566,13 @@ xlog_cil_insert_format_items(* set the item up as though it is a new insertion so * that the space reservation accounting is correct. */ - *diff_len -= lv->lv_bytes; + *diff_len -=xfs_log_vec_bytes (lv);/* Ensure the lv is set up according to ->iop_size */ lv->lv_niovecs = shadow->lv_niovecs;/* reset the lv buffer information for new formatting */ lv->lv_buf_used =0 ; - lv->lv_bytes =0 ; lv->lv_buf = (char *)lv +xlog_cil_iovec_space (lv->lv_niovecs); }else {
@@ -1212,7 +1209,7 @@ struct xlog_cil_trans_hdr {* in xlog_write() for handling empty opheaders for start, commit and unmount * records much simpler. */ -static void +static int xlog_cil_build_trans_hdr( struct xfs_cil_ctx *ctx, struct xlog_cil_trans_hdr *hdr,
@@ -1220,6 +1217,7 @@ xlog_cil_build_trans_hdr( int num_iovecs) {struct xlog_ticket *tic = ctx->ticket; +int len;memset (hdr,0 ,sizeof (*hdr));
@@ -1241,9 +1239,10 @@ xlog_cil_build_trans_hdr( lvhdr->lv_niovecs =2 ; lvhdr->lv_iovecp = &hdr->lhdr[0 ]; - lvhdr->lv_bytes = hdr->lhdr[0 ].i_len + hdr->lhdr[1 ].i_len; - tic->t_curr_res -= lvhdr->lv_bytes; + len =xfs_log_vec_bytes (lvhdr); + tic->t_curr_res -= len; +return len; }/*
@@ -1300,7 +1299,7 @@ xlog_cil_build_lv_chain(/* we don't write ordered log vectors */ if (lv->lv_buf_used !=XFS_LOG_VEC_ORDERED ) - *num_bytes += lv->lv_bytes; + *num_bytes +=xfs_log_vec_bytes (lv); *num_iovecs += lv->lv_niovecs;list_add_tail (&lv->lv_list, &ctx->lv_chain);
@@ -1478,8 +1477,7 @@ xlog_cil_push_work(* Add the lvhdr to the head of the lv chain we pass to xlog_write() so * it gets written into the iclog first. */ -xlog_cil_build_trans_hdr (ctx, &thdr, &lvhdr, num_iovecs); - num_bytes += lvhdr.lv_bytes; + num_bytes +=xlog_cil_build_trans_hdr (ctx, &thdr, &lvhdr, num_iovecs);list_add (&lvhdr.lv_list, &ctx->lv_chain);/*
@@ -1767,7 +1765,7 @@ xlog_cil_process_intents(continue ;set_bit (XFS_LI_WHITEOUT , &ilip->li_flags);trace_xfs_cil_whiteout_mark (ilip); - len += ilip->li_lv->lv_bytes; + len +=xfs_log_vec_bytes (ilip->li_lv);kvfree (ilip->li_lv); ilip->li_lv =NULL ;
fs/xfs/xfs_log_priv.h +9 -1
@@ -26,7 +26,6 @@ struct xfs_log_vec {struct xfs_log_iovec *lv_iovecp;/* iovec array */ struct xfs_log_item *lv_item;/* owner */ char *lv_buf;/* formatted buffer */ -int lv_bytes;/* accounted space in buffer */ int lv_buf_used;/* buffer space used so far */ int lv_alloc_size;/* size of allocated lv */ };
@@ -746,4 +745,13 @@ static inline __be32 *xlog_cycle_data(struct xlog_rec_header *rhead, unsigned i) return &rhead->h_cycle_data[i]; } +static inline unsigned int xfs_log_vec_bytes (struct xfs_log_vec *lv) +{ +unsigned int bytes =0 , i; + +for (i =0 ; i < lv->lv_niovecs; i++) + bytes += lv->lv_iovecp[i].i_len; +return bytes; +} +#endif /* __XFS_LOG_PRIV_H__ */
Signature · 1 line
2.53.0
PATCH 13/15 xfs: create ophdrs on the fly in xlog_write
In reply to Christoph HellwigCurrently each log iovec starts with an xlog_op_header in the CIL buffer. This wastes a little bit of memory, but more importantly makes managing the alignment of the individual log regions a bit annoying.
Stop allocating this space now that the opheaders are generated by xlog_write and switch i_len to only account for the actual log region managed by the log item which doesn't include the opheader. Instead the opheader is only included in the low-level space reservation managed by xfs_log_vec_bytes.
--- fs/xfs/xfs_log.c | 26 +++++++----------- fs/xfs/xfs_log_cil.c | 61 ++++++++++--------------------------------- fs/xfs/xfs_log_priv.h | 7 ++++- 3 files changed, 29 insertions(+), 65 deletions(-)
fs/xfs/xfs_log.c +9 -17
@@ -835,17 +835,12 @@ xlog_write_unmount_record(struct xlog *log, struct xlog_ticket *ticket) { -struct { -struct xlog_op_header ophdr; -struct xfs_unmount_log_format ulf; - } unmount_rec = { - .ulf = { - .magic =XLOG_UNMOUNT_TYPE , - }, + struct xfs_unmount_log_format ulf = { + .magic =XLOG_UNMOUNT_TYPE , };struct xfs_log_iovec reg = { - .i_addr = &unmount_rec, - .i_len =sizeof (unmount_rec), + .i_addr = &ulf, + .i_len =sizeof (ulf), .i_type =XLOG_REG_TYPE_UNMOUNT , };
@@ -2016,7 +2011,7 @@ xlog_write_ophdr( ophdr =xlog_write_space_advance (data,sizeof (struct xlog_op_header )); ophdr->oh_tid =cpu_to_be32 (data->ticket->t_tid); - ophdr->oh_len =cpu_to_be32 (rlen -sizeof (struct xlog_op_header )); + ophdr->oh_len =cpu_to_be32 (rlen); ophdr->oh_clientid =XFS_TRANSACTION ; ophdr->oh_flags =xlog_ophdr_flag (reg);if (rlen != reg->i_len)
@@ -2118,15 +2113,12 @@ xlog_write_region(if (error)return error; } - - rlen =min_t (uint32_t, reg->i_len,xlog_write_space_left (data)); + rlen =min_t (uint32_t, reg->i_len, +xlog_write_space_left (data) -sizeof (struct xlog_op_header ));xlog_write_ophdr (data, reg, rlen); -if (rlen >sizeof (struct xlog_op_header )) { -xlog_write_iovec (data, - reg->i_addr +sizeof (struct xlog_op_header ), - rlen -sizeof (struct xlog_op_header )); - } +if (rlen) +xlog_write_iovec (data, reg->i_addr, rlen);/* * If we wrote the whole region, move to the next region.
fs/xfs/xfs_log_cil.c +14 -47
128 lines not on this page · raw message
fs/xfs/xfs_log_priv.h +6 -1
@@ -745,12 +745,17 @@ static inline __be32 *xlog_cycle_data(struct xlog_rec_header *rhead, unsigned i)return &rhead->h_cycle_data[i]; } +static inline unsigned int xfs_log_iovec_bytes (struct xfs_log_iovec *reg) +{ +return sizeof (struct xlog_op_header ) + reg->i_len; +} +static inline unsigned int xfs_log_vec_bytes (struct xfs_log_vec *lv) {unsigned int bytes =0 , i;for (i =0 ; i < lv->lv_niovecs; i++) - bytes += lv->lv_iovecp[i].i_len; + bytes +=xfs_log_iovec_bytes (&lv->lv_iovecp[i]);return bytes; }
Signature · 1 line
2.53.0
PATCH 14/15 xfs: move building the checkpoint header into xlog_cil_write_chain
In reply to Christoph HellwigKeeping the building of the checkpoint header log vec inside of xlog_cil_write_chain nicely contains the life-time of the on-disk structures to a small section and allows building them at declaration time without needing the xlog_cil_trans_hdr wrapper structure.
It also reduces code size and matches the flow in xlog_write_one_vec.
--- fs/xfs/xfs_log_cil.c | 136 +++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 77 deletions(-)
fs/xfs/xfs_log_cil.c +59 -77
@@ -1116,23 +1116,72 @@ xlog_cil_order_write( }/* -* Write out the log vector change now attached to the CIL context. This will -* write a start record that needs to be strictly ordered in ascending CIL -* sequence order so that log recovery will always use in-order start LSNs when -* replaying checkpoints. +* Write out the log vector chain now attached to the CIL context. +* +* This will write a start record that needs to be strictly ordered in ascending +* CIL sequence order so that log recovery will always use in-order start LSNs +* when replaying checkpoints. */ static int xlog_cil_write_chain (struct xfs_cil_ctx *ctx, -uint32_t chain_len) +uint32_t chain_len, +uint32_t num_iovecs) { -struct xlog *log = ctx->cil->xc_log; +struct xfs_trans_header thdr = { + .th_magic =XFS_TRANS_HEADER_MAGIC , + .th_type =XFS_TRANS_CHECKPOINT , + .th_tid = ctx->ticket->t_tid, + .th_num_items = num_iovecs, + }; +struct xfs_log_iovec lhdr[2 ] = { + { +/* Log start record */ + .i_type =XLOG_REG_TYPE_LRHEADER , + }, + { +/* Transaction header */ + .i_addr = &thdr, + .i_len =sizeof (thdr), + .i_type =XLOG_REG_TYPE_TRANSHDR , + }, + }; +struct xfs_log_vec lvhdr = { + .lv_niovecs =ARRAY_SIZE (lhdr), + .lv_iovecp = lhdr, + + }; +int len =xfs_log_vec_bytes (&lvhdr);int error; +/* +* Build a checkpoint transaction header and write it to the log before +* the chain of changed log item to begin the transaction. +* +* This is the only place we write a transaction header, so we also wrap +* the transaction header. We keep the start record in it's own log +* vector rather than compacting them into a single region as this ends +* up making the logic in xlog_write() for handling empty regions for +* start, commit and unmount records much simpler. +* +* We need to account for the space used by the transaction header here +* as it is not accounted for in xlog_write(). +*/ +list_add (&lvhdr.lv_list, &ctx->lv_chain); + chain_len += len; + ctx->ticket->t_curr_res -= len; + error =xlog_cil_order_write (ctx->cil, ctx->sequence, _START_RECORD); -if (error) -return error; -return xlog_write (log, ctx, &ctx->lv_chain, ctx->ticket, chain_len); +if (!error) + error =xlog_write (ctx->cil->xc_log, ctx, &ctx->lv_chain, + ctx->ticket, chain_len); + +/* +* Take the lvhdr back off the lv_chain immediately after writing to the +* log as it should not be passed to log I/O completion. +*/ +list_del (&lvhdr.lv_list); +return error; }/*
@@ -1163,55 +1212,6 @@ xlog_cil_write_commit_record(return error; } -struct xlog_cil_trans_hdr { -struct xfs_trans_header thdr; -struct xfs_log_iovec lhdr[2 ]; -}; - -/* -* Build a checkpoint transaction header to begin the journal transaction. We -* need to account for the space used by the transaction header here as it is -* not accounted for in xlog_write(). -* -* This is the only place we write a transaction header, so we also wrap the -* transaction header. We keep the start record in it's own log vector rather -* than compacting them into a single region as this ends up making the logic -* in xlog_write() for handling empty opheaders for start, commit and unmount -* records much simpler. -*/ -static int -xlog_cil_build_trans_hdr ( -struct xfs_cil_ctx *ctx, -struct xlog_cil_trans_hdr *hdr, -struct xfs_log_vec *lvhdr, -int num_iovecs) -{ -struct xlog_ticket *tic = ctx->ticket; -int len; - -memset (hdr,0 ,sizeof (*hdr)); - -/* Log start record */ - hdr->lhdr[0 ].i_type =XLOG_REG_TYPE_LRHEADER ; - -/* transaction header in host byte order format */ - hdr->thdr.th_magic =XFS_TRANS_HEADER_MAGIC ; - hdr->thdr.th_type =XFS_TRANS_CHECKPOINT ; - hdr->thdr.th_tid = tic->t_tid; - hdr->thdr.th_num_items = num_iovecs; - - hdr->lhdr[1 ].i_addr = &hdr->thdr; - hdr->lhdr[1 ].i_len =sizeof (struct xfs_trans_header ); - hdr->lhdr[1 ].i_type =XLOG_REG_TYPE_TRANSHDR ; - - lvhdr->lv_niovecs =2 ; - lvhdr->lv_iovecp = &hdr->lhdr[0 ]; - - len =xfs_log_vec_bytes (lvhdr); - tic->t_curr_res -= len; -return len; -} -/* * CIL item reordering compare function. We want to order in ascending ID order, * but we want to leave items with the same ID in the order they were added to
@@ -1322,8 +1322,6 @@ xlog_cil_push_work(int num_iovecs =0 ;int num_bytes =0 ;int error =0 ; -struct xlog_cil_trans_hdr thdr; -struct xfs_log_vec lvhdr = {};xfs_csn_t push_seq;bool push_commit_stable;LIST_HEAD (whiteouts);
@@ -1437,23 +1435,7 @@ xlog_cil_push_work(*/ list_sort (NULL , &ctx->lv_chain, xlog_cil_order_cmp); -/* -* Build a checkpoint transaction header and write it to the log to -* begin the transaction. We need to account for the space used by the -* transaction header here as it is not accounted for in xlog_write(). -* Add the lvhdr to the head of the lv chain we pass to xlog_write() so -* it gets written into the iclog first. -*/ - num_bytes +=xlog_cil_build_trans_hdr (ctx, &thdr, &lvhdr, num_iovecs); -list_add (&lvhdr.lv_list, &ctx->lv_chain); - -/* -* Take the lvhdr back off the lv_chain immediately after calling -* xlog_cil_write_chain() as it should not be passed to log IO -* completion. -*/ - error =xlog_cil_write_chain (ctx, num_bytes); -list_del (&lvhdr.lv_list); + error =xlog_cil_write_chain (ctx, num_bytes, num_iovecs);if (error) goto out_abort_free_ticket;
Signature · 1 line
2.53.0
PATCH 15/15 xfs: cleanup log vec used tracking
In reply to Christoph HellwigThe lv_buf_used is used for two unrelated things: one to propagate the fact that a log vec is for an ordered buffer, and also to track the amount of data copied into the linear buffer of a non-ordered logvec.
Use a field in the on-stack xlog_format_buf structure for the buffer usage tracking, and replace the lv_buf_used field in struct xfs_log_vec with a boolean to indicate that it is an ordered buffer.
--- fs/xfs/xfs_log.c | 2 +- fs/xfs/xfs_log_cil.c | 28 +++++++++++----------------- fs/xfs/xfs_log_priv.h | 2 +- 3 files changed, 13 insertions(+), 19 deletions(-)
fs/xfs/xfs_log.c +1 -1
@@ -1943,7 +1943,7 @@ xlog_print_trans(xfs_warn (mp," niovecs = %d" , lv->lv_niovecs);xfs_warn (mp," alloc_size = %d" , lv->lv_alloc_size);xfs_warn (mp," bytes = %u" ,xfs_log_vec_bytes (lv)); -xfs_warn (mp," buf used= %d" , lv->lv_buf_used); +xfs_warn (mp," ordered = %u" , lv->lv_ordered);/* dump each iovec for the log item */ vec = lv->lv_iovecp;
fs/xfs/xfs_log_cil.c +11 -17
@@ -338,22 +338,17 @@ xlog_cil_alloc_shadow_bufs(INIT_LIST_HEAD (&lv->lv_list); lv->lv_item = lip; lv->lv_alloc_size = alloc_size; -if (ordered) - lv->lv_buf_used =XFS_LOG_VEC_ORDERED ; -else +if (!ordered) lv->lv_iovecp = (struct xfs_log_iovec *)&lv[1 ]; lip->li_lv_shadow = lv; }else {/* same or smaller, optimise common overwrite case */ lv = lip->li_lv_shadow; -if (ordered) - lv->lv_buf_used =XFS_LOG_VEC_ORDERED ; -else - lv->lv_buf_used =0 ; }/* Ensure the lv is set up according to ->iop_size */ lv->lv_niovecs = niovecs; + lv->lv_ordered = ordered;/* The allocated data region lies beyond the iovec region */ lv->lv_buf = (char *)lv +xlog_cil_iovec_space (niovecs);
@@ -373,7 +368,7 @@ xfs_cil_prepare_item( int *diff_len) {/* Account for the new LV being passed in */ -if (lv->lv_buf_used !=XFS_LOG_VEC_ORDERED ) +if (!lv->lv_ordered) *diff_len +=xfs_log_vec_bytes (lv);/*
@@ -388,7 +383,7 @@ xfs_cil_prepare_item( lv->lv_item->li_ops->iop_pin (lv->lv_item); lv->lv_item->li_lv_shadow =NULL ; }else if (lip->li_lv != lv) { -ASSERT (lv->lv_buf_used !=XFS_LOG_VEC_ORDERED ); +ASSERT (!lv->lv_ordered); *diff_len -=xfs_log_vec_bytes (lip->li_lv); lv->lv_item->li_lv_shadow = lip->li_lv;
@@ -410,6 +405,7 @@ xfs_cil_prepare_item(struct xlog_format_buf {struct xfs_log_vec *lv;unsigned int idx; +unsigned int buf_used;/* buffer space used */ };/*
@@ -430,10 +426,10 @@ xlog_format_start(ASSERT (lfb->idx < lv->lv_niovecs); - lv->lv_buf_used =round_up (lv->lv_buf_used,sizeof (uint64_t )); + lfb->buf_used =round_up (lfb->buf_used,sizeof (uint64_t )); vec->i_type = type; - vec->i_addr = lv->lv_buf + lv->lv_buf_used; + vec->i_addr = lv->lv_buf + lfb->buf_used;return vec->i_addr; }
@@ -454,12 +450,11 @@ xlog_format_commit( len =xlog_calc_iovec_len (data_len);if (len - data_len !=0 )memset (vec->i_addr + data_len,0 , len - data_len); - - lv->lv_buf_used += len; vec->i_len = len; + lfb->buf_used += len;/* Catch buffer overruns */ -ASSERT ((void *)lv->lv_buf + lv->lv_buf_used <= +ASSERT ((void *)lv->lv_buf + lfb->buf_used <= (void *)lv + lv->lv_alloc_size); lfb->idx++;
@@ -520,7 +515,7 @@ xlog_cil_insert_format_items(* The formatting size information is already attached to * the shadow lv on the log item. */ -if (shadow->lv_buf_used ==XFS_LOG_VEC_ORDERED ) { +if (shadow->lv_ordered) {if (!lv) { lv = shadow; lv->lv_item = lip;
@@ -548,7 +543,6 @@ xlog_cil_insert_format_items( lv->lv_niovecs = shadow->lv_niovecs;/* reset the lv buffer information for new formatting */ - lv->lv_buf_used =0 ; lv->lv_buf = (char *)lv +xlog_cil_iovec_space (lv->lv_niovecs); }else {
@@ -1265,7 +1259,7 @@ xlog_cil_build_lv_chain( lv->lv_order_id = item->li_order_id;/* we don't write ordered log vectors */ -if (lv->lv_buf_used !=XFS_LOG_VEC_ORDERED ) +if (!lv->lv_ordered) *num_bytes +=xfs_log_vec_bytes (lv); *num_iovecs += lv->lv_niovecs;list_add_tail (&lv->lv_list, &ctx->lv_chain);
fs/xfs/xfs_log_priv.h +1 -1
@@ -26,8 +26,8 @@ struct xfs_log_vec {struct xfs_log_iovec *lv_iovecp;/* iovec array */ struct xfs_log_item *lv_item;/* owner */ char *lv_buf;/* formatted buffer */ -int lv_buf_used;/* buffer space used so far */ int lv_alloc_size;/* size of allocated lv */ +bool lv_ordered;/* ordered logvec? */ };/*
Signature · 1 line
2.53.0
Quoted 9 lines · Christoph Hellwig
Hi all,
for historic reasons, generating of the log ophdrs is split over the log item formatting and the core log write in somewhat awkward ways. This less to subtle extra code, extra (small) memory usage for keeping the headers in memory when they are not needed. This series refactors the log vec formatting a bit and the
xlog_writecode a lot so that the ophdrs are formatted when writing to the iclog, and the no memory for the ophdrs is allocated for logvecs in the CIL.
I don't have the capacity to review this any time soon.
Given all the issues we're still finding and having to fix from LLM analysis, I'm not a great fan of doing open-heart surgery to the core journal write path right now. This is not simple code, and without proper on-disk journal format verification, we've never really had a way of rigourously testing journal write path reworks.
These sorts of changes have always been a bit of a 'merge and hope' process because 'test it with log stress' via fstests doesn't actually verify that what has been written to the journal has been recovered correctly. It just tests that recovery completes with error, and the lack of errors used to imply 'the code is good'.
I don't think that's good enough anymore. In this new world of journal fuzzing and LLM bug finding, we really need much more rigourous verification of what gets written to the journal before we start making fundamental changes to the way we track and write formatted log items into the journal. That way the log stress tests we currently have will formally verify that the contents of the journal being recovered are valid, and that we haven't introduced some subtle weird bug that will bite us in the future.
So, can we hold off making runtime infrastructure changes to the journal write path until after we land the recovery time on-disk journal format verification?
-Dave.
Signature · 2 lines
Dave Chinner [email protected]