Deleted Added
full compact
dsl_scan.c (240957) dsl_scan.c (243674)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012 by Delphix. All rights reserved.
23 */
24
25#include <sys/dsl_scan.h>
26#include <sys/dsl_pool.h>
27#include <sys/dsl_dataset.h>
28#include <sys/dsl_prop.h>
29#include <sys/dsl_dir.h>
30#include <sys/dsl_synctask.h>

--- 8 unchanged lines hidden (view full) ---

39#include <sys/zfs_znode.h>
40#include <sys/spa_impl.h>
41#include <sys/vdev_impl.h>
42#include <sys/zil_impl.h>
43#include <sys/zio_checksum.h>
44#include <sys/ddt.h>
45#include <sys/sa.h>
46#include <sys/sa_impl.h>
24 */
25
26#include <sys/dsl_scan.h>
27#include <sys/dsl_pool.h>
28#include <sys/dsl_dataset.h>
29#include <sys/dsl_prop.h>
30#include <sys/dsl_dir.h>
31#include <sys/dsl_synctask.h>

--- 8 unchanged lines hidden (view full) ---

40#include <sys/zfs_znode.h>
41#include <sys/spa_impl.h>
42#include <sys/vdev_impl.h>
43#include <sys/zil_impl.h>
44#include <sys/zio_checksum.h>
45#include <sys/ddt.h>
46#include <sys/sa.h>
47#include <sys/sa_impl.h>
48#include <sys/zfeature.h>
47#ifdef _KERNEL
48#include <sys/zfs_vfsops.h>
49#endif
50
51typedef int (scan_cb_t)(dsl_pool_t *, const blkptr_t *, const zbookmark_t *);
52
53static scan_cb_t dsl_scan_defrag_cb;
54static scan_cb_t dsl_scan_scrub_cb;
55static scan_cb_t dsl_scan_remove_cb;
56static dsl_syncfunc_t dsl_scan_cancel_sync;
57static void dsl_scan_sync_state(dsl_scan_t *, dmu_tx_t *tx);
58
49#ifdef _KERNEL
50#include <sys/zfs_vfsops.h>
51#endif
52
53typedef int (scan_cb_t)(dsl_pool_t *, const blkptr_t *, const zbookmark_t *);
54
55static scan_cb_t dsl_scan_defrag_cb;
56static scan_cb_t dsl_scan_scrub_cb;
57static scan_cb_t dsl_scan_remove_cb;
58static dsl_syncfunc_t dsl_scan_cancel_sync;
59static void dsl_scan_sync_state(dsl_scan_t *, dmu_tx_t *tx);
60
59int zfs_top_maxinflight = 32; /* maximum I/Os per top-level */
60int zfs_resilver_delay = 2; /* number of ticks to delay resilver */
61int zfs_scrub_delay = 4; /* number of ticks to delay scrub */
62int zfs_scan_idle = 50; /* idle window in clock ticks */
61unsigned int zfs_top_maxinflight = 32; /* maximum I/Os per top-level */
62unsigned int zfs_resilver_delay = 2; /* number of ticks to delay resilver */
63unsigned int zfs_scrub_delay = 4; /* number of ticks to delay scrub */
64unsigned int zfs_scan_idle = 50; /* idle window in clock ticks */
63
65
64int zfs_scan_min_time_ms = 1000; /* min millisecs to scrub per txg */
65int zfs_free_min_time_ms = 1000; /* min millisecs to free per txg */
66int zfs_resilver_min_time_ms = 3000; /* min millisecs to resilver per txg */
66unsigned int zfs_scan_min_time_ms = 1000; /* min millisecs to scrub per txg */
67unsigned int zfs_free_min_time_ms = 1000; /* min millisecs to free per txg */
68unsigned int zfs_resilver_min_time_ms = 3000; /* min millisecs to resilver
69 per txg */
67boolean_t zfs_no_scrub_io = B_FALSE; /* set to disable scrub i/o */
68boolean_t zfs_no_scrub_prefetch = B_FALSE; /* set to disable srub prefetching */
70boolean_t zfs_no_scrub_io = B_FALSE; /* set to disable scrub i/o */
71boolean_t zfs_no_scrub_prefetch = B_FALSE; /* set to disable srub prefetching */
72
73SYSCTL_DECL(_vfs_zfs);
74TUNABLE_INT("vfs.zfs.top_maxinflight", &zfs_top_maxinflight);
75SYSCTL_UINT(_vfs_zfs, OID_AUTO, top_maxinflight, CTLFLAG_RW,
76 &zfs_top_maxinflight, 0, "Maximum I/Os per top-level vdev");
77TUNABLE_INT("vfs.zfs.resilver_delay", &zfs_resilver_delay);
78SYSCTL_UINT(_vfs_zfs, OID_AUTO, resilver_delay, CTLFLAG_RW,
79 &zfs_resilver_delay, 0, "Number of ticks to delay resilver");
80TUNABLE_INT("vfs.zfs.scrub_delay", &zfs_scrub_delay);
81SYSCTL_UINT(_vfs_zfs, OID_AUTO, scrub_delay, CTLFLAG_RW,
82 &zfs_scrub_delay, 0, "Number of ticks to delay scrub");
83TUNABLE_INT("vfs.zfs.scan_idle", &zfs_scan_idle);
84SYSCTL_UINT(_vfs_zfs, OID_AUTO, scan_idle, CTLFLAG_RW,
85 &zfs_scan_idle, 0, "Idle scan window in clock ticks");
86TUNABLE_INT("vfs.zfs.scan_min_time_ms", &zfs_scan_min_time_ms);
87SYSCTL_UINT(_vfs_zfs, OID_AUTO, scan_min_time_ms, CTLFLAG_RW,
88 &zfs_scan_min_time_ms, 0, "Min millisecs to scrub per txg");
89TUNABLE_INT("vfs.zfs.free_min_time_ms", &zfs_free_min_time_ms);
90SYSCTL_UINT(_vfs_zfs, OID_AUTO, free_min_time_ms, CTLFLAG_RW,
91 &zfs_free_min_time_ms, 0, "Min millisecs to free per txg");
92TUNABLE_INT("vfs.zfs.resilver_min_time_ms", &zfs_resilver_min_time_ms);
93SYSCTL_UINT(_vfs_zfs, OID_AUTO, resilver_min_time_ms, CTLFLAG_RW,
94 &zfs_resilver_min_time_ms, 0, "Min millisecs to resilver per txg");
95TUNABLE_INT("vfs.zfs.no_scrub_io", &zfs_no_scrub_io);
96SYSCTL_INT(_vfs_zfs, OID_AUTO, no_scrub_io, CTLFLAG_RW,
97 &zfs_no_scrub_io, 0, "Disable scrub I/O");
98TUNABLE_INT("vfs.zfs.no_scrub_prefetch", &zfs_no_scrub_prefetch);
99SYSCTL_INT(_vfs_zfs, OID_AUTO, no_scrub_prefetch, CTLFLAG_RW,
100 &zfs_no_scrub_prefetch, 0, "Disable scrub prefetching");
101
69enum ddt_class zfs_scrub_ddt_class_max = DDT_CLASS_DUPLICATE;
70
71#define DSL_SCAN_IS_SCRUB_RESILVER(scn) \
72 ((scn)->scn_phys.scn_func == POOL_SCAN_SCRUB || \
73 (scn)->scn_phys.scn_func == POOL_SCAN_RESILVER)
74
75extern int zfs_txg_timeout;
76

--- 299 unchanged lines hidden (view full) ---

376dsl_read_nolock(zio_t *pio, spa_t *spa, const blkptr_t *bpp,
377 arc_done_func_t *done, void *private, int priority, int zio_flags,
378 uint32_t *arc_flags, const zbookmark_t *zb)
379{
380 return (arc_read_nolock(pio, spa, bpp, done, private,
381 priority, zio_flags, arc_flags, zb));
382}
383
102enum ddt_class zfs_scrub_ddt_class_max = DDT_CLASS_DUPLICATE;
103
104#define DSL_SCAN_IS_SCRUB_RESILVER(scn) \
105 ((scn)->scn_phys.scn_func == POOL_SCAN_SCRUB || \
106 (scn)->scn_phys.scn_func == POOL_SCAN_RESILVER)
107
108extern int zfs_txg_timeout;
109

--- 299 unchanged lines hidden (view full) ---

409dsl_read_nolock(zio_t *pio, spa_t *spa, const blkptr_t *bpp,
410 arc_done_func_t *done, void *private, int priority, int zio_flags,
411 uint32_t *arc_flags, const zbookmark_t *zb)
412{
413 return (arc_read_nolock(pio, spa, bpp, done, private,
414 priority, zio_flags, arc_flags, zb));
415}
416
384static boolean_t
385bookmark_is_zero(const zbookmark_t *zb)
386{
387 return (zb->zb_objset == 0 && zb->zb_object == 0 &&
388 zb->zb_level == 0 && zb->zb_blkid == 0);
389}
390
391/* dnp is the dnode for zb1->zb_object */
392static boolean_t
393bookmark_is_before(const dnode_phys_t *dnp, const zbookmark_t *zb1,
394 const zbookmark_t *zb2)
395{
396 uint64_t zb1nextL0, zb2thisobj;
397
398 ASSERT(zb1->zb_objset == zb2->zb_objset);
399 ASSERT(zb2->zb_level == 0);
400
401 /*
402 * A bookmark in the deadlist is considered to be after
403 * everything else.
404 */
405 if (zb2->zb_object == DMU_DEADLIST_OBJECT)
406 return (B_TRUE);
407
408 /* The objset_phys_t isn't before anything. */
409 if (dnp == NULL)
410 return (B_FALSE);
411
412 zb1nextL0 = (zb1->zb_blkid + 1) <<
413 ((zb1->zb_level) * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT));
414
415 zb2thisobj = zb2->zb_object ? zb2->zb_object :
416 zb2->zb_blkid << (DNODE_BLOCK_SHIFT - DNODE_SHIFT);
417
418 if (zb1->zb_object == DMU_META_DNODE_OBJECT) {
419 uint64_t nextobj = zb1nextL0 *
420 (dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT) >> DNODE_SHIFT;
421 return (nextobj <= zb2thisobj);
422 }
423
424 if (zb1->zb_object < zb2thisobj)
425 return (B_TRUE);
426 if (zb1->zb_object > zb2thisobj)
427 return (B_FALSE);
428 if (zb2->zb_object == DMU_META_DNODE_OBJECT)
429 return (B_FALSE);
430 return (zb1nextL0 <= zb2->zb_blkid);
431}
432
433static uint64_t
434dsl_scan_ds_maxtxg(dsl_dataset_t *ds)
435{
436 uint64_t smt = ds->ds_dir->dd_pool->dp_scan->scn_phys.scn_max_txg;
437 if (dsl_dataset_is_snapshot(ds))
438 return (MIN(smt, ds->ds_phys->ds_creation_txg));
439 return (smt);
440}

--- 6 unchanged lines hidden (view full) ---

447 DMU_POOL_SCAN, sizeof (uint64_t), SCAN_PHYS_NUMINTS,
448 &scn->scn_phys, tx));
449}
450
451static boolean_t
452dsl_scan_check_pause(dsl_scan_t *scn, const zbookmark_t *zb)
453{
454 uint64_t elapsed_nanosecs;
417static uint64_t
418dsl_scan_ds_maxtxg(dsl_dataset_t *ds)
419{
420 uint64_t smt = ds->ds_dir->dd_pool->dp_scan->scn_phys.scn_max_txg;
421 if (dsl_dataset_is_snapshot(ds))
422 return (MIN(smt, ds->ds_phys->ds_creation_txg));
423 return (smt);
424}

--- 6 unchanged lines hidden (view full) ---

431 DMU_POOL_SCAN, sizeof (uint64_t), SCAN_PHYS_NUMINTS,
432 &scn->scn_phys, tx));
433}
434
435static boolean_t
436dsl_scan_check_pause(dsl_scan_t *scn, const zbookmark_t *zb)
437{
438 uint64_t elapsed_nanosecs;
455 int mintime;
439 unsigned int mintime;
456
457 /* we never skip user/group accounting objects */
458 if (zb && (int64_t)zb->zb_object < 0)
459 return (B_FALSE);
460
461 if (scn->scn_pausing)
462 return (B_TRUE); /* we're already pausing */
463
440
441 /* we never skip user/group accounting objects */
442 if (zb && (int64_t)zb->zb_object < 0)
443 return (B_FALSE);
444
445 if (scn->scn_pausing)
446 return (B_TRUE); /* we're already pausing */
447
464 if (!bookmark_is_zero(&scn->scn_phys.scn_bookmark))
448 if (!ZB_IS_ZERO(&scn->scn_phys.scn_bookmark))
465 return (B_FALSE); /* we're resuming */
466
467 /* We only know how to resume from level-0 blocks. */
468 if (zb && zb->zb_level != 0)
469 return (B_FALSE);
470
471 mintime = (scn->scn_phys.scn_func == POOL_SCAN_RESILVER) ?
472 zfs_resilver_min_time_ms : zfs_scan_min_time_ms;

--- 138 unchanged lines hidden (view full) ---

611
612static boolean_t
613dsl_scan_check_resume(dsl_scan_t *scn, const dnode_phys_t *dnp,
614 const zbookmark_t *zb)
615{
616 /*
617 * We never skip over user/group accounting objects (obj<0)
618 */
449 return (B_FALSE); /* we're resuming */
450
451 /* We only know how to resume from level-0 blocks. */
452 if (zb && zb->zb_level != 0)
453 return (B_FALSE);
454
455 mintime = (scn->scn_phys.scn_func == POOL_SCAN_RESILVER) ?
456 zfs_resilver_min_time_ms : zfs_scan_min_time_ms;

--- 138 unchanged lines hidden (view full) ---

595
596static boolean_t
597dsl_scan_check_resume(dsl_scan_t *scn, const dnode_phys_t *dnp,
598 const zbookmark_t *zb)
599{
600 /*
601 * We never skip over user/group accounting objects (obj<0)
602 */
619 if (!bookmark_is_zero(&scn->scn_phys.scn_bookmark) &&
603 if (!ZB_IS_ZERO(&scn->scn_phys.scn_bookmark) &&
620 (int64_t)zb->zb_object >= 0) {
621 /*
622 * If we already visited this bp & everything below (in
623 * a prior txg sync), don't bother doing it again.
624 */
604 (int64_t)zb->zb_object >= 0) {
605 /*
606 * If we already visited this bp & everything below (in
607 * a prior txg sync), don't bother doing it again.
608 */
625 if (bookmark_is_before(dnp, zb, &scn->scn_phys.scn_bookmark))
609 if (zbookmark_is_before(dnp, zb, &scn->scn_phys.scn_bookmark))
626 return (B_TRUE);
627
628 /*
629 * If we found the block we're trying to resume from, or
630 * we went past it to a different object, zero it out to
631 * indicate that it's OK to start checking for pausing
632 * again.
633 */

--- 176 unchanged lines hidden (view full) ---

810 "visiting ds=%p/%llu zb=%llx/%llx/%llx/%llx buf=%p bp=%p",
811 ds, ds ? ds->ds_object : 0,
812 zb->zb_objset, zb->zb_object, zb->zb_level, zb->zb_blkid,
813 pbuf, bp);
814
815 if (bp->blk_birth <= scn->scn_phys.scn_cur_min_txg)
816 return;
817
610 return (B_TRUE);
611
612 /*
613 * If we found the block we're trying to resume from, or
614 * we went past it to a different object, zero it out to
615 * indicate that it's OK to start checking for pausing
616 * again.
617 */

--- 176 unchanged lines hidden (view full) ---

794 "visiting ds=%p/%llu zb=%llx/%llx/%llx/%llx buf=%p bp=%p",
795 ds, ds ? ds->ds_object : 0,
796 zb->zb_objset, zb->zb_object, zb->zb_level, zb->zb_blkid,
797 pbuf, bp);
798
799 if (bp->blk_birth <= scn->scn_phys.scn_cur_min_txg)
800 return;
801
818 if (BP_GET_TYPE(bp) != DMU_OT_USERGROUP_USED) {
819 /*
820 * For non-user-accounting blocks, we need to read the
821 * new bp (from a deleted snapshot, found in
822 * check_existing_xlation). If we used the old bp,
823 * pointers inside this block from before we resumed
824 * would be untranslated.
825 *
826 * For user-accounting blocks, we need to read the old
827 * bp, because we will apply the entire space delta to
828 * it (original untranslated -> translations from
829 * deleted snap -> now).
830 */
831 bp_toread = *bp;
832 }
833
834 if (dsl_scan_recurse(scn, ds, ostype, dnp, &bp_toread, zb, tx,
835 &buf) != 0)
836 return;
837
838 /*
839 * If dsl_scan_ddt() has aready visited this block, it will have
840 * already done any translations or scrubbing, so don't call the
841 * callback again.

--- 548 unchanged lines hidden (view full) ---

1390 dsl_scan_visitds(scn, dsobj, tx);
1391 zap_cursor_fini(&zc);
1392 if (scn->scn_pausing)
1393 return;
1394 }
1395 zap_cursor_fini(&zc);
1396}
1397
802 if (dsl_scan_recurse(scn, ds, ostype, dnp, &bp_toread, zb, tx,
803 &buf) != 0)
804 return;
805
806 /*
807 * If dsl_scan_ddt() has aready visited this block, it will have
808 * already done any translations or scrubbing, so don't call the
809 * callback again.

--- 548 unchanged lines hidden (view full) ---

1358 dsl_scan_visitds(scn, dsobj, tx);
1359 zap_cursor_fini(&zc);
1360 if (scn->scn_pausing)
1361 return;
1362 }
1363 zap_cursor_fini(&zc);
1364}
1365
1398static int
1399dsl_scan_free_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
1366static boolean_t
1367dsl_scan_free_should_pause(dsl_scan_t *scn)
1400{
1368{
1401 dsl_scan_t *scn = arg;
1402 uint64_t elapsed_nanosecs;
1403
1404 elapsed_nanosecs = gethrtime() - scn->scn_sync_start_time;
1369 uint64_t elapsed_nanosecs;
1370
1371 elapsed_nanosecs = gethrtime() - scn->scn_sync_start_time;
1405
1406 if (elapsed_nanosecs / NANOSEC > zfs_txg_timeout ||
1372 return (elapsed_nanosecs / NANOSEC > zfs_txg_timeout ||
1407 (elapsed_nanosecs / MICROSEC > zfs_free_min_time_ms &&
1408 txg_sync_waiting(scn->scn_dp)) ||
1373 (elapsed_nanosecs / MICROSEC > zfs_free_min_time_ms &&
1374 txg_sync_waiting(scn->scn_dp)) ||
1409 spa_shutting_down(scn->scn_dp->dp_spa))
1410 return (ERESTART);
1375 spa_shutting_down(scn->scn_dp->dp_spa));
1376}
1411
1377
1378static int
1379dsl_scan_free_block_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
1380{
1381 dsl_scan_t *scn = arg;
1382
1383 if (!scn->scn_is_bptree ||
1384 (BP_GET_LEVEL(bp) == 0 && BP_GET_TYPE(bp) != DMU_OT_OBJSET)) {
1385 if (dsl_scan_free_should_pause(scn))
1386 return (ERESTART);
1387 }
1388
1412 zio_nowait(zio_free_sync(scn->scn_zio_root, scn->scn_dp->dp_spa,
1413 dmu_tx_get_txg(tx), bp, 0));
1414 dsl_dir_diduse_space(tx->tx_pool->dp_free_dir, DD_USED_HEAD,
1415 -bp_get_dsize_sync(scn->scn_dp->dp_spa, bp),
1416 -BP_GET_PSIZE(bp), -BP_GET_UCSIZE(bp), tx);
1417 scn->scn_visited_this_txg++;
1418 return (0);
1419}

--- 7 unchanged lines hidden (view full) ---

1427 if (spa->spa_load_state != SPA_LOAD_NONE)
1428 return (B_FALSE);
1429 if (spa_shutting_down(spa))
1430 return (B_FALSE);
1431
1432 if (scn->scn_phys.scn_state == DSS_SCANNING)
1433 return (B_TRUE);
1434
1389 zio_nowait(zio_free_sync(scn->scn_zio_root, scn->scn_dp->dp_spa,
1390 dmu_tx_get_txg(tx), bp, 0));
1391 dsl_dir_diduse_space(tx->tx_pool->dp_free_dir, DD_USED_HEAD,
1392 -bp_get_dsize_sync(scn->scn_dp->dp_spa, bp),
1393 -BP_GET_PSIZE(bp), -BP_GET_UCSIZE(bp), tx);
1394 scn->scn_visited_this_txg++;
1395 return (0);
1396}

--- 7 unchanged lines hidden (view full) ---

1404 if (spa->spa_load_state != SPA_LOAD_NONE)
1405 return (B_FALSE);
1406 if (spa_shutting_down(spa))
1407 return (B_FALSE);
1408
1409 if (scn->scn_phys.scn_state == DSS_SCANNING)
1410 return (B_TRUE);
1411
1412 if (spa_feature_is_active(spa,
1413 &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
1414 return (B_TRUE);
1415 }
1435 if (spa_version(scn->scn_dp->dp_spa) >= SPA_VERSION_DEADLISTS) {
1436 (void) bpobj_space(&scn->scn_dp->dp_free_bpobj,
1437 &used, &comp, &uncomp);
1438 }
1439 return (used != 0);
1440}
1441
1442void

--- 30 unchanged lines hidden (view full) ---

1473
1474 /*
1475 * First process the free list. If we pause the free, don't do
1476 * any scanning. This ensures that there is no free list when
1477 * we are scanning, so the scan code doesn't have to worry about
1478 * traversing it.
1479 */
1480 if (spa_version(dp->dp_spa) >= SPA_VERSION_DEADLISTS) {
1416 if (spa_version(scn->scn_dp->dp_spa) >= SPA_VERSION_DEADLISTS) {
1417 (void) bpobj_space(&scn->scn_dp->dp_free_bpobj,
1418 &used, &comp, &uncomp);
1419 }
1420 return (used != 0);
1421}
1422
1423void

--- 30 unchanged lines hidden (view full) ---

1454
1455 /*
1456 * First process the free list. If we pause the free, don't do
1457 * any scanning. This ensures that there is no free list when
1458 * we are scanning, so the scan code doesn't have to worry about
1459 * traversing it.
1460 */
1461 if (spa_version(dp->dp_spa) >= SPA_VERSION_DEADLISTS) {
1462 scn->scn_is_bptree = B_FALSE;
1481 scn->scn_zio_root = zio_root(dp->dp_spa, NULL,
1482 NULL, ZIO_FLAG_MUSTSUCCEED);
1483 err = bpobj_iterate(&dp->dp_free_bpobj,
1463 scn->scn_zio_root = zio_root(dp->dp_spa, NULL,
1464 NULL, ZIO_FLAG_MUSTSUCCEED);
1465 err = bpobj_iterate(&dp->dp_free_bpobj,
1484 dsl_scan_free_cb, scn, tx);
1466 dsl_scan_free_block_cb, scn, tx);
1485 VERIFY3U(0, ==, zio_wait(scn->scn_zio_root));
1467 VERIFY3U(0, ==, zio_wait(scn->scn_zio_root));
1468
1469 if (err == 0 && spa_feature_is_active(spa,
1470 &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
1471 scn->scn_is_bptree = B_TRUE;
1472 scn->scn_zio_root = zio_root(dp->dp_spa, NULL,
1473 NULL, ZIO_FLAG_MUSTSUCCEED);
1474 err = bptree_iterate(dp->dp_meta_objset,
1475 dp->dp_bptree_obj, B_TRUE, dsl_scan_free_block_cb,
1476 scn, tx);
1477 VERIFY3U(0, ==, zio_wait(scn->scn_zio_root));
1478 if (err != 0)
1479 return;
1480
1481 /* disable async destroy feature */
1482 spa_feature_decr(spa,
1483 &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY], tx);
1484 ASSERT(!spa_feature_is_active(spa,
1485 &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY]));
1486 VERIFY3U(0, ==, zap_remove(dp->dp_meta_objset,
1487 DMU_POOL_DIRECTORY_OBJECT,
1488 DMU_POOL_BPTREE_OBJ, tx));
1489 VERIFY3U(0, ==, bptree_free(dp->dp_meta_objset,
1490 dp->dp_bptree_obj, tx));
1491 dp->dp_bptree_obj = 0;
1492 }
1486 if (scn->scn_visited_this_txg) {
1487 zfs_dbgmsg("freed %llu blocks in %llums from "
1493 if (scn->scn_visited_this_txg) {
1494 zfs_dbgmsg("freed %llu blocks in %llums from "
1488 "free_bpobj txg %llu",
1495 "free_bpobj/bptree txg %llu",
1489 (longlong_t)scn->scn_visited_this_txg,
1490 (longlong_t)
1491 (gethrtime() - scn->scn_sync_start_time) / MICROSEC,
1492 (longlong_t)tx->tx_txg);
1493 scn->scn_visited_this_txg = 0;
1494 /*
1495 * Re-sync the ddt so that we can further modify
1496 * it when doing bprewrite.

--- 98 unchanged lines hidden (view full) ---

1595 * incomplete stats in that case.
1596 */
1597 if (zab == NULL)
1598 return;
1599
1600 for (i = 0; i < 4; i++) {
1601 int l = (i < 2) ? BP_GET_LEVEL(bp) : DN_MAX_LEVELS;
1602 int t = (i & 1) ? BP_GET_TYPE(bp) : DMU_OT_TOTAL;
1496 (longlong_t)scn->scn_visited_this_txg,
1497 (longlong_t)
1498 (gethrtime() - scn->scn_sync_start_time) / MICROSEC,
1499 (longlong_t)tx->tx_txg);
1500 scn->scn_visited_this_txg = 0;
1501 /*
1502 * Re-sync the ddt so that we can further modify
1503 * it when doing bprewrite.

--- 98 unchanged lines hidden (view full) ---

1602 * incomplete stats in that case.
1603 */
1604 if (zab == NULL)
1605 return;
1606
1607 for (i = 0; i < 4; i++) {
1608 int l = (i < 2) ? BP_GET_LEVEL(bp) : DN_MAX_LEVELS;
1609 int t = (i & 1) ? BP_GET_TYPE(bp) : DMU_OT_TOTAL;
1610 if (t & DMU_OT_NEWTYPE)
1611 t = DMU_OT_OTHER;
1603 zfs_blkstat_t *zb = &zab->zab_type[l][t];
1604 int equal;
1605
1606 zb->zb_count++;
1607 zb->zb_asize += BP_GET_ASIZE(bp);
1608 zb->zb_lsize += BP_GET_LSIZE(bp);
1609 zb->zb_psize += BP_GET_PSIZE(bp);
1610 zb->zb_gangs += BP_COUNT_GANG(bp);

--- 44 unchanged lines hidden (view full) ---

1655{
1656 dsl_scan_t *scn = dp->dp_scan;
1657 size_t size = BP_GET_PSIZE(bp);
1658 spa_t *spa = dp->dp_spa;
1659 uint64_t phys_birth = BP_PHYSICAL_BIRTH(bp);
1660 boolean_t needs_io;
1661 int zio_flags = ZIO_FLAG_SCAN_THREAD | ZIO_FLAG_RAW | ZIO_FLAG_CANFAIL;
1662 int zio_priority;
1612 zfs_blkstat_t *zb = &zab->zab_type[l][t];
1613 int equal;
1614
1615 zb->zb_count++;
1616 zb->zb_asize += BP_GET_ASIZE(bp);
1617 zb->zb_lsize += BP_GET_LSIZE(bp);
1618 zb->zb_psize += BP_GET_PSIZE(bp);
1619 zb->zb_gangs += BP_COUNT_GANG(bp);

--- 44 unchanged lines hidden (view full) ---

1664{
1665 dsl_scan_t *scn = dp->dp_scan;
1666 size_t size = BP_GET_PSIZE(bp);
1667 spa_t *spa = dp->dp_spa;
1668 uint64_t phys_birth = BP_PHYSICAL_BIRTH(bp);
1669 boolean_t needs_io;
1670 int zio_flags = ZIO_FLAG_SCAN_THREAD | ZIO_FLAG_RAW | ZIO_FLAG_CANFAIL;
1671 int zio_priority;
1663 int scan_delay = 0;
1672 unsigned int scan_delay = 0;
1664
1665 if (phys_birth <= scn->scn_phys.scn_min_txg ||
1666 phys_birth >= scn->scn_phys.scn_max_txg)
1667 return (0);
1668
1669 count_block(dp->dp_blkstats, bp);
1670
1671 ASSERT(DSL_SCAN_IS_SCRUB_RESILVER(scn));

--- 40 unchanged lines hidden (view full) ---

1712 needs_io = vdev_dtl_contains(vd, DTL_PARTIAL,
1713 phys_birth, 1);
1714 }
1715 }
1716 }
1717
1718 if (needs_io && !zfs_no_scrub_io) {
1719 vdev_t *rvd = spa->spa_root_vdev;
1673
1674 if (phys_birth <= scn->scn_phys.scn_min_txg ||
1675 phys_birth >= scn->scn_phys.scn_max_txg)
1676 return (0);
1677
1678 count_block(dp->dp_blkstats, bp);
1679
1680 ASSERT(DSL_SCAN_IS_SCRUB_RESILVER(scn));

--- 40 unchanged lines hidden (view full) ---

1721 needs_io = vdev_dtl_contains(vd, DTL_PARTIAL,
1722 phys_birth, 1);
1723 }
1724 }
1725 }
1726
1727 if (needs_io && !zfs_no_scrub_io) {
1728 vdev_t *rvd = spa->spa_root_vdev;
1720 uint64_t maxinflight = rvd->vdev_children * zfs_top_maxinflight;
1729 uint64_t maxinflight = rvd->vdev_children *
1730 MAX(zfs_top_maxinflight, 1);
1721 void *data = zio_data_buf_alloc(size);
1722
1723 mutex_enter(&spa->spa_scrub_lock);
1724 while (spa->spa_scrub_inflight >= maxinflight)
1725 cv_wait(&spa->spa_scrub_io_cv, &spa->spa_scrub_lock);
1726 spa->spa_scrub_inflight++;
1727 mutex_exit(&spa->spa_scrub_lock);
1728
1729 /*
1730 * If we're seeing recent (zfs_scan_idle) "important" I/Os
1731 * then throttle our workload to limit the impact of a scan.
1732 */
1733 if (ddi_get_lbolt64() - spa->spa_last_io <= zfs_scan_idle)
1731 void *data = zio_data_buf_alloc(size);
1732
1733 mutex_enter(&spa->spa_scrub_lock);
1734 while (spa->spa_scrub_inflight >= maxinflight)
1735 cv_wait(&spa->spa_scrub_io_cv, &spa->spa_scrub_lock);
1736 spa->spa_scrub_inflight++;
1737 mutex_exit(&spa->spa_scrub_lock);
1738
1739 /*
1740 * If we're seeing recent (zfs_scan_idle) "important" I/Os
1741 * then throttle our workload to limit the impact of a scan.
1742 */
1743 if (ddi_get_lbolt64() - spa->spa_last_io <= zfs_scan_idle)
1734 delay(scan_delay);
1744 delay(MAX((int)scan_delay, 0));
1735
1736 zio_nowait(zio_read(NULL, spa, bp, data, size,
1737 dsl_scan_scrub_done, NULL, zio_priority,
1738 zio_flags, zb));
1739 }
1740
1741 /* do not relocate this block */
1742 return (0);

--- 23 unchanged lines hidden ---
1745
1746 zio_nowait(zio_read(NULL, spa, bp, data, size,
1747 dsl_scan_scrub_done, NULL, zio_priority,
1748 zio_flags, zb));
1749 }
1750
1751 /* do not relocate this block */
1752 return (0);

--- 23 unchanged lines hidden ---