From owner-svn-src-all@FreeBSD.ORG Wed May 7 06:26:34 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C9991421; Wed, 7 May 2014 06:26:34 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A927C9CC; Wed, 7 May 2014 06:26:34 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s476QYQh087821; Wed, 7 May 2014 06:26:34 GMT (envelope-from trasz@svn.freebsd.org) Received: (from trasz@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s476QYoX087820; Wed, 7 May 2014 06:26:34 GMT (envelope-from trasz@svn.freebsd.org) Message-Id: <201405070626.s476QYoX087820@svn.freebsd.org> From: Edward Tomasz Napierala Date: Wed, 7 May 2014 06:26:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r265494 - stable/10/sys/cam/ctl X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 May 2014 06:26:35 -0000 Author: trasz Date: Wed May 7 06:26:34 2014 New Revision: 265494 URL: http://svnweb.freebsd.org/changeset/base/265494 Log: MFC r264020: Remove the homegrown ctl_be_block_io allocator, replacing it with UMA. There is no performance difference. Reviewed by: mav@ Sponsored by: The FreeBSD Foundation Modified: stable/10/sys/cam/ctl/ctl_backend_block.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/ctl/ctl_backend_block.c ============================================================================== --- stable/10/sys/cam/ctl/ctl_backend_block.c Wed May 7 06:24:46 2014 (r265493) +++ stable/10/sys/cam/ctl/ctl_backend_block.c Wed May 7 06:26:34 2014 (r265494) @@ -177,9 +177,7 @@ struct ctl_be_block_lun { * Overall softc structure for the block backend module. */ struct ctl_be_block_softc { - STAILQ_HEAD(, ctl_be_block_io) beio_free_queue; struct mtx lock; - int prealloc_beio; int num_disks; STAILQ_HEAD(, ctl_block_disk) disk_list; int num_luns; @@ -209,7 +207,6 @@ struct ctl_be_block_io { uint64_t io_offset; struct ctl_be_block_softc *softc; struct ctl_be_block_lun *lun; - STAILQ_ENTRY(ctl_be_block_io) links; }; static int cbb_num_threads = 14; @@ -221,10 +218,6 @@ SYSCTL_INT(_kern_cam_ctl_block, OID_AUTO static struct ctl_be_block_io *ctl_alloc_beio(struct ctl_be_block_softc *softc); static void ctl_free_beio(struct ctl_be_block_io *beio); -static int ctl_grow_beio(struct ctl_be_block_softc *softc, int count); -#if 0 -static void ctl_shrink_beio(struct ctl_be_block_softc *softc); -#endif static void ctl_complete_beio(struct ctl_be_block_io *beio); static int ctl_be_block_move_done(union ctl_io *io); static void ctl_be_block_biodone(struct bio *bio); @@ -286,68 +279,24 @@ static struct ctl_backend_driver ctl_be_ MALLOC_DEFINE(M_CTLBLK, "ctlblk", "Memory used for CTL block backend"); CTL_BACKEND_DECLARE(cbb, ctl_be_block_driver); +static uma_zone_t beio_zone; + static struct ctl_be_block_io * ctl_alloc_beio(struct ctl_be_block_softc *softc) { struct ctl_be_block_io *beio; - int count; - - mtx_lock(&softc->lock); - - beio = STAILQ_FIRST(&softc->beio_free_queue); - if (beio != NULL) { - STAILQ_REMOVE(&softc->beio_free_queue, beio, - ctl_be_block_io, links); - } - mtx_unlock(&softc->lock); - - if (beio != NULL) { - bzero(beio, sizeof(*beio)); - beio->softc = softc; - return (beio); - } - - for (;;) { - - count = ctl_grow_beio(softc, /*count*/ 10); - - /* - * This shouldn't be possible, since ctl_grow_beio() uses a - * blocking malloc. - */ - if (count == 0) - return (NULL); - - /* - * Since we have to drop the lock when we're allocating beio - * structures, it's possible someone else can come along and - * allocate the beio's we've just allocated. - */ - mtx_lock(&softc->lock); - beio = STAILQ_FIRST(&softc->beio_free_queue); - if (beio != NULL) { - STAILQ_REMOVE(&softc->beio_free_queue, beio, - ctl_be_block_io, links); - } - mtx_unlock(&softc->lock); - if (beio != NULL) { - bzero(beio, sizeof(*beio)); - beio->softc = softc; - break; - } - } + beio = uma_zalloc(beio_zone, M_WAITOK | M_ZERO); + beio->softc = softc; return (beio); } static void ctl_free_beio(struct ctl_be_block_io *beio) { - struct ctl_be_block_softc *softc; int duplicate_free; int i; - softc = beio->softc; duplicate_free = 0; for (i = 0; i < beio->num_segs; i++) { @@ -362,47 +311,10 @@ ctl_free_beio(struct ctl_be_block_io *be printf("%s: %d duplicate frees out of %d segments\n", __func__, duplicate_free, beio->num_segs); } - mtx_lock(&softc->lock); - STAILQ_INSERT_TAIL(&softc->beio_free_queue, beio, links); - mtx_unlock(&softc->lock); -} -static int -ctl_grow_beio(struct ctl_be_block_softc *softc, int count) -{ - int i; - - for (i = 0; i < count; i++) { - struct ctl_be_block_io *beio; - - beio = (struct ctl_be_block_io *)malloc(sizeof(*beio), - M_CTLBLK, - M_WAITOK | M_ZERO); - beio->softc = softc; - mtx_lock(&softc->lock); - STAILQ_INSERT_TAIL(&softc->beio_free_queue, beio, links); - mtx_unlock(&softc->lock); - } - - return (i); + uma_zfree(beio_zone, beio); } -#if 0 -static void -ctl_shrink_beio(struct ctl_be_block_softc *softc) -{ - struct ctl_be_block_io *beio, *beio_tmp; - - mtx_lock(&softc->lock); - STAILQ_FOREACH_SAFE(beio, &softc->beio_free_queue, links, beio_tmp) { - STAILQ_REMOVE(&softc->beio_free_queue, beio, - ctl_be_block_io, links); - free(beio, M_CTLBLK); - } - mtx_unlock(&softc->lock); -} -#endif - static void ctl_complete_beio(struct ctl_be_block_io *beio) { @@ -937,16 +849,7 @@ ctl_be_block_cw_dispatch(struct ctl_be_b softc = be_lun->softc; beio = ctl_alloc_beio(softc); - if (beio == NULL) { - /* - * This should not happen. ctl_alloc_beio() will call - * ctl_grow_beio() with a blocking malloc as needed. - * A malloc with M_WAITOK should not fail. - */ - ctl_set_busy(&io->scsiio); - ctl_done(io); - return; - } + KASSERT(beio != NULL, ("ctl_alloc_beio() failed")); beio->io = io; beio->softc = softc; @@ -1017,16 +920,7 @@ ctl_be_block_dispatch(struct ctl_be_bloc } beio = ctl_alloc_beio(softc); - if (beio == NULL) { - /* - * This should not happen. ctl_alloc_beio() will call - * ctl_grow_beio() with a blocking malloc as needed. - * A malloc with M_WAITOK should not fail. - */ - ctl_set_busy(&io->scsiio); - ctl_done(io); - return; - } + KASSERT(beio != NULL, ("ctl_alloc_beio() failed")); beio->io = io; beio->softc = softc; @@ -2369,10 +2263,10 @@ ctl_be_block_init(void) retval = 0; mtx_init(&softc->lock, "ctlblk", NULL, MTX_DEF); - STAILQ_INIT(&softc->beio_free_queue); + beio_zone = uma_zcreate("beio", sizeof(struct ctl_be_block_io), + NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); STAILQ_INIT(&softc->disk_list); STAILQ_INIT(&softc->lun_list); - ctl_grow_beio(softc, 200); return (retval); }