mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 18:11:00 +03:00
3ec3bc2167
Reviewed by: Steve Gonczi <steve.gonczi@delphix.com> Reviewed by: George Wilson <george.wilson@delphix.com> Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com> Ported-by: Brian Behlendorf <behlendorf1@llnl.gov> Background information: This assertion about tx_space_* verifies that we are not dirtying more stuff than we thought we would. We “need” to know how much we will dirty so that we can check if we should fail this transaction with ENOSPC/EDQUOT, in dmu_tx_assign(). While the transaction is open (i.e. between dmu_tx_assign() and dmu_tx_commit() — typically less than a millisecond), we call dbuf_dirty() on the exact blocks that will be modified. Once this happens, the temporary accounting in tx_space_* is unnecessary, because we know exactly what blocks are newly dirtied; we call dnode_willuse_space() to track this more exact accounting. The fundamental problem causing this bug is that dmu_tx_hold_*() relies on the current state in the DMU (e.g. dn_nlevels) to predict how much will be dirtied by this transaction, but this state can change before we actually perform the transaction (i.e. call dbuf_dirty()). This bug will be fixed by removing the assertion that the tx_space_* accounting is perfectly accurate (i.e. we never dirty more than was predicted by dmu_tx_hold_*()). By removing the requirement that this accounting be perfectly accurate, we can also vastly simplify it, e.g. removing most of the logic in dmu_tx_count_*(). The new tx space accounting will be very approximate, and may be more or less than what is actually dirtied. It will still be used to determine if this transaction will put us over quota. Transactions that are marked by dmu_tx_mark_netfree() will be excepted from this check. We won’t make an attempt to determine how much space will be freed by the transaction — this was rarely accurate enough to determine if a transaction should be permitted when we are over quota, which is why dmu_tx_mark_netfree() was introduced in 2014. We also won’t attempt to give “credit” when overwriting existing blocks, if those blocks may be freed. This allows us to remove the do_free_accounting logic in dbuf_dirty(), and associated routines. This logic attempted to predict what will be on disk when this txg syncs, to know if the overwritten block will be freed (i.e. exists, and has no snapshots). OpenZFS-issue: https://www.illumos.org/issues/7793 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/3704e0a Upstream bugs: DLPX-32883a Closes #5804 Porting notes: - DNODE_SIZE replaced with DNODE_MIN_SIZE in dmu_tx_count_dnode(), Using the default dnode size would be slightly better. - DEBUG_DMU_TX wrappers and configure option removed. - Resolved _by_dnode() conflicts these changes have not yet been applied to OpenZFS.
181 lines
4.5 KiB
C
181 lines
4.5 KiB
C
/*
|
|
* CDDL HEADER START
|
|
*
|
|
* The contents of this file are subject to the terms of the
|
|
* Common Development and Distribution License (the "License").
|
|
* You may not use this file except in compliance with the License.
|
|
*
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
* See the License for the specific language governing permissions
|
|
* and limitations under the License.
|
|
*
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
*
|
|
* CDDL HEADER END
|
|
*/
|
|
/*
|
|
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
|
|
* Use is subject to license terms.
|
|
*/
|
|
/*
|
|
* Copyright (c) 2012, 2016 by Delphix. All rights reserved.
|
|
*/
|
|
|
|
#ifndef _SYS_DMU_TX_H
|
|
#define _SYS_DMU_TX_H
|
|
|
|
#include <sys/inttypes.h>
|
|
#include <sys/dmu.h>
|
|
#include <sys/txg.h>
|
|
#include <sys/refcount.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct dmu_buf_impl;
|
|
struct dmu_tx_hold;
|
|
struct dnode_link;
|
|
struct dsl_pool;
|
|
struct dnode;
|
|
struct dsl_dir;
|
|
|
|
struct dmu_tx {
|
|
/*
|
|
* No synchronization is needed because a tx can only be handled
|
|
* by one thread.
|
|
*/
|
|
list_t tx_holds; /* list of dmu_tx_hold_t */
|
|
objset_t *tx_objset;
|
|
struct dsl_dir *tx_dir;
|
|
struct dsl_pool *tx_pool;
|
|
uint64_t tx_txg;
|
|
uint64_t tx_lastsnap_txg;
|
|
uint64_t tx_lasttried_txg;
|
|
txg_handle_t tx_txgh;
|
|
void *tx_tempreserve_cookie;
|
|
struct dmu_tx_hold *tx_needassign_txh;
|
|
|
|
/* list of dmu_tx_callback_t on this dmu_tx */
|
|
list_t tx_callbacks;
|
|
|
|
/* placeholder for syncing context, doesn't need specific holds */
|
|
boolean_t tx_anyobj;
|
|
|
|
/* has this transaction already been delayed? */
|
|
boolean_t tx_waited;
|
|
|
|
/* transaction is marked as being a "net free" of space */
|
|
boolean_t tx_netfree;
|
|
|
|
/* time this transaction was created */
|
|
hrtime_t tx_start;
|
|
|
|
/* need to wait for sufficient dirty space */
|
|
boolean_t tx_wait_dirty;
|
|
|
|
int tx_err;
|
|
};
|
|
|
|
enum dmu_tx_hold_type {
|
|
THT_NEWOBJECT,
|
|
THT_WRITE,
|
|
THT_BONUS,
|
|
THT_FREE,
|
|
THT_ZAP,
|
|
THT_SPACE,
|
|
THT_SPILL,
|
|
THT_NUMTYPES
|
|
};
|
|
|
|
typedef struct dmu_tx_hold {
|
|
dmu_tx_t *txh_tx;
|
|
list_node_t txh_node;
|
|
struct dnode *txh_dnode;
|
|
refcount_t txh_space_towrite;
|
|
refcount_t txh_memory_tohold;
|
|
enum dmu_tx_hold_type txh_type;
|
|
uint64_t txh_arg1;
|
|
uint64_t txh_arg2;
|
|
} dmu_tx_hold_t;
|
|
|
|
typedef struct dmu_tx_callback {
|
|
list_node_t dcb_node; /* linked to tx_callbacks list */
|
|
dmu_tx_callback_func_t *dcb_func; /* caller function pointer */
|
|
void *dcb_data; /* caller private data */
|
|
} dmu_tx_callback_t;
|
|
|
|
/*
|
|
* Used for dmu tx kstat.
|
|
*/
|
|
typedef struct dmu_tx_stats {
|
|
kstat_named_t dmu_tx_assigned;
|
|
kstat_named_t dmu_tx_delay;
|
|
kstat_named_t dmu_tx_error;
|
|
kstat_named_t dmu_tx_suspended;
|
|
kstat_named_t dmu_tx_group;
|
|
kstat_named_t dmu_tx_memory_reserve;
|
|
kstat_named_t dmu_tx_memory_reclaim;
|
|
kstat_named_t dmu_tx_dirty_throttle;
|
|
kstat_named_t dmu_tx_dirty_delay;
|
|
kstat_named_t dmu_tx_dirty_over_max;
|
|
kstat_named_t dmu_tx_quota;
|
|
} dmu_tx_stats_t;
|
|
|
|
extern dmu_tx_stats_t dmu_tx_stats;
|
|
|
|
#define DMU_TX_STAT_INCR(stat, val) \
|
|
atomic_add_64(&dmu_tx_stats.stat.value.ui64, (val));
|
|
#define DMU_TX_STAT_BUMP(stat) \
|
|
DMU_TX_STAT_INCR(stat, 1);
|
|
|
|
/*
|
|
* These routines are defined in dmu.h, and are called by the user.
|
|
*/
|
|
dmu_tx_t *dmu_tx_create(objset_t *dd);
|
|
int dmu_tx_assign(dmu_tx_t *tx, txg_how_t txg_how);
|
|
void dmu_tx_commit(dmu_tx_t *tx);
|
|
void dmu_tx_abort(dmu_tx_t *tx);
|
|
uint64_t dmu_tx_get_txg(dmu_tx_t *tx);
|
|
struct dsl_pool *dmu_tx_pool(dmu_tx_t *tx);
|
|
void dmu_tx_wait(dmu_tx_t *tx);
|
|
|
|
void dmu_tx_callback_register(dmu_tx_t *tx, dmu_tx_callback_func_t *dcb_func,
|
|
void *dcb_data);
|
|
void dmu_tx_do_callbacks(list_t *cb_list, int error);
|
|
|
|
/*
|
|
* These routines are defined in dmu_spa.h, and are called by the SPA.
|
|
*/
|
|
extern dmu_tx_t *dmu_tx_create_assigned(struct dsl_pool *dp, uint64_t txg);
|
|
|
|
/*
|
|
* These routines are only called by the DMU.
|
|
*/
|
|
dmu_tx_t *dmu_tx_create_dd(dsl_dir_t *dd);
|
|
int dmu_tx_is_syncing(dmu_tx_t *tx);
|
|
int dmu_tx_private_ok(dmu_tx_t *tx);
|
|
void dmu_tx_add_new_object(dmu_tx_t *tx, dnode_t *dn);
|
|
void dmu_tx_dirty_buf(dmu_tx_t *tx, struct dmu_buf_impl *db);
|
|
void dmu_tx_hold_space(dmu_tx_t *tx, uint64_t space);
|
|
|
|
#ifdef ZFS_DEBUG
|
|
#define DMU_TX_DIRTY_BUF(tx, db) dmu_tx_dirty_buf(tx, db)
|
|
#else
|
|
#define DMU_TX_DIRTY_BUF(tx, db)
|
|
#endif
|
|
|
|
void dmu_tx_init(void);
|
|
void dmu_tx_fini(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _SYS_DMU_TX_H */
|