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

By dynamically adjusting the capacity of the first memory area where the kernel state data is located in the virtual machine and performing fragmentation-free management in the second memory area where the user state data is located, the problem of the inability to dynamically adjust the memory usage ratio in the prior art is solved, and the memory resources of the database service in the secure container are automatically expanded.

CN119988044AActive Publication Date: 2025-05-13ALIBABA CLOUD COMPUTING CO LTD

Patent Information

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

AI Technical Summary

Technical Problem

In the prior art, it is impossible to dynamically adjust the proportion of immovable memory and removable memory based on application scenario requirements, resulting in the automatic scaling capacity of database services in the secure container.

Method used

By isolating kernel-state data in the first memory area and dynamically adjusting the capacity of the first memory area during the virtual machine operation, the elastic expansion and expansion of kernel-state memory is achieved. At the same time, the user-state data is isolated in the second memory area for fragmented memory management.

Benefits of technology

It realizes automatic expansion and scaling of memory resources, solves the lack of dynamic adjustment of the proportion of immovable memory and removable memory usage, reduces the problem of memory fragmentation, and ensures the elastic scaling ability of database services.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119988044A_ABST
    Figure CN119988044A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a memory management method, a host machine, electronic equipment, a storage medium and a program product, and relates to the technical field of computers.The method comprises the steps that in response to a memory capacity adjusting request of a virtual machine, a target physical memory block is determined from a physical address space of the host machine, the memory capacity adjustment request is triggered in the running process of the virtual machine and is used for requesting to adjust the capacity of a first memory area of the virtual machine, and the first memory area is used for allocating a virtual memory for 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 on the physical address space of the host machine. According to the technical scheme provided by the embodiment of the invention, the kernel mode data is isolated in the first memory area, and the capacity of the first memory area is dynamically adjusted in the running process of the virtual machine, so that the elastic capacity expansion and shrinkage of the kernel mode memory are realized.
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 means that the available free blocks in the memory are divided into many discontinuous small blocks. Although the total free memory capacity may be sufficient, these memory blocks are scattered and large blocks of continuous memory cannot be allocated. In order to reduce memory fragmentation, the memory space on the virtual machine can be divided into non-removable memory and removable memory. However, if the proportion of non-removable memory is set too high, it may lead to insufficient removable memory, thus affecting memory elastic expansion; if the proportion of non-removable memory is set too low, it may lead to insufficient non-removable memory, thus 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; 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 machine.

[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: during the operation of the 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, and the first memory area is used to allocate virtual memory for 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 embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory, and the processor implements any method of the embodiment of the present application when executing the computer program.

[0008] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the method of any one of the embodiments of the present application is implemented.

[0009] In a sixth aspect, an embodiment of the present application provides a computer program product, including a computer program, which implements any method of the embodiments of the present application when executed by a processor.

[0010] According to the technical solution of the embodiment of the present application, by isolating kernel-state data in the first memory area, the fragmentation problem of kernel-state data in the memory allocation process is prevented from affecting other memory areas, and by dynamically adjusting the capacity of the first memory area during the operation of the virtual machine, the elastic expansion and contraction of the kernel-state memory is achieved, which solves the problem in the related technology that the occupancy ratio of non-removable memory and removable memory cannot be dynamically adjusted based on application scenario requirements, so that the database service can still achieve automatic expansion and contraction of memory resources after being migrated to the secure container.

[0011] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the multiple drawings represent the same or similar parts or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings only depict some embodiments according to the present application and should not be regarded as limiting the scope of the present application.

[0013] Figure 1 The invention shows a memory management method of a virtual machine in the related art.

[0014] Figure 2A A schematic diagram of the structure of a host machine 200 provided in an embodiment of the present application is shown.

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

[0016] Figure 2C A schematic diagram showing the principles of the memory management method provided in 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 a host machine and a virtual machine.

[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 by an embodiment of the present application is shown. DETAILED DESCRIPTION

[0021] In the following, only some exemplary embodiments are briefly described. As those skilled in the art will appreciate, the described embodiments may be modified in various ways without departing from the concept or scope of the present application. Therefore, the drawings and descriptions are considered to be exemplary in nature and not restrictive.

[0022] For ease of understanding, let's first introduce the terms that will be used below: Kernel state: It is the state or space 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.

[0023] 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.

[0024] 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.

[0025] 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 allocators are usually used to allocate and manage fixed-size memory blocks.

[0026] vmalloc function: 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.

[0027] Page Table (pgtable) interface: It is the management and allocation interface of the page table. The page table is used by the operating system to represent the mapping relationship between the virtual address and the physical address of the page.

[0028] Buddy System: It is an algorithm for memory management. It manages and allocates memory efficiently and reduces memory fragmentation by splitting memory blocks into blocks of sizes that are powers of 2. When the system needs to allocate a block of memory, it first finds the smallest block that meets the requirement. If there is no block of the right size, the system will split the larger block into two equal small blocks until a block of the right size is found. When the memory is no longer in use, the system will release the memory and try to merge it with the adjacent "buddy" block. If both "buddy" blocks are free and the same size, they can be merged into a larger block. This process can be done recursively until it can no longer be merged.

[0029] 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 the compatibility issues of some 32-bit hardware devices when performing DMA on 64-bit systems.

[0030] Normal Zone: Also called 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.

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

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

[0033] 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 they all belong to the protection scope of the embodiments of the present application.

[0034] In the related art, the memory space on a virtual machine (Guest) is usually divided into a non-removable memory and a removable memory. Figure 1 The memory management method of the virtual machine in the related art is shown, such as Figure 1As shown, the virtualized physical address space of the 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 realize direct memory access of 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 from here, 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.

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

[0036] In an exemplary application scenario, in a database service based on cloud computing, users do not need to manage the underlying infrastructure, and the cloud service provider is responsible for automatically configuring, expanding, and managing database instances. A major feature of database services based on cloud computing is elastic scaling, that is, the database service dynamically adjusts infrastructure resources, such as computing resources and storage resources, according to the load, reducing resource usage and reducing costs when traffic is low (light load); and automatically increasing resource scheduling when traffic is high (high load). Therefore, the database service needs to automatically expand or shrink capacity (increase memory capacity or reduce memory capacity) based on the database load.

[0037] In order to ensure database security, the database service needs to be migrated to a secure container. A secure container is a virtual machine that has stronger isolation and security than a physical machine or lightweight container. In a secure container environment, it is also necessary to implement elastic scaling of database services. However, as a virtual machine, the memory blocks (including removable memory and non-removable memory) of a secure container are randomly allocated. Therefore, the memory blocks are randomly allocated to different physical address spaces or virtualized physical address spaces, which may increase the gaps between memory blocks. Although the total free memory capacity may be sufficient, since these memory blocks are scattered, large blocks of continuous memory cannot be allocated, resulting in fragmentation problems. In addition, non-removable memory is fixed to a specific physical address and cannot be migrated. If these non-removable memories are randomly allocated, the fragmentation problem will be further aggravated. The existence of fragmentation problems will limit the elastic expansion capabilities of database services.

[0038] In view of this, the embodiments of the present application provide a technical solution for memory management, a memory management method, a host machine, a memory management device, an electronic device, a computer-readable storage medium, and a computer program product, which realizes elastic expansion and contraction of kernel-state memory by isolating kernel-state data in a first memory area and dynamically adjusting the capacity of the first memory area during the operation of the virtual machine. Furthermore, user-state data is isolated in a second memory area, which facilitates non-fragmentation memory management of user-visible memory in the second memory area.

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

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

[0041] 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. The Host operating system 206 runs in the Host kernel space, controls and manages actual hardware resources (including processor 201, non-volatile memory 202 and physical memory 203, etc.), and runs one or more Host applications 207. The Host user space provides an environment for running Host applications 207 on the Host operating system 206. Further, in a virtualization scenario, the Host operating system 206 runs a virtual machine monitor (Virtual Machine Monitor, VMM), thereby starting one or more virtual machines (Virtual Machine, VM) 205. The VMM is responsible for virtualizing the hardware resources in the virtual machine 205 and managing the virtual hardware resources of the virtual machine 205. The virtual machine operating system (i.e., the Guest operating system) runs in the Guest kernel space, and the virtual machine application (i.e., the Guest application) runs in the Guest user space.

[0042] In the embodiment of the present application, a memory management program is stored in 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.

[0043] Figure 2C A schematic diagram of the principle of the memory management method provided by an embodiment of the present application is shown. Among them, 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 first physical memory area and the second physical memory area from the physical address space of the host machine, 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.

[0044] During the operation of the virtual machine, the virtual machine can send a memory capacity adjustment request for the first memory area to the VMM through virtio-mem, requesting to adjust the capacity of the first memory area of ​​the virtual machine. The VMM responds to the memory capacity adjustment request, 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 on the first memory area, that is, adjusts the address mapping relationship between the target physical memory block and the first memory area.

[0045] Similarly, the virtual machine can send a memory capacity adjustment request for the second memory area to the VMM through virtio-mem, requesting to adjust the capacity of the second memory area of ​​the virtual machine. The VMM responds to the memory capacity adjustment request, 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 on the second memory area, that is, adjusts the address mapping relationship between the target physical memory block and the second memory area.

[0046] In the technical solution of the embodiment of the present application, by isolating the 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 the user state data in the second memory area for removable memory, the memory allocation of the kernel state data is prevented from affecting 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 the kernel state memory, which solves the problem in the related art that the occupancy ratio of the non-removable memory and the 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 the random allocation of memory blocks under the premise of achieving secure isolation of the kernel state data and the user state data.

[0047] 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.

[0048] Step S301: In response to a memory capacity adjustment request of the virtual machine, a target physical memory block is determined 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, and the first memory area is used to allocate virtual memory for kernel state data of the virtual machine.

[0049] The 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.

[0050] 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 it can also be called a memory block. Each page corresponds to its memory address. The physical memory page has a physical address in the physical address space, the virtual memory page has a virtual address in the virtual address space, and the virtualized physical memory page has a virtualized physical address in the virtualized physical address space. Among them, 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.

[0051] 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 relationship with the 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 in the eyes of the guest, these virtual memory pages are its physical memory pages. Therefore, in the embodiment of the present application, the virtual memory pages allocated by the host to the guest are called virtualized physical memory pages.

[0052] 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 to allocate 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.

[0053] The memory management module on the guest side can select virtualized physical memory pages with continuous or discontinuous virtualized physical addresses from the virtualized physical address space, and allocate virtual memory pages with address mapping relationship with the virtualized physical memory pages to each process on the guest, thereby constructing the virtual address space on the guest side. In other words, the virtual address space on the guest side contains multiple virtual memory pages.

[0054] Exemplarily, when the guest process of the virtual machine needs to allocate virtual memory (such as a virtual memory page) for kernel state data, the information with the memory allocation identifier is passed to the memory allocation interface. Such information can indicate that the source of the memory allocation is the first memory area, so that the virtual memory page is allocated for the kernel state data of the virtual machine in the first memory area, and after the virtual memory page is allocated, the address mapping relationship of the virtual memory page on the first memory area is updated in the first page table.

[0055] During the operation of the virtual machine, the virtual machine may trigger a memory capacity adjustment request for the first memory area. Exemplarily, the virtual machine may detect the flow of kernel state data, and determine whether to trigger a memory capacity adjustment request for the first memory area according to the flow change, such as sending a memory expansion request for the first memory area to the VMM when the flow is higher than a certain threshold, so as to request to increase the capacity of the first memory area; or sending a memory reduction request for the first memory area to the VMM when the flow is lower than another threshold, so as to request to reduce the capacity of the first memory area.

[0056] In response to the memory capacity adjustment request of the virtual machine, the VMM determines a target physical memory block from the physical address space of the host machine. The target physical memory block is a memory block having 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 the memory size) carried in the memory reduction request can be selected from the physical address space as the target physical memory block.

[0057] 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.

[0058] 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 capacity, 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.

[0059] According to the technical solution of the embodiment of the present application, by isolating the kernel state data in the first memory area, it is avoided to pollute other memory areas (user state data memory allocation area), such as avoiding the fragmentation problem of kernel state data in the memory allocation process affecting other memory areas. At the same time, the first memory area is configured as a reserved area of ​​​​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 the kernel state memory, which solves the problem in the related technology 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.

[0060] In one embodiment, 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.

[0061] The operating load refers to the actual consumption of resources (such as CPU, memory, disk I / O, network bandwidth, etc.) by the virtual machine during operation, such as CPU usage, memory usage, disk I / O bandwidth, network traffic, database load indicators, etc. Database load indicators are parameters that measure the current operating status of the database and are used to determine whether resources (such as memory) need to be adjusted. Database load indicators 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 submissions 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 when a transaction is delayed due to waiting for a lock, etc.; Number of connections, which refers to the number of connections to the current database.

[0062] 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.

[0063] Based on this, the technical solution of the embodiment of the present application can be applied to the scenario of migrating database services to a secure container. The secure container, as a virtual machine, detects the traffic of the secure container (the index value of the database load index) to achieve automatic expansion and contraction of the memory resource allocation for kernel state data.

[0064] In one implementation, 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; in step S301, determine the target physical memory block from the physical address space of the host machine, including: allocate a physical memory block in an idle state 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, adjust the address mapping relationship of the first memory area in the physical address space of the host machine, including: establish an address mapping relationship between the physical address of the target physical memory block and the first memory area.

[0065] As an example, when a virtual machine detects that its running load is greater than the expansion threshold, a memory expansion request can be triggered through virtio-mem. VMM responds to the memory expansion request and allocates a free physical memory block from the physical address space of the host machine as the target physical memory block. Exemplarily, 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 with increased capacity); VMM selects a physical memory block of corresponding size and in free state (i.e., not allocated) from the physical address space as the target physical memory block.

[0066] Establishing the 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. Further, updating the address mapping relationship of the first memory area on 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.

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

[0068] In one embodiment, the above-mentioned establishment of the address mapping relationship of the target physical memory block in 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.

[0069] 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, etc., 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.

[0070] 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.

[0071] In another implementation, 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; in step S301, determine the target physical memory block from the physical address space of the host machine, including: based on the address mapping relationship of the reduced capacity portion of the first memory area in the physical address space of the host machine, determine the target physical memory block; in step S302, based on the physical address of the target physical memory block, 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, including: release the address mapping relationship between the physical address of the target physical memory block and the first memory area.

[0072] As an example, when the virtual machine detects that its running load is less than the 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 reduced capacity portion of the first memory area in the physical address space of the host machine. Exemplarily, the memory reduction request can carry the starting address of the reduced capacity portion of the first memory area and the size of the virtualized physical memory block (i.e., the reduced capacity memory size); the VMM searches the second page table, and based on the starting address and the size of the virtualized physical memory block, finds the physical address mapped to the reduced capacity portion in the physical address space of the host machine, and the physical memory block corresponding to the physical address is the target physical memory block.

[0073] 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.

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

[0075] In one implementation, the method of the embodiment of the present application may further include: during the creation 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.

[0076] Among them, the first memory area has a continuous virtualized physical address, that is, the first memory area has a continuous address in the virtualized physical address space. Exemplarily, when creating a virtual machine (Guest), the VMM can divide the first physical memory area from the physical address space of the host machine. For example, the VMM allocates continuous physical memory pages through the partner system and reserves a continuous address interval in the virtualized physical address space of the virtual machine. The size of this interval should match the size of the allocated physical memory. For example, if a 4MB first physical memory area is allocated, the address interval from 0x10000000 to 0x10040000 is reserved in the virtualized physical address space.

[0077] Furthermore, an address mapping relationship between the first physical memory area and the first memory area is established, 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 is started, the VMM initializes the address mapping relationship between the first physical memory area and the first memory area through the second page table. After the virtual machine is started, it will update its own first page table according to the information of the first memory area provided by the VMM, which is used to allocate virtual memory pages for its kernel state data.

[0078] 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.

[0079] User state data refers to the data used by applications running in user state in the virtual machine operating system. In the virtualized physical address space of the virtual machine, a first memory area and a second memory area are defined that are independent of each other. For the user state data of the virtual machine, virtual memory needs to be allocated from the second memory area. Each user state process of the virtual machine has an independent virtual address space. Therefore, in a virtualized environment, the second memory area is configured as the system random access memory (System RAM) of the virtual machine to provide memory resources for the applications of the virtual machine.

[0080] Exemplarily, when creating a virtual machine, the VMM can divide an independent first physical memory area and a second physical memory area from the physical address space of the host machine. For example, the VMM allocates continuous physical memory pages through the partner system as the first physical memory area, and allocates continuous or discontinuous physical memory pages through the partner system as the second physical memory area, and ensures that there are no overlapping physical addresses between the first physical memory area and the second physical memory area during allocation. Furthermore, a continuous address interval is reserved in the virtualized physical address space of the virtual machine as the first memory area, and a continuous or discontinuous address interval is reserved as the second memory area.

[0081] Furthermore, an address mapping relationship between the second physical memory area and the second memory area is established, 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 is started, the VMM initializes the address mapping relationship between the second physical memory area and the second memory area through the second page table. After the virtual machine is started, it will update its own first page table according to the information of the second memory area provided by the VMM, which is used to allocate virtual memory pages for its user state data.

[0082] 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 to adjust the capacity of the second memory area of ​​the virtual machine. The VMM responds to the memory capacity adjustment request, determines the 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 between the physical address and the second memory area based on the physical address of the physical memory block.

[0083] Based on this, user-state data is isolated in the second memory area (System RAM), which facilitates non-fragmentation memory management of user-visible memory in the second memory area, thereby reducing the fragmentation problem caused by random allocation of memory blocks under the premise of achieving safe isolation of kernel-state data and user-state data. Among them, the non-fragmentation memory management of user-visible memory in the second memory area includes but is not limited to: merging standard pages (4KB) into large pages (such as 2MB, 1GB); using the buddy system for continuous memory allocation; releasing cold pages and merging hot pages, etc.

[0084] Figure 5 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 a virtual machine. Figure 5 As shown, the memory management method may include: step S501: during the operation of the virtual machine, sending a memory capacity adjustment request, wherein the memory capacity adjustment request is used to request to adjust 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. The specific implementation method and technical effects are described above and will not be repeated here.

[0085] It should be noted that the above application scenarios or application examples provided in the embodiments of the present application are for ease of understanding, and the embodiments of the present 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 need to comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0086] 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.

[0087] 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 target physical memory block and the address of the first memory area.

[0088] 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.

[0089] 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 reduced capacity portion 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.

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

[0091] 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.

[0092] 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.

[0093] 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, including: a memory capacity adjustment request module, 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.

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

[0095] Figure 6 FIG. 1 is a block diagram of an electronic device used to implement an embodiment of the present application. Figure 6 As shown, the electronic device includes: a memory 601 and a processor 602, and the memory 601 stores a computer program that can be run on the processor 602. When the processor 602 executes the computer program, the method 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 performing data exchange transmission.

[0096] In specific implementation, if the memory 601, the processor 602 and the communication interface 603 are implemented independently, the memory 601, the processor 602 and the communication interface 603 can be connected to each other through 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 only one type of bus.

[0097] 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 can communicate with each other through an internal interface.

[0098] 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.

[0099] 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.

[0100] 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 by the embodiment of the present application.

[0101] An embodiment of the present application also provides a chip, including: an input interface, an output interface, a processor and a memory, wherein the input interface, the output interface, the processor and the memory are connected via an internal connection path, and 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.

[0102] It should be understood that the processor may be a CPU, or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. It is worth noting that the processor may be a processor supporting the Advanced RISC Machines (ARM) architecture.

[0103] Further, optionally, the above-mentioned memory may include a read-only memory and a random access memory. The memory may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memory. Among them, the non-volatile memory may include a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may include a random access memory (RAM), which is used as an external cache. By way of exemplary but not limiting description, 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 dynamic random access memory (SLDRAM) and direct memory bus random access memory (DR RAM).

[0104] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium.

[0105] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example" or "some examples" etc. means 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 one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments or examples described in this specification and the features of different embodiments or examples, unless they are contradictory.

[0106] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.

[0107] Any process or method described in the flow chart or otherwise described herein can be understood as a module, fragment or portion of a code representing one or more executable instructions for implementing the steps of a specific logical function or process. And the scope of the preferred embodiment of the present application includes other implementations, in which the functions may not be performed in the order shown or discussed, including in a substantially simultaneous manner or in a reverse order according to the functions involved.

[0108] The logic and / or steps described in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, which 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 an instruction execution system, apparatus or device and execute instructions), or used in combination with these instruction execution systems, apparatuses or devices.

[0109] It should be understood that the various parts of the present application can be implemented with hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented with 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, and when the program is executed, it includes one of the steps of the method embodiment or a combination thereof.

[0110] In addition, each functional unit in each embodiment of the present application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into one module. The above-mentioned integrated module can be implemented in the form of hardware or in the form of a software functional module. If the above-mentioned integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. The storage medium can be a read-only memory, a disk or an optical disk, etc.

[0111] The above is only an exemplary embodiment of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various changes or substitutions within the technical scope recorded in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A memory management method, comprising: In response to a memory capacity adjustment request of the virtual machine, determining a target physical memory block from a 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, the first memory area being used to allocate virtual memory for kernel state data of the virtual machine; 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.

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 comprises: 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 capacity reduction request, and the memory capacity reduction request is used to request to reduce the capacity of the first memory area; The determining 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 reduction 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 between the first physical memory area and the first memory area is established, wherein the first memory area has a continuous virtualized physical address.

7. The method according to claim 6, further comprising: 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; An address mapping relationship is established between the second physical memory area and a second memory area, wherein 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.

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, 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 kernel 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 allocation method

    CN102012870A

  • Method, device and system for transferring from physical machine to virtual machine on line

    CN102081552A

  • Method and system for implementing bidirectional auto scaling service of virtual machines

    CN103559072A

  • Cloud platform virtual machine memory capacity reduction method and device and storage medium

    CN115309504A

  • Memory allocation method and device in microkernel operating system, equipment and medium

    CN115756849A

Cited By

  • Memory management method and computer equipment

    CN120704799A