From owner-svn-src-stable@freebsd.org Tue Jun 2 20:39:34 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E39642F9B1E; Tue, 2 Jun 2020 20:39:34 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49c3n25nvQz3Tfg; Tue, 2 Jun 2020 20:39:34 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C20A622B02; Tue, 2 Jun 2020 20:39:34 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 052KdYHh050547; Tue, 2 Jun 2020 20:39:34 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 052KdYjC050546; Tue, 2 Jun 2020 20:39:34 GMT (envelope-from mav@FreeBSD.org) Message-Id: <202006022039.052KdYjC050546@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Tue, 2 Jun 2020 20:39:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r361733 - stable/12/sys/cam/ctl X-SVN-Group: stable-12 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/12/sys/cam/ctl X-SVN-Commit-Revision: 361733 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Jun 2020 20:39:35 -0000 Author: mav Date: Tue Jun 2 20:39:34 2020 New Revision: 361733 URL: https://svnweb.freebsd.org/changeset/base/361733 Log: MFC r361590: Remove ctl_free_beio() LUN and ctl_io dependencies. This slightly simplifies the code, plus may be a ground for asynchronous buffer free. Modified: stable/12/sys/cam/ctl/ctl_backend_block.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/cam/ctl/ctl_backend_block.c ============================================================================== --- stable/12/sys/cam/ctl/ctl_backend_block.c Tue Jun 2 20:38:53 2020 (r361732) +++ stable/12/sys/cam/ctl/ctl_backend_block.c Tue Jun 2 20:39:34 2020 (r361733) @@ -162,7 +162,6 @@ struct ctl_be_block_lun { cbb_dispatch_t unmap; cbb_dispatch_t get_lba_status; cbb_getattr_t getattr; - uma_zone_t lun_zone; uint64_t size_blocks; uint64_t size_bytes; struct ctl_be_block_softc *softc; @@ -187,9 +186,10 @@ struct ctl_be_block_lun { struct ctl_be_block_softc { struct sx modify_lock; struct mtx lock; - uma_zone_t beio_zone; int num_luns; SLIST_HEAD(, ctl_be_block_lun) lun_list; + uma_zone_t beio_zone; + uma_zone_t buf_zone; }; static struct ctl_be_block_softc backend_block_softc; @@ -202,6 +202,7 @@ struct ctl_be_block_io { struct ctl_sg_entry sg_segs[CTLBLK_MAX_SEGS]; struct iovec xiovecs[CTLBLK_MAX_SEGS]; int bio_cmd; + int two_sglists; int num_segs; int num_bios_sent; int num_bios_done; @@ -310,32 +311,20 @@ ctl_alloc_beio(struct ctl_be_block_softc *softc) static void ctl_free_beio(struct ctl_be_block_io *beio) { - int duplicate_free; + struct ctl_be_block_softc *softc = beio->softc; int i; - duplicate_free = 0; - for (i = 0; i < beio->num_segs; i++) { - if (beio->sg_segs[i].addr == NULL) - duplicate_free++; + uma_zfree(softc->buf_zone, beio->sg_segs[i].addr); - uma_zfree(beio->lun->lun_zone, beio->sg_segs[i].addr); - beio->sg_segs[i].addr = NULL; - /* For compare we had two equal S/G lists. */ - if (ARGS(beio->io)->flags & CTL_LLF_COMPARE) { - uma_zfree(beio->lun->lun_zone, + if (beio->two_sglists) { + uma_zfree(softc->buf_zone, beio->sg_segs[i + CTLBLK_HALF_SEGS].addr); - beio->sg_segs[i + CTLBLK_HALF_SEGS].addr = NULL; } } - if (duplicate_free > 0) { - printf("%s: %d duplicate frees out of %d segments\n", __func__, - duplicate_free, beio->num_segs); - } - - uma_zfree(beio->softc->beio_zone, beio); + uma_zfree(softc->beio_zone, beio); } static void @@ -1272,6 +1261,7 @@ static void ctl_be_block_cw_dispatch_ws(struct ctl_be_block_lun *be_lun, union ctl_io *io) { + struct ctl_be_block_softc *softc = be_lun->softc; struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun; struct ctl_be_block_io *beio; struct ctl_lba_len_flags *lbalen; @@ -1336,7 +1326,7 @@ ctl_be_block_cw_dispatch_ws(struct ctl_be_block_lun *b } else seglen -= seglen % cbe_lun->blocksize; beio->sg_segs[i].len = seglen; - beio->sg_segs[i].addr = uma_zalloc(be_lun->lun_zone, M_WAITOK); + beio->sg_segs[i].addr = uma_zalloc(softc->buf_zone, M_WAITOK); DPRINTF("segment %d addr %p len %zd\n", i, beio->sg_segs[i].addr, beio->sg_segs[i].len); @@ -1590,10 +1580,12 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun, DPRINTF("%s at LBA %jx len %u @%ju\n", (beio->bio_cmd == BIO_READ) ? "READ" : "WRITE", (uintmax_t)lbalen->lba, lbalen->len, bptrlen->len); - if (lbalen->flags & CTL_LLF_COMPARE) + if (lbalen->flags & CTL_LLF_COMPARE) { + beio->two_sglists = 1; lbas = CTLBLK_HALF_IO_SIZE; - else + } else { lbas = CTLBLK_MAX_IO_SIZE; + } lbas = MIN(lbalen->len - bptrlen->len, lbas / cbe_lun->blocksize); beio->io_offset = (lbalen->lba + bptrlen->len) * cbe_lun->blocksize; beio->io_len = lbas * cbe_lun->blocksize; @@ -1607,17 +1599,17 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun, * Setup the S/G entry for this chunk. */ beio->sg_segs[i].len = min(CTLBLK_MAX_SEG, len_left); - beio->sg_segs[i].addr = uma_zalloc(be_lun->lun_zone, M_WAITOK); + beio->sg_segs[i].addr = uma_zalloc(softc->buf_zone, M_WAITOK); DPRINTF("segment %d addr %p len %zd\n", i, beio->sg_segs[i].addr, beio->sg_segs[i].len); /* Set up second segment for compare operation. */ - if (lbalen->flags & CTL_LLF_COMPARE) { + if (beio->two_sglists) { beio->sg_segs[i + CTLBLK_HALF_SEGS].len = beio->sg_segs[i].len; beio->sg_segs[i + CTLBLK_HALF_SEGS].addr = - uma_zalloc(be_lun->lun_zone, M_WAITOK); + uma_zalloc(softc->buf_zone, M_WAITOK); } beio->num_segs++; @@ -1627,7 +1619,7 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun, beio->beio_cont = ctl_be_block_next; io->scsiio.be_move_done = ctl_be_block_move_done; /* For compare we have separate S/G lists for read and datamove. */ - if (lbalen->flags & CTL_LLF_COMPARE) + if (beio->two_sglists) io->scsiio.kern_data_ptr = (uint8_t *)&beio->sg_segs[CTLBLK_HALF_SEGS]; else io->scsiio.kern_data_ptr = (uint8_t *)beio->sg_segs; @@ -2240,13 +2232,6 @@ ctl_be_block_create(struct ctl_be_block_softc *softc, mtx_init(&be_lun->io_lock, "ctlblock io", NULL, MTX_DEF); mtx_init(&be_lun->queue_lock, "ctlblock queue", NULL, MTX_DEF); cbe_lun->options = nvlist_clone(req->args_nvl); - be_lun->lun_zone = uma_zcreate("ctlblock", CTLBLK_MAX_SEG, - NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); - if (be_lun->lun_zone == NULL) { - snprintf(req->error_str, sizeof(req->error_str), - "error allocating UMA zone"); - goto bailout_error; - } if (params->flags & CTL_LUN_FLAG_DEV_TYPE) cbe_lun->lun_type = params->device_type; @@ -2416,8 +2401,6 @@ bailout_error: ctl_be_block_close(be_lun); if (be_lun->dev_path != NULL) free(be_lun->dev_path, M_CTLBLK); - if (be_lun->lun_zone != NULL) - uma_zdestroy(be_lun->lun_zone); nvlist_destroy(cbe_lun->options); mtx_destroy(&be_lun->queue_lock); mtx_destroy(&be_lun->io_lock); @@ -2612,7 +2595,6 @@ ctl_be_block_lun_shutdown(void *lun) taskqueue_free(be_lun->io_taskqueue); if (be_lun->disk_stats != NULL) devstat_remove_entry(be_lun->disk_stats); - uma_zdestroy(be_lun->lun_zone); nvlist_destroy(be_lun->cbe_lun.options); free(be_lun->dev_path, M_CTLBLK); mtx_destroy(&be_lun->queue_lock); @@ -2794,6 +2776,8 @@ ctl_be_block_init(void) mtx_init(&softc->lock, "ctlblock", NULL, MTX_DEF); softc->beio_zone = uma_zcreate("beio", sizeof(struct ctl_be_block_io), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); + softc->buf_zone = uma_zcreate("ctlblock", CTLBLK_MAX_SEG, + NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); SLIST_INIT(&softc->lun_list); return (0); } @@ -2819,6 +2803,7 @@ ctl_be_block_shutdown(void) mtx_lock(&softc->lock); } mtx_unlock(&softc->lock); + uma_zdestroy(softc->buf_zone); uma_zdestroy(softc->beio_zone); mtx_destroy(&softc->lock); sx_destroy(&softc->modify_lock);