2016-07-22 18:52:49 +03: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
|
2022-07-12 00:16:13 +03:00
|
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
2016-07-22 18:52:49 +03:00
|
|
|
* 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 (c) 2014 by Chunwei Chen. All rights reserved.
|
single-chunk scatter ABDs can be treated as linear
Scatter ABD's are allocated from a number of pages. In contrast to
linear ABD's, these pages are disjoint in the kernel's virtual address
space, so they can't be accessed as a contiguous buffer. Therefore
routines that need a linear buffer (e.g. abd_borrow_buf() and friends)
must allocate a separate linear buffer (with zio_buf_alloc()), and copy
the contents of the pages to/from the linear buffer. This can have a
measurable performance overhead on some workloads.
https://github.com/zfsonlinux/zfs/commit/87c25d567fb7969b44c7d8af63990e
("abd_alloc should use scatter for >1K allocations") increased the use
of scatter ABD's, specifically switching 1.5K through 4K (inclusive)
buffers from linear to scatter. For workloads that access blocks whose
compressed sizes are in this range, that commit introduced an additional
copy into the read code path. For example, the
sequential_reads_arc_cached tests in the test suite were reduced by
around 5% (this is doing reads of 8K-logical blocks, compressed to 3K,
which are cached in the ARC).
This commit treats single-chunk scattered buffers as linear buffers,
because they are contiguous in the kernel's virtual address space.
All single-page (4K) ABD's can be represented this way. Some multi-page
ABD's can also be represented this way, if we were able to allocate a
single "chunk" (higher-order "page" which represents a power-of-2 series
of physically-contiguous pages). This is often the case for 2-page (8K)
ABD's.
Representing a single-entry scatter ABD as a linear ABD has the
performance advantage of avoiding the copy (and allocation) in
abd_borrow_buf_copy / abd_return_buf_copy. A performance increase of
around 5% has been observed for ARC-cached reads (of small blocks which
can take advantage of this), fixing the regression introduced by
87c25d567.
Note that this optimization is only possible because all physical memory
is always mapped into the kernel's address space. This is not the case
for HIGHMEM pages, so the optimization can not be made on 32-bit
systems.
Reviewed-by: Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes #8580
2019-06-11 19:02:31 +03:00
|
|
|
* Copyright (c) 2016, 2019 by Delphix. All rights reserved.
|
2016-07-22 18:52:49 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ABD_H
|
|
|
|
#define _ABD_H
|
|
|
|
|
|
|
|
#include <sys/isa_defs.h>
|
|
|
|
#include <sys/debug.h>
|
2020-07-30 02:35:33 +03:00
|
|
|
#include <sys/zfs_refcount.h>
|
2016-07-22 18:52:49 +03:00
|
|
|
#include <sys/uio.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-01-20 22:24:37 +03:00
|
|
|
typedef enum abd_flags {
|
|
|
|
ABD_FLAG_LINEAR = 1 << 0, /* is buffer linear (or scattered)? */
|
|
|
|
ABD_FLAG_OWNER = 1 << 1, /* does it own its data buffers? */
|
|
|
|
ABD_FLAG_META = 1 << 2, /* does this represent FS metadata? */
|
|
|
|
ABD_FLAG_MULTI_ZONE = 1 << 3, /* pages split over memory zones */
|
|
|
|
ABD_FLAG_MULTI_CHUNK = 1 << 4, /* pages split over multiple chunks */
|
|
|
|
ABD_FLAG_LINEAR_PAGE = 1 << 5, /* linear but allocd from page */
|
|
|
|
ABD_FLAG_GANG = 1 << 6, /* mult ABDs chained together */
|
|
|
|
ABD_FLAG_GANG_FREE = 1 << 7, /* gang ABD is responsible for mem */
|
|
|
|
ABD_FLAG_ZEROS = 1 << 8, /* ABD for zero-filled buffer */
|
|
|
|
ABD_FLAG_ALLOCD = 1 << 9, /* we allocated the abd_t */
|
|
|
|
} abd_flags_t;
|
|
|
|
|
|
|
|
typedef struct abd {
|
|
|
|
abd_flags_t abd_flags;
|
|
|
|
uint_t abd_size; /* excludes scattered abd_offset */
|
|
|
|
list_node_t abd_gang_link;
|
2021-01-30 21:04:42 +03:00
|
|
|
#ifdef ZFS_DEBUG
|
2021-01-20 22:24:37 +03:00
|
|
|
struct abd *abd_parent;
|
|
|
|
zfs_refcount_t abd_children;
|
2021-01-30 21:04:42 +03:00
|
|
|
#endif
|
2021-01-20 22:24:37 +03:00
|
|
|
kmutex_t abd_mtx;
|
|
|
|
union {
|
|
|
|
struct abd_scatter {
|
|
|
|
uint_t abd_offset;
|
|
|
|
#if defined(__FreeBSD__) && defined(_KERNEL)
|
|
|
|
void *abd_chunks[1]; /* actually variable-length */
|
|
|
|
#else
|
|
|
|
uint_t abd_nents;
|
|
|
|
struct scatterlist *abd_sgl;
|
|
|
|
#endif
|
|
|
|
} abd_scatter;
|
|
|
|
struct abd_linear {
|
|
|
|
void *abd_buf;
|
|
|
|
struct scatterlist *abd_sgl; /* for LINEAR_PAGE */
|
|
|
|
} abd_linear;
|
|
|
|
struct abd_gang {
|
|
|
|
list_t abd_gang_chain;
|
|
|
|
} abd_gang;
|
|
|
|
} abd_u;
|
|
|
|
} abd_t;
|
2016-07-22 18:52:49 +03:00
|
|
|
|
2020-06-06 22:54:04 +03:00
|
|
|
typedef int abd_iter_func_t(void *buf, size_t len, void *priv);
|
|
|
|
typedef int abd_iter_func2_t(void *bufa, void *bufb, size_t len, void *priv);
|
2023-12-11 08:05:54 +03:00
|
|
|
#if defined(__linux__) && defined(_KERNEL)
|
|
|
|
typedef int abd_iter_page_func_t(struct page *, size_t, size_t, void *);
|
|
|
|
#endif
|
2016-07-22 18:52:49 +03:00
|
|
|
|
|
|
|
extern int zfs_abd_scatter_enabled;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocations and deallocations
|
|
|
|
*/
|
|
|
|
|
2023-05-27 01:47:52 +03:00
|
|
|
__attribute__((malloc))
|
2016-07-22 18:52:49 +03:00
|
|
|
abd_t *abd_alloc(size_t, boolean_t);
|
2023-05-27 01:47:52 +03:00
|
|
|
__attribute__((malloc))
|
2016-07-22 18:52:49 +03:00
|
|
|
abd_t *abd_alloc_linear(size_t, boolean_t);
|
2023-05-27 01:47:52 +03:00
|
|
|
__attribute__((malloc))
|
2021-01-20 22:24:37 +03:00
|
|
|
abd_t *abd_alloc_gang(void);
|
2023-05-27 01:47:52 +03:00
|
|
|
__attribute__((malloc))
|
2016-07-22 18:52:49 +03:00
|
|
|
abd_t *abd_alloc_for_io(size_t, boolean_t);
|
2023-05-27 01:47:52 +03:00
|
|
|
__attribute__((malloc))
|
2016-07-22 18:52:49 +03:00
|
|
|
abd_t *abd_alloc_sametype(abd_t *, size_t);
|
2021-07-28 02:05:47 +03:00
|
|
|
boolean_t abd_size_alloc_linear(size_t);
|
2020-05-21 04:06:09 +03:00
|
|
|
void abd_gang_add(abd_t *, abd_t *, boolean_t);
|
2016-07-22 18:52:49 +03:00
|
|
|
void abd_free(abd_t *);
|
|
|
|
abd_t *abd_get_offset(abd_t *, size_t);
|
2016-08-24 16:42:51 +03:00
|
|
|
abd_t *abd_get_offset_size(abd_t *, size_t, size_t);
|
2021-01-20 22:24:37 +03:00
|
|
|
abd_t *abd_get_offset_struct(abd_t *, abd_t *, size_t, size_t);
|
2020-05-21 04:06:09 +03:00
|
|
|
abd_t *abd_get_zeros(size_t);
|
2016-07-22 18:52:49 +03:00
|
|
|
abd_t *abd_get_from_buf(void *, size_t);
|
2020-06-18 07:44:13 +03:00
|
|
|
void abd_cache_reap_now(void);
|
2016-07-22 18:52:49 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Conversion to and from a normal buffer
|
|
|
|
*/
|
|
|
|
|
|
|
|
void *abd_to_buf(abd_t *);
|
|
|
|
void *abd_borrow_buf(abd_t *, size_t);
|
|
|
|
void *abd_borrow_buf_copy(abd_t *, size_t);
|
|
|
|
void abd_return_buf(abd_t *, void *, size_t);
|
|
|
|
void abd_return_buf_copy(abd_t *, void *, size_t);
|
|
|
|
void abd_take_ownership_of_buf(abd_t *, boolean_t);
|
|
|
|
void abd_release_ownership_of_buf(abd_t *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ABD operations
|
|
|
|
*/
|
|
|
|
|
|
|
|
int abd_iterate_func(abd_t *, size_t, size_t, abd_iter_func_t *, void *);
|
|
|
|
int abd_iterate_func2(abd_t *, abd_t *, size_t, size_t, size_t,
|
|
|
|
abd_iter_func2_t *, void *);
|
2023-12-11 08:05:54 +03:00
|
|
|
#if defined(__linux__) && defined(_KERNEL)
|
|
|
|
int abd_iterate_page_func(abd_t *, size_t, size_t, abd_iter_page_func_t *,
|
|
|
|
void *);
|
|
|
|
#endif
|
2016-07-22 18:52:49 +03:00
|
|
|
void abd_copy_off(abd_t *, abd_t *, size_t, size_t, size_t);
|
|
|
|
void abd_copy_from_buf_off(abd_t *, const void *, size_t, size_t);
|
|
|
|
void abd_copy_to_buf_off(void *, abd_t *, size_t, size_t);
|
|
|
|
int abd_cmp(abd_t *, abd_t *);
|
|
|
|
int abd_cmp_buf_off(abd_t *, const void *, size_t, size_t);
|
2024-08-10 00:30:26 +03:00
|
|
|
int abd_cmp_zero_off(abd_t *, size_t, size_t);
|
2016-07-22 18:52:49 +03:00
|
|
|
void abd_zero_off(abd_t *, size_t, size_t);
|
2020-05-10 22:23:52 +03:00
|
|
|
void abd_verify(abd_t *);
|
2016-08-31 09:26:43 +03:00
|
|
|
|
2023-10-31 00:54:27 +03:00
|
|
|
void abd_raidz_gen_iterate(abd_t **cabds, abd_t *dabd, size_t off,
|
|
|
|
size_t csize, size_t dsize, const unsigned parity,
|
2016-08-24 16:42:51 +03:00
|
|
|
void (*func_raidz_gen)(void **, const void *, size_t, size_t));
|
|
|
|
void abd_raidz_rec_iterate(abd_t **cabds, abd_t **tabds,
|
2023-10-31 00:54:27 +03:00
|
|
|
size_t tsize, const unsigned parity,
|
2016-08-24 16:42:51 +03:00
|
|
|
void (*func_raidz_rec)(void **t, const size_t tsize, void **c,
|
|
|
|
const unsigned *mul),
|
|
|
|
const unsigned *mul);
|
|
|
|
|
2016-07-22 18:52:49 +03:00
|
|
|
/*
|
|
|
|
* Wrappers for calls with offsets of 0
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
abd_copy(abd_t *dabd, abd_t *sabd, size_t size)
|
|
|
|
{
|
|
|
|
abd_copy_off(dabd, sabd, 0, 0, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2017-06-26 13:46:45 +03:00
|
|
|
abd_copy_from_buf(abd_t *abd, const void *buf, size_t size)
|
2016-07-22 18:52:49 +03:00
|
|
|
{
|
|
|
|
abd_copy_from_buf_off(abd, buf, 0, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
abd_copy_to_buf(void* buf, abd_t *abd, size_t size)
|
|
|
|
{
|
|
|
|
abd_copy_to_buf_off(buf, abd, 0, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2017-06-26 13:46:45 +03:00
|
|
|
abd_cmp_buf(abd_t *abd, const void *buf, size_t size)
|
2016-07-22 18:52:49 +03:00
|
|
|
{
|
|
|
|
return (abd_cmp_buf_off(abd, buf, 0, size));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
abd_zero(abd_t *abd, size_t size)
|
|
|
|
{
|
|
|
|
abd_zero_off(abd, 0, size);
|
|
|
|
}
|
|
|
|
|
2024-08-10 00:30:26 +03:00
|
|
|
static inline int
|
|
|
|
abd_cmp_zero(abd_t *abd, size_t size)
|
|
|
|
{
|
|
|
|
return (abd_cmp_zero_off(abd, 0, size));
|
|
|
|
}
|
|
|
|
|
2020-05-10 22:23:52 +03:00
|
|
|
/*
|
|
|
|
* ABD type check functions
|
|
|
|
*/
|
2021-01-20 22:24:37 +03:00
|
|
|
static inline boolean_t
|
|
|
|
abd_is_linear(abd_t *abd)
|
|
|
|
{
|
2021-02-15 21:15:50 +03:00
|
|
|
return ((abd->abd_flags & ABD_FLAG_LINEAR) ? B_TRUE : B_FALSE);
|
2021-01-20 22:24:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline boolean_t
|
|
|
|
abd_is_linear_page(abd_t *abd)
|
|
|
|
{
|
2021-02-15 21:15:50 +03:00
|
|
|
return ((abd->abd_flags & ABD_FLAG_LINEAR_PAGE) ? B_TRUE : B_FALSE);
|
2021-01-20 22:24:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline boolean_t
|
|
|
|
abd_is_gang(abd_t *abd)
|
|
|
|
{
|
2021-02-15 21:15:50 +03:00
|
|
|
return ((abd->abd_flags & ABD_FLAG_GANG) ? B_TRUE : B_FALSE);
|
2021-01-20 22:24:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint_t
|
|
|
|
abd_get_size(abd_t *abd)
|
|
|
|
{
|
|
|
|
return (abd->abd_size);
|
|
|
|
}
|
2020-05-10 22:23:52 +03:00
|
|
|
|
2016-07-22 18:52:49 +03:00
|
|
|
/*
|
|
|
|
* Module lifecycle
|
2020-05-10 22:23:52 +03:00
|
|
|
* Defined in each specific OS's abd_os.c
|
2016-07-22 18:52:49 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void abd_init(void);
|
|
|
|
void abd_fini(void);
|
|
|
|
|
2020-05-10 22:23:52 +03:00
|
|
|
/*
|
|
|
|
* Linux ABD bio functions
|
2024-01-09 04:12:56 +03:00
|
|
|
* Note: these are only needed to support vdev_classic. See comment in
|
|
|
|
* vdev_disk.c.
|
2020-05-10 22:23:52 +03:00
|
|
|
*/
|
|
|
|
#if defined(__linux__) && defined(_KERNEL)
|
2020-05-21 04:06:09 +03:00
|
|
|
unsigned int abd_bio_map_off(struct bio *, abd_t *, unsigned int, size_t);
|
2020-05-10 22:23:52 +03:00
|
|
|
unsigned long abd_nr_pages_off(abd_t *, unsigned int, size_t);
|
|
|
|
#endif
|
|
|
|
|
2016-07-22 18:52:49 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _ABD_H */
|