Memory management method, host computer, electronic device, storage medium and program product

By isolating kernel-mode data in a virtual machine and dynamically adjusting the memory area capacity, the problems of virtual machine memory fragmentation and a fixed ratio of immovable memory are solved, enabling automatic expansion and contraction of memory resources and improved system stability.

CN119988044BActive Publication Date: 2025-10-14ALIBABA CLOUD COMPUTING CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510480284.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-17
Publication Date
2025-10-14
Estimated Expiration
2045-04-17

AI Technical Summary

Technical Problem

In the existing technology, the random allocation of memory blocks in virtual machines leads to fragmentation problems, affecting the elastic scaling capabilities of database services. In addition, the proportion of immovable memory is fixed and cannot be dynamically adjusted according to application scenarios, affecting system stability and performance.

Method used

By isolating kernel-state data in the first memory area and dynamically adjusting the capacity of the first memory area during the operation of the virtual machine, elastic expansion and contraction of kernel-state memory is achieved, and fragmentation-free management is achieved by isolating user-state data in the second memory area.

Benefits of technology

It realizes dynamic adjustment of memory ratio during the operation of virtual machines, solves the fragmentation problem, ensures that database services can automatically expand and shrink memory resources on secure containers, and improves system stability and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119988044B_ABST
    Figure CN119988044B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a memory management method, a host computer, an electronic device, a storage medium and a program product, and relate to the technical field of computers. The method comprises: in response to a memory capacity adjustment request of a virtual machine, determining a target physical memory block from a physical address space of the host computer, wherein the memory capacity adjustment request is triggered during the running of the virtual machine, and is used to request adjustment of the capacity of a first memory area of the virtual machine, and the first memory area is used to allocate virtual memory for the kernel mode data of the virtual machine; and based on the physical address of the target physical memory block, adjusting the address mapping relationship of the first memory area in the physical address space of the host computer. The technical solution of the embodiments of the present application isolates the kernel mode data in the first memory area, and dynamically adjusts the capacity of the first memory area during the running of the virtual machine, thereby realizing the elastic expansion and contraction of the kernel mode memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a memory management method, a host machine, an electronic device, a computer-readable storage medium, and a computer program product. Background Art

[0002] Memory fragmentation occurs when available free blocks in memory are divided into many discontinuous small blocks. Although the total free memory capacity may be sufficient, the scattered memory blocks make it impossible to allocate large, contiguous blocks of memory. To reduce memory fragmentation, you can divide the memory space on a virtual machine into non-removable memory and removable memory. However, if the non-removable memory ratio is set too high, it may lead to insufficient removable memory, affecting elastic memory expansion. If the non-removable memory ratio is set too low, it may also lead to insufficient non-removable memory, affecting system stability and performance. Summary of the Invention

[0003] Embodiments of the present application provide a memory management method, a host machine, an electronic device, a computer-readable storage medium, and a computer program product to alleviate or solve one or more technical problems existing in the prior art.

[0004] In a first aspect, an embodiment of the present application provides a memory management method, comprising: in response to a memory capacity adjustment request of a virtual machine, determining a target physical memory block from the physical address space of a host machine, wherein the memory capacity adjustment request is triggered during the operation of the virtual machine and is used to request adjustment of the capacity of a first memory area of ​​the virtual machine, the first memory area being used to allocate virtual memory for kernel-state data of the virtual machine; and adjusting the address mapping relationship of the first memory area in the physical address space of the host machine based on the physical address of the target physical memory block.

[0005] In a second aspect, an embodiment of the present application provides a memory management method applied to a virtual machine, the memory management method comprising: sending a memory capacity adjustment request during the operation of the virtual machine, wherein the memory capacity adjustment request is used to request adjustment of the capacity of a first memory area of ​​the virtual machine, and the first memory area is used to allocate virtual memory for the kernel state data of the virtual machine.

[0006] In a third aspect, an embodiment of the present application provides a host machine, comprising: a non-volatile memory storing a memory management program; a physical memory providing a physical address space; a processor carrying one or more virtual machines, wherein the processor implements any method of the embodiments of the present application when executing the memory management program.

[0007] In a fourth aspect, an electronic device is provided, which includes a memory, a processor, and a computer program stored in the memory. The processor implements the method of any of the embodiments of the present application when executing the computer program.

[0008] In a fifth aspect, a computer readable storage medium is provided, which stores a computer program. The computer program is executed by a processor to implement the method of any of the embodiments of the present application.

[0009] In a sixth aspect, a computer program product is provided, which includes a computer program. The computer program is executed by a processor to implement the method of any of the embodiments of the present application.

[0010] According to the technical solution of the embodiments of the present application, by isolating the kernel mode data in the first memory area, the fragmentation problem of the kernel mode data in the memory allocation process is avoided to affect other memory areas, and by dynamically adjusting the capacity of the first memory area during the running of the virtual machine, the elastic expansion and contraction of the kernel mode memory is realized, which solves the problem that in the related art, the occupying proportion of the non-movable memory and the movable memory cannot be dynamically adjusted based on the application scenario demand, so that the automatic expansion and contraction of the memory resources can still be realized after the database service is migrated to the secure container.

[0011] The above description is only a summary of the technical solutions of the present application. In order to more clearly understand the technical means of the present application, the description can be implemented according to the content of the specification, and in order to make the above and other purposes, characteristics and advantages of the present application more obvious and easy to understand, the specific embodiments of the present application are described below. BRIEF DESCRIPTION OF DRAWINGS

[0012] In the drawings, the same reference numbers in the several figures indicate corresponding or similar components or elements. The drawings are not necessarily to scale. It should be understood that the drawings only depict some embodiments in accordance with the present application and should not be considered as limiting the scope of the present application.

[0013] Figure 1 A memory management method of a virtual machine in the related art is shown.

[0014] Figure 2A A structural schematic diagram of a host computer 200 provided by an embodiment of the present application is shown.

[0015] Figure 2B A system architecture schematic diagram of a host computer provided by an embodiment of the present application is shown.

[0016] Figure 2C A principle schematic diagram of a memory management method provided by an embodiment of the present application is shown.

[0017] Figure 3 A flowchart of a memory management method according to an embodiment of the present application is shown.

[0018] Figure 4 A diagram showing the memory address spaces of the host and virtual machines.

[0019] Figure 5 A flowchart of a memory management method according to an embodiment of the present application is shown.

[0020] Figure 6 A block diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0021] Hereinafter, only certain exemplary embodiments are briefly described. As will be appreciated by those skilled in the art, the described embodiments may be modified in various ways without departing from the spirit or scope of the present application. Therefore, the drawings and description are to be regarded as illustrative in nature and not restrictive.

[0022] For ease of understanding, let's first introduce the terms used below:

[0023] Kernel state: It is the state or spatial domain in which the operating system kernel (Kernel) runs. The operating system kernel itself runs in kernel state, including key functions such as memory management, process scheduling, file system management, and drivers.

[0024] User state: refers to the state or space domain where applications run at a lower permission level. User state runs all common applications, such as browsers, text editors, games, etc.

[0025] malloc function: a standard memory allocation interface in user space, used to dynamically allocate memory pages of a specified size. The size and number of allocated memory pages can be dynamically adjusted while the program is running.

[0026] Slab allocator: It is a memory allocation mechanism of the Linux operating system. It reduces memory fragmentation and improves allocation efficiency by dividing memory into fixed-size caches (called Slabs). Slab allocator is usually used to allocate and manage fixed-size memory blocks.

[0027] vmalloc function: It is a kernel interface used to allocate virtual memory pages with continuous virtual addresses without requiring the physical memory to be continuous. The continuity of virtual memory pages is achieved by mapping non-contiguous physical pages.

[0028] Page Table (pgtable) interface: This is the interface for managing and allocating page tables. The page table is used by the operating system to represent the mapping between the virtual address and the physical address of a page.

[0029] The Buddy System is a memory management algorithm that efficiently manages and allocates memory by splitting memory blocks into blocks of sizes that are powers of two, thereby reducing memory fragmentation. When the system needs to allocate a block of memory, it first finds the smallest block that meets the requirement. If no block of the appropriate size exists, the system splits the larger block into two equal blocks until a suitable block is found. When memory is no longer in use, the system frees the block and attempts to merge it with an adjacent "buddy" block. If both "buddy" blocks are free and of the same size, they can be merged into a larger block. This process continues recursively until no further merges are possible.

[0030] 32-bit Direct Memory Access 32 (DMA32): is a special memory area used to support devices that require Direct Memory Access (DMA). These devices can only access less than 4GB of physical memory (virtualized physical memory when it is on the virtual machine side). It is used to solve compatibility issues when some 32-bit hardware devices perform DMA on 64-bit systems.

[0031] Conventional Memory (Normal Zone): Also known as Normal memory, it is a commonly used memory area in the operating system, mainly used for memory allocation of kernel state data and normal operations of the operating system.

[0032] Movable Zone: A movable memory area, usually used for memory allocation in user mode (such as anonymous memory mapping and page cache).

[0033] Memory fragmentation: refers to the free blocks available in the memory being divided into many discontinuous small blocks.

[0034] To facilitate understanding of the technical solutions of the embodiments of the present application, the following describes the related technologies of the embodiments of the present application. The following related technologies can be combined with the technical solutions of the embodiments of the present application as optional solutions, and all of them fall within the scope of protection of the embodiments of the present application.

[0035] In the related art, the memory space on a virtual machine (Guest) is usually divided into non-removable memory and removable memory. Figure 1 The memory management method of the virtual machine in the related art is shown as follows: Figure 1As shown, the virtualized physical address space of a virtual machine includes direct memory, non-removable memory, and removable memory. Among them, the virtualized physical address space is the virtual memory allocated to it by the host machine of the virtual machine. Direct memory can enable direct memory access by certain hardware devices, such as DMA32; non-removable memory, such as Normal memory, is usually used to allocate virtual pages that cannot be easily moved, such as allocating virtual pages for the kernel state data of the virtual machine to support the stability of the virtual machine operating system; removable memory is usually used to allocate virtual pages that can be moved, such as allocating virtual pages for user state data to support the elastic expansion and contraction of the virtual machine, thereby isolating kernel state virtual pages and user state virtual pages.

[0036] In an isolation solution based on non-removable and removable memory, when creating a virtual machine, you need to set an appropriate memory usage ratio for non-removable and removable memory based on the virtual machine's application scenario. If the non-removable memory ratio is set too high, removable memory may be insufficient, affecting elastic memory expansion; if the non-removable memory ratio is set too low, it may also lead to insufficient non-removable memory, affecting system stability and performance. Once a virtual machine is created, the non-removable and removable memory usage ratio is fixed and cannot be changed based on changes in the application scenario.

[0037] In an exemplary application scenario, in a cloud-based database service, users do not need to manage the underlying infrastructure; the cloud service provider automatically configures, scales, and manages the database instances. A key feature of cloud-based database services is elastic scaling, which dynamically adjusts infrastructure resources, such as compute and storage, based on load. This reduces resource usage and lowers costs during periods of low traffic (light load) and automatically increases resource allocation during periods of high traffic (heavy load). Therefore, database services need to automatically scale capacity (increasing or decreasing memory capacity) based on database load.

[0038] To ensure database security, database services need to be migrated to secure containers. Secure containers are virtual machines that offer stronger isolation and security than physical machines or lightweight containers. Elastic scaling of database services is also required in secure container environments. However, as virtual machines, secure containers allocate memory blocks (both removable and non-removable) randomly. Consequently, memory blocks are randomly allocated to different physical address spaces or virtualized physical address spaces, which can increase the gaps between memory blocks. Although total free memory capacity may be sufficient, the fragmented nature of these memory blocks prevents the allocation of large, contiguous blocks, leading to fragmentation. Furthermore, non-removable memory is fixed to specific physical addresses and cannot be migrated. Randomly allocating this non-removable memory further exacerbates the fragmentation problem. This fragmentation limits the elastic scaling capabilities of database services.

[0039] In view of this, embodiments of the present application provide a technical solution for memory management, including a memory management method, a host machine, a memory management device, an electronic device, a computer-readable storage medium, and a computer program product. These solutions achieve elastic expansion and contraction of kernel-mode memory by isolating kernel-mode data in a first memory area and dynamically adjusting the capacity of the first memory area during virtual machine operation. Furthermore, user-mode data is isolated in a second memory area, facilitating fragment-free memory management of user-visible memory in the second memory area.

[0040] To facilitate understanding, first combine Figure 2A and Figure 2B Introduce the hardware architecture and software architecture of the embodiment of the present application. Figure 2A FIG2 shows a schematic diagram of the structure of a host machine (Host) 200 provided in an embodiment of the present application. Figure 2B A schematic diagram of the system architecture of a host machine provided in an embodiment of the present application is shown.

[0041] Specifically, if Figure 2A As shown, the hardware layer structure of the host machine 200 may include a processor 201, non-volatile memory 202, and physical memory 203. The processor 201 is, for example, a central processing unit (CPU); the physical memory 203 is, for example, random access memory (RAM), which provides the physical address space of the host machine 200. The number of processors 201, non-volatile memory 202 (such as a solid-state drive or flash memory), and physical memory 203 can be one or more, and they are interconnected via a bus 204 to facilitate communication.

[0042] When the host machine (Host) 200 is started, the processor 201 first reads the startup program from the non-volatile memory 202 to load the Host operating system 206, such as Figure 2B As shown in the figure, the host operating system 206 runs in the host kernel space, controlling and managing actual hardware resources (including the processor 201, non-volatile memory 202, and physical memory 203), and running one or more host applications 207. The host user space provides an environment for running host applications 207 on the host operating system 206. Furthermore, in a virtualization scenario, the host operating system 206 runs a virtual machine manager (VMM), thereby starting one or more virtual machines (VMs) 205. The VMM is responsible for virtualizing the hardware resources in the virtual machines 205 and managing the virtual hardware resources of the virtual machines 205. The virtual machine operating system (i.e., the guest operating system) runs in the guest kernel space, and the virtual machine applications (i.e., the guest applications) run in the guest user space.

[0043] In the embodiment of the present application, a memory management program is stored on the non-volatile memory 202. When the processor 201 executes the memory management program, the memory management method of the embodiment of the present application can be implemented. Figure 2C Give a detailed introduction.

[0044] Figure 2C A schematic diagram illustrating the principles of the memory management method provided by an embodiment of the present application is shown. The memory management component (virtio-mem) is a functional component in the VMM. When creating a virtual machine (Guest), the initial capacity of the first memory area is defined in the virtual machine configuration, and the function of the first memory area is defined to allocate virtual memory for the kernel-state data of the virtual machine. Similarly, the initial capacity of the second memory area is defined in the virtual machine configuration, and the function of the second memory area is defined to allocate virtual memory for the user-state data of the virtual machine. The VMM can divide the physical address space of the host machine into a first physical memory area and a second physical memory area that are independent of each other, and map the first physical memory area to the first memory area and the second physical memory area to the second memory area through virtio-mem.

[0045] During the operation of a virtual machine, the virtual machine can send a memory capacity adjustment request for a first memory zone to the VMM via virtio-mem, requesting that the capacity of the first memory zone of the virtual machine be adjusted. In response to the memory capacity adjustment request, the VMM determines the target physical memory block corresponding to the memory capacity adjustment request from the physical address space of the host machine and adjusts the address mapping relationship of the target physical memory block to the first memory zone, that is, adjusts the address mapping relationship between the target physical memory block and the first memory zone.

[0046] Similarly, the virtual machine can send a memory capacity adjustment request for the second memory zone to the VMM via virtio-mem, requesting that the capacity of the second memory zone of the virtual machine be adjusted. In response to the memory capacity adjustment request, the VMM determines the target physical memory block corresponding to the memory capacity adjustment request from the physical address space of the host machine and adjusts the address mapping relationship of the target physical memory block in the second memory zone, that is, adjusts the address mapping relationship between the target physical memory block and the second memory zone.

[0047] In the technical solution of the embodiment of the present application, by isolating kernel-state data in the first memory area, that is, the first memory area replaces the non-removable memory in the related art, and isolating user-state data in the second memory area for removable memory, it is avoided that the memory allocation of kernel-state data affects the second memory area. And during the operation of the virtual machine, the capacity of the first memory area is dynamically adjusted to achieve elastic expansion and contraction of kernel-state memory, solving the problem in the related art that the occupancy ratio of non-removable memory and removable memory cannot be dynamically adjusted based on the application scenario requirements, so that the database service can still achieve automatic expansion and contraction of memory resources after migrating to the secure container. Furthermore, the user-visible memory can be managed in a non-fragmented manner in the second memory area, thereby reducing the fragmentation problem caused by random allocation of memory blocks while achieving secure isolation between kernel-state data and user-state data.

[0048] Figure 3 The flowchart of the memory management method of the embodiment of the present application is shown, and the memory management method can be applied to the host machine, for example, implemented by the VMM. Figure 3 As shown, the memory management method may include step S301 and step S302.

[0049] Step S301: In response to the memory capacity adjustment request of the virtual machine, determine the target physical memory block from the physical address space of the host machine, wherein the memory capacity adjustment request is triggered during the operation of the virtual machine and is used to request adjustment of the capacity of the first memory area of ​​the virtual machine, and the first memory area is used to allocate virtual memory for the kernel state data of the virtual machine.

[0050] Kernel state data refers to various data structures and information used and managed by the guest operating system during operation, including but not limited to process information, memory management data, file system data, driver data, etc. The first memory area is used to allocate virtual memory, such as virtual memory pages, for the kernel state data of the virtual machine.

[0051] Figure 4 A schematic diagram showing the memory address space of the host machine and the virtual machine. Figure 4 As shown, the memory address space can be divided into the physical address space on the host side, the virtualized physical address space on the guest side, and the virtual address space on the guest side. Each memory management granularity can be called a page, or also called a memory block. Each page corresponds to its own memory address. Physical memory pages have physical addresses in the physical address space, virtual memory pages have virtual addresses in the virtual address space, and virtualized physical memory pages have virtualized physical addresses in the virtualized physical address space. The address mapping relationship between the virtualized physical address space and the virtual address space is represented by the first page table, and the address mapping relationship between the physical address space and the virtualized physical address space is represented by the second page table.

[0052] The VMM can select physical memory pages with continuous or discontinuous physical addresses from the physical address space and allocate virtual memory pages with address mapping relationships to these physical memory pages to each process on the guest, thereby constructing a virtualized physical address space on the guest side. In other words, the virtualized physical address space on the guest side contains multiple virtual memory pages allocated by the host side, but from the guest's perspective, these virtual memory pages are its physical memory pages. Therefore, in the embodiments of the present application, the virtual memory pages allocated by the host to the guest are called virtualized physical memory pages.

[0053] When creating a guest, the VMM defines the initial capacity of the first memory area in the virtual machine configuration and defines the function of the first memory area as allocating virtual memory for the kernel state data of the virtual machine; the VMM divides the first physical memory area and the second physical memory area from the physical address space of the host machine, maps the first physical memory area to the first memory area through virtio-mem, and updates the address mapping relationship between the first physical memory area and the first memory area in the second page table.

[0054] The guest's memory management module selects virtualized physical memory pages with continuous or discontinuous virtualized physical addresses from the virtualized physical address space and allocates virtual memory pages that have address mappings to these virtualized physical memory pages to each process on the guest, thereby constructing the guest's virtual address space. In other words, the guest's virtual address space consists of multiple virtual memory pages.

[0055] For example, when a guest process of a virtual machine needs to allocate virtual memory (e.g., a virtual memory page) for kernel-mode data, it passes information containing a memory allocation identifier to a memory allocation interface. This information may indicate that the memory allocation originates from the first memory area, thereby allocating a virtual memory page for the kernel-mode data of the virtual machine in the first memory area. After the virtual memory page is allocated, the address mapping of the virtual memory page to the first memory area is updated in the first page table.

[0056] During the operation of a virtual machine, the virtual machine may trigger a memory capacity adjustment request for a first memory area. For example, the virtual machine may detect kernel-mode data traffic and, based on traffic changes, determine whether to trigger a memory capacity adjustment request for the first memory area. For example, when the traffic exceeds a certain threshold, the virtual machine may send a memory expansion request for the first memory area to the VMM to request an increase in the capacity of the first memory area; or, when the traffic falls below another threshold, the virtual machine may send a memory reduction request for the first memory area to the VMM to request a decrease in the capacity of the first memory area.

[0057] In response to the memory capacity adjustment request of the virtual machine, the VMM determines the target physical memory block from the physical address space of the host machine. The target physical memory block is a memory block that has an address mapping relationship with the capacity adjustment portion of the first memory area. For example, Figure 4 As shown, the VMM responds to the memory capacity adjustment request for the first memory area and determines the target physical memory block. For example, if the memory capacity adjustment request is a memory expansion request, a physical memory block of a corresponding size can be selected from the physical address space as the target physical memory block based on the memory size of the increased capacity carried in the memory expansion request. For another example, if the memory capacity adjustment request is a memory reduction request, a physical memory block corresponding to the virtualized physical address information (such as the starting address and memory size) carried in the memory reduction request can be selected from the physical address space as the target physical memory block.

[0058] Step S302: Based on the physical address of the target physical memory block, adjust the address mapping relationship of the first memory area in the physical address space of the host machine.

[0059] The address mapping relationship of the first memory area in the physical address space of the host machine is the mapping relationship between the virtualized physical address of the first memory area and the physical address of the target physical memory block. Exemplarily, adjusting the address mapping relationship of the first memory area in the physical address space of the host machine includes: when expanding the capacity of the first memory area, establishing the address mapping relationship of the target physical memory block in the first memory area, and Figure 4 The address mapping relationship is updated in the second page table shown; when the first memory area is reduced in size, the address mapping relationship of the target physical memory block on the first memory area is released, and the address mapping relationship is updated in the second page table.

[0060] According to the technical solution of the embodiments of the present application, by isolating kernel-mode data in the first memory area, contamination of other memory areas (user-mode data memory allocation areas) is avoided. For example, the fragmentation of kernel-mode data during memory allocation is prevented from affecting other memory areas. At the same time, the first memory area is configured as a reserved area for para-virtualization (PV) memory. That is, during the operation of the virtual machine, the capacity of the first memory area is dynamically adjusted to achieve elastic expansion and contraction of kernel-mode memory. This solves the problem in related technologies of being unable to dynamically adjust the usage ratio of non-removable and removable memory based on application scenario requirements. This allows the database service to continue to achieve automatic expansion and contraction of memory resources after migrating to a secure container.

[0061] In one embodiment, the memory capacity adjustment request is triggered by detecting the operating load of the virtual machine, where the operating load includes at least one database load indicator.

[0062] The operational load refers to the actual resource consumption (e.g., CPU, memory, disk I / O, network bandwidth, etc.) of a virtual machine during operation, including CPU utilization, memory usage, disk I / O bandwidth, network traffic, and database load metrics. Database load metrics are parameters that measure the current operational status of the database and are used to determine whether resource adjustments (e.g., memory) are necessary. Database load metrics include, but are not limited to: Queries Per Second (QPS), which refers to the total number of user queries processed by the system per unit time; Transactions Per Second (TPS), which refers to the number of transaction commits completed per unit time; Cache Hit Rate, which refers to the number of cache hits or the total number of queries; Lock Wait Time, which refers to the time a transaction is delayed due to waiting for a lock; and Number of Connections, which refers to the number of connections to the current database.

[0063] Exemplarily, the virtual machine collects data on the virtual machine's operating load by calling a corresponding operating load monitoring interface or using a dedicated operating load monitoring tool, such as a database system that provides an indicator value monitoring tool for viewing database load indicators. By presetting a threshold, and when it is detected that the virtual machine's operating load exceeds the corresponding threshold, a memory capacity adjustment request is triggered, including: a preset expansion threshold, that is, when the virtual machine detects that its operating load is greater than the expansion threshold, a memory expansion request is triggered; a preset reduction threshold, that is, when the virtual machine detects that its operating load is less than the reduction threshold, a memory reduction request is triggered. Among them, an indicator threshold can be preset for each database load indicator, and the virtual machine triggers a memory capacity adjustment request when it detects that the indicator value of a certain database load indicator exceeds the corresponding indicator threshold.

[0064] Based on this, the technical solutions of the embodiments of this application can be applied to scenarios where database services are migrated to secure containers. The secure container, acting as a virtual machine, automatically scales memory resources allocated to kernel-mode data by detecting the secure container's traffic (indicator values ​​of database load indicators).

[0065] In one implementation, the memory capacity adjustment request includes a memory expansion request, which is used to request an increase in the capacity of the first memory area; in step S301, a target physical memory block is determined from the physical address space of the host machine, including: allocating an idle physical memory block from the physical address space of the host machine as the target physical memory block; in step S302, based on the physical address of the target physical memory block, an address mapping relationship of the first memory area in the physical address space of the host machine is adjusted, including: establishing an address mapping relationship between the physical address of the target physical memory block and the address of the first memory area.

[0066] As an example, when a virtual machine detects that its operating load is greater than the expansion threshold, a memory expansion request can be triggered through virtio-mem. The VMM responds to the memory expansion request and allocates an idle physical memory block from the host machine's physical address space as the target physical memory block. For example, the memory expansion request can carry the starting address of the virtualized physical address and the size of the virtualized physical memory block (i.e., the size of the memory to be increased); the VMM selects a physical memory block of the corresponding size and in an idle state (i.e., unallocated) from the physical address space as the target physical memory block.

[0067] Establishing an address mapping relationship of the target physical memory block on the first memory area can be understood as mapping the target physical memory block to the first memory area, such as assigning a virtualized physical address belonging to the first memory area to the target physical memory block, which can be a starting virtualized physical address, and then establishing a mapping relationship between the starting physical address of the target physical memory block and the starting virtualized physical address. Furthermore, updating the address mapping relationship of the first memory area in the physical address space of the host machine, that is, updating the address mapping relationship between the first memory area and the first physical memory area in the second page table.

[0068] Based on this, when the virtual machine's operating load is high, the memory resource allocation for kernel data can be automatically expanded.

[0069] In one embodiment, the above-mentioned establishment of the address mapping relationship of the target physical memory block on the first memory area may include: allocating a continuous virtualized physical address belonging to the first memory area to the target physical memory block; and establishing a mapping relationship between the physical address of the target physical memory block and the continuous virtualized physical address.

[0070] Among them, the physical address of the target physical memory block can be continuous. For example, the VMM can allocate a target physical memory block of continuous physical pages through a partner system, and allocate a continuous virtualized physical address to the target physical memory block, mark the continuous virtualized physical address as belonging to the first memory area, and then update the mapping relationship between this continuous virtualized physical address and the physical address of the target physical memory block in the second page table.

[0071] Based on this, the continuity of the virtualized physical address of the first memory area can be ensured, and the memory fragmentation problem can be alleviated.

[0072] In another implementation, the memory capacity adjustment request includes a memory reduction request, which is used to request to reduce the capacity of the first memory area; in step S301, the target physical memory block is determined from the physical address space of the host machine, including: determining the target physical memory block based on the address mapping relationship of the capacity-reduced part of the first memory area in the physical address space of the host machine; in step S302, based on the physical address of the target physical memory block, adjusting the address mapping relationship of the target physical memory block in the first memory area in the physical address space of the host machine, including: releasing the address mapping relationship between the physical address of the target physical memory block and the first memory area.

[0073] As an example, when a virtual machine detects that its running load is less than a reduction threshold, a memory reduction request can be triggered through virtio-mem. The VMM responds to the memory reduction request and determines the target physical memory block based on the address mapping relationship of the capacity-reduced portion of the first memory area on the physical address space of the host machine. Exemplarily, the memory reduction request can carry the starting address of the capacity-reduced portion of the first memory area and the size of the virtualized physical memory block (i.e., the size of the memory with reduced capacity); the VMM searches the second page table and finds the physical address mapped to the capacity-reduced portion on the physical address space of the host machine based on the starting address and the size of the virtualized physical memory block. The physical memory block corresponding to the physical address is the target physical memory block.

[0074] Removing the mapping relationship between the physical address of the target physical memory block and the address of the first memory area can be understood as deleting the virtualized physical address mapped by the target physical memory block in the second page table.

[0075] Based on this, when the virtual machine's operating load is low, the memory resource allocation for kernel data can be automatically reduced.

[0076] In one embodiment, the method of the embodiment of the present application may further include: during the creation process of the virtual machine, determining a first physical memory area from the physical address space of the host machine; and establishing an address mapping relationship between the first physical memory area and the first memory area.

[0077] The first memory area has continuous virtualized physical addresses, meaning it has continuous addresses in the virtualized physical address space. For example, when creating a virtual machine (guest), the VMM can carve out the first physical memory area from the host machine's physical address space. For example, the VMM allocates continuous physical memory pages through the buddy system and reserves a continuous address range in the virtualized physical address space of the virtual machine. The size of this range should match the allocated physical memory size. For example, if a 4MB first physical memory area is allocated, the address range from 0x10000000 to 0x10040000 is reserved in the virtualized physical address space.

[0078] Furthermore, an address mapping relationship is established between the first physical memory area and the first memory area, that is, each virtualized physical address in the first memory area corresponds to a physical address in the first physical memory area. For example, before the virtual machine starts, the VMM initializes the address mapping relationship between the first physical memory area and the first memory area using the second page table. After the virtual machine starts, it updates its own first page table based on the information about the first memory area provided by the VMM, which is used to allocate virtual memory pages for its kernel state data.

[0079] In one embodiment, the method of the embodiment of the present application may further include: during the creation of the virtual machine, determining a second physical memory area different from the first physical memory area from the physical address space of the host machine; and establishing an address mapping relationship between the second physical memory area and the second memory area. The second memory area has a virtualized physical address different from the first memory area and is used to allocate virtual memory for user state data of the virtual machine.

[0080] User-state data refers to data used by applications running in user mode within a virtual machine's operating system. A first memory area and a second memory area are defined independently within the virtual machine's virtualized physical address space. Virtual memory is allocated from the second memory area for the virtual machine's user-state data. Each user-state process in a virtual machine has an independent virtual address space. Therefore, in a virtualized environment, the second memory area is configured as the virtual machine's system random access memory (RAM), providing memory resources for the virtual machine's applications.

[0081] For example, when creating a virtual machine, the VMM can separate a first physical memory area and a second physical memory area from the host machine's physical address space. For example, the VMM allocates contiguous physical memory pages through a partner system as the first physical memory area, and allocates contiguous or discontiguous physical memory pages through the partner system as the second physical memory area. During the allocation process, the VMM ensures that the first and second physical memory areas do not have overlapping physical addresses. Furthermore, a contiguous address range is reserved in the virtualized physical address space of the virtual machine as the first memory area, and a contiguous or discontiguous address range is reserved as the second memory area.

[0082] Furthermore, an address mapping relationship is established between the second physical memory area and the second memory area, that is, each virtualized physical address in the second memory area corresponds to a physical address in the second physical memory area. For example, before the virtual machine starts, the VMM initializes the address mapping relationship between the second physical memory area and the second memory area using the second page table. After the virtual machine starts, it updates its first page table based on the information about the second memory area provided by the VMM to allocate virtual memory pages for its user-mode data.

[0083] Similar to the first memory area, the virtual machine can send a memory capacity adjustment request for the second memory area to the VMM through virtio-mem, requesting that the capacity of the second memory area of ​​the virtual machine be adjusted. In response to the memory capacity adjustment request, the VMM determines the physical memory block corresponding to the memory capacity adjustment request from the physical address space of the host machine and, based on the physical address of the physical memory block, adjusts the address mapping relationship between the physical address and the address of the second memory area.

[0084] Based on this, user-mode data is isolated in the second memory area (System RAM), facilitating fragment-free memory management of user-visible memory in this area. This reduces the fragmentation caused by randomly allocated memory blocks while ensuring secure isolation between kernel-mode and user-mode data. Methods for fragment-free memory management of user-visible memory in the second memory area include, but are not limited to: merging standard pages (4KB) into large pages (e.g., 2MB, 1GB); utilizing a buddy system for contiguous memory allocation; and releasing cold pages and merging them with hot pages.

[0085] Figure 5 FIG1 shows a flow chart of a memory management method according to an embodiment of the present application, which can be applied to a virtual machine. Figure 5 As shown, the memory management method may include: Step S501: During the operation of a virtual machine, sending a memory capacity adjustment request, wherein the memory capacity adjustment request is used to request adjustment of the capacity of a first memory area of ​​the virtual machine, the first memory area being used to allocate virtual memory for kernel-mode data of the virtual machine. The specific implementation and technical effects are described above and will not be repeated here.

[0086] It should be noted that the above-mentioned application scenarios or application examples provided in the embodiments of this application are for ease of understanding, and the embodiments of this application do not specifically limit the application of the technical solution. In addition, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation portals for users to choose to authorize or refuse.

[0087] Corresponding to the memory management method provided in the embodiment of the present application, the embodiment of the present application also provides a memory management device, which includes: a target physical memory block determination module, used to determine the target physical memory block from the physical address space of the host machine in response to the memory capacity adjustment request of the virtual machine, wherein the memory capacity adjustment request is triggered during the operation of the virtual machine and is used to request adjustment of the capacity of the first memory area of ​​the virtual machine, and the first memory area is used to allocate virtual memory for the kernel state data of the virtual machine; an address mapping relationship adjustment module, used to adjust the address mapping relationship of the target physical memory block in the first memory area in the physical address space of the host machine based on the physical address of the target physical memory block.

[0088] In one embodiment, the memory capacity adjustment request includes a memory expansion request, and the memory expansion request is used to request to increase the capacity of the first memory area; the target physical memory block determination module is specifically used to: allocate a physical memory block in an idle state from the physical address space of the host machine as the target physical memory block; the address mapping relationship adjustment module is specifically used to: establish a physical address mapping relationship between the physical address of the target physical memory block and the address of the first memory area.

[0089] In one embodiment, the address mapping relationship adjustment module is specifically used to: allocate a continuous virtualized physical address belonging to the first memory area to the target physical memory block; and establish a mapping relationship between the physical address of the target physical memory block and the virtualized physical address.

[0090] In one embodiment, the memory capacity adjustment request includes a memory reduction request, and the memory reduction request is used to request to reduce the capacity of the first memory area; the target physical memory block determination module is specifically used to: determine the target physical memory block based on the address mapping relationship of the capacity reduction part of the first memory area in the physical address space of the host machine; the address mapping relationship adjustment module is specifically used to: release the address mapping relationship between the physical address of the target physical memory block and the address of the first memory area.

[0091] In one embodiment, the memory capacity adjustment request is triggered by detecting an operating load of the virtual machine, where the operating load includes at least one database load indicator.

[0092] In one embodiment, the device also includes a first physical memory area creation module, which is used to determine the first physical memory area from the physical address space of the host machine during the creation process of the virtual machine; establish an address mapping relationship between the first physical memory area and the first memory area, wherein the first memory area has a continuous virtualized physical address.

[0093] In one embodiment, the device also includes a second physical memory area creation module, which is used to determine a second physical memory area different from the first physical memory area from the physical address space of the host machine during the creation process of the virtual machine; establish an address mapping relationship between the second physical memory area and the second memory area, wherein the second memory area has a virtualized physical address different from the first memory area, and is used to allocate virtual memory for user-state data of the virtual machine.

[0094] Corresponding to the memory management method provided in the embodiment of the present application, the embodiment of the present application also provides a memory management device, which is applied to a virtual machine and includes: a memory capacity adjustment request module, which is used to send a memory capacity adjustment request during the operation of the virtual machine, wherein the memory capacity adjustment request is used to request adjustment of the capacity of the first memory area of ​​the virtual machine, and the first memory area is used to allocate virtual memory for the kernel state data of the virtual machine.

[0095] The functions of each module in each device in the embodiment of the present application can be referred to the corresponding description in the above method, and have corresponding beneficial effects, which will not be repeated here.

[0096] Figure 6 FIG. 1 is a block diagram of an electronic device for implementing an embodiment of the present application. Figure 6 As shown, the electronic device includes a memory 601 and a processor 602. The memory 601 stores a computer program executable by the processor 602. When the processor 602 executes the computer program, the method described in the above embodiment is implemented. The number of the memory 601 and the processor 602 can be one or more. In a specific implementation, the electronic device may also include a communication interface 603 for communicating with external devices and exchanging data.

[0097] In a specific implementation, if the memory 601, processor 602, and communication interface 603 are implemented independently, the memory 601, processor 602, and communication interface 603 can be connected to each other via a bus and communicate with each other. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.

[0098] Optionally, in a specific implementation, if the memory 601 , the processor 602 , and the communication interface 603 are integrated on a chip, the memory 601 , the processor 602 , and the communication interface 603 may communicate with each other through an internal interface.

[0099] An embodiment of the present application provides a computer-readable storage medium storing a computer program, which implements the method provided in the embodiment of the present application when the program is executed by a processor.

[0100] An embodiment of the present application provides a computer program product, including a computer program, which implements the method provided in the embodiment of the present application when executed by a processor.

[0101] An embodiment of the present application also provides a chip, which includes a processor for calling and executing instructions stored in the memory from the memory, so that a communication device equipped with the chip executes the method provided in the embodiment of the present application.

[0102] An embodiment of the present application also provides a chip, including: an input interface, an output interface, a processor and a memory. The input interface, the output interface, the processor and the memory are connected through an internal connection path. The processor is used to execute the code in the memory. When the code is executed, the processor is used to execute the method provided in the embodiment of the application.

[0103] It should be understood that the processor described above may be a CPU, or other general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, etc. The general-purpose processor may be a microprocessor or any conventional processor. It is worth noting that the processor may be a processor that supports the Advanced RISC Machines (ARM) architecture.

[0104] Furthermore, optionally, the aforementioned memory may include read-only memory and random access memory. The memory may be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. Non-volatile memory may include read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory may include random access memory (RAM), which serves as an external cache memory. By way of example and not limitation, many forms of RAM are available. For example, static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM) and direct memory bus random access memory (DR RAM).

[0105] In the above embodiments, all or part of the embodiments may be implemented using software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments may be implemented in the form of a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the present application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another.

[0106] In the description of this specification, the reference terms "one embodiment," "some embodiments," "example," "specific example," or "some examples" mean that the specific features, structures, materials, or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. Moreover, the specific features, structures, materials, or characteristics described may be combined in any appropriate manner in any one or more embodiments or examples. In addition, those skilled in the art may combine and integrate different embodiments or examples described in this specification, as well as features of different embodiments or examples, unless they are mutually inconsistent.

[0107] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features being referred to. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. Throughout the description of this application, "plurality" means two or more, unless otherwise specifically defined.

[0108] Any process or method described in the flowchart or otherwise described herein can be understood to represent a module, segment or portion of code comprising one or more executable instructions for implementing the steps of a specific logical function or process. The scope of the preferred embodiments of the present application includes other implementations in which the functions may be performed in a different order than shown or discussed, including performing the functions substantially simultaneously or in reverse order depending on the functions involved.

[0109] The logic and / or steps described in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, apparatus or device (such as a computer-based system, a system including a processor, or other system that can fetch instructions from and execute instructions on an instruction execution system, apparatus or device), or used in conjunction with such instruction execution systems, apparatuses or devices.

[0110] It should be understood that various parts of the present application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. All or part of the steps of the above embodiment method can be completed by instructing the relevant hardware through a program, which can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiment.

[0111] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing module, or each unit may exist physically separately, or two or more units may be integrated into a single module. The aforementioned integrated modules may be implemented in the form of hardware or in the form of software functional modules. If the aforementioned integrated modules are implemented in the form of software functional modules and sold or used as independent products, they may also be stored in a computer-readable storage medium. The storage medium may be a read-only memory, a magnetic disk, or an optical disk, etc.

[0112] The above is merely an exemplary embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily conceive of various modifications or substitutions within the technical scope described in this application, and such modifications or substitutions should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

Claims

1. A memory management method, applied to a virtual machine manager of a host machine, comprising: In response to a memory capacity adjustment request sent by the virtual machine to the virtual machine manager through the memory management component virtio-mem, determining a target physical memory block from the physical address space of the host machine, wherein the memory capacity adjustment request is triggered during the operation of the virtual machine and is used to request adjustment of the capacity of a first memory area of ​​the virtual machine during the operation of the virtual machine, the first memory area being allocated to the virtual machine by the virtual machine manager when the virtual machine is created and being used to allocate virtual memory for kernel state data of the virtual machine; Adjusting an address mapping relationship of the first memory area in the physical address space of the host machine based on the physical address of the target physical memory block; In response to a second memory capacity adjustment request for a second memory area sent by the virtual machine to the virtual machine manager through virtio-mem, determining a second physical memory block corresponding to the second memory capacity adjustment request from the physical address space of the host machine, wherein the second memory capacity adjustment request is triggered during the operation of the virtual machine and is used to request adjustment of the capacity of the second memory area of ​​the virtual machine during the operation of the virtual machine, the second memory area is allocated to the virtual machine by the virtual machine manager when the virtual machine is created, the second memory area has a virtualized physical address different from that of the first memory area, and is used to allocate virtual memory for user state data of the virtual machine; Based on the physical address of the second physical memory block, an address mapping relationship of the second memory area in the physical address space of the host machine is adjusted.

2. The method according to claim 1, wherein The memory capacity adjustment request includes a memory capacity expansion request, and the memory capacity expansion request is used to request to increase the capacity of the first memory area; The determining the target physical memory block from the physical address space of the host machine includes: allocating a physical memory block in an idle state from the physical address space of the host machine as the target physical memory block; The adjusting the address mapping relationship of the first memory area in the physical address space of the host machine based on the physical address of the target physical memory block includes: establishing an address mapping relationship between the physical address of the target physical memory block and the first memory area.

3. The method according to claim 2, wherein: Establishing a mapping relationship between the physical address of the target physical memory block and the address of the first memory area includes: Allocating a continuous virtualized physical address belonging to the first memory area to the target physical memory block; A mapping relationship between the physical address of the target physical memory block and the virtualized physical address is established.

4. The method according to claim 1, wherein The memory capacity adjustment request includes a memory shrinkage request, and the memory shrinkage request is used to request to reduce the capacity of the first memory area; The determining of the target physical memory block from the physical address space of the host machine comprises: determining the target physical memory block based on an address mapping relationship of the capacity-reduced portion of the first memory area in the physical address space of the host machine; The adjusting the address mapping relationship of the first memory area in the physical address space of the host machine based on the physical address of the target physical memory block includes: releasing the address mapping relationship between the physical address of the target physical memory block and the first memory area.

5. The method according to claim 1, wherein The memory capacity adjustment request is triggered by detecting the operating load of the virtual machine, and the operating load includes at least one database load indicator.

6. The method according to any one of claims 1 to 5, further comprising: During the creation of the virtual machine, determining a first physical memory area from the physical address space of the host machine; An address mapping relationship is established between the first physical memory area and the first memory area, wherein the first memory area has a continuous virtualized physical address.

7. The method according to claim 6, further comprising: During creation of the virtual machine, determining a second physical memory area different from the first physical memory area from the physical address space of the host machine; An address mapping relationship is established between the second physical memory area and the second memory area.

8. A memory management method, applied to a virtual machine, the memory management method comprising: During the operation of the virtual machine, a memory capacity adjustment request is sent to the virtual machine manager of the host machine where the virtual machine is located through virtio-mem, wherein the memory capacity adjustment request is used to request adjustment of the capacity of a first memory area of ​​the virtual machine during the operation of the virtual machine, where the first memory area is allocated to the virtual machine by the virtual machine manager when the virtual machine is created and is used to allocate virtual memory for kernel state data of the virtual machine; During the operation of the virtual machine, a second memory capacity adjustment request for the second memory area is sent to the virtual machine manager through virtio-mem, wherein the second memory capacity adjustment request is used to request adjustment of the capacity of the second memory area of ​​the virtual machine during the operation of the virtual machine, the second memory area is allocated to the virtual machine by the virtual machine manager when creating the virtual machine, the second memory area has a virtualized physical address different from that of the first memory area, and is used to allocate virtual memory for user state data of the virtual machine.

9. A host machine, comprising: A non-volatile memory storing a memory management program; Physical memory, which provides physical address space; A processor carrying one or more virtual machines, wherein the processor implements the method according to any one of claims 1 to 8 when executing the memory management program.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory, wherein the processor implements the method according to any one of claims 1 to 8 when executing the computer program.

11. A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.

12. A computer program product comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Memory management method, host machine, electronic equipment, storage medium and program product

    CN118819871A