qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
	Alberto Garcia <berto@igalia.com>,
	qemu-devel@nongnu.org, Alexander Graf <agraf@suse.de>
Subject: [Qemu-devel] [PATCH 3/3] qcow2: Add DEFAULT_L2_CACHE_CLUSTERS
Date: Mon,  1 Jun 2015 18:09:19 +0200	[thread overview]
Message-ID: <1433174959-7176-4-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1433174959-7176-1-git-send-email-mreitz@redhat.com>

If a relatively large cluster size is chosen, the default of 1 MB L2
cache is not really appropriate. In this case, unless overridden by the
user, the default cache size should not be determined by its size in
bytes but by the number of L2 tables (clusters) it is supposed to
contain.

Note that without this patch, MIN_L2_CACHE_SIZE will effectively take
over the same role. However, providing space for just two L2 tables is
not enough to be the default.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/qcow2.c | 11 ++++++++---
 block/qcow2.h |  2 ++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index f7b4cc6..c4f6938 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -483,9 +483,11 @@ static const char *overlap_bool_option_names[QCOW2_OL_MAX_BITNR] = {
     [QCOW2_OL_INACTIVE_L2_BITNR]    = QCOW2_OPT_OVERLAP_INACTIVE_L2,
 };
 
-static void read_cache_sizes(QemuOpts *opts, uint64_t *l2_cache_size,
+static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
+                             uint64_t *l2_cache_size,
                              uint64_t *refcount_cache_size, Error **errp)
 {
+    BDRVQcowState *s = bs->opaque;
     uint64_t combined_cache_size;
     bool l2_cache_size_set, refcount_cache_size_set, combined_cache_size_set;
 
@@ -525,7 +527,9 @@ static void read_cache_sizes(QemuOpts *opts, uint64_t *l2_cache_size,
         }
     } else {
         if (!l2_cache_size_set && !refcount_cache_size_set) {
-            *l2_cache_size = DEFAULT_L2_CACHE_BYTE_SIZE;
+            *l2_cache_size = MAX(DEFAULT_L2_CACHE_BYTE_SIZE,
+                                 (uint64_t)DEFAULT_L2_CACHE_CLUSTERS
+                                 * s->cluster_size);
             *refcount_cache_size = *l2_cache_size
                                  / DEFAULT_L2_REFCOUNT_SIZE_RATIO;
         } else if (!l2_cache_size_set) {
@@ -803,7 +807,8 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
         goto fail;
     }
 
-    read_cache_sizes(opts, &l2_cache_size, &refcount_cache_size, &local_err);
+    read_cache_sizes(bs, opts, &l2_cache_size, &refcount_cache_size,
+                     &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         ret = -EINVAL;
diff --git a/block/qcow2.h b/block/qcow2.h
index aa20022..5936d29 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -68,6 +68,8 @@
 /* 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
-- 
2.4.1

  parent reply	other threads:[~2015-06-01 16:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-01 16:09 [Qemu-devel] [PATCH 0/3] qcow2: Fix MIN_L2_CACHE_SIZE Max Reitz
2015-06-01 16:09 ` [Qemu-devel] [PATCH 1/3] qcow2: Set MIN_L2_CACHE_SIZE to 2 Max Reitz
2015-06-01 16:10   ` Max Reitz
2015-06-01 16:12   ` Alexander Graf
2015-06-01 16:14   ` Alberto Garcia
2015-06-01 16:09 ` [Qemu-devel] [PATCH 2/3] iotests: qcow2 COW with minimal L2 cache size Max Reitz
2015-06-01 17:01   ` Alberto Garcia
2015-06-01 16:09 ` Max Reitz [this message]
2015-06-01 17:16   ` [Qemu-devel] [PATCH 3/3] qcow2: Add DEFAULT_L2_CACHE_CLUSTERS Alberto Garcia
2015-06-02  9:31 ` [Qemu-devel] [PATCH 0/3] qcow2: Fix MIN_L2_CACHE_SIZE Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1433174959-7176-4-git-send-email-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=agraf@suse.de \
    --cc=berto@igalia.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).