| 501 | } |
| 502 | |
| 503 | static void |
| 504 | txg_sync_thread(void *arg) |
| 505 | { |
| 506 | dsl_pool_t *dp = arg; |
| 507 | spa_t *spa = dp->dp_spa; |
| 508 | tx_state_t *tx = &dp->dp_tx; |
| 509 | callb_cpr_t cpr; |
| 510 | clock_t start, delta; |
| 511 | |
| 512 | (void) spl_fstrans_mark(); |
| 513 | txg_thread_enter(tx, &cpr); |
| 514 | |
| 515 | start = delta = 0; |
| 516 | for (;;) { |
| 517 | clock_t timeout = zfs_txg_timeout * hz; |
| 518 | clock_t timer; |
| 519 | uint64_t txg; |
| 520 | uint64_t dirty_min_bytes = |
| 521 | zfs_dirty_data_max * zfs_dirty_data_sync_percent / 100; |
| 522 | |
| 523 | /* |
| 524 | * We sync when we're scanning, there's someone waiting |
| 525 | * on us, or the quiesce thread has handed off a txg to |
| 526 | * us, or we have reached our timeout. |
| 527 | */ |
| 528 | timer = (delta >= timeout ? 0 : timeout - delta); |
| 529 | while (!dsl_scan_active(dp->dp_scan) && |
| 530 | !tx->tx_exiting && timer > 0 && |
| 531 | tx->tx_synced_txg >= tx->tx_sync_txg_waiting && |
| 532 | !txg_has_quiesced_to_sync(dp) && |
| 533 | dp->dp_dirty_total < dirty_min_bytes) { |
| 534 | dprintf("waiting; tx_synced=%llu waiting=%llu dp=%p\n", |
| 535 | tx->tx_synced_txg, tx->tx_sync_txg_waiting, dp); |
| 536 | txg_thread_wait(tx, &cpr, &tx->tx_sync_more_cv, timer); |
| 537 | delta = ddi_get_lbolt() - start; |
| 538 | timer = (delta > timeout ? 0 : timeout - delta); |
| 539 | } |
| 540 | |
| 541 | /* |
| 542 | * Wait until the quiesce thread hands off a txg to us, |
| 543 | * prompting it to do so if necessary. |
| 544 | */ |
| 545 | while (!tx->tx_exiting && !txg_has_quiesced_to_sync(dp)) { |
| 546 | if (tx->tx_quiesce_txg_waiting < tx->tx_open_txg+1) |
| 547 | tx->tx_quiesce_txg_waiting = tx->tx_open_txg+1; |
| 548 | cv_broadcast(&tx->tx_quiesce_more_cv); |
| 549 | txg_thread_wait(tx, &cpr, &tx->tx_quiesce_done_cv, 0); |
| 550 | } |
| 551 | |
| 552 | if (tx->tx_exiting) |
| 553 | txg_thread_exit(tx, &cpr, &tx->tx_sync_thread); |
| 554 | |
| 555 | /* |
| 556 | * Consume the quiesced txg which has been handed off to |
| 557 | * us. This may cause the quiescing thread to now be |
| 558 | * able to quiesce another txg, so we must signal it. |
| 559 | */ |
| 560 | ASSERT(tx->tx_quiesced_txg != 0); |
nothing calls this directly
no test coverage detected