Virtual machine asynchronous memory allocation method and device, computer equipment and medium
By detecting whether the Qemu software version supports asynchronous memory preallocation in the virtual machine, and creating and executing asynchronous memory allocation tasks in iothread, the problem of synchronous memory preallocation of the virtual machine is solved, resulting in long-term occupation of the main thread, and the normal operation of the virtual machine business and efficient utilization of resources are achieved.
Patent Information
- Application Number
- CN202411747457.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-04-15
Smart Images

Figure CN119829195A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of virtual machine technology, and in particular to a method, device, computer equipment and medium for allocating asynchronous memory of a virtual machine. Background Art
[0002] With the rapid development of cloud computing technology, virtualization technology has played an extremely important role in it. In kernel virtualization, a native open source full virtualization solution for Linux based on hardware-assisted virtualization, the simulator and libvirt together build a complete virtualization management system. In its architecture, the main thread undertakes the main loop task, which continuously monitors two specific event sources and timers. When an event source is detected to have an event to be processed, the corresponding callback function is called serially and a specific lock is held. Many operations, such as input and output reading and writing of a certain block device, virtio-net event processing, and specific command processing (including hot-add memory), are executed in the main loop.
[0003] Since open source simulators usually use synchronous methods to pre-allocate memory, when a virtual machine uses a pass-through device or a specific protocol and needs to pre-allocate a large amount of memory, the memory pre-allocation task will occupy the main thread until it is completed, causing the main loop to be occupied for a long time, and other tasks or events are difficult to handle in time, which in turn causes the virtual machine to function abnormally. For example, the processing of block device read and write tasks is blocked, and the reading and writing inside the virtual machine are all stopped; the virtio-net event processing task is blocked, and the network will be interrupted for a long time when the network traffic is large; the virtual network calculation and console cannot be refreshed because the main thread is occupied, which greatly affects the normal operation of the virtual machine business. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a method, apparatus, computer equipment and medium for allocating asynchronous memory of a virtual machine to solve the problem that the existing virtual machine synchronous memory pre-allocation causes the main thread to be occupied for a long time in specific scenarios, which may easily lead to internal read and write stagnation, network interruption, virtual network calculation and console abnormalities when hot adding memory.
[0005] In a first aspect, an embodiment of the present invention provides a method for allocating asynchronous memory of a virtual machine, the method comprising:
[0006] Check whether the Qemu software version of the virtual machine meets the asynchronous memory pre-allocation conditions;
[0007] If the asynchronous memory pre-allocation condition is met, a corresponding object-add command is generated through a preset memory management protocol of the virtual machine;
[0008] Creating a corresponding asynchronous memory allocation task in the iothread of the virtual machine based on the parameters of the object-add command, and setting the allocation state of the memory object to a running state;
[0009] The virtual machine is controlled to execute the asynchronous memory allocation task in the iothread, to obtain an execution result, and to adjust the allocation state of the memory object according to the execution result.
[0010] Further, the detecting whether the Qemu software version of the virtual machine meets the asynchronous memory pre-allocation condition includes:
[0011] Detecting whether there is a pre-allocation requirement for the memory of the virtual machine;
[0012] If the pre-allocation requirement exists, query whether the Qemu software version has an asynchronous memory pre-allocation attribute, and if it has the asynchronous memory pre-allocation attribute, set the attribute value of the asynchronous memory pre-allocation attribute to a first preset value, and determine that the Qemu software version meets the asynchronous memory pre-allocation condition;
[0013] Or, if the pre-allocation requirement does not exist, or the asynchronous memory pre-allocation function is not provided, it is determined that the Qemu software version does not meet the asynchronous memory pre-allocation condition.
[0014] Further, adjusting the allocation state of the memory object according to the execution result includes:
[0015] If the execution result is successful, the allocation state of the memory object is adjusted to a completed state; or, if the execution result is a failure, a corresponding rollback operation is performed on the asynchronous memory allocation task, and the allocation state of the memory object is adjusted to a terminated state.
[0016] Further, after creating a corresponding asynchronous memory allocation task in the iothread of the virtual machine based on the parameters of the object-add command, the method further includes:
[0017] Sending a main thread release signal to the libvirt;
[0018] Receiving the main thread release signal through the libvirt, and obtaining the attribute value of the asynchronous memory pre-allocation attribute;
[0019] If the attribute value is a first preset value, querying the allocation state of the memory object, and when the allocation state is a running state, continuing to perform the allocation state monitoring operation;
[0020] Or, if the attribute value is a second preset value, and / or the allocation state of the memory object is a completed state or a terminated state, a memory device integration mechanism is triggered, and corresponding control operations are performed on the virtual machine based on the memory device integration mechanism.
[0021] Furthermore, the triggering of the memory device integration mechanism and the execution of corresponding control operations based on the memory device integration mechanism include:
[0022] Adding a virtual dual in-line memory module as a memory device to a configuration environment of the virtual machine through a preset memory management protocol of the virtual machine;
[0023] In the configuration environment, an association relationship is established between the virtual dual in-line memory module and the Qemu software version of the virtual machine.
[0024] Furthermore, the method further comprises:
[0025] Get the memory devices added within a preset time period;
[0026] Matching the memory device with the Qemu software version in the virtual machine to obtain a matching result;
[0027] A corresponding processing operation is performed on the memory device according to the matching result.
[0028] Furthermore, performing a corresponding processing operation on the memory device according to the matching result includes:
[0029] When the matching result is that the memory device does not match the Qemu software version, the allocation status of the memory object is obtained; if the allocation status is a completed state or a terminated state, a deletion operation is performed on the memory device; or, if the allocation status is a running state, the currently running asynchronous memory allocation task is terminated, and after the task is terminated, a deletion operation is performed on the memory device;
[0030] When the matching result is that the memory device matches the Qemu software version, monitor the usage requirements for the memory device, obtain the allocation status of the memory object according to the usage requirements, and perform a usage operation on the memory device when the allocation status is a completion state or a termination state.
[0031] In a second aspect, an embodiment of the present invention provides a device for allocating asynchronous memory of a virtual machine, the device comprising:
[0032] A detection module is used to detect whether the Qemu software version of the virtual machine meets the asynchronous memory pre-allocation conditions;
[0033] A generation module, configured to generate a corresponding object-add command through a preset memory management protocol of the virtual machine if the asynchronous memory pre-allocation condition is met;
[0034] A creation module is used to create a corresponding asynchronous memory allocation task in the iothread of the virtual machine based on the object-add command, and set the allocation state of the Qemu software version to a running state;
[0035] The control module is used to control the virtual machine to execute the asynchronous memory allocation task in the iothread, obtain the execution result, and adjust the allocation state of the Qemu software version according to the execution result.
[0036] In a third aspect, an embodiment of the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0037] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the method of the first aspect or any corresponding embodiment thereof.
[0038] The method provided in the embodiment of the present application has the following beneficial effects:
[0039] The method provided in the embodiment of the present application can accurately locate the time when asynchronous memory pre-allocation is required by detecting whether the Qemu software version of the virtual machine meets the asynchronous memory pre-allocation conditions, avoid unnecessary asynchronous operation startup, improve resource utilization efficiency and reduce system overhead. If the asynchronous memory pre-allocation conditions are met, the corresponding object-add command is generated through the preset memory management protocol of the virtual machine. The command is generated through a specific protocol, which ensures the standardization and compatibility of command generation, so that the memory pre-allocation process can be stably initiated under different virtual machine environments and configurations. Based on the parameters of the object-add command, a corresponding asynchronous memory allocation task is created in the iothread of the virtual machine, and the allocation state of the Qemu software version is set to the running state. Creating the task in the iothread instead of the main thread effectively solves the problem of the main thread being occupied for a long time due to synchronous memory pre-allocation. The main thread is released, and other tasks such as block device reading and writing, virtio-net event processing, virtual network computing processing, and specific command processing can be processed in time, avoiding the occurrence of read and write stagnation, network interruption, virtual network computing and console abnormalities in the virtual machine, and ensuring the normal operation of the virtual machine business. Control the virtual machine to execute asynchronous memory allocation tasks in iothread, obtain the execution results, and adjust the allocation status of the Qemu software version according to the execution results. By adjusting the status according to the execution results, you can clearly understand the completion status of the memory pre-allocation task, which is convenient for the subsequent management and allocation of memory resources. For example, if the allocation is successful, the memory can be directly put into use. If it fails, the rollback operation can be performed in time to restore the system status, further improving the stability and reliability of the system.
[0040] The method provided in the embodiment of the present application sends a main thread release signal after creating an asynchronous memory allocation task to prevent the main thread from being occupied for a long time and ensure the overall business smoothness of the virtual machine. Libvirt receives the signal and obtains the attribute value, providing a basis for subsequent operations, which helps to accurately control memory allocation and resource management. If the attribute value is the first preset value, query the allocation status and continuously monitor to enhance system stability and reliability. If the attribute value is the second preset value or the allocation status is the completed state or the terminated state, the memory device integration mechanism is triggered, a virtual dual in-line memory module is added and an association is established, the flexibility and effectiveness of memory management are improved, and the performance of the virtual machine is optimized.
[0041] The method provided in the embodiment of the present application obtains memory devices within a preset time period, statistics and sorts out their changes, and provides a data basis for accurate management and optimized configuration. Matching memory devices with Qemu software versions can ensure the correct correspondence and avoid problems caused by incorrect associations. When there is a mismatch, delete operations are performed according to the allocation status of the memory object or delete after the asynchronous task is completed, clean up useless devices, and ensure pure and efficient use of resources. When matching, monitor usage needs and use devices according to the allocation status, reasonably allocate resources, improve utilization and virtual machine efficiency, adapt to dynamic needs, and improve system performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0043] Figure 1 It is a flowchart of a method for allocating asynchronous memory of a virtual machine according to an embodiment of the present invention;
[0044] Figure 2 is a flow chart of a cyclic scheduling mechanism in a software system according to an embodiment of the present invention;
[0045] Figure 3 is a schematic diagram of a flow chart of performing operations based on pre-allocated asynchronous attributes according to an embodiment of the present invention;
[0046] Figure 4 is a flowchart of a virtual machine memory management interaction process according to an embodiment of the present invention;
[0047] Figure 5 is a flow chart of a method for testing a virtual machine memory management technology according to an embodiment of the present invention;
[0048] Figure 6 is a structural block diagram of a device for allocating asynchronous memory of a virtual machine according to an embodiment of the present invention;
[0049] Figure 7 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0051] According to an embodiment of the present invention, a method, apparatus, computer device and medium for allocating asynchronous memory of a virtual machine are provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0052] In this embodiment, a method for allocating asynchronous memory of a virtual machine is provided. Figure 1 is a flow chart of a method for allocating asynchronous memory of a virtual machine according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:
[0053] Step S11, detecting whether the Qemu software version of the virtual machine meets the asynchronous memory pre-allocation condition.
[0054] In the embodiment of the present application, step S11 includes the following steps A1-A3:
[0055] Step A1, detecting whether there is a pre-allocation requirement for the memory of the virtual machine.
[0056] It should be noted that a virtual machine is a computer system that is simulated by software and has complete hardware system functions and runs in a completely isolated environment. Pre-allocation requirements refer to the need to allocate more memory resources to the virtual machine in advance to ensure the normal operation of the virtual machine due to business growth, load increase, etc.
[0057] Specifically, the pre-allocation requirement of the virtual machine memory can be detected in a variety of ways. For example, the memory usage of the virtual machine can be continuously monitored. When the memory usage reaches a certain threshold, it is considered that there is a pre-allocation requirement. It is also possible to determine whether there may be insufficient memory in the future based on the business type and load forecast carried by the virtual machine. If there is a possibility of insufficient memory in the future, it is determined that there is a pre-allocation requirement.
[0058] Step A2: if there is a pre-allocation requirement, query whether the Qemu software version has an asynchronous memory pre-allocation attribute, and if it has the asynchronous memory pre-allocation attribute, set the attribute value of the asynchronous memory pre-allocation attribute to a first preset value to determine whether the Qemu software version meets the asynchronous memory pre-allocation condition.
[0059] It should be noted that the Qemu software version is the specific release version number of the Qemu software used by the virtual machine. It is a distinguishing mark of the Qemu software at different development and release stages. Each version has its own unique features, such as new features, performance improvement measures, security vulnerability fixes, and bug fixes. This difference between versions has a real impact on the function of the virtual machine. In terms of memory management, different versions of Qemu software vary in their asynchronous memory pre-allocation capabilities. Some versions have this feature, while others do not. Therefore, when determining whether the conditions for asynchronous memory pre-allocation are met, the software version is a key point.
[0060] Among them, the asynchronous memory pre-allocation attribute is a special feature added to achieve asynchronous memory pre-allocation. Its core function is to clarify whether the corresponding Qemu software version supports asynchronous memory pre-allocation, which can be regarded as a functional identification mark. When it is determined that a certain Qemu software version has this attribute, its attribute value will be set to the first preset value. This first preset value is a predetermined specific symbolic value. Its function is to indicate that the attribute has been successfully switched to the effective enabled state, which means that this Qemu software version has met the asynchronous memory pre-allocation conditions, thereby providing strong support and guarantee for the subsequent memory pre-allocation operations that may be carried out by the virtual machine.
[0061] Specifically, when it is detected that the virtual machine has a pre-allocation requirement, libvirt (a software library for managing virtualization platforms) will query whether the Qemu software version has an asynchronous memory pre-allocation attribute. This can be achieved by checking the attribute list of the Qemu software version or calling a specific interface. If the Qemu software version has this attribute, it means that it supports asynchronous memory pre-allocation. At this time, the attribute value of the asynchronous memory pre-allocation attribute can be set to a first preset value, such as "true" or "1", to determine that the Qemu software version meets the asynchronous memory pre-allocation condition.
[0062] Step A3: If there is no pre-allocation requirement, or the asynchronous memory pre-allocation function is not provided, it is determined that the Qemu software version does not meet the asynchronous memory pre-allocation condition.
[0063] Specifically, if the virtual machine does not have a pre-allocation requirement, asynchronous memory pre-allocation is not required, so it is determined that the Qemu software version does not meet the asynchronous memory pre-allocation condition. In addition, if the Qemu software version does not have an asynchronous memory pre-allocation function, even if there is a pre-allocation requirement, asynchronous memory pre-allocation cannot be performed, and it is also determined that the asynchronous memory pre-allocation condition is not met.
[0064] Step S12: If the asynchronous memory pre-allocation condition is met, a corresponding object-add command is generated through a preset memory management protocol of the virtual machine.
[0065] In the embodiment of the present application, the asynchronous memory pre-allocation condition is that the Qemu software version of the virtual machine has a pre-allocation requirement and has an asynchronous memory pre-allocation attribute; the preset memory management protocol is a set of specifications and methods for managing the memory of the virtual machine, which specifies how to allocate, release, query the status of the memory, etc. Different virtual machine software can have different preset memory management protocols. The object-add command is an instruction for adding a specific Qemu software version to the virtual machine system.
[0066] As an example, the QEMU virtual machine can generate an object-add command through the QMP machine protocol (QEMU Machine Protocol, QMP). Specifically, if libvirt determines that the qemu virtual machine supports asynchronous memory preallocation and memory needs to be preallocated, the prealloc_async attribute is specified as true in the qmp object_add command. This means that asynchronous memory allocation is enabled so that asynchronous memory allocation tasks can be performed in a dedicated iothread later. If the qemu virtual machine does not support asynchronous memory preallocation or memory does not need to be preallocated, the prealloc_async attribute is not specified and the qmp command is executed directly.
[0067] Step S13: Create a corresponding asynchronous memory allocation task in the iothread of the virtual machine based on the parameters of the object-add command, and set the allocation state of the memory object to the running state.
[0068] In the embodiment of the present application, an object-add command is generated after the asynchronous memory pre-allocation condition is met, and an asynchronous memory allocation task is created in the iothread of the virtual machine based on the command parameters of the object-add command. In the combination of QEMU and ibvirt, when the condition is met, libvirt specifies the prealloc_async attribute as true in the qmp object_add command, and qemu creates a task in a dedicated iothread (iothread) after parsing, and sets the Qemu software version allocation status to the running status, so as to track the progress of the management task later, so that other parts of the system can understand the current status and perform corresponding processing and monitoring.
[0069] Step S14, controlling the virtual machine to execute the asynchronous memory allocation task in the iothread, obtaining the execution result, and adjusting the allocation state of the memory object according to the execution result.
[0070] In an embodiment of the present application, after an asynchronous memory allocation task is created in an iothread, it is necessary to control the virtual machine to execute this task in the iothread. For example, in the combination of QEMU and libvirt, the qemu virtual machine executes the memory asynchronous allocation task in a dedicated iothread. The specific process may be to create a touch thread to trigger the actual memory allocation and wait for the allocation to be completed. During the execution of the task, the virtual machine will continuously monitor the progress of the task. If the memory allocation is successful, the execution result is done; if a problem occurs during the allocation process and causes failure, the execution result is error.
[0071] In an embodiment of the present application, the allocation state of the memory object is adjusted according to the execution result, including: if the execution result is successful, the allocation state of the memory object is adjusted to a completed state; or, if the execution result is a failure, a corresponding rollback operation is performed on the asynchronous memory allocation task, and the allocation state of the memory object is adjusted to a terminated state.
[0072] Specifically, after the virtual machine executes the asynchronous memory allocation task in iothread, if the result is successful, such as in the interaction between QEMU and libvirt, qemu sets the res_async attribute to done after completing the allocation, and the memory object state is adjusted to the completed state; if it fails, a rollback operation is performed, such as releasing some allocated resources, undoing some system state changes, and then setting the res_async attribute to error, and the memory object state is adjusted to the terminated state.
[0073] It should be noted that Figure 2A loop system is shown, starting from initialization, through preparation, polling, scheduling, and then returning to the main loop to form a closed loop. In the scheduling stage, there will also be external callback function call operations. This flow chart is usually used to describe the event loop or task scheduling mechanism in the software system. In the virtual machine memory management technology of this application, the software system also has a similar loop scheduling mechanism to ensure that various operations are carried out in an orderly manner. For example, in the process of memory allocation and management, there may be similar initialization of relevant memory management parameters, preparation of memory allocation space, polling of memory usage status, scheduling of memory allocation tasks, and externally triggered callback function operations involved in scheduling (for example, adjusting the memory allocation strategy according to external events) to ensure the stable operation of the entire virtual machine memory management system.
[0074] As an example, Figure 3 As shown, Libvirt first queries the memory backend properties (query mem-backendproperties). Check whether it has the preallocation asynchronous property (has prealloc_async property?). If it has the preallocation asynchronous property, Libvirt sends a command through QMP to add a memory backend object and sets the preallocation asynchronous to true (object_add memory-backend prealloc_async=true). If it does not have the preallocation asynchronous property, Libvirt directly sends a command through QMP to add a memory backend object (object_add memory-backend). Libvirt queries the memory device through QMP (query-memdev). After receiving the command, Qemu operates according to the situation: if it is preallocation asynchronous, Qemu creates a new I / O thread (create new iothread), performs backend memory preallocation (backendmemory alloc mem_prealloc), and performs memory preallocation in the I / O thread (iothread_mem_prealloc). If it is not preallocation asynchronous, Qemu performs backend memory allocation (backend memory alloc). Qemu updates the result (update res) and feeds the result back to Libvirt. Libvirt checks whether the asynchronous result is completed or an error occurs (res_async is done / error?), and draws a conclusion of completion or error (Done / Error).
[0075] In the embodiment of the present application, after creating a corresponding asynchronous memory allocation task in the iothread of the virtual machine based on the parameters of the object-add command, the method further includes:
[0076] Step S21, sending a main thread release signal to libvirt.
[0077] In the embodiment of the present application, after the corresponding asynchronous memory allocation task is successfully created in the iothread of the virtual machine, the system will send a main thread release signal to libvirt. The sending of this signal can be implemented by calling a specific function or following an established communication protocol, depending on the implementation mechanism of the virtual machine and libvirt used. For example, in the combined scenario of QEMU and libvirt, the signal will be sent in the manner agreed between them so that libvirt can receive the information that the main thread can be released.
[0078] Step S22, receiving a main thread release signal through libvirt, and obtaining a property value of an asynchronous memory pre-allocation property.
[0079] In an embodiment of the present application, libvirt (such as libvirt) obtains the attribute value of the asynchronous memory pre-allocation attribute after receiving the main thread release signal, specifically including querying the relevant attribute settings of the Qemu software version, and obtaining the attribute value by calling the corresponding interface function or querying a specific data structure. For example, libvirt sends a query request to the virtual machine to obtain the value of the prealloc_async attribute of the qemu memory-backend object, so as to clarify the relevant settings of the current memory pre-allocation task.
[0080] Step S23: If the attribute value is the first preset value, query the allocation status of the Qemu software version, and when the allocation status is the running status, continue to perform the allocation status monitoring operation.
[0081] Specifically, if the attribute value of the asynchronous memory pre-allocation attribute obtained is the first preset value, it means that the current situation requires further attention to the progress of the memory allocation task. At this time, libvirt queries the allocation status of the memory object. If the allocation status is found to be running, it means that the memory allocation task is in progress, and it is necessary to continue to perform the allocation status monitoring operation. For example, query requests are sent to the virtual machine regularly to obtain the value of the res_async attribute (indicating the asynchronous execution state) of the memory object, so as to grasp the progress of the memory allocation task in real time, so as to deal with it in time when an exception occurs.
[0082] Step S24: if the attribute value is the second preset value, and / or the allocation state of the memory object is a completed state or a terminated state, the memory device integration mechanism is triggered, and corresponding control operations are performed on the virtual machine based on the memory device integration mechanism.
[0083] Specifically, when the attribute value of the acquired asynchronous memory pre-allocation attribute is the second preset value, or the allocation status of the memory object is in the completed status or the terminated status, the memory device integration mechanism will be triggered. The memory device integration mechanism is a mechanism for optimizing the management and integration of the memory devices of the virtual machine. When specific conditions (such as attribute value and allocation status conditions) are met, the mechanism will be triggered to reasonably configure and associate the memory device with the Qemu software version through a series of operations to improve the utilization efficiency and overall performance of the virtual machine's memory resources.
[0084] In the embodiment of the present application, triggering the memory device integration mechanism and performing corresponding control operations on the virtual machine based on the memory device integration mechanism include the following steps B1-B2:
[0085] Step B1, adding the virtual dual in-line memory module as a memory device to the configuration environment of the virtual machine through the preset memory management protocol of the virtual machine.
[0086] Specifically, a virtual dual in-line memory module (Personal Computer-Dual In-line Memory Module, PC-DIMM) is a type of computer memory module. In a virtual machine environment, it refers to a concept similar to a physical memory module that is processed in a software simulation manner to provide additional memory resources for the virtual machine. The configuration environment includes various existing hardware resource simulations (such as virtual CPU, virtual disk, etc.) and related software settings (such as operating system, driver, etc.). Adding memory devices in this environment allows the virtual machine to recognize and use the newly added memory resources.
[0087] Step B2: in the configuration environment, establishing an association relationship between the virtual dual in-line memory module and the Qemu software version of the virtual machine.
[0088] Specifically, after adding the virtual dual inline memory module to the virtual machine configuration environment, it is necessary to establish an association between it and the virtual machine Qemu software version. It is necessary to set relevant parameters or data structures in the virtual machine system to identify it, such as adding a pointer to the memory module or recording identification information in the data structure of the Qemu software version, and the virtual dual inline memory module also records the corresponding association information, so that subsequent memory operations can accurately find and coordinate management and optimize the use of virtual machine memory resources.
[0089] In an embodiment of the present application, the method further comprises the following steps:
[0090] Step S31, obtaining memory devices added within a preset time period.
[0091] In an embodiment of the present application, the preset time period refers to a time period corresponding to defining the status of a recently added memory device and performing related processing operations; a memory device refers to a virtual device that provides memory resources for a virtual machine, such as a memory device created by simulating a virtual dual in-line memory module (PC-DIMM), etc. These devices are storage units that can be used when the virtual machine is running, and their addition, use, and management are crucial to the normal operation and performance of the virtual machine.
[0092] Step S32, matching the memory device with the Qemu software version in the virtual machine to obtain a matching result.
[0093] In an embodiment of the present application, after obtaining the memory device information added within a preset time period, each memory device is matched with the Qemu software version in the virtual machine one by one. When matching, the memory device identification information (such as device number, type, etc.) and the Qemu software version management range or adaptation type are compared. For example, by comparing whether the device number is within the management range, whether the type is adapted, etc., the matching result of each memory device and the Qemu software version is obtained, and it is clear whether it matches and the specific matching situation (based on the set rules).
[0094] Step S33, performing corresponding processing operations on the memory device according to the matching result.
[0095] In the embodiment of the present application, step S33 includes the following steps C1-C2:
[0096] Step C1, when the matching result is that the memory device does not match the Qemu software version, obtain the allocation status of the memory object; if the allocation status is a completed state or a terminated state, perform a deletion operation on the memory device; or, if the allocation status is a running state, end the currently running asynchronous memory allocation task, and perform a deletion operation on the memory device after the end.
[0097] Specifically, when the matching result is that the memory device does not match the Qemu software version, first query the data structure related to the virtual machine memory management or call the corresponding query interface to obtain the allocation status of the memory object. If the allocation status is completed or terminated, you can use the relevant protocol (such as the QMP protocol) to send a deletion instruction (such as the qmp object_del command) to delete the unmatched memory device and release resources. If the allocation status is the running status, the memory device cannot be deleted directly. You can end the running asynchronous memory allocation task through specific instructions or operations (such as sending a termination signal in the relevant thread), and then process the memory device in the above deletion method.
[0098] Step C2, when the matching result is that the memory device matches the Qemu software version, monitor the usage requirements for the memory device, obtain the allocation status of the memory object according to the usage requirements, and perform the usage operation on the memory device when the allocation status is a completion state or a termination state.
[0099] Specifically, when the memory device matches the Qemu software version, the memory usage requirements are monitored by monitoring the access and usage of the application and system processes in the virtual machine, and the relevant data structure is queried or the query interface is called to obtain the memory object allocation status according to the monitored usage requirements. If the obtained allocation status is completed or terminated, it can be allocated to the corresponding application or system process by updating the memory mapping table.
[0100] As an example, Figure 4 As shown in the figure, the process includes: first, libvirt uses the virsh command to attach a device configuration file (dimm.xml); checks the memory slots and maximum memory, and allocates memory slots; builds memory device strings and backend properties; creates memory backend objects, memory devices, and updates memory devices. Secondly, libvirt interacts with Qemu through QMP. Qemu adds memory backend objects and PC-DIMM devices and queries memory devices. Qemu pre-allocates backend memory and inserts PC-DIMMs through ACPI notification to create DIMM objects. The guest's udev is online, and the kernel performs memory hot-plug operations.
[0101] In this embodiment, a method for testing a virtual machine memory management technology is provided. Figure 5 is a flow chart of a method for testing a virtual machine memory management technology according to an embodiment of the present invention. Figure 5 As shown, the process includes the following steps:
[0102] Step S41, deploying a preset virtual machine software library in a preset virtual environment, and creating a first virtual machine, a second virtual machine, and a third virtual machine, wherein the second virtual machine is a virtual machine to be tested, and the first virtual machine and the second virtual machine are control virtual machines.
[0103] Specifically, first, deploy and install the libvirt (virtual machine software library) version that supports asynchronous memory pre-allocation. Then, create and start three virtual machines configured as 4C8G, named vm1, vm2 and vm3. These virtual machines are equipped with a virtual network card type called vhost-user network card. Among them, vm1 and vm3 use the open source qemu version virtual machine that does not support this technical solution, while vm2 uses the qemu version virtual machine that supports this technical solution. Such a configuration arrangement is intended to more comprehensively verify the effectiveness of this technical solution by comparing the performance of different versions of virtual machines in the same test scenario.
[0104] Step S42, adding a first memory module of preset capacity to the first virtual machine and the second virtual machine respectively, detecting a first output state of the first virtual machine and a second output state of the second virtual machine, and obtaining a first test result according to the first output state and the second output state.
[0105] Specifically, a 120GB memory was hot-added to each of the virtual machines vm1 and vm2. During the memory addition process, the console output of the virtual machine was checked to see if it was normal (the virtual machine was set to output time information once per second). The result was that the console output of vm1 was interrupted for 18 seconds, while the console output of vm2 remained completely normal.
[0106] Step S43, executing specific commands in the first virtual machine and the second virtual machine respectively to obtain IO reading status, and performing hot-add memory operation on the first virtual machine and the second virtual machine to obtain a second test result.
[0107] Specifically, specific commands are executed inside virtual machines vm1 and vm2 to test the IO reading situation, where the specific command can be: sleep 3&&time dd if= / dev / vda of= / tmp / tmp iflag=direct count=10. This means that the virtual machine is first delayed for 3 seconds, and then the "dd" command is started. In direct I / O mode, a certain amount of data (here set to 10 blocks) is read from the first virtual disk device ( / dev / vda) of the virtual machine, and the read data is filled into the " / tmp / tmp" file. At the same time, the "time" command will record the execution time of the entire "dd" command, so that the disk I / O performance can be accurately evaluated later. In addition, after executing this command, the virtual machine is immediately hot-added with memory. The purpose of this is to observe the impact of the hot-add memory operation on the disk I / O performance. After testing, it was concluded that vm1 took 10.063s to read 5.1k data, while vm2 only took 0.003s, a difference of thousands of times.
[0108] Step S44, adding a second memory module with preset capacity in the first virtual machine and the second virtual machine respectively, and using the third virtual machine to send data streams to the first virtual machine and the second virtual machine, obtaining the first network bandwidth of the first virtual machine and the second network bandwidth of the second virtual machine, and generating a third test result according to the first network bandwidth and the second network bandwidth.
[0109] Specifically, a 120G memory was hot-added to virtual machines vm1 and vm2 respectively. At the same time, the iperf3 command was used in virtual machine vm3 to send data traffic (i.e., traffic) to vm1 and vm2 respectively to observe the network bandwidth of the virtual machines. After testing, it was concluded that the network of vm1 was interrupted, and the interruption time was as long as 20+s, while the network of vm2 was not interrupted and its bandwidth remained normal. This result further highlights the different performance of different virtual machine versions in terms of network bandwidth stability under the memory hot-add operation.
[0110] The testing method provided in the embodiment of the present application can comprehensively verify the performance of the virtual machine memory management-related technical solutions involved in the present application in different aspects (such as console output stability, disk I / O performance, network bandwidth stability, etc.) through the testing steps and corresponding conclusions in the above-mentioned different scenarios, thereby proving its effectiveness in improving the operating performance and stability of the virtual machine.
[0111] In this embodiment, a device for allocating asynchronous memory of a virtual machine is also provided, and the device is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0112] This embodiment provides a virtual machine asynchronous memory allocation device, such as Figure 6 As shown, including:
[0113] A detection module 61 is used to detect whether the Qemu software version of the virtual machine meets the asynchronous memory pre-allocation condition;
[0114] A generating module 62, configured to generate a corresponding object-add command through a preset memory management protocol of the virtual machine if the asynchronous memory pre-allocation condition is met;
[0115] A creation module 63 is used to create a corresponding asynchronous memory allocation task in the iothread of the virtual machine based on the parameters of the object-add command, and set the allocation state of the memory object to the running state;
[0116] The control module 64 is used to control the virtual machine to execute the asynchronous memory allocation task in the iothread, obtain the execution result, and adjust the allocation state of the memory object according to the execution result.
[0117] In an optional embodiment of the present application, the detection module 61 is used to detect whether there is a pre-allocation requirement for the virtual machine's memory; if there is a pre-allocation requirement, query whether the Qemu software version has an asynchronous memory pre-allocation attribute, and if it has the asynchronous memory pre-allocation attribute, set the attribute value of the asynchronous memory pre-allocation attribute to a first preset value, and determine that the Qemu software version meets the asynchronous memory pre-allocation condition; or, if there is no pre-allocation requirement, or does not have the asynchronous memory pre-allocation function, determine that the Qemu software version does not meet the asynchronous memory pre-allocation condition.
[0118] In an optional embodiment of the present application, the control module 64 is used to adjust the allocation state of the memory object to a completed state if the execution result is successful; or, if the execution result is a failure, perform a corresponding rollback operation on the asynchronous memory allocation task and adjust the allocation state of the memory object to a terminated state.
[0119] In an optional embodiment of the present application, the device also includes: a sending module, used to send a main thread release signal to libvirt; receive the main thread release signal through libvirt, and obtain the attribute value of the asynchronous memory pre-allocation attribute; if the attribute value is a first preset value, query the allocation status of the memory object, and when the allocation status is a running state, continue to perform the allocation status monitoring operation; or, if the attribute value is a second preset value, and / or, the allocation status of the memory object is a completed state or a terminated state, trigger the memory device integration mechanism, and perform corresponding control operations on the virtual machine based on the memory device integration mechanism.
[0120] In an optional embodiment of the present application, a sending module is used to add a virtual dual in-line memory module as a memory device to the configuration environment of the virtual machine through the preset memory management protocol of the virtual machine; in the configuration environment, an association relationship is established between the virtual dual in-line memory module and the Qemu software version of the virtual machine.
[0121] In an optional embodiment of the present application, the device also includes: a matching module for obtaining memory devices added within a preset time period; matching the memory devices with the Qemu software version in the virtual machine to obtain a matching result; and performing corresponding processing operations on the memory devices according to the matching results.
[0122] In an optional implementation of the present application, a matching module is used to obtain the allocation status of a memory object when the matching result is that the memory device does not match the Qemu software version; if the allocation status is a completed state or a terminated state, a deletion operation is performed on the memory device; or, if the allocation status is a running state, the currently running asynchronous memory allocation task is terminated, and a deletion operation is performed on the memory device after the end; when the matching result is that the memory device matches the Qemu software version, the usage requirements for the memory device are monitored, the allocation status of the memory object is obtained according to the usage requirements, and when the allocation status is a completed state or a terminated state, a usage operation is performed on the memory device.
[0123] See also Figure 7 , Figure 7 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 7As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system).
[0124] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0125] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.
[0126] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the use of a computer device based on the presentation of a small program landing page, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0127] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0128] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0129] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0130] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A method for allocating asynchronous memory of a virtual machine, characterized in that: The method comprises: Check whether the Qemu software version of the virtual machine meets the asynchronous memory pre-allocation conditions; If the asynchronous memory pre-allocation condition is met, a corresponding object-add command is generated through a preset memory management protocol of the virtual machine; Creating a corresponding asynchronous memory allocation task in the iothread of the virtual machine based on the parameters of the object-add command, and setting the allocation state of the memory object to a running state; The virtual machine is controlled to execute the asynchronous memory allocation task in the iothread, to obtain an execution result, and to adjust the allocation state of the memory object according to the execution result.
2. The method according to claim 1, characterized in that The step of detecting whether the Qemu software version of the virtual machine meets the asynchronous memory pre-allocation condition includes: Detecting whether there is a pre-allocation requirement for the memory of the virtual machine; If the pre-allocation requirement exists, query whether the Qemu software version has an asynchronous memory pre-allocation attribute, and if it has the asynchronous memory pre-allocation attribute, set the attribute value of the asynchronous memory pre-allocation attribute to a first preset value, and determine that the Qemu software version meets the asynchronous memory pre-allocation condition; Or, if the pre-allocation requirement does not exist, or the asynchronous memory pre-allocation function is not provided, it is determined that the Qemu software version does not meet the asynchronous memory pre-allocation condition.
3. The method according to claim 1, characterized in that The adjusting the allocation state of the memory object according to the execution result includes: If the execution result is successful, the allocation state of the Qemu software version is adjusted to a completed state; or, if the execution result is a failure, a corresponding rollback operation is performed on the asynchronous memory allocation task, and the allocation state of the Qemu software version is adjusted to a terminated state.
4. The method according to claim 1, characterized in that: After creating a corresponding asynchronous memory allocation task in the iothread of the virtual machine based on the parameters of the object-add command, the method further includes: Send the main thread release signal to libvirt; Receiving the main thread release signal through the libvirt, and obtaining the attribute value of the asynchronous memory pre-allocation attribute; If the attribute value is a first preset value, querying the allocation state of the memory object, and when the allocation state is a running state, continuing to perform the allocation state monitoring operation; Or, if the attribute value is a second preset value, and / or the allocation state of the memory object is a completed state or a terminated state, a memory device integration mechanism is triggered, and corresponding control operations are performed on the virtual machine based on the memory device integration mechanism.
5. The method according to claim 4, characterized in that The triggering of the memory device integration mechanism and performing corresponding control operations based on the memory device integration mechanism include: Adding a virtual dual in-line memory module as a memory device to a configuration environment of the virtual machine through a preset memory management protocol of the virtual machine; In the configuration environment, an association relationship is established between the virtual dual in-line memory module and the Qemu software version of the virtual machine.
6. The method according to claim 1, characterized in that The method further comprises: Get the memory devices added within a preset time period; Matching the memory device with the Qemu software version in the virtual machine to obtain a matching result; A corresponding processing operation is performed on the memory device according to the matching result.
7. The method according to claim 6, characterized in that The performing a corresponding processing operation on the memory device according to the matching result includes: When the matching result is that the memory device does not match the Qemu software version, the allocation status of the memory object is obtained; if the allocation status is a completed state or a terminated state, a deletion operation is performed on the memory device; or, if the allocation status is a running state, the currently running asynchronous memory allocation task is terminated, and after the task is terminated, a deletion operation is performed on the memory device; When the matching result is that the memory device matches the Qemu software version, monitor the usage requirements for the memory device, obtain the allocation status of the memory object according to the usage requirements, and perform a usage operation on the memory device when the allocation status is a completion state or a termination state.
8. A device for allocating asynchronous memory of a virtual machine, characterized in that: The device comprises: A detection module is used to detect whether the Qemu software version of the virtual machine meets the asynchronous memory pre-allocation conditions; A generation module, configured to generate a corresponding object-add command through a preset memory management protocol of the virtual machine if the asynchronous memory pre-allocation condition is met; A creation module is used to create a corresponding asynchronous memory allocation task in the iothread of the virtual machine based on the parameters of the object-add command, and set the allocation state of the memory object to the running state; The control module is used to control the virtual machine to execute the asynchronous memory allocation task in the iothread, obtain the execution result, and adjust the allocation state of the memory object according to the execution result.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the method according to any one of claims 1 to 7.
Citation Information
Cited By
Virtual machine asynchronous memory allocation method and apparatus, and computer device and storage medium
WO2026114144A1