qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Orit Wasserman <owasserm@redhat.com>
Cc: aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com,
	mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org,
	blauwirbel@gmail.com, Petter Svard <petters@cs.umu.se>,
	Benoit Hudzia <benoit.hudzia@sap.com>,
	avi@redhat.com, pbonzini@redhat.com,
	Aidan Shribman <aidan.shribman@sap.com>
Subject: Re: [Qemu-devel] [PATCH v10 8/9] Add set_cachesize command
Date: Wed, 16 May 2012 10:45:27 -0600	[thread overview]
Message-ID: <4FB3D9A7.2060704@redhat.com> (raw)
In-Reply-To: <1337169582-28312-9-git-send-email-owasserm@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2833 bytes --]

On 05/16/2012 05:59 AM, Orit Wasserman wrote:
> Change XBZRLE cache size in bytes (the size should be a power of 2).
> If XBZRLE cache size is too small there will be many cache miss.
> 
> Signed-off-by: Benoit Hudzia <benoit.hudzia@sap.com>
> Signed-off-by: Petter Svard <petters@cs.umu.se>
> Signed-off-by: Aidan Shribman <aidan.shribman@sap.com>
> Signed-off-by: Orit Wasserman <owasserm@redhat.com>

>  
> +
> +void xbzrle_cache_resize(int64_t order)
> +{
> +    cache_resize(XBZRLE.cache, pow(2, order));

'1 << order' is much more efficient than a call to pow().


> +void qmp_migrate_set_cachesize(int64_t value, Error **errp)

> +
> +    /* power of 2 */
> +    if (value != 1 && !is_power_of_2(value)) {
> +        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
> +                  "needs to be power of 2");

We already have QERR_PROPERTY_VALUE_NOT_POWER_OF_2, why aren't you using
that here?

> +        return;
> +    }
> +
> +    s->xbzrle_cache_size = value;
> +    xbzrle_cache_resize(log2(value));

log2() is rather expensive, ffs() from <strings.h> is more efficient at
converting a single bit into the appropriate order.


>  ##
> +# @migrate_set_cachesize
> +#
> +# Set XBZRLE cache size
> +#
> +# @value: cache size in bytes
> +#
> +# Returns: nothing on success

Document the error for a non-power-of-2 or for overflow.

Document whether this command is safe for an ongoing migration, or
whether it must be called in advance of a migration.

> +#
> +# Since: 1.1

1.2.


> +static inline bool is_power_of_2(int64_t value)
> +{
> +    return !(value & (value - 1));
> +}

This says '0' is a power of 2, which is not true.  Either fix the logic
to exclude 0, or fix the function name to state that you are really
checking that at most one bit is set.

Also, if value is 0x8000000000000000, you are triggering unspecified
behavior per C99.  Is it worth using uint64_t for defined behavior, or
do you need to take precautions regarding negative values?


> +SQMP
> +migrate_set_cachesize
> +---------------------
> +
> +Set cache size to be used by XBZRLE migration
> +
> +Arguments:
> +
> +- "value": cache size in bytes (json-int)

Would it be any easier to take 'order' (log2 of the size) instead of the
actual cache size?  That is, instead of calling "value":1048576, I would
rather type "value":20.

> +
> +Example:
> +
> +-> { "execute": "migrate_set_cachesize", "arguments": { "value": 512 } }

Isn't 512 bytes rather small?  And given my argument about taking order
rather than bytes as being easier to use, don't you really mean 512
megabytes (order 29) rather than 512 bytes (order 9)?

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]

  reply	other threads:[~2012-05-16 18:28 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-16 11:59 [Qemu-devel] [PATCH v10 0/9] XBZRLE delta for live migration of large memory app Orit Wasserman
2012-05-16 11:59 ` [Qemu-devel] [PATCH v10 1/9] From: Isaku Yamahata <yamahata@valinux.co.jp> Orit Wasserman
2012-05-16 12:43   ` Peter Maydell
2012-05-16 16:50     ` [Qemu-devel] [PATCH v10 1/9] Add MigrationParams structure Orit Wasserman
2012-05-16 11:59 ` [Qemu-devel] [PATCH v10 2/9] Add migration capabilites Orit Wasserman
2012-05-16 11:59 ` [Qemu-devel] [PATCH v10 3/9] Add XBZRLE documentation Orit Wasserman
2012-05-16 16:28   ` Eric Blake
2012-05-16 16:53     ` Orit Wasserman
2012-05-16 11:59 ` [Qemu-devel] [PATCH v10 4/9] Add cache handling functions Orit Wasserman
2012-05-16 11:59 ` [Qemu-devel] [PATCH v10 5/9] Add uleb encoding/decoding functions Orit Wasserman
2012-05-16 11:59 ` [Qemu-devel] [PATCH v10 6/9] Add save_block_hdr function Orit Wasserman
2012-05-16 11:59 ` [Qemu-devel] [PATCH v10 7/9] Add XBZRLE to ram_save_block and ram_save_live Orit Wasserman
2012-05-16 11:59 ` [Qemu-devel] [PATCH v10 8/9] Add set_cachesize command Orit Wasserman
2012-05-16 16:45   ` Eric Blake [this message]
2012-05-16 17:04     ` Orit Wasserman
2012-05-16 17:58       ` Eric Blake
2012-05-17  9:46         ` Avi Kivity
2012-05-17 12:25           ` Orit Wasserman
2012-05-16 11:59 ` [Qemu-devel] [PATCH v10 9/9] Add XBZRLE statistics Orit Wasserman

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=4FB3D9A7.2060704@redhat.com \
    --to=eblake@redhat.com \
    --cc=aidan.shribman@sap.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=benoit.hudzia@sap.com \
    --cc=blauwirbel@gmail.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=owasserm@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=petters@cs.umu.se \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=stefanha@gmail.com \
    /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).