Index: sys/cam/cam_xpt.c =================================================================== --- sys/cam/cam_xpt.c +++ sys/cam/cam_xpt.c @@ -54,6 +54,8 @@ #include #include +#include + #include #include #include @@ -94,9 +96,6 @@ /* Datastructures internal to the xpt layer */ MALLOC_DEFINE(M_CAMXPT, "CAM XPT", "CAM XPT buffers"); -MALLOC_DEFINE(M_CAMDEV, "CAM DEV", "CAM devices"); -MALLOC_DEFINE(M_CAMCCB, "CAM CCB", "CAM CCBs"); -MALLOC_DEFINE(M_CAMPATH, "CAM path", "CAM paths"); struct xpt_softc { uint32_t xpt_generation; @@ -188,6 +187,10 @@ static periph_init_t xpt_periph_init; +static uma_zone_t __read_mostly camccbzone; +static uma_zone_t __read_mostly camdevicezone; +static uma_zone_t __read_mostly campathzone; + static struct periph_driver xpt_driver = { xpt_periph_init, "xpt", @@ -900,6 +903,13 @@ xsoftc.xpt_taskq = taskqueue_create("CAM XPT task", M_WAITOK, taskqueue_thread_enqueue, /*context*/&xsoftc.xpt_taskq); + camccbzone = uma_zcreate("cam_ccb", sizeof (union ccb), + NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); + camdevicezone = uma_zcreate("cam_device", sizeof (struct cam_ed), + NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); + campathzone = uma_zcreate("cam_path", sizeof (struct cam_path), + NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); + #ifdef CAM_BOOT_DELAY /* * Override this value at compile time to assist our users @@ -3555,6 +3565,12 @@ } /* Path manipulation functions */ +static struct cam_path * +xpt_alloc_path() +{ + return uma_zalloc(campathzone, M_NOWAIT); +} + cam_status xpt_create_path(struct cam_path **new_path_ptr, struct cam_periph *perph, path_id_t path_id, target_id_t target_id, lun_id_t lun_id) @@ -3562,7 +3578,7 @@ struct cam_path *path; cam_status status; - path = (struct cam_path *)malloc(sizeof(*path), M_CAMPATH, M_NOWAIT); + path = xpt_alloc_path(); if (path == NULL) { status = CAM_RESRC_UNAVAIL; @@ -3570,7 +3586,7 @@ } status = xpt_compile_path(path, perph, path_id, target_id, lun_id); if (status != CAM_REQ_CMP) { - free(path, M_CAMPATH); + uma_zfree(campathzone, path); path = NULL; } *new_path_ptr = path; @@ -3668,7 +3684,7 @@ { struct cam_path *new_path; - new_path = (struct cam_path *)malloc(sizeof(*path), M_CAMPATH, M_NOWAIT); + new_path = xpt_alloc_path(); if (new_path == NULL) return(CAM_RESRC_UNAVAIL); *new_path = *path; @@ -3706,7 +3722,7 @@ CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_free_path\n")); xpt_release_path(path); - free(path, M_CAMPATH); + uma_zfree(campathzone, path); } void @@ -4651,7 +4667,7 @@ { union ccb *new_ccb; - new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_WAITOK); + new_ccb = uma_zalloc(camccbzone, M_ZERO|M_WAITOK); return (new_ccb); } @@ -4660,14 +4676,14 @@ { union ccb *new_ccb; - new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_NOWAIT); + new_ccb = uma_zalloc(camccbzone, M_ZERO|M_NOWAIT); return (new_ccb); } void xpt_free_ccb(union ccb *free_ccb) { - free(free_ccb, M_CAMCCB); + uma_zfree(camccbzone, free_ccb); } /* Private XPT functions */ @@ -4682,7 +4698,7 @@ { union ccb *new_ccb; - new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_NOWAIT); + new_ccb = xpt_alloc_ccb_nowait(); if (new_ccb == NULL) return (NULL); periph->periph_allocated++; @@ -4696,7 +4712,7 @@ union ccb *new_ccb; cam_periph_unlock(periph); - new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_WAITOK); + new_ccb = xpt_alloc_ccb(); cam_periph_lock(periph); periph->periph_allocated++; cam_ccbq_take_opening(&periph->path->device->ccbq); @@ -4845,7 +4861,7 @@ mtx_lock(&device->device_mtx); mtx_destroy(&device->device_mtx); - free(device, M_CAMDEV); + uma_zfree(camdevicezone, device); } struct cam_ed * @@ -4864,8 +4880,7 @@ if (status != CAM_REQ_CMP) return (NULL); - device = (struct cam_ed *)malloc(sizeof(*device), - M_CAMDEV, M_NOWAIT|M_ZERO); + device = uma_zalloc(camdevicezone, M_NOWAIT|M_ZERO); if (device == NULL) return (NULL); @@ -4875,7 +4890,7 @@ device->sim = bus->sim; if (cam_ccbq_init(&device->ccbq, bus->sim->max_dev_openings) != 0) { - free(device, M_CAMDEV); + uma_zfree(camdevicezone, device); return (NULL); } SLIST_INIT(&device->asyncs);