Skip to content

Commit 9d76950

Browse files
authored
ZIL: Improve write log size accounting
Before this change write log size TXG throttling mechanism was accounting only user payload bytes. But the actual ZIL both on disk and especially in memory include headers of hundred(s) of bytes. Not accouting those may allow applications like bonnie++, in their wisdom writing one byte at a time, to consume excessive amount of memory and ZIL/SLOG in one TXG. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Rob Norris <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Sponsored by: iXsystems, Inc. Closes #17373
1 parent b01d7bd commit 9d76950

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

module/zfs/zfs_log.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,7 @@ zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
617617
dmu_buf_impl_t *db = (dmu_buf_impl_t *)sa_get_db(zp->z_sa_hdl);
618618
uint32_t blocksize = zp->z_blksz;
619619
itx_wr_state_t write_state;
620-
uint64_t gen = 0;
621-
ssize_t size = resid;
620+
uint64_t gen = 0, log_size = 0;
622621

623622
if (zil_replaying(zilog, tx) || zp->z_unlinked ||
624623
zfs_xattr_owner_unlinked(zp)) {
@@ -680,6 +679,10 @@ zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
680679
}
681680
}
682681

682+
log_size += itx->itx_size;
683+
if (wr_state == WR_NEED_COPY)
684+
log_size += len;
685+
683686
itx->itx_wr_state = wr_state;
684687
lr->lr_foid = zp->z_id;
685688
lr->lr_offset = off;
@@ -699,9 +702,7 @@ zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
699702
resid -= len;
700703
}
701704

702-
if (write_state == WR_COPIED || write_state == WR_NEED_COPY) {
703-
dsl_pool_wrlog_count(zilog->zl_dmu_pool, size, tx->tx_txg);
704-
}
705+
dsl_pool_wrlog_count(zilog->zl_dmu_pool, log_size, tx->tx_txg);
705706
}
706707

707708
/*

module/zfs/zvol.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ zvol_log_write(zvol_state_t *zv, dmu_tx_t *tx, uint64_t offset,
871871
uint32_t blocksize = zv->zv_volblocksize;
872872
zilog_t *zilog = zv->zv_zilog;
873873
itx_wr_state_t write_state;
874-
uint64_t sz = size;
874+
uint64_t log_size = 0;
875875

876876
if (zil_replaying(zilog, tx))
877877
return;
@@ -909,6 +909,10 @@ zvol_log_write(zvol_state_t *zv, dmu_tx_t *tx, uint64_t offset,
909909
wr_state = WR_NEED_COPY;
910910
}
911911

912+
log_size += itx->itx_size;
913+
if (wr_state == WR_NEED_COPY)
914+
log_size += len;
915+
912916
itx->itx_wr_state = wr_state;
913917
lr->lr_foid = ZVOL_OBJ;
914918
lr->lr_offset = offset;
@@ -924,9 +928,7 @@ zvol_log_write(zvol_state_t *zv, dmu_tx_t *tx, uint64_t offset,
924928
size -= len;
925929
}
926930

927-
if (write_state == WR_COPIED || write_state == WR_NEED_COPY) {
928-
dsl_pool_wrlog_count(zilog->zl_dmu_pool, sz, tx->tx_txg);
929-
}
931+
dsl_pool_wrlog_count(zilog->zl_dmu_pool, log_size, tx->tx_txg);
930932
}
931933

932934
/*

0 commit comments

Comments
 (0)