WO2018233369A1 - Copy-on-write based write method and device for virtual disk, and storage medium - Google Patents

Copy-on-write based write method and device for virtual disk, and storage medium Download PDF

Info

Publication number
WO2018233369A1
WO2018233369A1 PCT/CN2018/083778 CN2018083778W WO2018233369A1 WO 2018233369 A1 WO2018233369 A1 WO 2018233369A1 CN 2018083778 W CN2018083778 W CN 2018083778W WO 2018233369 A1 WO2018233369 A1 WO 2018233369A1
Authority
WO
WIPO (PCT)
Prior art keywords
write
virtual disk
written
file
copy
Prior art date
Application number
PCT/CN2018/083778
Other languages
French (fr)
Chinese (zh)
Inventor
刘仁仕
张齐国
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2018233369A1 publication Critical patent/WO2018233369A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/061Improving I/O performance
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/0644Management of space entities, e.g. partitions, extents, pools
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0668Interfaces specially adapted for storage systems adopting a particular infrastructure
    • G06F3/0671In-line storage system

Definitions

  • the present application relates to the field of virtual disk technologies, and in particular, to a method and device for writing a virtual disk based on copy-on-write, and a storage medium.
  • Virtual disk (Virtual Disk), is to virtualize a disk inside a remote computer in the local computer, it feels like the hard disk on the machine, but in fact it is not on the machine.
  • a virtual disk is a technology that virtualizes one or more disks in memory. Like virtual memory, memory is much faster than a hard disk. With this, virtual disk one or more disks in memory can speed up the disk. The speed of data exchange, which increases the speed of the computer.
  • Virtual disks are widely used in current cloud computing environments.
  • virtual disks are fragmented after multiple times of writing files, that is, continuous virtual address spaces are distributed in non-contiguous file address spaces, which inevitably brings Write amplification, that is, a write operation to the virtual disk will be amplified into multiple file write operations, which has a certain impact on write performance.
  • the size of the data block to be written is 2 MB
  • the size of the default cluster is 64 KB
  • 32 data clusters need to be written, and the 32 data clusters may be discretely distributed in the discontinuous file addresses.
  • the write operation is amplified to 32 times, resulting in a decrease in the write performance of the virtual disk.
  • the main purpose of the present application is to provide a method and a device for writing a virtual disk based on copy-on-write, and a storage medium, which aims to solve the problem that a virtual disk in a prior art writes a file after being written to a file multiple times, resulting in virtual Technical problem with reduced disk write performance.
  • the present application provides a method for writing a virtual disk based on copy-on-write, and the method for writing a virtual disk based on copy-on-write includes:
  • the write-once copy is turned on for the write operation to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk;
  • a contiguous address space is allocated for the write operation in the virtual disk, and a file to be written in the cache is written to the virtual disk.
  • the present application further provides a virtual disk writing device based on copy-on-write, wherein the copy-on-write-based virtual disk writing device includes: a memory, a processor, and a memory stored in the memory and A copy-on-write virtual disk write program executable on the processor, the copy-on-write-based virtual disk write program being executed by the processor to implement the following steps:
  • the write-once copy is turned on for the write operation to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk;
  • a contiguous address space is allocated for the write operation in the virtual disk, and a file to be written in the cache is written to the virtual disk.
  • the present application further provides a storage medium on which a virtual disk write program based on copy-on-write is stored, and the virtual disk write program based on copy-on-write is executed by a processor.
  • the respective steps corresponding to the virtual disk writing method based on copy-on-write as described above are implemented.
  • the present application further provides a virtual disk writing device based on copy-on-write, wherein the virtual disk writing device based on copy-on-write includes:
  • a detecting module configured to detect a write magnification of the write operation when detecting that the virtual disk has a write operation
  • a copy module configured to: when the write magnification is equal to or greater than a preset threshold, enable copy-on-write for the write operation to temporarily write the file to be written corresponding to the write operation to the virtual The cache of the disk;
  • a writing module configured to allocate a continuous address space for the write operation in the virtual disk and write a file to be written in the cache to the virtual disk when receiving a storage instruction .
  • the method and device for writing a virtual disk based on copy-on-write and the storage medium provided by the present application can realize that a write operation of the virtual disk is detected, and a write magnification of the write operation is equal to or greater than a preset
  • the copy-on-write is turned on for the write operation, so that the file to be written corresponding to the write operation is temporarily written into the cache of the virtual disk, instead of directly writing to the virtual disk, when receiving the storage instruction. Only allocate a contiguous address space for the write operation in the above virtual disk, and then write the file to be written in the cache to the virtual disk.
  • the write amplification factor protects the write performance of the virtual disk, and solves the technical problem that the virtual disk in the prior art generates write amplification after multiple times of writing the file, resulting in a decrease in virtual disk write performance.
  • FIG. 1 is a schematic flowchart of a first embodiment of a method for writing a virtual disk based on copy-on-write according to the present application
  • step S30 is a schematic flow chart of the refinement step of step S30 shown in FIG. 1 of the present application;
  • FIG. 3 is a schematic structural diagram of a software running environment involved in a virtual disk writing device based on copy-on-write according to the present application.
  • the following embodiment provides a virtual disk write method based on copy-on-write.
  • the virtual disk is detected to have a write operation, and the write magnification of the write operation is equal to or greater than a preset threshold.
  • the copy-on-write is performed to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk, instead of directly writing to the virtual disk, when receiving the storage instruction,
  • the contiguous address space is allocated for the write operation in the above virtual disk, and then the file to be written in the cache is written to the virtual disk.
  • the write-once copy is enabled for each write operation, so that the file to be written can be written into the continuous address space of the virtual disk, thereby effectively controlling the virtual disk.
  • Write write magnification to protect the write performance of the virtual disk.
  • FIG. 1 is a schematic flowchart of a first embodiment of a method for writing a virtual disk based on copy-on-write according to the present application.
  • the virtual disk writing method includes:
  • step S10 when it is detected that the virtual disk has a write operation, the write magnification of the write operation is detected.
  • the virtual disk in the embodiment refers to “disguising” data, files, network files, and memory into a disk by technical means, so that the user feels like a “disk” existing on a real disk.
  • the client can connect to the iSCSI on the server through the local area network.
  • the Cake server virtualizes a hard disk locally to achieve the effect of sharing the server hard disk through the network. For example, Internet cafe owners only need iSCSI on the server. Add a directory and install game software in Cake.
  • the client's local virtual hard disk has the corresponding game software, and you don't need to install it on every machine.
  • the above write operation refers to a process of writing and storing a file to be written to the above virtual disk, and specifically, Vhd (Microsoft) Virtual Hard Disk format) is a virtual disk write tool.
  • Vhd Microsoft Virtual Hard Disk format
  • the file to be written corresponding to the above write operation includes a Qcow2 image format file, and the Qcow2 image format file belongs to a QEMU (Quick) Emulator, virtual operating system emulator)
  • QEMU Quick Emulator, virtual operating system emulator
  • a disk image file supported by the emulator which can represent a fixed-size block device disk in the form of a file.
  • write amplification is an undesired phenomenon in virtual disks, that is, the amount of physical information actually written is a multiple of the number of logics to be written. Because flash must be erased before it can be rewritten, the process of performing these operations produces more than one movement (or rewrite) of user data and metadata. This multiplication effect increases the number of requests written. The write is amplified, and the number of times the write is requested is the write magnification.
  • the write enlargement corresponding to the write operation is detected.
  • the step of detecting the write amplification factor corresponding to the write operation includes: detecting a size of the data block to be written, and a size of the corresponding data cluster for each write operation, according to the size of the data block and the size of the data cluster. Calculate the write magnification corresponding to the above write operation. For example, when the size of the written data block is 2 MB, and the size of the corresponding data cluster for each write operation is 64 KB, a total of 32 data clusters need to be written, and the 32 data clusters may be discretely distributed in the discontinuous file. In the address, at this time, the write magnification corresponding to the above write operation is 32 times.
  • Step S20 when the write amplification factor is equal to or greater than a preset threshold, then copy-on-write is turned on for the write operation to temporarily write the file to be written corresponding to the write operation to the virtual disk. In the cache.
  • a write amplification threshold is set in advance, for example, set to 5 times, 10 times, etc., and when the write amplification factor is equal to or greater than the threshold, copy-on-write is turned on for the write operation.
  • copy-on-write is COW (copy-on-write) technology
  • COW technology uses "refcount” (refcount)
  • the constructor of the string allocates memory from the heap according to the parameters passed in.
  • the reference count is automatically accumulated, when there is class destruction. The reference count is decremented by one until the last class is destructed, at which point the reference count is 1 or 0.
  • fwrite write file
  • fprintf transfer formatted output to a file
  • the copy-on-write is turned on for the write operation.
  • Step S30 when receiving the storage instruction, allocate a continuous address space for the write operation in the virtual disk, and write the file to be written in the cache to the virtual disk.
  • the writing process of the qcow2 file in the prior art will be described as an example.
  • the write amplification may still be caused when the large data block is written to the virtual disk.
  • the storage instruction may be triggered (such as clicking “save”), and after receiving the storage instruction, the virtual disk writing device is to be written in the virtual disk.
  • the write operation corresponding to the input file allocates a contiguous address space, and then the above-mentioned file to be written is written to the virtual disk.
  • the method for writing a virtual disk based on copy-on-write when the virtual disk is detected to have a write operation, and the write magnification of the write operation is equal to or greater than a preset threshold, the write is performed.
  • the write operation enables copy-on-write to temporarily write the file to be written corresponding to the write operation to the cache of the virtual disk instead of directly writing to the virtual disk, and is in the virtual disk when receiving the storage instruction.
  • a contiguous address space is allocated for the write operation, and then the file to be written in the cache is written to the above virtual disk.
  • FIG. 2 is a schematic flowchart of a refinement step of step S30 shown in FIG. 1 according to the present application.
  • the first embodiment of the method for writing a virtual disk based on copy-on-write according to the present application is based on copy-on-write.
  • the contiguous address space is allocated to the write operation in the virtual disk in step S30 shown in FIG. 1 above, and the cache is to be written.
  • the input file is written to the virtual disk and includes:
  • Step S31 assigning consecutive clusters to the file to be written in the virtual disk
  • Step S32 writing the file to be written in the cache into the consecutive clusters, and updating the virtual address offset of the file to be written in the cache.
  • the qcow2 file is taken as an example of the file to be written, and the qcow2 file is composed of a plurality of fixed-size clusters, wherein the virtual disk is composed of multiple sectors, and several sectors are combined. As a cluster; in addition, the writing and reading of files in the virtual disk is also in clusters.
  • qcow2 files can be divided into the following categories:
  • header the file header, through the data in the header, can be indexed to l1_table, reference count table (refcount table);
  • l2_table virtual address offset, storing the offset position of the data block
  • refcount_table reference count table, store reference count block (refcount Offset position of block);
  • refcount_block reference counting block, storing the reference count (refcount) value
  • snapshot table snapshot table, used to store the basic information of the snapshot.
  • the above snapshot refers to a fully available copy of the specified data set, the copy includes an image of the corresponding data at a certain point in time (the point in time when the copy starts), and the snapshot may be a copy of the data represented by the snapshot, or Is a replica of the data.
  • the role of the snapshot is to enable online data backup and recovery. When the storage device fails or the file is damaged, you can perform fast data recovery and restore the data to a usable time point.
  • Another function of the snapshot is to provide another data access channel for the storage user. When the original data is processed online, the user can access the snapshot data, and can also use the snapshot for testing.
  • the qcow2 file implements the conversion from the logical address to the area in the actual file through the two-level index of l1_table and l2_table, thereby realizing the support time allocation. That is, if there is no write operation in an area, the actual address space is not allocated for the area.
  • a continuous cluster is allocated to the file to be written in the virtual disk, and then the file to be written is written into the allocated continuous cluster, and updated.
  • the virtual address offset of the file to be written is written.
  • the method for writing a virtual disk based on copy-on-write when a virtual disk writes a file, first allocates a continuous cluster for the file to be written in the virtual disk, and then writes the file to be written. Up to the allocated consecutive clusters, and updating the virtual address offset of the file to be written, thereby effectively controlling the write magnification of the virtual disk and protecting the write performance of the virtual disk.
  • the third embodiment of the method for writing a virtual disk based on copy-on-write is provided in the third embodiment of the present invention. Updating the virtual address offset of the file to be written in the cache as described in the following:
  • the file header header of the file to be written may be indexed to l1_table, and then may be indexed to the virtual address offset l2_table according to the l1_table.
  • Refcount_table which can be indexed to the reference count block refcount by reference counting table The cluster where the block is located; in addition, through the above file header, it is also possible to index to the snapshot table, and then index the data to the snapshot, that is, the file to be written.
  • step of releasing the clusters already occupied in the virtual disk is as follows:
  • the reference count corresponding to the occupied cluster is decremented by one.
  • the reference count refcount is a data block index value
  • each cluster in the qcow2 file has a corresponding reference count. If the cluster is not allocated, its reference count is 0. If the cluster is allocated, Its reference count is greater than zero. For a cluster, each time it performs a write-time copy, its corresponding reference count value is incremented by one. Therefore, the clusters already occupied in the virtual disk can be released by decrementing the reference count corresponding to the above-mentioned occupied cluster.
  • the method for writing a virtual disk based on copy-on-write may index the virtual address offset of the file to be written according to the file header of the file to be written, thereby updating the virtual file to be written.
  • the address offset, and the reference count corresponding to the occupied cluster in the virtual disk is decremented by 1, thereby releasing the occupied cluster in the virtual disk, and the file to be written can be written into the allocated virtual disk.
  • Continuous address space which effectively controls the write magnification of the virtual disk and protects the write performance of the virtual disk.
  • the present application is based on the fourth embodiment of the method for writing a virtual disk based on copy-on-write.
  • Allocating a contiguous address space for the write operation in the virtual disk in the step S30, and writing the file to be written in the cache to the virtual disk includes:
  • the virtual address offset of the file to be written needs to be updated, and the cluster that has been occupied in the virtual disk needs to be released, thereby The data written in the write operation of the write file is lost. Therefore, in the embodiment, when the file to be written is written to the virtual disk, the first and last data segments corresponding to the occupied cluster are read. And spliced with the above-mentioned file to be written and simultaneously written to the virtual disk.
  • the method for writing a virtual disk based on the copy-on-write according to the present embodiment, when writing the file to be written corresponding to the write operation to the virtual disk, reading the first and last data segments corresponding to the occupied cluster, And the splicing of the file to be written is simultaneously written into the virtual disk, so that all the files to be written corresponding to the above write operation can be written into the virtual disk, thereby ensuring the accuracy of writing the virtual disk data.
  • the present application also provides a virtual disk writing device based on copy-on-write
  • the copy-on-write-based virtual disk writing device includes: a memory, a processor, and is stored on the memory and operable on the processor
  • the virtual disk writing program based on copy-on-write, the device is capable of: when detecting that the virtual disk has a write operation, and the write magnification of the write operation is equal to or greater than a preset threshold, then the write The write operation enables copy-on-write to temporarily write the file to be written corresponding to the write operation to the cache of the virtual disk instead of directly writing to the virtual disk, and is in the virtual disk when receiving the storage instruction.
  • a contiguous address space is allocated for the write operation, and then the file to be written in the cache is written to the above virtual disk. Since the device generates multiple write operations on the virtual disk, copy-on-write is enabled for each write operation, so that the file to be written can be written into a continuous address space in the virtual disk, thereby effectively controlling the virtual disk. Write write magnification to protect the write performance of the virtual disk.
  • the write-once copy is turned on for the write operation to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk;
  • a contiguous address space is allocated for the write operation in the virtual disk, and a file to be written in the cache is written to the virtual disk.
  • FIG. 3 is a schematic structural diagram of a software running environment involved in a virtual disk writing device based on copy-on-write in the present application.
  • the incoming device can include a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002.
  • the communication bus 1002 is configured to implement connection communication between the components; the user interface 1003 may include a display, an input unit such as a keyboard, and the optional user interface 1003 may further include a standard wired interface and a wireless interface.
  • the network interface 1004 may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface); the memory 1005 may be a high speed RAM memory or a stable memory (non-volatile) Memory, such as a disk storage; the memory 1005 may alternatively be a storage device independent of the processor 1001 described above.
  • a wireless interface such as a WI-FI interface
  • the memory 1005 may be a high speed RAM memory or a stable memory (non-volatile) Memory, such as a disk storage; the memory 1005 may alternatively be a storage device independent of the processor 1001 described above.
  • FIG. 3 does not constitute a limitation on the above-described copy-on-write virtual disk writing device, which may include more or less components than those illustrated, or a combination of Some parts, or different parts are arranged.
  • a memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a virtual disk write program based on copy-on-write.
  • the network interface 1004 is mainly used to connect to the background server and perform data communication with the background server.
  • the user interface 1003 is mainly used to connect the client (user end) to perform data communication with the client; and the processor 1001 can use
  • the virtual disk write program based on copy-on-write stored in the memory 1005 is called and the corresponding operation is performed.
  • the embodiment corresponding to the virtual disk writing device based on the copy-on-write is basically the same as the corresponding embodiment of the virtual disk writing method based on the copy-on-write, and therefore no further details are provided herein.
  • the present application further provides a storage medium on which a virtual disk write program based on copy-on-write is stored, and the storage medium is capable of: detecting that a virtual disk has a write operation, and writing the write operation
  • the magnification is equal to or greater than the preset threshold
  • the copy-on-write is turned on for the write operation, so that the file to be written corresponding to the write operation is temporarily written into the cache of the virtual disk instead of directly writing to the virtual disk.
  • a storage instruction is received, a contiguous address space is allocated for the write operation in the virtual disk, and then the file to be written in the cache is written to the virtual disk.
  • copy-on-write is enabled for each write operation, so that the file to be written can be written into a continuous address space in the virtual disk, thereby effectively controlling the virtual disk.
  • Write write magnification to protect the write performance of the virtual disk.
  • the write-once copy is turned on for the write operation to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk;
  • a contiguous address space is allocated for the write operation in the virtual disk, and a file to be written in the cache is written to the virtual disk.
  • the corresponding embodiment of the storage medium is substantially the same as the corresponding embodiment of the virtual disk writing method based on the copy-on-write. Therefore, details are not described herein again.
  • the present application further provides a virtual disk writing device based on copy-on-write, wherein the copy-on-write-based virtual disk writing device includes:
  • a detecting module configured to detect a write magnification of the write operation when detecting that the virtual disk has a write operation
  • a copy module configured to: when the write magnification is equal to or greater than a preset threshold, enable copy-on-write for the write operation to temporarily write the file to be written corresponding to the write operation to the virtual The cache of the disk;
  • a writing module configured to allocate a continuous address space for the write operation in the virtual disk and write a file to be written in the cache to the virtual disk when receiving a storage instruction .
  • the writing module includes:
  • An allocating unit configured to allocate, in the virtual disk, a continuous cluster for the file to be written in the cache
  • an updating unit configured to write the file to be written in the cache into the consecutive clusters, and update a virtual address offset of the file to be written in the cache.
  • the update unit includes:
  • An index subunit configured to index a virtual address offset of the file to be written according to the file header of the file to be written
  • An update subunit is configured to update a virtual address offset of the file to be written in the cache, and release a cluster that has been occupied in the virtual disk.
  • update subunit is further configured to:
  • the reference count corresponding to the occupied cluster is decremented by one.
  • writing module is further configured to:

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Human Computer Interaction (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

Disclosed is a copy-on-write based write method for a virtual disk, comprising: upon detection of a write operation performed on a virtual disk, detecting a write amplification ratio of the write operation; if the write amplification ratio is equal to or greater than a preset threshold, activating a copy-on-write function for the write operation to temporarily write, to a cache of the virtual disk, a file to be written corresponding to the write operation; and upon reception of a storage instruction, allocating, to the write operation, continuous address spaces in the virtual disk, and writing the file in the cache to the virtual disk. Also disclosed are a copy-on-write based write device for a virtual disk, and a storage medium.

Description

基于写时复制的虚拟磁盘写入方法及装置、存储介质  Virtual disk writing method and device based on copy-on-write, storage medium
本申请要求于2017年06月20日提交中国专利局、申请号为201710472651.4、发明名称为“基于写时复制的虚拟磁盘写入方法及装置、存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese Patent Application filed on June 20, 2017, the Chinese Patent Office, the application number is 201710472651.4, and the invention name is "write-copy-based virtual disk writing method and device, storage medium". The content is incorporated herein by reference.
技术领域Technical field
本申请涉及虚拟磁盘技术领域,尤其涉及一种基于写时复制的虚拟磁盘写入方法及装置、存储介质。The present application relates to the field of virtual disk technologies, and in particular, to a method and device for writing a virtual disk based on copy-on-write, and a storage medium.
背景技术Background technique
虚拟磁盘(Virtual disk),就是在本地电脑里面虚拟出一个远程电脑里面的磁盘,感觉像是在本机上的硬盘一样,但其实它没在本机上。虚拟磁盘就是用内存中虚拟出一个或者多个磁盘的技术,和虚拟内存一样,内存的速度要比硬盘快得多,利用这一点,在内存中虚拟出一个或多个磁盘就可以加快磁盘的数据交换速度,从而提高电脑的运行速度。Virtual disk (Virtual Disk), is to virtualize a disk inside a remote computer in the local computer, it feels like the hard disk on the machine, but in fact it is not on the machine. A virtual disk is a technology that virtualizes one or more disks in memory. Like virtual memory, memory is much faster than a hard disk. With this, virtual disk one or more disks in memory can speed up the disk. The speed of data exchange, which increases the speed of the computer.
虚拟磁盘在当前的云计算环境中得到广泛使用,目前,虚拟磁盘在多次写入文件后会形成碎片,即连续虚拟地址空间分布在不连续的文件地址空间中,这样就会不可避免地带来写入放大,即对虚拟磁盘的一次写操作会被放大成多个文件写操作,对写性能带来了一定影响。如当写入的数据块大小为2MB时,默认簇的大小为64KB时,则需要写入32个数据簇,而这32个数据簇可能离散分布在不连续的文件地址中。此时,写入操作就会被放大到32倍,导致虚拟磁盘的写入性能降低。Virtual disks are widely used in current cloud computing environments. Currently, virtual disks are fragmented after multiple times of writing files, that is, continuous virtual address spaces are distributed in non-contiguous file address spaces, which inevitably brings Write amplification, that is, a write operation to the virtual disk will be amplified into multiple file write operations, which has a certain impact on write performance. For example, when the size of the data block to be written is 2 MB, and the size of the default cluster is 64 KB, 32 data clusters need to be written, and the 32 data clusters may be discretely distributed in the discontinuous file addresses. At this point, the write operation is amplified to 32 times, resulting in a decrease in the write performance of the virtual disk.
发明内容Summary of the invention
本申请的主要目的在于提出一种基于写时复制的虚拟磁盘写入方法及装置、存储介质,旨在解决现有技术中虚拟磁盘在多次写入文件后,会产生写入放大,导致虚拟磁盘写入性能降低的技术问题。The main purpose of the present application is to provide a method and a device for writing a virtual disk based on copy-on-write, and a storage medium, which aims to solve the problem that a virtual disk in a prior art writes a file after being written to a file multiple times, resulting in virtual Technical problem with reduced disk write performance.
为实现上述目的,本申请提供一种基于写时复制的虚拟磁盘写入方法,所述基于写时复制的虚拟磁盘写入方法包括:To achieve the above objective, the present application provides a method for writing a virtual disk based on copy-on-write, and the method for writing a virtual disk based on copy-on-write includes:
在检测到虚拟磁盘有写入操作时,检测所述写入操作的写入放大倍数;Detecting a write magnification of the write operation when detecting that the virtual disk has a write operation;
当所述写入放大倍数等于或大于预设的阈值时,则对所述写入操作开启写时复制,以将所述写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中;When the write amplification factor is equal to or greater than a preset threshold, the write-once copy is turned on for the write operation to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk;
当接收到存储指令时,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中。When a store instruction is received, a contiguous address space is allocated for the write operation in the virtual disk, and a file to be written in the cache is written to the virtual disk.
此外,为实现上述目的,本申请还提供一种基于写时复制的虚拟磁盘写入装置,所述基于写时复制的虚拟磁盘写入装置包括:存储器、处理器及存储在所述存储器上并可在所述处理器上运行的基于写时复制的虚拟磁盘写入程序,所述基于写时复制的虚拟磁盘写入程序被所述处理器执行时实现如下步骤:In addition, in order to achieve the above object, the present application further provides a virtual disk writing device based on copy-on-write, wherein the copy-on-write-based virtual disk writing device includes: a memory, a processor, and a memory stored in the memory and A copy-on-write virtual disk write program executable on the processor, the copy-on-write-based virtual disk write program being executed by the processor to implement the following steps:
在检测到虚拟磁盘有写入操作时,检测所述写入操作的写入放大倍数;Detecting a write magnification of the write operation when detecting that the virtual disk has a write operation;
当所述写入放大倍数等于或大于预设的阈值时,则对所述写入操作开启写时复制,以将所述写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中;When the write amplification factor is equal to or greater than a preset threshold, the write-once copy is turned on for the write operation to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk;
当接收到存储指令时,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中。When a store instruction is received, a contiguous address space is allocated for the write operation in the virtual disk, and a file to be written in the cache is written to the virtual disk.
此外,为实现上述目的,本申请还提供一种存储介质,所述存储介质上存储有基于写时复制的虚拟磁盘写入程序,所述基于写时复制的虚拟磁盘写入程序被处理器执行时实现如上所述的基于写时复制的虚拟磁盘写入方法对应的各个步骤。In addition, in order to achieve the above object, the present application further provides a storage medium on which a virtual disk write program based on copy-on-write is stored, and the virtual disk write program based on copy-on-write is executed by a processor. The respective steps corresponding to the virtual disk writing method based on copy-on-write as described above are implemented.
此外,为实现上述目的,本申请还提供一种基于写时复制的虚拟磁盘写入装置,其特征在于,所述基于写时复制的虚拟磁盘写入装置包括:In addition, in order to achieve the above object, the present application further provides a virtual disk writing device based on copy-on-write, wherein the virtual disk writing device based on copy-on-write includes:
检测模块,用于在检测到虚拟磁盘有写入操作时,检测所述写入操作的写入放大倍数;a detecting module, configured to detect a write magnification of the write operation when detecting that the virtual disk has a write operation;
复制模块,用于当所述写入放大倍数等于或大于预设的阈值时,则对所述写入操作开启写时复制,以将所述写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中;a copy module, configured to: when the write magnification is equal to or greater than a preset threshold, enable copy-on-write for the write operation to temporarily write the file to be written corresponding to the write operation to the virtual The cache of the disk;
写入模块,用于当接收到存储指令时,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中。a writing module, configured to allocate a continuous address space for the write operation in the virtual disk and write a file to be written in the cache to the virtual disk when receiving a storage instruction .
本申请所提供的基于写时复制的虚拟磁盘写入方法及装置、存储介质,能够实现:在检测到虚拟磁盘有写入操作,且该写入操作的写入放大倍数等于或大于预设的阈值时,则对该写入操作开启写时复制,以将该写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中,而不是直接写入虚拟磁盘中,当接收到存储指令时,才在上述虚拟磁盘中为该写入操作分配连续的地址空间,然后将缓存中的待写入文件写入到上述虚拟磁盘中。由于本申请在虚拟磁盘产生多次写入操作时,便对每一次写入操作开启写时复制,从而可以将待写入文件写入虚拟磁盘中连续的地址空间内,因此能够有效控制虚拟磁盘的写入放大倍数,保护虚拟磁盘的写入性能,解决了现有技术中虚拟磁盘在多次写入文件后,会产生写入放大,导致虚拟磁盘写入性能降低的技术问题。The method and device for writing a virtual disk based on copy-on-write and the storage medium provided by the present application can realize that a write operation of the virtual disk is detected, and a write magnification of the write operation is equal to or greater than a preset When the threshold is used, the copy-on-write is turned on for the write operation, so that the file to be written corresponding to the write operation is temporarily written into the cache of the virtual disk, instead of directly writing to the virtual disk, when receiving the storage instruction. Only allocate a contiguous address space for the write operation in the above virtual disk, and then write the file to be written in the cache to the virtual disk. Since the present application generates multiple write operations on the virtual disk, copy-on-write is enabled for each write operation, so that the file to be written can be written into a continuous address space in the virtual disk, thereby effectively controlling the virtual disk. The write amplification factor protects the write performance of the virtual disk, and solves the technical problem that the virtual disk in the prior art generates write amplification after multiple times of writing the file, resulting in a decrease in virtual disk write performance.
附图说明DRAWINGS
图1为本申请基于写时复制的虚拟磁盘写入方法第一实施例的流程示意图;1 is a schematic flowchart of a first embodiment of a method for writing a virtual disk based on copy-on-write according to the present application;
图2为本申请图1所示步骤S30的细化步骤流程示意图;2 is a schematic flow chart of the refinement step of step S30 shown in FIG. 1 of the present application;
图3为本申请基于写时复制的虚拟磁盘写入装置涉及的软件运行环境的结构示意图。FIG. 3 is a schematic structural diagram of a software running environment involved in a virtual disk writing device based on copy-on-write according to the present application.
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The implementation, functional features and advantages of the present application will be further described with reference to the accompanying drawings.
具体实施方式Detailed ways
以下结合说明书附图对本申请的优选实施例进行说明,应当理解,此处所描述的优选实施例仅用于说明和解释本申请,并不用于限定本申请,并且在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互组合。The preferred embodiments of the present application are described with reference to the accompanying drawings, and the preferred embodiments described herein are only used to illustrate and explain the present application, and are not intended to limit the present application, and in the case of no conflict, the present application The embodiments and the features in the embodiments can be combined with each other.
本申请以下实施例提供一种基于写时复制的虚拟磁盘写入方法,该方法中,在检测到虚拟磁盘有写入操作,且该写入操作的写入放大倍数等于或大于预设的阈值时,则对该写入操作开启写时复制,以将该写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中,而不是直接写入虚拟磁盘中,当接收到存储指令时,才在上述虚拟磁盘中为该写入操作分配连续的地址空间,然后将缓存中的待写入文件写入到上述虚拟磁盘中。即该方法在虚拟磁盘产生多次写入操作时,便对每一次写入操作开启写时复制,从而可以将待写入文件写入虚拟磁盘中连续的地址空间内,因此能够有效控制虚拟磁盘的写入放大倍数,保护虚拟磁盘的写入性能。The following embodiment provides a virtual disk write method based on copy-on-write. In the method, the virtual disk is detected to have a write operation, and the write magnification of the write operation is equal to or greater than a preset threshold. When the write operation is enabled, the copy-on-write is performed to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk, instead of directly writing to the virtual disk, when receiving the storage instruction, The contiguous address space is allocated for the write operation in the above virtual disk, and then the file to be written in the cache is written to the virtual disk. That is, when the virtual disk generates multiple write operations, the write-once copy is enabled for each write operation, so that the file to be written can be written into the continuous address space of the virtual disk, thereby effectively controlling the virtual disk. Write write magnification to protect the write performance of the virtual disk.
参照图1,图1为本申请基于写时复制的虚拟磁盘写入方法第一实施例的流程示意图,本申请基于写时复制的虚拟磁盘写入方法第一实施例中,上述基于写时复制的虚拟磁盘写入方法包括:1 is a schematic flowchart of a first embodiment of a method for writing a virtual disk based on copy-on-write according to the present application. In the first embodiment of the method for writing a virtual disk based on copy-on-write, the above-mentioned copy-on-write is performed. The virtual disk writing method includes:
步骤S10,在检测到虚拟磁盘有写入操作时,检测所述写入操作的写入放大倍数。In step S10, when it is detected that the virtual disk has a write operation, the write magnification of the write operation is detected.
其中,本实施例中所述的虚拟磁盘,是指把数据、文件,网络文件,内存等通过技术手段“伪装”成磁盘,让用户感觉像是以一个真实磁盘存在的“磁盘”。具体的,客户端可以通过局域网连接服务器上的iSCSI Cake服务器,在本地虚拟出一块硬盘,以达到通过网络共享服务器硬盘的效果。例如,网吧业主只需要在服务器上的iSCSI Cake里添加目录和安装游戏软件,客户端的本地虚拟硬盘里就有了相应的游戏软件,不需要到每台机器进行安装。The virtual disk in the embodiment refers to “disguising” data, files, network files, and memory into a disk by technical means, so that the user feels like a “disk” existing on a real disk. Specifically, the client can connect to the iSCSI on the server through the local area network. The Cake server virtualizes a hard disk locally to achieve the effect of sharing the server hard disk through the network. For example, Internet cafe owners only need iSCSI on the server. Add a directory and install game software in Cake. The client's local virtual hard disk has the corresponding game software, and you don't need to install it on every machine.
上述写入操作是指把待写入文件写入并存储到上述虚拟磁盘的过程,具体可以利用Vhd(Microsoft Virtual Hard Disk format,微软虚拟磁盘文件)虚拟磁盘写入工具来进行。The above write operation refers to a process of writing and storing a file to be written to the above virtual disk, and specifically, Vhd (Microsoft) Virtual Hard Disk format) is a virtual disk write tool.
其中,上述写入操作对应的待写入文件包括Qcow2镜像格式文件,Qcow2镜像格式文件属于一种QEMU(Quick Emulator,虚拟操作***模拟器)模拟器支持的磁盘镜像文件,它可以用一个文件的形式来表示一块固定大小的块设备磁盘。The file to be written corresponding to the above write operation includes a Qcow2 image format file, and the Qcow2 image format file belongs to a QEMU (Quick) Emulator, virtual operating system emulator) A disk image file supported by the emulator, which can represent a fixed-size block device disk in the form of a file.
其中,写入放大是虚拟磁盘中一种不期望的现象,即实际写入的物理信息量是将要写入的逻辑数量的多倍。因为闪存在可重新写入数据前必须先擦除,执行这些操作的过程就产生了一次以上的用户数据和元数据的移动(或重新写入),此倍增效应会增加请求写入的次数导致写入放大,而请求写入的次数即为写入放大倍数。Among them, write amplification is an undesired phenomenon in virtual disks, that is, the amount of physical information actually written is a multiple of the number of logics to be written. Because flash must be erased before it can be rewritten, the process of performing these operations produces more than one movement (or rewrite) of user data and metadata. This multiplication effect increases the number of requests written. The write is amplified, and the number of times the write is requested is the write magnification.
本实施例中,在检测到虚拟磁盘有写入操作时,便检测该写入操作对应的写入放大倍数。In this embodiment, when it is detected that the virtual disk has a write operation, the write enlargement corresponding to the write operation is detected.
其中,检测上述写入操作对应的写入放大倍数的步骤包括:检测所要写入的数据块的大小,以及每一次写入操作对应数据簇的大小,根据该数据块的大小及数据簇的大小,计算出上述写入操作对应的写入放大倍数。例如,当写入的数据块大小为2MB,每一次写入操作对应数据簇的大小为64KB时,则一共需要写入32个数据簇,而这32个数据簇可能离散分布在不连续的文件地址中,此时,上述写入操作对应的写入放大倍数即为32倍。The step of detecting the write amplification factor corresponding to the write operation includes: detecting a size of the data block to be written, and a size of the corresponding data cluster for each write operation, according to the size of the data block and the size of the data cluster. Calculate the write magnification corresponding to the above write operation. For example, when the size of the written data block is 2 MB, and the size of the corresponding data cluster for each write operation is 64 KB, a total of 32 data clusters need to be written, and the 32 data clusters may be discretely distributed in the discontinuous file. In the address, at this time, the write magnification corresponding to the above write operation is 32 times.
步骤S20,当所述写入放大倍数等于或大于预设的阈值时,则对所述写入操作开启写时复制,以将所述写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中。Step S20, when the write amplification factor is equal to or greater than a preset threshold, then copy-on-write is turned on for the write operation to temporarily write the file to be written corresponding to the write operation to the virtual disk. In the cache.
本实施例中,预先设置一个写入放大倍数阈值,例如设置为5倍、10倍等,当上述写入放大倍数等于或大于该阈值时,则对上述写入操作开启写时复制。In this embodiment, a write amplification threshold is set in advance, for example, set to 5 times, 10 times, etc., and when the write amplification factor is equal to or greater than the threshold, copy-on-write is turned on for the write operation.
其中,写时复制即为COW(copy-on-write,写时复制)技术,COW技术使用了“引用计数”(refcount),会有一个变量用于保存引用的数量。当第一个类构造时,字符串(string)的构造函数会根据传入的参数从堆上分配内存,当有其它类需要这块内存时,该引用计数为自动累加,当有类析构时,该引用计数会减1,直到最后一个类析构时,此时的引用计数为1或是0。Among them, copy-on-write is COW (copy-on-write) technology, COW technology uses "refcount" (refcount), there will be a variable to save the number of references. When the first class is constructed, the constructor of the string (string) allocates memory from the heap according to the parameters passed in. When there are other classes that need this memory, the reference count is automatically accumulated, when there is class destruction. The reference count is decremented by one until the last class is destructed, at which point the reference count is 1 or 0.
例如,某个程序要写入文件时,需要不断地根据网络或者用户上传来的数据写入,如果每一次fwrite(写入文件)操作或是fprintf(传送格式化输出到一个文件中)都要进行一个虚拟磁盘的I/O操作(指对设备与cpu连接的接口电路的操作,如虚拟磁盘的写入操作)的话,则会给虚拟磁盘的写入性能带来巨大的损失。因此,为了保护虚拟磁盘的写入性能,本实施例采用COW技术,将每次写入操作都先写入虚拟磁盘的缓存中(磁盘内存)中,只有当关闭文件或者接收到存储指令时,才写入到虚拟磁盘内。For example, when a program is to be written to a file, it needs to be continuously written according to the data uploaded by the network or the user, if every fwrite (write file) operation or fprintf (transfer formatted output to a file) Performing an I/O operation of a virtual disk (refers to the operation of the interface circuit of the device connected to the CPU, such as a virtual disk write operation) will cause a huge loss to the write performance of the virtual disk. Therefore, in order to protect the write performance of the virtual disk, the COW technology is used in this embodiment to write each write operation to the cache (disk memory) of the virtual disk first, only when the file is closed or a storage instruction is received. It is written to the virtual disk.
具体的,本实施例中,当上述写入放大倍数等于或大于预设的阈值时,则对该写入操作开启写时复制。Specifically, in this embodiment, when the write amplification factor is equal to or greater than a preset threshold, the copy-on-write is turned on for the write operation.
步骤S30,当接收到存储指令时,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中。Step S30, when receiving the storage instruction, allocate a continuous address space for the write operation in the virtual disk, and write the file to be written in the cache to the virtual disk.
为了更好的理解本申请,以现有技术中qcow2文件的写入过程为例进行说明。现有技术中,在虚拟磁盘中写入一个大数据块时,由于写入虚拟磁盘的地址是离散分配的,因此,在将该大数据块写入虚拟磁盘时仍旧可能会造成写入放大。For a better understanding of the present application, the writing process of the qcow2 file in the prior art will be described as an example. In the prior art, when a large data block is written in a virtual disk, since the address written to the virtual disk is discretely allocated, the write amplification may still be caused when the large data block is written to the virtual disk.
本实施例中,在将缓存中的待写入文件写入虚拟磁盘之前,先在该虚拟磁盘中为待写入文件对应的写入操作分配连续的地址空间,然后再将上述待写入文件写入到该虚拟磁盘中。In this embodiment, before writing the file to be written in the cache to the virtual disk, first allocate a continuous address space for the write operation corresponding to the file to be written in the virtual disk, and then write the file to be written. Write to this virtual disk.
其中,当用户想要将待写入文件写入虚拟磁盘时,可以触发存储指令(如点击“保存”),虚拟磁盘写入装置在接收到该存储指令后,在上述虚拟磁盘中为待写入文件对应的写入操作分配连续的地址空间,然后再将上述待写入文件写入到该虚拟磁盘中。Wherein, when the user wants to write the file to be written to the virtual disk, the storage instruction may be triggered (such as clicking “save”), and after receiving the storage instruction, the virtual disk writing device is to be written in the virtual disk. The write operation corresponding to the input file allocates a contiguous address space, and then the above-mentioned file to be written is written to the virtual disk.
本实施例所述的基于写时复制的虚拟磁盘写入方法,在检测到虚拟磁盘有写入操作,且该写入操作的写入放大倍数等于或大于预设的阈值时,则对该写入操作开启写时复制,以将该写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中,而不是直接写入虚拟磁盘中,当接收到存储指令时,才在上述虚拟磁盘中为该写入操作分配连续的地址空间,然后将缓存中的待写入文件写入到上述虚拟磁盘中。由于本实施例在虚拟磁盘产生多次写入操作时,便对每一次写入操作开启写时复制,从而可以将待写入文件写入虚拟磁盘中连续的地址空间内,因此能够有效控制虚拟磁盘的写入放大倍数,保护虚拟磁盘的写入性能,解决了现有技术中虚拟磁盘在多次写入文件后,会产生写入放大,导致虚拟磁盘写入性能降低的技术问题。The method for writing a virtual disk based on copy-on-write according to the embodiment, when the virtual disk is detected to have a write operation, and the write magnification of the write operation is equal to or greater than a preset threshold, the write is performed. The write operation enables copy-on-write to temporarily write the file to be written corresponding to the write operation to the cache of the virtual disk instead of directly writing to the virtual disk, and is in the virtual disk when receiving the storage instruction. A contiguous address space is allocated for the write operation, and then the file to be written in the cache is written to the above virtual disk. In this embodiment, when the virtual disk generates multiple write operations, copy-on-write is enabled for each write operation, so that the file to be written can be written into the continuous address space in the virtual disk, thereby effectively controlling the virtual The write amplification factor of the disk protects the write performance of the virtual disk, and solves the technical problem that the virtual disk writes and enlarges after the file is written to the file multiple times in the prior art, resulting in a decrease in the write performance of the virtual disk.
进一步地,参照图2,图2为本申请图1所示步骤S30的细化步骤流程示意图,基于本申请基于写时复制的虚拟磁盘写入方法第一实施例,本申请基于写时复制的虚拟磁盘写入方法第二实施例中,上述图1所示的步骤S30中所述的在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中包括:Further, referring to FIG. 2, FIG. 2 is a schematic flowchart of a refinement step of step S30 shown in FIG. 1 according to the present application. The first embodiment of the method for writing a virtual disk based on copy-on-write according to the present application is based on copy-on-write. In the second embodiment, the contiguous address space is allocated to the write operation in the virtual disk in step S30 shown in FIG. 1 above, and the cache is to be written. The input file is written to the virtual disk and includes:
步骤S31,在所述虚拟磁盘中为所述待写入文件分配连续的簇;Step S31, assigning consecutive clusters to the file to be written in the virtual disk;
步骤S32,将所述缓存中的待写入文件写入到所述连续的簇中,并更新所述缓存中的待写入文件的虚拟地址偏移量。Step S32, writing the file to be written in the cache into the consecutive clusters, and updating the virtual address offset of the file to be written in the cache.
本实施例中,以qcow2文件为上述待写入文件为例,qcow2文件由许多固定大小的簇(cluster)组成,其中,上述虚拟磁盘是由若多个扇区组成的,若干个扇区合为一个簇;另外,虚拟磁盘中文件的写入与读取也是以簇为单位的。In this embodiment, the qcow2 file is taken as an example of the file to be written, and the qcow2 file is composed of a plurality of fixed-size clusters, wherein the virtual disk is composed of multiple sectors, and several sectors are combined. As a cluster; in addition, the writing and reading of files in the virtual disk is also in clusters.
根据各个簇的功能,qcow2文件可以分为以下几类:According to the function of each cluster, qcow2 files can be divided into the following categories:
(1)、header:文件头部,通过header中的数据,可以索引到l1_table、引用计数表(refcount table);(1), header: the file header, through the data in the header, can be indexed to l1_table, reference count table (refcount table);
(2)、l1_table:存放l2_table的偏移位置;(2), l1_table: store the offset position of l2_table;
(3)、l2_table:虚拟地址偏移量,存放数据块的偏移位置;(3), l2_table: virtual address offset, storing the offset position of the data block;
(4)、refcount_table:引用计数表,存放引用计数块(refcount block)的偏移位置;(4), refcount_table: reference count table, store reference count block (refcount Offset position of block);
(5)、refcount_block:引用计数块,存放引用计数(refcount)值;(5), refcount_block: reference counting block, storing the reference count (refcount) value;
(6)、snapshot table:快照表,用于存放快照的基本信息。(6), snapshot table: snapshot table, used to store the basic information of the snapshot.
其中,上述快照是指关于指定数据集合的一个完全可用拷贝,该拷贝包括相应数据在某个时间点(拷贝开始的时间点)的映像,快照可以是其所表示的数据的一个副本,也可以是数据的一个复制品。快照的作用主要是能够进行在线数据备份与恢复,当存储设备发生应用故障或者文件损坏时可以进行快速的数据恢复,将数据恢复某个可用的时间点的状态。快照的另一个作用是为存储用户提供了另外一个数据访问通道,当原数据进行在线应用处理时,用户可以访问快照数据,还可以利用快照进行测试等工作。Wherein, the above snapshot refers to a fully available copy of the specified data set, the copy includes an image of the corresponding data at a certain point in time (the point in time when the copy starts), and the snapshot may be a copy of the data represented by the snapshot, or Is a replica of the data. The role of the snapshot is to enable online data backup and recovery. When the storage device fails or the file is damaged, you can perform fast data recovery and restore the data to a usable time point. Another function of the snapshot is to provide another data access channel for the storage user. When the original data is processed online, the user can access the snapshot data, and can also use the snapshot for testing.
其中,在对上述写入操作开启写时复制,即在待写入文件第一次写入到虚拟磁盘某个存储位置时,首先需要将原有的内容读取出来,写到另一位置处(为快照保留的存储空间,此文中我们称为快照空间),然后再将待写入文件写入到虚拟磁盘中,而下次针对这一存储位置的写入操作将不再执行写时复制操作。Wherein, when the write operation is started for the above write operation, that is, when the file to be written is first written to a storage location of the virtual disk, the original content needs to be read out and written to another location. (The storage space reserved for snapshots, which we call snapshot space in this article), and then write the file to be written to the virtual disk, and the next write operation for this storage location will no longer perform copy-on-write operating.
qcow2文件通过l1_table、l2_table两级索引实现从逻辑地址到实际文件中所在区域的转换,从而实现支持用时分配,即若某一区域没有写入操作,则不为该区域分配实际的地址空间。The qcow2 file implements the conversion from the logical address to the area in the actual file through the two-level index of l1_table and l2_table, thereby realizing the support time allocation. That is, if there is no write operation in an area, the actual address space is not allocated for the area.
具体的,在上述待写入文件写入虚拟磁盘时,在虚拟磁盘中为该待写入文件分配连续的簇,然后将该待写入文件写入到所分配的连续的簇中,并更新该待写入文件的虚拟地址偏移量。Specifically, when the file to be written is written to the virtual disk, a continuous cluster is allocated to the file to be written in the virtual disk, and then the file to be written is written into the allocated continuous cluster, and updated. The virtual address offset of the file to be written.
本实施例所述的基于写时复制的虚拟磁盘写入方法,在虚拟磁盘写入文件时,先在虚拟磁盘中为该待写入文件分配连续的簇,然后将该待写入文件写入到所分配的连续的簇中,并更新该待写入文件的虚拟地址偏移量,从而能够有效控制虚拟磁盘的写入放大倍数,保护虚拟磁盘的写入性能。The method for writing a virtual disk based on copy-on-write according to the embodiment, when a virtual disk writes a file, first allocates a continuous cluster for the file to be written in the virtual disk, and then writes the file to be written. Up to the allocated consecutive clusters, and updating the virtual address offset of the file to be written, thereby effectively controlling the write magnification of the virtual disk and protecting the write performance of the virtual disk.
进一步地,基于上述本申请基于写时复制的虚拟磁盘写入方法第一、第二实施例,本申请基于写时复制的虚拟磁盘写入方法第三实施例中,上述图2所示步骤S32中所述的更新所述缓存中的待写入文件的虚拟地址偏移量包括:Further, based on the first and second embodiments of the method for writing a virtual disk based on the above-mentioned copy of the present application, the third embodiment of the method for writing a virtual disk based on copy-on-write is provided in the third embodiment of the present invention. Updating the virtual address offset of the file to be written in the cache as described in the following:
根据所述待写入文件的文件头部,索引出所述待写入文件的虚拟地址偏移量;Determining, according to the file header of the file to be written, a virtual address offset of the file to be written;
更新所述缓存中的待写入文件的虚拟地址偏移量,并释放所述虚拟磁盘中已被占用的簇。Updating the virtual address offset of the file to be written in the cache and releasing the cluster that has been occupied in the virtual disk.
其中,通过待写入文件的文件头部header,可以索引到l1_table,进而可以根据l1_table索引到虚拟地址偏移量l2_table。另外,通过上述文件头部,可以索引到引用计数表 refcount_table,通过引用计数表便可以索引到引用计数块refcount block所在簇;另外,通过上述文件头部,还可以索引到快照表snapshot table,进而索引到快照的数据,即上述待写入文件。The file header header of the file to be written may be indexed to l1_table, and then may be indexed to the virtual address offset l2_table according to the l1_table. In addition, through the above file header, you can index to the reference count table. Refcount_table, which can be indexed to the reference count block refcount by reference counting table The cluster where the block is located; in addition, through the above file header, it is also possible to index to the snapshot table, and then index the data to the snapshot, that is, the file to be written.
进一步地,上述释放所述虚拟磁盘中已被占用的簇的步骤包括:Further, the step of releasing the clusters already occupied in the virtual disk is as follows:
将所述已被占用的簇对应的引用计数减1。The reference count corresponding to the occupied cluster is decremented by one.
本实施例中,引用计数refcount为数据块索引值,qcow2文件中每一个簇都有一个对应的引用计数,如果这个簇没有被分配,那么它的引用计数为0,如果该簇被分配,则其引用计数大于0。对某个簇而言,其每执行一次写时复制,其对应的引用计数值加1。因此,可以通过将上述已被占用的簇对应的引用计数减1,来释放虚拟磁盘中已被占用的簇。In this embodiment, the reference count refcount is a data block index value, and each cluster in the qcow2 file has a corresponding reference count. If the cluster is not allocated, its reference count is 0. If the cluster is allocated, Its reference count is greater than zero. For a cluster, each time it performs a write-time copy, its corresponding reference count value is incremented by one. Therefore, the clusters already occupied in the virtual disk can be released by decrementing the reference count corresponding to the above-mentioned occupied cluster.
本实施例所述的基于写时复制的虚拟磁盘写入方法,可根据待写入文件的文件头部来索引出待写入文件的虚拟地址偏移量,从而更新该待写入文件的虚拟地址偏移量,并对虚拟磁盘中已被占用的簇对应的引用计数减1,由此来释放虚拟磁盘中已被占用的簇,上述待写入文件即可写入虚拟磁盘中已分配的连续的地址空间中,从而有效控制虚拟磁盘的写入放大倍数,保护虚拟磁盘的写入性能。The method for writing a virtual disk based on copy-on-write according to the embodiment may index the virtual address offset of the file to be written according to the file header of the file to be written, thereby updating the virtual file to be written. The address offset, and the reference count corresponding to the occupied cluster in the virtual disk is decremented by 1, thereby releasing the occupied cluster in the virtual disk, and the file to be written can be written into the allocated virtual disk. Continuous address space, which effectively controls the write magnification of the virtual disk and protects the write performance of the virtual disk.
进一步地,基于上述本申请基于写时复制的虚拟磁盘写入方法第一、第二、第三实施例,本申请基于写时复制的虚拟磁盘写入方法第四实施例中,上述图1所示的步骤S30中所述的在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中包括:Further, based on the first, second, and third embodiments of the method for writing a virtual disk based on the above-mentioned present application, the present application is based on the fourth embodiment of the method for writing a virtual disk based on copy-on-write. Allocating a contiguous address space for the write operation in the virtual disk in the step S30, and writing the file to be written in the cache to the virtual disk includes:
读取已被占用的簇对应的首尾数据段,并与所述缓存中的待写入文件进行拼接后同时写入到所述虚拟磁盘中。Reading the first and last data segments corresponding to the occupied cluster, and splicing with the file to be written in the cache, and simultaneously writing to the virtual disk.
本实施例中,在将上述待写入文件写入到上述虚拟磁盘的过程中,需要更新待写入文件的虚拟地址偏移量,并需要释放虚拟磁盘中已被占用的簇,从而可能会造成上述写入文件某个写入操作写入的数据丢失,因此,本实施例中,在将上述待写入文件写入到上述虚拟磁盘时,读取已被占用的簇对应的首尾数据段,并与上述待写入文件进行拼接后同时写入到虚拟磁盘中。In this embodiment, in the process of writing the file to be written to the virtual disk, the virtual address offset of the file to be written needs to be updated, and the cluster that has been occupied in the virtual disk needs to be released, thereby The data written in the write operation of the write file is lost. Therefore, in the embodiment, when the file to be written is written to the virtual disk, the first and last data segments corresponding to the occupied cluster are read. And spliced with the above-mentioned file to be written and simultaneously written to the virtual disk.
本实施例所述的基于写时复制的虚拟磁盘写入方法,在将上述写入操作对应的待写入文件写入到虚拟磁盘中时,读取已被占用的簇对应的首尾数据段,并与上述待写入文件进行拼接后同时写入到虚拟磁盘中,使得上述写入操作对应的待写入文件全部能够写入到虚拟磁盘中,从而保证了虚拟磁盘数据写入的准确性。The method for writing a virtual disk based on the copy-on-write according to the present embodiment, when writing the file to be written corresponding to the write operation to the virtual disk, reading the first and last data segments corresponding to the occupied cluster, And the splicing of the file to be written is simultaneously written into the virtual disk, so that all the files to be written corresponding to the above write operation can be written into the virtual disk, thereby ensuring the accuracy of writing the virtual disk data.
本申请还提供一种基于写时复制的虚拟磁盘写入装置,该基于写时复制的虚拟磁盘写入装置包括:存储器、处理器及存储在所述存储器上并可在所述处理器上运行的基于写时复制的虚拟磁盘写入程序,该装置能够实现:在检测到虚拟磁盘有写入操作,且该写入操作的写入放大倍数等于或大于预设的阈值时,则对该写入操作开启写时复制,以将该写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中,而不是直接写入虚拟磁盘中,当接收到存储指令时,才在上述虚拟磁盘中为该写入操作分配连续的地址空间,然后将缓存中的待写入文件写入到上述虚拟磁盘中。由于本装置在虚拟磁盘产生多次写入操作时,便对每一次写入操作开启写时复制,从而可以将待写入文件写入虚拟磁盘中连续的地址空间内,因此能够有效控制虚拟磁盘的写入放大倍数,保护虚拟磁盘的写入性能。The present application also provides a virtual disk writing device based on copy-on-write, the copy-on-write-based virtual disk writing device includes: a memory, a processor, and is stored on the memory and operable on the processor The virtual disk writing program based on copy-on-write, the device is capable of: when detecting that the virtual disk has a write operation, and the write magnification of the write operation is equal to or greater than a preset threshold, then the write The write operation enables copy-on-write to temporarily write the file to be written corresponding to the write operation to the cache of the virtual disk instead of directly writing to the virtual disk, and is in the virtual disk when receiving the storage instruction. A contiguous address space is allocated for the write operation, and then the file to be written in the cache is written to the above virtual disk. Since the device generates multiple write operations on the virtual disk, copy-on-write is enabled for each write operation, so that the file to be written can be written into a continuous address space in the virtual disk, thereby effectively controlling the virtual disk. Write write magnification to protect the write performance of the virtual disk.
具体的,上述基于写时复制的虚拟磁盘写入程序被所述处理器执行时实现如下步骤:Specifically, when the above-mentioned copy-on-write virtual disk write program is executed by the processor, the following steps are implemented:
在检测到虚拟磁盘有写入操作时,检测所述写入操作的写入放大倍数;Detecting a write magnification of the write operation when detecting that the virtual disk has a write operation;
当所述写入放大倍数等于或大于预设的阈值时,则对所述写入操作开启写时复制,以将所述写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中;When the write amplification factor is equal to or greater than a preset threshold, the write-once copy is turned on for the write operation to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk;
当接收到存储指令时,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中。When a store instruction is received, a contiguous address space is allocated for the write operation in the virtual disk, and a file to be written in the cache is written to the virtual disk.
为了更好的理解本申请,参照图3,图3为本申请基于写时复制的虚拟磁盘写入装置涉及的软件运行环境的结构示意图,本实施例中,上述基于写时复制的虚拟磁盘写入装置可包括:处理器1001,例如CPU,网络接口1004,用户接口1003,存储器1005,通信总线1002。其中,通信总线1002用于实现这些组件之间的连接通信;用户接口1003可以包括显示屏(Display)、输入单元比如键盘(Keyboard),可选用户接口1003还可以包括标准的有线接口、无线接口;网络接口1004可选的可以包括标准的有线接口、无线接口(如WI-FI接口);存储器1005可以是高速RAM存储器,也可以是稳定的存储器(non-volatile memory),例如磁盘存储器;存储器1005可选的还可以是独立于前述处理器1001的存储装置。For a better understanding of the present application, referring to FIG. 3, FIG. 3 is a schematic structural diagram of a software running environment involved in a virtual disk writing device based on copy-on-write in the present application. In this embodiment, the above-mentioned virtual disk writing based on copy-on-write is performed. The incoming device can include a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. The communication bus 1002 is configured to implement connection communication between the components; the user interface 1003 may include a display, an input unit such as a keyboard, and the optional user interface 1003 may further include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface); the memory 1005 may be a high speed RAM memory or a stable memory (non-volatile) Memory, such as a disk storage; the memory 1005 may alternatively be a storage device independent of the processor 1001 described above.
本领域技术人员可以理解,图3中示出的结构并不构成对上述基于写时复制的虚拟磁盘写入装置的限定,该装置可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。It will be understood by those skilled in the art that the structure shown in FIG. 3 does not constitute a limitation on the above-described copy-on-write virtual disk writing device, which may include more or less components than those illustrated, or a combination of Some parts, or different parts are arranged.
如图3所示,作为一种计算机存储介质的存储器1005中,可以包括操作***、网络通信模块、用户接口模块以及基于写时复制的虚拟磁盘写入程序。As shown in FIG. 3, a memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a virtual disk write program based on copy-on-write.
如图3所示,网络接口1004主要用于连接后台服务器,与后台服务器进行数据通信;用户接口1003主要用于连接客户端(用户端),与客户端进行数据通信;而处理器1001可以用于调用存储器1005中存储的基于写时复制的虚拟磁盘写入程序,并执行相应的操作。As shown in FIG. 3, the network interface 1004 is mainly used to connect to the background server and perform data communication with the background server. The user interface 1003 is mainly used to connect the client (user end) to perform data communication with the client; and the processor 1001 can use The virtual disk write program based on copy-on-write stored in the memory 1005 is called and the corresponding operation is performed.
其中,该基于写时复制的虚拟磁盘写入装置对应的实施例与上述基于写时复制的虚拟磁盘写入方法对应的各个实施例基本相同,故在此不再赘述。The embodiment corresponding to the virtual disk writing device based on the copy-on-write is basically the same as the corresponding embodiment of the virtual disk writing method based on the copy-on-write, and therefore no further details are provided herein.
本申请还提供一种存储介质,该存储介质上存储有基于写时复制的虚拟磁盘写入程序,该存储介质能够实现:在检测到虚拟磁盘有写入操作,且该写入操作的写入放大倍数等于或大于预设的阈值时,则对该写入操作开启写时复制,以将该写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中,而不是直接写入虚拟磁盘中,当接收到存储指令时,才在上述虚拟磁盘中为该写入操作分配连续的地址空间,然后将缓存中的待写入文件写入到上述虚拟磁盘中。由于本装置在虚拟磁盘产生多次写入操作时,便对每一次写入操作开启写时复制,从而可以将待写入文件写入虚拟磁盘中连续的地址空间内,因此能够有效控制虚拟磁盘的写入放大倍数,保护虚拟磁盘的写入性能。The present application further provides a storage medium on which a virtual disk write program based on copy-on-write is stored, and the storage medium is capable of: detecting that a virtual disk has a write operation, and writing the write operation When the magnification is equal to or greater than the preset threshold, the copy-on-write is turned on for the write operation, so that the file to be written corresponding to the write operation is temporarily written into the cache of the virtual disk instead of directly writing to the virtual disk. When a storage instruction is received, a contiguous address space is allocated for the write operation in the virtual disk, and then the file to be written in the cache is written to the virtual disk. Since the device generates multiple write operations on the virtual disk, copy-on-write is enabled for each write operation, so that the file to be written can be written into a continuous address space in the virtual disk, thereby effectively controlling the virtual disk. Write write magnification to protect the write performance of the virtual disk.
具体的,上述基于写时复制的虚拟磁盘写入程序被处理器执行时实现如下步骤:Specifically, when the above-mentioned copy-on-write virtual disk write program is executed by the processor, the following steps are implemented:
在检测到虚拟磁盘有写入操作时,检测所述写入操作的写入放大倍数;Detecting a write magnification of the write operation when detecting that the virtual disk has a write operation;
当所述写入放大倍数等于或大于预设的阈值时,则对所述写入操作开启写时复制,以将所述写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中;When the write amplification factor is equal to or greater than a preset threshold, the write-once copy is turned on for the write operation to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk;
当接收到存储指令时,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中。When a store instruction is received, a contiguous address space is allocated for the write operation in the virtual disk, and a file to be written in the cache is written to the virtual disk.
其中,该存储介质对应的实施例与上述基于写时复制的虚拟磁盘写入方法对应的各个实施例基本相同,故在此不再赘述。The corresponding embodiment of the storage medium is substantially the same as the corresponding embodiment of the virtual disk writing method based on the copy-on-write. Therefore, details are not described herein again.
本申请还提供一种基于写时复制的虚拟磁盘写入装置,所述基于写时复制的虚拟磁盘写入装置包括:The present application further provides a virtual disk writing device based on copy-on-write, wherein the copy-on-write-based virtual disk writing device includes:
检测模块,用于在检测到虚拟磁盘有写入操作时,检测所述写入操作的写入放大倍数;a detecting module, configured to detect a write magnification of the write operation when detecting that the virtual disk has a write operation;
复制模块,用于当所述写入放大倍数等于或大于预设的阈值时,则对所述写入操作开启写时复制,以将所述写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中;a copy module, configured to: when the write magnification is equal to or greater than a preset threshold, enable copy-on-write for the write operation to temporarily write the file to be written corresponding to the write operation to the virtual The cache of the disk;
写入模块,用于当接收到存储指令时,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中。a writing module, configured to allocate a continuous address space for the write operation in the virtual disk and write a file to be written in the cache to the virtual disk when receiving a storage instruction .
进一步地,所述写入模块包括:Further, the writing module includes:
分配单元,用于在所述虚拟磁盘中为所述缓存中的待写入文件分配连续的簇;An allocating unit, configured to allocate, in the virtual disk, a continuous cluster for the file to be written in the cache;
更新单元,用于将所述缓存中的待写入文件写入到所述连续的簇中,并更新所述缓存中的待写入文件的虚拟地址偏移量。And an updating unit, configured to write the file to be written in the cache into the consecutive clusters, and update a virtual address offset of the file to be written in the cache.
进一步地,所述更新单元包括:Further, the update unit includes:
索引子单元,用于根据所述待写入文件的文件头部,索引出所述待写入文件的虚拟地址偏移量;An index subunit, configured to index a virtual address offset of the file to be written according to the file header of the file to be written;
更新子单元,用于更新所述缓存中的待写入文件的虚拟地址偏移量,并释放所述虚拟磁盘中已被占用的簇。An update subunit is configured to update a virtual address offset of the file to be written in the cache, and release a cluster that has been occupied in the virtual disk.
进一步地,所述更新子单元还用于:Further, the update subunit is further configured to:
将所述已被占用的簇对应的引用计数减1。The reference count corresponding to the occupied cluster is decremented by one.
进一步地,所述写入模块,还用于:Further, the writing module is further configured to:
读取已被占用的簇对应的首尾数据段,并与所述缓存中的待写入文件进行拼接后同时写入到所述虚拟磁盘中。Reading the first and last data segments corresponding to the occupied cluster, and splicing with the file to be written in the cache, and simultaneously writing to the virtual disk.
其中,该基于写时复制的虚拟磁盘写入装置中各模块对应的实施例与上述基于写时复制的虚拟磁盘写入方法对应的各个实施例基本相同,故在此不再赘述。The embodiments corresponding to the modules in the virtual disk writing device based on the copy-on-write are basically the same as the corresponding embodiments of the virtual disk writing method based on the copy-on-write, and therefore are not described here.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。It is to be understood that the term "comprises", "comprising", or any other variants thereof, is intended to encompass a non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes those elements. It also includes other elements that are not explicitly listed, or elements that are inherent to such a process, method, article, or device. An element that is defined by the phrase "comprising a ..." does not exclude the presence of additional equivalent elements in the process, method, item, or device that comprises the element.
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。The serial numbers of the embodiments of the present application are merely for the description, and do not represent the advantages and disadvantages of the embodiments.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备执行本申请各个实施例所述的方法。Through the description of the above embodiments, those skilled in the art can clearly understand that the foregoing embodiment method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be through hardware, but in many cases, the former is better. Implementation. Based on such understanding, the technical solution of the present application, which is essential or contributes to the prior art, may be embodied in the form of a software product stored in a storage medium (such as ROM/RAM as described above). , a disk, an optical disk, including a plurality of instructions for causing a terminal device to perform the method described in the various embodiments of the present application.
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本申请的专利保护范围内。The above is only a preferred embodiment of the present application, and is not intended to limit the scope of the patent application, and the equivalent structure or equivalent process transformations made by the specification and the drawings of the present application, or directly or indirectly applied to other related technical fields. The same is included in the scope of patent protection of this application.

Claims (20)

  1. 一种基于写时复制的虚拟磁盘写入方法,其特征在于,所述基于写时复制的虚拟磁盘写入方法包括: A method for writing a virtual disk based on copy-on-write, wherein the method for writing a virtual disk based on copy-on-write includes:
    在检测到虚拟磁盘有写入操作时,检测所述写入操作的写入放大倍数;Detecting a write magnification of the write operation when detecting that the virtual disk has a write operation;
    当所述写入放大倍数等于或大于预设的阈值时,则对所述写入操作开启写时复制,以将所述写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中;When the write amplification factor is equal to or greater than a preset threshold, the write-once copy is turned on for the write operation to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk;
    当接收到存储指令时,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中。When a store instruction is received, a contiguous address space is allocated for the write operation in the virtual disk, and a file to be written in the cache is written to the virtual disk.
  2. 如权利要求1所述的基于写时复制的虚拟磁盘写入方法,其特征在于,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中的步骤包括:The method for writing a virtual disk based on copy-on-write according to claim 1, wherein a contiguous address space is allocated to said write operation in said virtual disk, and said cache is to be written The steps for writing files to the virtual disk include:
    在所述虚拟磁盘中为所述缓存中的待写入文件分配连续的簇;Allocating a continuous cluster in the virtual disk for the file to be written in the cache;
    将所述缓存中的待写入文件写入到所述连续的簇中,并更新所述缓存中的待写入文件的虚拟地址偏移量。Writing a file to be written in the cache to the consecutive clusters and updating a virtual address offset of the file to be written in the cache.
  3. 如权利要求2所述的基于写时复制的虚拟磁盘写入方法,其特征在于,更新所述缓存中的待写入文件的虚拟地址偏移量的步骤包括:The method for writing a virtual disk offset based on copy-on-write according to claim 2, wherein the step of updating the virtual address offset of the file to be written in the cache comprises:
    根据所述待写入文件的文件头部,索引出所述待写入文件的虚拟地址偏移量;Determining, according to the file header of the file to be written, a virtual address offset of the file to be written;
    更新所述缓存中的待写入文件的虚拟地址偏移量,并释放所述虚拟磁盘中已被占用的簇。Updating the virtual address offset of the file to be written in the cache and releasing the cluster that has been occupied in the virtual disk.
  4. 如权利要求3所述的基于写时复制的虚拟磁盘写入方法,其特征在于,释放所述虚拟磁盘中已被占用的簇的步骤包括:The method for writing a virtual disk based on copy-on-write according to claim 3, wherein the step of releasing the cluster that has been occupied in the virtual disk comprises:
    将所述已被占用的簇对应的引用计数减1。The reference count corresponding to the occupied cluster is decremented by one.
  5. 如权利要求3所述的基于写时复制的虚拟磁盘写入方法,其特征在于,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中的步骤还包括:A method for writing a virtual disk based on copy-on-write according to claim 3, wherein a contiguous address space is allocated to said write operation in said virtual disk, and said cache is to be written The steps of writing the file into the virtual disk further include:
    读取已被占用的簇对应的首尾数据段,并与所述缓存中的待写入文件进行拼接后同时写入到所述虚拟磁盘中。Reading the first and last data segments corresponding to the occupied cluster, and splicing with the file to be written in the cache, and simultaneously writing to the virtual disk.
  6. 如权利要求4所述的基于写时复制的虚拟磁盘写入方法,其特征在于,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中的步骤还包括:The method for writing a virtual disk based on copy-on-write according to claim 4, wherein a contiguous address space is allocated to said write operation in said virtual disk, and said cache is to be written The steps of writing the file into the virtual disk further include:
    读取已被占用的簇对应的首尾数据段,并与所述缓存中的待写入文件进行拼接后同时写入到所述虚拟磁盘中。Reading the first and last data segments corresponding to the occupied cluster, and splicing with the file to be written in the cache, and simultaneously writing to the virtual disk.
  7. 一种基于写时复制的虚拟磁盘写入装置,其特征在于,所述基于写时复制的虚拟磁盘写入装置包括:存储器、处理器及存储在所述存储器上并可在所述处理器上运行的基于写时复制的虚拟磁盘写入程序,所述基于写时复制的虚拟磁盘写入程序被所述处理器执行时实现如下步骤:A virtual disk writing device based on copy-on-write, characterized in that the copy-on-write-based virtual disk writing device comprises: a memory, a processor, and is stored on the memory and can be on the processor A write-on-copy-based virtual disk writer that runs the following steps when executed by the processor:
    在检测到虚拟磁盘有写入操作时,检测所述写入操作的写入放大倍数;Detecting a write magnification of the write operation when detecting that the virtual disk has a write operation;
    当所述写入放大倍数等于或大于预设的阈值时,则对所述写入操作开启写时复制,以将所述写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中;When the write amplification factor is equal to or greater than a preset threshold, the write-once copy is turned on for the write operation to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk;
    当接收到存储指令时,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中。When a store instruction is received, a contiguous address space is allocated for the write operation in the virtual disk, and a file to be written in the cache is written to the virtual disk.
  8. 如权利要求7所述的基于写时复制的虚拟磁盘写入装置,其特征在于,所述基于写时复制的虚拟磁盘写入程序被所述处理器执行时,还可以实现如下步骤:The write-on-copy-based virtual disk writing device of claim 7, wherein when the copy-on-write virtual disk write program is executed by the processor, the following steps are further implemented:
    在所述虚拟磁盘中为所述待写入文件分配连续的簇;Allocating consecutive clusters for the file to be written in the virtual disk;
    将所述缓存中的待写入文件写入到所述连续的簇中,并更新所述缓存中的待写入文件的虚拟地址偏移量。Writing a file to be written in the cache to the consecutive clusters and updating a virtual address offset of the file to be written in the cache.
  9. 如权利要求8所述的基于写时复制的虚拟磁盘写入装置,其特征在于,所述基于写时复制的虚拟磁盘写入程序被所述处理器执行时,还可以实现如下步骤:The copy-on-write virtual disk writing device according to claim 8, wherein when the copy-on-write virtual disk writing program is executed by the processor, the following steps are further implemented:
    根据所述待写入文件的文件头部,索引出所述待写入文件的虚拟地址偏移量;Determining, according to the file header of the file to be written, a virtual address offset of the file to be written;
    更新所述缓存中的待写入文件的虚拟地址偏移量,并释放所述虚拟磁盘中已被占用的簇。Updating the virtual address offset of the file to be written in the cache and releasing the cluster that has been occupied in the virtual disk.
  10. 如权利要求9所述的基于写时复制的虚拟磁盘写入装置,其特征在于,所述基于写时复制的虚拟磁盘写入程序被所述处理器执行时,还可以实现如下步骤:The copy-on-write virtual disk writing device according to claim 9, wherein when the copy-on-write virtual disk write program is executed by the processor, the following steps are further implemented:
    读取已被占用的簇对应的首尾数据段,并与所述缓存中的待写入文件进行拼接后同时写入到所述虚拟磁盘中。Reading the first and last data segments corresponding to the occupied cluster, and splicing with the file to be written in the cache, and simultaneously writing to the virtual disk.
  11. 一种存储介质,其特征在于,所述存储介质上存储有基于写时复制的虚拟磁盘写入程序,所述基于写时复制的虚拟磁盘写入程序被处理器执行时实现如下步骤:A storage medium, characterized in that a virtual disk write program based on copy-on-write is stored on the storage medium, and the virtual disk write program based on copy-on-write is executed by the processor to implement the following steps:
    在检测到虚拟磁盘有写入操作时,检测所述写入操作的写入放大倍数;Detecting a write magnification of the write operation when detecting that the virtual disk has a write operation;
    当所述写入放大倍数等于或大于预设的阈值时,则对所述写入操作开启写时复制,以将所述写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中;When the write amplification factor is equal to or greater than a preset threshold, the write-once copy is turned on for the write operation to temporarily write the file to be written corresponding to the write operation into the cache of the virtual disk;
    当接收到存储指令时,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中。When a store instruction is received, a contiguous address space is allocated for the write operation in the virtual disk, and a file to be written in the cache is written to the virtual disk.
  12. 如权利要求11所述的基于写时复制的虚拟磁盘写入方法,其特征在于,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中的步骤包括:The method for writing a virtual disk based on copy-on-write according to claim 11, wherein a contiguous address space is allocated to said write operation in said virtual disk, and said cache is to be written The steps for writing files to the virtual disk include:
    在所述虚拟磁盘中为所述缓存中的待写入文件分配连续的簇;Allocating a continuous cluster in the virtual disk for the file to be written in the cache;
    将所述缓存中的待写入文件写入到所述连续的簇中,并更新所述缓存中的待写入文件的虚拟地址偏移量。Writing a file to be written in the cache to the consecutive clusters and updating a virtual address offset of the file to be written in the cache.
  13. 如权利要求12所述的基于写时复制的虚拟磁盘写入方法,其特征在于,更新所述缓存中的待写入文件的虚拟地址偏移量的步骤包括:The method according to claim 12, wherein the step of updating the virtual address offset of the file to be written in the cache comprises:
    根据所述待写入文件的文件头部,索引出所述待写入文件的虚拟地址偏移量;Determining, according to the file header of the file to be written, a virtual address offset of the file to be written;
    更新所述缓存中的待写入文件的虚拟地址偏移量,并释放所述虚拟磁盘中已被占用的簇。Updating the virtual address offset of the file to be written in the cache and releasing the cluster that has been occupied in the virtual disk.
  14. 如权利要求13所述的基于写时复制的虚拟磁盘写入方法,其特征在于,释放所述虚拟磁盘中已被占用的簇的步骤包括:The method for writing a virtual disk based on copy-on-write according to claim 13, wherein the step of releasing the cluster that has been occupied in the virtual disk comprises:
    将所述已被占用的簇对应的引用计数减1。The reference count corresponding to the occupied cluster is decremented by one.
  15. 如权利要求13所述的基于写时复制的虚拟磁盘写入方法,其特征在于,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中的步骤还包括:The method for writing a virtual disk based on copy-on-write according to claim 13, wherein a contiguous address space is allocated to said write operation in said virtual disk, and said cache is to be written The steps of writing the file into the virtual disk further include:
    读取已被占用的簇对应的首尾数据段,并与所述缓存中的待写入文件进行拼接后同时写入到所述虚拟磁盘中。Reading the first and last data segments corresponding to the occupied cluster, and splicing with the file to be written in the cache, and simultaneously writing to the virtual disk.
  16. 一种基于写时复制的虚拟磁盘写入装置,其特征在于,所述基于写时复制的虚拟磁盘写入装置包括:A virtual disk writing device based on copy-on-write, characterized in that the virtual disk writing device based on copy-on-write includes:
    检测模块,用于在检测到虚拟磁盘有写入操作时,检测所述写入操作的写入放大倍数;a detecting module, configured to detect a write magnification of the write operation when detecting that the virtual disk has a write operation;
    复制模块,用于当所述写入放大倍数等于或大于预设的阈值时,则对所述写入操作开启写时复制,以将所述写入操作对应的待写入文件暂时写入虚拟磁盘的缓存中;a copy module, configured to: when the write magnification is equal to or greater than a preset threshold, enable copy-on-write for the write operation to temporarily write the file to be written corresponding to the write operation to the virtual The cache of the disk;
    写入模块,用于当接收到存储指令时,在所述虚拟磁盘中为所述写入操作分配连续的地址空间,并将所述缓存中的待写入文件写入到所述虚拟磁盘中。a writing module, configured to allocate a continuous address space for the write operation in the virtual disk and write a file to be written in the cache to the virtual disk when receiving a storage instruction .
  17. 如权利要求16所述的基于写时复制的虚拟磁盘写入方法,其特征在于,所述写入模块包括:The method according to claim 16, wherein the writing module comprises:
    分配单元,用于在所述虚拟磁盘中为所述缓存中的待写入文件分配连续的簇;An allocating unit, configured to allocate, in the virtual disk, a continuous cluster for the file to be written in the cache;
    更新单元,用于将所述缓存中的待写入文件写入到所述连续的簇中,并更新所述缓存中的待写入文件的虚拟地址偏移量。And an updating unit, configured to write the file to be written in the cache into the consecutive clusters, and update a virtual address offset of the file to be written in the cache.
  18. 如权利要求17所述的基于写时复制的虚拟磁盘写入方法,其特征在于,所述更新单元包括:The method according to claim 17, wherein the updating unit comprises:
    索引子单元,用于根据所述待写入文件的文件头部,索引出所述待写入文件的虚拟地址偏移量;An index subunit, configured to index a virtual address offset of the file to be written according to the file header of the file to be written;
    更新子单元,用于更新所述缓存中的待写入文件的虚拟地址偏移量,并释放所述虚拟磁盘中已被占用的簇。An update subunit is configured to update a virtual address offset of the file to be written in the cache, and release a cluster that has been occupied in the virtual disk.
  19. 如权利要求18所述的基于写时复制的虚拟磁盘写入方法,其特征在于,所述更新子单元还用于:The method for writing a virtual disk based on copy-on-write according to claim 18, wherein the update subunit is further configured to:
    将所述已被占用的簇对应的引用计数减1。The reference count corresponding to the occupied cluster is decremented by one.
  20. 如权利要求19所述的基于写时复制的虚拟磁盘写入方法,其特征在于,所述写入模块,还用于:The method for writing a virtual disk based on a copy-on-write according to claim 19, wherein the writing module is further configured to:
    读取已被占用的簇对应的首尾数据段,并与所述缓存中的待写入文件进行拼接后同时写入到所述虚拟磁盘中。 Reading the first and last data segments corresponding to the occupied cluster, and splicing with the file to be written in the cache, and simultaneously writing to the virtual disk.
PCT/CN2018/083778 2017-06-20 2018-04-19 Copy-on-write based write method and device for virtual disk, and storage medium WO2018233369A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710472651.4 2017-06-20
CN201710472651.4A CN107861685A (en) 2017-06-20 2017-06-20 Virtual disk wiring method and device, storage medium based on copy-on-write

Publications (1)

Publication Number Publication Date
WO2018233369A1 true WO2018233369A1 (en) 2018-12-27

Family

ID=61699112

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/083778 WO2018233369A1 (en) 2017-06-20 2018-04-19 Copy-on-write based write method and device for virtual disk, and storage medium

Country Status (2)

Country Link
CN (1) CN107861685A (en)
WO (1) WO2018233369A1 (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107861685A (en) * 2017-06-20 2018-03-30 平安科技(深圳)有限公司 Virtual disk wiring method and device, storage medium based on copy-on-write
CN108845908A (en) * 2018-06-21 2018-11-20 郑州云海信息技术有限公司 A kind of SSD method for testing hard disk, device, equipment and medium
CN109086002A (en) * 2018-06-28 2018-12-25 平安科技(深圳)有限公司 Space management, device, computer installation and the storage medium of storage object
CN109491620B (en) * 2018-11-23 2020-08-14 柏科数据技术(深圳)股份有限公司 Storage data rewriting method, device, server and storage medium
CN113626081A (en) * 2020-05-08 2021-11-09 安徽寒武纪信息科技有限公司 Data processing method and device and related product
CN113867630A (en) * 2021-09-10 2021-12-31 长沙市致存科技有限责任公司 Data batch writing method and device of memory, terminal equipment and storage medium
CN115629716B (en) * 2022-12-07 2023-04-11 广东睿江云计算股份有限公司 Defragmentation method and defragmentation system based on disk mirror image file

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8239617B1 (en) * 2010-02-12 2012-08-07 Emc Corporation Enterprise data storage system using multi-level cell flash memory
US20120320679A1 (en) * 2011-05-17 2012-12-20 Sprouse Steven T System and method for minimizing write amplification while maintaining sequential performance using logical group stripping in a multi-bank system
CN104834607A (en) * 2015-05-19 2015-08-12 华中科技大学 Method for improving distributed cache hit rate and reducing solid state disk wear
CN107861685A (en) * 2017-06-20 2018-03-30 平安科技(深圳)有限公司 Virtual disk wiring method and device, storage medium based on copy-on-write

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104503710B (en) * 2015-01-23 2018-02-13 福州瑞芯微电子股份有限公司 A kind of method and apparatus for improving flash memory writing speed
CN104765575B (en) * 2015-04-23 2017-09-15 成都博元时代软件有限公司 information storage processing method
CN106020718A (en) * 2016-05-09 2016-10-12 福建联迪商用设备有限公司 A method and a system for improving virtual disk write-in performance
CN106201916B (en) * 2016-07-25 2019-03-29 中国人民解放军国防科学技术大学 A kind of nonvolatile cache method towards SSD

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8239617B1 (en) * 2010-02-12 2012-08-07 Emc Corporation Enterprise data storage system using multi-level cell flash memory
US20120320679A1 (en) * 2011-05-17 2012-12-20 Sprouse Steven T System and method for minimizing write amplification while maintaining sequential performance using logical group stripping in a multi-bank system
CN104834607A (en) * 2015-05-19 2015-08-12 华中科技大学 Method for improving distributed cache hit rate and reducing solid state disk wear
CN107861685A (en) * 2017-06-20 2018-03-30 平安科技(深圳)有限公司 Virtual disk wiring method and device, storage medium based on copy-on-write

Also Published As

Publication number Publication date
CN107861685A (en) 2018-03-30

Similar Documents

Publication Publication Date Title
WO2018233369A1 (en) Copy-on-write based write method and device for virtual disk, and storage medium
WO2018014567A1 (en) Method for improving performance of virtual machine, and terminal, device and computer-readable storage medium
JP2019096355A (en) Method and device for maintaining logical volume
WO2019165691A1 (en) Method, apparatus and device for automatically generating test case, and readable storage medium
WO2015005634A1 (en) Memory system and method for controlling same
WO2013143341A1 (en) Method and device for updating application information of mobile terminal
WO2014082500A1 (en) Page loading method and system therefor, and computer storage medium
WO2015016516A1 (en) Method and device for managing tab window indicating application group including heterogeneous applications
WO2017190450A1 (en) Process closing method and apparatus
WO2013085334A1 (en) User terminal device and method for displaying background screen thereof
WO2017206601A1 (en) Client data processing method and apparatus
WO2014208863A1 (en) Integrated data management apparatus and method for non-volatile buffer cache and non-volatile storage
WO2014000635A1 (en) Method for reader to provide service, reader, terminal and computer storage medium
WO2019062109A1 (en) Method of mounting disk array, android device and storage medium
WO2018120430A1 (en) Page construction method, terminal, computer-readable storage medium and page construction device
WO2018090585A1 (en) Data virtualization storage method and apparatus, and server and storage medium
WO2019062102A1 (en) Method of mounting disk array, android device and storage medium
US20160070621A1 (en) Pruning unwanted file content from an image backup
WO2021080385A1 (en) Computing device and operating method thereof
WO2013091456A1 (en) Desktop management method and device
EP3539046A1 (en) Electronic device and method for managing data in electronic device
WO2017036208A1 (en) Method and system for extracting information in display interface
WO2019062093A1 (en) Raid management method and device, and computer-readable storage medium
WO2019080247A1 (en) Method, apparatus and device for generating insurance policy approval, and computer readable storage medium
WO2019019249A1 (en) Method, apparatus and device for executing network request, and computer-readable storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18819758

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18819758

Country of ref document: EP

Kind code of ref document: A1