diff options
author | Matthew Ahrens <[email protected]> | 2013-08-28 20:01:20 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2013-12-06 09:32:43 -0800 |
commit | e8b96c6007bf97cdf34869c1ffbd0ce753873a3d (patch) | |
tree | 9ebee6183b2832766051ffa570ba66f45967ba77 /include/sys | |
parent | 384f8a09f8423d951bb81d9ca945e588de14f95f (diff) |
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <[email protected]>
Reviewed by: Adam Leventhal <[email protected]>
Reviewed by: Christopher Siden <[email protected]>
Reviewed by: Ned Bass <[email protected]>
Reviewed by: Brendan Gregg <[email protected]>
Approved by: Robert Mustacchi <[email protected]>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #1913
Diffstat (limited to 'include/sys')
-rw-r--r-- | include/sys/Makefile.am | 1 | ||||
-rw-r--r-- | include/sys/arc.h | 12 | ||||
-rw-r--r-- | include/sys/dbuf.h | 5 | ||||
-rw-r--r-- | include/sys/dmu.h | 1 | ||||
-rw-r--r-- | include/sys/dmu_tx.h | 23 | ||||
-rw-r--r-- | include/sys/dsl_dir.h | 2 | ||||
-rw-r--r-- | include/sys/dsl_pool.h | 31 | ||||
-rw-r--r-- | include/sys/sa_impl.h | 4 | ||||
-rw-r--r-- | include/sys/spa_impl.h | 4 | ||||
-rw-r--r-- | include/sys/txg.h | 3 | ||||
-rw-r--r-- | include/sys/txg_impl.h | 4 | ||||
-rw-r--r-- | include/sys/vdev_impl.h | 20 | ||||
-rw-r--r-- | include/sys/zfs_context.h | 14 | ||||
-rw-r--r-- | include/sys/zfs_delay.h | 41 | ||||
-rw-r--r-- | include/sys/zio.h | 68 |
15 files changed, 163 insertions, 70 deletions
diff --git a/include/sys/Makefile.am b/include/sys/Makefile.am index 34c715101..9d7756627 100644 --- a/include/sys/Makefile.am +++ b/include/sys/Makefile.am @@ -62,6 +62,7 @@ COMMON_H = \ $(top_srcdir)/include/sys/zfs_context.h \ $(top_srcdir)/include/sys/zfs_ctldir.h \ $(top_srcdir)/include/sys/zfs_debug.h \ + $(top_srcdir)/include/sys/zfs_delay.h \ $(top_srcdir)/include/sys/zfs_dir.h \ $(top_srcdir)/include/sys/zfs_fuid.h \ $(top_srcdir)/include/sys/zfs_rlock.h \ diff --git a/include/sys/arc.h b/include/sys/arc.h index 221946da3..9d68d3b43 100644 --- a/include/sys/arc.h +++ b/include/sys/arc.h @@ -145,12 +145,13 @@ int arc_referenced(arc_buf_t *buf); #endif int arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, - arc_done_func_t *done, void *private, int priority, int flags, + arc_done_func_t *done, void *private, zio_priority_t priority, int flags, uint32_t *arc_flags, const zbookmark_t *zb); zio_t *arc_write(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, arc_buf_t *buf, boolean_t l2arc, boolean_t l2arc_compress, - const zio_prop_t *zp, arc_done_func_t *ready, arc_done_func_t *done, - void *private, int priority, int zio_flags, const zbookmark_t *zb); + const zio_prop_t *zp, arc_done_func_t *ready, arc_done_func_t *physdone, + arc_done_func_t *done, void *private, zio_priority_t priority, + int zio_flags, const zbookmark_t *zb); arc_prune_t *arc_add_prune_callback(arc_prune_func_t *func, void *private); void arc_remove_prune_callback(arc_prune_t *p); @@ -179,11 +180,6 @@ void l2arc_fini(void); void l2arc_start(void); void l2arc_stop(void); -/* Global tunings */ -extern int zfs_write_limit_shift; -extern unsigned long zfs_write_limit_max; -extern kmutex_t zfs_write_limit_lock; - #ifndef _KERNEL extern boolean_t arc_watch; #endif diff --git a/include/sys/dbuf.h b/include/sys/dbuf.h index 3140665ab..23b919bf7 100644 --- a/include/sys/dbuf.h +++ b/include/sys/dbuf.h @@ -112,6 +112,9 @@ typedef struct dbuf_dirty_record { /* pointer to parent dirty record */ struct dbuf_dirty_record *dr_parent; + /* How much space was changed to dsl_pool_dirty_space() for this? */ + unsigned int dr_accounted; + union dirty_types { struct dirty_indirect { @@ -252,7 +255,7 @@ dmu_buf_impl_t *dbuf_hold_level(struct dnode *dn, int level, uint64_t blkid, int dbuf_hold_impl(struct dnode *dn, uint8_t level, uint64_t blkid, int create, void *tag, dmu_buf_impl_t **dbp); -void dbuf_prefetch(struct dnode *dn, uint64_t blkid); +void dbuf_prefetch(struct dnode *dn, uint64_t blkid, zio_priority_t prio); void dbuf_add_ref(dmu_buf_impl_t *db, void *tag); uint64_t dbuf_refcount(dmu_buf_impl_t *db); diff --git a/include/sys/dmu.h b/include/sys/dmu.h index 5485131df..1314c1eed 100644 --- a/include/sys/dmu.h +++ b/include/sys/dmu.h @@ -218,6 +218,7 @@ typedef enum dmu_object_type { typedef enum txg_how { TXG_WAIT = 1, TXG_NOWAIT, + TXG_WAITED, } txg_how_t; void byteswap_uint64_array(void *buf, size_t size); diff --git a/include/sys/dmu_tx.h b/include/sys/dmu_tx.h index 48a507e34..f6a62af4b 100644 --- a/include/sys/dmu_tx.h +++ b/include/sys/dmu_tx.h @@ -23,7 +23,7 @@ * Use is subject to license terms. */ /* - * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2013 by Delphix. All rights reserved. */ #ifndef _SYS_DMU_TX_H @@ -60,8 +60,22 @@ struct dmu_tx { txg_handle_t tx_txgh; void *tx_tempreserve_cookie; struct dmu_tx_hold *tx_needassign_txh; - list_t tx_callbacks; /* list of dmu_tx_callback_t on this dmu_tx */ - uint8_t tx_anyobj; + + /* 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; + + /* time this transaction was created */ + hrtime_t tx_start; + + /* need to wait for sufficient dirty space */ + boolean_t tx_wait_dirty; + int tx_err; #ifdef DEBUG_DMU_TX uint64_t tx_space_towrite; @@ -121,7 +135,8 @@ typedef struct dmu_tx_stats { kstat_named_t dmu_tx_memory_reclaim; kstat_named_t dmu_tx_memory_inflight; kstat_named_t dmu_tx_dirty_throttle; - kstat_named_t dmu_tx_write_limit; + 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; diff --git a/include/sys/dsl_dir.h b/include/sys/dsl_dir.h index 2477e89af..d69d47696 100644 --- a/include/sys/dsl_dir.h +++ b/include/sys/dsl_dir.h @@ -20,7 +20,7 @@ */ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2013 by Delphix. All rights reserved. */ #ifndef _SYS_DSL_DIR_H diff --git a/include/sys/dsl_pool.h b/include/sys/dsl_pool.h index 0f9471486..d5bad8dc1 100644 --- a/include/sys/dsl_pool.h +++ b/include/sys/dsl_pool.h @@ -20,7 +20,7 @@ */ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2013 by Delphix. All rights reserved. */ #ifndef _SYS_DSL_POOL_H @@ -51,6 +51,14 @@ struct dsl_pool; struct dmu_tx; struct dsl_scan; +extern unsigned long zfs_dirty_data_max; +extern unsigned long zfs_dirty_data_max_max; +extern unsigned long zfs_dirty_data_sync; +extern int zfs_dirty_data_max_percent; +extern int zfs_dirty_data_max_max_percent; +extern int zfs_delay_min_dirty_percent; +extern unsigned long zfs_delay_scale; + /* These macros are for indexing into the zfs_all_blkstats_t. */ #define DMU_OT_DEFERRED DMU_OT_NONE #define DMU_OT_OTHER DMU_OT_NUMTYPES /* place holder for DMU_OT() types */ @@ -85,9 +93,6 @@ typedef struct dsl_pool { /* No lock needed - sync context only */ blkptr_t dp_meta_rootbp; - hrtime_t dp_read_overhead; - uint64_t dp_throughput; /* bytes per millisec */ - uint64_t dp_write_limit; uint64_t dp_tmp_userrefs_obj; bpobj_t dp_free_bpobj; uint64_t dp_bptree_obj; @@ -97,12 +102,19 @@ typedef struct dsl_pool { /* Uses dp_lock */ kmutex_t dp_lock; - uint64_t dp_space_towrite[TXG_SIZE]; - uint64_t dp_tempreserved[TXG_SIZE]; + kcondvar_t dp_spaceavail_cv; + uint64_t dp_dirty_pertxg[TXG_SIZE]; + uint64_t dp_dirty_total; uint64_t dp_mos_used_delta; uint64_t dp_mos_compressed_delta; uint64_t dp_mos_uncompressed_delta; + /* + * Time of most recently scheduled (furthest in the future) + * wakeup for delayed transactions. + */ + hrtime_t dp_last_wakeup; + /* Has its own locking */ tx_state_t dp_tx; txg_list_t dp_dirty_datasets; @@ -131,10 +143,8 @@ void dsl_pool_sync_done(dsl_pool_t *dp, uint64_t txg); int dsl_pool_sync_context(dsl_pool_t *dp); uint64_t dsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree); uint64_t dsl_pool_adjustedfree(dsl_pool_t *dp, boolean_t netfree); -int dsl_pool_tempreserve_space(dsl_pool_t *dp, uint64_t space, dmu_tx_t *tx); -void dsl_pool_tempreserve_clear(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx); -void dsl_pool_memory_pressure(dsl_pool_t *dp); -void dsl_pool_willuse_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx); +void dsl_pool_dirty_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx); +void dsl_pool_undirty_space(dsl_pool_t *dp, int64_t space, uint64_t txg); void dsl_free(dsl_pool_t *dp, uint64_t txg, const blkptr_t *bpp); void dsl_free_sync(zio_t *pio, dsl_pool_t *dp, uint64_t txg, const blkptr_t *bpp); @@ -143,6 +153,7 @@ void dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx); void dsl_pool_upgrade_dir_clones(dsl_pool_t *dp, dmu_tx_t *tx); void dsl_pool_mos_diduse_space(dsl_pool_t *dp, int64_t used, int64_t comp, int64_t uncomp); +boolean_t dsl_pool_need_dirty_delay(dsl_pool_t *dp); void dsl_pool_config_enter(dsl_pool_t *dp, void *tag); void dsl_pool_config_exit(dsl_pool_t *dp, void *tag); boolean_t dsl_pool_config_held(dsl_pool_t *dp); diff --git a/include/sys/sa_impl.h b/include/sys/sa_impl.h index 582bd76f0..fcbd8eb34 100644 --- a/include/sys/sa_impl.h +++ b/include/sys/sa_impl.h @@ -20,7 +20,7 @@ */ /* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2013 by Delphix. All rights reserved. */ #ifndef _SYS_SA_IMPL_H @@ -153,7 +153,7 @@ struct sa_os { * * The header has a fixed portion with a variable number * of "lengths" depending on the number of variable sized - * attribues which are determined by the "layout number" + * attributes which are determined by the "layout number" */ #define SA_MAGIC 0x2F505A /* ZFS SA */ diff --git a/include/sys/spa_impl.h b/include/sys/spa_impl.h index 2e65ce845..55515c1fc 100644 --- a/include/sys/spa_impl.h +++ b/include/sys/spa_impl.h @@ -20,7 +20,7 @@ */ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2013 by Delphix. All rights reserved. * Copyright 2011 Nexenta Systems, Inc. All rights reserved. */ @@ -234,7 +234,7 @@ struct spa { uint64_t spa_feat_desc_obj; /* Feature descriptions */ taskqid_t spa_deadman_tqid; /* Task id */ uint64_t spa_deadman_calls; /* number of deadman calls */ - uint64_t spa_sync_starttime; /* starting time fo spa_sync */ + hrtime_t spa_sync_starttime; /* starting time of spa_sync */ uint64_t spa_deadman_synctime; /* deadman expiration timer */ spa_stats_t spa_stats; /* assorted spa statistics */ diff --git a/include/sys/txg.h b/include/sys/txg.h index 9e547819b..1bb6bac91 100644 --- a/include/sys/txg.h +++ b/include/sys/txg.h @@ -23,7 +23,7 @@ * Use is subject to license terms. */ /* - * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2013 by Delphix. All rights reserved. */ #ifndef _SYS_TXG_H @@ -76,6 +76,7 @@ extern void txg_register_callbacks(txg_handle_t *txghp, list_t *tx_callbacks); extern void txg_delay(struct dsl_pool *dp, uint64_t txg, hrtime_t delta, hrtime_t resolution); +extern void txg_kick(struct dsl_pool *dp); /* * Wait until the given transaction group has finished syncing. diff --git a/include/sys/txg_impl.h b/include/sys/txg_impl.h index 8a0977f1f..e583d61ea 100644 --- a/include/sys/txg_impl.h +++ b/include/sys/txg_impl.h @@ -18,6 +18,7 @@ * * CDDL HEADER END */ + /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -89,11 +90,14 @@ struct tx_cpu { typedef struct tx_state { tx_cpu_t *tx_cpu; /* protects access to tx_open_txg */ kmutex_t tx_sync_lock; /* protects the rest of this struct */ + uint64_t tx_open_txg; /* currently open txg id */ uint64_t tx_quiesced_txg; /* quiesced txg waiting for sync */ uint64_t tx_syncing_txg; /* currently syncing txg id */ uint64_t tx_synced_txg; /* last synced txg id */ + hrtime_t tx_open_time; /* start time of tx_open_txg */ + uint64_t tx_sync_txg_waiting; /* txg we're waiting to sync */ uint64_t tx_quiesce_txg_waiting; /* txg we're waiting to open */ diff --git a/include/sys/vdev_impl.h b/include/sys/vdev_impl.h index 45a2b5e48..4b465d295 100644 --- a/include/sys/vdev_impl.h +++ b/include/sys/vdev_impl.h @@ -100,12 +100,22 @@ struct vdev_cache { kmutex_t vc_lock; }; +typedef struct vdev_queue_class { + uint32_t vqc_active; + + /* + * Sorted by offset or timestamp, depending on if the queue is + * LBA-ordered vs FIFO. + */ + avl_tree_t vqc_queued_tree; +} vdev_queue_class_t; + struct vdev_queue { - avl_tree_t vq_deadline_tree; - avl_tree_t vq_read_tree; - avl_tree_t vq_write_tree; - avl_tree_t vq_pending_tree; - hrtime_t vq_io_complete_ts; + vdev_t *vq_vdev; + vdev_queue_class_t vq_class[ZIO_PRIORITY_NUM_QUEUEABLE]; + avl_tree_t vq_active_tree; + uint64_t vq_last_offset; + hrtime_t vq_io_complete_ts; /* time last i/o completed */ hrtime_t vq_io_delta_ts; list_t vq_io_list; kmutex_t vq_lock; diff --git a/include/sys/zfs_context.h b/include/sys/zfs_context.h index 28a1306aa..3fd9e1be0 100644 --- a/include/sys/zfs_context.h +++ b/include/sys/zfs_context.h @@ -25,7 +25,7 @@ /* * Copyright 2011 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2012, Joyent, Inc. All rights reserved. - * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2013 by Delphix. All rights reserved. */ #ifndef _SYS_ZFS_CONTEXT_H @@ -61,6 +61,7 @@ #include <sys/zone.h> #include <sys/sdt.h> #include <sys/zfs_debug.h> +#include <sys/zfs_delay.h> #include <sys/fm/fs/zfs.h> #include <sys/sunddi.h> #include <sys/ctype.h> @@ -224,6 +225,8 @@ typedef void (*thread_func_t)(void *); typedef void (*thread_func_arg_t)(void *); typedef pthread_t kt_did_t; +#define kpreempt(x) ((void)0) + typedef struct kthread { kt_did_t t_tid; thread_func_t t_func; @@ -708,6 +711,15 @@ void ksiddomain_rele(ksiddomain_t *); #define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) \ sysevent_post_event(_c, _d, _b, "libzpool", _e, _f) +#define zfs_sleep_until(wakeup) \ + do { \ + hrtime_t delta = wakeup - gethrtime(); \ + struct timespec ts; \ + ts.tv_sec = delta / NANOSEC; \ + ts.tv_nsec = delta % NANOSEC; \ + (void) nanosleep(&ts, NULL); \ + } while (0) + #endif /* _KERNEL */ #endif /* _SYS_ZFS_CONTEXT_H */ diff --git a/include/sys/zfs_delay.h b/include/sys/zfs_delay.h new file mode 100644 index 000000000..4c7663117 --- /dev/null +++ b/include/sys/zfs_delay.h @@ -0,0 +1,41 @@ +/* + * 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 + */ + +#ifndef _SYS_FS_ZFS_DELAY_H +#define _SYS_FS_ZFS_DELAY_H + +#include <linux/delay_compat.h> + +/* + * Generic wrapper to sleep until a given time. + */ +#define zfs_sleep_until(wakeup) \ + do { \ + hrtime_t delta = wakeup - gethrtime(); \ + \ + if (delta > 0) { \ + unsigned long delta_us; \ + delta_us = delta / (NANOSEC / MICROSEC); \ + usleep_range(delta_us, delta_us + 100); \ + } \ + } while (0) + +#endif /* _SYS_FS_ZFS_DELAY_H */ diff --git a/include/sys/zio.h b/include/sys/zio.h index b505ca1e6..cfb256f0f 100644 --- a/include/sys/zio.h +++ b/include/sys/zio.h @@ -22,7 +22,7 @@ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2011 Nexenta Systems, Inc. All rights reserved. - * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2013 by Delphix. All rights reserved. * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. */ @@ -130,19 +130,16 @@ enum zio_compress { #define ZIO_FAILURE_MODE_CONTINUE 1 #define ZIO_FAILURE_MODE_PANIC 2 -#define ZIO_PRIORITY_NOW (zio_priority_table[0]) -#define ZIO_PRIORITY_SYNC_READ (zio_priority_table[1]) -#define ZIO_PRIORITY_SYNC_WRITE (zio_priority_table[2]) -#define ZIO_PRIORITY_LOG_WRITE (zio_priority_table[3]) -#define ZIO_PRIORITY_CACHE_FILL (zio_priority_table[4]) -#define ZIO_PRIORITY_AGG (zio_priority_table[5]) -#define ZIO_PRIORITY_FREE (zio_priority_table[6]) -#define ZIO_PRIORITY_ASYNC_WRITE (zio_priority_table[7]) -#define ZIO_PRIORITY_ASYNC_READ (zio_priority_table[8]) -#define ZIO_PRIORITY_RESILVER (zio_priority_table[9]) -#define ZIO_PRIORITY_SCRUB (zio_priority_table[10]) -#define ZIO_PRIORITY_DDT_PREFETCH (zio_priority_table[11]) -#define ZIO_PRIORITY_TABLE_SIZE 12 +typedef enum zio_priority { + ZIO_PRIORITY_SYNC_READ, + ZIO_PRIORITY_SYNC_WRITE, /* ZIL */ + ZIO_PRIORITY_ASYNC_READ, /* prefetch */ + ZIO_PRIORITY_ASYNC_WRITE, /* spa_sync() */ + ZIO_PRIORITY_SCRUB, /* asynchronous scrub/resilver reads */ + ZIO_PRIORITY_NUM_QUEUEABLE, + + ZIO_PRIORITY_NOW /* non-queued i/os (e.g. free) */ +} zio_priority_t; #define ZIO_PIPELINE_CONTINUE 0x100 #define ZIO_PIPELINE_STOP 0x101 @@ -198,7 +195,8 @@ enum zio_flag { ZIO_FLAG_GODFATHER = 1 << 24, ZIO_FLAG_NOPWRITE = 1 << 25, ZIO_FLAG_REEXECUTED = 1 << 26, - ZIO_FLAG_FASTWRITE = 1 << 27 + ZIO_FLAG_DELEGATED = 1 << 27, + ZIO_FLAG_FASTWRITE = 1 << 28 }; #define ZIO_FLAG_MUSTSUCCEED 0 @@ -238,8 +236,7 @@ enum zio_wait_type { typedef void zio_done_func_t(zio_t *zio); -extern uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE]; -extern char *zio_type_name[ZIO_TYPES]; +extern const char *zio_type_name[ZIO_TYPES]; /* * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely @@ -381,7 +378,7 @@ struct zio { zio_type_t io_type; enum zio_child io_child_type; int io_cmd; - uint8_t io_priority; + zio_priority_t io_priority; uint8_t io_reexecute; uint8_t io_state[ZIO_WAIT_TYPES]; uint64_t io_txg; @@ -396,7 +393,8 @@ struct zio { zio_transform_t *io_transform_stack; /* Callback info */ - zio_done_func_t *io_ready; + zio_done_func_t *io_ready; + zio_done_func_t *io_physdone; zio_done_func_t *io_done; void *io_private; int64_t io_prev_space_delta; /* DMU private */ @@ -414,13 +412,10 @@ struct zio { const zio_vsd_ops_t *io_vsd_ops; uint64_t io_offset; - uint64_t io_deadline; /* expires at timestamp + deadline */ hrtime_t io_timestamp; /* submitted at */ hrtime_t io_delta; /* vdev queue service delta */ uint64_t io_delay; /* vdev disk service delta (ticks) */ - avl_node_t io_offset_node; - avl_node_t io_deadline_node; - avl_tree_t *io_vdev_tree; + avl_node_t io_queue_node; /* Internal pipeline state */ enum zio_flag io_flags; @@ -433,6 +428,7 @@ struct zio { int io_child_error[ZIO_CHILD_TYPES]; uint64_t io_children[ZIO_CHILD_TYPES][ZIO_WAIT_TYPES]; uint64_t io_child_count; + uint64_t io_phys_children; uint64_t io_parent_count; uint64_t *io_stall; zio_t *io_gang_leader; @@ -458,16 +454,17 @@ extern zio_t *zio_root(spa_t *spa, extern zio_t *zio_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, void *data, uint64_t size, zio_done_func_t *done, void *private, - int priority, enum zio_flag flags, const zbookmark_t *zb); + zio_priority_t priority, enum zio_flag flags, const zbookmark_t *zb); extern zio_t *zio_write(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, void *data, uint64_t size, const zio_prop_t *zp, - zio_done_func_t *ready, zio_done_func_t *done, void *private, - int priority, enum zio_flag flags, const zbookmark_t *zb); + zio_done_func_t *ready, zio_done_func_t *physdone, zio_done_func_t *done, + void *private, + zio_priority_t priority, enum zio_flag flags, const zbookmark_t *zb); extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, void *data, uint64_t size, zio_done_func_t *done, void *private, - int priority, enum zio_flag flags, zbookmark_t *zb); + zio_priority_t priority, enum zio_flag flags, zbookmark_t *zb); extern void zio_write_override(zio_t *zio, blkptr_t *bp, int copies, boolean_t nopwrite); @@ -479,17 +476,17 @@ extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, zio_done_func_t *done, void *private, enum zio_flag flags); extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd, - zio_done_func_t *done, void *private, int priority, enum zio_flag flags); + zio_done_func_t *done, void *private, enum zio_flag flags); extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size, void *data, int checksum, - zio_done_func_t *done, void *private, int priority, enum zio_flag flags, - boolean_t labels); + zio_done_func_t *done, void *private, zio_priority_t priority, + enum zio_flag flags, boolean_t labels); extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size, void *data, int checksum, - zio_done_func_t *done, void *private, int priority, enum zio_flag flags, - boolean_t labels); + zio_done_func_t *done, void *private, zio_priority_t priority, + enum zio_flag flags, boolean_t labels); extern zio_t *zio_free_sync(zio_t *pio, spa_t *spa, uint64_t txg, const blkptr_t *bp, enum zio_flag flags); @@ -520,11 +517,12 @@ extern void zio_vdev_free(void *buf); extern void zio_resubmit_stage_async(void *); extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd, - uint64_t offset, void *data, uint64_t size, int type, int priority, - enum zio_flag flags, zio_done_func_t *done, void *private); + uint64_t offset, void *data, uint64_t size, int type, + zio_priority_t priority, enum zio_flag flags, + zio_done_func_t *done, void *private); extern zio_t *zio_vdev_delegated_io(vdev_t *vd, uint64_t offset, - void *data, uint64_t size, int type, int priority, + void *data, uint64_t size, int type, zio_priority_t priority, enum zio_flag flags, zio_done_func_t *done, void *private); extern void zio_vdev_io_bypass(zio_t *zio); |