This application claims priority under 35 U.S.C§119(a) from Chinese Patent Application no. 200810213096.4, filed on Aug. 28, 2008, the entire contents of which is incorporated herein by reference.
1. Field of the Invention
The present invention relates to a method, system and article of manufacture tangibly embodying a computer readable medium for performing defragment on a hard disk, and more particularly to a method, system and article of manufacture tangibly embodying a computer readable medium for performing defragment on a physical hard disk of a host machine system including a virtual machine.
2. Description of the Related Art
The virtual machine (VM) technology has been widely used in many application fields.
As shown in
A virtual disk used in a VM system is generally represented in the form of a huge file in a physical hard disk of a host machine. For example, the VM system can be a VMWare® system from the VMWare Corporation and its virtual disk is stored as, for example, a file of “*.vmdk” in the physical hard disk of the host machine. In the prior art, there are mainly three methods for allocating hard disk space for the VM in the host machine:
1) allocating the hard disk space on the host machine to the VM at the time of creating the VM—for example, allocating a predetermined space, e.g. 40 GB, for the virtual hard disk of the VM at the time of creating the VM;
2) allocating the hard disk space for the VM successively—for example, allocating a predetermined space on the host machine hard disk for the VM as required, e.g. allocating a 2 GB space for the VM when it applies each time; or
3) dynamically allocating the VM the hard disk space it needs on the host machine hard disk, wherein the allocated hard disk space can be continuously increased as the VM needs—the VM, is allocated a space as required on the physical hard disk of the host machine.
It is well known that there is a need for defragging a hard disk to eliminate fragmentation periodically or non-periodically in the existing operating system. Here, the fragmentation occurs because a file, when stored, is stored at plural incontiguous positions in the hard disk due to various reasons. If there are excessive fragments, when accessing a file, a magnetic head of the hard disk has to frequently jump to different physical positions to perform the access. As a result, access time for the file is prolonged and the service life of the hard disk is shortened, thereby deteriorating system performance. Thus, in order to solve the above problem, it is necessary to perform periodic or non-periodic defragment of the hard disk to store each file at contiguous physical positions as far as possible, so that the number of track seeking times of the magnetic head is reduced when these files are read.
The circumstance of defragment performed in a host machine system on which a VM system is running is analyzed below. The host machine's hard disk has a huge file (hereinafter referred to as a huge file A, which corresponds to a virtual hard disk of a VM) for the VM and other various files thereon. When allocating space for the huge file A on the physical hard disk of the host machine during the creation of the VM system: according to the aforementioned allocating method 1), the host machine hard disk cannot have a contiguous free space of the required size, and thus the huge file A can occupy incontiguous storage positions on the hard disk of host machine; according to the aforementioned allocating methods 2) and 3), due to the nature of successive allocation and dynamical allocation per se, it is a good possibility that the huge file A occupies incontiguous storage positions on the host machine hard disk.
As described above, the host machine needs to perform defragment of the huge file A and other files on the host machine. Next, with respect to the VM system, as shown in
a-8c exemplarily show a process of performing hard disk defragment of a host machine system including a VM in the prior art. As shown in
In the prior art, typically the host machine first needs to perform defragment of the files on the physical hard disk of the host machine. As shown in
As described above, in order to achieve the result that each file is stored at contiguous positions on both the virtual hard disk and the physical hard disk of the host machine, the existing technical solution needs to perform hard disk defragment twice, so that the defragment time for the system is increased and operation costs are increased, and the service life of the hard disk is degenerated.
In view of the above, there is a need for providing a technique of enabling the files on the host machine hard disk and the virtual hard disk to be stored at contiguous physical positions by performing defragment one time.
In one aspect, the present invention provides a method for performing defragment on a physical hard disk of a host machine system having a virtual machine (VM) system. The method includes obtaining a physical position distribution on the physical hard disk of data blocks constituting a VM file in the VM system according to VM file allocation information of the VM system and host machine file allocation information of the host machine system.
According to another aspect of the present invention, a hard disk defragment apparatus is provided for performing defragment on a physical hard disk of a host machine system having a virtual machine (VM) system. The hard disk defragment apparatus includes a physical position distribution acquiring unit for obtaining a physical position distribution on the physical hard disk of data blocks constituting a VM file in the VM system according to VM file allocation information of the VM system and host machine file allocation information of the host machine system.
According to a further aspect, the present invention provides an article of manufacture tangibly embodying a computer readable program containing executable program instructions which when executed, implements the steps of a method according to claim 1.
a-2b are views showing a process of performing defragment of a hard disk of a VM and a physical hard disk of a host machine according to an aspect of the present invention;
a-8c show a process of performing defragment of a physical hard disk of the host machine including the VM system according to the prior art.
The present invention will be easily understood by reference to the following description of the preferred embodiments when read in conjunction with the accompanying drawings in which same or corresponding reference numerals refer to same or corresponding characteristics or components.
In one aspects, the present invention can enable files on the physical hard disk of the host machine and the virtual hard disk to be stored contiguously by performing defragment one time so that fragments are decreased and the defragment method is simplified, thereby improving the system performance.
Referring to
As shown in
The VM file C occupies data blocks 3000-3100 on the virtual hard disk, that is, from the 3001st block (counted from the 0th block) in the huge file A which corresponds to the virtual hard disk, the VM file C occupies 101 blocks. Thus, it is necessary to calculate the physical position distribution from the 3001st block of the huge file A on the host machine hard disk occupied by the 101 blocks. As shown in
According to calculations, first, the huge file A in turn occupies 20001 blocks from block 20000 to 40000, occupies one block at the 78th block and occupies 10001 blocks from block 80000 to 90000, and the sum of these three portions reaches 30003 blocks. Thus, the 30011th block (block 30010) in the huge file A will be located within the section of data blocks 70010-70080 which is occupied by the huge file, i.e., a data block 70016. Therefore, it can be obtained through the above position calculation that the data block 30010 of the VM file C on the virtual hard disk corresponds to the data block 70016 on the host machine hard disk.
Similar to the above calculation, the position on the host machine hard disk occupied by data blocks 19000-21000 of the VM file C on the virtual hard disk continues to be calculated. First, a data block 19000 on the virtual hard disk corresponds to a data block 39000 of the huge file A on the host machine hard disk. The data blocks 19000-21000 of the VM file C totally have a hard disk space of 2001 blocks Thus, it is necessary to calculate the position distribution from the data block 39000 of the huge file A on the host machine hard disk, of totally 2001 blocks of the huge file A, such position distribution on the host machine hard disk will correspond to the data blocks 19000-21000 of the VM file C. The huge file A can provide in turn a 1001-block space from the data block 39000 to 40000, then next provide a one-block space at the block 78 and thereafter, provide 1999 blocks at blocks 80000-81998, leading to a total number of which is just 2001 blocks. Thereby, it is possible to obtain that the physical position distribution on the host machine hard disk occupied by the data blocks 19000-21000 of the VM file C is data blocks 390000-40000, 78 and 80000-81998 on the host machine. As described above, the physical position distribution on the host machine hard disk for the VM file C is obtained according to file allocation information of the VM system and file allocation information of the host machine system. In the following, the defragment is performed according to the physical position distribution.
Typically, a defragment at step 20 can be implemented by using various well-known techniques or software, such as a hard disk defragment program under the operating system Windows 2000® of Microsoft Corporation. A person skilled in the art can understand that since a specific position distribution in the host machine hard disk for each file in the VM system is known, the defragment can be implemented according to a hard disk defragment method in the prior art. The hard disk defragment in the prior art includes modifying, after defragment, file allocation information of the hard disk according to a result of the defragment.
As described above, although the VM file has a virtual position distribution on the virtual hard disk, the VM file is actually still stored on the host machine physical hard disk. Consequently, when the physical position distribution on the physical hard disk for data blocks of the VM file is obtained according to the above method, the VM file and the host machine file can be stored contiguously or substantially contiguously by way of once defragment according to the hard disk defragment method in the prior art, as shown in
After completing the above defragment at step 30, the file allocation information of the VM is updated according to the result of the defragment. For example, the new position distribution of the VM file C on the virtual hard disk after the defragment is calculated according to the result of the defragment, and the file allocation information of the VM is updated based on the new position distribution. In an example as shown in
The first acquiring unit 112 in the physical position distribution acquiring unit 110 acquires the virtual position distribution of a VM file C in the virtual hard disk according to VM file allocation information. The second acquiring unit 114 of the physical position distribution acquiring unit 110 acquires the physical position distribution in the physical hard disk of data blocks of the VM file according to above virtual position distribution and the host machine file allocation information. When the physical position distribution of the data blocks of the VM file is obtained, the physical position distribution acquiring unit 110 delivers it to the defragment unit 120.
The defragment unit 120 performs defragment according to the above physical position distribution. A person skilled in the art can understand that since the defragment unit 120 has known the position distribution in a host machine hard disk of each file in a VM system, the defragment can be implemented according to the hard disk defragment method in the prior art.
After the above defragment, the file allocation information modifying unit 130 modifies the VM file allocation information according to the result of defragment. For example, the virtual address updating unit 132 calculates the new position distribution of the VM file C on the virtual hard disk after the defragment according to the result of defragment, and the file allocation information modifying unit 130 modifies the VM file allocation information based on the new position distribution.
In an alternative embodiment defragment is performed on both the virtual hard disk and the host machine physical hard disk without activating the VM. According to the alternative embodiment, the physical position distribution acquiring unit 110 needs to acquire the file allocation information of the virtual hard disk without running the virtual machine. A person skilled in the art can understand that the VM defines the format of a huge file corresponding thereto, for example, header information of the VM system and the file allocation information of the virtual hard disk stored at a predetermined position of the huge file. Accordingly, when the type of the VM is determined based on the suffix name of the huge file of the VM (for example, VMWare® can have a suffix name.vmdk), according to the type of the VM, the predetermined position in the huge file where the file allocation information of the virtual hard disk is stored can be ascertained. Then the position distribution in the physical hard disk of the file allocation information of the virtual hard disk can be acquired with reference to the physical position distribution of the huge file in the host machine physical hard disk. Thereby, it is possible to obtain the file allocation information of the host machine hard disk and the file allocation information of the virtual hard disk in the case where the VM does not run, and the defragment is performed based on the file allocation information.
In another alternative embodiment, contiguous storage space for the virtual hard disk is pre-allocated at the time of defragment according to the current size of the virtual hard disk. For example, when the virtual hard disk has been allocated a 40 G hard disk space, a contiguous storage space of 40 G for the virtual hard disk can be pre-allocated during or before the defragment, thereby ensuring the huge file A to be contiguous on the physical hard disk.
In a further alternative embodiment, defragment of the huge file A is given a higher priority. More specifically, it is preferably assured that the huge file A has a contiguous physical position distribution on the host machine hard disk and each VM file has a contiguous virtual position distribution on the virtual hard disk. Alternatively, it is possible to only perform defragment of the huge file A and the virtual file on the virtual hard disk.
In another alternative embodiment, the VM file allocation information is stored in a VM file allocation table (FAT), and the host machine file allocation information is stored in a host machine file allocation table (FAT). The file allocation tables can be read to obtain the file allocation information.
In an additional alternative embodiment, when performing the hard disk defragment, the VM FAT is treated as a VM file during defragment.
It should be appreciated that the term “defragment” here should be understood in a broad sense, and it can refer to both performing defragment of a whole hard disk and performing defragment of a particular portion of the hard disk (such as a hard disk partition). According to the prior art, the defragment can include various algorithms.
It should be appreciated that the present invention can be applied to various cases. For example, when a VM file has a contiguously virtual position distribution in a virtual hard disk defragment can be performed on the host machine hard disk. On the contrary, when each file on the host machine hard disk has a contiguously physical position distribution, it is also possible to perform defragment on the virtual hard disk The present invention can also be applied to a plurality of file system formats, such as but not limited to NTFS, FAT 32, EXT, and so on. The present invention can further include a method and apparatus only for providing a defragment scheme for hard disk defragment. For example, a hard disk defragment apparatus 500 in
In the former, the third-party defragment apparatus only needs to move each data block according to the provided scheme so as to perform hard disk defragment. In the latter, the third-party defragment apparatus will shoulder the work of calculating how to move data blocks and ultimately completing the hard disk defragment according to the obtained physical distribution based on actual conditions, that is, the hard disk defragment apparatus 500 cannot include the defragment scheme designing unit 530.
The hard disk defragment apparatus can reside in a host machine system. However, a person skilled in the art can understand that the hard disk defragment apparatus can also reside in part, in a VM. For example, the physical position distribution acquiring unit 110 and the file allocation information modifying unit 130 as shown in
A person skilled in the art can understand that the apparatuses described here can be implemented in the form of software, hardware or any combination thereof. The present application does not intend to limit the specific apparatus types, so long as they can achieve the object of the present application.
As described above, the host machine system having a VM, achieves contiguous storage of each file on the VM and the host machine with only one defragment, thereby saving the addressing time and times for a hard disk magnetic head, so that the performance of the whole system is improved and the service life of the hard disk is prolonged.
It should be appreciated that the above embodiments, advantages and effects are illustrative rather than limiting. The above embodiments can combine with each other in an appropriate manner to form various implementation modes, and although these possible combinations are not illustrated in detail in the specification, they should be considered to have been specifically disclosed in the specification.
The present invention is illustrated with reference to the specific embodiments. However, a person skilled in the art can understand that various changes can be made and each component can be substituted for an equivalent thereof without departing from the spirit and scope of the present invention as defined by the accompanying claims. Moreover, a person skilled in the art can realize that various components and operations of the present invention that are specifically described here are not exclusive but only provided for facilitating understanding and evaluating the inventive principles and advantages of the present invention, instead of for limiting the present invention in any manner. Thus, the specification and the drawings should be deemed to be illustrative rather than limiting, and the above changes and substitution should be deemed to be within the scope of the present invention.
Number | Date | Country | Kind |
---|---|---|---|
200810213096.4 | Aug 2008 | CN | national |