Summary of the invention
The object of the present invention is to provide a kind of virtual machine dynamic EMS memory management system based on the internal memory hot plug, this system can break the internal memory upper limit of virtual machine, increases or reduce virtual machine arbitrarily; Can adjust the memory size of each virtual machine dynamically according to the variation of virtual machine load, satisfy the memory requirements of virtual machine and improve the memory usage of physical machine; When the physical machine low memory, by rationally reducing the internal memory of existing virtual machine, the virtual machine that dynamic creation is new.
Virtual machine dynamic EMS memory management system based on the internal memory hot plug comprises
The internal memory monitoring module is used to obtain the memory information of each virtual machine;
Memory allocating module is used for carrying out Dram distribution and dynmaic establishing virtual machine according to the memory information of each virtual machine;
The internal memory hot plug module is used for the internal memory of virtual machine is adjusted to the internal memory desired value that memory allocating module calculates;
Described Dram distribution is carried out in the following manner:
(11) calculate the memory increase Δ M of each virtual machinel=MUsed(n)l-MUsed(n-1)lWith exchange partition increment Delta Sl=S (n)l-S (n-1)l, M whereinUsed(n)lAnd MUsed(n-1)lBe respectively the use internal memory of l virtual machine, S (n) at n and n-1 time pointlAnd S (n-1)lBe respectively the use exchange partition of l virtual machine at n and n-1 time point, l=1 ..., L, L are the virtual machine sum;
(12) predict the use internal memory M that the next time point of each virtual machine needsPredict(n+1)l=MUsed(n)l+ Δ Ml+ Δ Sl
(13) the average memory usage of n+1 time point of calculating
(14) calculate the internal memory desired value M of each virtual machine at n+1 time pointTarget(n+1)l=MPredict(n+1)l/ UAvg(n+1);
(15) the invoke memory hot plug module is adjusted the internal memory of each virtual machine to desired value MTarget(n+1)l
(16) sleep T second, return step (11) then;
Described dynmaic establishing virtual machine carries out in the following manner:
(21) if the internal memory that the free memory of physical machine is set more than or equal to new virtual machine is then directly created new virtual machine, finish; Otherwise, enter step (22);
(22) calculate the existing current average memory usage U of virtual machineAvg=∑ MUsed/ (∑ MTotal-MNew+ MFree), wherein, ∑ MUsedBe the existing current use internal memory summation of virtual machine, ∑ MTotalBe the internal memory sum of existing virtual machine, MNewBe the internal memory that new virtual machine is set, MFreeBe the current free memory of physical machine;
(23) calculate the internal memory desired value M of each existing virtual machineTargetl=MUsedl/ UAvg, MUsedlBe l the current use internal memory of existing virtual machine;
(24) the invoke memory hot plug module is created new virtual machine after the internal memory of each existing virtual machine is adjusted to the internal memory desired value that step (23) obtains.
Further, described internal memory hot plug module is adjusted virutal machine memory in the following manner:
(31) the internal memory desired value of virtual machine and the current internal memory of virtual machine are compared, if greater than, step (32) entered; If less than, enter step (34); If equal, then finish;
(32) if the physical address space of virtual machine less than the internal memory desired value of virtual machine, then expand its physical address space to more than or equal to the internal memory desired value, remember that the memory pages in the new physics address space of expanding is an off-line page, enter step (33), otherwise, directly enter step (33);
(33) increase virutal machine memory to the internal memory desired value:
(331) if the internal memory desired value of virtual machine greater than current internal memory, is then calculated the difference DELTA of virutal machine memory desired value and current internal memory1, enter step (332), otherwise, finish;
(332) if there is the reservation page, then is one and keeps page storage allocation, remember that this reservation page is a free Page, return step (331); Otherwise, enter step (333);
(333) if Δ1Greater than 128M and there is the off-line application heap, then be an off-line application heap storage allocation, remember that this off-line application heap is the free memory section, return step (331), otherwise, enter step (334);
(335) according to the address sequencing one by one to the off-line page storage allocation up to the internal memory that is assigned with equal Δ1, the off-line page that note is assigned with internal memory is a free Page;
(34) reduce virutal machine memory to the internal memory desired value:
(341) if the internal memory desired value of virtual machine less than current internal memory, is then calculated the difference DELTA of current internal memory and virutal machine memory desired value2, enter step (342), otherwise, finish;
(342) if Δ2More than or equal to 128M, then enter step (343), otherwise, enter step (344);
(343) whether inquiry exists deletable application heap, if exist, then the internal memory with one of them application heap discharges to virtual machine manager, remembers that this application heap is the off-line application heap, returns step (341), otherwise, enter step (344);
(344) be Δ to VME operating system application size2Internal memory, the memory pages of applying for is discharged to virtual machine manager, and remembers that these pages are for keeping the page.
Particularly, the present invention has following characteristics:
(1) favorable expandability
Xen uses balloon to drive the memory size of adjusting virtual machine now, balloon drive can not EVM(extended virtual machine) physical address space, the internal memory upper limit in the time of promptly can not breaking through virtual machine activation, frequent in addition use balloon drives and can produce a large amount of memory fragmentations.The virutal machine memory hot plug technology that realizes among the present invention, physical address space that can EVM(extended virtual machine) makes the memory size no maximum of virtual machine, can increase or reduce virutal machine memory arbitrarily, effectively raises the extendability of virutal machine memory; Drive with balloon and to compare, the mode by the internal memory hot plug reduces the generation that internal memory can be avoided memory fragmentation.
(2) availability is good
The memory management of Xen virtual machine is static, can only manually adjust the virutal machine memory size, along with the variation of load, the situation of low memory or internal memory waste may occur.Dram distribution function among the present invention is the memory pressure of perception virtual machine dynamically, the memory requirements of prediction virtual machine, the memory pressure of balance virtual machine, can satisfy the memory requirements of virtual machine, improve the virtual machine performance, can improve the memory usage of physical machine again, strengthen the availability of virtual machine.
When the physical machine low memory, Xen can't create new virtual machine.Dynmaic establishing virtual machine function among the present invention can be when the physical machine low memory, by rationally reducing the internal memory of existing virtual machine, create new virtual machine, realize the excessive use of critical function internal memory (memory overcommit) in the Intel Virtualization Technology, strengthened the availability of virtual machine.
(3) good stability
The present invention is through test for a long time, use multiple test environment during test, comprise the various extreme cases of manual setting, and use various authoritys' benchmark to test for a long time, every function in the proof system all is stable as a result, reliably.
Embodiment
The dynamic EMS memory management system that the present invention realizes is developed based on Xen4.0, at half virtual virtual machine.
System architecture as shown in Figure 1, this system applies is in the physical hardware of x86 framework, virtual machine manager (Virtual Machine Monitor) operates on the physical hardware, is responsible for the resource management of the bottom, such as memory management, CPU scheduling, device access etc.Domain 0 is a privileged domain, has only one, is in charge of each domain U.Domain U is the client territory, can have a plurality ofly, and the virtual machine of hereinafter mentioning all refers to domain U.Xenstore is the file system of a similar database, is set up by domain 0, shares with each domain U.Xenstore has stored the configuration and the status information of virtual machine, and every kind of information all has corresponding data item, and domain 0 and domain U carry out inter-domain communication by reading and writing same data item.Memory information monitoring process of operation among each domain U obtains memory information and sends to domain 0; Dram distribution process of operation among the domain 0, be responsible for receiving the memory information of domain U, for Dram distributes and dynmaic establishing virtual machine function is calculated the internal memory desired value of each domain U, and send to the internal memory hot plug driving among the domain U.The operating system of Domain 0 and domain U is 64 Linux (the kernel version is 2.6.31).
As shown in Figure 2, this system is made of three modules, is respectively the internal memory monitoring module, memory allocating module and internal memory hot plug module.
The effect of internal memory monitoring module is the memory information that monitors each virtual machine, and specific practice is to carry out inter-domain communication by xenstore.Process of operation obtains required memory information among the Domain U, comprises memory usage, exchange partition utilization factor etc., and write xenstore; Process of operation reads xenstore among the domain 0, obtains the memory information of domain U.The internal memory of virtual machine comprises use internal memory and free memory, and memory usage just is to use internal memory to account for the ratio of virutal machine memory.
The effect of memory allocating module is how to distribute virutal machine memory when calculating Dram distribution and dynmaic establishing virtual machine.Specific practice is to analyze the memory information that the internal memory monitoring module obtains, and uses corresponding allocation algorithm to calculate the desired value of each virutal machine memory size.
The effect of internal memory hot plug module is a memory size of adjusting each virtual machine, and specific practice is the virutal machine memory desired value that calculates according to memory allocating module, and the invoke memory hot plug drives adjusts virutal machine memory to desired value; The calling interface of user's attitude also is provided in addition, and manually the invoke memory hot plug drives and adjusts the virutal machine memory size.
The state that physical address space may occur in the internal memory hot plug driving implementation as shown in Figure 3.White portion is represented the free memory of operating system; Dash area is represented the unavailable internal memory of operating system, and comprise the off-line application heap that produces when reducing internal memory and keep the page, and the off-line page at the physical address space end that stays when increasing internal memory of fine granularity.
Dynamic EMS memory management system has the internal memory hot plug, and Dram distributes, and three kinds of basic functions of dynmaic establishing virtual machine are done detailed explanation below in conjunction with accompanying drawing and example to the present invention.
(1) as shown in Figure 4, the workflow of internal memory hot plug driving is as follows:
(1.1) load internal memory hot plug driver module, and initialization;
(1.2) receive the internal memory desired value, carry out internal memory hot plug task;
(1.3) increase internal memory processing function if the internal memory desired value greater than the virutal machine memory currency, is carried out, increase the associative operation of internal memory, enter step (1.4); Reduce internal memory processing function if desired value less than the virutal machine memory currency, is carried out, reduce the associative operation of internal memory, enter step (1.4);
(1.4), finish if desired value equals currency; Otherwise (certain step occurs wrong) enters step (1.3) behind the timeticks of dormancy (HZ), continues to carry out internal memory hot plug task.
As shown in Figure 5, the flow process of increase internal memory is as follows:
(A1) if the physical address space of virtual machine less than the internal memory desired value of virtual machine, then expand its physical address space to more than or equal to the internal memory desired value, remember that the memory pages in the new physics address space of expanding is an off-line page, enter step (2.2), otherwise, directly enter step (2.2)
(A2) if the internal memory desired value of virtual machine greater than current internal memory, is then calculated the difference DELTA of virutal machine memory desired value and current internal memory1, enter step (A3), otherwise, finish;
(A3) if there is the reservation page, then, remember that this reservation page is that free Page has promptly increased one page internal memory, returns step (A2) for one of them keeps page storage allocation; Otherwise, enter step (A4);
(A4) if Δ1More than or equal to 128M and there is the off-line application heap, then be one of them off-line application heap storage allocation, remember that this off-line application heap is that the free memory section has promptly increased by one section internal memory, return step (A2), otherwise, enter step (A5);
(A5) according to the address sequencing one by one to the off-line page storage allocation up to the internal memory that is assigned with equal Δ1, the off-line page that note is assigned with internal memory is a free Page, increase internal memory operation and finish this moment.
As shown in Figure 6, it is as follows to reduce the flow process of internal memory:
(B1) if the internal memory desired value of virtual machine less than current internal memory, is then calculated the difference DELTA of current internal memory and virutal machine memory desired value2, enter step (B2), otherwise, finish;
(B2) if Δ2More than or equal to 128M, then enter step (B3), otherwise, enter step (B4);
(B3) whether inquiry exists deletable application heap, deletable application heap is meant and can makes all memory pages in this application heap become free page by the internal memory migrating technology, if exist, then one of them application heap physical address corresponding space is deleted from memory allocator, and the internal memory of this application heap discharged to virtual machine manager, remember that this application heap is that the off-line application heap has promptly reduced one section internal memory, returns step (B1), otherwise, enter step (B4)
(B4) be Δ to VME operating system application size2Internal memory, the memory pages of applying for is discharged to virtual machine manager, and remembers that these pages for keeping the page, have promptly reduced size and have been Δ2Internal memory, the operation that reduce internal memory this moment is finished.
(2) as shown in Figure 7, the Dram flow process that shares out the work is as follows:
(2.1) obtain the memory information of each virtual machine by the internal memory monitoring module;
(2.2) calculate the memory increase Δ M of each virtual machinelWith exchange partition increment Delta Sl, computing method are as follows, wherein MUsed(n)lAnd MUsed(n-1)lBe respectively the use internal memory of l virtual machine, S (n) at n and n-1 time pointlAnd S (n-1)lBe respectively the use exchange partition of l virtual machine at n and n-1 time point, l=1 ..., L, L are the virtual machine sum, n time point is current point in time;
(2.3) prediction memory requirements, the use internal memory that promptly next time point needs, predicted value MPredict(n+1)lEqual current use internal memory MUsed(n)lAdd memory increase and exchange partition increment;
| Mpredict(n+1)l=Mused(n)l+ΔMl+ΔSl |
(2.4) the average memory usage U of n+1 time point of calculatingAvg(n+1), MTotal(n)lBe the internal memory of l virtual machine at n time point;
(2.5) calculate the internal memory desired value M of each virtual machine at n+1 time pointTarget(n+1)l, equal the memory requirements predicted value divided by average memory usage.
| Mtarget(n+1)l=Mpredict(n+1)l/Uavg(n+1) |
(2.6) if the virutal machine memory utilization factor in average memory usage scope (1~10%), enters step (2.7); Otherwise enter step (2.8);
| |Mpredict(n+1)l/Mtotal(n)l-Uavg(n+1) |≤average memory usage scope |
(2.7) internal memory desired value assignment is the internal memory currency, does not adjust memory size, and purpose is to reduce the number of times that internal memory is adjusted;
(2.8) if the internal memory desired value less than producing the critical value (Committed_AS the among/proc/meminfo) that internal memory overflows, enters step (2.9), otherwise enters step (2.10);
(2.9) internal memory desired value assignment is Committed_AS, avoids producing internal memory and overflows;
| Mtarget(n+1)l=Committed_AS |
(2.10) the invoke memory hot plug drives the internal memory of each virtual machine of adjustment to desired value MTarget(n+1)l
(2.11) sleep T second, T is the cycle that Dram distributes, and returns step (2.1) then.
Wherein step (2.6) is optimization process at some special circumstances to step (2.9), uses the memory usage scope to reduce the number of times that internal memory is adjusted on the one hand, will avoid producing internal memory on the other hand and overflow.Step (2.6) is to the dispensable step of step (2.9).
(3) as shown in Figure 8, the flow process of dynmaic establishing virtual machine is as follows:
(3.1) if the internal memory that the free memory of physical machine is set more than or equal to new virtual machine is then directly created new virtual machine, finish; Otherwise, enter step (3.2);
(3.2) obtain the memory information of each virtual machine by the internal memory monitoring module;
(3.3) behind the internal memory that the new virtual machine of reservation is set, calculate average memory usage UAvg, ∑ M whereinUsedBe the use internal memory summation of existing virtual machine, ∑ MTotalBe the internal memory sum of existing virtual machine, MNewBe the internal memory that new virtual machine is set, MFreeIt is the free memory of physical machine;
| Uavg=∑Mused/(∑Mtotal-Mnew+Mfree) |
(3.4) calculate the internal memory desired value M of each existing virtual machineTargetl, M whereinUsed lBe l the current use internal memory of existing virtual machine
(3.5) the internal memory desired value M of invoke memory hot plug internal memory that drive to adjust each virtual machine to the step (3.4)Targetl
(3.6) create new virtual machine, this moment, physical machine had enough free memories to create new virtual machine.
Example:
Dynamic EMS memory management system set forth in the present invention can illustrate that experimental situation only needs a PC, disposes as follows by instantiation:
Need to install amended Xen 4.0 of the present invention and Linux 2.6.31 kernel on the physical machine, domain U and domain 0 use Linux 2.6.31 kernel, test three kinds of functions of the present invention below respectively.
(1) virutal machine memory hot plug test
(1.1) original state: save as 2G in the physical machine, domain 0 internal memory is fixed as 1G (can not be changed);
(1.2) virtual machine of a 256 MB of memory of establishment;
(1.3) coarseness increases internal memory: uses internal memory hot plug driving at user's attitude interface of domain 0 virutal machine memory to be set and be 512M, increased 256 MB of memory, promptly increased by two sections internal memories;
(1.4) fine granularity increases internal memory: it is 562M that virutal machine memory is set, and has increased by 50 internal memories;
(1.5) coarseness reduces internal memory: it is 434M that virutal machine memory is set, and has reduced the 128M internal memory, i.e. one section internal memory;
(1.6) fine granularity reduces internal memory: it is 400M that virutal machine memory is set, and has reduced the 34M internal memory.
More than test has proved that the virutal machine memory hot plug can break the initial internal memory upper limit of virtual machine, increases or reduce virutal machine memory arbitrarily.The test process of Dram distribution needs long-time frequent adjustment memory size in addition, can prove stability and reliability that the internal memory hot plug drives.
(2) dynmaic establishing virtual machine test
(2.1) original state: save as 2G in the physical machine, domain 0 internal memory is fixed as 1G, and the free memory of physical machine is about 1G;
(2.2) create two virtual machines, internal memory all is 500M, and the physical machine free time is about 20M;
(2.3) use " xm create " order directly to create the virtual machine of a 256 MB of memory, create failure, because the free memory deficiency of physical machine;
(2.4) use dynmaic establishing virtual machine function, create new virtual machine success;
(2.5) use dynmaic establishing virtual machine function, create the virtual machine success of the 4th 256 MB of memory;
(2.6) use dynmaic establishing virtual machine function, create the virtual machine success of the 5th 256 MB of memory.More than test has proved that dynmaic establishing virtual machine function can be under the situation of physical machine low memory, by rationally reducing the internal memory of existing virtual machine, create new virtual machine, has realized the excessive use of internal memory.
(3) Dram allocation for test
(3.1) original state: save as 2G in the physical machine, the domain0 internal memory is fixed as 1G, and the free memory of physical machine is about 1G;
(3.2) create two virtual machines, internal memory all is 512M;
(3.3) static memory allocation for test: a virtual machine operation benchmark Spec CPU 2006, another virtual machine idle running;
(3.4) after the static memory allocation for test finishes, two virtual machines are closed, create two virtual machines again according to identical configuration then;
(3.5) Dram allocation for test: a virtual machine operation benchmark Spec CPU 2006, another virtual machine idle running.
In Dram allocation for test process, along with the variation of virtual machine load, the dynamic change of two virutal machine memory sizes makes the virtual machine of high capacity have bigger internal memory, and the virtual machine of low load has less internal memory.
The test result of benchmark Spec CPU 2006 is as shown in the table, and Dram distributes the intensive test event perlbench of internal memory, and the performance of bzip2 and gcc has tangible lifting, and other test events are less demanding to internal memory, and performance change is little.The benchmark of operation high capacity has also proved high stability and the reliability that Dram distributes for a long time.