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

WIP: Avoid kmem_alloc in IO path #667

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/sys/ldi_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
extern "C" {
#endif /* __cplusplus */


/*
* Buffer context for LDI strategy
*/
Expand All @@ -50,6 +51,11 @@ typedef struct ldi_buf {
uint64_t pad; /* Pad to 64 bytes */
} ldi_buf_t; /* XXX Currently 64b */

typedef struct vdev_buf {
ldi_buf_t vb_buf; /* buffer that describes the io */
void *vb_io; /* pointer back to the original zio_t */
} vdev_buf_t;

ldi_buf_t *ldi_getrbuf(int);
void ldi_freerbuf(ldi_buf_t *);
void ldi_bioinit(ldi_buf_t *);
Expand Down
10 changes: 1 addition & 9 deletions include/sys/vdev_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ struct vdev {

/* pool checkpoint related */
space_map_t *vdev_checkpoint_sm; /* contains reserved blocks */

boolean_t vdev_initialize_exit_wanted;
vdev_initializing_state_t vdev_initialize_state;
kthread_t *vdev_initialize_thread;
Expand Down Expand Up @@ -500,14 +500,6 @@ extern boolean_t vdev_obsolete_counts_are_precise(vdev_t *vd);
*/
int vdev_checkpoint_sm_object(vdev_t *vd);

/*
* The vdev_buf_t is used to translate between zio_t and buf_t, and back again.
*/
typedef struct vdev_buf {
ldi_buf_t vb_buf; /* buffer that describes the io */
zio_t *vb_io; /* pointer back to the original zio_t */
} vdev_buf_t;

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 6 additions & 0 deletions include/sys/zio.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <sys/avl.h>
#include <sys/fs/zfs.h>
#include <sys/zio_impl.h>
#include <sys/ldi_buf.h>


#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -489,6 +491,10 @@ struct zio {
kcondvar_t io_cv;
int io_allocator;

#if __APPLE__
vdev_buf_t io_ldi_buf;
#endif

/* FMA state */
zio_cksum_report_t *io_cksum_report;
uint64_t io_ena;
Expand Down
24 changes: 14 additions & 10 deletions module/zfs/ldi_iokit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include <IOKit/storage/IOBlockStorageDevice.h>
#include <IOKit/storage/IOStorageDeviceCharacteristics.h>

#include <sys/ldi_buf.h>

/*
* ZFS internal
*/
Expand Down Expand Up @@ -1176,10 +1178,10 @@ media_from_path(const char *path = 0)

/* Define an IOKit buffer for buf_strategy_iokit */
typedef struct ldi_iokit_buf {
IOMemoryDescriptor *iomem;
IOStorageCompletion iocompletion;
IOStorageAttributes ioattr;
} ldi_iokit_buf_t; /* XXX Currently 64b */
IOMemoryDescriptor *iomem;
IOStorageCompletion iocompletion;
IOStorageAttributes ioattr;
} ldi_iokit_buf_t; /* XXX Currently 64b */

/* Completion handler for IOKit strategy */
static void
Expand All @@ -1188,7 +1190,6 @@ ldi_iokit_io_intr(void *target, void *parameter,
{
ldi_iokit_buf_t *iobp = (ldi_iokit_buf_t *)target;
ldi_buf_t *lbp = (ldi_buf_t *)parameter;

#ifdef DEBUG
/* In debug builds, verify buffer pointers */
ASSERT3U(lbp, !=, 0);
Expand Down Expand Up @@ -1243,7 +1244,8 @@ ldi_iokit_io_intr(void *target, void *parameter,
}

/* Free IOKit buffer */
kmem_free(iobp, sizeof (ldi_iokit_buf_t));
//kmem_free(iobp, sizeof (ldi_iokit_buf_t));
FREE(iobp, M_TEMP);

/* Call original completion function */
if (lbp->b_iodone) {
Expand Down Expand Up @@ -1291,6 +1293,7 @@ buf_sync_strategy_iokit(ldi_buf_t *lbp, ldi_iokit_buf_t *iobp,
* IOStorageAttributes * attributes = 0,
* UInt64 * actualByteCount = 0);
*/

int
buf_strategy_iokit(ldi_buf_t *lbp, struct ldi_handle *lhp)
{
Expand All @@ -1309,8 +1312,9 @@ buf_strategy_iokit(ldi_buf_t *lbp, struct ldi_handle *lhp)
#endif /* DEBUG */

/* Allocate an IOKit buffer */
iobp = (ldi_iokit_buf_t *)kmem_alloc(sizeof (ldi_iokit_buf_t),
KM_SLEEP);
//iobp = (ldi_iokit_buf_t *)MALLOC(sizeof (ldi_iokit_buf_t));
MALLOC(iobp, ldi_iokit_buf_t *, sizeof (ldi_iokit_buf_t),M_TEMP,M_WAITOK);

if (!iobp) {
dprintf("%s couldn't allocate buf_iokit_t\n", __func__);
return (ENOMEM);
Expand Down Expand Up @@ -1346,7 +1350,7 @@ buf_strategy_iokit(ldi_buf_t *lbp, struct ldi_handle *lhp)
if (iobp->iomem) {
iobp->iomem->release();
}
kmem_free(iobp, sizeof (ldi_iokit_buf_t));
//kmem_free(iobp, sizeof (ldi_iokit_buf_t));
return (ENOMEM);
}

Expand All @@ -1355,7 +1359,7 @@ buf_strategy_iokit(ldi_buf_t *lbp, struct ldi_handle *lhp)
dprintf("%s device not online\n", __func__);
iobp->iomem->complete();
iobp->iomem->release();
kmem_free(iobp, sizeof (ldi_iokit_buf_t));
//kmem_free(iobp, sizeof (ldi_iokit_buf_t));
return (ENODEV);
}

Expand Down
7 changes: 4 additions & 3 deletions module/zfs/vdev_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ vdev_disk_io_intr(ldi_buf_t *bp)
0, zio->io_size, zio->io_abd->abd_size);
}

kmem_free(vb, sizeof (vdev_buf_t));
//kmem_free(vb, sizeof (vdev_buf_t));

zio_delay_interrupt(zio);
}
Expand Down Expand Up @@ -838,7 +838,8 @@ vdev_disk_io_start(zio_t *zio)

zio->io_target_timestamp = zio_handle_io_delay(zio);

vb = kmem_alloc(sizeof (vdev_buf_t), KM_SLEEP);
// vb = kmem_alloc(sizeof (vdev_buf_t), KM_SLEEP);
vb = &(zio->io_ldi_buf);

vb->vb_io = zio;
bp = &vb->vb_buf;
Expand Down Expand Up @@ -892,7 +893,7 @@ vdev_disk_io_start(zio_t *zio)
if (error != 0) {
dprintf("%s error from ldi_strategy %d\n", __func__, error);
zio->io_error = EIO;
kmem_free(vb, sizeof (vdev_buf_t));
//kmem_free(vb, sizeof (vdev_buf_t));
zio_execute(zio);
// zio_interrupt(zio);
}
Expand Down