From patchwork Mon Nov 12 10:34:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 198357 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A488B2C0089 for ; Mon, 12 Nov 2012 21:34:27 +1100 (EST) Received: from localhost ([::1]:40711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXrLV-0007oI-R9 for incoming@patchwork.ozlabs.org; Mon, 12 Nov 2012 05:34:25 -0500 Received: from eggs.gnu.org ([208.118.235.92]:42829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXrLL-0007na-U9 for qemu-devel@nongnu.org; Mon, 12 Nov 2012 05:34:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TXrLI-00039T-Ru for qemu-devel@nongnu.org; Mon, 12 Nov 2012 05:34:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59080) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXrLI-00039N-Il for qemu-devel@nongnu.org; Mon, 12 Nov 2012 05:34:12 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qACAYB4G001709 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 12 Nov 2012 05:34:11 -0500 Received: from dhcp-5-188.str.redhat.com (vpn1-5-133.ams2.redhat.com [10.36.5.133]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qACAY89i018072 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Mon, 12 Nov 2012 05:34:10 -0500 Message-ID: <50A0D09B.5080202@redhat.com> Date: Mon, 12 Nov 2012 11:34:03 +0100 From: Kevin Wolf User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0 MIME-Version: 1.0 To: Stefan Hajnoczi References: <1351697677-31598-1-git-send-email-stefanha@redhat.com> <1351697677-31598-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1351697677-31598-3-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH v2 2/3] aio: use g_slice_alloc() for AIOCB pooling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Am 31.10.2012 16:34, schrieb Stefan Hajnoczi: > AIO control blocks are frequently acquired and released because each aio > request involves at least one AIOCB. Therefore, we pool them to avoid > heap allocation overhead. > > The problem with the freelist approach in AIOPool is thread-safety. If > we want BlockDriverStates to associate with AioContexts that execute in > multiple threads, then a global freelist becomes a problem. > > This patch drops the freelist and instead uses g_slice_alloc() which is > tuned for per-thread fixed-size object pools. qemu_aio_get() and > qemu_aio_release() are now thread-safe. > > Note that the change from g_malloc0() to g_slice_alloc() should be safe > since the freelist reuse case doesn't zero the AIOCB either. Of course the real reason is that all fields are set anyway. We could even express this fact more clearly in the code: If you agree, I'll commit this on top of your series. Kevin diff --git a/block.c b/block.c index 854ebd6..6f5a0e7 100644 --- a/block.c +++ b/block.c @@ -3910,10 +3910,13 @@ void *qemu_aio_get(const AIOCBInfo *aiocb_info, BlockDriverState *bs, BlockDriverAIOCB *acb; acb = g_slice_alloc(aiocb_info->aiocb_size); - acb->aiocb_info = aiocb_info; - acb->bs = bs; - acb->cb = cb; - acb->opaque = opaque; + *acb = (BlockDriverAIOCB) { + .aiocb_info = aiocb_info, + .bs = bs, + .cb = cb, + .opaque = opaque, + }; + return acb; }