Virtual machine memory handling methods, devices, products, virtualization servers and media

By setting corresponding modules in the virtual machine monitor and operating system kernel, the virtual machine memory is dynamically locked, which solves the problem of memory resource waste in PCI device passthrough scenarios and improves memory utilization and migration efficiency.

CN120872507BActive Publication Date: 2026-01-30JINAN INSPUR DATA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511405528.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-29
Publication Date
2026-01-30
Estimated Expiration
2045-09-29

AI Technical Summary

Technical Problem

In PCI device passthrough scenarios, virtual machine memory is locked by the hypervisor layer, resulting in wasted memory resources and a large amount of data migration, making it difficult to manage effectively.

Method used

By setting up a virtual input/output backend module in the virtual machine monitor and a virtual input/output frontend module in the virtual machine operating system kernel, memory allocation events of direct memory access can be detected, and virtual machine memory can be dynamically locked, locking only the necessary memory and reducing resource waste.

Benefits of technology

It improved memory utilization, reduced resource waste and data migration, and optimized memory management efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120872507B_ABST
    Figure CN120872507B_ABST
Patent Text Reader

Abstract

This invention discloses a virtual machine memory processing method, apparatus, product, virtualization server, and medium, relating to the field of server virtualization. In this method, a virtual input / output backend module set on the virtual machine monitor in the host and a virtual input / output frontend module on the virtual machine ensure that the virtual input / output backend module can obtain information about direct memory access memory allocation events. Secondly, after obtaining the information about direct memory access memory allocation events, the virtual input / output backend module locks the addresses involved in the memory allocation events, meaning the locked addresses satisfy the direct memory access requirements. This dynamic locking of virtual machine memory improves memory utilization and reduces resource waste. Furthermore, since only a portion of the virtual machine memory is locked, when the host is replaced, only the locked memory portion needs to be migrated, reducing the amount of data to be migrated after a host replacement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of server virtualization, and in particular to a virtual machine memory processing method, apparatus, product, virtualization server, and medium. Background Technology

[0002] Passthrough technology for devices that conform to the Peripheral Component Interconnect Express (PCIE) standard (PCI devices) is a key technology in the field of virtualization.

[0003] Because host-side memory pages are managed and scheduled by the hypervisor layer's memory manager, virtual machine memory pages may be moved or swapped out. If virtual machine memory is not locked, Direct Memory Access (DMA) transfers by PCI device drivers within the virtual machine will encounter problems. Furthermore, since PCI device passthrough technology allows virtual machines to bypass the hypervisor layer and directly access physical PCI devices, the hypervisor layer is unaware of the virtual machine memory used for DMA data transfers. Therefore, during relevant PCI device passthrough accesses, the hypervisor layer will lock (pin) all virtual machine memory, preventing the hypervisor layer from scheduling it and resulting in wasted memory resources.

[0004] Therefore, while satisfying DMA data transfer requirements, how to reduce the size of memory locked in PCI device passthrough scenarios and improve the memory management efficiency of the hypervisor layer is a technical problem that urgently needs to be solved by those in this field. Summary of the Invention

[0005] The purpose of this invention is to provide a virtual machine memory processing method, apparatus, product, virtualization server, and medium to solve the problem that in related PCI device pass-through access, the hypervisor layer locks all virtual machine memory, and all locked memory cannot be scheduled by the hypervisor layer, resulting in a waste of memory resources.

[0006] To address the aforementioned technical problems, this invention provides a virtual machine memory processing method applied to a virtual input / output backend module in a virtual machine monitor, wherein the virtual machine monitor is located in the host machine, and the method includes:

[0007] Obtain information representing memory allocation events that constitute direct memory access; wherein, the memory allocation events are detected by the virtual input / output front-end module deployed on the virtual machine operating system kernel;

[0008] The target physical address of the virtual machine to be used by direct memory access is determined based on the information from the memory allocation event.

[0009] Obtain the host target address corresponding to the virtual machine's target physical address;

[0010] Lock the host target address to lock the memory corresponding to the target physical address of the virtual machine.

[0011] On the one hand, the virtual input / output front-end module detects memory allocation events for direct memory access, including:

[0012] Obtain tools for characterizing and tracing kernel behavior;

[0013] The tool is used to monitor the memory allocation interface for direct memory access and to obtain the first monitoring result;

[0014] The memory allocation event for direct memory access is determined based on the first monitoring result.

[0015] On the other hand, the process of using the tool to monitor the memory allocation interface for direct memory access and obtaining the first monitoring result includes:

[0016] After a call operation occurs at the memory allocation interface, the input parameters at the memory allocation interface are obtained by the first probe deployed at the function entry point of the memory allocation interface; wherein, the input parameters include at least the requested memory size, memory address alignment requirements, and device-related constraint information required for direct memory access transfer;

[0017] The return value and output parameters captured by the second probe at the memory allocation interface are obtained, wherein the output parameters include the starting physical address of the memory for the actual allocated direct memory access and the actual length of the allocated memory; the second probe is deployed at the location where the memory allocation interface has completed execution and returned;

[0018] The input parameters, the return value, and the output parameters are used as the first monitoring result;

[0019] The determination of direct memory access memory allocation events based on the first monitoring result includes:

[0020] The captured input parameters, return values, and output parameters are associated, and a correspondence is established between memory allocation request information and actual allocation results.

[0021] A direct memory access memory allocation event is generated based on the correspondence; wherein the information of the direct memory access memory allocation event includes at least the physical address and length of the allocated memory.

[0022] On the other hand, after the virtual input / output front-end module detects a memory allocation event for direct memory access, it also includes:

[0023] A request message is created based on the information from the memory allocation event of the direct memory access;

[0024] The request message is placed into a shared memory queue;

[0025] The information obtained to characterize memory allocation events for direct memory access includes:

[0026] Retrieve request messages from the shared memory queue to obtain information characterizing memory allocation events that represent direct memory access.

[0027] On the other hand, obtaining the host target address corresponding to the target physical address of the virtual machine includes:

[0028] Obtain the address mapping relationship between the pre-established physical address of the virtual machine and the virtual address of the host;

[0029] Based on the address mapping relationship, determine the host target virtual address corresponding to the virtual machine's target physical address;

[0030] Locking the host target address includes locking the host target virtual address.

[0031] On the other hand, locking the host target address includes:

[0032] Obtain a function to characterize the target address of the locked host; wherein the parameters of the function include at least the target address parameter of the host, the target physical address of the virtual machine and the address length parameter, and a parameter for a flag characterizing the locked memory;

[0033] The host target address, the virtual machine target physical address and address length, as well as the flag used to represent locked memory, are input into the function used to represent locked host target address;

[0034] In the function used to characterize the target address of the locked host, the memory range of the virtual machine to be operated is determined according to the target physical address and address length of the virtual machine;

[0035] If the host-side address corresponding to the virtual machine memory range is detected to be completely matched with the host target address, or is contained in the host target address, the target physical page located from the host target address is determined to be the memory page actually used by the virtual machine when performing direct memory access operations;

[0036] The corresponding target physical page is located from the host target address, and a locking operation is performed on the target physical page according to the flag used to characterize the locked memory, so as to lock the host target address.

[0037] On the other hand, after locating the corresponding target physical page from the host target address, and before performing the locking operation on the target physical page according to the flag used to characterize the locked memory, the method further includes:

[0038] Obtain the initial reference count value of the target physical page;

[0039] Update the initial reference count value to the new reference count value;

[0040] If the new reference count value is detected to be greater than the initial reference count value, proceed to the step of performing a locking operation on the target physical page according to the flag used to characterize the locked memory.

[0041] On the other hand, after performing a locking operation on the target physical page according to the flag used to characterize the locked memory, the method further includes:

[0042] Obtain the memory address range and corresponding memory page identifier submitted when the virtual machine initiates a direct memory access operation, and record the memory address range and corresponding memory page identifier as the target locking range;

[0043] Call the host operating system's memory management interface to query the current locking status and locking range parameters of the memory page corresponding to the memory page identifier, in order to determine the actual locking range;

[0044] If the target locking range and the actual locking range meet the preset requirements, the object of the locking operation is determined to be the target physical page; wherein, the preset requirements are that the memory address start value, end value and the number of memory pages covered in the target locking range are consistent with the memory address start value, end value and the number of memory pages covered in the actual locking range.

[0045] On the other hand, after determining the actual locking range, it also includes:

[0046] Obtain the difference between the actual locking range and the target locking range;

[0047] If the difference is detected to be greater than 0, acquire the additional locked physical page; trigger the unlocking mechanism to release the additional locked physical page; wherein, the additional locked physical page is a physical page that exists in the actual locking range but does not exist in the target locking range;

[0048] If the difference is detected to be less than 0, the step of obtaining information representing the memory allocation event of direct memory access is returned.

[0049] On the other hand, after performing a locking operation on the target physical page according to the flag used to characterize the locked memory, the method further includes:

[0050] Obtain the access records of the target physical page;

[0051] If, after a preset time period, the target physical page is detected to be in a locked state, and if no access record is found on the target physical page, the state of the target physical page will be changed from locked to released.

[0052] On the other hand, after changing the state of the target physical page from locked to released, the process also includes:

[0053] Obtain the pre-defined priority order of virtual machines; wherein the priority order of virtual machines is determined at least by the service type and user configuration weight of the virtual machines;

[0054] The memory space after the target physical page is released is allocated to the virtual machine according to the virtual machine's priority order.

[0055] On the other hand, after performing a locking operation on the target physical page according to the flag used to characterize the locked memory, the method further includes:

[0056] Acquire data of the target physical page migrated from the target host; wherein the target host is a host that has locked the target physical page;

[0057] Write the data of the migrated target physical page into a locally allocated memory area;

[0058] Receive direct memory access requests sent by the virtual machine;

[0059] Based on the established mapping relationship between the memory region and the virtual machine address space, the virtual machine physical address in the direct memory access request is converted into the host physical address;

[0060] Data is transferred based on the translated host physical address in response to the direct memory access request.

[0061] On the other hand, the physical address of the virtual machine is obtained by converting the host physical address to the host virtual address, and then converting the host virtual address again.

[0062] On the other hand, it also includes:

[0063] The virtual input / output front-end module uses tools to monitor the memory release interface of direct memory access and obtains a second monitoring result;

[0064] The memory release event for direct memory access is determined based on the second monitoring result;

[0065] Based on the information from the memory release event, the host target address that is in a locked state is released.

[0066] On the other hand, before using the aforementioned tool to monitor the memory allocation interface for direct memory access, the following is also included:

[0067] Obtain the type of direct memory access and determine the target memory allocation interface based on the type of direct memory access; wherein, the type of direct memory access includes the type of consistent direct memory access and the type of streaming direct memory access;

[0068] Monitoring the memory allocation interface for direct memory access using the aforementioned tool includes:

[0069] Use the aforementioned tool to monitor the target memory allocation interface corresponding to direct memory access;

[0070] Before the virtual input / output front-end module uses tools to monitor the memory release interface of direct memory access, it also includes:

[0071] Obtain the type of direct memory access and determine the target memory release interface based on the type of direct memory access;

[0072] The virtual input / output front-end module uses tools to monitor memory release interfaces that are directly accessed by memory, including:

[0073] The virtual input / output front-end module uses tools to monitor the target memory release interface for direct memory access.

[0074] To address the aforementioned technical problems, the present invention also provides a virtual machine memory processing method, applied to a virtual input / output front-end module in a virtual machine, the method comprising:

[0075] Obtain information about memory allocation events for direct memory access;

[0076] The information of the memory allocation event is sent to the virtual input / output backend module in the virtual machine monitor, so that the virtual input / output backend module in the virtual machine monitor can determine the target physical address of the virtual machine to be used by direct memory access based on the information of the memory allocation event; obtain the host target address corresponding to the target physical address of the virtual machine; lock the host target address to lock the memory corresponding to the target physical address of the virtual machine; wherein, the virtual machine monitor is located in the host.

[0077] To address the aforementioned technical problems, the present invention also provides a virtual machine memory processing apparatus, comprising:

[0078] The first acquisition module is used to acquire information representing memory allocation events that represent direct memory access; wherein, the memory allocation events are detected by the virtual input / output front-end module deployed on the virtual machine operating system kernel;

[0079] The determination module is used to determine the target physical address of the virtual machine to be used by direct memory access based on the information of the memory allocation event.

[0080] The second acquisition module is used to acquire the host target address corresponding to the target physical address of the virtual machine;

[0081] The locking module is used to lock the host target address in order to lock the memory corresponding to the target physical address of the virtual machine.

[0082] To address the aforementioned technical problems, the present invention also provides a computer program product, comprising a computer program that, when executed by a processor, implements the steps of the aforementioned virtual machine memory processing method.

[0083] To address the aforementioned technical problems, the present invention also provides a virtualization server, comprising:

[0084] Memory, used to store computer programs;

[0085] A processor is used to implement the steps of the virtual machine memory processing method described above when executing the computer program.

[0086] To address the aforementioned technical problems, the present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the virtual machine memory processing method described above.

[0087] The beneficial effects of this invention are as follows: First, a virtual input / output backend module is set on the virtual machine monitor located in the host, and a virtual input / output frontend module is set in the operating system kernel of the virtual machine. The virtual input / output frontend module detects memory allocation events for direct memory access, and the virtual input / output backend module on the virtual machine monitor obtains the information of the memory allocation events for direct memory access detected by the virtual input / output frontend module. Compared to previous PCI passthrough technology, where communication between the virtual machine and the host bypassed the virtual machine monitor layer (meaning the virtual machine monitor could not obtain memory allocation events), this invention utilizes a virtual input / output backend module on the virtual machine monitor in the host and a virtual input / output frontend module on the virtual machine. This ensures that the virtual input / output backend module on the virtual machine monitor can obtain information about memory allocation events detected by the virtual input / output frontend module for direct memory access. Furthermore, after obtaining information about direct memory access memory allocation events, the virtual input / output backend module in the virtual machine monitor locks the addresses involved in the memory allocation events. This means the locked addresses satisfy the direct memory access requirements, and the locking of addresses is based on memory allocation events, meaning the locked addresses will differ for each memory allocation event. Therefore, this invention provides a method for dynamically locking virtual machine memory based on memory allocation events. Compared to locking all virtual machine memory, the method provided in this invention does not lock all virtual machine memory. Therefore, unused memory can still be used by other virtual machines, improving memory utilization and reducing resource waste. Furthermore, when locking the target physical address of the virtual machine to be used for direct memory access, the host target address corresponding to the virtual machine's target physical address is first obtained; then, the host target address is locked. By locking the host target memory, what the virtual machine sees is only the memory corresponding to its own target physical address being locked, thus achieving memory locking corresponding to the virtual machine's target physical address. Additionally, the method provided in this invention only locks a portion of the virtual machine's memory. When the host is replaced, only the locked memory portion needs to be migrated, reducing the amount of data to be migrated after a host replacement.

[0088] In addition, the virtual input / output front-end module utilizes tools for characterizing and tracing kernel behavior to monitor the memory allocation interface through the capture results of the first probe and the capture results of the second probe, enabling accurate capture of memory allocation events.

[0089] Based on the information transmission method of shared memory queues, information can be quickly transmitted to the virtual input / output backend module on the host side without going through a complex network protocol stack or external storage relay, ensuring that the virtual input / output backend module can quickly obtain information about memory allocation events.

[0090] During the process of locking the host target address, a function is called with parameters including the host target address, the virtual machine's target physical address and address length, and a flag representing the locked memory. This process locks the physical page corresponding to the host target address. Furthermore, based on the virtual machine's target physical address and address length, the range of virtual machine memory to be operated on is determined. The determined range of virtual machine memory to be operated on is then matched with the host target address, and the containment relationship is verified, ensuring the accuracy of the locked memory page. Finally, the reference count value of the physical page further guarantees the accuracy of the locked memory page.

[0091] After performing a locking operation on the target physical page based on the flags used to characterize the locked memory, the system obtains the target locking range when the virtual machine initiated the direct memory access operation and the actual locking range queried by the host operating system. When the target locking range matches the actual locking range, the object of the locking operation is determined to be the target physical page, thus verifying the correctness of the locked target physical page. If more physical pages are determined to be locked, the additional locked physical pages are released, allowing them to still be used and improving memory resource utilization. If fewer physical pages are determined to be locked, the system returns to the step of obtaining information on the memory allocation event characterizing direct memory access, re-determines the locked memory portion, and ensures that the locked memory can meet the needs of direct memory access.

[0092] If no access record is found for the target physical page within a preset time period after the target physical page is detected to be locked, the state of the target physical page will be changed from locked to released, so that the released physical page can still be used, thereby improving the utilization of memory resources.

[0093] Migrating only the target physical pages (i.e., the locked physical pages) on the target host reduces the amount of data to be migrated compared to migrating all physical pages.

[0094] In addition, the present invention also provides a virtual machine memory processing method, a virtual machine memory processing device, a computer program product, a virtualization server, and a computer-readable storage medium for use in a virtual input / output front-end module in a virtual machine, which have the same or corresponding technical features as the virtual machine memory processing method for use in a virtual machine monitor back-end module mentioned above, and have the same effects. Attached Figure Description

[0095] To more clearly illustrate the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0096] Figure 1 A schematic diagram of a related PCI device pass-through technology provided in an embodiment of the present invention;

[0097] Figure 2 A flowchart illustrating a virtual machine memory processing method provided in an embodiment of the present invention;

[0098] Figure 3 A schematic diagram illustrating the optimization scheme for virtualized PCI device pass-through memory usage provided in an embodiment of the present invention;

[0099] Figure 4 A schematic diagram of an address translation relationship provided in an embodiment of the present invention;

[0100] Figure 5 This is a structural diagram of a virtualization server provided in an embodiment of the present invention. Detailed Implementation

[0101] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of the present invention.

[0102] The core of this invention is to provide a virtual machine memory processing method, apparatus, product, virtualization server, and medium to solve the problem that in related PCI device pass-through access, the hypervisor layer locks all virtual machine memory, and all locked memory can no longer be scheduled by the hypervisor layer, resulting in a waste of memory resources.

[0103] PCI device passthrough is a key technology in the field of virtualization. Figure 1 This is a schematic diagram illustrating a related PCI device pass-through technology provided in an embodiment of the present invention. For example... Figure 1 As shown, it includes Virtual Machine 1 and Host 2. Virtual Machine 1 includes a Guest Operating System (Guest OS) and device drivers (i.e., PCI physical drivers) that conform to the Peripheral Component Interconnect (PCI) standard. Host 2 includes the virtual machine monitor layer and hardware (such as physical devices). Figure 1The left side of the diagram utilizes PCI device passthrough, allowing virtual machines (VMs) to directly access physical PCI devices, bypassing the VM monitor layer's translation process. This enables VM access to devices with performance approaching native host access. PCI device passthrough works by mapping PCI devices directly to the VM's Guest Physical Address (GPA) via the Input / Output Memory Management Unit (IOMMU). The VM's operating system's device drivers can directly interact with the PCI devices, eliminating virtualization overhead. The VM can utilize the full functionality of the PCI device and enjoys better compatibility. Based on these advantages, PCI device passthrough is widely used in server virtualization. Common physical devices used for PCI device passthrough include Graphics Processing Unit (GPU) graphics cards, network interface cards (NICs), Host Bus Adapter (HBA) cards, and Field-Programmable Gate Array (FPGA) accelerator cards. Figure 1 The right side shows how the virtual machine (Guest OS) interacts with the host (physical device) through the virtual machine driver (Guest driver (virtio)), the emulated device, and the PCI physical driver, which conforms to the high-speed interconnection standard for peripheral components.

[0104] However, in PCI device passthrough technology, pinning virtual machine memory is a key technology to ensure the stability and performance of passthrough devices, because PCI devices rely on Direct Memory Access (DMA) to directly read and write memory, bypassing the CPU. The virtual machine driver requests a memory buffer within the virtual machine's memory. The device driver initiates a DMA request based on the physical address (Guest Physical Address, GPA) of the memory buffer. The IOMMU translates the GPA into the hypervisor physical address (Host Physical Address, HPA) to complete the data transfer. Since virtual machine memory is dynamically allocated in the hypervisor and subject to scheduling by the memory management layer (e.g., swapping, load balancing, memory reclamation), physical memory page changes occur, necessitating the pinning of virtual machine memory. For PCI device passthrough scenarios, because the hypervisor cannot access the portion of the virtual machine's memory that might be used for DMA data transfer, a pinning strategy is employed for all virtual machine memory. For example, if a virtual machine with 16GB of memory is created and PCI device passthrough is configured, then all 16GB of memory will be pinned. Before the virtual machine is shut down, the hypervisor cannot reclaim or allocate this part of the memory again, resulting in reduced memory utilization efficiency.

[0105] As can be seen, in the relevant PCI device passthrough technology, all memory of the passthrough virtual machine needs to be pinned at the hypervisor layer and can no longer be managed and scheduled, resulting in a waste of memory resources. In addition, when the host is replaced (such as when the host fails), a large amount of memory needs to be migrated.

[0106] Therefore, this embodiment of the invention provides a virtual machine memory processing method to reduce memory resource waste and minimize the amount of memory migrated when the host is replaced. To enable those skilled in the art to better understand the present invention, the invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. The virtual machine memory processing method provided in this embodiment is applied to the virtual input / output backend module in a virtual machine monitor. The virtual machine monitor is located in the host. Figure 2 A flowchart of a virtual machine memory processing method provided in an embodiment of the present invention is shown below. Figure 2 As shown, the method includes:

[0107] S10: Obtain information representing memory allocation events that represent direct memory access; wherein, the memory allocation events are detected by the virtual input / output front-end module deployed on the virtual machine operating system kernel;

[0108] S11: Determine the target physical address of the virtual machine to be used by direct memory access based on the information from the memory allocation event;

[0109] S12: Obtain the host target address corresponding to the target physical address of the virtual machine;

[0110] S13: Lock the host target address to lock the memory corresponding to the target physical address of the virtual machine.

[0111] It is worth noting that in the relevant PCI device passthrough technology, communication between the virtual machine and the host bypasses the virtual machine monitor layer. That is, the virtual machine monitor layer in this PCI device passthrough technology cannot detect direct memory access events (such as memory allocation or deallocation events). To enable the virtual machine monitor layer to obtain direct memory access events, in this embodiment of the invention, a virtual input / output backend module is configured on the virtual machine monitor in the host, and a virtual input / output frontend module is configured on the virtual machine. This is a prerequisite for ensuring that the virtual input / output backend module on the virtual machine monitor can obtain information about memory allocation events detected by the virtual input / output frontend module. Figure 3 This is a schematic diagram illustrating the optimized scheme for virtualized PCI device pass-through memory usage provided in an embodiment of the present invention. Figure 3 The diagram illustrates the virtual machine's userspace, kernel, and physical address (GPA); the host includes the virtual machine monitor and host physical address (HPA). The kernel deploys the virtual input / output frontend, and the virtual machine monitor deploys the virtual input / output backend. The memory also includes device drivers compliant with the High Speed ​​Peripheral Component Interconnect (HSPIT) standard.

[0112] In implementation, the virtual input / output front-end module detects memory allocation events for direct memory access, including:

[0113] Obtain tools for characterizing and tracing kernel behavior;

[0114] Use tools to monitor the memory allocation interface for direct memory access and obtain the initial monitoring results;

[0115] The memory allocation events for direct memory access are determined based on the first monitoring results.

[0116] For example, the tool used to characterize and trace kernel behavior is the kprobe tracing tool. Before using tools to monitor the memory allocation interface for direct memory access, the following is also included:

[0117] Obtain the type of direct memory access and determine the target memory allocation interface based on the type of direct memory access; the types of direct memory access include consistent direct memory access and streaming direct memory access.

[0118] Tools for monitoring memory allocation interfaces that directly access memory include:

[0119] Use tools to monitor the target memory allocation interface corresponding to direct memory access.

[0120] Table 1 lists the main interfaces related to Linux kernel DMA memory allocation. As shown in Table 1, different types of direct memory access correspond to different allocation and deallocation interfaces. Direct memory access types include consistent direct memory access (CMDMA) and streaming direct memory access (DMDMA). The allocation interface for CMDMA is pci_alloc_consistent, while the allocation interfaces for streaming DMA are pci_map_single and pci_map_sg. The deallocation interface for CMDMA is pci_free_consistent, while the deallocation interfaces for streaming DMA are pci_unmap_single and pci_unmap_sg.

[0121] Table 1. Contents of the main interfaces related to Linux kernel DMA memory allocation

[0122] .

[0123] Consistent DMA is memory accessed by both the CPU and PCI devices simultaneously, while streaming DMA is temporary memory accessed only by the DMA device. In PCI device passthrough scenarios, the memory used by both types of DMA needs to be pinned on the hypervisor side. By capturing the calls to these kernel functions, it is possible to determine the memory used for DMA, as well as the timing of its allocation and deallocation.

[0124] To accurately capture memory allocation events, in practice, tools are used to monitor the memory allocation interface for direct memory access, and the initial monitoring results include:

[0125] After a call operation occurs at the memory allocation interface, the input parameters at the memory allocation interface are obtained by the first probe deployed at the function entry point of the memory allocation interface; wherein, the input parameters include at least the requested memory size, memory address alignment requirements, and device-related constraint information required for direct memory access transmission;

[0126] The return value and output parameters of the memory allocation interface captured by the second probe are obtained. The output parameters include the starting physical address of the memory to be allocated for direct memory access and the actual length of the allocated memory. The second probe is deployed at the location where the memory allocation interface has completed execution and returned.

[0127] Input parameters, return values, and output parameters are used as the first monitoring results.

[0128] Based on the first monitoring results, the memory allocation events for direct memory access include:

[0129] The captured input parameters, return values, and output parameters are associated, and a correspondence is established between memory allocation request information and actual allocation results.

[0130] Memory allocation events for direct memory access are generated based on the correspondence; the information of the memory allocation events for direct memory access includes at least the physical address and length of the allocated memory.

[0131] By introducing the kernel's kprobe mechanism to trace the execution of these functions, kprobe allows users to embed "probes" along the execution path of specified kernel functions without modifying the kernel source code. This enables the tracking of the execution, return, input parameters, and return values ​​of any function. Using this mechanism, DMA memory allocation and deallocation interfaces can be captured, enabling dynamic tracking of DMA memory events.

[0132] In addition, the virtual input / output front-end module (i.e., the virtio-pin driver front-end module) calls the above tracing function to support synchronizing the virtual machine's DMA memory events to the hypervisor layer.

[0133] The Virtual Input / Output Front End (VIOF) module is a kernel module that needs to be loaded into the guest OS. This module primarily implements kprobe registration for key DMA interface functions and performs tracing. The main tracing information includes: whether memory is being allocated or freed, and the GPA address and length of the allocated memory.

[0134] After the virtual input / output front-end module detects a direct memory access memory allocation event, in order to improve the efficiency of the virtual input / output back-end module in obtaining direct memory access memory allocation event information, in implementation, the virtual input / output front-end module, after detecting a direct memory access memory allocation event, also includes:

[0135] Create request messages based on information about memory allocation events from direct memory access events;

[0136] The request message is placed into a shared memory queue.

[0137] Information obtained representing memory allocation events that are direct memory accesses includes:

[0138] Retrieve request messages from the shared memory queue to obtain information representing memory allocation events that represent direct memory access.

[0139] In this embodiment, based on the virtio framework, a standard semi-virtualized device framework, efficient communication between the virtual machine and the host is achieved through virtual input / output front-end modules, virtual input / output back-end modules, and a shared memory queue (virtqueue). Furthermore, virtio is easily extensible and can be used not only for device emulation but also, in this embodiment, as a communication framework between the virtual machine and the host. The virtual input / output front-end and virtual input / output back-end modules are specifically designed for DMA memory event message synchronization between the virtual machine and the host.

[0140] In this embodiment of the invention, a virtual input / output backend module (i.e., virio-pin backend) is set up on the virtual machine monitor in the host, which is responsible for authorizing DMA memory access events from virtqueue, parsing the events, and performing pin / unpin operations on the corresponding memory.

[0141] Since the memory addresses contained in DMA memory events are GPA addresses, the hypervisor needs to perform address translation. To lock a portion of the virtual machine's memory addresses, after determining the target physical address of the virtual machine to be used by direct memory access based on the memory allocation event information, the host target address corresponding to the virtual machine's target physical address is obtained, including:

[0142] Obtain the address mapping relationship between the pre-established physical address of the virtual machine and the virtual address of the host;

[0143] Determine the target virtual address of the host corresponding to the target physical address of the virtual machine based on the address mapping relationship;

[0144] Locking the host target address includes locking the host target virtual address.

[0145] Figure 4 This is a schematic diagram illustrating an address translation relationship provided in an embodiment of the present invention. Figure 4 As shown, the virtual machine's physical address (GPA) is obtained by converting the host physical address (HPA) to the host virtual address (HVA), and then converting the host virtual address to the virtual address.

[0146] In this method, when locking the target physical address of the virtual machine to be used for direct memory access, the host target address corresponding to the virtual machine's target physical address is first obtained; then the host target address is locked. By locking the host target memory, what the virtual machine sees is that the memory corresponding to the virtual machine's own target physical address is locked, thus achieving the locking of the memory corresponding to the virtual machine's target physical address.

[0147] To ensure the accuracy of the locked memory pages, in some embodiments, locking the host target address includes:

[0148] Obtain a function that represents the target address of the locked host; wherein the parameters of the function include at least the target address of the host, the target physical address of the virtual machine and the address length, and a parameter representing the flags used to represent the locked memory;

[0149] Input the host target address, the virtual machine target physical address and address length, as well as the flags used to represent locked memory, into the function used to represent the host target address;

[0150] In the function used to characterize the target address of the locked host, the memory range of the virtual machine to be operated on is determined based on the target physical address and address length of the virtual machine;

[0151] If the host-side address corresponding to the virtual machine memory range is found to be completely matched with the host target address, or is contained in the host target address, the target physical page located from the host target address is determined to be the memory page actually used by the virtual machine when performing direct memory access operations;

[0152] Locate the corresponding target physical page from the host target address, and perform a locking operation on the target physical page according to the flags used to identify the locked memory, so as to lock the host target address.

[0153] In addition, after locating the corresponding target physical page from the host target address, and before performing a locking operation on the target physical page based on the flags used to characterize the locked memory, the following steps are also included:

[0154] Get the initial reference count value of the target physical page;

[0155] Update the initial reference count value to the new reference count value;

[0156] If a new reference count value is detected that is greater than the initial reference count value, the process proceeds to the step of performing a locking operation on the target physical page based on the flags used to characterize the locked memory.

[0157] The hypervisor queries virtualization memory management information to translate the GPA into the HVA address of the hypervisor process. Linux provides the `guest_user_pages` family of functions to retrieve the corresponding physical page from the user-space address space (HVA) address and increment the reference count to prevent memory swapping out. The `guest_user_pages` family of functions are as follows:

[0158] int get_user_pages(unsigned long start,int nr_pages, unsigned intgup_flags.

[0159] Simultaneously, passing the PG_mlocked flag to gup_flags enables pinning of memory pages, preventing the kernel memory management mechanism from moving memory pages. The virio-pin backend implements pinning of DMA memory pages through the above interface.

[0160] By introducing virtio-pin, virtual machines can be created without pinning all memory in PCI device pass-through scenarios, enabling dynamic memory pin support and thus significantly optimizing memory usage efficiency.

[0161] In practice, page locking errors may occur. Therefore, in this embodiment, after locking the memory page, the accuracy of the locked memory page is further verified. Specifically, after performing the locking operation on the target physical page based on the flag used to characterize the locked memory, the method further includes:

[0162] Obtain the memory address range and corresponding memory page identifier submitted when the virtual machine initiates a direct memory access operation, and record the memory address range and corresponding memory page identifier as the target locking range;

[0163] Call the host operating system's memory management interface to query the current locking status and locking range parameters of the memory page corresponding to the memory page identifier, in order to determine the actual locking range;

[0164] If the target locking range and the actual locking range meet the preset requirements, the object of the locking operation is determined to be the target physical page; wherein, the preset requirements are that the starting value, ending value and number of memory pages covered in the target locking range are consistent with the starting value, ending value and number of memory pages covered in the actual locking range.

[0165] After determining the actual locked area, the following is also included:

[0166] Obtain the difference between the actual locked range and the target locked range;

[0167] If the difference is greater than 0, acquire the additional locked physical page; trigger the unlocking mechanism to release the additional locked physical page; wherein, the additional locked physical page is a physical page that exists in the actual locked range but does not exist in the target locked range;

[0168] If the difference is detected to be less than 0, return to the step of obtaining information representing the memory allocation event of direct memory access.

[0169] In the method provided in this embodiment, after performing a locking operation on the target physical page according to the flag used to characterize the locked memory, the target locking range when the virtual machine initiates the direct memory access operation and the actual locking range queried by the host operating system are obtained. When the target locking range is detected to be consistent with the actual locking range, the object of the locking operation is determined to be the target physical page, thus verifying the correctness of the locked target physical page. When it is determined that there are many locked physical pages, the additional locked physical pages are released, so that the released physical pages can still be used, improving the utilization of memory resources. When it is determined that there are few locked physical pages, the step of obtaining the information of the memory allocation event characterizing the direct memory access is returned, and the locked memory portion is re-determined, ensuring that the locked memory can meet the requirements of direct memory access.

[0170] In practice, some memory pages may be locked but not accessed, resulting in a waste of memory resources. Therefore, in some embodiments, after performing a locking operation on the target physical page based on the flag used to characterize the locked memory, the process further includes:

[0171] Retrieve the access records of the target physical page;

[0172] Once the target physical page is detected to be locked, if no access record is found on the target physical page within a preset time period, the state of the target physical page will be changed from locked to released.

[0173] In this embodiment, if no access record is detected on the target physical page within a preset time period after the target physical page is detected to be in a locked state, the state of the target physical page is changed from the locked state to the released state, so that the released physical page can still be used, thereby improving the utilization of memory resources.

[0174] After the memory page is released, in order to meet business requirements, the implementation includes, after changing the state of the target physical page from locked to released, the following steps:

[0175] Obtain the pre-defined priority order of virtual machines; wherein the priority order of virtual machines is determined at least by the service type and user configuration weight of the virtual machines;

[0176] The memory space after the target physical page is released is allocated to the virtual machine according to the virtual machine's priority order.

[0177] In the method provided in this embodiment, the memory space after the released physical pages is allocated to the virtual machines according to the virtual machine's priority order, thus meeting the business requirements.

[0178] In practice, there may be host replacement operations (such as a failure of the host communicating with the virtual machine). To reduce memory migration, after performing a locking operation on the target physical page based on the flags used to characterize the locked memory, the following steps are also included:

[0179] Retrieve data of the target physical page migrated from the target host; where the target host is the host that has locked the target physical page;

[0180] Write the data of the target physical page to a locally allocated memory area;

[0181] Receive direct memory access requests sent by the virtual machine;

[0182] Based on the established mapping relationship between memory regions and virtual machine address spaces, the virtual machine physical address in the direct memory access request is translated into the host physical address;

[0183] Data is transferred based on the translated host physical address in response to direct memory access requests.

[0184] This means that only the target physical pages (physical pages that are locked) on the target host are migrated, which reduces the amount of data migrated compared to migrating all physical pages.

[0185] The above describes locking the memory corresponding to a memory allocation event after it is obtained. To improve memory utilization, this embodiment obtains a memory release event and releases the memory corresponding to the memory release event. Specifically, the virtual machine memory handling method further includes:

[0186] The virtual input / output front-end module uses tools to monitor the memory release interface of direct memory access and obtains a second monitoring result;

[0187] The memory release event for direct memory access is determined based on the second monitoring result;

[0188] Release the host target address that is locked based on the information of the memory release event.

[0189] Before the virtual input / output front-end module uses tools to monitor the memory release interface of direct memory access, it also includes:

[0190] Obtain the type of direct memory access and determine the target memory release interface based on the type of direct memory access;

[0191] The virtual input / output front-end module uses tools to monitor the memory release interface of direct memory access, including: the target memory release interface of direct memory access monitored by the virtual input / output front-end module.

[0192] The memory release interface is shown in Table 1. The method for obtaining memory release events is the same as that described above for obtaining memory allocation events, and will not be repeated here.

[0193] The method provided in this invention first identifies the DMA memory allocation and release interfaces in the virtual machine operating system kernel and tracks these interface calls using kernel function tracing tools. Second, a virtio-pin driver front-end module is designed and developed. This module needs to be installed in the virtual machine and will pass the tracked memory events to the hypervisor layer through the virtio mechanism. Finally, the hypervisor receives DMA memory access events sent by the virtio-pin front-end, obtains the HPA address of the accessed memory page through address translation, and then performs pin and unpin operations on the corresponding memory pages for memory allocation and release events. Therefore, only a portion of the memory needs to be pinned to support PCI device passthrough application scenarios, optimizing memory usage. This effectively solves the memory management problem in PCI device passthrough scenarios. By reducing the amount of pinned memory data, it effectively improves the application scenarios and performance of server virtualization. Especially for the increasingly developed AI technology application scenarios, this solution can improve the application of virtualization solutions in GPU graphics card learning and inference scenarios, fully leverage the resource management capabilities of the virtualization platform, and enhance the competitiveness of server virtualization products.

[0194] The above describes a virtual machine memory processing method for a virtual input / output backend module in a virtual machine monitor. This embodiment also provides a virtual machine memory processing method for a virtual input / output frontend module in a virtual machine. The method includes:

[0195] Obtain information about memory allocation events for direct memory access;

[0196] The memory allocation event information is sent to the virtual input / output backend module in the virtual machine monitor, so that the virtual input / output backend module in the virtual machine monitor can determine the target physical address of the virtual machine to be used by direct memory access based on the memory allocation event information; obtain the host target address corresponding to the target physical address of the virtual machine; lock the host target address to lock the memory corresponding to the target physical address of the virtual machine; wherein, the virtual machine monitor is located in the host.

[0197] The virtual machine memory processing method for the virtual input / output front-end module in a virtual machine provided in this embodiment has the same or corresponding technical features as the virtual machine memory processing method for the virtual input / output back-end module in a virtual machine monitor described above. The embodiments of the virtual machine memory processing method for the virtual input / output back-end module in a virtual machine monitor have been described in detail above, and the embodiments of the virtual machine memory processing method for the virtual input / output front-end module in a virtual machine will not be described again here, and the effects are the same as above.

[0198] In the above embodiments, the method for processing virtual machine memory has been described in detail. This invention also provides embodiments corresponding to a virtual machine memory processing device. It should be noted that this invention describes the device portion of the embodiments from two perspectives: one based on functional modules, and the other based on hardware.

[0199] The present invention provides a virtual machine memory processing device, which, from the perspective of functional modules, includes:

[0200] The first acquisition module is used to acquire information representing memory allocation events that represent direct memory access; wherein, the memory allocation events are detected by the virtual input / output front-end module deployed on the virtual machine operating system kernel;

[0201] The determination module is used to determine the target physical address of the virtual machine to be used by direct memory access based on information from memory allocation events.

[0202] The second acquisition module is used to acquire the host target address corresponding to the target physical address of the virtual machine;

[0203] The locking module is used to lock the host target address in order to lock the memory corresponding to the target physical address of the virtual machine.

[0204] In some embodiments, the virtual machine memory processing apparatus includes a first detection module for the virtual input / output front-end module to detect memory allocation events of direct memory access.

[0205] The first detection module specifically includes:

[0206] The third acquisition module is used to acquire tools for characterizing and tracing kernel behavior;

[0207] The monitoring and acquisition module is used to monitor the memory allocation interface for direct memory access using tools and acquire the first monitoring results;

[0208] The first determination module is used to determine memory allocation events for direct memory access based on the first monitoring results.

[0209] In some embodiments, the monitoring and acquisition module specifically includes:

[0210] The fourth acquisition module is used to acquire the input parameters of the memory allocation interface captured by the first probe deployed at the function entry point of the memory allocation interface after a call operation exists at the memory allocation interface; wherein, the input parameters include at least the requested memory size, memory address alignment requirements, and device-related constraint information required for direct memory access transmission;

[0211] The fifth acquisition module is used to acquire the return value and output parameters of the memory allocation interface captured by the second probe. The output parameters include the starting physical address of the directly accessed memory and the actual length of the allocated memory. The second probe is deployed at the location where the memory allocation interface has completed execution and returned.

[0212] As a module, it is used to take input parameters, return values, and output parameters as the first monitoring result;

[0213] The first determination module specifically includes:

[0214] The association module is used to associate the captured input parameters, return values ​​and output parameters, and to establish a correspondence between memory allocation request information and actual allocation results.

[0215] The generation module is used to generate direct memory access memory allocation events based on the correspondence; wherein the information of the direct memory access memory allocation event includes at least the physical address and length of the allocated memory.

[0216] In some embodiments, the virtual machine memory processing apparatus further includes:

[0217] Create a module for creating request messages based on information from memory allocation events for direct memory access;

[0218] The `put` module is used to put request messages into a shared memory queue;

[0219] The first acquisition module is specifically used to: retrieve request messages from the shared memory queue to obtain information representing memory allocation events that represent direct memory access.

[0220] In some embodiments, the second acquisition module includes:

[0221] The sixth acquisition module is used to acquire the address mapping relationship between the pre-established physical address of the virtual machine and the virtual address of the host.

[0222] The second determining module is used to determine the host target virtual address corresponding to the target physical address of the virtual machine based on the address mapping relationship.

[0223] The locking module is specifically used to lock the target virtual address of the host.

[0224] In some embodiments, the locking module specifically includes:

[0225] The seventh acquisition module is used to acquire a function that represents the target address of the locked host; wherein the parameters of the function include at least the host target address parameter, the target physical address of the virtual machine and the address length parameter, as well as a parameter representing the flag used to lock the memory;

[0226] The input module is used to input the host target address, the virtual machine target physical address and address length, as well as the flags used to represent locked memory, into the function used to represent the locked host target address;

[0227] The third determining module is used to determine the memory range of the virtual machine to be operated on based on the target physical address and address length of the virtual machine in the function used to characterize the target address of the locked host.

[0228] The fourth determination module is used to determine, when the host-side address corresponding to the virtual machine memory range is completely matched with the host target address, or is contained in the host target address, the corresponding target physical page located from the host target address is the memory page actually used by the virtual machine when performing direct memory access operations;

[0229] The locking submodule is used to locate the corresponding target physical page from the host target address, and perform a locking operation on the target physical page according to the flags used to identify the locked memory, so as to lock the host target address.

[0230] In some embodiments, the virtual machine memory processing apparatus further includes:

[0231] The eighth acquisition module is used to obtain the initial reference count value of the target physical page;

[0232] The update module is used to update the initial reference count value to a new reference count value;

[0233] The first detection and triggering module is used to trigger the locking submodule when a new reference count value is detected that is greater than the initial reference count value.

[0234] In some embodiments, the virtual machine memory processing apparatus further includes:

[0235] The ninth acquisition module is used to acquire the memory address range and corresponding memory page identifier submitted when the virtual machine initiates a direct memory access operation, and to record the memory address range and corresponding memory page identifier as the target locking range;

[0236] The call and query module is used to call the host operating system's memory management interface to query the current locking status and locking range parameters of the memory page corresponding to the memory page identifier, so as to determine the actual locking range;

[0237] The fifth determination module is used to determine that the object of the locking operation is the target physical page when the target locking range and the actual locking range meet the preset requirements. The preset requirements are that the starting and ending values ​​of the memory addresses in the target locking range and the number of memory pages covered are consistent with the starting and ending values ​​of the memory addresses and the number of memory pages covered in the actual locking range.

[0238] In some embodiments, the virtual machine memory processing apparatus further includes:

[0239] The tenth acquisition module is used to obtain the difference between the actual locking range and the target locking range;

[0240] The acquisition and release module is used to acquire additional locked physical pages when a difference greater than 0 is detected; and to trigger an unlocking mechanism to release the additional locked physical pages; wherein, the additional locked physical pages are physical pages that exist in the actual locking range but do not exist in the target locking range;

[0241] The second detection and triggering module is used to trigger the first acquisition module when the detected difference is less than 0.

[0242] In some embodiments, the virtual machine memory processing apparatus further includes:

[0243] The eleventh acquisition module is used to acquire the access records of the target physical page;

[0244] The adjustment module is used to adjust the state of the target physical page from locked to released if no access record is detected on the target physical page within a preset time period after the target physical page is detected to be locked.

[0245] In some embodiments, the virtual machine memory processing apparatus further includes:

[0246] The twelfth acquisition module is used to acquire the pre-set priority order of virtual machines; wherein the priority order of virtual machines is determined at least by the service type and user configuration weight of the virtual machines;

[0247] The allocation module is used to allocate the memory space after the target physical page is released to the virtual machine according to the virtual machine's priority order.

[0248] In some embodiments, the virtual machine memory processing apparatus further includes:

[0249] The thirteenth acquisition module is used to acquire data of the target physical page migrated from the target host; wherein, the target host is the host that has locked the target physical page;

[0250] The write module is used to write the data of the target physical page to the locally allocated memory area.

[0251] The receiving module is used to receive direct memory access requests sent by the virtual machine;

[0252] The translation module is used to translate the virtual machine physical address in the direct memory access request into the host physical address based on the established mapping relationship between memory regions and virtual machine address space.

[0253] The transmission module is used to transmit data based on the translated host physical address in response to direct memory access requests.

[0254] In some embodiments, the virtual machine memory processing apparatus further includes:

[0255] The monitoring and release module is used by the virtual input / output front-end module to monitor the memory release interface of direct memory access using tools and obtain the second monitoring result;

[0256] The sixth determination module is used to determine memory release events for direct memory access based on the second monitoring results;

[0257] The release module is used to release a locked host target address based on information from a memory release event.

[0258] In some embodiments, the virtual machine memory processing apparatus further includes:

[0259] The acquisition and determination module is used to acquire the type of direct memory access and determine the target memory allocation interface based on the type of direct memory access; wherein, the type of direct memory access includes the type of consistent direct memory access and the type of streaming direct memory access;

[0260] The first monitoring module is used to monitor the memory allocation interface for direct memory access using tools;

[0261] The first monitoring module is specifically used to monitor the target memory allocation interface corresponding to direct memory access using tools.

[0262] Also includes:

[0263] The fourteenth acquisition module is used to acquire the type of direct memory access and determine the target memory release interface based on the type of direct memory access.

[0264] The second monitoring module is used by the virtual input / output front-end module to monitor the memory release interface of direct memory access using tools;

[0265] The second monitoring module is specifically used by the virtual input / output front-end module to monitor the target memory release interface for direct memory access using tools.

[0266] This invention also provides another virtual machine memory processing device, comprising:

[0267] The fifteenth acquisition module is used to acquire information about memory allocation events for direct memory access;

[0268] The sending module is used to send memory allocation event information to the virtual input / output backend module in the virtual machine monitor, so that the virtual input / output backend module in the virtual machine monitor can determine the target physical address of the virtual machine to be used by direct memory access based on the memory allocation event information; obtain the host target address corresponding to the target physical address of the virtual machine; and lock the host target address to lock the memory corresponding to the target physical address of the virtual machine; wherein, the virtual machine monitor is located in the host.

[0269] Since the embodiments of the apparatus and the embodiments of the method correspond to each other, please refer to the description of the embodiments of the method for the embodiments of the apparatus, which will not be repeated here.

[0270] Figure 5 This is a structural diagram of a virtualization server provided in an embodiment of the present invention. This embodiment is based on a hardware perspective, such as... Figure 5 As shown, the virtualization server includes:

[0271] Memory 20 is used to store computer programs;

[0272] The processor 21 is used to implement the steps of the virtual machine memory processing method mentioned in the above embodiments when executing a computer program.

[0273] The processor 21 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 21 may be implemented using at least one of the following hardware forms: Digital Signal Processor (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 21 may also include a main processor and a coprocessor. The main processor, also known as the Central Processing Unit (CPU), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 21 may integrate a Graphics Processing Unit (GPU), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 21 may also include an Artificial Intelligence (AI) processor, which handles computational operations related to machine learning.

[0274] The memory 20 may include one or more computer-readable storage media, which may be non-transitory. The memory 20 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In this embodiment, the memory 20 is used to store at least the following computer program 201, which, after being loaded and executed by the processor 21, is capable of implementing the relevant steps of the virtual machine memory processing method disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, and the storage method may be temporary storage or permanent storage. The operating system 202 may include Windows, Unix, Linux, etc. The data 203 may include, but is not limited to, the data involved in the aforementioned virtual machine memory processing method.

[0275] In some embodiments, the virtualization server may further include a display screen 22, an input / output interface 23, a communication interface 24, a power supply 25, and a communication bus 26.

[0276] Those skilled in the art will understand that Figure 5 The structure shown does not constitute a limitation on the virtualization server and may include more or fewer components than illustrated.

[0277] The virtualization server provided in this embodiment of the invention includes a memory and a processor. When the processor executes a program stored in the memory, it can implement the following method: virtual machine memory processing method, with the same effect as above.

[0278] This invention also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the above-described virtual machine memory processing method.

[0279] Finally, the present invention also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, which, when executed by a processor, performs the steps described in the above method embodiments.

[0280] It is understood that if the methods in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and executes all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0281] The computer-readable storage medium provided by this invention includes the virtual machine memory processing method mentioned above, and has the same effect.

[0282] The virtual machine memory processing method, apparatus, product, virtualization server, and medium provided by the present invention have been described in detail above. The various embodiments in the specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section. It should be noted that those skilled in the art can make several improvements and modifications to the present invention without departing from the principles of the invention, and these improvements and modifications also fall within the protection scope of the present invention.

[0283] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

Claims

1. A method for processing memory of a virtual machine, the method comprising: A virtual input / output back-end module applied in a virtual machine monitor, the virtual machine monitor being located in a host, the method comprising: obtaining information representing a memory allocation event of a direct memory access; wherein the memory allocation event is detected by a virtual input / output front-end module deployed in a virtual machine operating system kernel; determining a target physical address of a virtual machine to be used by the direct memory access according to the information of the memory allocation event; obtaining a host target address corresponding to the target physical address of the virtual machine; locking the host target address to lock a memory corresponding to the target physical address of the virtual machine; the virtual input / output front-end module detecting the memory allocation event of the direct memory access comprising: obtaining a tool for representing a kernel behavior tracking tool; monitoring a memory allocation interface of the direct memory access by using the tool and obtaining a first monitoring result; determining the memory allocation event of the direct memory access according to the first monitoring result; further comprising: monitoring a memory release interface of the direct memory access by using the tool and obtaining a second monitoring result by the virtual input / output front-end module; determining a memory release event of the direct memory access according to the second monitoring result; releasing the host target address in the locked state based on the information of the memory release event.

2. The virtual machine memory handling method of claim 1, wherein, the monitoring the memory allocation interface of the direct memory access by using the tool and obtaining the first monitoring result comprising: after an invocation operation exists at the memory allocation interface, obtaining input parameters at the memory allocation interface captured by a first probe deployed at a function entry of the memory allocation interface; wherein the input parameters at least include a requested memory size, a memory address alignment requirement, and device-related constraint information required for the direct memory access transmission; obtaining return values and output parameters at the memory allocation interface captured by a second probe, wherein the output parameters include an actually allocated direct memory access memory starting physical address and an actually allocated memory length; the second probe is deployed at a position where the memory allocation interface execution is completed and returned; taking the input parameters, the return values, and the output parameters as the first monitoring result; the determining the memory allocation event of the direct memory access according to the first monitoring result comprising: associating the captured input parameters, return values, and output parameters, and establishing a corresponding relationship including memory allocation request information and actual allocation results; generating the memory allocation event of the direct memory access based on the corresponding relationship; wherein the information of the memory allocation event of the direct memory access at least includes a physical address and a length of the allocated memory.

3. The method of claim 2, wherein, after the virtual input / output front-end module detects the memory allocation event of the direct memory access, further comprising: creating a request message based on the information of the memory allocation event of the direct memory access; putting the request message into a shared memory queue; the obtaining the information representing the memory allocation event of the direct memory access comprising: obtaining the request message from the shared memory queue to obtain the information representing the memory allocation event of the direct memory access.

4. The method of claim 1, wherein, the obtaining the host target address corresponding to the target physical address of the virtual machine comprising: Obtaining an address mapping relationship between a physical address of a pre-established virtual machine and a host virtual address; Determining a host target virtual address corresponding to a target physical address of the virtual machine based on the address mapping relationship; Locking the host target address includes locking the host target virtual address.

5. The method of claim 4, wherein, The locking the host target address includes: Obtaining a function for representing the locking of the host target address; wherein the parameters of the function at least include a host target address parameter, a target physical address of the virtual machine and an address length parameter, and a parameter for representing a lock memory flag; Inputting the host target address, the target physical address of the virtual machine and the address length, and the flag for representing the lock memory into the function for representing the locking of the host target address; In the function for representing the locking of the host target address, determining a virtual machine memory range to be operated according to the target physical address of the virtual machine and the address length; In the case where it is detected that the host side address corresponding to the virtual machine memory range is completely matched with the host target address, or is contained in the host target address, determining that the target physical page located from the host target address is the memory page actually used when performing the direct memory access operation for the virtual machine; Locating the target physical page from the host target address, and performing a lock operation on the target physical page according to the flag for representing the lock memory, so as to lock the host target address.

6. The method of claim 5, wherein, After locating the target physical page from the host target address, and before performing the lock operation on the target physical page according to the flag for representing the lock memory, it further includes: Obtaining an initial reference count value of the target physical page; Updating the initial reference count value as a new reference count value; In the case where it is detected that the new reference count value is greater than the initial reference count value, entering the step of performing the lock operation on the target physical page according to the flag for representing the lock memory.

7. The method of claim 5, wherein, After performing the lock operation on the target physical page according to the flag for representing the lock memory, it further includes: Obtaining a memory address interval and a corresponding memory page identifier submitted when the virtual machine initiates the direct memory access operation, and recording the memory address interval and the corresponding memory page identifier as a target lock range; Calling a memory management interface of the host operating system to query a current lock state and a lock range parameter of the memory page corresponding to the memory page identifier, so as to determine an actual lock range; In the case where it is detected that the target lock range and the actual lock range meet a preset requirement, determining that the target physical page is the object of the lock operation; wherein the preset requirement is that the memory address start value, the memory address end value and the number of memory pages covered in the target lock range are consistent with the memory address start value, the memory address end value and the number of memory pages covered in the actual lock range.

8. The method of claim 7, wherein, After determining the actual lock range, it further includes: Obtaining a difference value obtained by subtracting the target lock range from the actual lock range; In a case where it is detected that the difference is greater than 0, an additional locked physical page is acquired; a release mechanism is triggered to release the additional locked physical page; wherein the additional locked physical page is a physical page existing in the actual locking range and not existing in the target locking range; In a case where it is detected that the difference is less than 0, the step of acquiring information representing a memory allocation event of direct memory access is returned.

9. The method of claim 5, wherein, After performing the locking operation on the target physical page according to the flag representing the locked memory, the method further comprises: acquiring access records of the target physical page; starting from detecting that the target physical page is in a locked state, if it is detected that the target physical page has no access record within a preset time length, adjusting the state of the target physical page from the locked state to a released state.

10. The method of claim 9, wherein, After adjusting the state of the target physical page from the locked state to the released state, the method further comprises: acquiring a priority order of virtual machines; wherein the priority order of virtual machines is determined by at least a service type of the virtual machines and a user configuration weight; allocating the memory space after releasing the target physical page to the virtual machines according to the priority order of the virtual machines.

11. The method of claim 5, wherein, After performing the locking operation on the target physical page according to the flag representing the locked memory, the method further comprises: acquiring data of the target physical page migrated from a target host; wherein the target host is a host locking the target physical page; writing the data of the migrated target physical page into a locally allocated memory area; receiving a direct memory access request sent by a virtual machine; based on the mapping relationship between the memory area and the virtual machine address space, converting a virtual machine physical address in the direct memory access request into a host physical address; performing data transmission according to the converted host physical address to respond to the direct memory access request.

12. The method of claim 1 to 11, wherein, The physical address of the virtual machine is converted from a host physical address to a host virtual address, and then converted from the host virtual address.

13. The method of claim 1, wherein, Before monitoring the memory allocation interface of direct memory access by using the tool, the method further comprises: acquiring a type of direct memory access, and determining a target memory allocation interface according to the type of direct memory access; wherein the type of direct memory access includes a type of coherent direct memory access and a type of streaming direct memory access; monitoring the target memory allocation interface of direct memory access by using the tool comprises: monitoring the target memory allocation interface of direct memory access by using the tool; Before monitoring the memory release interface of direct memory access by using the tool by the virtual input / output front-end module, the method further comprises: acquiring a type of direct memory access, and determining a target memory release interface according to the type of direct memory access; monitoring the memory release interface of direct memory access by using the tool by the virtual input / output front-end module comprises: monitoring the target memory release interface of direct memory access by using the tool by the virtual input / output front-end module.

14. A method for processing memory of a virtual machine, the method comprising: The method applied to a virtual input / output front-end module in a virtual machine comprises: acquiring information of a memory allocation event of direct memory access; The information of the memory allocation event is sent to a virtual input / output back-end module in a virtual machine monitor, so that the virtual input / output back-end module in the virtual machine monitor determines a target physical address of a virtual machine to be used by the direct memory access according to the information of the memory allocation event; a host target address corresponding to the target physical address of the virtual machine is obtained; and the host target address is locked to lock the memory corresponding to the target physical address of the virtual machine; wherein the virtual machine monitor is located in a host. The virtual input / output front-end module detecting the memory allocation event of the direct memory access comprises: obtaining a tool for representing tracking kernel behavior; monitoring a memory allocation interface of the direct memory access by using the tool, and obtaining a first monitoring result; determining the memory allocation event of the direct memory access according to the first monitoring result; further comprising: the virtual input / output front-end module monitoring a memory release interface of the direct memory access by using the tool, and obtaining a second monitoring result; determining a memory release event of the direct memory access according to the second monitoring result; releasing the host target address in the locked state based on the information of the memory release event.

15. A processing device for virtual machine memory, the processing device comprising: comprising: a first obtaining module, configured to obtain information representing a memory allocation event of a direct memory access; wherein the memory allocation event is detected by a virtual input / output front-end module deployed on a kernel of a virtual machine operating system; a determining module, configured to determine a target physical address of a virtual machine to be used by the direct memory access according to the information of the memory allocation event; a second obtaining module, configured to obtain a host target address corresponding to the target physical address of the virtual machine; a locking module, configured to lock the host target address to lock the memory corresponding to the target physical address of the virtual machine; the virtual machine memory processing apparatus comprises a first detecting module, configured to detect, by a virtual input / output front-end module, a memory allocation event of a direct memory access; the first detecting module specifically comprises: a third obtaining module, configured to obtain a tool for representing tracking kernel behavior; a monitoring and obtaining module, configured to monitor a memory allocation interface of the direct memory access by using the tool, and obtain a first monitoring result; a first determining module, configured to determine the memory allocation event of the direct memory access according to the first monitoring result; the virtual machine memory processing apparatus further comprises: a monitoring and releasing module, configured to monitor, by the virtual input / output front-end module, a memory release interface of the direct memory access by using the tool, and obtain a second monitoring result; a sixth determining module, configured to determine a memory release event of the direct memory access according to the second monitoring result; a releasing module, configured to release the host target address in the locked state based on the information of the memory release event.

16. A computer program product comprising a computer program, characterized in that, The computer program is executed by a processor to implement the steps of the virtual machine memory processing method according to any one of claims 1 to 14.

17. A virtualization server, comprising: comprising: a memory, configured to store a computer program; a processor, configured to implement the steps of the virtual machine memory processing method according to any one of claims 1 to 14 when the computer program is executed.

18. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to implement the steps of the virtual machine memory processing method in any one of claims 1 to 14.

Citation Information

Patent Citations

  • Dynamic mapping method and system for cloud host with direct connection equipment

    CN119960902A

  • Data transmission method and device, electronic equipment and storage medium

    CN120045484A