Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use freeuio() to free allocated uio #2

Open
wants to merge 12 commits into
base: freebsd
Choose a base branch
from
Open
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6580,7 +6580,7 @@ print_holds(boolean_t scripted, int nwidth, int tagwidth, nvlist_t *nvl,
if (scripted) {
if (parsable) {
(void) printf("%s\t%s\t%ld\n", zname,
tagname, time);
tagname, (unsigned long)time);
} else {
(void) printf("%s\t%s\t%s\n", zname,
tagname, tsbuf);
Expand All @@ -6589,7 +6589,7 @@ print_holds(boolean_t scripted, int nwidth, int tagwidth, nvlist_t *nvl,
if (parsable) {
(void) printf("%-*s %-*s %ld\n",
nwidth, zname, tagwidth,
tagname, time);
tagname, (unsigned long)time);
} else {
(void) printf("%-*s %-*s %s\n",
nwidth, zname, tagwidth,
Expand Down
13 changes: 12 additions & 1 deletion include/os/freebsd/spl/sys/simd_aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@
#include <machine/md_var.h>
#include <machine/pcb.h>

#ifdef _STANDALONE

#define kfpu_allowed() 0
#define kfpu_begin() do {} while (0)
#define kfpu_end() do {} while (0)

#else

#define kfpu_allowed() 1
#define kfpu_initialize(tsk) do {} while (0)
#define kfpu_begin() do { \
if (__predict_false(!is_fpu_kern_thread(0))) \
fpu_kern_enter(curthread, NULL, FPU_KERN_NOCTX); \
Expand All @@ -61,6 +68,10 @@
if (__predict_false(curthread->td_pcb->pcb_fpflags & PCB_FP_NOSAVE)) \
fpu_kern_leave(curthread, NULL); \
} while (0)

#endif

#define kfpu_initialize(tsk) do {} while (0)
#define kfpu_init() (0)
#define kfpu_fini() do {} while (0)

Expand Down
2 changes: 1 addition & 1 deletion include/os/freebsd/spl/sys/simd_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include <machine/elf.h>
#include <machine/md_var.h>

#define kfpu_allowed() 1
#define kfpu_allowed() 0
#define kfpu_initialize(tsk) do {} while (0)
#define kfpu_begin() do {} while (0)
#define kfpu_end() do {} while (0)
Expand Down
9 changes: 5 additions & 4 deletions include/os/freebsd/spl/sys/vnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ enum symfollow { NO_FOLLOW = NOFOLLOW };
#include <sys/syscallsubr.h>
#include <sys/vm.h>
#include <vm/vm_object.h>
#include <vm/vnode_pager.h>

typedef struct vop_vector vnodeops_t;
#define VOP_FID VOP_VPTOFH
Expand Down Expand Up @@ -100,11 +101,11 @@ vn_flush_cached_data(vnode_t *vp, boolean_t sync)
#else
if (vp->v_object->flags & OBJ_MIGHTBEDIRTY) {
#endif
int flags = sync ? OBJPC_SYNC : 0;
vn_lock(vp, LK_SHARED | LK_RETRY);
zfs_vmobject_wlock(vp->v_object);
vm_object_page_clean(vp->v_object, 0, 0, flags);
zfs_vmobject_wunlock(vp->v_object);
if (sync)
vnode_pager_clean_sync(vp);
else
vnode_pager_clean_async(vp);
VOP_UNLOCK1(vp);
}
}
Expand Down
13 changes: 8 additions & 5 deletions module/icp/algs/blake3/blake3_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@

#include "blake3_impl.h"

#if defined(__aarch64__) || \
#if !defined(OMIT_SIMD) && (defined(__aarch64__) || \
(defined(__x86_64) && defined(HAVE_SSE2)) || \
(defined(__PPC64__) && defined(__LITTLE_ENDIAN__))
(defined(__PPC64__) && defined(__LITTLE_ENDIAN__)))

Check failure on line 35 in module/icp/algs/blake3/blake3_impl.c

View workflow job for this annotation

GitHub Actions / checkstyle

indent by spaces instead of tabs

Check failure on line 35 in module/icp/algs/blake3/blake3_impl.c

View workflow job for this annotation

GitHub Actions / checkstyle

indent by spaces instead of tabs
#define USE_SIMD

Check failure on line 36 in module/icp/algs/blake3/blake3_impl.c

View workflow job for this annotation

GitHub Actions / checkstyle

#define followed by space instead of tab

Check failure on line 36 in module/icp/algs/blake3/blake3_impl.c

View workflow job for this annotation

GitHub Actions / checkstyle

#define followed by space instead of tab
#endif

#ifdef USE_SIMD
extern void ASMABI zfs_blake3_compress_in_place_sse2(uint32_t cv[8],
const uint8_t block[BLAKE3_BLOCK_LEN], uint8_t block_len,
uint64_t counter, uint8_t flags);
Expand Down Expand Up @@ -96,9 +99,7 @@
};
#endif

#if defined(__aarch64__) || \
(defined(__x86_64) && defined(HAVE_SSE2)) || \
(defined(__PPC64__) && defined(__LITTLE_ENDIAN__))
#ifdef USE_SIMD

extern void ASMABI zfs_blake3_compress_in_place_sse41(uint32_t cv[8],
const uint8_t block[BLAKE3_BLOCK_LEN], uint8_t block_len,
Expand Down Expand Up @@ -257,6 +258,7 @@

static const blake3_ops_t *const blake3_impls[] = {
&blake3_generic_impl,
#ifdef USE_SIMD
#if defined(__aarch64__) || \
(defined(__x86_64) && defined(HAVE_SSE2)) || \
(defined(__PPC64__) && defined(__LITTLE_ENDIAN__))
Expand All @@ -273,6 +275,7 @@
#if defined(__x86_64) && defined(HAVE_AVX512F) && defined(HAVE_AVX512VL)
&blake3_avx512_impl,
#endif
#endif
};

/* use the generic implementation functions */
Expand Down
2 changes: 1 addition & 1 deletion module/os/freebsd/spl/spl_taskq.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
{
taskq_t *tq = context;

#if defined(__amd64__) || defined(__i386__) || defined(__aarch64__)
#if defined(__amd64__) || defined(__aarch64__)

Check failure on line 203 in module/os/freebsd/spl/spl_taskq.c

View workflow job for this annotation

GitHub Actions / checkstyle

space or tab at end of line

Check failure on line 203 in module/os/freebsd/spl/spl_taskq.c

View workflow job for this annotation

GitHub Actions / checkstyle

space or tab at end of line
if (context != NULL && tsd_get(taskq_tsd) == NULL)
fpu_kern_thread(FPU_KERN_NORMAL);
#endif
Expand Down
11 changes: 10 additions & 1 deletion module/os/freebsd/spl/spl_uio.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
#include <sys/vnode.h>
#include <sys/zfs_znode.h>

/* XXX: should be an __FreeBSD_version check once API is upstream. */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The freeuio() interface is upstream already, and this bug is fixed in FreeBSD's copy of ZFS, but not in OpenZFS. I'll get that fixed (using a __FreeBSD_version check).

Copy link

@markjdb markjdb Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I misread, this is not fixed in FreeBSD (but that's harmless for now).

#ifndef UIO_EXT_IOVEC
void
freeuio(struct uio *uio)
{
free(uio, M_IOV);
}
#endif

int
zfs_uiomove(void *cp, size_t n, zfs_uio_rw_t dir, zfs_uio_t *uio)
{
Expand Down Expand Up @@ -77,7 +86,7 @@ zfs_uiocopy(void *p, size_t n, zfs_uio_rw_t rw, zfs_uio_t *uio, size_t *cbytes)
error = vn_io_fault_uiomove(p, n, uio_clone);
*cbytes = zfs_uio_resid(uio) - uio_clone->uio_resid;
if (uio_clone != &small_uio_clone)
free(uio_clone, M_IOV);
freeuio(uio_clone);
return (error);
}

Expand Down
4 changes: 1 addition & 3 deletions module/os/freebsd/zfs/zfs_vnops_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -6324,9 +6324,7 @@ zfs_freebsd_copy_file_range(struct vop_copy_file_range_args *ap)
bad_write_fallback:
if (mp != NULL)
vn_finished_write(mp);
error = vn_generic_copy_file_range(ap->a_invp, ap->a_inoffp,
ap->a_outvp, ap->a_outoffp, ap->a_lenp, ap->a_flags,
ap->a_incred, ap->a_outcred, ap->a_fsizetd);
error = ENOSYS;
return (error);
}
#endif
Expand Down
63 changes: 59 additions & 4 deletions module/zfs/lz4_zfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
int LZ4_uncompress_unknownOutputSize(const char *source, char *dest,
int isize, int maxOutputSize);

static kmem_cache_t *lz4_cache;
static void *lz4_alloc(int flags);
static void lz4_free(void *ctx);

size_t
lz4_compress_zfs(void *s_start, void *d_start, size_t s_len,
Expand Down Expand Up @@ -842,8 +843,7 @@
void *ctx;
int result;

ASSERT(lz4_cache != NULL);
ctx = kmem_cache_alloc(lz4_cache, KM_SLEEP);
ctx = lz4_alloc(KM_SLEEP);

/*
* out of kernel memory, gently fall through - this will disable
Expand All @@ -859,10 +859,29 @@
else
result = LZ4_compressCtx(ctx, source, dest, isize, osize);

kmem_cache_free(lz4_cache, ctx);
lz4_free(ctx);
return (result);
}

#ifdef __FreeBSD__
/*
* FreeBSD has 4, 8 and 16 KB malloc zones which can be used here.
* Should struct refTables get resized this may need to be revisited, hence
* compiler-time asserts.
*/
_Static_assert(sizeof(struct refTables) <= 16384,

Check failure on line 872 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

missing space between keyword and paren

Check failure on line 872 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

missing space between keyword and paren
"refTables too big for malloc");

Check failure on line 873 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

indent by spaces instead of tabs

Check failure on line 873 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

indent by spaces instead of tabs
_Static_assert((sizeof(struct refTables) % 4096) == 0,

Check failure on line 874 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

missing space between keyword and paren

Check failure on line 874 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

missing space between keyword and paren
"refTables not a multiple of page size");

Check failure on line 875 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

indent by spaces instead of tabs

Check failure on line 875 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

indent by spaces instead of tabs
#else
#define ZFS_LZ4_USE_CACHE

Check failure on line 877 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

#define followed by space instead of tab

Check failure on line 877 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

#define followed by space instead of tab
#endif

#ifdef ZFS_LZ4_USE_CACHE
static kmem_cache_t *lz4_cache;
#endif

#ifdef ZFS_LZ4_USE_CACHE
void
lz4_init(void)
{
Expand All @@ -878,3 +897,39 @@
lz4_cache = NULL;
}
}

static void *
lz4_alloc(int flags)
{
ASSERT(lz4_cache != NULL);
return (kmem_cache_alloc(lz4_cache, flags));
}

Check failure on line 907 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

space or tab at end of line

Check failure on line 907 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

indent by spaces instead of tabs

Check failure on line 907 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

space or tab at end of line

Check failure on line 907 in module/zfs/lz4_zfs.c

View workflow job for this annotation

GitHub Actions / checkstyle

indent by spaces instead of tabs
static void
lz4_free(void *ctx)
{
kmem_cache_free(lz4_cache, ctx);
}
#else
void
lz4_init(void)
{
}

void
lz4_fini(void)
{
}

static void *
lz4_alloc(int flags)
{
return (kmem_alloc(sizeof (struct refTables), flags));
}

static void
lz4_free(void *ctx)
{
kmem_free(ctx, sizeof (struct refTables));
}
#endif
18 changes: 17 additions & 1 deletion module/zstd/zfs_zstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@
#include "lib/zstd.h"
#include "lib/common/zstd_errors.h"

#ifndef IN_LIBSA
static uint_t zstd_earlyabort_pass = 1;
static int zstd_cutoff_level = ZIO_ZSTD_LEVEL_3;
static unsigned int zstd_abort_size = (128 * 1024);
#endif

static kstat_t *zstd_ksp = NULL;

Expand Down Expand Up @@ -180,16 +182,20 @@ struct zstd_levelmap {
*
* The ZSTD handlers were split up for the most simplified implementation.
*/
#ifndef IN_LIBSA
static void *zstd_alloc(void *opaque, size_t size);
#endif
static void *zstd_dctx_alloc(void *opaque, size_t size);
static void zstd_free(void *opaque, void *ptr);

#ifndef IN_LIBSA
/* Compression memory handler */
static const ZSTD_customMem zstd_malloc = {
zstd_alloc,
zstd_free,
NULL,
};
#endif

/* Decompression memory handler */
static const ZSTD_customMem zstd_dctx_malloc = {
Expand Down Expand Up @@ -429,7 +435,7 @@ zstd_enum_to_level(enum zio_zstd_levels level, int16_t *zstd_level)
return (1);
}


#ifndef IN_LIBSA
size_t
zfs_zstd_compress_wrap(void *s_start, void *d_start, size_t s_len, size_t d_len,
int level)
Expand Down Expand Up @@ -593,6 +599,7 @@ zfs_zstd_compress(void *s_start, void *d_start, size_t s_len, size_t d_len,

return (c_len + sizeof (*hdr));
}
#endif

/* Decompress block using zstd and return its stored level */
int
Expand Down Expand Up @@ -680,6 +687,7 @@ zfs_zstd_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len,
NULL));
}

#ifndef IN_LIBSA
/* Allocator for zstd compression context using mempool_allocator */
static void *
zstd_alloc(void *opaque __maybe_unused, size_t size)
Expand All @@ -696,6 +704,7 @@ zstd_alloc(void *opaque __maybe_unused, size_t size)

return ((void*)z + (sizeof (struct zstd_kmem)));
}
#endif

/*
* Allocator for zstd decompression context using mempool_allocator with
Expand Down Expand Up @@ -844,6 +853,13 @@ zstd_mempool_deinit(void)
void
zfs_zstd_cache_reap_now(void)
{

/*
* Short-circuit if there are no buffers to begin with.
*/
if (ZSTDSTAT(zstd_stat_buffers) == 0)
return;

/*
* calling alloc with zero size seeks
* and releases old unused objects
Expand Down
1 change: 0 additions & 1 deletion scripts/zfs-images
Submodule zfs-images deleted from 333160
Loading