From nobody Sat May 30 17:43:40 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=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1780019740; cv=none; d=zohomail.com; s=zohoarc; b=fYObuib1XGsr1PCitKPXCsKT+HaeLVjw8JUqQN8+b//Sf3XZnxW7zMySDzPho523lf4/soCCGn47epnt6zhDu9b/uhwBJu9SCcZJNFHsI1APxZqx8jAmz9YLWRHoq+75bzwKJ1sO5mx4BigD4xe1M8SXq968FpYrtXpR2VPsL3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780019740; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IGnRlquDckY+vILeeivpNQ/AOtX8lfZBlLU5G6d3wDw=; b=bRdsiFKSNb0MGJXb/vpVCJ2VnZrUXwqVPj1Rb7ewAUUii7f/ILzHHY2DuJD8aBKEr0HhVlYzg9BNW4mpESFLdVkZqLf0bI/gfihpfEXBdVhgggZoujmZLtTV9d11amY97K9EblPRMCZFpLDPCzhxlQdkRX5V0pW9p0MNvi3p4/M= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780019740002283.4146691419239; Thu, 28 May 2026 18:55:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSmRF-0002bg-Nx; Thu, 28 May 2026 21:55:05 -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 1wSmRE-0002bV-2t for qemu-devel@nongnu.org; Thu, 28 May 2026 21:55:04 -0400 Received: from [115.124.30.119] (helo=out30-119.freemail.mail.aliyun.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSmR6-0005uI-Ii for qemu-devel@nongnu.org; Thu, 28 May 2026 21:55:03 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X3nuvYX_1780019664 cluster:ay36) by smtp.aliyun-inc.com; Fri, 29 May 2026 09:54:25 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1780019666; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=IGnRlquDckY+vILeeivpNQ/AOtX8lfZBlLU5G6d3wDw=; b=pjFYWMZyH38KxhsDa5tZMOnpUc3IqVYCYqxaZy04UL02T1fBn1WUMJX/9Le57WlJYKonMJ0zXYyCagI6EXrdYMsCZGnH000tto81nKASZrlH69Q+eRR1LXxZZaOKV9MPz36Do6mpSL6KNT6uhAmriFi4+eqj2HZWD3KmkbihVAE= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R591e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam011083073210; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0X3nuvYX_1780019664; From: Bin Guo To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, kwolf@redhat.com Subject: [PATCH] util/qemu-coroutine: skip global pool lock when pool is empty Date: Fri, 29 May 2026 09:54:23 +0800 Message-ID: <20260529015423.49688-1-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.124.30.119 (deferred) 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=115.124.30.119; envelope-from=guobin@linux.alibaba.com; helo=out30-119.freemail.mail.aliyun.com X-Spam_score_int: -88 X-Spam_score: -8.9 X-Spam_bar: -------- X-Spam_report: (-8.9 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action 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 @linux.alibaba.com) X-ZM-MESSAGEID: 1780019742641154100 Content-Type: text/plain; charset="utf-8" coroutine_pool_refill_local() acquires global_pool_lock on every call even when the global pool is empty (global_pool_size =3D=3D 0). Under high I/O concurrency many threads simultaneously attempt to refill from an empty global pool, causing unnecessary mutex contention. Add a fast-path check: read global_pool_size with qatomic_read() before acquiring the mutex. If zero, the global pool is empty and we return immediately. This is a racy read but correctness is preserved: the only consequence of a stale read is a missed refill opportunity, which will be retried on the next coroutine allocation. Signed-off-by: Bin Guo --- util/qemu-coroutine.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c index d17135f585..0f8c3a23eb 100644 --- a/util/qemu-coroutine.c +++ b/util/qemu-coroutine.c @@ -138,6 +138,15 @@ static void coroutine_pool_refill_local(void) CoroutinePool *local_pool =3D get_ptr_local_pool(); CoroutinePoolBatch *batch =3D NULL; =20 + /* + * Fast path: skip the lock when the global pool is obviously empty. + * The read is racy but harmless -- worst case we miss a concurrent + * put and retry on the next allocation. + */ + if (qatomic_read(&global_pool_size) =3D=3D 0) { + return; + } + WITH_QEMU_LOCK_GUARD(&global_pool_lock) { batch =3D QSLIST_FIRST(&global_pool); =20 --=20 2.50.1 (Apple Git-155)