Xen为什么一定要进入内核


这个问题我问了一位名为笑遍世界的博主,这位博主在写一本名为《KVM虚拟化原理与实践》的书,在他的博客上连载了书里面的部分章节,目前我在网上能找到最好的中文资料就是这个连载了。

博客地址:http://smilejay.com/kvm_theory_practice/


我:

有几个问题想请问博主,还望解疑: Xen为什么一定要进入内核呢,进入内核意味着它也要借助linux内核对硬件资源管理和调度吗? 博主能不能简单说点对KVMXen的看法? 谢谢


master

对的,应该是你说的那样的,不过注意xen hypervisor本身几乎是永远不能进入Linux内核的,只是说和Xen配合使用的dom0 kernel已经可以完全直接使用Linux kernel upstream了(意思是Linux内核这边的为了xen进行的相关改动已经全部进入到Linux原生内核中了)。我工作和学习对KVMXen都是涉及到的,其实很早就准备写一篇KVM/Xen的看法的,等等吧~~ 我的大致观点与这篇文章有点类似(我不敢自称专家哈):
http://chucknology.com/2012/04/15/kvm-is-still-linux-xen-is-still-not/


KVM is still Linux. Xen is still not.

Posted on April 15, 2012by cdubuque

http://chucknology.com/2012/04/15/kvm-is-still-linux-xen-is-still-not/


我希望之前写的KVM is Linux, Xen is Not  这篇文章能帮助大家更好的理解KVMXen之间的区别。

Its been gratifying to see lots of folks finding my site a couple of months after my first post, reading the article KVM is Linux, Xen is Not, and retweeting it to a broader audience. I seem to have hit a nerve, and I hope I have provided some value in helping folks understand the differences between KVM and Xen.

我是Red Hat公司的员工,工作也是与KVM相关。当然是KVM技术的支持者。

If youve read in the last couple of weeks, you probably noticed that posting has attracted some less than positive comments from Xen adherents.

All cards on the table: I am a KVM adherent. I work for Red Hat, and I work on a KVM-based product. Moreover, I personally believe that KVM is the best technology going forward for open source virtualization.

Linux 3.0. 内核中,加入了部分Xen代码,而我那篇文章主要是为了谈谈在Xen的部分代码进入linux3.0之前与之后,XenKVM的一些架构上的区别。

My goal in the post was to point out the architectural differences between Xen and KVM, before and after the inclusion of some Xen code beginning with Linux 3.0. And yes, to poke some fun at Citrix and Oracle.

Based on the recent comments Ive gotten, I thought it was worth writing a short post before going on to other topics.

I was tempted to do some editing to the original post (a footnote here, a qualification there), but aside from fixing a couple of incorrect links, I decided to let it stand as originally written and posted for better or worse.

I do apologize for initially pointing to the incorrect article as the attribution link for Simon Crosbys quote. I have made that correction in the post.

But unless there are technical inaccuracies, I am not making any further edits. You the reader can decide if I was fair, pushing things to make a point, or way off base and need to apologize for muckraking.

Lets step back in time a bit

那篇大致在 2011/07 写完,是为了说清楚关于Xen进入Linux内核的真正意义的问题。

Now, the post is a bit out of its historical context. After all I wrote most of it in July of 2011 for a different forum to address a real issuethe confusion about what Xen being acceptedinto Linux actually means.

Confusion still reigns

额。。关于Xen进入内核到底意味着什么,很多人仍然有困惑。

OracleCitrix的一年前的一篇声明让很多人产生一种印象,就是Xen也进入了Linux内核,这使得KVM这种基于linux内核的技术,失去了它作为Linux内核一部分而带来的相对优势。

正是为了澄清这一个误解,我才写了KVM is Linux, Xen is Not 这篇文章。

Almost a year later, people still ask what that announcement from Oracle and Citrix means. And still the overwhelming impression that people come away with from reading the coverage and talking to sales people is that Xen is now integrated into Linux, and that KVMs advantages in that regard are moot.

Addressing that confusion was the ultimate intent of the post.

Was it a bit cheeky to call out the Oracle and Citrix at the top of the article? Sure. Guilty as charged. It helped get the post out to a broader audience than I expected for what at its heart is a relatively dry but important architectural distinction.

Is there anything technically inaccurate in the post? I havent heard of anything yet, but I commit to immediately correct any technical inaccuracies.

Did I not give the people behind the posts the benefit of the doubt?Maybe. I admit I was fixated on the inaccuracies and FUD circulating at the time.

我想说的是,如果你对XenKVM的技术架构有足够的了解,而且也了解Linux内核中与之相关的那部分内核代码,那么你读了KVM is Linux, Xen is Not这篇文章之后,是应该能够知道Xen的那篇声明是什么意思的。

I will say this: if you understand enough about the architecture of Xen, of KVM, and the process of including code in the Linux kernel, then reading in full the cited articles will give you an accurate account of what the Xen announcement means for Xen and for KVM.

If however you dont know hypervisor architectures that well, or you only read the press and second hand accounts, or what a sales person told you, or the headlines and soundbites, then you probably got the wrong impression. This article was written for you.

Enough said.

Im moving on to other topics. Feel free to comment.

KVM is Linux. Xen is Not.


Linux 3.0内核开始接收Xen 的部分代码了,有些人说这意味着Xen已经如同Kvm一样被紧密的整合到了Linux内核中,我想告诉你的是事实并非如此。 Kvm仍然是唯一整合进Linux内核的技术。

Last year there was a lot of talk from Citrix, XenSource, and Oracle about the acceptance of certain Xen code and drivers into the Linux 3.0 kernel. I still hear it today. Theyre implying that it means the Xen has been as tightly integrated into the Linux kernel as KVM. And Im here to tell you that they are wrong.

Heres what Oracle and Citrix have said on the matter:

Ive heard over the last few years, competitors use There is no Xen support in Linuxas a tagline to create FUD with the Xen userbase and promote alternatives. Well, its all there people.Wim Coekaert, Oracle

During all the fuss of Citrix Synergy last week, an event of pretty earth-shattering importance occurred in the open source world: all key Xen code was accepted into the Linux mainline kernel.Simon Crosby, Citrix

Wrong!

The Oracle and Citrix marketing on this issue are misleading to say the least. It implies that the recent acceptance of some Xen enablement code into the Linux kernel equates to integration, or that the Xen architecture doesnt matter now that some of their code is in Linux.

KVM is still the only Linux kernel-integrated hypervisor technology. End of sentence. End of story.

KVM被整合到Linux内核中,意味着KVM使用Linux来做包括 设备管理,CPU调度,内存页分享,以更好的算法利用 CPU内核和内存,以及利用近五年来 IntelAMDx86硬件虚拟化技术。

There is no special KVM enablement needed in the Linux kernel. KVM is integrated into the Linux kernel.KVM uses Linux for everything from device management to CPU scheduling, memory page sharing, better algorithms for making use of lots of cores and lots of memory, and tying into all the hardware virtualization technology AMD and Intel have been building into x86 for the past 5 years.

Xen is no more mainineor mainstreamtoday in 2012 when it comes to Linux than it was in 2007 when KVM was accepted into the Linux kernel, or 2009 when Red Hat decided to move forward with KVM instead of Xen and integrated KVM into RHEL.

OK, then, whats the Real Scoop?

Xen实际上仍然是没有进入内核的,Xenhypervisor技术,决定了它无法直接“影响”linux内核的技术,如:transparent huge pages - 透明大型分页, CFS scheduler, paging-分页, memory overcommitment with KSM -内存过载,等等。

你仍然需要在裸硬件上安装Xen kernel,构建一个特殊的VM客户机“Dom0”来管理这个Xen kenerl(我不太了解Xen, 或许我这里翻译有误, 仅作参考),并提供设备驱动。Xen的技术架构仍然是 Xen-Dom0-DomU

Xen has still not been accepted (and probably never will be) into the Linux kernel, and cannot leverage directly Linux technologies such as transparent huge pages, CFS scheduler, paging, memory overcommitment with KSM, etc. for its hypervisor technology. You still need to install the Xen kernel on bare metal and build a special VM called a Dom0 to manage it and to provide device drivers. And you still have the suboptimal Xen architecture with Xen-Dom0-DomU. See the ugly diagrams below for more details.

那所谓的Linux 3.0接收Xen进入意味着什么呢。仅意味着两件事情:
1、自linux 3.0开始,Xen使用的paravirtualized drivers - 半虚拟化驱动 会被整合到linux内核中。这个类似于,从Linux 3.x+ 开始,如果你想在Linux 3.x+内核的客户机中使用virtio ( KVM/libvirt )pv-scsi ( VMware )pv-ops 这些用来加速 disk(磁盘) 和 NIC(网卡)硬件,就不用自己去整合到客户机里面,已经给你准备好了。

2、从linxu 3.0开始,你不需要修改内核,就可以使用linux做为Dom0。记住Dom0Xen的控制台操作系统所在,也要负责处理某些的来自客户机的IO请求。Dom0不是Xen本身,Xen仍然在裸硬件上,是独立于Linux的一个项目,Xen要自己去做支持硬件和新的虚拟化技术的工作。

总之,从linux 3.0开始,如果你要使用Xen(当前版本和未来的版本)来做hypervisor,那么,你使用Linux 系统作为客户机,或者作为Dom0,会相对容易一些。

如果你要使用linux 3.0之前的版本做Dom0,则需要修改 (wont work without modifications)

如果你要使用linux 3.0之前的版本做客户机,你需要hack in the drivers(不明白什么意思)

因为KVM被整合进了Linux 内核,所以它可以利用继承自linux的一些功能来做hypervisor的工作。如:scheduling, paging, frequency scaling and hardware enablement

Xen仍然需要自己完成这一部分的工作,这是Xen技术的一部分,将来也不会改变的。

The announcement of Xen and Linux 3.0 means two (and only two) things:

1. The paravirtualized drivers that Xen uses will be integrated into Linux starting with 3.0. This means that just like virtio(KVM/Libvirt) and pv-scsi (VMware), the pv-ops drivers used for accelerated disk and NIC will be available in any Linux 3.x+ guest without having to integrate drivers. This leaves Microsoft Hyper-V alone in requiring integrating drivers for guests.

2. A Linux 3.0 or higher guest can be used unmodified as a Dom0. Remember Dom0is where the console operating system resides and is also a slave for certain IO from the guests. It is not Xen itself. Xen still resides on the bare metal and is still a separate project from Linux that has to duplicate effort to support hardware and new virtualization technologies.

In summary, it will be slightly easier to use future versions of Linux guests with current and future versionsof Xen, and it will be slightly easier to use future versionsof Linux as a Dom0for current and future versionsof Xen.

If you want to use a pre-3.0 Linux as a Dom0 it wont work without modifications. If you want to use pre-3.0 Linux guests, you still need to hack in the drivers.

Not such a big deal after all. So does this change anything for KVM?

In a word, No.

One of KVMs strengths is that it is integrated into the Linux kernel and therefore can utilize Linux features for things that hypervisors do besides just being a hypervisor.

Xen hypervisor is still a separate project and a completely separate code base, and features that KVM can use for virtualization and inherits from Linux (scheduling, paging, frequency scaling and hardware enablement, for example) will still need to be separately implemented in Xen. This is part of the design of Xen and is not going to change.

KVM Architecture

Elegant, isnt it?

114213295.png

Xen Architecture

What a mess

114238471.png

114239328.png


What did they say? Word for word. Im taking down names.

Heres links to the various blogs Citrix and Oracle have put out:

http://blogs.citrix.com/2011/05/30/xen-celebrates-the-final-step-of-a-four-year-odyssey/

http://blogs.oracle.com/wim/entry/linux_mainline_contains_all_the