分类: 虚拟化
2014-12-05 18:09:40
Xenheap 和domheap的区别
Ian Campbell在Xen-devel里的回答
There are two models for xen vs. domheap, and therefore two version of
init_*heap_pages.
The original model is the split heap model, which is used on platforms
which have smaller virtual address spaces. e.g. arm32, for the moment
arm64 (but I am about to switch to the second model) and historically
the x86_32 platform. This is because as Andy notes xenheap must always
be mapped while domheap is not (and cannot be on these platforms),
domheap is mapped only on demand (map_domain_page).
In this case init_xenheap_pages contains:
/*
* Yuk! Ensure there is a one-page buffer between Xen and Dom zones, to
* prevent merging of power-of-two blocks across the zone boundary.
*/
if ( ps && !is_xen_heap_mfn(paddr_to_pfn(ps)-1) )
ps += PAGE_SIZE;
if ( !is_xen_heap_mfn(paddr_to_pfn(pe)) )
pe -= PAGE_SIZE;
The second model is used on systems which have large enough virtual
address to map all of RAM, currently x86_64 and soon arm64. In this case
there is only one underlying pool of memory and the split is more
logical than real, although it is tracked by setting PGC_xen_heap when
allocating xenheap pages. In this case domheap is actually always mapped
but you still must use map_domain_page to access it (so common code work
on both models)
There is actually an extension to the second model for systems which
have enourmous amounts of physical memory (e.g. >5TB on x86_64) which
brings back the xen/domheap split but in a different way to the first
model. In this case the split is implemented in alloc_xenheap_pages by
consulting xenheap_bits to restrict the allocations to only the direct
mapped region.
Andrew Cooper的回答
xenheap
pages have permanent mappings in the Xen virtual address space, so they can be
accessed from anywhere in the code. domheap pages by default do not have mappings,
and must be explicitly mapped to be used.
For PV guests, Xen hand most of the virtual
address space to the guest, so only the really critical memory can have
permanent mappings.
就只说ARM32吧,在ARM32上是分xenheap和domheap的,因为32位cpu地址空间只有4G,物理内存却可以比4G多,所以不是所有物理内存都有地址映射。
alloc_xenheap_pages()分配出来的页面,是map在xenheap地址空间的,从函数原型可以看出
返回的直接是xen地址空间的指针,不需要在调用map_pages_to_xen()了。并且__pa()和__va()这两个宏只能用于xenheap pages。
xen\xen\include\asm-arm\mm.h
而alloc_domheap_pages()分配出来的页面是没有map的,因此只能通过mfn来操作这个页面。
可以看到返回的是struct page_info*结构指针,想读写页面还得先map。而map的方式有三种:
1
xen\xen\arch\arm\mm.c
这种最好理解,映射到ioremap的256M-1G空间了,至于为什么是global的,貌似和PCPU VCPU相关的页表有关,我还没弄明白。看来并不是只有device能用这段地址。
xen\xen\include\xen\domain_page.h
2
调用map_domain_page()后,用返回的指针在xen的代码里就可以直接读写页面了,但我不明白为什么注释里说和VCPU有关。并且alloc_domheap_pages()第一个参数是domain,可以为NULL,也可以是domain。不同的domain,它们的dom page可以被别的domain访问吗?
看一个用到这个函数的例子
xen\xen\arch\arm\domain_build.c
点击(此处)折叠或打开
这是在创建dom0的时候调用的initrd_load(),这时候和VCPU有关了吗?
3
这个是可以map到指定的virtual address。
xen\xen\common\vmap.c
vmap()也是调的 create_xen_entries(),说明这个函数可以映射到xen的任意地址空间,不知道这样说对不对,可以映射到domheap地址空间吗?
Sure, you could take a xenheap page, extract the mfn and use
map_domain_page, but why?
从Ian的回答看,应该是可以的,至少用map_domain_page()是可以的。
用到map_pages_to_xen()的主要就是在__vmap()里。
xen\xen\common\vmap.c
点击(此处)折叠或打开
因为在256M-1G的VMAP地址空间, 前几个页面是bitmap机制自己用的。
如果不涉及到VCPU相关,很容易理解domheap的用法,和Windows里也差不多,但分配domheap的时候是和domain相关的,这个还要再看。
可以理解allocate_memory_11里为什么用alloc_domheap_pages()而不是xenheap,因为是分配给dom0的内存,xen不需要操作这个页面,只是知道这些物理页已经被分配了就可以了,所以xen不要把这些页面映射到xen自己的地址空间来。这些页面已经通过p2m机制,也就是create_p2m_entries()映射到dom0中了,所以dom0里的系统是可以用这些物理页的。
http://lists.xen.org/archives/html/xen-devel/2013-08/msg00702.html
http://lists.xen.org/archives/html/xen-devel/2013-08/msg00695.html
http://lists.xen.org/archives/html/xen-devel/2013-08/msg00871.html
http://lists.xen.org/archives/html/xen-devel/2013-08/msg01361.html