Skip to content

Commit

Permalink
FreeBSD: use zero_region instead of allocating a dedicated page
Browse files Browse the repository at this point in the history
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Closes openzfs#13406
  • Loading branch information
mjguzik authored and andrewc12 committed Sep 23, 2022
1 parent b70c992 commit 298a2f6
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions module/os/freebsd/zfs/abd_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ static kstat_t *abd_ksp;
* memory by only using a single zero buffer for the scatter chunks.
*/
abd_t *abd_zero_scatter = NULL;
static char *abd_zero_buf = NULL;

static uint_t
abd_chunkcnt_for_bytes(size_t size)
Expand Down Expand Up @@ -241,26 +240,24 @@ abd_free_struct_impl(abd_t *abd)

/*
* Allocate scatter ABD of size SPA_MAXBLOCKSIZE, where
* each chunk in the scatterlist will be set to abd_zero_buf.
* each chunk in the scatterlist will be set to the same area.
*/
_Static_assert(ZERO_REGION_SIZE >= PAGE_SIZE, "zero_region too small");
static void
abd_alloc_zero_scatter(void)
{
uint_t i, n;

n = abd_chunkcnt_for_bytes(SPA_MAXBLOCKSIZE);
abd_zero_buf = kmem_cache_alloc(abd_chunk_cache, KM_PUSHPAGE);
memset(abd_zero_buf, 0, PAGE_SIZE);
abd_zero_scatter = abd_alloc_struct(SPA_MAXBLOCKSIZE);

abd_zero_scatter->abd_flags |= ABD_FLAG_OWNER | ABD_FLAG_ZEROS;
abd_zero_scatter->abd_size = SPA_MAXBLOCKSIZE;

ABD_SCATTER(abd_zero_scatter).abd_offset = 0;

for (i = 0; i < n; i++) {
ABD_SCATTER(abd_zero_scatter).abd_chunks[i] =
abd_zero_buf;
__DECONST(void *, zero_region);
}

ABDSTAT_BUMP(abdstat_scatter_cnt);
Expand All @@ -275,7 +272,6 @@ abd_free_zero_scatter(void)

abd_free_struct(abd_zero_scatter);
abd_zero_scatter = NULL;
kmem_cache_free(abd_chunk_cache, abd_zero_buf);
}

static int
Expand Down

0 comments on commit 298a2f6

Please sign in to comment.