From nobody Mon Sep 16 19:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1695283089; cv=none; d=zohomail.com; s=zohoarc; b=ZUaGmZsxe2w6mJUdvJistkP/6AUtaSSp+CwOoIirc2O8ayYo4qLo2D/wHvaeD9XSBJD2YMAfmhmiPyrvB64dKp+hKiX0jyW2QIcWcD5zuV4v9WqdEjA/wxUnmhDhe7jgUg5PuxYIM+nKetJudjAvC2vHlogvO24k8evB+VQ3ujs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695283089; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ELZYegetsxN4zobNnb3CLRbjaDug5+53RZ9LZ4iPoDo=; b=RxWLpDTaIrczOQ9IONoiAwTdPCDNjaGTzJRDFyNsXcLSRiDlUusj/bDBmUvm0d0NId2kCoHC877ty+RnD3HzVq3HceTA3I3oxvi5L6PxlHgCgRW/cfQHHvQeUBQwM4LidbK8P8FIct43j8Yrt8W4Z6+/fBAiZilCHLFAvsSwLTM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16952830899191007.2137112305201; Thu, 21 Sep 2023 00:58:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjEYt-00035C-BN; Thu, 21 Sep 2023 03:57:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qjEYS-0002hM-No; Thu, 21 Sep 2023 03:56:58 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qjEYQ-0002KG-6C; Thu, 21 Sep 2023 03:56:56 -0400 Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=iris.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1qjEWU-00BsUn-1C; Thu, 21 Sep 2023 09:55:07 +0200 To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Alexander Ivanov Subject: [PULL v2 17/22] parallels: naive implementation of allocate_clusters with used bitmap Date: Thu, 21 Sep 2023 09:54:55 +0200 Message-Id: <20230921075500.694585-18-den@openvz.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075500.694585-1-den@openvz.org> References: <20230921075500.694585-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=130.117.225.111; envelope-from=den@openvz.org; helo=relay.virtuozzo.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "Denis V. Lunev" From: "Denis V. Lunev" via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1695283091598100003 Content-Type: text/plain; charset="utf-8" The access to the bitmap is not optimized completely. Signed-off-by: Denis V. Lunev Reviewed-by: Alexander Ivanov --- block/parallels.c | 51 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index ec35237119..ebcdff8736 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -253,7 +253,7 @@ allocate_clusters(BlockDriverState *bs, int64_t sector_= num, { int ret =3D 0; BDRVParallelsState *s =3D bs->opaque; - int64_t pos, space, idx, to_allocate, i, len; + int64_t i, pos, idx, to_allocate, first_free, host_off; =20 pos =3D block_status(s, sector_num, nb_sectors, pnum); if (pos > 0) { @@ -276,15 +276,13 @@ allocate_clusters(BlockDriverState *bs, int64_t secto= r_num, */ assert(idx < s->bat_size && idx + to_allocate <=3D s->bat_size); =20 - space =3D to_allocate * s->tracks; - len =3D bdrv_co_getlength(bs->file->bs); - if (len < 0) { - return len; - } - if (s->data_end + space > (len >> BDRV_SECTOR_BITS)) { + first_free =3D find_first_zero_bit(s->used_bmap, s->used_bmap_size); + if (first_free =3D=3D s->used_bmap_size) { uint32_t new_usedsize; + int64_t space =3D to_allocate * s->tracks + s->prealloc_size; + + host_off =3D s->data_end * BDRV_SECTOR_SIZE; =20 - space +=3D s->prealloc_size; /* * We require the expanded size to read back as zero. If the * user permitted truncation, we try that; but if it fails, we @@ -313,6 +311,32 @@ allocate_clusters(BlockDriverState *bs, int64_t sector= _num, s->used_bmap =3D bitmap_zero_extend(s->used_bmap, s->used_bmap_siz= e, new_usedsize); s->used_bmap_size =3D new_usedsize; + } else { + int64_t next_used; + next_used =3D find_next_bit(s->used_bmap, s->used_bmap_size, first= _free); + + /* Not enough continuous clusters in the middle, adjust the size */ + if (next_used - first_free < to_allocate) { + to_allocate =3D next_used - first_free; + *pnum =3D (idx + to_allocate) * s->tracks - sector_num; + } + + host_off =3D s->data_start * BDRV_SECTOR_SIZE; + host_off +=3D first_free * s->cluster_size; + + /* + * No need to preallocate if we are using tail area from the above + * branch. In the other case we are likely re-using hole. Prealloc= ate + * the space if required by the prealloc_mode. + */ + if (s->prealloc_mode =3D=3D PRL_PREALLOC_MODE_FALLOCATE && + host_off < s->data_end * BDRV_SECTOR_SIZE) { + ret =3D bdrv_co_pwrite_zeroes(bs->file, host_off, + s->cluster_size * to_allocate, 0); + if (ret < 0) { + return ret; + } + } } =20 /* @@ -344,15 +368,18 @@ allocate_clusters(BlockDriverState *bs, int64_t secto= r_num, } } =20 - ret =3D mark_used(bs, s->used_bmap, s->used_bmap_size, - s->data_end << BDRV_SECTOR_BITS, to_allocate); + ret =3D mark_used(bs, s->used_bmap, s->used_bmap_size, host_off, to_al= locate); if (ret < 0) { /* Image consistency is broken. Alarm! */ return ret; } for (i =3D 0; i < to_allocate; i++) { - parallels_set_bat_entry(s, idx + i, s->data_end / s->off_multiplie= r); - s->data_end +=3D s->tracks; + parallels_set_bat_entry(s, idx + i, + host_off / BDRV_SECTOR_SIZE / s->off_multiplier); + host_off +=3D s->cluster_size; + } + if (host_off > s->data_end * BDRV_SECTOR_SIZE) { + s->data_end =3D host_off / BDRV_SECTOR_SIZE; } =20 return bat2sect(s, idx) + sector_num % s->tracks; --=20 2.34.1