From nobody Fri Nov 14 16:53:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589222274; cv=none; d=zohomail.com; s=zohoarc; b=OKe7qa+/GafsChz6wHRiZHeVXEPVyyU2ekWGOsc172AnJzgIthRImcU3LUXdvSjKywTDFks32lsym1o7EDi2xVXd5uznvHwoLhc7v3gzfPpy35j8STvLMJl/TOJKx/8FudLbQmDh2xlFA6Zhz+dVteChsXyM4Ve/rgcm/bsPJkQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589222274; h=Content-Type: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:References:Sender:Subject:To; bh=detrTPCuCfAG/mIePNerc0GXWkj/VuOpI3Y0eXMjOvA=; b=i4Tp7P17x4Um6Rzk3fXjAlb8LM1RHfhulUeBTMKypQkLk2PUrMQlC/lexevvUuz2rbyjgbUA6YMwkP3l143WZhJA7UNNQCAOVZluYQPgK5G1SsKTGCNXoFbxGn87o9lW5V7YgF7THxAqVtXaCegu6yA751OimYFaAzCRSArtUHY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589222274598785.1775616548662; Mon, 11 May 2020 11:37:54 -0700 (PDT) Received: from localhost ([::1]:36848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYDJJ-0000lA-6r for importer@patchew.org; Mon, 11 May 2020 14:37:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44948) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYDII-0007Vn-Lo for qemu-devel@nongnu.org; Mon, 11 May 2020 14:36:50 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:57508 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jYDII-0005CP-0D for qemu-devel@nongnu.org; Mon, 11 May 2020 14:36:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-393-J8MuR9SyM8ua4DJT9-IjbA-1; Mon, 11 May 2020 14:36:45 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 37640107ACCA; Mon, 11 May 2020 18:36:44 +0000 (UTC) Received: from localhost (ovpn-114-247.ams2.redhat.com [10.36.114.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 344CB1002382; Mon, 11 May 2020 18:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589222209; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=detrTPCuCfAG/mIePNerc0GXWkj/VuOpI3Y0eXMjOvA=; b=GeTk1bbLLwMm3OhOOh71xdswElfuy8DDOJsn4ocNBeBUzebitb69vtaa68Gyc7w91aAawk l2LOh2EWx37ZfnwzXGbMt7EOQL4xts0vvZiyDh6H+UGckccvm6lk89FMEge6mEVNUdYfF7 sFu5cZMBah8XWec/VWqxxPT9ItmOl5s= X-MC-Unique: J8MuR9SyM8ua4DJT9-IjbA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 1/2] aio-posix: don't duplicate fd handler deletion in fdmon_io_uring_destroy() Date: Mon, 11 May 2020 19:36:29 +0100 Message-Id: <20200511183630.279750-2-stefanha@redhat.com> In-Reply-To: <20200511183630.279750-1-stefanha@redhat.com> References: <20200511183630.279750-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=207.211.31.81; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/11 01:43:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Stefan Weil , qemu-stable@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The io_uring file descriptor monitoring implementation has an internal list of fd handlers that are pending submission to io_uring. fdmon_io_uring_destroy() deletes all fd handlers on the list. Don't delete fd handlers directly in fdmon_io_uring_destroy() for two reasons: 1. This duplicates the aio-posix.c AioHandler deletion code and could become outdated if the struct changes. 2. Only handlers with the FDMON_IO_URING_REMOVE flag set are safe to remove. If the flag is not set then something still has a pointer to the fd handler. Let aio-posix.c and its user worry about that. In practice this isn't an issue because fdmon_io_uring_destroy() is only called when shutting down so all users have removed their fd handlers, but the next patch will need this! Signed-off-by: Stefan Hajnoczi Tested-by: Oleksandr Natalenko --- util/aio-posix.c | 1 + util/fdmon-io_uring.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/util/aio-posix.c b/util/aio-posix.c index c3613d299e..8af334ab19 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -679,6 +679,7 @@ void aio_context_destroy(AioContext *ctx) { fdmon_io_uring_destroy(ctx); fdmon_epoll_disable(ctx); + aio_free_deleted_handlers(ctx); } =20 void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, diff --git a/util/fdmon-io_uring.c b/util/fdmon-io_uring.c index d5a80ed6fb..1d14177df0 100644 --- a/util/fdmon-io_uring.c +++ b/util/fdmon-io_uring.c @@ -342,11 +342,18 @@ void fdmon_io_uring_destroy(AioContext *ctx) =20 io_uring_queue_exit(&ctx->fdmon_io_uring); =20 - /* No need to submit these anymore, just free them. */ + /* Move handlers due to be removed onto the deleted list */ while ((node =3D QSLIST_FIRST_RCU(&ctx->submit_list))) { + unsigned flags =3D atomic_fetch_and(&node->flags, + ~(FDMON_IO_URING_PENDING | + FDMON_IO_URING_ADD | + FDMON_IO_URING_REMOVE)); + + if (flags & FDMON_IO_URING_REMOVE) { + QLIST_INSERT_HEAD_RCU(&ctx->deleted_aio_handlers, node, no= de_deleted); + } + QSLIST_REMOVE_HEAD_RCU(&ctx->submit_list, node_submitted); - QLIST_REMOVE(node, node); - g_free(node); } =20 ctx->fdmon_ops =3D &fdmon_poll_ops; --=20 2.25.3 From nobody Fri Nov 14 16:53:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589222329; cv=none; d=zohomail.com; s=zohoarc; b=hY/XXOM7R1YKK1GnMIAc0vIcW+zswU9JcinMRLyJchtb0HWWObvgj8IWSHjFMyZBPCyt4viHbfMicjrxi/lm77QAQoXtphiVtPELL9+uXXQ5ViV5XM/eEkm0HBaSi3H2rq+ou8SxzfszsUw2ERYNnzEKsFNiphs7roBP+le08AI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589222329; h=Content-Type: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:References:Sender:Subject:To; bh=EhOQI+A1nf+HXVI8yeJRo+ww5eOdXYoY9cww+n33/4o=; b=JyAV5EuklKVF+c3nBJPj68tcUvahc9yCKbTvaq4DL8l8vlzfH9mWOD3OAXKShFvWKMZanehqjQqO7jtyVQ1/fVu/P85+9ekZHTXP82WPT/SJh1EM87E0Rj6rO17441ZIvTYOvNC1o8T8ouxT3M4HttHuVIGrV6qr9HbWKE6zbTc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589222329949471.156858494994; Mon, 11 May 2020 11:38:49 -0700 (PDT) Received: from localhost ([::1]:41272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYDKC-00032Q-NY for importer@patchew.org; Mon, 11 May 2020 14:38:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYDIK-0007ae-W5 for qemu-devel@nongnu.org; Mon, 11 May 2020 14:36:53 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:52812 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jYDIK-0005Cd-1B for qemu-devel@nongnu.org; Mon, 11 May 2020 14:36:52 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-510-QDKD1pNXPOu3p7z4gVJmjw-1; Mon, 11 May 2020 14:36:47 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 365EE19057AA; Mon, 11 May 2020 18:36:46 +0000 (UTC) Received: from localhost (ovpn-114-247.ams2.redhat.com [10.36.114.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A79F5C1B5; Mon, 11 May 2020 18:36:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589222211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EhOQI+A1nf+HXVI8yeJRo+ww5eOdXYoY9cww+n33/4o=; b=DuNTUnWz9+a6zWQeqxqa9HNOLnlXCcNVXfLVp1fVRj8AussDKqK4g3KGbMdUebgOzlWf32 5Z9h8ys5pJQplkMM1QhZApqOpmXNGnZKtzHhZiERbimmAonJ5piCbUCYQiUk9zaOjPOvRK mtP+DbNBiKQE46WEpDlw1wWXoKJKAo0= X-MC-Unique: QDKD1pNXPOu3p7z4gVJmjw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 2/2] aio-posix: disable fdmon-io_uring when GSource is used Date: Mon, 11 May 2020 19:36:30 +0100 Message-Id: <20200511183630.279750-3-stefanha@redhat.com> In-Reply-To: <20200511183630.279750-1-stefanha@redhat.com> References: <20200511183630.279750-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=205.139.110.61; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/11 03:10:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Stefan Weil , qemu-stable@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The glib event loop does not call fdmon_io_uring_wait() so fd handlers waiting to be submitted build up in the list. There is no benefit is using io_uring when the glib GSource is being used, so disable it instead of implementing a more complex fix. This fixes a memory leak where AioHandlers would build up and increasing amounts of CPU time were spent iterating them in aio_pending(). The symptom is that guests become slow when QEMU is built with io_uring support. Buglink: https://bugs.launchpad.net/qemu/+bug/1877716 Fixes: 73fd282e7b6dd4e4ea1c3bbb3d302c8db51e4ccf ("aio-posix: add io_uring f= d monitoring implementation") Signed-off-by: Stefan Hajnoczi Tested-by: Oleksandr Natalenko --- include/block/aio.h | 3 +++ util/aio-posix.c | 12 ++++++++++++ util/aio-win32.c | 4 ++++ util/async.c | 1 + 4 files changed, 20 insertions(+) diff --git a/include/block/aio.h b/include/block/aio.h index 62ed954344..b2f703fa3f 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -701,6 +701,9 @@ void aio_context_setup(AioContext *ctx); */ void aio_context_destroy(AioContext *ctx); =20 +/* Used internally, do not call outside AioContext code */ +void aio_context_use_g_source(AioContext *ctx); + /** * aio_context_set_poll_params: * @ctx: the aio context diff --git a/util/aio-posix.c b/util/aio-posix.c index 8af334ab19..1b2a3af65b 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -682,6 +682,18 @@ void aio_context_destroy(AioContext *ctx) aio_free_deleted_handlers(ctx); } =20 +void aio_context_use_g_source(AioContext *ctx) +{ + /* + * Disable io_uring when the glib main loop is used because it doesn't + * support mixed glib/aio_poll() usage. It relies on aio_poll() being + * called regularly so that changes to the monitored file descriptors = are + * submitted, otherwise a list of pending fd handlers builds up. + */ + fdmon_io_uring_destroy(ctx); + aio_free_deleted_handlers(ctx); +} + void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, int64_t grow, int64_t shrink, Error **err= p) { diff --git a/util/aio-win32.c b/util/aio-win32.c index 729d533faf..953c56ab48 100644 --- a/util/aio-win32.c +++ b/util/aio-win32.c @@ -414,6 +414,10 @@ void aio_context_destroy(AioContext *ctx) { } =20 +void aio_context_use_g_source(AioContext *ctx) +{ +} + void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, int64_t grow, int64_t shrink, Error **err= p) { diff --git a/util/async.c b/util/async.c index 3165a28f2f..1319eee3bc 100644 --- a/util/async.c +++ b/util/async.c @@ -362,6 +362,7 @@ static GSourceFuncs aio_source_funcs =3D { =20 GSource *aio_get_g_source(AioContext *ctx) { + aio_context_use_g_source(ctx); g_source_ref(&ctx->source); return &ctx->source; } --=20 2.25.3