From: Kevin Wolf <kwolf@suse.de>
To: Laurent Vivier <Laurent.Vivier@bull.net>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [patch 1/5][v2] Extract code from get_cluster_offset()
Date: Tue, 05 Aug 2008 16:15:20 +0200 [thread overview]
Message-ID: <48986078.6060701@suse.de> (raw)
In-Reply-To: <20080729141447.164763280@bull.net>
Laurent Vivier schrieb:
> Extract code from get_cluster_offset() into new functions:
>
> - seek_l2_table()
>
> Search an l2 offset in the l2_cache table.
>
> - l2_load()
>
> Read the l2 entry from disk
>
> - l2_allocate()
>
> Allocate a new l2 entry.
>
> Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
Acked-by: Kevin Wolf <kwolf@suse.de>
However, unrelated to your patch, I noticed that you touch code which
could use more comments in some places. (Oh btw, why do you explain the
new functions in the patch header but not in the code itself? But okay,
these are more or less obvious.)
> +static uint64_t *seek_l2_table(BDRVQcowState *s, uint64_t l2_offset)
> +{
> + int i,j;
> +
> + for(i = 0; i < L2_CACHE_SIZE; i++) {
> + if (l2_offset == s->l2_cache_offsets[i]) {
> + /* increment the hit count */
> + if (++s->l2_cache_counts[i] == 0xffffffff) {
> + for(j = 0; j < L2_CACHE_SIZE; j++) {
> + s->l2_cache_counts[j] >>= 1;
> + }
> + }
This if block is one of them. While it's quite obvious that some counter
is incremented, the action to avoid an overflow isn't. Why don't we do
something like if (count < 0xffffffff) count++?
And l2_cache_counts is a bad name anyway, IMHO. I first thought of
something like a reference counter (and then it would be definitely
worth a comment; now it is debatable). l2_cache_hits could be a better name.
> + if (!(l2_offset & QCOW_OFLAG_COPIED) && allocate) {
> + free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_t));
> + ret = l2_allocate(bs, l1_index, &l2_table, &l2_offset);
> + if (ret == 0)
> + return 0;
The assumption is that allocate != 0 means there will be a write
operation and the cluster has to be copied, right? You certainly can
figure that out from the code, but it would be nice to have a comment
saying exactly this and that free_clusters is used to decrease the
refcount of the copied cluster.
Agreed, having written this, both are not really that bad. But it were
the places where I needed a bit more time to understand what the code is
doing and if it's right, so I thought I'd mention them.
Kevin
next prev parent reply other threads:[~2008-08-05 14:31 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-29 14:13 [Qemu-devel] [patch 0/5][v2] qcow2: improve I/O performance with cache=off Laurent Vivier
2008-07-29 14:13 ` [Qemu-devel] [patch 1/5][v2] Extract code from get_cluster_offset() Laurent Vivier
2008-08-05 14:15 ` Kevin Wolf [this message]
2008-08-05 14:28 ` Laurent Vivier
2008-08-05 14:34 ` Kevin Wolf
2008-08-05 14:45 ` Laurent Vivier
2008-07-29 14:13 ` [Qemu-devel] [patch 2/5][v2] Divide get_cluster_offset() Laurent Vivier
2008-08-05 15:13 ` Kevin Wolf
2008-08-05 15:25 ` Laurent Vivier
2008-08-05 15:41 ` Kevin Wolf
2008-07-29 14:13 ` [Qemu-devel] [patch 3/5][v2] Extract compressing part from alloc_cluster_offset() Laurent Vivier
2008-08-06 14:20 ` Kevin Wolf
2008-08-06 14:41 ` Laurent Vivier
2008-08-06 14:56 ` Kevin Wolf
2008-08-06 15:03 ` Laurent Vivier
2008-07-29 14:13 ` [Qemu-devel] [patch 4/5][v2] Aggregate same type clusters Laurent Vivier
2008-08-11 12:10 ` Kevin Wolf
2008-08-11 12:39 ` Laurent Vivier
2008-07-29 14:13 ` [Qemu-devel] [patch 5/5][v2] Try to aggregate free clusters and freed clusters Laurent Vivier
2008-08-11 13:13 ` Kevin Wolf
2008-08-11 14:04 ` Laurent Vivier
2008-08-11 14:42 ` Laurent Vivier
2008-08-11 15:03 ` Kevin Wolf
2008-07-29 19:15 ` [Qemu-devel] [patch 0/5][v2] qcow2: improve I/O performance with cache=off Anthony Liguori
2008-07-29 21:35 ` Laurent Vivier
2008-07-29 21:49 ` Anthony Liguori
2008-07-29 21:59 ` Laurent Vivier
2008-08-01 14:54 ` Anthony Liguori
2008-08-01 15:05 ` Laurent Vivier
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=48986078.6060701@suse.de \
--to=kwolf@suse.de \
--cc=Laurent.Vivier@bull.net \
--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).