dsl_pool.c revision e8397a2be4690aefe43370aae2d4214c6778327e
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * or http://www.opensolaris.org/os/licensing.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#pragma ident "%Z%%M% %I% %E% SMI"
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/dsl_pool.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/dsl_dataset.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/dsl_dir.h>
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens#include <sys/dsl_synctask.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/dmu_tx.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/dmu_objset.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/arc.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/zap.h>
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee#include <sys/zio.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/zfs_context.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/fs/zfs.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeeint zfs_no_write_throttle = 0;
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeeuint64_t zfs_write_limit_override = 0;
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockstatic int
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockdsl_pool_open_mos_dir(dsl_pool_t *dp, dsl_dir_t **ddp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint64_t obj;
fa9e4066f08beec538e775443c5be79dd423fcabahrens int err;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens err = zap_lookup(dp->dp_meta_objset,
fa9e4066f08beec538e775443c5be79dd423fcabahrens dp->dp_root_dir->dd_phys->dd_child_dir_zapobj,
fa9e4066f08beec538e775443c5be79dd423fcabahrens MOS_DIR_NAME, sizeof (obj), 1, &obj);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (err);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (dsl_dir_open_obj(dp, obj, MOS_DIR_NAME, dp, ddp));
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic dsl_pool_t *
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_open_impl(spa_t *spa, uint64_t txg)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_pool_t *dp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens blkptr_t *bp = spa_get_rootblkptr(spa);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee extern uint64_t zfs_write_limit_min;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens dp = kmem_zalloc(sizeof (dsl_pool_t), KM_SLEEP);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dp->dp_spa = spa;
fa9e4066f08beec538e775443c5be79dd423fcabahrens dp->dp_meta_rootbp = *bp;
5ad820458efd0fdb914baff9c1447c22b819fa23nd rw_init(&dp->dp_config_rwlock, NULL, RW_DEFAULT, NULL);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee dp->dp_write_limit = zfs_write_limit_min;
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_init(dp, txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_list_create(&dp->dp_dirty_datasets,
fa9e4066f08beec538e775443c5be79dd423fcabahrens offsetof(dsl_dataset_t, ds_dirty_link));
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_list_create(&dp->dp_dirty_dirs,
fa9e4066f08beec538e775443c5be79dd423fcabahrens offsetof(dsl_dir_t, dd_dirty_link));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens txg_list_create(&dp->dp_sync_tasks,
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens offsetof(dsl_sync_task_group_t, dstg_node));
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens list_create(&dp->dp_synced_datasets, sizeof (dsl_dataset_t),
fa9e4066f08beec538e775443c5be79dd423fcabahrens offsetof(dsl_dataset_t, ds_synced_link));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee mutex_init(&dp->dp_lock, NULL, MUTEX_DEFAULT, NULL);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (dp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockint
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockdsl_pool_open(spa_t *spa, uint64_t txg, dsl_pool_t **dpp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens int err;
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_pool_t *dp = dsl_pool_open_impl(spa, txg);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock objset_impl_t *osi;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens rw_enter(&dp->dp_config_rwlock, RW_READER);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock err = dmu_objset_open_impl(spa, NULL, &dp->dp_meta_rootbp, &osi);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock goto out;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock dp->dp_meta_objset = &osi->os;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
fa9e4066f08beec538e775443c5be79dd423fcabahrens err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
fa9e4066f08beec538e775443c5be79dd423fcabahrens DMU_POOL_ROOT_DATASET, sizeof (uint64_t), 1,
fa9e4066f08beec538e775443c5be79dd423fcabahrens &dp->dp_root_dir_obj);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock goto out;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock err = dsl_dir_open_obj(dp, dp->dp_root_dir_obj,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock NULL, dp, &dp->dp_root_dir);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock goto out;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock err = dsl_pool_open_mos_dir(dp, &dp->dp_mos_dir);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock goto out;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockout:
fa9e4066f08beec538e775443c5be79dd423fcabahrens rw_exit(&dp->dp_config_rwlock);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock dsl_pool_close(dp);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock else
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock *dpp = dp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (err);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_close(dsl_pool_t *dp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* drop our reference from dsl_pool_open() */
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (dp->dp_mos_dir)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock dsl_dir_close(dp->dp_mos_dir, dp);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (dp->dp_root_dir)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock dsl_dir_close(dp->dp_root_dir, dp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* undo the dmu_objset_open_impl(mos) from dsl_pool_open() */
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (dp->dp_meta_objset)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock dmu_objset_evict(NULL, dp->dp_meta_objset->os);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_list_destroy(&dp->dp_dirty_datasets);
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_list_destroy(&dp->dp_dirty_dirs);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens list_destroy(&dp->dp_synced_datasets);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee arc_flush(dp->dp_spa);
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_fini(dp);
5ad820458efd0fdb914baff9c1447c22b819fa23nd rw_destroy(&dp->dp_config_rwlock);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee mutex_destroy(&dp->dp_lock);
fa9e4066f08beec538e775443c5be79dd423fcabahrens kmem_free(dp, sizeof (dsl_pool_t));
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_t *
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_create(spa_t *spa, uint64_t txg)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens int err;
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_pool_t *dp = dsl_pool_open_impl(spa, txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_tx_t *tx = dmu_tx_create_assigned(dp, txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dp->dp_meta_objset = &dmu_objset_create_impl(spa,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee NULL, &dp->dp_meta_rootbp, DMU_OST_META, tx)->os;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create the pool directory */
fa9e4066f08beec538e775443c5be79dd423fcabahrens err = zap_create_claim(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
fa9e4066f08beec538e775443c5be79dd423fcabahrens DMU_OT_OBJECT_DIRECTORY, DMU_OT_NONE, 0, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT3U(err, ==, 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create and open the root dir */
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_dataset_create_root(dp, &dp->dp_root_dir_obj, tx);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock VERIFY(0 == dsl_dir_open_obj(dp, dp->dp_root_dir_obj,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock NULL, dp, &dp->dp_root_dir));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create and open the meta-objset dir */
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens (void) dsl_dir_create_sync(dp->dp_root_dir, MOS_DIR_NAME, tx);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock VERIFY(0 == dsl_pool_open_mos_dir(dp, &dp->dp_mos_dir));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_tx_commit(tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (dp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_sync(dsl_pool_t *dp, uint64_t txg)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee zio_t *zio;
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_tx_t *tx;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee dsl_dir_t *dd;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee dsl_dataset_t *ds;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee dsl_sync_task_group_t *dstg;
fa9e4066f08beec538e775443c5be79dd423fcabahrens objset_impl_t *mosi = dp->dp_meta_objset->os;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee int err;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens tx = dmu_tx_create_assigned(dp, txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee while (ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee if (!list_link_active(&ds->ds_synced_link))
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens list_insert_tail(&dp->dp_synced_datasets, ds);
af2c4821c0a23e873f2a63bca4145080aa2183e3maybee else
af2c4821c0a23e873f2a63bca4145080aa2183e3maybee dmu_buf_rele(ds->ds_dbuf, ds);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee dsl_dataset_sync(ds, zio, tx);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee }
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee err = zio_wait(zio);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee ASSERT(err == 0);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee while (dstg = txg_list_remove(&dp->dp_sync_tasks, txg))
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee dsl_sync_task_group_sync(dstg, tx);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee while (dd = txg_list_remove(&dp->dp_dirty_dirs, txg))
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee dsl_dir_sync(dd, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (list_head(&mosi->os_dirty_dnodes[txg & TXG_MASK]) != NULL ||
fa9e4066f08beec538e775443c5be79dd423fcabahrens list_head(&mosi->os_free_dnodes[txg & TXG_MASK]) != NULL) {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee dmu_objset_sync(mosi, zio, tx);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee err = zio_wait(zio);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee ASSERT(err == 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dprintf_bp(&dp->dp_meta_rootbp, "meta objset rootbp is %s", "");
fa9e4066f08beec538e775443c5be79dd423fcabahrens spa_set_rootblkptr(dp->dp_spa, &dp->dp_meta_rootbp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_tx_commit(tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_zil_clean(dsl_pool_t *dp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_dataset_t *ds;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens while (ds = list_head(&dp->dp_synced_datasets)) {
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens list_remove(&dp->dp_synced_datasets, ds);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT(ds->ds_user_ptr != NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens zil_clean(((objset_impl_t *)ds->ds_user_ptr)->os_zil);
af2c4821c0a23e873f2a63bca4145080aa2183e3maybee dmu_buf_rele(ds->ds_dbuf, ds);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee/*
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * TRUE if the current thread is the tx_sync_thread or if we
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * are being called from SPA context during pool initialization.
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee */
fa9e4066f08beec538e775443c5be79dd423fcabahrensint
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_sync_context(dsl_pool_t *dp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (curthread == dp->dp_tx.tx_sync_thread ||
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee spa_get_dsl(dp->dp_spa) == NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensuint64_t
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint64_t space, resv;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * Reserve about 1.6% (1/64), or at least 32MB, for allocation
fa9e4066f08beec538e775443c5be79dd423fcabahrens * efficiency.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * XXX The intent log is not accounted for, so it must fit
fa9e4066f08beec538e775443c5be79dd423fcabahrens * within this slop.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we're trying to assess whether it's OK to do a free,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * cut the reservation in half to allow forward progress
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (e.g. make it possible to rm(1) files from a full pool).
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
99653d4ee642c6528e88224f12409a5f23060994eschrock space = spa_get_dspace(dp->dp_spa);
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm resv = MAX(space >> 6, SPA_MINDEVSIZE >> 1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (netfree)
fa9e4066f08beec538e775443c5be79dd423fcabahrens resv >>= 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (space - resv);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeeint
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeedsl_pool_tempreserve_space(dsl_pool_t *dp, uint64_t space, dmu_tx_t *tx)
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee{
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee uint64_t reserved = 0;
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee uint64_t write_limit = (zfs_write_limit_override ?
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee zfs_write_limit_override : dp->dp_write_limit);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee if (zfs_no_write_throttle) {
c5904d138f3bdf0762dbf452a43d5a5c387ea6a8eschrock atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK],
c5904d138f3bdf0762dbf452a43d5a5c387ea6a8eschrock space);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee return (0);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee }
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee /*
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * Check to see if we have exceeded the maximum allowed IO for
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * this transaction group. We can do this without locks since
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * a little slop here is ok. Note that we do the reserved check
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * with only half the requested reserve: this is because the
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * reserve requests are worst-case, and we really don't want to
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * throttle based off of worst-case estimates.
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee */
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee if (write_limit > 0) {
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee reserved = dp->dp_space_towrite[tx->tx_txg & TXG_MASK]
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee + dp->dp_tempreserved[tx->tx_txg & TXG_MASK] / 2;
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee if (reserved && reserved > write_limit)
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee return (ERESTART);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee }
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], space);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee /*
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * If this transaction group is over 7/8ths capacity, delay
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * the caller 1 clock tick. This will slow down the "fill"
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * rate until the sync process can catch up with us.
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee */
e8397a2be4690aefe43370aae2d4214c6778327egw if (reserved && reserved > (write_limit - (write_limit >> 3)))
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee txg_delay(dp, tx->tx_txg, 1);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee return (0);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee}
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeevoid
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeedsl_pool_tempreserve_clear(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx)
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee{
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee ASSERT(dp->dp_tempreserved[tx->tx_txg & TXG_MASK] >= space);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], -space);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee}
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeevoid
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeedsl_pool_memory_pressure(dsl_pool_t *dp)
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee{
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee extern uint64_t zfs_write_limit_min;
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee uint64_t space_inuse = 0;
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee int i;
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee if (dp->dp_write_limit == zfs_write_limit_min)
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee return;
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee for (i = 0; i < TXG_SIZE; i++) {
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee space_inuse += dp->dp_space_towrite[i];
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee space_inuse += dp->dp_tempreserved[i];
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee }
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee dp->dp_write_limit = MAX(zfs_write_limit_min,
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee MIN(dp->dp_write_limit, space_inuse / 4));
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee}
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeevoid
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybeedsl_pool_willuse_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx)
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee{
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee if (space > 0) {
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee mutex_enter(&dp->dp_lock);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee dp->dp_space_towrite[tx->tx_txg & TXG_MASK] += space;
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee mutex_exit(&dp->dp_lock);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee }
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee}