From owner-svn-src-all@freebsd.org Thu Oct 12 21:25:12 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 54072E351AE; Thu, 12 Oct 2017 21:25:12 +0000 (UTC) (envelope-from asomers@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 mx1.freebsd.org (Postfix) with ESMTPS id 2FDD767A9F; Thu, 12 Oct 2017 21:25:12 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v9CLPBeH004345; Thu, 12 Oct 2017 21:25:11 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v9CLPBm7004344; Thu, 12 Oct 2017 21:25:11 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201710122125.v9CLPBm7004344@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Thu, 12 Oct 2017 21:25:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324568 - head/cddl/contrib/opensolaris/lib/libzfs/common X-SVN-Group: head X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: head/cddl/contrib/opensolaris/lib/libzfs/common X-SVN-Commit-Revision: 324568 X-SVN-Commit-Repository: base 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.23 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: Thu, 12 Oct 2017 21:25:12 -0000 Author: asomers Date: Thu Oct 12 21:25:11 2017 New Revision: 324568 URL: https://svnweb.freebsd.org/changeset/base/324568 Log: Optimize zpool_read_all_labels with AIO Read all labels in parallel instead of sequentially MFC after: 3 weeks X-MFC-With: 322854 Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D12495 Modified: head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c Modified: head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c ============================================================================== --- head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c Thu Oct 12 20:31:10 2017 (r324567) +++ head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c Thu Oct 12 21:25:11 2017 (r324568) @@ -42,6 +42,7 @@ * using our derived config, and record the results. */ +#include #include #include #include @@ -919,13 +920,17 @@ zpool_read_label(int fd, nvlist_t **config) * Given a file descriptor, read the label information and return an nvlist * describing the configuration, if there is one. * returns the number of valid labels found + * If a label is found, returns it via config. The caller is responsible for + * freeing it. */ int zpool_read_all_labels(int fd, nvlist_t **config) { struct stat64 statbuf; + struct aiocb aiocbs[VDEV_LABELS]; + struct aiocb *aiocbps[VDEV_LABELS]; int l; - vdev_label_t *label; + vdev_label_t *labels; uint64_t state, txg, size; int nlabels = 0; @@ -935,19 +940,39 @@ zpool_read_all_labels(int fd, nvlist_t **config) return (0); size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t); - if ((label = malloc(sizeof (vdev_label_t))) == NULL) + if ((labels = calloc(VDEV_LABELS, sizeof (vdev_label_t))) == NULL) return (0); + memset(aiocbs, 0, sizeof(aiocbs)); for (l = 0; l < VDEV_LABELS; l++) { + aiocbs[l].aio_fildes = fd; + aiocbs[l].aio_offset = label_offset(size, l); + aiocbs[l].aio_buf = &labels[l]; + aiocbs[l].aio_nbytes = sizeof(vdev_label_t); + aiocbs[l].aio_lio_opcode = LIO_READ; + aiocbps[l] = &aiocbs[l]; + } + + if (lio_listio(LIO_WAIT, aiocbps, VDEV_LABELS, NULL) != 0) { + if (errno == EAGAIN || errno == EINTR || errno == EIO) { + for (l = 0; l < VDEV_LABELS; l++) { + errno = 0; + int r = aio_error(&aiocbs[l]); + if (r != EINVAL) + (void)aio_return(&aiocbs[l]); + } + } + return (0); + } + + for (l = 0; l < VDEV_LABELS; l++) { nvlist_t *temp = NULL; - /* TODO: use aio_read so we can read al 4 labels in parallel */ - if (pread64(fd, label, sizeof (vdev_label_t), - label_offset(size, l)) != sizeof (vdev_label_t)) + if (aio_return(&aiocbs[l]) != sizeof(vdev_label_t)) continue; - if (nvlist_unpack(label->vl_vdev_phys.vp_nvlist, - sizeof (label->vl_vdev_phys.vp_nvlist), &temp, 0) != 0) + if (nvlist_unpack(labels[l].vl_vdev_phys.vp_nvlist, + sizeof (labels[l].vl_vdev_phys.vp_nvlist), &temp, 0) != 0) continue; if (nvlist_lookup_uint64(temp, ZPOOL_CONFIG_POOL_STATE, @@ -970,7 +995,7 @@ zpool_read_all_labels(int fd, nvlist_t **config) nlabels++; } - free(label); + free(labels); return (nlabels); }