55 static scan_cb_t dsl_scan_remove_cb; |
55 static scan_cb_t dsl_scan_remove_cb; |
56 static dsl_syncfunc_t dsl_scan_cancel_sync; |
56 static dsl_syncfunc_t dsl_scan_cancel_sync; |
57 static void dsl_scan_sync_state(dsl_scan_t *, dmu_tx_t *tx); |
57 static void dsl_scan_sync_state(dsl_scan_t *, dmu_tx_t *tx); |
58 |
58 |
59 int zfs_scan_min_time_ms = 1000; /* min millisecs to scrub per txg */ |
59 int zfs_scan_min_time_ms = 1000; /* min millisecs to scrub per txg */ |
|
60 int zfs_free_min_time_ms = 1000; /* min millisecs to free per txg */ |
60 int zfs_resilver_min_time_ms = 3000; /* min millisecs to resilver per txg */ |
61 int zfs_resilver_min_time_ms = 3000; /* min millisecs to resilver per txg */ |
61 boolean_t zfs_no_scrub_io = B_FALSE; /* set to disable scrub i/o */ |
62 boolean_t zfs_no_scrub_io = B_FALSE; /* set to disable scrub i/o */ |
62 boolean_t zfs_no_scrub_prefetch = B_FALSE; /* set to disable srub prefetching */ |
63 boolean_t zfs_no_scrub_prefetch = B_FALSE; /* set to disable srub prefetching */ |
63 enum ddt_class zfs_scrub_ddt_class_max = DDT_CLASS_DUPLICATE; |
64 enum ddt_class zfs_scrub_ddt_class_max = DDT_CLASS_DUPLICATE; |
64 int dsl_scan_delay_completion = B_FALSE; /* set to delay scan completion */ |
65 int dsl_scan_delay_completion = B_FALSE; /* set to delay scan completion */ |
597 |
598 |
598 /* |
599 /* |
599 * XXX need to make sure all of these arc_read() prefetches are |
600 * XXX need to make sure all of these arc_read() prefetches are |
600 * done before setting xlateall (similar to dsl_read()) |
601 * done before setting xlateall (similar to dsl_read()) |
601 */ |
602 */ |
602 (void) arc_read(scn->scn_prefetch_zio_root, scn->scn_dp->dp_spa, bp, |
603 (void) arc_read(scn->scn_zio_root, scn->scn_dp->dp_spa, bp, |
603 buf, NULL, NULL, ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, |
604 buf, NULL, NULL, ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, |
604 &flags, &czb); |
605 &flags, &czb); |
605 } |
606 } |
606 |
607 |
607 static boolean_t |
608 static boolean_t |
1376 return; |
1377 return; |
1377 } |
1378 } |
1378 zap_cursor_fini(&zc); |
1379 zap_cursor_fini(&zc); |
1379 } |
1380 } |
1380 |
1381 |
|
1382 static int |
|
1383 dsl_scan_free_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx) |
|
1384 { |
|
1385 dsl_scan_t *scn = arg; |
|
1386 uint64_t elapsed_nanosecs; |
|
1387 |
|
1388 elapsed_nanosecs = gethrtime() - scn->scn_sync_start_time; |
|
1389 |
|
1390 if (elapsed_nanosecs / NANOSEC > zfs_txg_timeout || |
|
1391 (elapsed_nanosecs / MICROSEC > zfs_free_min_time_ms && |
|
1392 txg_sync_waiting(scn->scn_dp)) || |
|
1393 spa_shutting_down(scn->scn_dp->dp_spa)) |
|
1394 return (ERESTART); |
|
1395 |
|
1396 zio_nowait(zio_free_sync(scn->scn_zio_root, scn->scn_dp->dp_spa, |
|
1397 dmu_tx_get_txg(tx), bp, 0)); |
|
1398 dsl_dir_diduse_space(tx->tx_pool->dp_free_dir, DD_USED_HEAD, |
|
1399 -bp_get_dsize_sync(scn->scn_dp->dp_spa, bp), |
|
1400 -BP_GET_PSIZE(bp), -BP_GET_UCSIZE(bp), tx); |
|
1401 scn->scn_visited_this_txg++; |
|
1402 return (0); |
|
1403 } |
|
1404 |
|
1405 boolean_t |
|
1406 dsl_scan_active(dsl_scan_t *scn) |
|
1407 { |
|
1408 spa_t *spa = scn->scn_dp->dp_spa; |
|
1409 uint64_t used = 0, comp, uncomp; |
|
1410 |
|
1411 if (spa->spa_load_state != SPA_LOAD_NONE) |
|
1412 return (B_FALSE); |
|
1413 if (spa_shutting_down(spa)) |
|
1414 return (B_FALSE); |
|
1415 |
|
1416 if (scn->scn_phys.scn_state == DSS_SCANNING) |
|
1417 return (B_TRUE); |
|
1418 |
|
1419 if (spa_version(scn->scn_dp->dp_spa) >= SPA_VERSION_DEADLISTS) { |
|
1420 (void) bpobj_space(&scn->scn_dp->dp_free_bpobj, |
|
1421 &used, &comp, &uncomp); |
|
1422 } |
|
1423 return (used != 0); |
|
1424 } |
|
1425 |
1381 void |
1426 void |
1382 dsl_scan_sync(dsl_pool_t *dp, dmu_tx_t *tx) |
1427 dsl_scan_sync(dsl_pool_t *dp, dmu_tx_t *tx) |
1383 { |
1428 { |
1384 dsl_scan_t *scn = dp->dp_scan; |
1429 dsl_scan_t *scn = dp->dp_scan; |
1385 spa_t *spa = dp->dp_spa; |
1430 spa_t *spa = dp->dp_spa; |
|
1431 int err; |
1386 |
1432 |
1387 /* |
1433 /* |
1388 * Check for scn_restart_txg before checking spa_load_state, so |
1434 * Check for scn_restart_txg before checking spa_load_state, so |
1389 * that we can restart an old-style scan while the pool is being |
1435 * that we can restart an old-style scan while the pool is being |
1390 * imported (see dsl_scan_init). |
1436 * imported (see dsl_scan_init). |
1398 zfs_dbgmsg("restarting scan func=%u txg=%llu", |
1444 zfs_dbgmsg("restarting scan func=%u txg=%llu", |
1399 func, tx->tx_txg); |
1445 func, tx->tx_txg); |
1400 dsl_scan_setup_sync(scn, &func, tx); |
1446 dsl_scan_setup_sync(scn, &func, tx); |
1401 } |
1447 } |
1402 |
1448 |
1403 if (dp->dp_spa->spa_load_state != SPA_LOAD_NONE || |
1449 |
1404 spa_shutting_down(spa) || |
1450 if (!dsl_scan_active(scn) || |
1405 spa_sync_pass(dp->dp_spa) > 1 || |
1451 spa_sync_pass(dp->dp_spa) > 1) |
1406 scn->scn_phys.scn_state != DSS_SCANNING) |
|
1407 return; |
1452 return; |
1408 |
1453 |
1409 scn->scn_visited_this_txg = 0; |
1454 scn->scn_visited_this_txg = 0; |
1410 scn->scn_pausing = B_FALSE; |
1455 scn->scn_pausing = B_FALSE; |
1411 scn->scn_sync_start_time = gethrtime(); |
1456 scn->scn_sync_start_time = gethrtime(); |
1412 spa->spa_scrub_active = B_TRUE; |
1457 spa->spa_scrub_active = B_TRUE; |
|
1458 |
|
1459 /* |
|
1460 * First process the free list. If we pause the free, don't do |
|
1461 * any scanning. This ensures that there is no free list when |
|
1462 * we are scanning, so the scan code doesn't have to worry about |
|
1463 * traversing it. |
|
1464 */ |
|
1465 if (spa_version(dp->dp_spa) >= SPA_VERSION_DEADLISTS) { |
|
1466 scn->scn_zio_root = zio_root(dp->dp_spa, NULL, |
|
1467 NULL, ZIO_FLAG_MUSTSUCCEED); |
|
1468 err = bpobj_iterate(&dp->dp_free_bpobj, |
|
1469 dsl_scan_free_cb, scn, tx); |
|
1470 VERIFY3U(0, ==, zio_wait(scn->scn_zio_root)); |
|
1471 if (scn->scn_visited_this_txg) { |
|
1472 zfs_dbgmsg("freed %llu blocks in %llums from " |
|
1473 "free_bpobj txg %llu", |
|
1474 (longlong_t)scn->scn_visited_this_txg, |
|
1475 (longlong_t) |
|
1476 (gethrtime() - scn->scn_sync_start_time) / MICROSEC, |
|
1477 (longlong_t)tx->tx_txg); |
|
1478 scn->scn_visited_this_txg = 0; |
|
1479 /* |
|
1480 * Re-sync the ddt so that we can further modify |
|
1481 * it when doing bprewrite. |
|
1482 */ |
|
1483 ddt_sync(spa, tx->tx_txg); |
|
1484 } |
|
1485 if (err == ERESTART) |
|
1486 return; |
|
1487 } |
|
1488 |
|
1489 if (scn->scn_phys.scn_state != DSS_SCANNING) |
|
1490 return; |
|
1491 |
1413 |
1492 |
1414 if (scn->scn_phys.scn_ddt_bookmark.ddb_class <= |
1493 if (scn->scn_phys.scn_ddt_bookmark.ddb_class <= |
1415 scn->scn_phys.scn_ddt_class_max) { |
1494 scn->scn_phys.scn_ddt_class_max) { |
1416 zfs_dbgmsg("doing scan sync txg %llu; " |
1495 zfs_dbgmsg("doing scan sync txg %llu; " |
1417 "ddt bm=%llu/%llu/%llu/%llx", |
1496 "ddt bm=%llu/%llu/%llu/%llx", |
1431 (longlong_t)scn->scn_phys.scn_bookmark.zb_object, |
1510 (longlong_t)scn->scn_phys.scn_bookmark.zb_object, |
1432 (longlong_t)scn->scn_phys.scn_bookmark.zb_level, |
1511 (longlong_t)scn->scn_phys.scn_bookmark.zb_level, |
1433 (longlong_t)scn->scn_phys.scn_bookmark.zb_blkid); |
1512 (longlong_t)scn->scn_phys.scn_bookmark.zb_blkid); |
1434 } |
1513 } |
1435 |
1514 |
1436 scn->scn_prefetch_zio_root = zio_root(dp->dp_spa, NULL, |
1515 scn->scn_zio_root = zio_root(dp->dp_spa, NULL, |
1437 NULL, ZIO_FLAG_CANFAIL); |
1516 NULL, ZIO_FLAG_CANFAIL); |
1438 dsl_scan_visit(scn, tx); |
1517 dsl_scan_visit(scn, tx); |
1439 (void) zio_wait(scn->scn_prefetch_zio_root); |
1518 (void) zio_wait(scn->scn_zio_root); |
1440 scn->scn_prefetch_zio_root = NULL; |
1519 scn->scn_zio_root = NULL; |
1441 |
1520 |
1442 zfs_dbgmsg("visited %llu blocks in %llums", |
1521 zfs_dbgmsg("visited %llu blocks in %llums", |
1443 (longlong_t)scn->scn_visited_this_txg, |
1522 (longlong_t)scn->scn_visited_this_txg, |
1444 (longlong_t)(gethrtime() - scn->scn_sync_start_time) / MICROSEC); |
1523 (longlong_t)(gethrtime() - scn->scn_sync_start_time) / MICROSEC); |
1445 |
1524 |