From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:43447) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7iq3-0004f5-OH for qemu-devel@nongnu.org; Wed, 14 Mar 2012 03:41:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S7ipz-00012K-QG for qemu-devel@nongnu.org; Wed, 14 Mar 2012 03:41:39 -0400 Received: from mail-we0-f173.google.com ([74.125.82.173]:52001) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7ipz-00011h-EN for qemu-devel@nongnu.org; Wed, 14 Mar 2012 03:41:35 -0400 Received: by werp12 with SMTP id p12so1569119wer.4 for ; Wed, 14 Mar 2012 00:41:33 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <4F604B98.9090606@redhat.com> Date: Wed, 14 Mar 2012 08:41:12 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1331226917-6658-1-git-send-email-pbonzini@redhat.com> <1331226917-6658-7-git-send-email-pbonzini@redhat.com> <4F5A31B2.3050701@redhat.com> <4F5A46A1.4000508@redhat.com> <1331402560.8577.46.camel@watermelon.coderich.net> <4F5DEBCE.3040409@redhat.com> <1331665990.24052.42.camel@watermelon.coderich.net> In-Reply-To: <1331665990.24052.42.camel@watermelon.coderich.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC PATCH 06/17] block: use bdrv_{co, aio}_discard for write_zeroes operations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Laager Cc: qemu-devel@nongnu.org Il 13/03/2012 20:13, Richard Laager ha scritto: >> > To be completely correct, I suggest the following behavior: >>> > > 1. Add a discard boolean option to the disk layer. >>> > > 2. If discard is not specified: >>> > > * For files, detect a true/false value by comparing >>> > > stat.st_blocks != stat.st_size>>9. >>> > > * For devices, assume a fixed value (true?). >>> > > 3. If discard is true, issue discards. >>> > > 4. If discard is false, do not issue discards. >> > >> > The problem is, who will use this interface? > I'm a libvirt and virt-manager user; virt-manager already differentiates > between thin and thick provisioning. So I'm envisioning passing that > information to libvirt, which would save it in a config file and use > that to set discard=true vs. discard=false when using QEMU. Yeah, it could be set also at the pool level for libvirt. >>> > > * For SCSI, report an unmap_granularity to the guest as follows: >>> > > max(logical_block_size, discard_granularity) / logical_block_size >> > >> > This is more or less already in place later in the series. > I didn't see it. Which patch number? Patch 11: + discard_granularity = s->qdev.conf.discard_granularity; + if (discard_granularity == -1) { + s->qdev.conf.discard_granularity = s->qdev.conf.logical_block_size; + } else if (discard_granularity < s->qdev.conf.logical_block_size) { + error_report("scsi-block: invalid discard_granularity"); + return -1; + } else if (discard_granularity & (discard_granularity - 1)) { + error_report("scsi-block: discard_granularity not a power of two"); + return -1; + } > > If you have a new kernel that supports SEEK_HOLE/SEEK_DATA, it can also > > be done by skipping the zero write on known holes. > > > > This could even be done at the block layer level using bdrv_is_allocated. > > Would we want to make all write_zeros operations check for and skip > holes, or is write_zeros different from a discard in that it SHOULD/MUST > allocate space? I think that's pretty much the question to answer for this patch to graduate from the RFC state (the rest is just technicalities, so to speak). So far, write_zeros was intended to be an efficient operation (it avoids allocating a cluster in qed and will do the same in qcow3, which is why I decided to merge it with discard). >>> > > If we could probe for FALLOC_FL_PUNCH_HOLE support, then we could avoid >>> > > advertising discard support based on FALLOC_FL_PUNCH_HOLE when it is not >>> > > going to work. This would side step these problems. >> > >> > ... and introduce others when migrating if your datacenter doesn't have >> > homogeneous kernel versions and/or filesystems. :( > I hadn't thought of the migration issues. Thanks for bringing that up. > > Worst case, you end up doing a bunch of zero writing if and only if you > migrate from a discard_zeros_data host to one that doesn't (or doesn't > do discard at all). But this only lasts until the guest reboots > (assuming we also add a behavior of re-probing on guest reboot--or until > it shuts down if we don't or can't). As far as I can see, this is > unavoidable, though. And this is no worse than writing zeros ALL of the > time that fallocate() fails, which is the behavior of your patch series, > right? It is worse in that we do not want the hardware parameters exposed to the guest to change behind the scenes, except if you change the machine type or if you use the default unversioned type. > This might be another use case for a discard option on the disk. If some > but not all of one's hosts support discard, a system administrator might > want to set discard=0 to avoid this. A discard option is already there (discard_granularity=0). Libvirt could choose to expose it even now, but it would be of little use in the absence of support for unaligned discards. Paolo