Re: [libvirt] virNodeGetFreeMemory() returns bytes with Xen driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Apr 14, 2009 at 02:08:27PM -0700, Tyrel Datwyler wrote:
> 
> The libvirt API states that the return value of virNodeGetFreeMemory() is
> in kilobytes. When making this call against a Xen hypervisor and comparing
> the returned value with what is listed by "xm info" it appears that libvirt
> is returning the free memory in bytes and not kilobytes. Can anybody
> confirm this behavior?
> 
> This code snippet:
> 
>     conn = virConnectOpen("xen:///localhost/");
>     hostmem = virNodeGetFreeMemory(conn);
>     fprintf(stdout, "Host free memory = %llu\n", hostmem);
> 
> produces the following output:
> 
>     Host free memory = 3236012032
> 
> The following comes from running "xm info" on the Xen host:
> 
>     free_memory            : 3086
> 
> The libvirt value is convertable into the "xm" returned value if bytes is
> assumed.

  Yes that's an unfortunate case where the implementations didn't follow
the expected APIs, all drivers seems to return byte values, instead of
kB. So at this point it sounds better to acknoledge the fact, and avoid
breaking all applications. It's annoying because all other memory APIs
in libvirt use kB so I will put a special not in the function
description.

   thanks for the heads-up !

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
Index: src/libvirt.c
===================================================================
RCS file: /data/cvs/libxen/src/libvirt.c,v
retrieving revision 1.201
diff -u -r1.201 libvirt.c
--- src/libvirt.c	31 Mar 2009 15:47:17 -0000	1.201
+++ src/libvirt.c	17 Apr 2009 14:05:12 -0000
@@ -3158,8 +3158,10 @@
  * @conn: pointer to the hypervisor connection
  *
  * provides the free memory available on the Node
+ * Note: most libvirt APIs provide memory sizes in kilobytes, but in this
+ * function the returned value is in bytes. Divide by 1024 as necessary.
  *
- * Returns the available free memory in kilobytes or 0 in case of error
+ * Returns the available free memory in bytes or 0 in case of error
  */
 unsigned long long
 virNodeGetFreeMemory(virConnectPtr conn)
--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]