Received: from eggs.gnu.org ([2001:4830:134:3::10]:39334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTmzw-0003rt-V6 for qemu-devel@nongnu.org; Tue, 16 Sep 2014 03:16:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XTmzq-0001kE-PC for qemu-devel@nongnu.org; Tue, 16 Sep 2014 03:16:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36216) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTmzq-0001jx-HP for qemu-devel@nongnu.org; Tue, 16 Sep 2014 03:16:18 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8G7GDAW002830 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 16 Sep 2014 03:16:14 -0400 Date: Tue, 16 Sep 2014 15:16:11 +0800 From: Fam Zheng Message-ID: <20140916071611.GA21826@fam-t430.nay.redhat.com> References: <1410758605-29375-1-git-send-email-famz@redhat.com> <1410758605-29375-3-git-send-email-famz@redhat.com> <5416BCB0.30502@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5416BCB0.30502@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 2/2] virtio-scsi: Optimize virtio_scsi_init_req List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org On Mon, 09/15 12:17, Paolo Bonzini wrote: > Il 15/09/2014 07:23, Fam Zheng ha scritto: > > SCSIRequest *sreq; > > size_t resp_size; > > enum SCSIXferMode mode; > > - QEMUIOVector resp_iov; > > union { > > VirtIOSCSICmdResp cmd; > > VirtIOSCSICtrlTMFResp tmf; > > @@ -68,23 +75,27 @@ static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun) > > static VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq) > > { > > VirtIOSCSIReq *req; > > - VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s); > > - > > - req = g_malloc0(sizeof(*req) + vs->cdb_size); > > + VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s; > > + const size_t zero_skip = offsetof(VirtIOSCSIReq, elem) > > + + sizeof(VirtQueueElement); > > > > + req = g_slice_alloc(sizeof(*req) + vs->cdb_size); > > Looks good, but why do you need to zero the union? You only need to > zero sreq, resp_size and mode, don't you (and at this point, memset > becomes superfluous)? > The structures in unions are not zeroed by caller, also leaving them breaks virtio-scsi in my test. FWIW, I will remove the "req->sreq = NULL;" two lines below in v3. At this point tuning these small fields are subtle optimization compared to the arrays, I say let's just simply keep the memset so that adding more fields in the future are also safe. Fam