2010-08-26 18:45:02 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2011-02-22 20:15:13 +00:00
|
|
|
|
2010-08-26 18:45:02 +00:00
|
|
|
/*
|
2011-02-22 20:15:13 +00:00
|
|
|
* Copyright (C) 2011 Lawrence Livermore National Security, LLC.
|
2010-08-26 18:45:02 +00:00
|
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
|
|
|
* LLNL-CODE-403049.
|
|
|
|
*/
|
|
|
|
|
2011-02-22 20:15:13 +00:00
|
|
|
#ifndef _ZFS_BLKDEV_H
|
2013-11-01 19:26:11 +00:00
|
|
|
#define _ZFS_BLKDEV_H
|
2010-08-26 18:45:02 +00:00
|
|
|
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/elevator.h>
|
2014-07-11 18:35:58 +00:00
|
|
|
#include <linux/backing-dev.h>
|
2018-02-16 01:53:18 +00:00
|
|
|
#include <linux/hdreg.h>
|
2018-06-15 22:05:21 +00:00
|
|
|
#include <linux/msdos_fs.h> /* for SECTOR_* */
|
2010-08-26 18:45:02 +00:00
|
|
|
|
|
|
|
#ifndef HAVE_FMODE_T
|
|
|
|
typedef unsigned __bitwise__ fmode_t;
|
|
|
|
#endif /* HAVE_FMODE_T */
|
|
|
|
|
2018-04-10 17:32:14 +00:00
|
|
|
#ifndef HAVE_BLK_QUEUE_FLAG_SET
|
|
|
|
static inline void
|
|
|
|
blk_queue_flag_set(unsigned int flag, struct request_queue *q)
|
|
|
|
{
|
2018-04-13 02:46:14 +00:00
|
|
|
queue_flag_set(flag, q);
|
2018-04-10 17:32:14 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_BLK_QUEUE_FLAG_CLEAR
|
|
|
|
static inline void
|
|
|
|
blk_queue_flag_clear(unsigned int flag, struct request_queue *q)
|
|
|
|
{
|
2018-04-13 02:46:14 +00:00
|
|
|
queue_flag_clear(flag, q);
|
2018-04-10 17:32:14 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-05 09:11:38 +00:00
|
|
|
/*
|
2016-08-09 18:22:30 +00:00
|
|
|
* 4.7 - 4.x API,
|
|
|
|
* The blk_queue_write_cache() interface has replaced blk_queue_flush()
|
|
|
|
* interface. However, the new interface is GPL-only thus we implement
|
|
|
|
* our own trivial wrapper when the GPL-only version is detected.
|
|
|
|
*
|
|
|
|
* 2.6.36 - 4.6 API,
|
2011-09-05 09:11:38 +00:00
|
|
|
* The blk_queue_flush() interface has replaced blk_queue_ordered()
|
|
|
|
* interface. However, while the old interface was available to all the
|
|
|
|
* new one is GPL-only. Thus if the GPL-only version is detected we
|
2016-08-09 18:22:30 +00:00
|
|
|
* implement our own trivial helper.
|
|
|
|
*
|
|
|
|
* 2.6.x - 2.6.35
|
|
|
|
* Legacy blk_queue_ordered() interface.
|
2016-05-18 20:45:39 +00:00
|
|
|
*/
|
|
|
|
static inline void
|
2016-08-09 18:22:30 +00:00
|
|
|
blk_queue_set_write_cache(struct request_queue *q, bool wc, bool fua)
|
2016-05-18 20:45:39 +00:00
|
|
|
{
|
2016-08-09 18:22:30 +00:00
|
|
|
#if defined(HAVE_BLK_QUEUE_WRITE_CACHE_GPL_ONLY)
|
2016-05-18 20:45:39 +00:00
|
|
|
if (wc)
|
2018-04-13 02:46:14 +00:00
|
|
|
blk_queue_flag_set(QUEUE_FLAG_WC, q);
|
2016-05-18 20:45:39 +00:00
|
|
|
else
|
2018-04-13 02:46:14 +00:00
|
|
|
blk_queue_flag_clear(QUEUE_FLAG_WC, q);
|
2016-05-18 20:45:39 +00:00
|
|
|
if (fua)
|
2018-04-13 02:46:14 +00:00
|
|
|
blk_queue_flag_set(QUEUE_FLAG_FUA, q);
|
2016-05-18 20:45:39 +00:00
|
|
|
else
|
2018-04-13 02:46:14 +00:00
|
|
|
blk_queue_flag_clear(QUEUE_FLAG_FUA, q);
|
2016-08-09 18:22:30 +00:00
|
|
|
#elif defined(HAVE_BLK_QUEUE_WRITE_CACHE)
|
|
|
|
blk_queue_write_cache(q, wc, fua);
|
|
|
|
#elif defined(HAVE_BLK_QUEUE_FLUSH_GPL_ONLY)
|
|
|
|
if (wc)
|
|
|
|
q->flush_flags |= REQ_FLUSH;
|
|
|
|
if (fua)
|
|
|
|
q->flush_flags |= REQ_FUA;
|
|
|
|
#elif defined(HAVE_BLK_QUEUE_FLUSH)
|
|
|
|
blk_queue_flush(q, (wc ? REQ_FLUSH : 0) | (fua ? REQ_FUA : 0));
|
|
|
|
#else
|
|
|
|
blk_queue_ordered(q, QUEUE_ORDERED_DRAIN, NULL);
|
2016-05-18 20:45:39 +00:00
|
|
|
#endif
|
2016-08-09 18:22:30 +00:00
|
|
|
}
|
2016-05-18 20:45:39 +00:00
|
|
|
|
2010-11-11 00:38:14 +00:00
|
|
|
/*
|
|
|
|
* Most of the blk_* macros were removed in 2.6.36. Ostensibly this was
|
|
|
|
* done to improve readability and allow easier grepping. However, from
|
|
|
|
* a portability stand point the macros are helpful. Therefore the needed
|
|
|
|
* macros are redefined here if they are missing from the kernel.
|
|
|
|
*/
|
|
|
|
#ifndef blk_fs_request
|
2013-11-01 19:26:11 +00:00
|
|
|
#define blk_fs_request(rq) ((rq)->cmd_type == REQ_TYPE_FS)
|
2010-11-11 00:38:14 +00:00
|
|
|
#endif
|
|
|
|
|
2011-09-05 13:15:45 +00:00
|
|
|
/*
|
|
|
|
* 2.6.34 API change,
|
|
|
|
* The blk_queue_max_hw_sectors() function replaces blk_queue_max_sectors().
|
|
|
|
*/
|
|
|
|
#ifndef HAVE_BLK_QUEUE_MAX_HW_SECTORS
|
2013-11-01 19:26:11 +00:00
|
|
|
#define blk_queue_max_hw_sectors __blk_queue_max_hw_sectors
|
2011-09-05 13:15:45 +00:00
|
|
|
static inline void
|
|
|
|
__blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_sectors)
|
|
|
|
{
|
|
|
|
blk_queue_max_sectors(q, max_hw_sectors);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 2.6.34 API change,
|
|
|
|
* The blk_queue_max_segments() function consolidates
|
|
|
|
* blk_queue_max_hw_segments() and blk_queue_max_phys_segments().
|
|
|
|
*/
|
|
|
|
#ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
|
2013-11-01 19:26:11 +00:00
|
|
|
#define blk_queue_max_segments __blk_queue_max_segments
|
2011-09-05 13:15:45 +00:00
|
|
|
static inline void
|
|
|
|
__blk_queue_max_segments(struct request_queue *q, unsigned short max_segments)
|
|
|
|
{
|
|
|
|
blk_queue_max_phys_segments(q, max_segments);
|
|
|
|
blk_queue_max_hw_segments(q, max_segments);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-07-11 18:35:58 +00:00
|
|
|
static inline void
|
|
|
|
blk_queue_set_read_ahead(struct request_queue *q, unsigned long ra_pages)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_BLK_QUEUE_BDI_DYNAMIC
|
|
|
|
q->backing_dev_info->ra_pages = ra_pages;
|
|
|
|
#else
|
|
|
|
q->backing_dev_info.ra_pages = ra_pages;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-03-05 20:44:35 +00:00
|
|
|
#ifndef HAVE_GET_DISK_AND_MODULE
|
|
|
|
static inline struct kobject *
|
|
|
|
get_disk_and_module(struct gendisk *disk)
|
|
|
|
{
|
|
|
|
return (get_disk(disk));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-26 18:45:02 +00:00
|
|
|
#ifndef HAVE_GET_DISK_RO
|
|
|
|
static inline int
|
|
|
|
get_disk_ro(struct gendisk *disk)
|
|
|
|
{
|
|
|
|
int policy = 0;
|
|
|
|
|
|
|
|
if (disk->part[0])
|
|
|
|
policy = disk->part[0]->policy;
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
return (policy);
|
2010-08-26 18:45:02 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_GET_DISK_RO */
|
|
|
|
|
2014-03-28 07:08:21 +00:00
|
|
|
#ifdef HAVE_BIO_BVEC_ITER
|
|
|
|
#define BIO_BI_SECTOR(bio) (bio)->bi_iter.bi_sector
|
|
|
|
#define BIO_BI_SIZE(bio) (bio)->bi_iter.bi_size
|
|
|
|
#define BIO_BI_IDX(bio) (bio)->bi_iter.bi_idx
|
2015-12-08 20:37:24 +00:00
|
|
|
#define BIO_BI_SKIP(bio) (bio)->bi_iter.bi_bvec_done
|
zvol processing should use struct bio
Internally, zvols are files exposed through the block device API. This
is intended to reduce overhead when things require block devices.
However, the ZoL zvol code emulates a traditional block device in that
it has a top half and a bottom half. This is an unnecessary source of
overhead that does not exist on any other OpenZFS platform does this.
This patch removes it. Early users of this patch reported double digit
performance gains in IOPS on zvols in the range of 50% to 80%.
Comments in the code suggest that the current implementation was done to
obtain IO merging from Linux's IO elevator. However, the DMU already
does write merging while arc_read() should implicitly merge read IOs
because only 1 thread is permitted to fetch the buffer into ARC. In
addition, commercial ZFSOnLinux distributions report that regular files
are more performant than zvols under the current implementation, and the
main consumers of zvols are VMs and iSCSI targets, which have their own
elevators to merge IOs.
Some minor refactoring allows us to register zfs_request() as our
->make_request() handler in place of the generic_make_request()
function. This eliminates the layer of code that broke IO requests on
zvols into a top half and a bottom half. This has several benefits:
1. No per zvol spinlocks.
2. No redundant IO elevator processing.
3. Interrupts are disabled only when actually necessary.
4. No redispatching of IOs when all taskq threads are busy.
5. Linux's page out routines will properly block.
6. Many autotools checks become obsolete.
An unfortunate consequence of eliminating the layer that
generic_make_request() is that we no longer calls the instrumentation
hooks for block IO accounting. Those hooks are GPL-exported, so we
cannot call them ourselves and consequently, we lose the ability to do
IO monitoring via iostat. Since zvols are internally files mapped as
block devices, this should be okay. Anyone who is willing to accept the
performance penalty for the block IO layer's accounting could use the
loop device in between the zvol and its consumer. Alternatively, perf
and ftrace likely could be used. Also, tools like latencytop will still
work. Tools such as latencytop sometimes provide a better view of
performance bottlenecks than the traditional block IO accounting tools
do.
Lastly, if direct reclaim occurs during spacemap loading and swap is on
a zvol, this code will deadlock. That deadlock could already occur with
sync=always on zvols. Given that swap on zvols is not yet production
ready, this is not a blocker.
Signed-off-by: Richard Yao <ryao@gentoo.org>
2014-07-04 22:43:47 +00:00
|
|
|
#define bio_for_each_segment4(bv, bvp, b, i) \
|
|
|
|
bio_for_each_segment((bv), (b), (i))
|
|
|
|
typedef struct bvec_iter bvec_iterator_t;
|
2014-03-28 07:08:21 +00:00
|
|
|
#else
|
|
|
|
#define BIO_BI_SECTOR(bio) (bio)->bi_sector
|
|
|
|
#define BIO_BI_SIZE(bio) (bio)->bi_size
|
|
|
|
#define BIO_BI_IDX(bio) (bio)->bi_idx
|
2015-12-08 20:37:24 +00:00
|
|
|
#define BIO_BI_SKIP(bio) (0)
|
zvol processing should use struct bio
Internally, zvols are files exposed through the block device API. This
is intended to reduce overhead when things require block devices.
However, the ZoL zvol code emulates a traditional block device in that
it has a top half and a bottom half. This is an unnecessary source of
overhead that does not exist on any other OpenZFS platform does this.
This patch removes it. Early users of this patch reported double digit
performance gains in IOPS on zvols in the range of 50% to 80%.
Comments in the code suggest that the current implementation was done to
obtain IO merging from Linux's IO elevator. However, the DMU already
does write merging while arc_read() should implicitly merge read IOs
because only 1 thread is permitted to fetch the buffer into ARC. In
addition, commercial ZFSOnLinux distributions report that regular files
are more performant than zvols under the current implementation, and the
main consumers of zvols are VMs and iSCSI targets, which have their own
elevators to merge IOs.
Some minor refactoring allows us to register zfs_request() as our
->make_request() handler in place of the generic_make_request()
function. This eliminates the layer of code that broke IO requests on
zvols into a top half and a bottom half. This has several benefits:
1. No per zvol spinlocks.
2. No redundant IO elevator processing.
3. Interrupts are disabled only when actually necessary.
4. No redispatching of IOs when all taskq threads are busy.
5. Linux's page out routines will properly block.
6. Many autotools checks become obsolete.
An unfortunate consequence of eliminating the layer that
generic_make_request() is that we no longer calls the instrumentation
hooks for block IO accounting. Those hooks are GPL-exported, so we
cannot call them ourselves and consequently, we lose the ability to do
IO monitoring via iostat. Since zvols are internally files mapped as
block devices, this should be okay. Anyone who is willing to accept the
performance penalty for the block IO layer's accounting could use the
loop device in between the zvol and its consumer. Alternatively, perf
and ftrace likely could be used. Also, tools like latencytop will still
work. Tools such as latencytop sometimes provide a better view of
performance bottlenecks than the traditional block IO accounting tools
do.
Lastly, if direct reclaim occurs during spacemap loading and swap is on
a zvol, this code will deadlock. That deadlock could already occur with
sync=always on zvols. Given that swap on zvols is not yet production
ready, this is not a blocker.
Signed-off-by: Richard Yao <ryao@gentoo.org>
2014-07-04 22:43:47 +00:00
|
|
|
#define bio_for_each_segment4(bv, bvp, b, i) \
|
|
|
|
bio_for_each_segment((bvp), (b), (i))
|
|
|
|
typedef int bvec_iterator_t;
|
2014-03-28 07:08:21 +00:00
|
|
|
#endif
|
|
|
|
|
2011-02-22 20:15:13 +00:00
|
|
|
/*
|
|
|
|
* Portable helper for correctly setting the FAILFAST flags. The
|
|
|
|
* correct usage has changed 3 times from 2.6.12 to 2.6.38.
|
|
|
|
*/
|
2010-10-01 17:57:56 +00:00
|
|
|
static inline void
|
|
|
|
bio_set_flags_failfast(struct block_device *bdev, int *flags)
|
|
|
|
{
|
2010-11-10 22:40:38 +00:00
|
|
|
#ifdef CONFIG_BUG
|
2010-10-01 17:57:56 +00:00
|
|
|
/*
|
2010-11-10 22:40:38 +00:00
|
|
|
* Disable FAILFAST for loopback devices because of the
|
|
|
|
* following incorrect BUG_ON() in loop_make_request().
|
2010-10-01 17:57:56 +00:00
|
|
|
* This support is also disabled for md devices because the
|
|
|
|
* test suite layers md devices on top of loopback devices.
|
|
|
|
* This may be removed when the loopback driver is fixed.
|
|
|
|
*
|
|
|
|
* BUG_ON(!lo || (rw != READ && rw != WRITE));
|
|
|
|
*/
|
|
|
|
if ((MAJOR(bdev->bd_dev) == LOOP_MAJOR) ||
|
|
|
|
(MAJOR(bdev->bd_dev) == MD_MAJOR))
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef BLOCK_EXT_MAJOR
|
|
|
|
if (MAJOR(bdev->bd_dev) == BLOCK_EXT_MAJOR)
|
|
|
|
return;
|
|
|
|
#endif /* BLOCK_EXT_MAJOR */
|
|
|
|
#endif /* CONFIG_BUG */
|
2010-11-10 22:40:38 +00:00
|
|
|
|
2015-05-08 20:49:56 +00:00
|
|
|
#if defined(HAVE_BIO_RW_FAILFAST_DTD)
|
2010-11-10 22:40:38 +00:00
|
|
|
/* BIO_RW_FAILFAST_* preferred interface from 2.6.28 - 2.6.35 */
|
2013-11-01 19:26:11 +00:00
|
|
|
*flags |= (
|
|
|
|
(1 << BIO_RW_FAILFAST_DEV) |
|
|
|
|
(1 << BIO_RW_FAILFAST_TRANSPORT) |
|
|
|
|
(1 << BIO_RW_FAILFAST_DRIVER));
|
2015-05-08 20:49:56 +00:00
|
|
|
#elif defined(HAVE_REQ_FAILFAST_MASK)
|
2013-11-01 19:26:11 +00:00
|
|
|
/*
|
|
|
|
* REQ_FAILFAST_* preferred interface from 2.6.36 - 2.6.xx,
|
|
|
|
* the BIO_* and REQ_* flags were unified under REQ_* flags.
|
|
|
|
*/
|
2010-11-10 22:40:38 +00:00
|
|
|
*flags |= REQ_FAILFAST_MASK;
|
2015-05-08 20:49:56 +00:00
|
|
|
#else
|
|
|
|
#error "Undefined block IO FAILFAST interface."
|
|
|
|
#endif
|
2010-10-01 17:57:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 20:15:13 +00:00
|
|
|
/*
|
|
|
|
* Maximum disk label length, it may be undefined for some kernels.
|
|
|
|
*/
|
2010-08-26 18:45:02 +00:00
|
|
|
#ifndef DISK_NAME_LEN
|
2013-11-01 19:26:11 +00:00
|
|
|
#define DISK_NAME_LEN 32
|
2010-08-26 18:45:02 +00:00
|
|
|
#endif /* DISK_NAME_LEN */
|
|
|
|
|
2017-07-24 02:37:12 +00:00
|
|
|
#ifdef HAVE_BIO_BI_STATUS
|
|
|
|
static inline int
|
|
|
|
bi_status_to_errno(blk_status_t status)
|
|
|
|
{
|
|
|
|
switch (status) {
|
|
|
|
case BLK_STS_OK:
|
|
|
|
return (0);
|
|
|
|
case BLK_STS_NOTSUPP:
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
case BLK_STS_TIMEOUT:
|
|
|
|
return (ETIMEDOUT);
|
|
|
|
case BLK_STS_NOSPC:
|
|
|
|
return (ENOSPC);
|
|
|
|
case BLK_STS_TRANSPORT:
|
|
|
|
return (ENOLINK);
|
|
|
|
case BLK_STS_TARGET:
|
|
|
|
return (EREMOTEIO);
|
|
|
|
case BLK_STS_NEXUS:
|
|
|
|
return (EBADE);
|
|
|
|
case BLK_STS_MEDIUM:
|
|
|
|
return (ENODATA);
|
|
|
|
case BLK_STS_PROTECTION:
|
|
|
|
return (EILSEQ);
|
|
|
|
case BLK_STS_RESOURCE:
|
|
|
|
return (ENOMEM);
|
|
|
|
case BLK_STS_AGAIN:
|
|
|
|
return (EAGAIN);
|
|
|
|
case BLK_STS_IOERR:
|
|
|
|
return (EIO);
|
|
|
|
default:
|
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline blk_status_t
|
|
|
|
errno_to_bi_status(int error)
|
|
|
|
{
|
|
|
|
switch (error) {
|
|
|
|
case 0:
|
|
|
|
return (BLK_STS_OK);
|
|
|
|
case EOPNOTSUPP:
|
|
|
|
return (BLK_STS_NOTSUPP);
|
|
|
|
case ETIMEDOUT:
|
|
|
|
return (BLK_STS_TIMEOUT);
|
|
|
|
case ENOSPC:
|
|
|
|
return (BLK_STS_NOSPC);
|
|
|
|
case ENOLINK:
|
|
|
|
return (BLK_STS_TRANSPORT);
|
|
|
|
case EREMOTEIO:
|
|
|
|
return (BLK_STS_TARGET);
|
|
|
|
case EBADE:
|
|
|
|
return (BLK_STS_NEXUS);
|
|
|
|
case ENODATA:
|
|
|
|
return (BLK_STS_MEDIUM);
|
|
|
|
case EILSEQ:
|
|
|
|
return (BLK_STS_PROTECTION);
|
|
|
|
case ENOMEM:
|
|
|
|
return (BLK_STS_RESOURCE);
|
|
|
|
case EAGAIN:
|
|
|
|
return (BLK_STS_AGAIN);
|
|
|
|
case EIO:
|
|
|
|
return (BLK_STS_IOERR);
|
|
|
|
default:
|
|
|
|
return (BLK_STS_IOERR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_BIO_BI_STATUS */
|
|
|
|
|
2011-02-22 20:15:13 +00:00
|
|
|
/*
|
2015-09-23 15:55:15 +00:00
|
|
|
* 4.3 API change
|
|
|
|
* The bio_endio() prototype changed slightly. These are helper
|
|
|
|
* macro's to ensure the prototype and invocation are handled.
|
2011-02-22 20:15:13 +00:00
|
|
|
*/
|
2015-09-23 15:55:15 +00:00
|
|
|
#ifdef HAVE_1ARG_BIO_END_IO_T
|
2017-07-24 02:37:12 +00:00
|
|
|
#ifdef HAVE_BIO_BI_STATUS
|
|
|
|
#define BIO_END_IO_ERROR(bio) bi_status_to_errno(bio->bi_status)
|
|
|
|
#define BIO_END_IO_PROTO(fn, x, z) static void fn(struct bio *x)
|
|
|
|
#define BIO_END_IO(bio, error) bio_set_bi_status(bio, error)
|
|
|
|
static inline void
|
|
|
|
bio_set_bi_status(struct bio *bio, int error)
|
|
|
|
{
|
|
|
|
ASSERT3S(error, <=, 0);
|
|
|
|
bio->bi_status = errno_to_bi_status(-error);
|
|
|
|
bio_endio(bio);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define BIO_END_IO_ERROR(bio) (-(bio->bi_error))
|
2015-09-23 15:55:15 +00:00
|
|
|
#define BIO_END_IO_PROTO(fn, x, z) static void fn(struct bio *x)
|
2017-07-24 02:37:12 +00:00
|
|
|
#define BIO_END_IO(bio, error) bio_set_bi_error(bio, error)
|
|
|
|
static inline void
|
|
|
|
bio_set_bi_error(struct bio *bio, int error)
|
|
|
|
{
|
|
|
|
ASSERT3S(error, <=, 0);
|
|
|
|
bio->bi_error = error;
|
|
|
|
bio_endio(bio);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_BIO_BI_STATUS */
|
|
|
|
|
2011-02-22 20:15:13 +00:00
|
|
|
#else
|
2015-09-23 15:55:15 +00:00
|
|
|
#define BIO_END_IO_PROTO(fn, x, z) static void fn(struct bio *x, int z)
|
|
|
|
#define BIO_END_IO(bio, error) bio_endio(bio, error);
|
|
|
|
#endif /* HAVE_1ARG_BIO_END_IO_T */
|
2011-02-22 20:15:13 +00:00
|
|
|
|
|
|
|
/*
|
2011-02-22 22:55:35 +00:00
|
|
|
* 2.6.38 - 2.6.x API,
|
|
|
|
* blkdev_get_by_path()
|
|
|
|
* blkdev_put()
|
|
|
|
*
|
|
|
|
* 2.6.28 - 2.6.37 API,
|
|
|
|
* open_bdev_exclusive()
|
|
|
|
* close_bdev_exclusive()
|
|
|
|
*
|
|
|
|
* 2.6.12 - 2.6.27 API,
|
|
|
|
* open_bdev_excl()
|
|
|
|
* close_bdev_excl()
|
|
|
|
*
|
2011-02-22 20:15:13 +00:00
|
|
|
* Used to exclusively open a block device from within the kernel.
|
|
|
|
*/
|
2011-02-22 22:55:35 +00:00
|
|
|
#if defined(HAVE_BLKDEV_GET_BY_PATH)
|
2013-11-01 19:26:11 +00:00
|
|
|
#define vdev_bdev_open(path, md, hld) blkdev_get_by_path(path, \
|
2011-02-22 22:55:35 +00:00
|
|
|
(md) | FMODE_EXCL, hld)
|
2013-11-01 19:26:11 +00:00
|
|
|
#define vdev_bdev_close(bdev, md) blkdev_put(bdev, (md) | FMODE_EXCL)
|
2011-02-22 22:55:35 +00:00
|
|
|
#elif defined(HAVE_OPEN_BDEV_EXCLUSIVE)
|
2013-11-01 19:26:11 +00:00
|
|
|
#define vdev_bdev_open(path, md, hld) open_bdev_exclusive(path, md, hld)
|
|
|
|
#define vdev_bdev_close(bdev, md) close_bdev_exclusive(bdev, md)
|
2011-02-22 20:15:13 +00:00
|
|
|
#else
|
2013-11-01 19:26:11 +00:00
|
|
|
#define vdev_bdev_open(path, md, hld) open_bdev_excl(path, md, hld)
|
|
|
|
#define vdev_bdev_close(bdev, md) close_bdev_excl(bdev)
|
2011-02-22 22:55:35 +00:00
|
|
|
#endif /* HAVE_BLKDEV_GET_BY_PATH | HAVE_OPEN_BDEV_EXCLUSIVE */
|
2011-02-22 20:15:13 +00:00
|
|
|
|
Add support for autoexpand property
While the autoexpand property may seem like a small feature it
depends on a significant amount of system infrastructure. Enough
of that infrastructure is now in place that with a few modifications
for Linux it can be supported.
Auto-expand works as follows; when a block device is modified
(re-sized, closed after being open r/w, etc) a change uevent is
generated for udev. The ZED, which is monitoring udev events,
passes the change event along to zfs_deliver_dle() if the disk
or partition contains a zfs_member as identified by blkid.
From here the device is matched against all imported pool vdevs
using the vdev_guid which was read from the label by blkid. If
a match is found the ZED reopens the pool vdev. This re-opening
is important because it allows the vdev to be briefly closed so
the disk partition table can be re-read. Otherwise, it wouldn't
be possible to report the maximum possible expansion size.
Finally, if the property autoexpand=on a vdev expansion will be
attempted. After performing some sanity checks on the disk to
verify that it is safe to expand, the primary partition (-part1)
will be expanded and the partition table updated. The partition
is then re-opened (again) to detect the updated size which allows
the new capacity to be used.
In order to make all of the above possible the following changes
were required:
* Updated the zpool_expand_001_pos and zpool_expand_003_pos tests.
These tests now create a pool which is layered on a loopback,
scsi_debug, and file vdev. This allows for testing of non-
partitioned block device (loopback), a partition block device
(scsi_debug), and a file which does not receive udev change
events. This provided for better test coverage, and by removing
the layering on ZFS volumes there issues surrounding layering
one pool on another are avoided.
* zpool_find_vdev_by_physpath() updated to accept a vdev guid.
This allows for matching by guid rather than path which is a
more reliable way for the ZED to reference a vdev.
* Fixed zfs_zevent_wait() signal handling which could result
in the ZED spinning when a signal was not handled.
* Removed vdev_disk_rrpart() functionality which can be abandoned
in favor of kernel provided blkdev_reread_part() function.
* Added a rwlock which is held as a writer while a disk is being
reopened. This is important to prevent errors from occurring
for any configuration related IOs which bypass the SCL_ZIO lock.
The zpool_reopen_007_pos.ksh test case was added to verify IO
error are never observed when reopening. This is not expected
to impact IO performance.
Additional fixes which aren't critical but were discovered and
resolved in the course of developing this functionality.
* Added PHYS_PATH="/dev/zvol/dataset" to the vdev configuration for
ZFS volumes. This is as good as a unique physical path, while the
volumes are not used in the test cases anymore for other reasons
this improvement was included.
Reviewed by: Richard Elling <Richard.Elling@RichardElling.com>
Signed-off-by: Sara Hartse <sara.hartse@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #120
Closes #2437
Closes #5771
Closes #7366
Closes #7582
Closes #7629
2018-07-23 22:40:15 +00:00
|
|
|
/*
|
|
|
|
* 4.1 - x.y.z API,
|
|
|
|
* 3.10.0 CentOS 7.x API,
|
|
|
|
* blkdev_reread_part()
|
|
|
|
*
|
|
|
|
* For older kernels trigger a re-reading of the partition table by calling
|
|
|
|
* check_disk_change() which calls flush_disk() to invalidate the device.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_BLKDEV_REREAD_PART
|
|
|
|
#define vdev_bdev_reread_part(bdev) blkdev_reread_part(bdev)
|
|
|
|
#else
|
|
|
|
#define vdev_bdev_reread_part(bdev) check_disk_change(bdev)
|
|
|
|
#endif /* HAVE_BLKDEV_REREAD_PART */
|
|
|
|
|
2011-02-22 20:15:13 +00:00
|
|
|
/*
|
|
|
|
* 2.6.22 API change
|
|
|
|
* The function invalidate_bdev() lost it's second argument because
|
|
|
|
* it was unused.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_1ARG_INVALIDATE_BDEV
|
2013-11-01 19:26:11 +00:00
|
|
|
#define vdev_bdev_invalidate(bdev) invalidate_bdev(bdev)
|
2011-02-22 20:15:13 +00:00
|
|
|
#else
|
2013-11-01 19:26:11 +00:00
|
|
|
#define vdev_bdev_invalidate(bdev) invalidate_bdev(bdev, 1)
|
2011-02-22 20:15:13 +00:00
|
|
|
#endif /* HAVE_1ARG_INVALIDATE_BDEV */
|
|
|
|
|
2013-01-28 22:15:39 +00:00
|
|
|
/*
|
|
|
|
* 2.6.27 API change
|
2016-10-26 17:30:43 +00:00
|
|
|
* The function was exported for use, prior to this it existed but the
|
2013-01-28 22:15:39 +00:00
|
|
|
* symbol was not exported.
|
2016-10-26 17:30:43 +00:00
|
|
|
*
|
|
|
|
* 4.4.0-6.21 API change for Ubuntu
|
|
|
|
* lookup_bdev() gained a second argument, FMODE_*, to check inode permissions.
|
2013-01-28 22:15:39 +00:00
|
|
|
*/
|
2016-10-26 17:30:43 +00:00
|
|
|
#ifdef HAVE_1ARG_LOOKUP_BDEV
|
|
|
|
#define vdev_lookup_bdev(path) lookup_bdev(path)
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_2ARGS_LOOKUP_BDEV
|
|
|
|
#define vdev_lookup_bdev(path) lookup_bdev(path, 0)
|
|
|
|
#else
|
|
|
|
#define vdev_lookup_bdev(path) ERR_PTR(-ENOTSUP)
|
|
|
|
#endif /* HAVE_2ARGS_LOOKUP_BDEV */
|
|
|
|
#endif /* HAVE_1ARG_LOOKUP_BDEV */
|
2013-01-28 22:15:39 +00:00
|
|
|
|
2011-02-22 20:15:13 +00:00
|
|
|
/*
|
|
|
|
* 2.6.30 API change
|
2012-09-02 23:34:12 +00:00
|
|
|
* To ensure good performance preferentially use the physical block size
|
|
|
|
* for proper alignment. The physical size is supposed to be the internal
|
|
|
|
* sector size used by the device. This is often 4096 byte for AF devices,
|
|
|
|
* while a smaller 512 byte logical size is supported for compatibility.
|
|
|
|
*
|
|
|
|
* Unfortunately, many drives still misreport their physical sector size.
|
|
|
|
* For devices which are known to lie you may need to manually set this
|
|
|
|
* at pool creation time with 'zpool create -o ashift=12 ...'.
|
|
|
|
*
|
|
|
|
* When the physical block size interface isn't available, we fall back to
|
|
|
|
* the logical block size interface and then the older hard sector size.
|
2011-02-22 20:15:13 +00:00
|
|
|
*/
|
2012-09-02 23:34:12 +00:00
|
|
|
#ifdef HAVE_BDEV_PHYSICAL_BLOCK_SIZE
|
2013-11-01 19:26:11 +00:00
|
|
|
#define vdev_bdev_block_size(bdev) bdev_physical_block_size(bdev)
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_BDEV_LOGICAL_BLOCK_SIZE
|
|
|
|
#define vdev_bdev_block_size(bdev) bdev_logical_block_size(bdev)
|
2011-02-22 20:15:13 +00:00
|
|
|
#else
|
2013-11-01 19:26:11 +00:00
|
|
|
#define vdev_bdev_block_size(bdev) bdev_hardsect_size(bdev)
|
|
|
|
#endif /* HAVE_BDEV_LOGICAL_BLOCK_SIZE */
|
2012-09-02 23:34:12 +00:00
|
|
|
#endif /* HAVE_BDEV_PHYSICAL_BLOCK_SIZE */
|
2011-02-22 20:15:13 +00:00
|
|
|
|
2016-12-30 22:03:59 +00:00
|
|
|
#ifndef HAVE_BIO_SET_OP_ATTRS
|
2011-06-16 18:20:22 +00:00
|
|
|
/*
|
2016-12-30 22:03:59 +00:00
|
|
|
* Kernels without bio_set_op_attrs use bi_rw for the bio flags.
|
2011-06-16 18:20:22 +00:00
|
|
|
*/
|
2016-12-30 22:03:59 +00:00
|
|
|
static inline void
|
|
|
|
bio_set_op_attrs(struct bio *bio, unsigned rw, unsigned flags)
|
|
|
|
{
|
|
|
|
bio->bi_rw |= rw | flags;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bio_set_flush - Set the appropriate flags in a bio to guarantee
|
|
|
|
* data are on non-volatile media on completion.
|
|
|
|
*
|
|
|
|
* 2.6.X - 2.6.36 API,
|
|
|
|
* WRITE_BARRIER - Tells the block layer to commit all previously submitted
|
|
|
|
* writes to stable storage before this one is started and that the current
|
|
|
|
* write is on stable storage upon completion. Also prevents reordering
|
|
|
|
* on both sides of the current operation.
|
|
|
|
*
|
|
|
|
* 2.6.37 - 4.8 API,
|
|
|
|
* Introduce WRITE_FLUSH, WRITE_FUA, and WRITE_FLUSH_FUA flags as a
|
|
|
|
* replacement for WRITE_BARRIER to allow expressing richer semantics
|
|
|
|
* to the block layer. It's up to the block layer to implement the
|
|
|
|
* semantics correctly. Use the WRITE_FLUSH_FUA flag combination.
|
|
|
|
*
|
|
|
|
* 4.8 - 4.9 API,
|
|
|
|
* REQ_FLUSH was renamed to REQ_PREFLUSH. For consistency with previous
|
|
|
|
* ZoL releases, prefer the WRITE_FLUSH_FUA flag set if it's available.
|
|
|
|
*
|
|
|
|
* 4.10 API,
|
|
|
|
* The read/write flags and their modifiers, including WRITE_FLUSH,
|
|
|
|
* WRITE_FUA and WRITE_FLUSH_FUA were removed from fs.h in
|
|
|
|
* torvalds/linux@70fd7614 and replaced by direct flag modification
|
|
|
|
* of the REQ_ flags in bio->bi_opf. Use REQ_PREFLUSH.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
bio_set_flush(struct bio *bio)
|
|
|
|
{
|
2017-03-08 17:20:21 +00:00
|
|
|
#if defined(REQ_PREFLUSH) /* >= 4.10 */
|
|
|
|
bio_set_op_attrs(bio, 0, REQ_PREFLUSH);
|
2016-12-30 22:03:59 +00:00
|
|
|
#elif defined(WRITE_FLUSH_FUA) /* >= 2.6.37 and <= 4.9 */
|
|
|
|
bio_set_op_attrs(bio, 0, WRITE_FLUSH_FUA);
|
2017-03-08 17:20:21 +00:00
|
|
|
#elif defined(WRITE_BARRIER) /* < 2.6.37 */
|
|
|
|
bio_set_op_attrs(bio, 0, WRITE_BARRIER);
|
2016-07-27 18:06:17 +00:00
|
|
|
#else
|
2016-12-30 22:03:59 +00:00
|
|
|
#error "Allowing the build will cause bio_set_flush requests to be ignored."
|
2016-07-27 18:06:17 +00:00
|
|
|
#endif
|
2016-12-30 22:03:59 +00:00
|
|
|
}
|
2016-07-27 18:06:17 +00:00
|
|
|
|
2016-08-09 18:22:30 +00:00
|
|
|
/*
|
|
|
|
* 4.8 - 4.x API,
|
|
|
|
* REQ_OP_FLUSH
|
|
|
|
*
|
|
|
|
* 4.8-rc0 - 4.8-rc1,
|
|
|
|
* REQ_PREFLUSH
|
|
|
|
*
|
|
|
|
* 2.6.36 - 4.7 API,
|
|
|
|
* REQ_FLUSH
|
|
|
|
*
|
|
|
|
* 2.6.x - 2.6.35 API,
|
|
|
|
* HAVE_BIO_RW_BARRIER
|
|
|
|
*
|
|
|
|
* Used to determine if a cache flush has been requested. This check has
|
|
|
|
* been left intentionally broad in order to cover both a legacy flush
|
|
|
|
* and the new preflush behavior introduced in Linux 4.8. This is correct
|
|
|
|
* in all cases but may have a performance impact for some kernels. It
|
|
|
|
* has the advantage of minimizing kernel specific changes in the zvol code.
|
2016-08-11 21:58:13 +00:00
|
|
|
*
|
2016-08-09 18:22:30 +00:00
|
|
|
*/
|
|
|
|
static inline boolean_t
|
|
|
|
bio_is_flush(struct bio *bio)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_REQ_OP_FLUSH) && defined(HAVE_BIO_BI_OPF)
|
|
|
|
return ((bio_op(bio) == REQ_OP_FLUSH) || (bio->bi_opf & REQ_PREFLUSH));
|
|
|
|
#elif defined(REQ_PREFLUSH) && defined(HAVE_BIO_BI_OPF)
|
|
|
|
return (bio->bi_opf & REQ_PREFLUSH);
|
|
|
|
#elif defined(REQ_PREFLUSH) && !defined(HAVE_BIO_BI_OPF)
|
|
|
|
return (bio->bi_rw & REQ_PREFLUSH);
|
2016-08-11 21:58:13 +00:00
|
|
|
#elif defined(REQ_FLUSH)
|
|
|
|
return (bio->bi_rw & REQ_FLUSH);
|
2017-03-08 17:20:21 +00:00
|
|
|
#elif defined(HAVE_BIO_RW_BARRIER)
|
|
|
|
return (bio->bi_rw & (1 << BIO_RW_BARRIER));
|
2011-06-16 18:20:22 +00:00
|
|
|
#else
|
2017-03-07 17:54:55 +00:00
|
|
|
#error "Allowing the build will cause flush requests to be ignored."
|
2011-06-16 18:20:22 +00:00
|
|
|
#endif
|
2016-08-09 18:22:30 +00:00
|
|
|
}
|
2016-07-27 18:06:17 +00:00
|
|
|
|
2016-08-09 18:22:30 +00:00
|
|
|
/*
|
|
|
|
* 4.8 - 4.x API,
|
|
|
|
* REQ_FUA flag moved to bio->bi_opf
|
|
|
|
*
|
|
|
|
* 2.6.x - 4.7 API,
|
|
|
|
* REQ_FUA
|
|
|
|
*/
|
|
|
|
static inline boolean_t
|
|
|
|
bio_is_fua(struct bio *bio)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_BIO_BI_OPF)
|
|
|
|
return (bio->bi_opf & REQ_FUA);
|
|
|
|
#elif defined(REQ_FUA)
|
|
|
|
return (bio->bi_rw & REQ_FUA);
|
|
|
|
#else
|
2017-03-07 17:54:55 +00:00
|
|
|
#error "Allowing the build will cause fua requests to be ignored."
|
zvol processing should use struct bio
Internally, zvols are files exposed through the block device API. This
is intended to reduce overhead when things require block devices.
However, the ZoL zvol code emulates a traditional block device in that
it has a top half and a bottom half. This is an unnecessary source of
overhead that does not exist on any other OpenZFS platform does this.
This patch removes it. Early users of this patch reported double digit
performance gains in IOPS on zvols in the range of 50% to 80%.
Comments in the code suggest that the current implementation was done to
obtain IO merging from Linux's IO elevator. However, the DMU already
does write merging while arc_read() should implicitly merge read IOs
because only 1 thread is permitted to fetch the buffer into ARC. In
addition, commercial ZFSOnLinux distributions report that regular files
are more performant than zvols under the current implementation, and the
main consumers of zvols are VMs and iSCSI targets, which have their own
elevators to merge IOs.
Some minor refactoring allows us to register zfs_request() as our
->make_request() handler in place of the generic_make_request()
function. This eliminates the layer of code that broke IO requests on
zvols into a top half and a bottom half. This has several benefits:
1. No per zvol spinlocks.
2. No redundant IO elevator processing.
3. Interrupts are disabled only when actually necessary.
4. No redispatching of IOs when all taskq threads are busy.
5. Linux's page out routines will properly block.
6. Many autotools checks become obsolete.
An unfortunate consequence of eliminating the layer that
generic_make_request() is that we no longer calls the instrumentation
hooks for block IO accounting. Those hooks are GPL-exported, so we
cannot call them ourselves and consequently, we lose the ability to do
IO monitoring via iostat. Since zvols are internally files mapped as
block devices, this should be okay. Anyone who is willing to accept the
performance penalty for the block IO layer's accounting could use the
loop device in between the zvol and its consumer. Alternatively, perf
and ftrace likely could be used. Also, tools like latencytop will still
work. Tools such as latencytop sometimes provide a better view of
performance bottlenecks than the traditional block IO accounting tools
do.
Lastly, if direct reclaim occurs during spacemap loading and swap is on
a zvol, this code will deadlock. That deadlock could already occur with
sync=always on zvols. Given that swap on zvols is not yet production
ready, this is not a blocker.
Signed-off-by: Richard Yao <ryao@gentoo.org>
2014-07-04 22:43:47 +00:00
|
|
|
#endif
|
2016-08-09 18:22:30 +00:00
|
|
|
}
|
2011-06-16 18:20:22 +00:00
|
|
|
|
2011-09-02 13:23:12 +00:00
|
|
|
/*
|
2016-08-09 18:22:30 +00:00
|
|
|
* 4.8 - 4.x API,
|
|
|
|
* REQ_OP_DISCARD
|
2016-07-27 17:55:32 +00:00
|
|
|
*
|
|
|
|
* 2.6.36 - 4.7 API,
|
|
|
|
* REQ_DISCARD
|
|
|
|
*
|
2016-08-09 18:22:30 +00:00
|
|
|
* 2.6.28 - 2.6.35 API,
|
|
|
|
* BIO_RW_DISCARD
|
2016-07-27 17:55:32 +00:00
|
|
|
*
|
|
|
|
* In all cases the normal I/O path is used for discards. The only
|
|
|
|
* difference is how the kernel tags individual I/Os as discards.
|
2016-08-11 21:58:13 +00:00
|
|
|
*
|
|
|
|
* Note that 2.6.32 era kernels provide both BIO_RW_DISCARD and REQ_DISCARD,
|
|
|
|
* where BIO_RW_DISCARD is the correct interface. Therefore, it is important
|
|
|
|
* that the HAVE_BIO_RW_DISCARD check occur before the REQ_DISCARD check.
|
2011-09-02 13:23:12 +00:00
|
|
|
*/
|
2016-07-27 17:55:32 +00:00
|
|
|
static inline boolean_t
|
|
|
|
bio_is_discard(struct bio *bio)
|
|
|
|
{
|
2016-08-09 18:22:30 +00:00
|
|
|
#if defined(HAVE_REQ_OP_DISCARD)
|
|
|
|
return (bio_op(bio) == REQ_OP_DISCARD);
|
|
|
|
#elif defined(HAVE_BIO_RW_DISCARD)
|
|
|
|
return (bio->bi_rw & (1 << BIO_RW_DISCARD));
|
2016-08-11 21:58:13 +00:00
|
|
|
#elif defined(REQ_DISCARD)
|
|
|
|
return (bio->bi_rw & REQ_DISCARD);
|
zvol processing should use struct bio
Internally, zvols are files exposed through the block device API. This
is intended to reduce overhead when things require block devices.
However, the ZoL zvol code emulates a traditional block device in that
it has a top half and a bottom half. This is an unnecessary source of
overhead that does not exist on any other OpenZFS platform does this.
This patch removes it. Early users of this patch reported double digit
performance gains in IOPS on zvols in the range of 50% to 80%.
Comments in the code suggest that the current implementation was done to
obtain IO merging from Linux's IO elevator. However, the DMU already
does write merging while arc_read() should implicitly merge read IOs
because only 1 thread is permitted to fetch the buffer into ARC. In
addition, commercial ZFSOnLinux distributions report that regular files
are more performant than zvols under the current implementation, and the
main consumers of zvols are VMs and iSCSI targets, which have their own
elevators to merge IOs.
Some minor refactoring allows us to register zfs_request() as our
->make_request() handler in place of the generic_make_request()
function. This eliminates the layer of code that broke IO requests on
zvols into a top half and a bottom half. This has several benefits:
1. No per zvol spinlocks.
2. No redundant IO elevator processing.
3. Interrupts are disabled only when actually necessary.
4. No redispatching of IOs when all taskq threads are busy.
5. Linux's page out routines will properly block.
6. Many autotools checks become obsolete.
An unfortunate consequence of eliminating the layer that
generic_make_request() is that we no longer calls the instrumentation
hooks for block IO accounting. Those hooks are GPL-exported, so we
cannot call them ourselves and consequently, we lose the ability to do
IO monitoring via iostat. Since zvols are internally files mapped as
block devices, this should be okay. Anyone who is willing to accept the
performance penalty for the block IO layer's accounting could use the
loop device in between the zvol and its consumer. Alternatively, perf
and ftrace likely could be used. Also, tools like latencytop will still
work. Tools such as latencytop sometimes provide a better view of
performance bottlenecks than the traditional block IO accounting tools
do.
Lastly, if direct reclaim occurs during spacemap loading and swap is on
a zvol, this code will deadlock. That deadlock could already occur with
sync=always on zvols. Given that swap on zvols is not yet production
ready, this is not a blocker.
Signed-off-by: Richard Yao <ryao@gentoo.org>
2014-07-04 22:43:47 +00:00
|
|
|
#else
|
2017-03-07 17:54:55 +00:00
|
|
|
/* potentially triggering the DMU_MAX_ACCESS assertion. */
|
|
|
|
#error "Allowing the build will cause discard requests to become writes."
|
2011-09-02 13:23:12 +00:00
|
|
|
#endif
|
2016-07-27 17:55:32 +00:00
|
|
|
}
|
2016-08-09 18:22:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 4.8 - 4.x API,
|
|
|
|
* REQ_OP_SECURE_ERASE
|
|
|
|
*
|
|
|
|
* 2.6.36 - 4.7 API,
|
|
|
|
* REQ_SECURE
|
|
|
|
*
|
|
|
|
* 2.6.x - 2.6.35 API,
|
|
|
|
* Unsupported by kernel
|
|
|
|
*/
|
|
|
|
static inline boolean_t
|
|
|
|
bio_is_secure_erase(struct bio *bio)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_REQ_OP_SECURE_ERASE)
|
|
|
|
return (bio_op(bio) == REQ_OP_SECURE_ERASE);
|
|
|
|
#elif defined(REQ_SECURE)
|
|
|
|
return (bio->bi_rw & REQ_SECURE);
|
zvol processing should use struct bio
Internally, zvols are files exposed through the block device API. This
is intended to reduce overhead when things require block devices.
However, the ZoL zvol code emulates a traditional block device in that
it has a top half and a bottom half. This is an unnecessary source of
overhead that does not exist on any other OpenZFS platform does this.
This patch removes it. Early users of this patch reported double digit
performance gains in IOPS on zvols in the range of 50% to 80%.
Comments in the code suggest that the current implementation was done to
obtain IO merging from Linux's IO elevator. However, the DMU already
does write merging while arc_read() should implicitly merge read IOs
because only 1 thread is permitted to fetch the buffer into ARC. In
addition, commercial ZFSOnLinux distributions report that regular files
are more performant than zvols under the current implementation, and the
main consumers of zvols are VMs and iSCSI targets, which have their own
elevators to merge IOs.
Some minor refactoring allows us to register zfs_request() as our
->make_request() handler in place of the generic_make_request()
function. This eliminates the layer of code that broke IO requests on
zvols into a top half and a bottom half. This has several benefits:
1. No per zvol spinlocks.
2. No redundant IO elevator processing.
3. Interrupts are disabled only when actually necessary.
4. No redispatching of IOs when all taskq threads are busy.
5. Linux's page out routines will properly block.
6. Many autotools checks become obsolete.
An unfortunate consequence of eliminating the layer that
generic_make_request() is that we no longer calls the instrumentation
hooks for block IO accounting. Those hooks are GPL-exported, so we
cannot call them ourselves and consequently, we lose the ability to do
IO monitoring via iostat. Since zvols are internally files mapped as
block devices, this should be okay. Anyone who is willing to accept the
performance penalty for the block IO layer's accounting could use the
loop device in between the zvol and its consumer. Alternatively, perf
and ftrace likely could be used. Also, tools like latencytop will still
work. Tools such as latencytop sometimes provide a better view of
performance bottlenecks than the traditional block IO accounting tools
do.
Lastly, if direct reclaim occurs during spacemap loading and swap is on
a zvol, this code will deadlock. That deadlock could already occur with
sync=always on zvols. Given that swap on zvols is not yet production
ready, this is not a blocker.
Signed-off-by: Richard Yao <ryao@gentoo.org>
2014-07-04 22:43:47 +00:00
|
|
|
#else
|
2016-08-09 18:22:30 +00:00
|
|
|
return (0);
|
zvol processing should use struct bio
Internally, zvols are files exposed through the block device API. This
is intended to reduce overhead when things require block devices.
However, the ZoL zvol code emulates a traditional block device in that
it has a top half and a bottom half. This is an unnecessary source of
overhead that does not exist on any other OpenZFS platform does this.
This patch removes it. Early users of this patch reported double digit
performance gains in IOPS on zvols in the range of 50% to 80%.
Comments in the code suggest that the current implementation was done to
obtain IO merging from Linux's IO elevator. However, the DMU already
does write merging while arc_read() should implicitly merge read IOs
because only 1 thread is permitted to fetch the buffer into ARC. In
addition, commercial ZFSOnLinux distributions report that regular files
are more performant than zvols under the current implementation, and the
main consumers of zvols are VMs and iSCSI targets, which have their own
elevators to merge IOs.
Some minor refactoring allows us to register zfs_request() as our
->make_request() handler in place of the generic_make_request()
function. This eliminates the layer of code that broke IO requests on
zvols into a top half and a bottom half. This has several benefits:
1. No per zvol spinlocks.
2. No redundant IO elevator processing.
3. Interrupts are disabled only when actually necessary.
4. No redispatching of IOs when all taskq threads are busy.
5. Linux's page out routines will properly block.
6. Many autotools checks become obsolete.
An unfortunate consequence of eliminating the layer that
generic_make_request() is that we no longer calls the instrumentation
hooks for block IO accounting. Those hooks are GPL-exported, so we
cannot call them ourselves and consequently, we lose the ability to do
IO monitoring via iostat. Since zvols are internally files mapped as
block devices, this should be okay. Anyone who is willing to accept the
performance penalty for the block IO layer's accounting could use the
loop device in between the zvol and its consumer. Alternatively, perf
and ftrace likely could be used. Also, tools like latencytop will still
work. Tools such as latencytop sometimes provide a better view of
performance bottlenecks than the traditional block IO accounting tools
do.
Lastly, if direct reclaim occurs during spacemap loading and swap is on
a zvol, this code will deadlock. That deadlock could already occur with
sync=always on zvols. Given that swap on zvols is not yet production
ready, this is not a blocker.
Signed-off-by: Richard Yao <ryao@gentoo.org>
2014-07-04 22:43:47 +00:00
|
|
|
#endif
|
2016-08-09 18:22:30 +00:00
|
|
|
}
|
2011-09-02 13:23:12 +00:00
|
|
|
|
2012-08-01 08:29:59 +00:00
|
|
|
/*
|
|
|
|
* 2.6.33 API change
|
|
|
|
* Discard granularity and alignment restrictions may now be set. For
|
|
|
|
* older kernels which do not support this it is safe to skip it.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_DISCARD_GRANULARITY
|
|
|
|
static inline void
|
|
|
|
blk_queue_discard_granularity(struct request_queue *q, unsigned int dg)
|
|
|
|
{
|
|
|
|
q->limits.discard_granularity = dg;
|
|
|
|
}
|
|
|
|
#else
|
2013-11-01 19:26:11 +00:00
|
|
|
#define blk_queue_discard_granularity(x, dg) ((void)0)
|
2012-08-01 08:29:59 +00:00
|
|
|
#endif /* HAVE_DISCARD_GRANULARITY */
|
|
|
|
|
2019-03-29 16:13:20 +00:00
|
|
|
/*
|
|
|
|
* 2.6.32 - 4.x API,
|
|
|
|
* blk_queue_discard()
|
|
|
|
*/
|
|
|
|
#if !defined(HAVE_BLK_QUEUE_DISCARD)
|
|
|
|
#define blk_queue_discard(q) (0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 4.8 - 4.x API,
|
|
|
|
* blk_queue_secure_erase()
|
|
|
|
*
|
|
|
|
* 2.6.36 - 4.7 API,
|
|
|
|
* blk_queue_secdiscard()
|
|
|
|
*
|
|
|
|
* 2.6.x - 2.6.35 API,
|
|
|
|
* Unsupported by kernel
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
blk_queue_discard_secure(struct request_queue *q)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_BLK_QUEUE_SECURE_ERASE)
|
|
|
|
return (blk_queue_secure_erase(q));
|
|
|
|
#elif defined(HAVE_BLK_QUEUE_SECDISCARD)
|
|
|
|
return (blk_queue_secdiscard(q));
|
|
|
|
#else
|
|
|
|
return (0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-02-27 01:02:27 +00:00
|
|
|
/*
|
|
|
|
* A common holder for vdev_bdev_open() is used to relax the exclusive open
|
|
|
|
* semantics slightly. Internal vdev disk callers may pass VDEV_HOLDER to
|
|
|
|
* allow them to open the device multiple times. Other kernel callers and
|
|
|
|
* user space processes which don't pass this value will get EBUSY. This is
|
|
|
|
* currently required for the correct operation of hot spares.
|
|
|
|
*/
|
2013-11-01 19:26:11 +00:00
|
|
|
#define VDEV_HOLDER ((void *)0x2401de7)
|
2013-02-27 01:02:27 +00:00
|
|
|
|
2017-02-23 00:08:04 +00:00
|
|
|
static inline void
|
2017-09-16 18:00:19 +00:00
|
|
|
blk_generic_start_io_acct(struct request_queue *q, int rw,
|
|
|
|
unsigned long sectors, struct hd_struct *part)
|
2017-02-23 00:08:04 +00:00
|
|
|
{
|
2017-09-16 18:00:19 +00:00
|
|
|
#if defined(HAVE_GENERIC_IO_ACCT_3ARG)
|
|
|
|
generic_start_io_acct(rw, sectors, part);
|
|
|
|
#elif defined(HAVE_GENERIC_IO_ACCT_4ARG)
|
|
|
|
generic_start_io_acct(q, rw, sectors, part);
|
|
|
|
#endif
|
2017-02-23 00:08:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2017-09-16 18:00:19 +00:00
|
|
|
blk_generic_end_io_acct(struct request_queue *q, int rw,
|
|
|
|
struct hd_struct *part, unsigned long start_time)
|
2017-02-23 00:08:04 +00:00
|
|
|
{
|
2017-09-16 18:00:19 +00:00
|
|
|
#if defined(HAVE_GENERIC_IO_ACCT_3ARG)
|
|
|
|
generic_end_io_acct(rw, part, start_time);
|
|
|
|
#elif defined(HAVE_GENERIC_IO_ACCT_4ARG)
|
|
|
|
generic_end_io_acct(q, rw, part, start_time);
|
2015-09-07 16:03:19 +00:00
|
|
|
#endif
|
2017-09-16 18:00:19 +00:00
|
|
|
}
|
2015-09-07 16:03:19 +00:00
|
|
|
|
2011-02-22 20:15:13 +00:00
|
|
|
#endif /* _ZFS_BLKDEV_H */
|