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
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  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 /*
  23  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 #include <sys/zfs_context.h>
  27 #include <sys/spa.h>
  28 #include <sys/spa_impl.h>
  29 #include <sys/zio.h>
  30 #include <sys/ddt.h>
  31 #include <sys/zap.h>
  32 #include <sys/dmu_tx.h>
  33 #include <sys/arc.h>
  34 #include <sys/dsl_pool.h>
  35 #include <sys/zio_checksum.h>
  36 #include <sys/zio_compress.h>
  37 #include <sys/dsl_scan.h>
  38 
  39 /*
  40  * Enable/disable prefetching of dedup-ed blocks which are going to be freed.
  41  */
  42 int zfs_dedup_prefetch = 1;
  43 
 
 
1044                 if (nclass < oclass) {
1045                         dsl_scan_ddt_entry(dp->dp_scan,
1046                             ddt->ddt_checksum, dde, tx);
1047                 }
1048         }
1049 }
1050 
1051 static void
1052 ddt_sync_table(ddt_t *ddt, dmu_tx_t *tx, uint64_t txg)
1053 {
1054         spa_t *spa = ddt->ddt_spa;
1055         ddt_entry_t *dde;
1056         void *cookie = NULL;
1057 
1058         if (avl_numnodes(&ddt->ddt_tree) == 0)
1059                 return;
1060 
1061         ASSERT(spa->spa_uberblock.ub_version >= SPA_VERSION_DEDUP);
1062 
1063         if (spa->spa_ddt_stat_object == 0) {
1064                 spa->spa_ddt_stat_object = zap_create(ddt->ddt_os,
1065                     DMU_OT_DDT_STATS, DMU_OT_NONE, 0, tx);
1066                 VERIFY(zap_add(ddt->ddt_os, DMU_POOL_DIRECTORY_OBJECT,
1067                     DMU_POOL_DDT_STATS, sizeof (uint64_t), 1,
1068                     &spa->spa_ddt_stat_object, tx) == 0);
1069         }
1070 
1071         while ((dde = avl_destroy_nodes(&ddt->ddt_tree, &cookie)) != NULL) {
1072                 ddt_sync_entry(ddt, dde, tx, txg);
1073                 ddt_free(dde);
1074         }
1075 
1076         for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
1077                 uint64_t count = 0;
1078                 for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
1079                         if (ddt_object_exists(ddt, type, class)) {
1080                                 ddt_object_sync(ddt, type, class, tx);
1081                                 count += ddt_object_count(ddt, type, class);
1082                         }
1083                 }
1084                 for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
1085                         if (count == 0 && ddt_object_exists(ddt, type, class))
1086                                 ddt_object_destroy(ddt, type, class, tx);
1087                 }
1088         }
 
 | 
 
 
   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
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  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 /*
  23  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012 by Delphix. All rights reserved.
  25  */
  26 
  27 #include <sys/zfs_context.h>
  28 #include <sys/spa.h>
  29 #include <sys/spa_impl.h>
  30 #include <sys/zio.h>
  31 #include <sys/ddt.h>
  32 #include <sys/zap.h>
  33 #include <sys/dmu_tx.h>
  34 #include <sys/arc.h>
  35 #include <sys/dsl_pool.h>
  36 #include <sys/zio_checksum.h>
  37 #include <sys/zio_compress.h>
  38 #include <sys/dsl_scan.h>
  39 
  40 /*
  41  * Enable/disable prefetching of dedup-ed blocks which are going to be freed.
  42  */
  43 int zfs_dedup_prefetch = 1;
  44 
 
 
1045                 if (nclass < oclass) {
1046                         dsl_scan_ddt_entry(dp->dp_scan,
1047                             ddt->ddt_checksum, dde, tx);
1048                 }
1049         }
1050 }
1051 
1052 static void
1053 ddt_sync_table(ddt_t *ddt, dmu_tx_t *tx, uint64_t txg)
1054 {
1055         spa_t *spa = ddt->ddt_spa;
1056         ddt_entry_t *dde;
1057         void *cookie = NULL;
1058 
1059         if (avl_numnodes(&ddt->ddt_tree) == 0)
1060                 return;
1061 
1062         ASSERT(spa->spa_uberblock.ub_version >= SPA_VERSION_DEDUP);
1063 
1064         if (spa->spa_ddt_stat_object == 0) {
1065                 spa->spa_ddt_stat_object = zap_create_link(ddt->ddt_os,
1066                     DMU_OT_DDT_STATS, DMU_POOL_DIRECTORY_OBJECT,
1067                     DMU_POOL_DDT_STATS, tx);
1068         }
1069 
1070         while ((dde = avl_destroy_nodes(&ddt->ddt_tree, &cookie)) != NULL) {
1071                 ddt_sync_entry(ddt, dde, tx, txg);
1072                 ddt_free(dde);
1073         }
1074 
1075         for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
1076                 uint64_t count = 0;
1077                 for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
1078                         if (ddt_object_exists(ddt, type, class)) {
1079                                 ddt_object_sync(ddt, type, class, tx);
1080                                 count += ddt_object_count(ddt, type, class);
1081                         }
1082                 }
1083                 for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
1084                         if (count == 0 && ddt_object_exists(ddt, type, class))
1085                                 ddt_object_destroy(ddt, type, class, tx);
1086                 }
1087         }
 
 |