From patchwork Tue Oct 4 13:39:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ed Swierk X-Patchwork-Id: 678120 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3spLhR6Gy7z9t0P for ; Wed, 5 Oct 2016 01:21:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=skyportsystems.com header.i=@skyportsystems.com header.b=lw12wDVw; dkim-atps=neutral Received: from localhost ([::1]:42964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brQbU-0001k8-Lg for incoming@patchwork.ozlabs.org; Tue, 04 Oct 2016 10:21:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brPxY-0008Ld-9J for qemu-devel@nongnu.org; Tue, 04 Oct 2016 09:40:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1brPxS-0000Cd-II for qemu-devel@nongnu.org; Tue, 04 Oct 2016 09:40:39 -0400 Received: from mail-pa0-x234.google.com ([2607:f8b0:400e:c03::234]:36650) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brPxR-00009C-7F for qemu-devel@nongnu.org; Tue, 04 Oct 2016 09:40:34 -0400 Received: by mail-pa0-x234.google.com with SMTP id qn7so72767665pac.3 for ; Tue, 04 Oct 2016 06:40:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id; bh=IbtjyUeg8BBmSGhb1AhVMlgtN53F+dB7/vQXp8u7frM=; b=lw12wDVwhLYYTV0MCWfA9Q9L6fSoDQHl3hNKkRDJ00Mcyx84C/qwfkwqmQFrgpe5JZ OtcntvoETcodfRdufRm/q8LXWjJhumakMJVpEpTX1iyIzcfIE/BwVLsumTSbMrxSoqtR 6nrh8GK3vQSsuGOklVM7mmr9N1eUB0BWj6gNk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=IbtjyUeg8BBmSGhb1AhVMlgtN53F+dB7/vQXp8u7frM=; b=be9OQyJPCumFhVRWPd9KCjYT9hkd6MNi4ipcymGuA/8g374gYalXrMng/ZKkjeSPcH Rx0Qumbsc78YQJubbNCLAUnkSnjPMslxOFT/i/cIb+hf46smy/ohs7BXJJDjeLoqTU5R TmygCr0D2xXLaZj5J7RdmYEBnguNa8gdeGa9y5w2uOmS3AIK8ae9N9G+fJTIjmFSoWdQ F7UEmgQ1mYL7Ydm6onu8Hu54WnaTD4sJ28D4O4hq4nhIY3Yk1aD/BI+Z5K+xCNpkcOPI OxGwGKq3+yWnuD9xmmWh0oK80EAuj4ujgYVVGPzwZkrmAggCLsKN75+0KlzAE3+IUQux fImw== X-Gm-Message-State: AA6/9RkCE2oW9xHR3EWjWwgP9/Wrh8fPGKdEE5dym8BPPAJPz32hyWeXgxkpnF2x5KZbAhuE X-Received: by 10.66.16.74 with SMTP id e10mr5006235pad.148.1475588431055; Tue, 04 Oct 2016 06:40:31 -0700 (PDT) Received: from eswierk-sc.localdomain (gateway.skyportsystems.com. [74.93.0.69]) by smtp.gmail.com with ESMTPSA id v6sm7184396pfv.8.2016.10.04.06.40.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Oct 2016 06:40:30 -0700 (PDT) From: Ed Swierk To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Tue, 4 Oct 2016 06:39:52 -0700 Message-Id: <1475588392-10286-1-git-send-email-eswierk@skyportsystems.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c03::234 Subject: [Qemu-devel] [PATCH] qcow2: Optimize L2 table cache size based on image and cluster sizes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ed Swierk Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The optimal size of the qcow2 L2 table cache depends on the working set size and the cluster size of the disk image. If the cache is too small, L2 tables are be re-read from disk on every IO operation in the worst case. The host's buffer cache can paper over this inefficiency, but with cache=none or cache=directsync, L2 table cache thrashing dramatically reduces IO operations per second (e.g. from 50k/sec to 5k/sec for a qcow2 stored on a modern SSD). The L2 table cache size can be set manually via the l2-cache-size runtime option, but such a performance-critical value needs a sane default. Conservatively assuming the entire image is the working set, the existing hardcoded default value of 1 MiB is appropriate for images up to 8 GiB with the default 64 KiB cluster size. This change replaces the hardcoded default L2 table cache size with a value computed from the image size and cluster size. The resulting default cache size is just large enough to service random accesses in the entire image. Signed-off-by: Ed Swierk --- block/qcow2.c | 5 ++--- block/qcow2.h | 4 ---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 91ef4df..259e377 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -563,9 +563,8 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts, } } else { if (!l2_cache_size_set && !refcount_cache_size_set) { - *l2_cache_size = MAX(DEFAULT_L2_CACHE_BYTE_SIZE, - (uint64_t)DEFAULT_L2_CACHE_CLUSTERS - * s->cluster_size); + *l2_cache_size = (bs->total_sectors * BDRV_SECTOR_SIZE * 8 + + s->cluster_size - 1) / s->cluster_size; *refcount_cache_size = *l2_cache_size / DEFAULT_L2_REFCOUNT_SIZE_RATIO; } else if (!l2_cache_size_set) { diff --git a/block/qcow2.h b/block/qcow2.h index b36a7bf..f148c4d 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -68,10 +68,6 @@ /* Must be at least 4 to cover all cases of refcount table growth */ #define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */ -/* Whichever is more */ -#define DEFAULT_L2_CACHE_CLUSTERS 8 /* clusters */ -#define DEFAULT_L2_CACHE_BYTE_SIZE 1048576 /* bytes */ - /* The refblock cache needs only a fourth of the L2 cache size to cover as many * clusters */ #define DEFAULT_L2_REFCOUNT_SIZE_RATIO 4