2010-08-26 18:50:56 +00:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License, Version 1.0 only
|
|
|
|
* (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 2007 Sun Microsystems, Inc. All rights reserved.
|
|
|
|
* Use is subject to license terms.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include_next <assert.h>
|
|
|
|
|
|
|
|
#ifndef _LIBSPL_ASSERT_H
|
2013-11-01 19:26:11 +00:00
|
|
|
#define _LIBSPL_ASSERT_H
|
2010-08-26 18:50:56 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2017-07-05 17:39:13 +00:00
|
|
|
#include <stdarg.h>
|
2010-08-26 18:50:56 +00:00
|
|
|
|
2020-07-04 22:24:13 +00:00
|
|
|
/* Set to non-zero to avoid abort()ing on an assertion failure */
|
2021-06-03 17:04:13 +00:00
|
|
|
extern int libspl_assert_ok;
|
2020-07-04 22:24:13 +00:00
|
|
|
|
|
|
|
/* printf version of libspl_assert */
|
|
|
|
extern void libspl_assertf(const char *file, const char *func, int line,
|
|
|
|
const char *format, ...);
|
2019-11-27 18:45:56 +00:00
|
|
|
|
2016-03-01 14:45:43 +00:00
|
|
|
static inline int
|
|
|
|
libspl_assert(const char *buf, const char *file, const char *func, int line)
|
2010-08-26 18:50:56 +00:00
|
|
|
{
|
2020-07-04 22:24:13 +00:00
|
|
|
libspl_assertf(file, func, line, "%s", buf);
|
|
|
|
return (0);
|
2017-06-28 17:05:16 +00:00
|
|
|
}
|
|
|
|
|
2016-03-01 14:45:43 +00:00
|
|
|
#ifdef verify
|
|
|
|
#undef verify
|
|
|
|
#endif
|
2010-08-26 18:50:56 +00:00
|
|
|
|
2016-03-01 14:45:43 +00:00
|
|
|
#define VERIFY(cond) \
|
|
|
|
(void) ((!(cond)) && \
|
|
|
|
libspl_assert(#cond, __FILE__, __FUNCTION__, __LINE__))
|
|
|
|
#define verify(cond) \
|
|
|
|
(void) ((!(cond)) && \
|
|
|
|
libspl_assert(#cond, __FILE__, __FUNCTION__, __LINE__))
|
2010-08-26 18:50:56 +00:00
|
|
|
|
2018-10-04 03:16:45 +00:00
|
|
|
#define VERIFY3B(LEFT, OP, RIGHT) \
|
2016-03-01 14:45:43 +00:00
|
|
|
do { \
|
2018-10-04 03:16:45 +00:00
|
|
|
const boolean_t __left = (boolean_t)(LEFT); \
|
|
|
|
const boolean_t __right = (boolean_t)(RIGHT); \
|
2017-06-28 17:05:16 +00:00
|
|
|
if (!(__left OP __right)) \
|
|
|
|
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
|
2017-07-13 00:15:24 +00:00
|
|
|
"%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
|
|
|
|
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
|
2010-08-26 18:50:56 +00:00
|
|
|
} while (0)
|
|
|
|
|
2018-10-04 03:16:45 +00:00
|
|
|
#define VERIFY3S(LEFT, OP, RIGHT) \
|
|
|
|
do { \
|
|
|
|
const int64_t __left = (int64_t)(LEFT); \
|
|
|
|
const int64_t __right = (int64_t)(RIGHT); \
|
|
|
|
if (!(__left OP __right)) \
|
|
|
|
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
"%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
|
|
|
|
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define VERIFY3U(LEFT, OP, RIGHT) \
|
|
|
|
do { \
|
|
|
|
const uint64_t __left = (uint64_t)(LEFT); \
|
|
|
|
const uint64_t __right = (uint64_t)(RIGHT); \
|
|
|
|
if (!(__left OP __right)) \
|
|
|
|
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
"%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
|
|
|
|
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define VERIFY3P(LEFT, OP, RIGHT) \
|
|
|
|
do { \
|
|
|
|
const uintptr_t __left = (uintptr_t)(LEFT); \
|
|
|
|
const uintptr_t __right = (uintptr_t)(RIGHT); \
|
|
|
|
if (!(__left OP __right)) \
|
|
|
|
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
"%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
|
|
|
|
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define VERIFY0(LEFT) \
|
|
|
|
do { \
|
|
|
|
const uint64_t __left = (uint64_t)(LEFT); \
|
|
|
|
if (!(__left == 0)) \
|
|
|
|
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
"%s == 0 (0x%llx == 0)", #LEFT, \
|
|
|
|
(u_longlong_t)__left); \
|
|
|
|
} while (0)
|
2010-08-26 18:50:56 +00:00
|
|
|
|
2016-03-01 14:45:43 +00:00
|
|
|
#ifdef assert
|
|
|
|
#undef assert
|
|
|
|
#endif
|
|
|
|
|
2016-06-15 22:47:05 +00:00
|
|
|
/* Compile time assert */
|
|
|
|
#define CTASSERT_GLOBAL(x) _CTASSERT(x, __LINE__)
|
|
|
|
#define CTASSERT(x) { _CTASSERT(x, __LINE__); }
|
|
|
|
#define _CTASSERT(x, y) __CTASSERT(x, y)
|
|
|
|
#define __CTASSERT(x, y) \
|
|
|
|
typedef char __attribute__((unused)) \
|
|
|
|
__compile_time_assertion__ ## y[(x) ? 1 : -1]
|
|
|
|
|
2010-08-26 18:50:56 +00:00
|
|
|
#ifdef NDEBUG
|
OpenZFS 8585 - improve batching done in zil_commit()
Authored by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Brad Lewis <brad.lewis@delphix.com>
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Approved by: Dan McDonald <danmcd@joyent.com>
Ported-by: Prakash Surya <prakash.surya@delphix.com>
Problem
=======
The current implementation of zil_commit() can introduce significant
latency, beyond what is inherent due to the latency of the underlying
storage. The additional latency comes from two main problems:
1. When there's outstanding ZIL blocks being written (i.e. there's
already a "writer thread" in progress), then any new calls to
zil_commit() will block waiting for the currently oustanding ZIL
blocks to complete. The blocks written for each "writer thread" is
coined a "batch", and there can only ever be a single "batch" being
written at a time. When a batch is being written, any new ZIL
transactions will have to wait for the next batch to be written,
which won't occur until the current batch finishes.
As a result, the underlying storage may not be used as efficiently
as possible. While "new" threads enter zil_commit() and are blocked
waiting for the next batch, it's possible that the underlying
storage isn't fully utilized by the current batch of ZIL blocks. In
that case, it'd be better to allow these new threads to generate
(and issue) a new ZIL block, such that it could be serviced by the
underlying storage concurrently with the other ZIL blocks that are
being serviced.
2. Any call to zil_commit() must wait for all ZIL blocks in its "batch"
to complete, prior to zil_commit() returning. The size of any given
batch is proportional to the number of ZIL transaction in the queue
at the time that the batch starts processing the queue; which
doesn't occur until the previous batch completes. Thus, if there's a
lot of transactions in the queue, the batch could be composed of
many ZIL blocks, and each call to zil_commit() will have to wait for
all of these writes to complete (even if the thread calling
zil_commit() only cared about one of the transactions in the batch).
To further complicate the situation, these two issues result in the
following side effect:
3. If a given batch takes longer to complete than normal, this results
in larger batch sizes, which then take longer to complete and
further drive up the latency of zil_commit(). This can occur for a
number of reasons, including (but not limited to): transient changes
in the workload, and storage latency irregularites.
Solution
========
The solution attempted by this change has the following goals:
1. no on-disk changes; maintain current on-disk format.
2. modify the "batch size" to be equal to the "ZIL block size".
3. allow new batches to be generated and issued to disk, while there's
already batches being serviced by the disk.
4. allow zil_commit() to wait for as few ZIL blocks as possible.
5. use as few ZIL blocks as possible, for the same amount of ZIL
transactions, without introducing significant latency to any
individual ZIL transaction. i.e. use fewer, but larger, ZIL blocks.
In theory, with these goals met, the new allgorithm will allow the
following improvements:
1. new ZIL blocks can be generated and issued, while there's already
oustanding ZIL blocks being serviced by the storage.
2. the latency of zil_commit() should be proportional to the underlying
storage latency, rather than the incoming synchronous workload.
Porting Notes
=============
Due to the changes made in commit 119a394ab0, the lifetime of an itx
structure differs than in OpenZFS. Specifically, the itx structure is
kept around until the data associated with the itx is considered to be
safe on disk; this is so that the itx's callback can be called after the
data is committed to stable storage. Since OpenZFS doesn't have this itx
callback mechanism, it's able to destroy the itx structure immediately
after the itx is committed to an lwb (before the lwb is written to
disk).
To support this difference, and to ensure the itx's callbacks can still
be called after the itx's data is on disk, a few changes had to be made:
* A list of itxs was added to the lwb structure. This list contains
all of the itxs that have been committed to the lwb, such that the
callbacks for these itxs can be called from zil_lwb_flush_vdevs_done(),
after the data for the itxs is committed to disk.
* A list of itxs was added on the stack of the zil_process_commit_list()
function; the "nolwb_itxs" list. In some circumstances, an itx may
not be committed to an lwb (e.g. if allocating the "next" ZIL block
on disk fails), so this list is used to keep track of which itxs
fall into this state, such that their callbacks can be called after
the ZIL's writer pipeline is "stalled".
* The logic to actually call the itx's callback was moved into the
zil_itx_destroy() function. Since all consumers of zil_itx_destroy()
were effectively performing the same logic (i.e. if callback is
non-null, call the callback), it seemed like useful code cleanup to
consolidate this logic into a single function.
Additionally, the existing Linux tracepoint infrastructure dealing with
the ZIL's probes and structures had to be updated to reflect these code
changes. Specifically:
* The "zil__cw1" and "zil__cw2" probes were removed, so they had to be
removed from "trace_zil.h" as well.
* Some of the zilog structure's fields were removed, which affected
the tracepoint definitions of the structure.
* New tracepoints had to be added for the following 3 new probes:
* zil__process__commit__itx
* zil__process__normal__itx
* zil__commit__io__error
OpenZFS-issue: https://www.illumos.org/issues/8585
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/5d95a3a
Closes #6566
2017-12-05 17:39:16 +00:00
|
|
|
#define ASSERT3B(x, y, z) ((void)0)
|
2010-08-26 18:50:56 +00:00
|
|
|
#define ASSERT3S(x, y, z) ((void)0)
|
|
|
|
#define ASSERT3U(x, y, z) ((void)0)
|
|
|
|
#define ASSERT3P(x, y, z) ((void)0)
|
2013-05-10 21:17:03 +00:00
|
|
|
#define ASSERT0(x) ((void)0)
|
2016-03-01 14:45:43 +00:00
|
|
|
#define ASSERT(x) ((void)0)
|
|
|
|
#define assert(x) ((void)0)
|
2015-06-24 20:54:06 +00:00
|
|
|
#define IMPLY(A, B) ((void)0)
|
|
|
|
#define EQUIV(A, B) ((void)0)
|
2010-08-26 18:50:56 +00:00
|
|
|
#else
|
2018-10-04 03:16:45 +00:00
|
|
|
#define ASSERT3B VERIFY3B
|
|
|
|
#define ASSERT3S VERIFY3S
|
|
|
|
#define ASSERT3U VERIFY3U
|
|
|
|
#define ASSERT3P VERIFY3P
|
|
|
|
#define ASSERT0 VERIFY0
|
|
|
|
#define ASSERT VERIFY
|
|
|
|
#define assert VERIFY
|
2015-06-24 20:54:06 +00:00
|
|
|
#define IMPLY(A, B) \
|
|
|
|
((void)(((!(A)) || (B)) || \
|
2016-03-01 14:45:43 +00:00
|
|
|
libspl_assert("(" #A ") implies (" #B ")", \
|
|
|
|
__FILE__, __FUNCTION__, __LINE__)))
|
2015-06-24 20:54:06 +00:00
|
|
|
#define EQUIV(A, B) \
|
|
|
|
((void)((!!(A) == !!(B)) || \
|
2016-03-01 14:45:43 +00:00
|
|
|
libspl_assert("(" #A ") is equivalent to (" #B ")", \
|
|
|
|
__FILE__, __FUNCTION__, __LINE__)))
|
2015-06-24 20:54:06 +00:00
|
|
|
|
2010-08-26 18:50:56 +00:00
|
|
|
#endif /* NDEBUG */
|
|
|
|
|
|
|
|
#endif /* _LIBSPL_ASSERT_H */
|