From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:54448) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goQhO-0004YB-GB for qemu-devel@nongnu.org; Tue, 29 Jan 2019 05:33:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goQhN-0003Yd-OZ for qemu-devel@nongnu.org; Tue, 29 Jan 2019 05:32:58 -0500 MIME-Version: 1.0 References: <20190125164601.130556-1-vsementsov@virtuozzo.com> <20190129033155.GD3264@stefanha-x1.localdomain> In-Reply-To: From: Stefan Hajnoczi Date: Tue, 29 Jan 2019 18:32:44 +0800 Message-ID: Content-Type: text/plain; charset="UTF-8" Subject: Re: [Qemu-devel] [Qemu-block] [RFC PATCH] block: local qiov helper List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladimir Sementsov-Ogievskiy Cc: "qemu-devel@nongnu.org" , "qemu-block@nongnu.org" , "kwolf@redhat.com" , "fam@euphon.net" , "stefanha@redhat.com" , "mreitz@redhat.com" On Tue, Jan 29, 2019 at 6:24 PM Vladimir Sementsov-Ogievskiy wrote: > 29.01.2019 6:31, Stefan Hajnoczi wrote: > > On Fri, Jan 25, 2019 at 07:46:01PM +0300, Vladimir Sementsov-Ogievskiy wrote: > Hmm. In this case we definitely will have tiny extra memory usage, but we gain beautiful > readability. > > So, like this: > > diff --git a/include/qemu/iov.h b/include/qemu/iov.h > index 5f433c7768..53de1b38bb 100644 > --- a/include/qemu/iov.h > +++ b/include/qemu/iov.h > @@ -134,9 +134,31 @@ typedef struct QEMUIOVector { > struct iovec *iov; > int niov; > int nalloc; > - size_t size; > + union { > + struct { > + void *__unused_iov_base; This could be struct iovec *iov for nalloc > 0 users. Must resist hackiness! :) > + size_t size; > + }; > + struct iovec local_iov; > + }; > } QEMUIOVector; That's clever and not too hacky. Please include a comment so the intent is clear: /* Save space by reusing the embedded iovec's size field as the total size field. Users with external iovecs don't use the embedded iovec so this is safe. */ Stefan