From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYEua-0006vO-Il for qemu-devel@nongnu.org; Mon, 30 Jan 2017 11:34:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cYEuW-0002Kw-MB for qemu-devel@nongnu.org; Mon, 30 Jan 2017 11:34:36 -0500 From: Alberto Garcia In-Reply-To: <20170130161441.30493-1-berto@igalia.com> References: <20170130161441.30493-1-berto@igalia.com> Date: Mon, 30 Jan 2017 17:34:29 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] qcow2: Optimize the refcount-block overlap check List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Max Reitz , Kevin Wolf On Mon 30 Jan 2017 05:14:41 PM CET, Alberto Garcia wrote: > This patch keeps the index of the last used (i.e. non-zero) entry in > the refcount table and updates it every time the table changes. The > refcount-block overlap check then uses that index instead of reading > the whole table. Note that while I decided to go for this approach the patch can be made much simpler by simply stopping at the first empty entry in the refcount table: if ((chk & QCOW2_OL_REFCOUNT_BLOCK) && s->refcount_table) { for (i = 0; i < s->refcount_table_size; i++) { if (!(s->refcount_table[i] & REFT_OFFSET_MASK)) { break; } if (overlaps_with(s->refcount_table[i] & REFT_OFFSET_MASK, s->cluster_size)) { return QCOW2_OL_REFCOUNT_BLOCK; } } } I don't think QEMU produces files where refcount_table[i] == 0 but refcount_table[i + 1] != 0. Do they even make sense? In any case, my patch would cover those cases too, but this simplified version wouldn't. Berto