A concurrent virtual machine memory space processing method, device, equipment and medium

By copying the target page table data of the same runtime environment in the virtual machine to the main physical memory page table of the first virtual machine, the problem of low memory usage efficiency in sandbox detection is solved, achieving more efficient memory space management and reducing CPU resource waste.

CN114398147BActive Publication Date: 2026-01-02NSFOCUS INFORMATION TECHNOLOGY CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111621613.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-28
Publication Date
2026-01-02
Estimated Expiration
2041-12-28

AI Technical Summary

Technical Problem

Existing technologies cannot effectively reduce the physical memory usage of concurrent virtual machines on the host in a short period of time during sandbox testing, resulting in wasted CPU resources. Furthermore, existing memory compression and merging methods are inefficient.

Method used

When the first virtual machine is loaded and running, a target second virtual machine with the same running environment is determined, and the data of the target page table is copied to the main physical memory page table of the first virtual machine. Data copying is implemented using the kernel-mode VMM, driver layer, user-mode process fork and mmap interface, and the page table state is adjusted to optimize memory usage.

Benefits of technology

It improves the processing efficiency of the host's physical memory space, reduces the occupation of the host's physical memory by concurrent virtual machines, and reduces the waste of CPU resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114398147B_ABST
    Figure CN114398147B_ABST
Patent Text Reader

Abstract

The application discloses a concurrent virtual machine memory space processing method, device, equipment and medium. When a new first virtual machine is loaded and run, a target second virtual machine with the same running environment as the first virtual machine is determined, data of a target page table of the target second virtual machine is copied into a page table of a main physical memory of the first virtual machine, and the main physical memory is a physical memory with the largest memory space in a host physical memory space mapped by a guest physical memory space of the virtual machine. Therefore, the data of the first physical page identified by the target page table can be reused, the processing efficiency of the host physical memory space is improved, and the processing operation for reducing the occupation of the host physical memory space is performed.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of virtual machines, and particularly relates to a concurrent virtual machine memory space processing method and device, equipment and a medium. BACKGROUND

[0002] In recent years, various types of malicious software have emerged in an endless stream. In order to detect malicious software, the prior art adopts a sandbox detection technology, which judges whether software is malicious software by running the software in a virtual machine and observing the behavior of the software. In order to evade detection, malicious software usually identifies whether it is running in a virtual machine by obtaining the size of the memory space. Since the physical memory of the existing real running machine is greater than a preset size, for example, the preset size is 4 GB, the malicious software obtains the size of the guest physical memory space of the client system in which the malicious software is located, and if the guest physical memory space is less than the preset size, the malicious software determines that it is running in a virtual machine.

[0003] If the virtual machine is allocated a guest physical memory space greater than the preset size, the following problems will occur, that is, the virtual machine client system will load all non-all-zero data of the guest physical memory space to the host physical memory space. For a 64-bit Windows system, at least 4 GB of host physical memory space needs to be allocated to a virtual machine. For a real running machine including dual Xeon 20-core central processing units (CPUs), 128 GB of host physical memory space can at most concurrently run 32 virtual machines. After deducting the memory space for other purposes, the number of concurrent virtual machines may be less than 20. However, 20 concurrent virtual machines cannot occupy all CPU resources, which leads to waste of CPU resources. Therefore, it is necessary to increase the number of concurrent virtual machines and increase the occupied CPU resources to reduce the waste of CPU resources.

[0004] In order to increase the number of concurrent virtual machines, it is necessary to reduce the host physical memory space occupied by the concurrent virtual machines. In the prior art, the host physical memory space occupied by the concurrent virtual machines is mainly reduced by using a memory compression method and a concurrent virtual machine physical page merging method.

[0005] In the memory compression method in the prior art, a memory balloon technology is used to compress the host physical memory space of the concurrent multiple virtual machines. Specifically, the unused host physical memory space is compressed by the driver of the virtual machine, so as to reduce the overall occupation of the host physical memory space.

[0006] In the prior art, the transparent page sharing (TPS) technology and the kernel same-page merging (KSM) technology are used in the concurrent virtual machine physical page merging method. Specifically, a background running virtual machine service program compares the physical page data of the host physical memory space of all concurrently running virtual machines, and multiple physical pages with the same physical page data are merged into one physical page, thereby reducing the occupation of the host physical memory space of the concurrent virtual machines.

[0007] In the prior art, memory compression or memory merging is performed when multiple virtual machines are running. In order to not affect the execution efficiency of the virtual machines, the time for reducing the occupation of the host physical memory space of the concurrent virtual machines is relatively long in the prior art. Since the sandbox detection time is relatively short, the same effect of reducing the occupation of the host physical memory space as in the prior art needs to be achieved in a shorter time than the prior art in the sandbox detection environment. Therefore, when the sandbox detection needs to reduce the occupation of the host physical memory space of the concurrent virtual machines, how to improve the processing efficiency of the host physical memory space becomes a technical problem to be solved urgently. SUMMARY

[0008] The present application provides a concurrent virtual machine memory space processing method, device, equipment and medium, to solve the problem that the prior art cannot meet the optimization of memory occupation in the short-time startup process of sandbox detection.

[0009] The present application provides a concurrent virtual machine memory space processing method, comprising:

[0010] loading and running a first virtual machine, and determining a target second virtual machine with the same running environment as the first virtual machine according to the running environment of the first virtual machine and the running environment of each loaded second virtual machine;

[0011] copying data of a target page table of the target second virtual machine to a page table of the main physical memory of the first virtual machine, wherein the main physical memory is the largest memory in the host physical memory space mapped by the guest physical memory space of the virtual machine.

[0012] Further, the copying of the data of the target page table to the page table of the main physical memory of the first virtual machine comprises:

[0013] copying the data of the target page table to a virtual machine management layer (VMM) in the kernel mode, copying the data of the target page table from the VMM to the page table of the main physical memory of the first virtual machine; or

[0014] copying the data of the target page table from the driver layer to the page table of the main physical memory of the first virtual machine, or

[0015] invoking a user-mode interface of a user-mode process fork, and copying the data of the target page table in the page table data of the target second virtual machine process into the page table of the first virtual machine process through the user-mode interface of the user-mode process fork, or

[0016] invoking a user-mode interface of a user-mode process mmap, and copying the data of the target page table from a memory share and into the page table of the main physical memory of the first virtual machine through the user-mode interface of the user-mode process mmap, wherein the memory share is created when a snapshot file of a first physical page of the target page table identifier of the second virtual machine is pre-loaded.

[0017] Further, after the copying of the data of the target page table from the VMM and into the page table of the main physical memory of the first virtual machine, the method further comprises:

[0018] adjusting the state of the page table of the main physical memory of the first virtual machine to an unwritable state.

[0019] Further, the method further comprises:

[0020] if an access violation exit event is detected, obtaining a physical address corresponding to a violation address of the access violation exit event;

[0021] determining whether the physical address is identical to a target address of the target physical page;

[0022] if yes, applying, by the VMM, a second physical page with a same memory space size as the first physical page of the target page table identifier in a host physical memory space, copying data of the first physical page into the second physical page, updating identifier information of the first physical page recorded in the page table of the main physical memory of the first virtual machine to identifier information of the second physical page, and adjusting the state of the page table of the main physical memory of the first virtual machine to a readable and writable state.

[0023] Further, after the copying of the data of the target page table from the driver layer and into the page table of the main physical memory of the first virtual machine, the method further comprises:

[0024] adjusting the state of the page table of the main physical memory of the first virtual machine to a copy-on-write (COW) state.

[0025] Further, after the user-mode interface of the user-mode process fork copies the data of the target page table in the page table data of the target second virtual machine process to the page table of the first virtual machine process, the method further comprises:

[0026] calling the user-mode interface of the user-mode process fork to adjust the state of the page table of the main physical memory of the first virtual machine to the copy-on-write COW state;

[0027] performing a system initialization operation on the first virtual machine.

[0028] Further, after the user-mode interface of the user-mode process mmap copies the data of the target page table from the memory sharing and copies the data of the target page table to the page table of the main physical memory of the first virtual machine, the method further comprises:

[0029] calling the user-mode interface of the user-mode process mmap to adjust the state of the page table of the main physical memory of the first virtual machine to the copy-on-write COW state.

[0030] Correspondingly, the application provides a concurrent virtual machine memory space processing device, which comprises:

[0031] a determining module, configured to load a first virtual machine, and determine a target second virtual machine with the same running environment as the first virtual machine according to the running environment of the first virtual machine and the running environment of each loaded second virtual machine;

[0032] a processing module, configured to copy the data of a target page table of the target second virtual machine to the page table of the main physical memory of the first virtual machine according to the target page table, wherein the main physical memory is the largest physical memory in the host physical memory space mapped by the guest physical memory space of the virtual machine.

[0033] Further, the processing module is specifically configured to copy the data of the target page table into a virtual machine management layer (VMM) in a kernel mode, copy the data of the target page table from the VMM and copy into a page table of a main physical memory of the first virtual machine; or copy the data of the target page table into a driver layer in the kernel mode, copy the data of the target page table from the driver layer and copy into the page table of the main physical memory of the first virtual machine; or call a user state interface of a user state process fork, copy the data of the target page table in page table data of the target second virtual machine process into a page table of the first virtual machine process through the user state interface of the user state process fork; or call a user state interface of a user state process mmap, copy the data of the target page table from a memory sharing and copy into the page table of the main physical memory of the first virtual machine through the user state interface of the user state process mmap, wherein the memory sharing is a snapshot file of a first physical page of a target page table identifier of the second virtual machine preloaded.

[0034] Further, the processing module is further configured to, after the copying of the data of the target page table from the VMM and into the page table of the main physical memory of the first virtual machine, adjust a state of the page table of the main physical memory of the first virtual machine to an unwritable state.

[0035] Further, the processing module is further configured to, if an access violation exit event is detected, acquire a physical address corresponding to a violation address of the access violation exit event; determine whether the physical address is identical to a target address of the target physical page; if yes, apply, by the VMM, a second physical page with a same memory space size as the first physical page of the target page table identifier in a host physical memory space, copy data of the first physical page into the second physical page, update identifier information of the first physical page recorded in the page table of the main physical memory of the first virtual machine to identifier information of the second physical page, and adjust a state of the page table of the main physical memory of the first virtual machine to a readable and writable state.

[0036] Further, the processing module is further configured to, after the copying of the data of the target page table from the driver layer and into the page table of the main physical memory of the first virtual machine, adjust a state of the page table of the main physical memory of the first virtual machine to a copy-on-write (COW) state.

[0037] Further, the processing module is further configured to, after copying the data of the target page table in the page table data of the target second virtual machine process into the page table of the first virtual machine process through the user-mode process fork user-mode interface, call the user-mode process fork user-mode interface to adjust the state of the page table of the main physical memory of the first virtual machine to a copy-on-write COW state, and perform a system initialization operation on the first virtual machine.

[0038] Further, the processing module is further configured to, after copying the data of the target page table in the page table data of the target second virtual machine process into the page table of the first virtual machine process through the user-mode process fork user-mode interface, call the user-mode process fork user-mode interface to adjust the state of the page table of the main physical memory of the first virtual machine to a copy-on-write COW state, and perform a system initialization operation on the first virtual machine.

[0039] Correspondingly, the present application provides an electronic device, which comprises a processor and a memory, the memory is used to store program instructions, and the processor is used to execute the computer program stored in the memory to realize the steps of any one of the concurrent virtual machine memory space processing methods.

[0040] Correspondingly, the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to realize the steps of any one of the concurrent virtual machine memory space processing methods.

[0041] The present application provides a concurrent virtual machine memory space processing method, device, equipment and medium, when a new first virtual machine is loaded and run, a target second virtual machine in the same running environment as the first virtual machine is determined, and the data of the target page table is copied into the page table of the main physical memory of the first virtual machine according to the target page table of the main physical memory of the target second virtual machine, wherein the main physical memory is the largest physical memory in the host physical memory space mapped by the guest physical memory space of the virtual machine, so that the data of the first physical page identified by the target page table can be reused, the processing efficiency of the host physical memory space is improved, and the processing operation for reducing the occupation of the host physical memory space is reduced. BRIEF DESCRIPTION OF DRAWINGS

[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.

[0043] Figure 1A process schematic diagram of a method for determining unstable pixels provided by an embodiment of the present application is shown in FIG. 1.

[0044] Figure 2 A schematic diagram of copying data of a target page table into a page table of a main physical memory of a first virtual machine provided by an embodiment of the present application is shown in FIG. 2.

[0045] Figure 3 A schematic diagram of copying data of a target page table into a page table of a main physical memory of a first virtual machine provided by an embodiment of the present application is shown in FIG. 2.

[0046] Figure 4 A schematic diagram of copying data of a target page table into a page table of a main physical memory of a first virtual machine provided by an embodiment of the present application is shown in FIG. 2.

[0047] Figure 5 A schematic diagram of copying data of a target page table into a page table of a main physical memory of a first virtual machine provided by an embodiment of the present application is shown in FIG. 2.

[0048] Figure 6 A structure schematic diagram of a concurrent virtual machine memory space processing device provided by an embodiment of the present application is shown in FIG. 3.

[0049] Figure 7 A structure schematic diagram of an electronic device provided by an embodiment of the present application is shown in FIG. 4. DETAILED DESCRIPTION

[0050] In order to make the objects, technical solutions, and advantages of the present application clearer, further detailed description will be made to the present application with reference to the accompanying drawings, obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the protection scope of the present application.

[0051] In order to improve the processing efficiency of the host physical memory space when the processing operation of reducing the host physical memory space occupation of the concurrent virtual machine is needed in the sandbox detection, an embodiment of the present application provides a concurrent virtual machine memory space processing method, device, equipment, and medium.

[0052] Embodiment 1:

[0053] Figure 1 A process schematic diagram of a concurrent virtual machine memory space processing method provided by an embodiment of the present application is shown in FIG. 5, and the process includes the following steps.

[0054] S101: load and run a first virtual machine, and determine a target second virtual machine with the same running environment as the first virtual machine according to the running environment of the first virtual machine and the running environment of each loaded second virtual machine.

[0055] The concurrent virtual machine memory space processing method provided in the examples of the present application is applied to an electronic device, which can be a tablet computer, a PC, a smart terminal, etc., or a server, wherein the server can be a local server or a cloud server.

[0056] When the sandbox detection of the electronic device needs to reduce the processing operation of the host physical memory space occupied by the concurrent virtual machine, in order to improve the processing efficiency of the host physical memory space, the host physical memory space can be started to be reduced in loading and running the first virtual machine. The first virtual machine refers to a newly loaded and running virtual machine, which is relative to the already loaded and running virtual machine, which is referred to as the second virtual machine, wherein the number of the second virtual machine can be one or multiple.

[0057] The electronic device starts to load and run the first virtual machine, in order to reduce the occupation of the host physical memory space, the host physical memory space of a certain second virtual machine that has been loaded can be used, in order to determine the target second virtual machine to be used for the host physical memory space, according to the running environment of the first virtual machine and the running environment of each second virtual machine that has been loaded, the second virtual machine with the same running environment as the first virtual machine is determined, and the second virtual machine is determined as the target second virtual machine to be used for the host physical memory space.

[0058] The running environment includes both software and hardware, the software refers to the operating system, and the hardware includes CPU, memory, graphics card, hard disk, etc. Since the hardware of the virtual machines in the same electronic device is the same, the running environments of different virtual machines can refer to different operating systems, including Windows, Linux, Unix, etc. Windows can be further divided into Windows xp, Windows 7, Windows 10, etc. It can also be the same operating system but different software and patches, or the same operating system, the same software and patches but different snapshot files.

[0059] When the second virtual machine is the target second virtual machine with the same running environment as the first virtual machine, the first virtual machine can use the operating system in the host physical memory space of the target second virtual machine.

[0060] S102: According to the target page table of the target second virtual machine main physical memory, the data of the target page table is copied into the page table of the first virtual machine main physical memory, wherein the main physical memory is the host physical memory space mapped by the guest physical memory space of the virtual machine, and the physical memory with the largest memory space.

[0061] According to the determined target second virtual machine, in order to reuse the data of the first physical page of the target page table identifier of the host physical memory of the target second virtual machine, since the running environment of the target second virtual machine is the same as that of the first virtual machine, the first virtual machine can use the operating system in the host physical memory space of the target second virtual machine.

[0062] Since the host physical memory space of the target second virtual machine is used by mapping the physical page (MMU page) of the guest physical memory space of the target second virtual machine, and the memory space of the operating system in the host physical memory space of the target second virtual machine is the main physical memory, the memory space size of the main physical memory is the largest in the host physical memory space of the target second virtual machine, so in the embodiment of the application, the data of the target page table of the main physical memory can be copied to realize the reuse of the data of the first physical page of the target page table identifier by the first virtual machine.

[0063] According to the target page table of the main physical memory of the target second virtual machine, the data of the target page table is copied into the page table of the main physical memory of the first virtual machine. The target page table records the identification information of the physical page, for example, the identification information can be the page frame number (PFN) of the physical page. According to the target page table of the main physical memory of the target second virtual machine, the first physical page corresponding to the target page table can be determined, and the data of the first physical page identified by the target page table is used according to the target page table.

[0064] Since the method of the embodiment of the application determines the target second virtual machine with the same running environment as the first virtual machine when loading and running a new first virtual machine, and according to the target page table of the main physical memory of the target second virtual machine, the data of the target page table is copied into the page table of the main physical memory of the first virtual machine, wherein the main physical memory is the largest physical memory in the host physical memory space mapped by the guest physical memory space of the virtual machine, thereby the data of the first physical page identified by the target page table can be reused, and the processing efficiency of the host physical memory space is improved, wherein the processing is a processing operation for reducing the occupation of the host physical memory space.

[0065] Embodiment 2:

[0066] In order to realize saving the target page table into the first guest physical memory space of the first virtual machine, on the basis of the above-mentioned embodiment, in the embodiment of the application, the saving of the target page table into the first guest physical memory space of the first virtual machine comprises:

[0067] Method 1: copying data of the target page table into a virtual machine monitor (VMM) in a kernel mode, copying the data of the target page table from the VMM and into a page table of the main physical memory of the first virtual machine.

[0068] The electronic device includes a VMM in a kernel mode, which is operated in a kernel mode of an operating system, and a VMM driver can provide protection mechanisms necessary for virtualization technology.

[0069] The electronic device copies data of a target page table into a VMM in a kernel mode, and copies the data of the target page table from the VMM in the kernel mode and into a page table of the main physical memory of the first virtual machine. The target page table belongs to a two-dimensional page table (Two Dimensional Paging), also called second level address translation (SLAT).

[0070] Figure 2 A schematic diagram for copying data of a target page table into a page table of the main physical memory of the first virtual machine is provided for an embodiment of the present application, as shown in Figure 2 The electronic device includes a kernel mode and a user mode, a process of a virtual machine is operated in the user mode, and a VMM is operated in the kernel mode. Figure 2 The parent virtual machine process in the kernel mode is a process of a target second virtual machine, and the new virtual machine process is a process of the first virtual machine. Data of a target page table of the main physical memory of the parent virtual machine process is copied into the VMM, and the data of the target page table is copied from the VMM and into a page table of the main physical memory of the new virtual machine. After the parent virtual machine process loads a snapshot file and allocates a host physical memory space, the parent virtual machine process is in a suspended state.

[0071] Method 2: copying data of the target page table into a driver layer in a kernel mode, and copying the data of the target page table from the driver layer and into a page table of the main physical memory of the first virtual machine.

[0072] In an embodiment of the present application, data of a target page table can also be copied into a driver layer in a kernel mode, the data of the target page table is copied in the driver layer, and the copied data of the target page table is copied into a page table of the main physical memory of the first virtual machine. The target page table belongs to a process page table, and the process page table is a one-dimensional page table.

[0073] Figure 3 Another schematic diagram for copying data of a target page table into a page table of the main physical memory of the first virtual machine is provided for an embodiment of the present application, as shown in Figure 3As shown, the electronic device has a kernel state and a user state, the user state runs a process of a virtual machine, the kernel state runs a driver module, the parent virtual machine process in the figure is a process of a target second virtual machine, and the new virtual machine process is a process of a first virtual machine; data of a target page table in the main physical memory of the parent virtual machine process is copied to the driver module, and the data of the target page table is copied from the driver module to a page table of the main physical memory of the new virtual machine.

[0074] Mode 3: a user state interface of a user state process fork is called, and the data of the target page table in the page table data of the target second virtual machine process is copied to the page table of the first virtual machine process through the user state interface of the user state process fork.

[0075] In the embodiment of the application, the user state interface of the user state process fork can also be called to copy the data of the target page table in the page table data of the target second virtual machine process to the page table of the first virtual machine process.

[0076] The user state interface is an interface of the target second virtual machine, and the memory of the parent virtual machine process is completely copied by a child virtual machine process through the user state interface of the fork system, that is, the memory data and the handle of the target second virtual machine can be completely copied by the first virtual machine through the user state interface, and the memory data includes the data of the target page table.

[0077] Since the data of the target page table is copied in a third party, whether the third party is a VMM in a kernel state or a driver layer in the kernel state, the cost of copying the data of the target page table is high and the efficiency is low. In order to improve the efficiency of copying the data of the target page table, in the mode 3, a Linux kernel function is used to directly copy the data of the target page table, which ensures that the concurrent virtual machines do not affect each other, and the user state interface of the target second virtual machine is called in the mode 3 to directly copy the data of the target page table from the page table data of the target second virtual machine process.

[0078] Figure 4 Another schematic diagram for copying the data of the target page table to the page table of the main physical memory of the first virtual machine is provided in the embodiment of the application, as shown in Figure 4 As shown, the electronic device has a user state, the user state runs a process of a virtual machine, the parent virtual machine process in the figure is a process of a target second virtual machine, and the new virtual machine process is a process of a first virtual machine; the data of the target page table of the parent virtual machine can be copied to the page table of the main physical memory of the new virtual machine through the arrow fork between the parent virtual machine process and the new virtual machine process.

[0079] Mode 4: calling the user state interface of the user state process mmap, copying the data of the target page table from the memory share and copying the data of the target page table into the page table of the main physical memory of the first virtual machine through the user state interface of the mmap, wherein the memory share is created when the snapshot file of the first physical page of the target page table identifier of the second virtual machine is preloaded.

[0080] In the embodiment of the present application, the target second virtual machine preloads the snapshot file and allocates the main host physical memory space, and when the snapshot file corresponding to the first physical page of the target page table identifier of the second virtual machine is loaded, a memory share is created, and the name of the memory share is the name related to the virtual machine running environment, and after the snapshot file is loaded, the target second virtual machine is in a suspended state.

[0081] Therefore, the electronic device can also call the user state interface of the user state process mmap, directly copy the data of the target page table from the memory share of the target second virtual machine, and copy the data of the target page table into the page table of the main physical memory of the first virtual machine through the user state interface. The user state interface is the interface of the first virtual machine.

[0082] In the mode of directly copying the data of the target page table, the user state interface of the user state process mmap of the first virtual machine can also be called in the mode 4, and in order to ensure that the concurrent virtual machines do not affect each other, the data of the target page table is copied from the memory share of the target second virtual machine when the data of the target page table is copied through the user state interface of the first virtual machine.

[0083] Figure 5 Another schematic diagram for copying the data of the target page table into the page table of the main physical memory of the first virtual machine is provided for the embodiment of the present application, as shown in Figure 5 As shown in the figure, there is a user state in the electronic device, the user state runs the process of the virtual machine, the mother virtual machine process in the figure is the process of the target second virtual machine, and the new virtual machine process is the process of the first virtual machine. The data of the target page table in the memory share of the mother virtual machine can be copied into the page table of the main physical memory of the new virtual machine through the arrow mmap between the mother virtual machine process and the new virtual machine process.

[0084] In the embodiment of the present application, the virtual machines of the same running environment in the same system of the electronic device are concurrent, and since these virtual machines all use the same main physical memory, before the scheme of the embodiment of the present application is adopted, the virtual machines occupy n*m GB; wherein n is the number of the concurrent virtual machines of the same running environment, and m is the size of the main physical memory occupied by a single virtual machine; and after the scheme of the embodiment of the present application is adopted, the virtual machines occupy 2*m GB, thereby reducing the main host physical memory space occupied by the concurrent virtual machines.

[0085] In the above embodiments, the method 1 uses virtualization technology to implement, and uses a SALT page table to implement the main physical memory of the target second virtual machine.

[0086] The method 2 uses a one-dimensional page table and directly uses a system copy-on-write mechanism to implement the main physical memory of the target second virtual machine; the method 3 completely uses an operating system user interface and a copy-on-write function to implement the main physical memory of the target second virtual machine; and the method 4 uses a user interface and a copy-on-write function other than a fork to implement the main physical memory of the target second virtual machine.

[0087] The methods 1 and 2 need module support, and for Linux / Unix systems, a driver program needs to be compiled under different kernel versions, which is relatively costly. The methods 3 and 4 do not need driver module support and are good in universality. However, the method 3 needs to be reinitialized when running the first virtual machine, and the method 4 is the least costly and best in universality.

[0088] Embodiment 3

[0089] In order to implement normal running of the first virtual machine, on the basis of the above embodiments, in the embodiment of the present application, after copying the data of the target page table from the VMM and into the page table of the main physical memory of the first virtual machine, the method further comprises:

[0090] adjusting the state of the page table of the main physical memory of the first virtual machine to an unwritable state.

[0091] In the embodiment of the present application, after copying the data of the target page table from the VMM and saving in the page table of the main physical memory of the first virtual machine, in order to prevent the first virtual machine from affecting the target second virtual machine when using the target physical page corresponding to the target page table, the state of the page table of the main physical memory of the first virtual machine is further adjusted to an unwritable state.

[0092] The target page table includes identification information and state information of the target physical page, and the state information includes readable, writable, and executable states. The unwritable state includes the readable and executable states.

[0093] In order to make the first virtual machine run normally, in the embodiment of the present application, the method further comprises:

[0094] If the access violation exit event is detected, a physical address corresponding to a violation address of the access violation exit event is acquired;

[0095] It is judged whether the physical address is the same as a target address of the target physical page.

[0096] If yes, the VMM allocates a second physical page in the host physical memory space, which has the same memory space size as the first physical page identified by the target page table, copies the data of the first physical page into the second physical page, updates the identification information of the first physical page recorded in the page table of the main physical memory of the first virtual machine to the identification information of the second physical page, and adjusts the state of the page table of the main physical memory of the first virtual machine to a readable and writable state.

[0097] When the first virtual machine is running, an access violation exit event of memory write may occur. If the access violation exit event is detected, the physical address corresponding to the violation address of the access violation exit event is obtained, and it is determined whether the physical address is the same as the target address of the target physical page according to the physical address corresponding to the violation address. If the physical address is the same as the target address, it indicates that the first virtual machine accesses the physical page identified by the target page table and wants to perform a memory write operation. If the physical address is not the same as the target address, it indicates that the first virtual machine accesses a physical page that is not the physical page corresponding to the target page table.

[0098] When it is determined that the physical address is the same as the target address of the target physical page, the VMM allocates a second physical page in the host physical memory space, wherein the memory space size of the second physical page is the same as that of the first physical page, copies the data of the first physical page into the second physical page, updates the identification information of the first physical page recorded in the page table of the main physical memory of the first virtual machine to the identification information of the second physical page, and adjusts the state of the page table of the main physical memory of the first virtual machine to a readable and writable state.

[0099] Embodiment 4:

[0100] In order to realize the normal running of the first virtual machine, on the basis of the above embodiments, in the embodiment of the present application, after the data of the target page table is copied from the driver layer and into the page table of the main physical memory of the first virtual machine, the method further comprises:

[0101] adjusting the state of the page table of the main physical memory of the first virtual machine to a copy-on-write (COW) state.

[0102] In order to realize the normal running of the first virtual machine, in the embodiment of the present application, after the data of the target page table is copied from the driver layer and into the page table of the main physical memory of the first virtual machine in the manner 2 in the above embodiment 2, the state of the page table of the main physical memory of the first virtual machine can also be adjusted to a COW state.

[0103] COW means that for a physical page of a host physical memory space, the physical page can be mapped into the guest physical memory space of multiple virtual machine processes, and the multiple virtual machine processes can simultaneously read the content of the same physical page. However, when the content of the physical page of a process is rewritten, the system automatically creates a new physical page to save the modified data.

[0104] Embodiment 5

[0105] In order to realize the normal running of the first virtual machine, on the basis of the above embodiments, in the embodiment of the present application, after the user-mode interface of the user-mode process fork copies the data of the target page table in the page table data of the target second virtual machine process to the page table of the first virtual machine process, the method further comprises:

[0106] calling the user-mode interface of the user-mode process fork to adjust the state of the page table of the main physical memory of the first virtual machine to the copy-on-write COW state;

[0107] performing a system initialization operation on the first virtual machine.

[0108] In order to realize the normal running of the first virtual machine, in the embodiment of the present application, after the data of the target page table is copied to the page table of the main physical memory of the first virtual machine in the manner 3 in the above embodiment 2, the user-mode interface of the user-mode process fork can be further called to adjust the state of the page table of the main physical memory of the first virtual machine to the COW state.

[0109] And because the data of the target page table is completely copied when the user-mode interface of the user-mode process fork is called, the memory data and the handle of the target second virtual machine are completely copied, so the first virtual machine is completely the same as the target second virtual machine and is completely the same as other external interfaces. At this time, multiple virtual machine processes cannot be concurrently run, so a new first virtual machine needs to be initialized, including controlling the first virtual machine to use a new virtual machine disk image file, re-doing a VMM initialization operation, re-creating a socket port for communicating with an external program, and the like.

[0110] Embodiment 6

[0111] In order to realize the normal running of the first virtual machine, on the basis of the above embodiments, in the embodiment of the present application, after the user-mode interface of the user-mode process mmap copies the data of the target page table from the memory sharing and copies the data of the target page table to the page table of the main physical memory of the first virtual machine, the method further comprises:

[0112] calling a user state interface of the user state process mmap, adjusting a state of a page table of the main physical memory of the first virtual machine to a write-time copy COW state.

[0113] In order to realize normal running of the first virtual machine, in the embodiment of the present application, after copying the data of the target page table from the memory sharing and copying the data of the target page table into the page table of the main physical memory of the first virtual machine in the manner 4 in the above-mentioned embodiment 2, the user state interface of the user state process mmap can be further called to adjust the state of the page table of the main physical memory of the first virtual machine to a COW state.

[0114] Embodiment 7:

[0115] On the basis of the above-mentioned embodiments, Figure 6 A structure schematic diagram of a concurrent virtual machine memory space processing device provided by the embodiment of the present application, the device comprises:

[0116] A determining module 601, configured to load a first virtual machine, and determine a target second virtual machine with a same running environment as the first virtual machine according to a running environment of the first virtual machine and a running environment of each loaded second virtual machine.

[0117] A processing module 602, configured to copy data of a target page table of the target second virtual machine into a page table of a main physical memory of the first virtual machine, wherein the main physical memory is a physical memory with the largest memory space in a host physical memory space mapped by a guest physical memory space of a virtual machine.

[0118] Further, the processing module is specifically configured to copy the data of the target page table into a kernel state virtual machine management layer VMM, copy the data of the target page table from the VMM and into the page table of the main physical memory of the first virtual machine; or copy the data of the target page table into a kernel state driver layer, copy the data of the target page table from the driver layer and into the page table of the main physical memory of the first virtual machine; call a user state interface of a user state process fork, copy the data of the target page table in page table data of a process of the target second virtual machine into a page table of a process of the first virtual machine through the user state interface of the user state process fork; or call a user state interface of a user state process mmap, copy the data of the target page table from a memory sharing and into the page table of the main physical memory of the first virtual machine through the user state interface of the user state process mmap, wherein the memory sharing is created when a snapshot file of a first physical page of a target page table identifier of the second virtual machine is pre-loaded.

[0119] Further, the processing module is further configured to, after copying the data of the target page table from the VMM and into the page table of the main physical memory of the first virtual machine, adjust the state of the page table of the main physical memory of the first virtual machine to be in a non-writable state.

[0120] Further, the processing module is further configured to, if an access violation exit event is detected, acquire a physical address corresponding to a violation address of the access violation exit event; determine whether the physical address is identical to a target address of the target physical page; if yes, apply, by the VMM, a second physical page with a same memory space size as the first physical page identified by the target page table identifier in the host physical memory space, copy data of the first physical page into the second physical page, update the identification information of the first physical page recorded in the page table of the main physical memory of the first virtual machine to identification information of the second physical page, and adjust the state of the page table of the main physical memory of the first virtual machine to be in a readable and writable state.

[0121] Further, the processing module is further configured to, after copying the data of the target page table from the driver layer and into the page table of the main physical memory of the first virtual machine, adjust the state of the page table of the main physical memory of the first virtual machine to be in a copy-on-write (COW) state.

[0122] Further, the processing module is further configured to, after copying the data of the target page table from the user state interface of the user state process fork into the page table of the first virtual machine, call the user state interface of the user state process fork to adjust the state of the page table of the main physical memory of the first virtual machine to be in a copy-on-write (COW) state, and perform a system initialization operation on the first virtual machine.

[0123] Further, the processing module is further configured to, after copying the data of the target page table from the memory sharing and into the page table of the main physical memory of the first virtual machine by the user state interface of the user state process mmap, call the user state interface of the user state process mmap to adjust the state of the page table of the main physical memory of the first virtual machine to be in a copy-on-write (COW) state.

[0124] Embodiment 8:

[0125] Figure 7A structural schematic diagram of an electronic device is provided in the embodiment of the present application, and on the basis of the above embodiments, the embodiment of the present application further provides an electronic device, which comprises a processor 701, a communication interface 702, a memory 703 and a communication bus 704, wherein the processor 701, the communication interface 702 and the memory 703 complete mutual communication through the communication bus 704;

[0126] The memory 703 stores a computer program, and when the program is executed by the processor 701, the processor 701 executes the following steps:

[0127] loading and running a first virtual machine, and determining a target second virtual machine with the same running environment as the first virtual machine according to the running environment of the first virtual machine and the running environment of each loaded second virtual machine;

[0128] copying data of the target page table of the target second virtual machine into a page table of a main physical memory of the first virtual machine, wherein the main physical memory is a physical memory with the largest memory space in a host physical memory space mapped by a guest physical memory space of the virtual machine.

[0129] Further, the processor 701 is specifically configured to copy the data of the target page table into the page table of the main physical memory of the first virtual machine, including:

[0130] copying the data of the target page table into a virtual machine management layer (VMM) in a kernel mode, copying the data of the target page table from the VMM and into the page table of the main physical memory of the first virtual machine; or,

[0131] copying the data of the target page table into a driver layer in the kernel mode, copying the data of the target page table from the driver layer and into the page table of the main physical memory of the first virtual machine; or,

[0132] calling a user state interface of a user state process fork, copying the data of the target page table in the page table data of the target second virtual machine process into the page table of the first virtual machine process through the user state interface of the user state process fork; or,

[0133] calling a user state interface of a user state process mmap, copying the data of the target page table from a memory sharing and into the page table of the main physical memory of the first virtual machine through the user state interface of the user state process mmap, wherein the memory sharing is a snapshot file of a first physical page of a target page table identifier of the second virtual machine preloaded.

[0134] Further, the processor 701 is further configured to, after copying the data of the target page table from the VMM and into the page table of the main physical memory of the first virtual machine, the method further comprises:

[0135] adjusting a state of the page table of the main physical memory of the first virtual machine to an unwritable state.

[0136] Further, the processor 701 is further configured to, if detecting an access violation exit event, acquire a physical address corresponding to a violation address of the access violation exit event;

[0137] determining whether the physical address is same as a target address of the target physical page;

[0138] if yes, applying, by the VMM, a second physical page with a same memory space size as the first physical page identified by the target page table identifier in a host physical memory space, copying data of the first physical page into the second physical page, updating identification information of the first physical page recorded in the page table of the main physical memory of the first virtual machine to identification information of the second physical page, and adjusting a state of the page table of the main physical memory of the first virtual machine to a readable and writable state.

[0139] Further, the processor 701 is further configured to, after copying the data of the target page table from the driver layer and into the page table of the main physical memory of the first virtual machine, the method further comprises:

[0140] adjusting a state of the page table of the main physical memory of the first virtual machine to a copy-on-write COW state.

[0141] Further, the processor 701 is further configured to, after copying, by the user state interface of the user state process fork, the data of the target page table in the page table data of the target second virtual machine process into the page table of the first virtual machine process, the method further comprises:

[0142] calling the user state interface of the user state process fork to adjust a state of the page table of the main physical memory of the first virtual machine to a copy-on-write COW state.

[0143] performing a system initialization operation on the first virtual machine.

[0144] Further, the processor 701 is further configured to, after copying, by the user state interface of the user state process mmap, the data of the target page table from the memory sharing and into the page table of the main physical memory of the first virtual machine, the method further comprises:

[0145] A user-mode interface of the user-mode process mmap is called to adjust a state of a page table of a main physical memory of the first virtual machine to a copy-on-write (COW) state.

[0146] The communication bus mentioned in the electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For convenience of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0147] The communication interface 702 is configured to communicate between the electronic device and other devices.

[0148] The memory can include a Random Access Memory (RAM) and can also include a Non-Volatile Memory (NVM), such as at least one disk memory. Optionally, the memory can also be at least one storage device located away from the aforementioned processor.

[0149] The processor can be a general-purpose processor, including a central processing unit, a network processing unit (NP), etc. The processor can also be a Digital Signal Processing (DSP), an application-specific integrated circuit, a field programmable gate array, or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc.

[0150] Embodiment 9:

[0151] On the basis of the above-mentioned embodiments, the embodiment of the present application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to perform the following steps:

[0152] The first virtual machine is loaded and run, and according to the running environment of the first virtual machine and the running environment of each loaded second virtual machine, a target second virtual machine with the same running environment as the first virtual machine is determined.

[0153] According to a target page table of a main physical memory of the target second virtual machine, data of the target page table is copied into a page table of the main physical memory of the first virtual machine, wherein the main physical memory is a host physical memory space in a guest physical memory space mapping of a virtual machine, and the main physical memory is a physical memory with the largest memory space.

[0154] Further, the copying of the data of the target page table into the page table of the main physical memory of the first virtual machine comprises:

[0155] copying the data of the target page table into a kernel-mode virtual machine management layer (VMM), copying the data of the target page table from the VMM and into the page table of the main physical memory of the first virtual machine; or

[0156] copying the data of the target page table into a kernel-mode driver layer, copying the data of the target page table from the driver layer and into the page table of the main physical memory of the first virtual machine; or

[0157] invoking a user-mode interface of a user-mode process fork, copying the data of the target page table in the page table data of the target second virtual machine process into the page table of the first virtual machine process through the user-mode interface of the user-mode process fork; or

[0158] invoking a user-mode interface of a user-mode process mmap, copying the data of the target page table from a memory share and into the page table of the main physical memory of the first virtual machine through the user-mode interface of the user-mode process mmap, wherein the memory share is created when a snapshot file of a first physical page of a target page table identifier of the second virtual machine is pre-loaded.

[0159] Further, after the copying of the data of the target page table from the VMM and into the page table of the main physical memory of the first virtual machine, the method further comprises:

[0160] adjusting the state of the page table of the main physical memory of the first virtual machine to be non-writable.

[0161] Further, the method further comprises:

[0162] if an access violation exit event is detected, obtaining a physical address corresponding to a violation address of the access violation exit event;

[0163] determining whether the physical address is identical to a target address of the target physical page;

[0164] if yes, applying, by the VMM, a second physical page with a same memory space size as the first physical page of the target page table identifier in a host physical memory space, copying data of the first physical page into the second physical page, updating identifier information of the first physical page recorded in the page table of the main physical memory of the first virtual machine to identifier information of the second physical page, and adjusting the state of the page table of the main physical memory of the first virtual machine to be readable and writable.

[0165] Further, after the copying the data of the target page table from the drive layer and into the page table of the main physical memory of the first virtual machine, the method further comprises:

[0166] adjusting the state of the page table of the main physical memory of the first virtual machine to a copy-on-write COW state.

[0167] Further, after the copying the data of the target page table from the drive layer and into the page table of the main physical memory of the first virtual machine, the method further comprises:

[0168] calling the user-mode interface of the user-mode process mmap to adjust the state of the page table of the main physical memory of the first virtual machine to a copy-on-write COW state.

[0169] performing a system initialization operation on the first virtual machine.

[0170] Further, after the copying the data of the target page table from the drive layer and into the page table of the main physical memory of the first virtual machine, the method further comprises:

[0171] calling the user-mode interface of the user-mode process mmap to adjust the state of the page table of the main physical memory of the first virtual machine to a copy-on-write COW state.

[0172] Those skilled in the art will understand that embodiments of the present application can be provided as methods, systems, or computer program products. Thus, the present application can be embodied in a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can be embodied in a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk memory, CD-ROM, optical memory, etc.) having computer usable program code embodied thereon.

[0173] The present application is described in terms of flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to the present application. It will be understood that each flow and / or block of the flowcharts and / or block diagrams, and combinations of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processing machine, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions / acts specified in the flowcharts and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1means for performing the function specified by the block or blocks.

[0174] These computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture including instructions which implement the flow Figure 1 flow or flows and / or blocks Figure 1 means for performing the function specified by the block or blocks.

[0175] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the flow Figure 1 flow or flows and / or blocks Figure 1 means for performing the function specified by the block or blocks.

[0176] Obviously, numerous modifications and variations of the present application are possible in light of the above teachings. It is therefore to be understood that within the scope of the appended claims and their equivalents, the application can be practiced otherwise than as specifically described.

Claims

1. A method for processing concurrent virtual machine memory space, characterized in that, The method includes: Load and run the first virtual machine, and determine the target second virtual machine with the same running environment as the first virtual machine based on the running environment of the first virtual machine and the running environment of each loaded second virtual machine; According to the target page table of the main physical memory of the target second virtual machine, the data of the target page table is copied to the page table of the main physical memory of the first virtual machine, wherein the main physical memory is the physical memory with the largest memory space in the host physical memory space mapped from the virtual machine's guest physical memory space; The step of copying the data of the target page table to the page table in the main physical memory of the first virtual machine includes: The user-mode interface of the user-mode process mmap is invoked to copy the data of the target page table from the shared memory and copy the data of the target page table to the page table of the main physical memory of the first virtual machine. The shared memory is created when a snapshot file of the first physical page identified by the target page table of the second virtual machine is preloaded. The user-mode interface is the interface of the first virtual machine.

2. The method according to claim 1, characterized in that, After copying the data of the target page table from shared memory through the user-space interface of the user-space process mmap, and copying the data of the target page table to the page table of the main physical memory of the first virtual machine, the method further includes: The user-space interface of the user-space process mmap is invoked to adjust the state of the page table in the main physical memory of the first virtual machine to the copy-on-write (COW) state.

3. A concurrent virtual machine memory space processing device, characterized in that, The device includes: The determination module is used to load and run the first virtual machine, and determine the target second virtual machine with the same running environment as the first virtual machine based on the running environment of the first virtual machine and the running environment of each loaded second virtual machine; The processing module is configured to copy data from the target page table to the page table of the main physical memory of the first virtual machine, based on the target page table of the main physical memory of the second virtual machine. The main physical memory is the largest physical memory in the host physical memory space mapped from the virtual machine's guest physical memory space. Copying the data from the target page table to the page table of the first virtual machine's main physical memory includes: calling the user-mode interface of the user-mode process mmap, copying the data from the target page table from a shared memory location through the mmap user-mode interface, and copying the data from the target page table to the page table of the first virtual machine's main physical memory. The shared memory location is created when a snapshot file of the first physical page identified by the target page table of the second virtual machine is pre-loaded. The user-mode interface is an interface of the first virtual machine.

4. An electronic device, characterized in that, include: The processor, communication interface, memory, and communication bus are connected, with the processor, communication interface, and memory communicating with each other via the communication bus. The memory stores a computer program that, when executed by the processor, causes the processor to perform the method according to any one of claims 1-2.

5. A computer-readable storage medium, characterized in that, It stores a computer program executable by a processor, which, when run on the processor, causes the processor to perform the method according to any one of claims 1-2.

Citation Information

Patent Citations

  • KVM-oriented virtualization layer fault injection method

    CN109857522A

  • Method and device for sharing kernel memory by virtual machines

    CN111190752A