From nobody Mon Nov 25 03:59:41 2024 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1718992583; cv=none; d=zohomail.com; s=zohoarc; b=Y6qOqr6ppePIwasmmMgemGtXjkMbmdCNN/Cr7tCQGOQf52bUwdBBGXw1milCuPQfwzjkyzu9Y8A0BTVnpV8hCJJvLHch5IcP9QSQWwlOHR+fCMcMwt67/J4RCFKWCU5f2ARlxAW5aR+giC2iFUZtsr8MYHC3P169aRLV8S4BKEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718992583; 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=k+HmQP3h3Mm2DrDGsClDzMbx0rC1gh3vI8zM8d67lXI=; b=hak1whucqoRx3P3nmtDGbWZEHYGJXdyfPmB92/lGxMtPOzJH6xH3GwGmxK5FrFTZclieHTCSKpX6NjlnnQ7e/M/V7J5juUtVlXzPP66anTXfi4UQRZz4m9Xij+exRsDp/TBvSOiZfBWs9pke2hu2OJXWlAXO6Eg9/5bhc1rdU+E= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1718992582999910.5915149452983; Fri, 21 Jun 2024 10:56:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKiTY-0003Pt-VD; Fri, 21 Jun 2024 13:55:04 -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 1sKiTX-0003LU-3n for qemu-devel@nongnu.org; Fri, 21 Jun 2024 13:55:03 -0400 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sKiTV-0003Lb-6V for qemu-devel@nongnu.org; Fri, 21 Jun 2024 13:55:02 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D241721B37; Fri, 21 Jun 2024 17:54:59 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A4DFA13AAA; Fri, 21 Jun 2024 17:54:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id OGaDGnK+dWZNawAAD6G6ig (envelope-from ); Fri, 21 Jun 2024 17:54:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718992499; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k+HmQP3h3Mm2DrDGsClDzMbx0rC1gh3vI8zM8d67lXI=; b=NE4c6m6V8nSaEyL50t9Ebl+eTBXlddJ2jjl5RH2uo4FJF5q4pAHOCe+JRUvRGn3GKIF0sI SFeThs4frx4VygkFZQfuNsKMNmn2rdAu6Jx5LDUlibsGimfa6zzsMc5Xnkx+HQG6l4fxxo Ut3WvEKQF86k4/Sfma2GAMKIz4vbB3M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718992499; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k+HmQP3h3Mm2DrDGsClDzMbx0rC1gh3vI8zM8d67lXI=; b=VlRwAn2pFtjSwnXXYZQumXgT8nRCYjuqcXp0pHyP7L/Af47bwyPYJnzuv1laA68+ip8gfF 0d2GbKKFOmB/UaCQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=NE4c6m6V; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=VlRwAn2p DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718992499; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k+HmQP3h3Mm2DrDGsClDzMbx0rC1gh3vI8zM8d67lXI=; b=NE4c6m6V8nSaEyL50t9Ebl+eTBXlddJ2jjl5RH2uo4FJF5q4pAHOCe+JRUvRGn3GKIF0sI SFeThs4frx4VygkFZQfuNsKMNmn2rdAu6Jx5LDUlibsGimfa6zzsMc5Xnkx+HQG6l4fxxo Ut3WvEKQF86k4/Sfma2GAMKIz4vbB3M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718992499; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k+HmQP3h3Mm2DrDGsClDzMbx0rC1gh3vI8zM8d67lXI=; b=VlRwAn2pFtjSwnXXYZQumXgT8nRCYjuqcXp0pHyP7L/Af47bwyPYJnzuv1laA68+ip8gfF 0d2GbKKFOmB/UaCQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , Richard Henderson Subject: [PULL 12/28] migration/multifd: Add direct-io support Date: Fri, 21 Jun 2024 14:54:18 -0300 Message-Id: <20240621175434.31180-13-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240621175434.31180-1-farosas@suse.de> References: <20240621175434.31180-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: D241721B37 X-Spam-Score: -3.01 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCPT_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org 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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1718992584871100003 Content-Type: text/plain; charset="utf-8" When multifd is used along with mapped-ram, we can take benefit of a filesystem that supports the O_DIRECT flag and perform direct I/O in the multifd threads. This brings a significant performance improvement because direct-io writes bypass the page cache which would otherwise be thrashed by the multifd data which is unlikely to be needed again in a short period of time. To be able to use a multifd channel opened with O_DIRECT, we must ensure that a certain aligment is used. Filesystems usually require a block-size alignment for direct I/O. The way to achieve this is by enabling the mapped-ram feature, which already aligns its I/O properly (see MAPPED_RAM_FILE_OFFSET_ALIGNMENT at ram.c). By setting O_DIRECT on the multifd channels, all writes to the same file descriptor need to be aligned as well, even the ones that come from outside multifd, such as the QEMUFile I/O from the main migration code. This makes it impossible to use the same file descriptor for the QEMUFile and for the multifd channels. The various flags and metadata written by the main migration code will always be unaligned by virtue of their small size. To workaround this issue, we'll require a second file descriptor to be used exclusively for direct I/O. The second file descriptor can be obtained by QEMU by re-opening the migration file (already possible), or by being provided by the user or management application (support to be added in future patches). Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/file.c | 33 ++++++++++++++++++++++++++++----- migration/file.h | 1 - migration/migration.c | 23 +++++++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/migration/file.c b/migration/file.c index a903710f06..db870f2cf0 100644 --- a/migration/file.c +++ b/migration/file.c @@ -50,12 +50,31 @@ void file_cleanup_outgoing_migration(void) outgoing_args.fname =3D NULL; } =20 +static void file_enable_direct_io(int *flags) +{ +#ifdef O_DIRECT + *flags |=3D O_DIRECT; +#else + /* it should have been rejected when setting the parameter */ + g_assert_not_reached(); +#endif +} + bool file_send_channel_create(gpointer opaque, Error **errp) { QIOChannelFile *ioc; int flags =3D O_WRONLY; bool ret =3D true; =20 + if (migrate_direct_io()) { + /* + * Enable O_DIRECT for the secondary channels. These are used + * for sending ram pages and writes should be guaranteed to be + * aligned to at least page size. + */ + file_enable_direct_io(&flags); + } + ioc =3D qio_channel_file_new_path(outgoing_args.fname, flags, 0, errp); if (!ioc) { ret =3D false; @@ -117,21 +136,25 @@ static gboolean file_accept_incoming_migration(QIOCha= nnel *ioc, return G_SOURCE_REMOVE; } =20 -void file_create_incoming_channels(QIOChannel *ioc, Error **errp) +static void file_create_incoming_channels(QIOChannel *ioc, char *filename, + Error **errp) { - int i, fd, channels =3D 1; + int i, channels =3D 1; g_autofree QIOChannel **iocs =3D NULL; + int flags =3D O_RDONLY; =20 if (migrate_multifd()) { channels +=3D migrate_multifd_channels(); + if (migrate_direct_io()) { + file_enable_direct_io(&flags); + } } =20 iocs =3D g_new0(QIOChannel *, channels); - fd =3D QIO_CHANNEL_FILE(ioc)->fd; iocs[0] =3D ioc; =20 for (i =3D 1; i < channels; i++) { - QIOChannelFile *fioc =3D qio_channel_file_new_dupfd(fd, errp); + QIOChannelFile *fioc =3D qio_channel_file_new_path(filename, flags= , 0, errp); =20 if (!fioc) { while (i) { @@ -171,7 +194,7 @@ void file_start_incoming_migration(FileMigrationArgs *f= ile_args, Error **errp) return; } =20 - file_create_incoming_channels(QIO_CHANNEL(fioc), errp); + file_create_incoming_channels(QIO_CHANNEL(fioc), filename, errp); } =20 int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov, diff --git a/migration/file.h b/migration/file.h index 7699c04677..9f71e87f74 100644 --- a/migration/file.h +++ b/migration/file.h @@ -20,7 +20,6 @@ void file_start_outgoing_migration(MigrationState *s, int file_parse_offset(char *filespec, uint64_t *offsetp, Error **errp); void file_cleanup_outgoing_migration(void); bool file_send_channel_create(gpointer opaque, Error **errp); -void file_create_incoming_channels(QIOChannel *ioc, Error **errp); int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov, int niov, RAMBlock *block, Error **errp); int multifd_file_recv_data(MultiFDRecvParams *p, Error **errp); diff --git a/migration/migration.c b/migration/migration.c index e1b269624c..e03c80b3aa 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -155,6 +155,16 @@ static bool migration_needs_seekable_channel(void) return migrate_mapped_ram(); } =20 +static bool migration_needs_extra_fds(void) +{ + /* + * When doing direct-io, multifd requires two different, + * non-duplicated file descriptors so we can use one of them for + * unaligned IO. + */ + return migrate_multifd() && migrate_direct_io(); +} + static bool transport_supports_seeking(MigrationAddress *addr) { if (addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_FILE) { @@ -164,6 +174,12 @@ static bool transport_supports_seeking(MigrationAddres= s *addr) return false; } =20 +static bool transport_supports_extra_fds(MigrationAddress *addr) +{ + /* file: works because QEMU can open it multiple times */ + return addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_FILE; +} + static bool migration_channels_and_transport_compatible(MigrationAddress *addr, Error **errp) @@ -180,6 +196,13 @@ migration_channels_and_transport_compatible(MigrationA= ddress *addr, return false; } =20 + if (migration_needs_extra_fds() && + !transport_supports_extra_fds(addr)) { + error_setg(errp, + "Migration requires a transport that allows for extra f= ds (e.g. file)"); + return false; + } + return true; } =20 --=20 2.35.3