Skip to content

Commit

Permalink
zil: Free lwb_buf after write completion.
Browse files Browse the repository at this point in the history
There is no sense to keep that memory allocated during the flush.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Prakash Surya <[email protected]>
Signed-off-by:  Alexander Motin <[email protected]>
Sponsored by:   iXsystems, Inc.
Closes #14855
  • Loading branch information
amotin authored May 12, 2023
1 parent 895e031 commit 7381ddf
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions module/zfs/zil.c
Original file line number Diff line number Diff line change
Expand Up @@ -1376,20 +1376,10 @@ zil_lwb_flush_vdevs_done(zio_t *zio)

spa_config_exit(zilog->zl_spa, SCL_STATE, lwb);

zio_buf_free(lwb->lwb_buf, lwb->lwb_sz);
hrtime_t t = gethrtime() - lwb->lwb_issued_timestamp;

mutex_enter(&zilog->zl_lock);

/*
* If we have had an allocation failure and the txg is
* waiting to sync then we want zil_sync() to remove the lwb so
* that it's not picked up as the next new one in
* zil_process_commit_list(). zil_sync() will only remove the
* lwb if lwb_buf is null.
*/
lwb->lwb_buf = NULL;

zilog->zl_last_lwb_latency = (zilog->zl_last_lwb_latency * 7 + t) / 8;

lwb->lwb_root_zio = NULL;
Expand Down Expand Up @@ -1475,7 +1465,8 @@ zil_lwb_flush_wait_all(zilog_t *zilog, uint64_t txg)
IMPLY(lwb->lwb_issued_txg > 0,
lwb->lwb_state == LWB_STATE_FLUSH_DONE);
}
IMPLY(lwb->lwb_state == LWB_STATE_FLUSH_DONE,
IMPLY(lwb->lwb_state == LWB_STATE_WRITE_DONE ||
lwb->lwb_state == LWB_STATE_FLUSH_DONE,
lwb->lwb_buf == NULL);
lwb = list_next(&zilog->zl_lwb_list, lwb);
}
Expand Down Expand Up @@ -1519,6 +1510,8 @@ zil_lwb_write_done(zio_t *zio)
ASSERT(BP_GET_FILL(zio->io_bp) == 0);

abd_free(zio->io_abd);
zio_buf_free(lwb->lwb_buf, lwb->lwb_sz);
lwb->lwb_buf = NULL;

mutex_enter(&zilog->zl_lock);
ASSERT3S(lwb->lwb_state, ==, LWB_STATE_ISSUED);
Expand Down Expand Up @@ -3433,7 +3426,8 @@ zil_sync(zilog_t *zilog, dmu_tx_t *tx)

while ((lwb = list_head(&zilog->zl_lwb_list)) != NULL) {
zh->zh_log = lwb->lwb_blk;
if (lwb->lwb_buf != NULL || lwb->lwb_max_txg > txg)
if (lwb->lwb_state != LWB_STATE_FLUSH_DONE ||
lwb->lwb_max_txg > txg)
break;
list_remove(&zilog->zl_lwb_list, lwb);
zio_free(spa, txg, &lwb->lwb_blk);
Expand Down

0 comments on commit 7381ddf

Please sign in to comment.