A kind of virtual machine communication method based on shared drive
Technical field
The present invention relates to the inter-domain communication field of virtual machine, particularly relate to a kind of efficient virtual machine communication method based on shared drive.
Background technology
Virtual machine (Virtual Machine:VM) is to support a kind of system of multiple operating system parallel running on the single physical server, and can providing more effectively, bottom hardware uses.In virtual machine, the central processing unit chip marks off one section storage area from system's other parts, and operating system and application program operate under " protected mode " environment.Because the advantage of Intel Virtualization Technology maximum is that thereby he can create virtual machine and provide independently function and performance for those services application of sharing same physical hardware platform resource.Virtual machine can improve the operation overhead of the utilization factor reduction total system in the system scope.Virtual machine monitor (Virtual Machine Monitor:VMM) is a software layer that is used to coordinate and manage virtual machine in same host, and it organizes the independence of strengthening between the virtual machine by the group of hardware or software part usually.The virtual machine monitor Xen that for example increases income, it is that it provides a kind of half Intel Virtualization Technology that is referred to as, and makes virtual machine can obtain the high-performance near host by the increasing income of Cambridge University's exploitation.It is highest that Xen monitor (Hypervisor) operates in system privilege, has a believable virtual machine to be called domain 0 and assist management that other are in the virtual machine of non-level of privilege.
From the angle of safety, the independence of strengthening between the virtual machine is crucial.But independence also can become the obstacle of communicating by letter between the virtual machine in same host.Virtual machine on same physical machine adopts front end-rear end driving to communicate at present.Consult shown in Figure 1ly, at present in the Xen communication structure network-driven is being divided into two parts, front-end driven and rear end drive.The rear end drives and is arranged in domain 0, and front-end driven is arranged in guest virtual machine.The actual physics network hardware that low level has been abandoned in communication between the virtual machine communicates, but communicates by high-level abstract network driving.Doing like this can be so that virtual machine only need know use be network-driven, is not concerned about which type of network-driven what use is and do not spend.In the time of will communicating between the virtual machine, communication one side sends the data to the rear end that is arranged in domain 0 with communication data by front-end driven and drives.Have only the domain 0 can all physical equipment resources of actual access in the Xen structure, the rear end drives after receiving packet, is forwarded to purpose IP via physical network card again according to the address in the packet.Because our research is in the communication between the virtual machine on the same physical machine, so the front is a loop through physical network card, and packet has been sent to the front-end driven of another virtual machine on this host, transfers to then to use and handles.
By top the existing virtual machine communication process analysis that is positioned on the same host is not difficult to find that communication path is very long, needs third-party participation (participation of domain 0) just can finish communication.Communication means is the same with the virtual machine communication method that is arranged in the different hosts of network between the virtual machine in same host.This method has been ignored and is positioned at same host's virtual machine and is actually and has shared common physical resource, as internal memory, CPU etc.Thereby cause between the virtual machine communication efficiency low, communication resources utilization ratio.Need to use the communication between the virtual machine under a lot of application scenarioss, its communication efficiency directly has influence on overall performance.Use such as, distributed high-performance computing machine and to have two processes and be positioned at different virtual machine on the same physical machine, may be between them because will use the MPI storehouse to communicate.In network service,, operate in that service routine in the virtual machine may need and the data base server in another virtual machine communicates in order to satisfy a user's event request.In these are used, all wish to maximize the communication throughput minimum latency.
Independence between the virtual machine is the key point of Intel Virtualization Technology, and this characteristic has directly influenced in the communication performance between the virtual machine on the same host.Along with the widespread use of virtual technology, the demand that the communication performance between the virtual machine improves increases, and the communication means of studying between the high performance virtual machine is very necessary and urgent.In order to improve the communication performance between the virtual machine, be necessary the characteristic of virtual machine is analyzed, the combined with virtual machine is shared the new communication means of characteristics design of physical resource.Therefore, the present invention propose based on the virtual machine communication method of shared drive to improving the virtual machine communication performance, using the virtual machine network resource to have very important significance rationally and effectively.
Summary of the invention
The present invention with provide directly, virtual machine communication efficiently is target, is core concept with the shared drive, solves the low problem of virtual machine communication performance.Specifically comprise:
1. at the physical resource layer, based on the shared drive ring structure, design do not have lock can asynchronous concurrent visit the shared drive access method.When this method and thought is that a plurality of processes are to this structural reference in the virtual machine, do not need to carry out tangible synchronous operation.
2. at the virtual resource layer,, set up the communication path between the virtual machine based on event channel, simultaneously in the virtual machine indoor design dynamic binding event channel method of virtual processor, realize the communication path between the virtual machine.Design event channel table in virtual machine monitor, giving communicates by letter between virtual machine submits necessary information.
3. in credible virtual machine (domain 0), design dynamic discovery mechanism of virtual machine and virtual machine information maintaining method.The dynamic discovery mechanism of virtual machine is as new virtual machine creating or virtual machine (vm) migration is arranged or when destroying, credible virtual machine can in time be found, and recording-related information.It is that the information of the virtual machine in same host is collected and put in order that virtual machine information is safeguarded.
4. at guest virtual machine, design the virtual machine communication management method, this method is mainly used in credible virtual machine carries out some necessary information communications, and communicates preceding necessary communication path preliminary work with other virtual machines.
Compared with prior art, innovation part of the present invention is: catch the characteristic of sharing physical resource at the virtual machine of same host, based on Sharing Memory Realization virtual machine communication efficiently.Be embodied in:
1. virtual machine is found, allows virtual machine perceive to be positioned at other virtual machines on the same host.Can only adopt traditional communication means for the communication between the virtual machine on the different hosts, can adopt more direct communication means efficiently for the virtual machine of same host, but at first need to allow virtual machine perceive the existence of other virtual machines.
2. comparing the traditional communication path needs third-party participation, the invention provides directly, communication path efficiently.When virtual machine will communicate,, directly carry out data communication by setting up communication port with the communication party.
The present invention proposes a kind of virtual machine communication method based on shared drive, this method realizes having in the system of following structure: this system has the Xen monitor, this Xen monitor is supervised other as virtual machine monitor and is operated in virtual machine on the actual physics machine, this system has franchise virtual machine, this privilege virtual machine has all authorities, can directly visit physical resource, this system also has a plurality of guest virtual machines, communicate between the guest virtual machine, the method is characterized in that to comprise the steps:
1) in the Xen monitor, safeguards an event channel table, be used to write down the information of all guest virtual machines on the physical machine, in each guest virtual machine, safeguard a event channel table copy;
2) the Xen monitor is that a new guest virtual machine of creating and a guest virtual machine that communicates with are created a pair of actual physics shared drive circle queue: the first actual physics internal memory circle queue and the second actual physics internal memory circle queue, described actual physics shared drive circle queue are used for the data communication between the guest virtual machine;
3) at two client virtual machine locals that participate in communication two virtual shared drive circle queues are set separately: virtual data sends the shared drive circle queue and virtual data receives the shared drive circle queue, and two guest virtual machines are mapped to local virtual shared drive circle queue the actual physics shared drive circle queue under it separately; In mapping process, the virtual data reception shared drive circle queue that the virtual data of first guest virtual machine sends the shared drive circle queue and second guest virtual machine is mapped to the first actual physics shared drive circle queue jointly; The virtual data transmission shared drive circle queue that the virtual data of first guest virtual machine receives the shared drive circle queue and second guest virtual machine is mapped to the second actual physics shared drive circle queue jointly;
4) described newly-built guest virtual machine is that the guest virtual machine that communicates with is created an event channel, and this event channel information sent to the virtual client of communicating by letter with described newly-built guest virtual machine, event channel is used for transmitting the signal incident of informing between two virtual machines of communication takes place;
5) when needing to communicate by letter between the virtual machine, thereby the communication initiator knows according to communication objective IP address lookup local event channel table whether communication objective be on same host, as on same host, the data that guest virtual machine will send write the local virtual data and send the shared drive circle queue; Communication objective client virtual chance is engaged in the part passage and is got the primary data arrival, from local virtual Data Receiving shared drive circle queue reading of data.
The event channel table comprises three attribute: Domain, IP, Port, Domain is ID number of each virtual machine of unique identification, IP is the IP address of virtual machine, Port is the event channel port numbers of virtual machine correspondence, table information is carried out maintenance update by franchise virtual machine, and franchise virtual machine carries out information gathering to all guest virtual machines on the host at set intervals and upgrades this table then.
The Xen monitor regularly sends up-to-date event channel table copy to guest virtual machine.
In the step 4), the guest virtual machine of communicating by letter with described newly-built guest virtual machine is selected a virtual cpu at random according to the event channel information that receives and is tied to this event channel in this locality, and binding returns to confirmation of described newly-built guest virtual machine after finishing.
Have only a communication port between the guest virtual machine of every pair of communication, a plurality of virtual cpus are arranged in each guest virtual machine, once can only have a virtual cpu to have the control of communication port; Virtual cpu in same guest virtual machine is held consultation by sending internuclear communication, finishes the transfer of event channel control.
When guest virtual machine need communicate, in the event channel table, retrieve, obtain domain number, again according to domain number retrieval port according to the IP address of communication objective guest virtual machine.
Description of drawings
Fig. 1 Xen front end back end communications system assumption diagram
Fig. 2 is based on the virtual machine communication architecture figure of shared drive
Fig. 3 shared drive data transmission mechanism design drawing
Fig. 4 event channel table design drawing
Fig. 5 event channel is set up
Embodiment
Consult Fig. 2, the present invention constructs communication path by the comprehensive Design of shared drive and event channel between the virtual machine at same host.Based on this, by design virtual machine discovery mechanism in franchise virtual machine and guest virtual machine and virtual machine telecommunication management mechanism, realize the efficient communication between the virtual machine.A communication port is arranged between any a pair of virtual machine, and this passage comprises an event channel and two belt formations of shared drives.Event channel is used for transmitting the signal incident of informing between the communication virtual machine takes place, and the formation of shared drive ring is used for the data communication between the virtual machine.Because franchise virtual machine has the highest weight limit, therefore virtual machine of design finds that module is used to collect and manage the information that is positioned at all guest virtual machines on this host in franchise virtual machine.For make all guest virtual machines can under limited authority, have access to efficiently by franchise virtual machine collect the relevant information of other virtual machines, the present invention safeguards in the Xen monitor that simultaneously an event channel table is used to write down virtual machines all on this host and the event channel information between the virtual machine.Information in the virtual machine discovery module meeting timing update event channel table in the privilege virtual machine is with the validity of guarantee information.Design management module in guest virtual machine is used to find the existence of other virtual machines, the communication path that dynamically binds to of managing the communication between local communication path, management local virtual machine and other virtual machines and managing local virtual CPU.
Consult Fig. 3, the present invention has at first designed shared drive data transmission mechanism efficiently at the physical resource layer.Authorization list among the Xen provides the mechanism of a shared drive between virtual machine.Each virtual machine all has the authorization list of oneself, by the unified management of Xen monitor.Virtual machine tells other virtual machines of Xen monitor to its all authority that shared drive had by authorization list.This characteristic of authorization list allows to communicate by shared drive between the virtual machine.Virtual machine can carry out copying data by shared drive.The present invention is based on shared drive design circle queue and come storing communication information.Circle queue is a producer-consumer's an annular buffer memory, can avoid the synchronous operation between the producers and consumers like this.This circle queue has two pointer: front and back, and front points to the circle queue head, and back points to the circle queue tail.When producer produces data, the direction circle queue of promptly communicating by letter inserts data, the back pointer adds 1; When consumer spending data, promptly communication objective side has taken data away from circle queue, the front pointer adds 1.Such design need not be considered the stationary problem between the producers and consumers, simultaneously when a plurality of producers or consumer will visit circle queue, just can guarantee the exclusive reference between them and not need more synchronous operation by a visit lock.To the communication virtual machine, two virtual shared drive circle queues are all arranged for each, promptly have only structure in each virtual machine this locality, but unactual dispensers reason space.In these two circle queues, one is used for the data transmission, and one is used for Data Receiving.The present invention simultaneously in the Xen virtual machine monitor be each to two shared drive circle queues of virtual machine creating, and be its distribution actual physics shared memory space.The communication virtual machine is mapped to the actual physics shared drive circle queue that is arranged in the Xen virtual machine monitor with the virtual shared drive circle queue of this locality.Mapping step is as follows:
A) guest virtual machine 1 sends the shared drive circle queue with the local virtual data and is mapped to actual physics shared drive circle queue 1
B) guest virtual machine 1 is mapped to actual physics shared drive circle queue 2 with local virtual Data Receiving shared drive circle queue
C) guest virtual machine 2 sends the shared drive circle queue with the local virtual data and is mapped to actual physics shared drive circle queue 1
D) guest virtual machine 2 is mapped to actual physics shared drive circle queue 2 with local virtual Data Receiving shared drive circle queue
Making virtual data in the guest virtual machine 1 send virtual data in shared drive circle queue and the guest virtual machine 2 by above-mentioned mapping method receives the shared drive circle queue and is mapped to same actual physics shared drive circle queue.Like this, the 1 pair of local virtual data of guest virtual machine send the operation that writes data in the shared drive circle queue and are equal to data write operation to the local virtual Data Receiving shared drive circle queue of guest virtual machine 2.Same, the virtual data transmission shared drive circle queue that the virtual data in the guest virtual machine 1 receives in shared drive circle queue and the guest virtual machine 2 is mapped to same actual physics shared drive circle queue.By this mapping method, thereby make the memory copying that only need carry out once operate the data transmission that just can finish between the virtual machine.
At the virtual resource layer, we carry out asynchronous communication by set up event channel between each guest virtual machine to communication.Each virtual machine all can be set up an event channel and is used for communication in being positioned on the same host each other client virtual.In order to manage numerous event channels, the present invention has set up an event channel table in the Xen virtual machine monitor, as shown in Figure 4.The event channel table comprises three attributes:
Domain: i.e. domain ID, come unique identification position each virtual machine thereon with domain ID in the Xen architecture
IP: the IP address of virtual machine
Port: event channel port numbers, the event channel on can the unique identification host.
Event channel and port almost are of equal value in the Xen system architecture.An event channel is the abstract of two ports, and port is to be used to indicate the sign that is tied to which event channel.When having created an event channel, its end is ined succession and is created its virtual machine, and the other end can allow other virtual machines to connect.Two virtual machines are connected to such an extent that port numbers is the same, so port numbers can event channel of unique identification.By the design of above-mentioned event channel table, can know that by the query event channel table connecting which event channel in numerous event channels can communicate with the purpose guest virtual machine simultaneously so that all virtual machines perceive the existence of other virtual machines.When a guest virtual machine is want when another guest virtual machine is initiated communication, it can be found according to following steps and be tied to which event channel port and communicate:
A), obtain the VM_ID of purpose virtual machine according to the IP address browsing event channel table of purpose virtual machine
B) VM_ID according to the virtual machine that obtains searches the event channel port numbers set that this virtual machine has
C) search the own event channel port numbers set that is had according to self VM_ID
D) two set are occured simultaneously obtain an event channel port numbers
The information of event channel table is carried out maintenance update by franchise virtual machine, each guest virtual machine can send an announcement information and find module to the virtual machine in the franchise virtual machine when creating, this module can be set up a record for this guest virtual machine, and begins regularly to follow the trail of the information of this virtual machine since then.Communication is when guest virtual machine migration or destroy, and can send an announcement information equally to franchise virtual machine, and franchise virtual machine can be deleted the record of this virtual machine and event channel information record that all are relevant with this virtual machine in the event channel table.In order to improve the performance of guest virtual machine Access Events channel table, at the copy of an event channel table of each guest virtual machine local maintenance.When guest virtual machine was created, franchise virtual machine can send the copy of an event channel table to guest virtual machine.Guest virtual machine can have been inquired about efficiently in this locality like this, and need not visit again the Xen monitor that is in level of privilege.For the validity of the event channel table that keeps each client virtual machine local, franchise virtual machine regularly upgrades the local event channel table of each guest virtual machine.Between every pair of guest virtual machine, only there is a communication path, a plurality of virtual cpus are arranged in each virtual machine, therefore need a cover and coordinate the mechanism that virtual cpu uses unique communication path in each virtual machine inside.For this reason, the present invention in each virtual machine indoor design dynamic event passage binding mechanism control of coordinating event channel between virtual cpu, transmit, concrete steps are as follows:
A) request virtual cpu 1 sends internuclear communication information bag to the virtual cpu 2 that has the event channel control, and request obtains the control of event channel
B) virtual cpu 2 listens to the event channel request, checks at present the behaviour in service to event channel, if using then enter step c), if event channel does not use, then enters step d)
C) virtual cpu 2 release event passages send the idle request of event channel success packet by internuclear communication to virtual cpu 1
D) virtual cpu 2 continues to use event channel, and it is busy to send event channel by internuclear communication to virtual cpu 2, request failure information bag
E) virtual cpu 1 listens to the feedback information of CPU 2, if return message is the request failure, virtual cpu 1 waits for that certain hour changes step a) at interval again over to. if return message for to ask successfully, then changes step f) over to
F) virtual cpu 1 obtains the control of event channel, and oneself is tied to event channel, communicates
After a new guest virtual machine is created, this virtual machine can carry out necessary log-on message with franchise virtual machine and exchange, in the event channel table, register, guest virtual machine is created two virtual shared drive circle queues and an event channel earlier in this locality, set up communication port then and between the every other guest virtual machine on this host, specifically as shown in Figure 5.
Communication port between the guest virtual machine is set up process and is similar to the process that client and server connects.We will have less virtual machine ID number guest virtual machine as server (guest virtual machine 1) in setting up process, and another guest virtual machine is as client (guest virtual machine 2).At first guest virtual machine 1 is provided with two virtual shared drive circle queues in local shared drive: SEND and RECV, and the former is used to send data, and the latter is used to receive data.Guest virtual machine 1 is initiated the shared drive request to the Xen virtual machine monitor then, creates two actual physics shared drive circle queues in the Xen monitor.Virtual shared drive circle queue with this locality is mapped to actual physics shared drive circle queue according to method noted earlier then.Simultaneously, guest virtual machine 1 can be created an event channel, and this event channel one end is tied to a virtual cpu of guest virtual machine 1, exposes the guest virtual machine binding of another port for communication then.The information that guest virtual machine 1 will be created passage is packaged into packet and sends to guest virtual machine 2, and information comprises following content:
The SEND address: the virtual transmission shared drive circle queue of guest virtual machine 1 is mapped to the address of actual physics shared drive circle queue
The RECV address: the virtual reception shared drive circle queue of guest virtual machine 1 is mapped to the address of actual physics shared drive circle queue
Port number: another port of event channel is used for the binding to communication the opposing party
This information is intercepted and received to guest virtual machine 2, then according to the shared drive address in the information, oneself local virtual received the shared drive circle queue be mapped to the SEND address, and the virtual generation shared drive circle queue of this locality is mapped to the RECV address.Simultaneously, select a virtual cpu to be tied on the port of event channel.So far, the communication path between guest virtual machine 1 and the guest virtual machine 2 is set up and is finished.Guest virtual machine 2 can confirm that packet returns to guest virtual machine 1 by one of structure.In order to guarantee that setting up packets of information does not lose, guest virtual machine 1 is not received the affirmation packets of information from guest virtual machine 2 in the expectation time, can restart the establishment connection procedure, if failure is above three times, then guest virtual machine 1 is abandoned connecting, and error message is returned to franchise virtual machine.