Update the kmem_cache emulation to run its callbacks with

Solaris argument order.

No functional change intended.
This commit is contained in:
hannken 2019-05-23 08:32:30 +00:00
parent cdd738ef23
commit a4a3cea66e
7 changed files with 111 additions and 57 deletions

View File

@ -1578,9 +1578,6 @@ hdr_full_cons(void *vbuf, void *unused, int kmflag)
{
arc_buf_hdr_t *hdr = vbuf;
#ifdef __NetBSD__
hdr = unused;
#endif
bzero(hdr, HDR_FULL_SIZE);
cv_init(&hdr->b_l1hdr.b_cv, NULL, CV_DEFAULT, NULL);
refcount_create(&hdr->b_l1hdr.b_refcnt);
@ -1597,9 +1594,6 @@ hdr_l2only_cons(void *vbuf, void *unused, int kmflag)
{
arc_buf_hdr_t *hdr = vbuf;
#ifdef __NetBSD__
hdr = unused;
#endif
bzero(hdr, HDR_L2ONLY_SIZE);
arc_space_consume(HDR_L2ONLY_SIZE, ARC_SPACE_L2HDRS);
@ -1612,9 +1606,6 @@ buf_cons(void *vbuf, void *unused, int kmflag)
{
arc_buf_t *buf = vbuf;
#ifdef __NetBSD__
buf = unused;
#endif
bzero(buf, sizeof (arc_buf_t));
mutex_init(&buf->b_evict_lock, NULL, MUTEX_DEFAULT, NULL);
arc_space_consume(sizeof (arc_buf_t), ARC_SPACE_HDRS);

View File

@ -138,9 +138,6 @@ dbuf_cons(void *vdb, void *unused, int kmflag)
{
dmu_buf_impl_t *db = vdb;
#ifdef __NetBSD__
db = unused;
#endif
bzero(db, sizeof (dmu_buf_impl_t));
mutex_init(&db->db_mtx, NULL, MUTEX_DEFAULT, NULL);
cv_init(&db->db_changed, NULL, CV_DEFAULT, NULL);

View File

@ -107,9 +107,6 @@ dnode_cons(void *arg, void *unused, int kmflag)
dnode_t *dn = arg;
int i;
#ifdef __NetBSD__
dn = unused;
#endif
rw_init(&dn->dn_struct_rwlock, NULL, RW_DEFAULT, NULL);
mutex_init(&dn->dn_mtx, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&dn->dn_dbufs_mtx, NULL, MUTEX_DEFAULT, NULL);

View File

@ -212,9 +212,6 @@ sa_cache_constructor(void *buf, void *unused, int kmflag)
{
sa_handle_t *hdl = buf;
#ifdef __NetBSD__
hdl = unused;
#endif
mutex_init(&hdl->sa_lock, NULL, MUTEX_DEFAULT, NULL);
return (0);
}

View File

@ -130,9 +130,6 @@ zfs_znode_cache_constructor(void *buf, void *arg, int kmflags)
{
znode_t *zp = buf;
#ifdef __NetBSD__
zp = arg;
#endif
POINTER_INVALIDATE(&zp->z_zfsvfs);
list_link_init(&zp->z_link_node);

View File

@ -1,4 +1,4 @@
/* $NetBSD: kmem.c,v 1.1 2018/05/28 21:05:09 chs Exp $ */
/* $NetBSD: kmem.c,v 1.2 2019/05/23 08:32:30 hannken Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
@ -28,6 +28,102 @@
#include <sys/kmem.h>
struct kmem_cache {
pool_cache_t km_pool;
void *km_private;
int (*km_constructor)(void *, void *, int);
void (*km_destructor)(void *, void *);
void (*km_reclaim)(void *);
};
static int
solaris_constructor(void *private, void *object, int flag)
{
kmem_cache_t *km = private;
if (km->km_constructor)
return (*km->km_constructor)(object, km->km_private, flag);
return 0;
}
static void
solaris_destructor(void *private, void *object)
{
kmem_cache_t *km = private;
if (km->km_destructor)
(*km->km_destructor)(object, km->km_private);
}
static void
solaris_reclaim(void *private, int flag)
{
kmem_cache_t *km = private;
if (km->km_reclaim)
(*km->km_reclaim)(km->km_private);
}
kmem_cache_t *
kmem_cache_create(char *name, size_t bufsize, size_t align,
int (*constructor)(void *, void *, int), void (*destructor)(void *, void *),
void (*reclaim)(void *) __unused, void *private, vmem_t *vmp, int flags)
{
kmem_cache_t *km;
KASSERT(ISSET(flags, ~(KMC_NOTOUCH | KMC_NODEBUG)) == 0);
KASSERT(private == NULL);
KASSERT(vmp == NULL);
km = kmem_zalloc(sizeof(*km), KM_SLEEP);
km->km_private = private;
km->km_constructor = constructor;
km->km_destructor = destructor;
km->km_reclaim = reclaim;
km->km_pool = pool_cache_init(bufsize, align, 0, 0, name, NULL,
IPL_NONE, solaris_constructor, solaris_destructor, km);
if (km->km_pool == NULL) {
kmem_free(km, sizeof(*km));
return NULL;
}
if (reclaim)
pool_cache_set_drain_hook(km->km_pool, solaris_reclaim, km);
return km;
}
void
kmem_cache_destroy(kmem_cache_t *km)
{
pool_cache_destroy(km->km_pool);
kmem_free(km, sizeof(*km));
}
void *
kmem_cache_alloc(kmem_cache_t *km, int flags)
{
KASSERT(ISSET(flags, ~(KM_SLEEP | KM_NOSLEEP | KM_PUSHPAGE)) == 0);
return pool_cache_get(km->km_pool, flags);
}
void
kmem_cache_free(kmem_cache_t *km, void *object)
{
pool_cache_put(km->km_pool, object);
}
void
kmem_cache_reap_now(kmem_cache_t *km)
{
pool_cache_invalidate(km->km_pool);
}
#undef kmem_alloc
#undef kmem_zalloc
#undef kmem_free

View File

@ -1,5 +1,5 @@
/* $NetBSD: kmem.h,v 1.10 2018/05/28 21:05:10 chs Exp $ */
/* $NetBSD: kmem.h,v 1.11 2019/05/23 08:32:31 hannken Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@ -41,48 +41,27 @@
#define KM_NORMALPRI 0
#define KM_NODEBUG 0
#define KMC_NODEBUG 0
#define KMC_NOTOUCH 0
#define KMC_NOTOUCH 0x00010000
#define KMC_NODEBUG 0x00020000
typedef void kmem_cache_t;
struct kmem_cache;
typedef struct kmem_cache kmem_cache_t;
#define POINTER_IS_VALID(p) (!((uintptr_t)(p) & 0x3))
#define POINTER_INVALIDATE(pp) (*(pp) = (void *)((uintptr_t)(*(pp)) | 0x1))
void kmem_reap(void);
static inline kmem_cache_t *
kmem_cache_create(char *name, size_t bufsize, size_t align,
int (*constructor)(void *, void *, int), void (*destructor)(void *, void *),
void (*reclaim)(void *) __unused, void *private, vmem_t *vmp, int cflags)
{
pool_cache_t pc;
int flags = bufsize > PAGESIZE ? PR_NOALIGN : 0;
KASSERT(vmp == NULL);
pc = pool_cache_init(bufsize, align, 0, flags, name, NULL, IPL_NONE,
constructor, destructor, private);
if (pc != NULL && reclaim != NULL) {
pool_cache_set_drain_hook(pc, (void *)reclaim, private);
}
return pc;
}
static inline void *
kmem_cache_alloc(kmem_cache_t *cache, int flags)
{
return pool_cache_get(cache, flags);
}
#define kmem_cache_destroy(cache) pool_cache_destroy(cache)
#define kmem_cache_free(cache, buf) pool_cache_put(cache, buf)
#define kmem_cache_reap_now(cache) pool_cache_invalidate(cache)
kmem_cache_t *kmem_cache_create(char *, size_t, size_t,
int (*)(void *, void *, int), void (*)(void *, void *),
void (*)(void *), void *, vmem_t *, int);
void kmem_cache_destroy(kmem_cache_t *);
void *kmem_cache_alloc(kmem_cache_t *, int);
void kmem_cache_free(kmem_cache_t *, void *);
void kmem_cache_reap_now(kmem_cache_t *);
#define kmem_cache_set_move(cache, movefunc) do { } while (0)
#define heap_arena kmem_arena
#define kmem_cache_set_move(cache, movefunc) do { } while (0)
#define kmem_alloc solaris_kmem_alloc
#define kmem_zalloc solaris_kmem_zalloc
#define kmem_free solaris_kmem_free