Skip to content

Commit cddafdc

Browse files
mmatuskabehlendorf
authored andcommitted
Illumos #1313: Integer overflow in txg_delay()
The function txg_delay() is used to delay txg (transaction group) threads in ZFS. The timeout value for this function is calculated using: int timeout = ddi_get_lbolt() + ticks; Later, the actual wait is performed: while (ddi_get_lbolt() < timeout && tx->tx_syncing_txg < txg-1 && !txg_stalled(dp)) (void) cv_timedwait(&tx->tx_quiesce_more_cv, &tx->tx_sync_lock, timeout - ddi_get_lbolt()); The ddi_get_lbolt() function returns current uptime in clock ticks and is typed as clock_t. The clock_t type on 64-bit architectures is int64_t. The "timeout" variable will overflow depending on the tick frequency (e.g. for 1000 it will overflow in 28.855 days). This will make the expression "ddi_get_lbolt() < timeout" always false - txg threads will not be delayed anymore at all. This leads to a slowdown in ZFS writes. The attached patch initializes timeout as clock_t to match the return value of ddi_get_lbolt(). Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Issue #352
1 parent 0b7936d commit cddafdc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

module/zfs/txg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ void
506506
txg_delay(dsl_pool_t *dp, uint64_t txg, int ticks)
507507
{
508508
tx_state_t *tx = &dp->dp_tx;
509-
int timeout = ddi_get_lbolt() + ticks;
509+
clock_t timeout = ddi_get_lbolt() + ticks;
510510

511511
/* don't delay if this txg could transition to quiesing immediately */
512512
if (tx->tx_open_txg > txg ||

0 commit comments

Comments
 (0)