Display memory inconsistency between XM list and XL list
This problem occurs on a Windows VM on xen4.1.2:
# XM list test6
Name ID mem vcpus state time (s)
Test6 16 512 2-B ---- 158.0
# XL list test6
Name ID mem vcpus state time (s)
Test6 16 2048 2-B ---- 158.6
Two different tools are used to view the same Vm, and the memory size is nearly 2 GB.
Because the implementation mechanisms of XM and XL are different, you can view the source code of XM list and XL list respectively from the source code analysis.
XM list:
Previously (http://www.cnblogs.com/feisky/archive/2011/11/27/2265053.html) has analyzed the XM list source code, it gets the memory in xend and xenstore (both are always consistent)
The memory in xenstore can be read using the following command:
Xenstore-Read/Vm/[UUID]/memory
XL list:
==> XL. C: Main () --> cmdtable_lookup () --> main_list ()
==> Xl_cmdimpl.c: main_list ()
==> Libxl_domain_info (& CTX, & info_buf, domid );
==> Xc_domain_getinfolist (CTX-> xch, domid, 1, & xcinfo)
==> Xcinfo2xlinfo (& xcinfo, info_r)
==> Xlinfo-> current_memkb = page_to_memkb (xcinfo-> tot_pages );
==> Xc_domain_getinfolist (CTX-> xch, domid, 1, & xcinfo );
We can see that the XL list is implemented through the xen_sysctl_getdomaininfolist supercall.
==> Xen/common/sysctl. C: do_sysctl ()
==> Xen/common/domctl. C: getdomaininfo (D, & info)
Info-> tot_pages = D-> tot_pages;
Info-> max_pages = D-> max_pages;
Info-> shr_pages = atomic_read (& D-> shr_pages );
Info-> shared_info_frame = mfn_to_gmfn (D, _ Pa (D-> shared_info)> page_shift );
We can see that the XL list obtains the memory allocated by hypervisor for this domain.
Generally, hypervisor allocates 2 MB more memory for the domain than the memory passed in by xend (the same problem occurs on xen3.4.3, and the remaining 2 Mb is occupied by hypervisor)
[Root @ localhost ~] # XM Li test6
Name ID mem vcpus state time (s)
Test6 21 512 2-B ---- 79.4
[Root @ localhost ~] # XL list test6
Name ID mem vcpus state time (s)
Test6 21 514 2-B ---- 79.4
The problem encountered above is that although the memory is re-adjusted for the VM through XM mem-set, the new memory value is written to xend and xenstore, however, hypervisor does not immediately provide Ballon memory for the VM. If you execute the XL list multiple times, you can see that the memory of the test6 VM is reduced a little until 514 MB.