From: Yang Hongyang <yanghy@cn.fujitsu.com>
To: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Vincent Hanquez <Vincent.Hanquez@eu.citrix.com>,
Xen-devel <xen-devel@lists.xensource.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
Stefano Stabellini <Stefano.Stabellini@eu.citrix.com>
Subject: Re: [PATCH] xl: allow scaling suffix on memory sizes in mem-set and mem-max
Date: Tue, 18 May 2010 09:45:00 +0800 [thread overview]
Message-ID: <4BF1F11C.6020809@cn.fujitsu.com> (raw)
In-Reply-To: <4BF1E238.2060904@goop.org>
Hi jeremy,
On 05/18/2010 08:41 AM, Jeremy Fitzhardinge wrote:
> Allow mem-set and mem-max to take 'b', 'k', 'm', 'g' and 't' as scaling
> suffixes for bytes, kilobytes, mega, etc. An unadorned number is still
> treated as kilobytes so no existing users should be affected.
>
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
>
> diff -r baccadfd9418 tools/libxl/xl_cmdimpl.c
> --- a/tools/libxl/xl_cmdimpl.c Fri May 14 08:05:05 2010 +0100
> +++ b/tools/libxl/xl_cmdimpl.c Mon May 17 17:37:56 2010 -0700
> @@ -1200,16 +1200,40 @@
> }
> }
>
> +static long long int parse_mem_size_kb(char *mem)
I think here should use 'uint64_t' which is 'unsigned long long'
instead of 'long long int'.
> +{
> + char *endptr;
> + long long int bytes;
> + long long int scale = 1024;
> +
> + bytes = strtoll(mem, &endptr, 10);
> +
> + if (strlen(endptr) > 1)
> + return -1;
> +
> + switch (*endptr) {
> + case '\0': break;
> + case 'b': scale = 1; break;
> + case 'k': scale = 1024ll; break;
> + case 'm': scale = 1024ll * 1024; break;
> + case 'g': scale = 1024ll * 1024 * 1024; break;
> + case 't': scale = 1024ll * 1024 * 1024 * 1024; break;
> + default:
> + return -1;
> + }
> +
> + return (bytes * scale) / 1024;
> +}
> +
> int set_memory_max(char *p, char *mem)
> {
> - char *endptr;
> - uint32_t memorykb;
> + long long int memorykb;
> int rc;
>
> find_domain(p);
>
> - memorykb = strtoul(mem, &endptr, 10);
> - if (*endptr != '\0') {
> + memorykb = parse_mem_size_kb(mem);
> + if (memorykb == -1) {
> fprintf(stderr, "invalid memory size: %s\n", mem);
> exit(3);
> }
> @@ -1255,17 +1279,18 @@
>
> void set_memory_target(char *p, char *mem)
> {
> - char *endptr;
> - uint32_t memorykb;
> + long long int memorykb;
>
> find_domain(p);
>
> - memorykb = strtoul(mem, &endptr, 10);
> - if (*endptr != '\0') {
> - fprintf(stderr, "invalid memory size: %s\n", mem);
> - exit(3);
> + memorykb = parse_mem_size_kb(mem);
> +
> + if (memorykb == -1) {
> + fprintf(stderr, "invalid memory size: %s\n", mem);
> + exit(3);
> }
> - printf("setting domid %d memory to : %d\n", domid, memorykb);
> +
> + printf("setting domid %d memory to : %lld\n", domid, memorykb);
> libxl_set_memory_target(&ctx, domid, memorykb, /* enforce */ 1);
> }
>
> diff -r baccadfd9418 tools/libxl/xl_cmdtable.c
> --- a/tools/libxl/xl_cmdtable.c Fri May 14 08:05:05 2010 +0100
> +++ b/tools/libxl/xl_cmdtable.c Mon May 17 17:37:56 2010 -0700
> @@ -110,12 +110,12 @@
> },
> { "mem-max",
> &main_memmax,
> - "Set the maximum amount reservation for a domain",
> + "Set the maximum amount reservation for a domain. Units default to kilobytes, but can be suffixed with 'b' (bytes), 'k' (KB), 'm' (MB), 'g' (GB) or 't' (TB)",
> "<Domain> <MemKB>",
> },
> { "mem-set",
> &main_memset,
> - "Set the current memory usage for a domain",
> + "Set the current memory usage for a domain. Units default to kilobytes, but can be suffixed with 'b' (bytes), 'k' (KB), 'm' (MB), 'g' (GB) or 't' (TB)",
> "<Domain> <MemKB>",
> },
> { "button-press",
>
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>
>
--
Regards
Yang Hongyang
next prev parent reply other threads:[~2010-05-18 1:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-18 0:41 [PATCH] xl: allow scaling suffix on memory sizes in mem-set and mem-max Jeremy Fitzhardinge
2010-05-18 1:45 ` Yang Hongyang [this message]
2010-05-18 17:04 ` Jeremy Fitzhardinge
2010-05-21 10:40 ` Ian Jackson
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=4BF1F11C.6020809@cn.fujitsu.com \
--to=yanghy@cn.fujitsu.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=Stefano.Stabellini@eu.citrix.com \
--cc=Vincent.Hanquez@eu.citrix.com \
--cc=jeremy@goop.org \
--cc=xen-devel@lists.xensource.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.