From nobody Mon Jun 8 08:52:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=reject dis=none) header.from=sourceandstack.com ARC-Seal: i=1; a=rsa-sha256; t=1780237155; cv=none; d=zohomail.com; s=zohoarc; b=nZtwNl9/h9w5MtihnY1qVIv58Ue9ukzKW3yyb6AK5JKi23u3Vk9mO3kPr33avl2uQfavYqb+y8nQrMkfzs+/7mxanz29aCGZHfSIXSiW4Yk0aN7aHtyCddqlQ0KWax3hj7UahQ927ZnZ9URz8dCaxlQR90YQJnt3jbeZuePi/uw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780237155; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=103yqLzOjXtSUCqjlF7j8Q7Yiuzj9PJND4QkQcMrx3M=; b=C526v3dfbgPQD29OGXh9RNx8HoWLaeUZNyV4Sr5eu46hF3RBbp+fpQfb/zsoiJN/xYYT+whgJ14BFb4npCXIxuDK2o/yEMaLunbLnIVPvF3fxnAp2QnImuOxmV58LC0aPY3JU6AV486RtLYhpx9aDJrLwgLYtK7QtKsJ/GRrkBQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17802371552243.8971432931640493; Sun, 31 May 2026 07:19:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wTh0G-0002lU-0D; Sun, 31 May 2026 10:19:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wTdUj-0005HN-1R; Sun, 31 May 2026 06:34:13 -0400 Received: from sourceandstack.com ([159.223.220.208]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wTdUh-0004mn-4x; Sun, 31 May 2026 06:34:12 -0400 Received: from fedora.home (apoitiers-157-1-11-96.w90-5.abo.wanadoo.fr [90.5.14.96]) by sourceandstack.com (Postfix) with ESMTPSA id E5EF7480393B; Sun, 31 May 2026 10:34:07 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceandstack.com E5EF7480393B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sourceandstack.com; s=mail; t=1780223648; bh=EnYS33h/AhF9AFXQzHm8U0FQ0sY2KKXuUydYAwZDAg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IPsVmk9su1yxpnYN/PcXgBmSS/Mezsi0BPpOaOXS83Qkm3MzBlQk+bL/kuLS8A5GE n9A0H3F+gbYm+kdu7BruMnChhK+c+eg7oGf7t7jO7Kw7J7t2Zi8DEqZ6QYNf/GAeZl JjBp7tV87goDNdW0AOtyXVFale80BzTZGBBmTvbI= From: Christian Hergert To: qemu-devel@nongnu.org Cc: Hanna Reitz , qemu-block@nongnu.org, Kevin Wolf , Christian Hergert Subject: [PATCH 1/1] block/vvfat: defer write commits to half-second timer Date: Sun, 31 May 2026 12:34:37 +0200 Message-ID: <20260531103437.2896462-2-christian@sourceandstack.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260531103437.2896462-1-christian@sourceandstack.com> References: <20260531103437.2896462-1-christian@sourceandstack.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: E5EF7480393B X-Spamd-Result: default: False [1.40 / 15.00]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; MIME_GOOD(-0.10)[text/plain]; LOCAL_OUTBOUND(0.00)[]; ASN(0.00)[asn:3215, ipnet:90.5.0.0/17, country:FR]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_ZERO(0.00)[0]; TO_MATCH_ENVRCPT_ALL(0.00)[]; URIBL_BLOCKED(0.00)[sourceandstack.com:from_mime,sourceandstack.com:mid,sourceandstack.com:from_smtp,sourceandstack.com:email]; FROM_HAS_DN(0.00)[] X-Rspamd-Action: no action X-Rspamd-Server: sourceandstack.com 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=lists1p.gnu.org; Received-SPF: pass client-ip=159.223.220.208; envelope-from=christian@sourceandstack.com; helo=sourceandstack.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 31 May 2026 10:18:14 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @sourceandstack.com) X-ZM-MESSAGEID: 1780237157010158500 Content-Type: text/plain; charset="utf-8" This keeps consistent reads but defers writes to a half-second timer by implementing the suggested TODO in block/vvfat.c. I noticed slow boot performance when testing a UKI image. It was roughly 18 seconds to a login prompt with a simple userspace. I profiled quickly with Sysprof which showed an overwhelming amount of time spent in check_directory_consistency(). The -drive in question here is the following: file=3Dfat:rw:/tmp/machines-uki-esp-HVCXP3,format=3Draw,media=3Ddisk which has a temporary NvVars in it for quick throwaway VM testing which I use in conjunction with mkosi. With this commit in place, boot to login reduces from 18 seconds to 6. Signed-off-by: Christian Hergert --- block/vvfat.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 125 insertions(+), 5 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index e334b9febb..49756ac5e0 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -32,6 +32,7 @@ #include "block/qdict.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qemu/timer.h" #include "qemu/bswap.h" #include "migration/blocker.h" #include "qobject/qdict.h" @@ -53,8 +54,6 @@ Note that DOS assumes the system files to be the first files in the file system (test if the boot sector still relies on that fact)! */ /* MAYBE TODO: write block-visofs.c */ -/* TODO: call try_commit() only after a timeout */ - /* #define DEBUG */ =20 #ifdef DEBUG @@ -80,6 +79,8 @@ static void checkpoint(void); #define DIR_KANJI_FAKE 0x05 #define DIR_FREE 0x00 =20 +#define VVFAT_COMMIT_DELAY_NS (NANOSECONDS_PER_SECOND / 2) + /* dynamic array functions */ typedef struct array_t { char* pointer; @@ -332,6 +333,8 @@ typedef struct BDRVVVFATState { void* fat2; char* used_clusters; array_t commits; + QEMUTimer *commit_timer; + bool commit_pending; const char* path; int downcase_short_names; =20 @@ -1052,6 +1055,8 @@ static BDRVVVFATState *vvv =3D NULL; =20 static int enable_write_target(BlockDriverState *bs, Error **errp); static int coroutine_fn is_consistent(BDRVVVFATState *s); +static void vvfat_attach_aio_context(BlockDriverState *bs, + AioContext *new_context); =20 static QemuOptsList runtime_opts =3D { .name =3D "vvfat", @@ -1278,6 +1283,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, } =20 qemu_co_mutex_init(&s->lock); + vvfat_attach_aio_context(bs, bdrv_get_aio_context(bs)); =20 qemu_opts_del(opts); =20 @@ -2973,6 +2979,60 @@ DLOG(checkpoint()); return do_commit(s); } =20 +static int coroutine_fn GRAPH_RDLOCK +vvfat_commit_now(BDRVVVFATState *s) +{ + int ret; + + if (s->commit_timer) { + timer_del(s->commit_timer); + } + if (!s->commit_pending) { + return 0; + } + + qemu_co_mutex_lock(&s->lock); + ret =3D try_commit(s); + qemu_co_mutex_unlock(&s->lock); + + if (ret =3D=3D 0) { + s->commit_pending =3D false; + } + + return ret; +} + +static void coroutine_fn vvfat_commit_timer_entry(void *opaque) +{ + BlockDriverState *bs =3D opaque; + BDRVVVFATState *s =3D bs->opaque; + GRAPH_RDLOCK_GUARD(); + + vvfat_commit_now(s); + bdrv_dec_in_flight(bs); +} + +static void vvfat_commit_timer_cb(void *opaque) +{ + BlockDriverState *bs =3D opaque; + Coroutine *co; + + co =3D qemu_coroutine_create(vvfat_commit_timer_entry, bs); + bdrv_inc_in_flight(bs); + qemu_coroutine_enter(co); +} + +static void vvfat_schedule_commit(BDRVVVFATState *s) +{ + s->commit_pending =3D true; + + if (s->commit_timer) { + timer_mod_ns(s->commit_timer, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + VVFAT_COMMIT_DELAY_NS); + } +} + static int coroutine_fn GRAPH_RDLOCK vvfat_write(BlockDriverState *bs, int64_t sector_num, const uint8_t *buf, int nb_sectors) @@ -3098,8 +3158,7 @@ DLOG(fprintf(stderr, "Write to qcow backend: %d + %d\= n", (int)sector_num, nb_sec } =20 DLOG(checkpoint()); - /* TODO: add timeout */ - try_commit(s); + vvfat_schedule_commit(s); =20 DLOG(checkpoint()); return 0; @@ -3133,6 +3192,34 @@ vvfat_co_pwritev(BlockDriverState *bs, int64_t offse= t, int64_t bytes, return ret; } =20 +static int coroutine_fn GRAPH_RDLOCK +vvfat_co_flush(BlockDriverState *bs) +{ + BDRVVVFATState *s =3D bs->opaque; + + if (s->qcow =3D=3D NULL) { + return 0; + } + + return vvfat_commit_now(s); +} + +static void vvfat_drain_begin(BlockDriverState *bs) +{ + BDRVVVFATState *s =3D bs->opaque; + Coroutine *co; + + if (!s->commit_timer || !timer_pending(s->commit_timer)) { + return; + } + + timer_del(s->commit_timer); + + co =3D qemu_coroutine_create(vvfat_commit_timer_entry, bs); + bdrv_inc_in_flight(bs); + aio_co_enter(bdrv_get_aio_context(bs), co); +} + static int coroutine_fn vvfat_co_block_status(BlockDriverState *bs, unsigned int mode, int64_t offset, int64_t byte= s, @@ -3229,6 +3316,11 @@ static void vvfat_close(BlockDriverState *bs) { BDRVVVFATState *s =3D bs->opaque; =20 + if (s->commit_timer) { + timer_free(s->commit_timer); + s->commit_timer =3D NULL; + } + vvfat_close_current_file(s); array_free(&(s->fat)); array_free(&(s->directory)); @@ -3240,6 +3332,30 @@ static void vvfat_close(BlockDriverState *bs) } } =20 +static void vvfat_detach_aio_context(BlockDriverState *bs) +{ + BDRVVVFATState *s =3D bs->opaque; + + if (s->commit_timer) { + timer_free(s->commit_timer); + s->commit_timer =3D NULL; + } +} + +static void vvfat_attach_aio_context(BlockDriverState *bs, + AioContext *new_context) +{ + BDRVVVFATState *s =3D bs->opaque; + + if (s->qcow) { + s->commit_timer =3D aio_timer_new(new_context, QEMU_CLOCK_VIRTUAL, + SCALE_NS, vvfat_commit_timer_cb, b= s); + if (s->commit_pending) { + vvfat_schedule_commit(s); + } + } +} + static const char *const vvfat_strong_runtime_opts[] =3D { "dir", "fat-type", @@ -3263,7 +3379,11 @@ static BlockDriver bdrv_vvfat =3D { =20 .bdrv_co_preadv =3D vvfat_co_preadv, .bdrv_co_pwritev =3D vvfat_co_pwritev, - .bdrv_co_block_status =3D vvfat_co_block_status, + .bdrv_co_flush =3D vvfat_co_flush, + .bdrv_drain_begin =3D vvfat_drain_begin, + .bdrv_co_block_status =3D vvfat_co_block_status, + .bdrv_detach_aio_context =3D vvfat_detach_aio_context, + .bdrv_attach_aio_context =3D vvfat_attach_aio_context, =20 .strong_runtime_opts =3D vvfat_strong_runtime_opts, }; --=20 2.54.0