Memory adjusting method, database memory adjusting method and memory adjusting device

By identifying and releasing specific virtual address ranges within shared physical memory, the method addresses inefficiencies in existing memory management, reducing latency and complexity while maintaining system stability.

CN120315848APending Publication Date: 2025-07-15ALIBABA CLOUD COMPUTING CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410053479.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-12
Publication Date
2025-07-15

AI Technical Summary

Technical Problem

In the prior art, when dynamic scaling is performed through memory management functions, there are problems such as high memory adjustment delay, high complexity and insufficient efficiency, especially when releasing shared physical memory, it is necessary to wait for other processes to use, resulting in the impact of system stability.

Method used

By determining the target virtual address of the memory to be released, traversing the pre-configured virtual memory area, releasing the shared physical memory corresponding to the target virtual address range, using a smaller granular memory release method to avoid overall release of the virtual memory area, and using the madvise function to execute MADV_DONTNEED logic in the kernel state, simplifying the memory adjustment logic.

Benefits of technology

It reduces the delay and complexity of memory adjustment, improves the efficiency of memory adjustment, avoids waiting problems caused by the use of shared physical memory by other processes, and improves the stability and memory utilization of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120315848A_ABST
    Figure CN120315848A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a memory adjustment method, a database memory adjustment method and a memory adjustment device.The memory adjustment method comprises the steps that in response to a memory adjustment request, a target virtual address of a to-be-released memory is determined; traversing a pre-configured virtual memory area corresponding to at least one process, and determining a target virtual address range to which the target virtual address belongs, the virtual memory area including a plurality of pre-divided virtual address ranges; the shared physical memory corresponding to the target virtual address range is released, and the shared physical memory comprises the memory to be released. The shared physical memory corresponding to the whole virtual memory area does not need to be released, small-granularity memory release is achieved, memory adjustment delay is reduced, memory adjustment efficiency is improved, meanwhile, the small-granularity memory release avoids the problem that memory adjustment needs waiting, memory adjustment complexity is reduced, and memory adjustment efficiency is improved. And the memory adjustment efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of this specification relate to the field of computer technologies, and particularly to a memory adjustment method, a database memory adjustment method, and a memory adjustment device. Background Art

[0002] With the development of computer technologies, an operating system constructs a mapping between the virtual memory and the physical memory of a process through the virtual memory area (VMA, Virtual Memory Area) corresponding to the process. In the case where multiple processes map the same physical memory, the operation of sharing the physical memory is realized.

[0003] Currently, for applications that use a large amount of shared physical memory, according to the usage of the shared physical memory, it is necessary to perform dynamic expansion and contraction processing on the shared physical memory through memory management functions, such as the mmap function, the munmap function, the attach function, and the detach function, to achieve memory allocation on demand, ensure sufficient free memory, and avoid the occurrence of out-of-memory (OOM, Out Of Memory), which affects the stability of the operating system.

[0004] However, through dynamic expansion and contraction processing using memory management functions, it is necessary to release the shared physical memory corresponding to the entire virtual memory area and then reconstruct the virtual memory area. For example, if it is necessary to reduce the memory by 50MB, and the currently shared physical memory corresponding to the virtual memory area is 500MB, the entire 500MB of memory is released through the munmap function, and then a 450MB virtual memory area is reconstructed through the mmap function. There are problems of high latency and insufficient efficiency in memory adjustment. Moreover, when releasing the shared physical memory corresponding to the entire virtual memory area, there is a high probability that it will be used by other processes and waiting is required, resulting in problems of high complexity and insufficient efficiency in memory adjustment. Therefore, there is an urgent need for a memory adjustment method with low latency, low complexity, and high efficiency. Summary of the Invention

[0005] In view of this, the embodiments of this specification provide a memory adjustment method. One or more embodiments of this specification simultaneously relate to a database memory adjustment method, a memory adjustment device, a data platform, a computing device, a computer-readable storage medium, and a computer program to solve the technical defects existing in the prior art.

[0006] According to the first aspect of the embodiments of this specification, a memory adjustment method is provided, including:

[0007] Responding to a memory adjustment request, determining a target virtual address of the memory to be released;

[0008] Traverse the virtual memory areas corresponding to at least one pre-configured process to determine the target virtual address range to which the target virtual address belongs, where the virtual memory areas include multiple pre-divided virtual address ranges;

[0009] Release the shared physical memory corresponding to the target virtual address range, where the shared physical memory includes the memory to be released.

[0010] According to the second aspect of the embodiments of the present specification, there is provided a database memory adjustment method, which is applied to a database on the cloud, and the method includes:

[0011] Receive a memory release request for the memory to be released in the database on the cloud sent by the front end;

[0012] Based on the memory release request, determine the target virtual address of the memory to be released;

[0013] Traverse the virtual memory areas corresponding to at least one pre-configured process to determine the target virtual address range to which the target virtual address belongs, where the virtual memory areas include multiple pre-divided virtual address ranges;

[0014] Release the shared physical memory corresponding to the target virtual address range, where the shared physical memory includes the memory to be released;

[0015] Feedback the release result of the shared physical memory to the front end.

[0016] According to the third aspect of the embodiments of the present specification, there is provided a memory adjustment device, including:

[0017] An address determination module, configured to determine the target virtual address of the memory to be released in response to a memory adjustment request;

[0018] A range determination module, configured to traverse the virtual memory areas corresponding to at least one pre-configured process to determine the target virtual address range to which the target virtual address belongs, where the virtual memory areas include multiple pre-divided virtual address ranges;

[0019] A release module, configured to release the shared physical memory corresponding to the target virtual address range, where the shared physical memory includes the memory to be released.

[0020] According to the fourth aspect of the embodiments of the present specification, there is provided a data platform, including a memory management unit and physical memory, where the memory management unit deploys a target operating system;

[0021] The memory management unit is configured to, in response to a memory adjustment request, call the target operating system to determine the target virtual address of the memory to be released; traverse the virtual memory regions corresponding to at least one pre-configured process to determine the target virtual address range to which the target virtual address belongs, where the virtual memory region includes a plurality of pre-divided virtual address ranges; determine the shared physical memory corresponding to the target virtual address range from the physical memory, where the shared physical memory includes the memory to be released; query, based on the target virtual address range, the corresponding page table entry from the page table, clear the page table entry from the page table, and send a data clearing instruction to the shared physical memory, where the page table entry is the mapping relationship between the virtual address and the physical address;

[0022] The shared physical memory is configured to, in response to the data clearing instruction sent by the memory management unit, clear the cached data recorded.

[0023] According to the fifth aspect of the embodiments of the present specification, there is provided a computing device, including:

[0024] a memory and a processor;

[0025] The memory is configured to store computer-executable instructions, and the processor is configured to execute the computer-executable instructions, and when the computer-executable instructions are executed by the processor, the steps of the above-mentioned memory adjustment method are implemented.

[0026] According to the sixth aspect of the embodiments of the present specification, there is provided a computer-readable storage medium storing computer-executable instructions, and when the instructions are executed by a processor, the steps of the above-mentioned memory adjustment method are implemented.

[0027] According to the seventh aspect of the embodiments of the present specification, there is provided a computer program, where when the computer program is executed on a computer, the computer is made to execute the steps of the above-mentioned memory adjustment method.

[0028] In one embodiment of this specification, in response to a memory adjustment request, the target virtual address of the memory to be released is determined; the virtual memory regions corresponding to at least one pre-configured process are traversed to determine the target virtual address range to which the target virtual address belongs, where the virtual memory region includes multiple pre-divided virtual address ranges; the shared physical memory corresponding to the target virtual address range is released, where the shared physical memory includes the memory to be released. By traversing the virtual memory regions corresponding to each process and determining the smaller virtual address range where the target virtual address is located from multiple pre-divided virtual address ranges, and releasing the shared physical memory corresponding to the target virtual address range, it is not necessary to release the shared physical memory corresponding to the entire virtual memory region, achieving memory release with a smaller granularity, reducing the latency of memory adjustment, improving the efficiency of memory adjustment. At the same time, the memory release with a smaller granularity avoids the problem that the shared physical memory is more likely to be used by other processes, resulting in the need to wait for memory adjustment, reducing the complexity of memory adjustment and improving the efficiency of memory adjustment. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 is a flowchart of a memory adjustment method;

[0030] Figure 2 is a flowchart of a memory adjustment method provided by an embodiment of this specification;

[0031] Figure 3 is an architecture diagram of an operating system in a memory adjustment method provided by an embodiment of this specification;

[0032] Figure 4 is a schematic diagram of a virtual memory region in a memory adjustment method provided by an embodiment of this specification;

[0033] Figure 5 is a flowchart of a memory adjustment method provided by an embodiment of this specification;

[0034] Figure 6 is a flowchart of a database memory adjustment method provided by an embodiment of this specification;

[0035] Figure 7 is a processing procedure flowchart of a memory adjustment method applied to database management in a Linux system provided by an embodiment of this specification;

[0036] Figure 8 is a schematic diagram of the structure of a memory adjustment device provided by an embodiment of this specification;

[0037] Figure 9 is a schematic diagram of the structure of a data platform provided by an embodiment of this specification;

[0038] Figure 10 It is a structural block diagram of a computing device provided by an embodiment of this specification. Detailed implementation manners

[0039] Numerous specific details are set forth in the following description to facilitate a thorough understanding of this specification. However, this specification can be implemented in many other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the connotation of this specification. Therefore, this specification is not limited by the specific implementations disclosed below.

[0040] The terms used in one or more embodiments of this specification are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of this specification. The singular forms "a", "the", and "said" used in one or more embodiments of this specification and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more of the associated listed items.

[0041] It should be understood that although the terms first, second, etc. may be used in one or more embodiments of this specification to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "when" or "while" or "in response to determining".

[0042] In addition, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in one or more embodiments of this specification are all information and data that have been authorized by the user or fully authorized by all parties, and the collection, use, and processing of the relevant data need to comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding operation entrances are provided for the user to select to authorize or refuse.

[0043] In one or more embodiments of this specification, a large model refers to a deep learning model that covers a large number of model parameters, usually including hundreds of millions, tens of billions, hundreds of billions, trillions, or even more than one quadrillion model parameters. A large model can also be referred to as a Foundation Model. Through pre-training of a large model with a large amount of unlabeled corpus, a pre-trained model with more than one billion parameters is produced. Such a model can adapt to a wide range of downstream tasks and has good generalization ability, such as large language models (LLMs), multi-modal pre-training models, etc.

[0044] When a large model is actually applied, it only needs to be fine-tuned with a small number of samples for the pre-trained model to be applied to different tasks. Large models can be widely applied in fields such as natural language processing (NLP), computer vision, etc. Specifically, they can be applied to tasks in the field of computer vision such as visual question answering (VQA), image captioning (IC), image generation, etc., and tasks in the field of natural language processing such as text-based sentiment classification, text summary generation, machine translation, etc. The main application scenarios of large models include digital assistants, intelligent robots, search, online education, office software, e-commerce, intelligent design, etc.

[0045] First, the noun terms related to one or more embodiments of this specification are explained.

[0046] Kernel: The basic component of an operating system, responsible for managing and controlling hardware devices and providing a secure and reliable operating environment for users, including various kernel functions that can directly access physical memory.

[0047] Kernel Space: Refers to the memory space or address space used by the kernel of an operating system when it is running. The kernel space is usually located in the high address part and can only be accessed by the operating system kernel. When a user-mode process needs to perform some operations involving hardware operations, such as reading files or network communication, the operating system will switch it to the kernel mode and enter the kernel space for corresponding processing. This can effectively protect the underlying resources of the system from being damaged by malicious users and improve the operating efficiency of the system at the same time.

[0048] User Space: The operating environment composed of all programs and their related resources except the kernel in an operating system. User Space is usually located in the low-address part and can only be accessed by ordinary applications. These applications can include text editors, browsers, games, etc. When they need to perform operations involving hardware operations, such as reading files or network communication, the operating system will switch them to the kernel mode and enter the kernel space for corresponding processing. This can effectively protect the underlying resources of the system from being damaged by malicious users and also improve the operating efficiency of the system.

[0049] Kernel Mode: The kernel-level operating state in an operating system. In this state, a process can directly access the memory and other resources in the kernel space, but cannot directly access the memory and other resources in the user space. In an operating system, the system is divided into two different levels: user mode and kernel mode. Among them, kernel mode refers to the state in which the operating system kernel runs, while user mode refers to the state in which user-level programs in the operating system run. When a process runs in kernel mode, it can access its own kernel space and all hardware devices. These devices include disk drives, network adapters, graphics cards, etc. A process in kernel mode can access any memory location and directly control hardware devices. Such a design makes the operating system have powerful functions, but also brings some security risks. Therefore, the operating system must take some measures to protect itself from malicious attacks, such as restricting the permissions of user-mode programs through a sandbox mechanism.

[0050] User Mode: The user-level operating state in an operating system. In this state, a process can directly access the memory and other resources in the user space, but cannot directly access the memory and other resources in the kernel space. In an operating system, the system is divided into two different levels: user mode and kernel mode. Among them, user mode refers to the state in which user-level programs in the operating system run, while kernel mode refers to the state in which the operating system kernel runs. When a process runs in user mode, it can access its own user space and the system call interfaces provided by the operating system. These interfaces can be used to request services provided by the operating system, such as opening files, reading file contents, sending network data packets, etc. When a process initiates a system call, the operating system will switch it to the kernel mode and enter the kernel space to complete the corresponding tasks. This can effectively protect the underlying resources of the system from being damaged by malicious users and also improve the operating efficiency of the system.

[0051] mmap function: A memory mapping function in the Linux system. It directly maps the data in physical memory to the virtual memory of the process, enabling direct reading and writing of data, thereby improving the operation efficiency.

[0052] munmap function: A function in the Linux system for unmapping memory. It unmaps the data that has been mapped to the virtual memory of a process, thereby releasing the mapped physical memory resources.

[0053] madvise function: A memory optimization advice function in the Linux system. By providing advice on the memory usage of a process to the kernel, corresponding policy logic is executed in the kernel to improve memory utilization and reduce system overhead. It includes: MADV_NORMAL policy logic, MADV_RANDOM policy logic, MADV_SEQUENTIAL policy logic, MADV_WILLNEED policy logic, MADV_DONTNEED policy logic...

[0054] sysv functions: An abbreviation for a set of memory management functions in the Linux system, used to manage functions such as shared memory, message queues, semaphores, and event flags. These functions are mainly used to implement inter-process communication and synchronization. It includes: attach function and detach function.

[0055] Virtual address: The virtual address refers to the logical address used by an application to access data in memory. In the user space, only the virtual address can be presented. It is converted into the actual physical address in the kernel space for access. In the Linux system, the above conversion operation is performed through virtual memory areas.

[0056] Physical address: The physical address refers to the actual address of the computer hardware. In this specification, the physical address is the address on the physical memory hardware, which is unique and unchangeable. The physical address is generally processed in pages, that is, data is processed in the form of physical memory pages (usually 4KB in size).

[0057] Virtual Memory Area (VMA): A virtual address range block constructed by the operating system for a process. One process corresponds to one virtual address area. One virtual address area includes multiple virtual address ranges. A virtual address range (VMA subset) corresponds to a virtual address object (VMA object), and the virtual address mapping has continuous physical addresses. In the Linux system, linked lists are used to connect virtual address objects to achieve traversal. In the Linux system, red-black trees are constructed through virtual address objects to achieve querying.

[0058] 4K unit: The basic management unit for managing various memory data in the operating system. For example, in a 32-bit operating system, the maximum virtual memory area can be 4G, which is divided into units of 4KB for each physical memory page. The entire virtual memory area is then divided into 2 20Pages (stored in the format of paging unit structure).

[0059] Page Table: The page table of virtual memory records each virtual address in virtual memory and its corresponding physical address, including multiple page table entries. Any page table entry includes the mapping relationship between the virtual address and the corresponding physical address. When a process needs to access memory, it first looks up the page table through the virtual address to obtain the corresponding physical address, and then the memory management converts the virtual address into a physical address. This realizes the mapping of the virtual addresses of multiple processes to the same physical address, thus improving the utilization rate of memory. The page table is not fixed, but changes as the process runs and cache data is written, so the system needs to continuously update the page table to ensure the correct operation of the process.

[0060] Translation Lookaside Buffer (TLB) is also called page table cache, mainly used to accelerate the conversion from virtual address to physical address and reduce the read operation of the Central Processing Unit (CPU) to memory.

[0061] Freeing Memory: It refers to the operation of returning the physical memory that is no longer needed to the operating system for reallocation. When the physical memory is no longer in use or cannot be used, these physical memories are released back to the operating system to reduce the consumption of physical memory and improve the stability and efficiency of the operating system.

[0062] Currently, in the Linux operating system, the dynamic expansion and contraction of memory rely on the mmap function and munmap function to achieve. Figure 1 The flowchart of a memory adjustment method is shown as Figure 1 follows: By means of the madvise() function in the user state, the MADV_DONTNEED logic is executed in the kernel state, and it is impossible to truly release the shared physical memory corresponding to a range of virtual addresses. For the expansion of the shared memory of multiple processes of an application, the mmap() function in the user state is called to create the entire virtual memory area in the kernel state. For the contraction of the shared memory of multiple processes of an application, the munmap() function in the user state is called to release the entire virtual memory area in the kernel state, and then the shared physical memory is released.

[0063] However, such a method limits the overall expansion and contraction of the virtual memory area, resulting in frequent invalid mapping and release of the virtual memory area, making the virtual memory area unable to be effectively reserved and reused, with a high latency and insufficient efficiency. Moreover, there is a high probability that the entire virtual memory area will be used by other processes and waiting is required to execute the release, resulting in high complexity and insufficient efficiency in memory adjustment.

[0064] In view of the above problems, a memory adjustment method is provided in this specification. This specification also relates to a database memory adjustment method, a memory adjustment device, a data platform, a computing device, a computer-readable storage medium, and a computer program, which will be described in detail one by one in the following embodiments.

[0065] Refer to Figure 2 , Figure 2 which shows a flowchart of a memory adjustment method provided by an embodiment of this specification, including the following specific steps:

[0066] Step 202: In response to a memory adjustment request, determine the target virtual address of the memory to be released.

[0067] The embodiments of this specification are applied to an operating system, which includes but is not limited to: Unix operating system, Linux operating system, Solaris operating system. In the embodiments of this specification, the Linux system is taken as an example for illustration. Figure 3 which shows an architecture diagram of an operating system in a memory adjustment method provided by an embodiment of this specification, as Figure 3 shown: The operating system includes a user mode and a kernel mode. Virtual memory is determined in the user mode, but physical memory cannot be directly accessed. Multiple function interfaces are built in the kernel mode. When implementing memory expansion and contraction for an application process, based on the memory management functions in the function library, through calling the interfaces, memory management (Memory Management) in the kernel mode is realized, and through the virtual memory area, the operation of the physical memory in the hardware is determined.

[0068] Shared physical memory is the physical memory jointly mapped by multiple processes. For example, for process 1, a virtual address 0XFFFFFFFFF is built on the virtual memory area, and the corresponding physical address is 0XFFFFFFFFFFFFFFFFFF. The data (file) stored at this physical address is mapped to the virtual memory area. For process 2, a virtual address 0X00000000 is built on the virtual memory area, and the corresponding physical address is 0XFFFFFFFFFFFFFFFFFF. The data (file) stored at this physical address is mapped to the virtual memory area. Then, the physical memory corresponding to the physical address 0XFFFFFFFFFFFFFFFFFF is shared physical memory.

[0069] The memory adjustment request is an instruction request generated in the user mode for adjusting the shared physical memory. It may be determined because there is data read and write that has not been executed for a certain period of time, or it may be determined because there is data error, or it may be determined because the memory cannot be read and written by data. It is not limited here.

[0070] The memory to be released is the physical memory that needs to be released. The memory to be released has multiple physical addresses, and each physical address has a corresponding virtual address. The memory to be released may be determined because data reading and writing have not been performed within a certain period of time, or may be determined because there are data errors in the stored data, or may be determined because it cannot be read or written by data. This is not limited here.

[0071] The target virtual address is the virtual address corresponding to the physical address of the memory to be released. In the Linux system, the virtual address is represented by 48 bits: PGD index: bits 39 - 47 (a total of 9 bits), specifying the index in the page global directory (PGD, Page Global Directory). PUD index: bits 30 - 38 (a total of 9 bits), specifying the index in the page upper directory (PUD, Page Upper Directory). PMD index: bits 21 - 29 (a total of 9 bits), specifying the index in the page middle directory (PMD, Page Middle Directory). PTE index: bits 12 - 20 (a total of 9 bits), specifying the index in the page table (PT, Page Table). Offset: bits 0 - 11 (a total of 12 bits), specifying the offset (Offset) in the physical memory page.

[0072] It should be noted that the mapping relationship between the virtual address and the physical address is recorded in the page table entry of the page table. The page table is a page table structure for shared physical memory and is a shared page table. The shared page table allows multiple processes to share the same page table, improving the efficiency of the operating system.

[0073] Exemplarily, in the Linux system, for two processes of application A: task1 and task2, corresponding virtual memory areas are constructed: VMA1 and VMA2. In the virtual memory area VMA1, the virtual address Virtual addr1 (0X00000000 - 0X0000FFFF) and the physical address of the physical memory Physical page (33CE0000 - 33CF0000). In the virtual memory area VMA2, the virtual address Virtual addr2 (0XFFFF0000 - 0XFFFFFFFF) and the physical address of the physical memory Physical page (33CE0000 - 33CF0000). The cached data is stored at the physical address Physical page (33CE0000) to achieve data reading and writing of application A. The Linux system senses that data reading and writing of the cached data on some physical addresses have not been performed within a certain period of time, generates a memory adjustment request, and determines the target virtual address Virtual addr of the memory to be released: 0X00000000 - 0X00001000.

[0074] In response to a memory adjustment request, determine the target virtual address of the memory to be released, which lays a foundation for subsequent traversal of virtual memory regions.

[0075] Step 204: Traverse the virtual memory regions corresponding to at least one pre-configured process, and determine the target virtual address range to which the target virtual address belongs. Among them, the virtual memory region includes multiple pre-divided virtual address ranges.

[0076] The virtual memory region corresponding to a process is a virtual memory region pre-constructed for each process, and the virtual memory region includes multiple virtual address ranges. As Figure 4 shown, Figure 4 shows a schematic diagram of a virtual memory region in a memory adjustment method provided by an embodiment of this specification. As Figure 4 shown: The virtual memory region VMA corresponding to a process includes multiple pre-divided virtual address ranges: virtual address range A (virtual memory region object a, VMA object 1), virtual address range B (virtual memory region object b, VMA object 2), virtual address range C (virtual memory region object c, VMA object 3). Any virtual address range records a start address vm_start and an end address vm_end. When a process accesses memory, it is necessary to use the virtual memory region to convert the virtual address that can be accessed in the user space into the physical address that can be accessed in the kernel space, so as to achieve efficient memory access.

[0077] The target virtual address range is the virtual address range in the virtual memory region where the target virtual address is located. Since the virtual memory region includes multiple pre-divided virtual address ranges, the target virtual address range can be understood as a subset of the virtual memory region, or a virtual memory region object, including various attribute parameters: start address, end address, status flag, permission attribute, etc.

[0078] Traverse the virtual memory regions corresponding to at least one pre-configured process, and determine the target virtual address range to which the target virtual address belongs. The specific method is: determine the target virtual memory region that covers the target virtual address from the virtual memory regions corresponding to each process, and traverse the target virtual address range to which the target virtual address belongs from the target virtual memory region.

[0079] It should be noted that the physical memory cannot be directly accessed in the user space. It is necessary to pre-generate corresponding virtual memory regions for multiple processes, establish the mapping between virtual addresses and physical addresses, and convert the virtual addresses in the user state into physical addresses in the kernel state when the process accesses memory, so as to achieve memory access.

[0080] Exemplarily, the target virtual memory area VMA1 covering the target virtual address (0X00000000-0X00001000) is determined from the virtual memory areas corresponding to each process, and the target virtual address range vma3 (vm_start: 0X00000000; vm_end: 0X00002000) to which the target virtual address belongs is traversed from the target virtual memory area.

[0081] Traverse the virtual memory area corresponding to at least one pre-configured process to determine the target virtual address range to which the target virtual address belongs. Traverse the virtual memory area corresponding to at least one process to determine the smaller virtual address range where the target virtual address is located, laying the foundation for the subsequent small-grained memory release.

[0082] Step 206: Release the shared physical memory corresponding to the target virtual address range, wherein the shared physical memory includes the memory to be released.

[0083] The shared physical memory is a physical memory mapped by the virtual memory areas of multiple processes, including multiple physical addresses. It has been described in detail in step 202 and will not be repeated here. The shared physical memory includes the memory to be released, and the shared physical memory corresponding to the target virtual address range is the memory to be released.

[0084] It should be noted that releasing physical sharing includes releasing the mapping relationship between virtual addresses and physical addresses, that is, clearing the corresponding page table entries in the shared page table so that the physical memory can be reallocated to other processes, and may also include clearing the cache data recorded in the shared physical memory so that data can be read and written after the physical memory is reallocated to other processes. In the Linux system, this is achieved by executing the truncate_page_cache operation through the zap_page_range function in the kernel state space of the memory management (Memory Management).

[0085] Exemplarily, the zap_page_range function is called to execute the truncate_page_cache operation, release the mapping relationship between the target virtual address range vma3 (vm_start: 0X00000000; vm_end: 0X00002000) and the physical address (33CE0000), and clear the cache data recorded in the shared physical memory (33CE0000).

[0086] In the embodiments of this specification, in response to a memory adjustment request, determine the target virtual address of the memory to be released; traverse the virtual memory regions corresponding to at least one pre-configured process, and determine the target virtual address range to which the target virtual address belongs, where the virtual memory region includes multiple pre-divided virtual address ranges; release the shared physical memory corresponding to the target virtual address range, where the shared physical memory includes the memory to be released. Traverse the virtual memory regions corresponding to each process, determine the smaller virtual address range where the target virtual address is located from the multiple pre-divided virtual address ranges, and release the shared physical memory corresponding to the target virtual address range, without releasing the shared physical memory corresponding to the entire virtual memory region, achieving memory release with a smaller granularity, reducing the latency of memory adjustment, improving the efficiency of memory adjustment. At the same time, the memory release with a smaller granularity avoids the problem that the shared physical memory is more likely to be used by other processes, resulting in the need to wait for memory adjustment, reducing the complexity of memory adjustment, and improving the efficiency of memory adjustment.

[0087] In an optional embodiment of this specification, before step 202, the following specific steps are further included:

[0088] In response to a memory access request of any process, allocate a corresponding virtual memory region for any process;

[0089] Based on the virtual memory region, divide to obtain multiple virtual address ranges.

[0090] In the embodiments of this specification, in response to a process's access to memory, it is necessary to allocate a virtual memory region for the process, construct a mapping relationship between the virtual address and the physical address, and implement memory access.

[0091] The memory access request is an instruction request generated and sent in the user state for accessing memory.

[0092] In practical applications, there are various ways to allocate virtual memory regions for processes, which are specifically selected according to the actual situation, and the embodiments of this specification do not make any limitations in this regard. The virtual memory region can be allocated for the process by means of static allocation. For example, allocate a virtual memory region for it when the process is created to reduce memory fragmentation and improve memory utilization. The virtual memory region can also be allocated for the process by means of dynamic allocation. For example, allocate a virtual memory region for it according to the demand when the process is running to better meet the dynamic needs of the process and improve the flexibility and adaptability of the system. The virtual memory region can also be allocated for the process by means of stack allocation. For example, allocate a continuous memory segment for the process as a stack to store the local variables and function call information of the process to ensure the continuity and integrity of the stack and improve the access efficiency.

[0093] In response to the memory access request of any process, allocate a corresponding virtual memory area for any process. Based on the virtual memory area, multiple virtual address ranges are obtained through division. Specifically, it can be implemented through the mmap function, or through the attach function in sysv, or through the malloc function. There is no limitation here.

[0094] In an alternative embodiment of the present specification, the memory access request carries memory parameters of the target memory;

[0095] Correspondingly, allocating multiple virtual memory areas for any process includes the following specific steps:

[0096] Allocate a corresponding virtual memory area for any process based on the memory parameters.

[0097] The memory parameters are memory specification parameters carried in the memory access request of the process for realizing the required memory for running, including the memory size and memory type of the target memory, etc.

[0098] It should be noted that for the virtual address ranges corresponding to each virtual memory area, see Figure 4 .

[0099] Allocating a corresponding virtual memory area for any process based on the memory parameters realizes constructing a corresponding virtual memory area according to the actual memory parameters required for process access, completes the allocation of virtual memory areas on demand, and improves the adaptability of memory allocation.

[0100] Exemplarily, in response to the memory access request of process: task1, based on the memory size of 4GB, allocate a virtual memory area VMA for process: task1, and determine the virtual address ranges corresponding to the virtual memory area: virtual address range 1, vma1 (start address vm1_start, end address vm1_end), virtual address range 2, vma2 (start address vm2_start, end address vm2_end), virtual address range 3, vma3 (start address vm3_start, end address vm3_end)....

[0101] In response to the memory access request of any process, allocate a corresponding virtual memory area for any process; based on the virtual memory area, multiple virtual address ranges are obtained through division. By allocating a corresponding virtual memory area for any process and dividing each virtual memory area, multiple virtual address ranges are obtained, realizing constructing a corresponding virtual memory area according to the actual process access requirements, establishing a mapping between the virtual addresses in the user state and the physical memory in the kernel state, and laying a foundation for subsequent memory adjustment.

[0102] In an alternative embodiment of the present specification, step 204 includes the following specific steps:

[0103] Traverse the virtual memory areas corresponding to at least one pre-configured process to determine the target virtual memory area covering the target virtual address;

[0104] Traverse from the target virtual memory area to obtain the target virtual address range to which the target virtual address belongs according to a preset memory unit, where the preset memory unit is the basic address unit of physical memory.

[0105] The preset memory unit is the basic traversal unit for traversing the target virtual address range, which can be a 4K unit and is a kind of address traversal granularity.

[0106] Traverse from the target virtual memory area to obtain the target virtual address range to which the target virtual address belongs according to a preset memory unit. The specific method is: Traverse each virtual address range from the target virtual memory area according to the preset memory unit to obtain the target virtual address range to which the target virtual address belongs.

[0107] It should be noted that traversing through a small-granularity preset memory unit in the operating system can reduce the time overhead and improve the efficiency of memory adjustment in the case of multiple concurrent processes.

[0108] Exemplarily, traverse each virtual address range (vma1, vma2, vma3...) from the target virtual memory area according to the preset memory unit of 4K to obtain the target virtual address range vma3 (vm_start: 0X00000000; vm_end: 0X00002000) to which the target virtual address belongs.

[0109] Traverse the virtual memory areas corresponding to at least one pre-configured process to determine the target virtual memory area covering the target virtual address; Traverse from the target virtual memory area to obtain the target virtual address range to which the target virtual address belongs according to a preset memory unit, where the preset memory unit is the basic address unit of physical memory. By using this traversal granularity of the preset memory unit to traverse from the target virtual memory area to obtain the target virtual address range to which the target virtual address belongs, the time overhead is reduced and the efficiency of memory adjustment is improved.

[0110] In an optional embodiment of this specification, traversing the virtual memory areas corresponding to at least one pre-configured process to determine the target virtual memory area covering the target virtual address includes the following specific steps:

[0111] In the user space of memory management, traverse the virtual memory areas corresponding to at least one pre-configured process to determine the target virtual memory area covering the target virtual address, and modify the status flag of the target virtual memory area to the to-be-released state;

[0112] Correspondingly, according to a preset memory unit, traverse the target virtual address range to which the target virtual address belongs from the target virtual memory area, including the following specific steps:

[0113] In the user space of memory management, traverse the target virtual address range to which the target virtual address belongs from the target virtual memory area according to a preset memory unit;

[0114] Correspondingly, step 206 includes the following specific steps:

[0115] Switch from the user space of memory management to the kernel space of memory management;

[0116] In the kernel space of memory management, determine the target virtual memory area based on the status identifier of the virtual memory area corresponding to each process;

[0117] In the kernel space of memory management, for the target virtual memory area, release the shared physical memory corresponding to the target virtual address range.

[0118] It should be noted that in the embodiment of this specification, step 206 does not immediately release the shared physical memory, but will consider releasing and recycling it at a subsequent specific time (for example, a specific period or when memory is tight), so as to avoid performance losses caused by frequent memory adjustments.

[0119] The status identifier is an attribute parameter in the virtual memory area. For example, vm_flags in the Linux system is the status identifier. The status identifier is used to establish a unique identifier in the user space and the kernel space, and realizes the corresponding operations on the virtual memory area marked with the status identifier in the kernel space, such as releasing memory, scaling memory, and creating new memory. It realizes the effective management of memory across the user space and the kernel space.

[0120] The to-be-released status is a management label used in the user space to mark the virtual memory area, used to identify the virtual memory area that is no longer in use, and release the physical memory corresponding to the virtual memory area in the kernel space. For example, the "DONTNEED" label in the Linux system.

[0121] Modify the status identifier of the target virtual memory area to the to-be-released status. In the Linux system, this is implemented through the madvise function in the user space, and the corresponding MADV_DONTNEED policy logic is executed in the kernel space to modify the status identifier vm_flags of the target virtual memory area to "DONTNEED".

[0122] In the kernel state space of memory management, the target virtual memory area is determined based on the status identifier of the virtual memory area corresponding to each process. The specific method is as follows: in the kernel state space of memory management, the kernel function is scheduled, and the target virtual memory area is determined based on the status identifier of the virtual memory area corresponding to each process.

[0123] Exemplarily, the corresponding MADV_DONTNEED policy logic is executed in the kernel space through the madvise function in the user state, and the status flag vm_flags of the target virtual memory area VMA1 is modified to "DONTNEED". When the memory is tight, the kernel is scheduled to execute the truncate_page_cache operation to release the mapping relationship between the target virtual address range vma3 (vm_start: 0X00000000; vm_end: 0X00002000) and the physical address (33CE0000), and clear the cache data recorded in the shared physical memory (33CE0000).

[0124] In the user state space of memory management, traverse the virtual memory area corresponding to at least one pre-configured process, determine the target virtual memory area covering the target virtual address, and modify the state mark of the target virtual memory area to be released; switch from the user state space of memory management to the kernel state space of memory management; in the kernel state space of memory management, determine the target virtual memory area based on the state mark of the virtual memory area corresponding to each process; in the kernel state space of memory management, release the shared physical memory corresponding to the target virtual address range for the target virtual memory area. Through the state mark, the unique correspondence between the virtual memory area in the user state space and the kernel state space is effectively completed, and the shared physical address corresponding to the target virtual address range in the target memory area is accurately released in the kernel state space. At the same time, the performance loss caused by frequent memory adjustment is avoided, and the stability of memory adjustment is improved.

[0125] In an optional embodiment of the present specification, step 206 includes the following specific steps:

[0126] Based on the target virtual address range, query the physical address range corresponding to the target virtual address range from the page table;

[0127] Clear the cache data recorded in the shared physical memory corresponding to the physical address range.

[0128] The page table is a page table of virtual memory that records the virtual addresses in virtual memory and their corresponding physical addresses, and includes multiple page table entries. Any page table entry includes the mapping relationship between the virtual address and the corresponding physical address. For example, for process 1, a virtual address 0XFFFFFFFFF in the virtual memory area is constructed, and the corresponding physical address is 0XFFFFFFFFFFFFFFFFFF. For process 2, a virtual address 0X00000000 in the virtual memory area is constructed, and the corresponding physical address is 0XFFFFFFFFFFFFFFFFFF. The above two mapping relationships are recorded in the shared page table.

[0129] The physical address range is the physical address range corresponding to the target virtual address range and includes multiple physical addresses. For example, the target virtual address range is (vm_start: 0X00000000; vm_end: 0X00002000), and the corresponding physical address range is 33CE0000(+2000). The physical address range can be represented as at least one physical memory page.

[0130] The cached data is the cached data recorded in the shared physical memory. Since the read and write speed of the memory is much higher than that of the hard disk, recording the cached data in the physical memory improves the processing efficiency.

[0131] In an optional embodiment of this specification, based on the target virtual address range, querying the physical address range corresponding to the target virtual address range from the page table includes the following specific steps:

[0132] Based on the target virtual address range, query the corresponding page table entry from the page table, where the page table entry is the mapping relationship between the virtual address and the physical address;

[0133] Extract the physical address range corresponding to the target virtual address range from the page table entry.

[0134] In an optional embodiment of this specification, after extracting the physical address range corresponding to the target virtual address range, the following specific steps are further included:

[0135] Clear the page table entry from the page table.

[0136] The page table of virtual memory records each virtual address in the virtual memory and its corresponding physical address, including multiple page table entries. Any page table entry includes the mapping relationship between the virtual address and the corresponding physical address. When a process needs to access memory, it must first look up the page table through the virtual address to obtain the corresponding physical address, and then the memory management converts the virtual address into a physical address. It realizes the mapping of the virtual addresses of multiple processes to the same physical address, thereby improving the utilization of memory. The page table is not fixed, but changes as the process runs and the cache data is written. Therefore, the system needs to continuously update the page table to ensure the correct operation of the process.

[0137] Exemplarily, based on the target virtual address range vma3 (vm_start: 0X00000000; vm_end: 0X00002000), the corresponding page table entry is queried from the page table, and the physical address range 33CE0000 (+2000) corresponding to the target virtual address range is extracted from the page table entry, the zap_page_range function is called, and the truncate_page_cache operation is executed to release the mapping relationship between the target virtual address range vma3 (vm_start: 0X00000000; vm_end: 0X00002000) and the physical address (33CE0000), clear the page table entry of the mapping relationship from the page table, and clear the cache data recorded in the shared physical memory 33CE0000 (+2000).

[0138] Based on the target virtual address range, the physical address range corresponding to the target virtual address range is queried from the page table; the cache data recorded in the shared physical memory corresponding to the physical address range is cleared. The corresponding physical address range is determined through the page table, and the cache data is cleared, which improves the accuracy of memory adjustment, further reduces the complexity of memory adjustment, and further improves the efficiency of memory adjustment.

[0139] Figure 5 FIG. 1 shows a flow chart of a memory adjustment method provided by an embodiment of the present specification, such as Figure 5 As shown:

[0140] To expand the shared memory of multiple processes of an application, the mmap() function in user state is called to create the entire virtual memory area in kernel state and obtain the virtual memory area corresponding to each process. Through the madvise() function in user state, the MADV_DONTNEED logic is executed in kernel state to traverse the virtual memory area corresponding to each process, call zap_page_range(), execute the truncate_page_cache() operation, and release the shared physical memory.

[0141] In view of the insufficient support for memory expansion and contraction by the madvise function and the munmap function, in the embodiments of this specification, by improving the madvise function interface to enable it to support the true release of the target virtual memory area, the deficiency of page table sharing in memory expansion and contraction requirements is solved: (1) Low overhead and simple to use. Compared with the munmap function, it is not necessary to release the entire virtual memory area to release the shared physical memory. The minimum release granularity supports 2MB, fully meeting the application's memory expansion and contraction requirements. Since only the shared physical memory corresponding to the target virtual address range is released, the latency of memory adjustment is greatly reduced; (2) Simplify the application memory expansion and contraction processing logic: Since the munmap function needs to wait for other processes not to use the shared physical memory before starting memory adjustment, otherwise memory leakage will occur and stability problems will arise, its real-time performance cannot be guaranteed. Traverse the virtual memory areas corresponding to each process directly in the kernel state, determine the target virtual address range, and release the corresponding shared physical memory, reducing latency while simplifying the implementation logic of memory adjustment.

[0142] In practical applications, under the ARM microprocessor architecture, the memory adjustment method provided in the embodiments of this specification was tested, and the process concurrency of the test application was set to 32. During the test, the memory operation granularity of the madvise function was set to 2MiB, 4MiB to 512MiB respectively, and the overhead of the madvise function was counted.

[0143] Physical machine test data:

[0144]

[0145]

[0146] Table 1

[0147] Through the above data comparison, it can be confirmed that when the number of concurrent processes is 32, the overhead of the madvise function after adding the memory expansion and contraction function is on average 95% lower than that of using the munmap function in terms of time overhead.

[0148] Therefore, in the embodiments of this specification, the madvise function and the MADV_DONTNEED execution policy are improved, and the support for shared memory using the page table sharing function greatly reduces the time overhead of the memory expansion and contraction function, with very stable real-time performance; moreover, using the madvise function to implement memory expansion and contraction avoids creating new virtual memory areas, introducing unnecessary overhead, and at the same time greatly simplifies the logic of implementing memory expansion and contraction in the user state.

[0149] See Figure 6 , Figure 6Shows a database memory adjustment method provided by an embodiment of this specification, which is applied to a cloud database. The method includes:

[0150] Step 602: Receive a memory release request sent by the front end for the memory to be released in the cloud database.

[0151] Step 604: Based on the memory release request, determine the target virtual address of the memory to be released.

[0152] Step 606: Traverse the virtual memory regions corresponding to at least one pre-configured process, and determine the target virtual address range to which the target virtual address belongs. Among them, the virtual memory region includes multiple pre-divided virtual address ranges.

[0153] Step 608: Release the shared physical memory corresponding to the target virtual address range, where the shared physical memory includes the memory to be released.

[0154] Step 610: Feed back the release result of the shared physical memory to the front end.

[0155] The embodiment of this specification is applied to a cloud database. A cloud database, that is, a cloud database, is a database service built, deployed, and managed based on a cloud computing platform. It combines the functions of traditional databases with cloud technology, allowing users to access data storage resources hosted in the cloud through the Internet and dynamically expand or reduce computing power and storage space according to needs. The cloud database is configured with corresponding memory, and the release of the shared physical memory is completed through steps 602 to 608.

[0156] The embodiment of this specification and Figure 2 The embodiments of the specification are based on the same inventive concept. For the specific manners of steps 602 to 608, please refer to steps 202 to 208, which will not be elaborated here.

[0157] In the embodiments of this specification, a memory release request for the memory to be released in the cloud database sent by the front end is received; based on the memory release request, the target virtual address of the memory to be released is determined; the virtual memory regions corresponding to at least one pre-configured process are traversed to determine the target virtual address range to which the target virtual address belongs, where the virtual memory region includes a plurality of pre-divided virtual address ranges; the shared physical memory corresponding to the target virtual address range is released, where the shared physical memory includes the memory to be released; and the release result of the shared physical memory is fed back to the front end. By traversing the virtual memory regions corresponding to each process and determining the smaller virtual address range where the target virtual address is located from the plurality of pre-divided virtual address ranges, and releasing the shared physical memory in the cloud database corresponding to the target virtual address range, it is not necessary to release the shared physical memory in the cloud database corresponding to the entire virtual memory region, realizing memory release with a smaller granularity, reducing the latency of memory adjustment in the cloud database, improving the efficiency of memory adjustment in the cloud database. At the same time, memory release with a smaller granularity avoids the problem that the shared physical memory in the cloud database is more likely to be used by other processes, resulting in the need to wait for memory adjustment, reducing the complexity of memory adjustment in the cloud database, and improving the efficiency of memory adjustment in the cloud database.

[0158] The following, in combination with the accompanying drawings, takes the application of the memory adjustment method provided in this specification in database management in the Linux system as an example to further illustrate the memory adjustment method. Among them, Figure 7 The flowchart of the processing process of a memory adjustment method provided in an embodiment of this specification is shown, including the following specific steps:

[0159] Step 702: In response to a memory access request of a process of a database management application in the Linux system, based on the memory size and memory type, a virtual memory region VMA is allocated for the process, and based on the virtual memory region, a plurality of virtual address ranges are divided: vma1(vm_start1, vm_end1), vma2(vm_start2, vm_end2), vma3(vm_start3, vm_end3)......

[0160] Step 704: In response to a memory adjustment request, determine the target virtual address virtual addr of the memory to be released.

[0161] Step 706: In the user space, through the madvise function in the user space, convert from the user space of memory management to the kernel space of memory management. In the kernel space, execute the corresponding MADV_DONTNEED logic. Based on the target virtual address virtual addr, determine the target virtual memory area that covers the target virtual address from the virtual memory areas corresponding to each process (VMA1 corresponding to task1, VMA2 corresponding to task2, VMA3 corresponding to task3...): VMA1.

[0162] Step 708: Traverse the target virtual memory area VMA1 in 4K units to obtain the target virtual address range vma3 (vm_start3, vm_end3) to which the target virtual address virtual addr belongs.

[0163] Step 710: In the user space, modify the status flag vm_flags of the target virtual memory area VMA1 to the to-be-released status "DONTNEED".

[0164] Step 712: Convert from the user space of memory management to the kernel space of memory management. In the kernel space, the kernel determines the target virtual memory area VMA1 based on the status flags of the virtual memory areas corresponding to each process.

[0165] Step 714: Call the zap_page_range function to execute the truncate_page_cache operation: For the target virtual memory area, based on the target virtual address range (vm_start3, vm_end3), query the page table entries from the page table, extract the physical address range physical addr (pages...) corresponding to the target virtual address range, clear the page table entries from the page table, and clear the cached data recorded in the shared physical memory pages corresponding to the physical address range.

[0166] In the embodiments of this specification, a method is designed to dynamically expand and contract the shared physical memory using page table sharing in the operating system with less impact on application performance. The original method of calling the munmap function to release memory is improved to calling the madvise function to release the physical memory corresponding to the target virtual address range. For applications that use a large amount of shared physical memory, there is a scenario where the shared physical memory dynamically releases a specified range of physical memory to the Linux system for on-demand reallocation of memory. Ensure that the system has sufficient free physical memory to avoid memory leaks and thus affect stability, etc. Traverse and determine the target virtual address range in 4K units of smaller granularity, and target the release of the cached data on the physical memory corresponding to the target virtual address range, saving time overhead and improving efficiency. Database management, such a memory-intensive application, has innovative significance and application value.

[0167] Corresponding to the above method embodiments, this specification also provides embodiments of a memory adjustment device. Figure 8 The structural schematic diagram of a memory adjustment device provided by an embodiment of this specification is shown. As Figure 8 shown, the device includes:

[0168] An address determination module 802, configured to determine the target virtual address of the memory to be released in response to a memory adjustment request;

[0169] A range determination module 804, configured to traverse the virtual memory regions corresponding to at least one pre-configured process to determine the target virtual address range to which the target virtual address belongs, where the virtual memory region includes multiple pre-divided virtual address ranges;

[0170] A release module 806, configured to release the shared physical memory corresponding to the target virtual address range, where the shared physical memory includes the memory to be released.

[0171] Optionally, the device further includes:

[0172] A creation module, configured to allocate a corresponding virtual memory region for any process in response to a memory access request of any process; and divide multiple virtual address ranges based on the virtual memory region.

[0173] Optionally, the memory access request carries memory parameters of the target memory;

[0174] Correspondingly, the creation module is further configured to:

[0175] Allocate a corresponding virtual memory region for any process based on the memory parameters.

[0176] Optionally, the range determination module 804 is further configured to:

[0177] Traverse the virtual memory regions corresponding to at least one pre-configured process to determine the target virtual memory region covering the target virtual address; traverse from the target virtual memory region to obtain the target virtual address range to which the target virtual address belongs according to the preset memory unit, where the preset memory unit is the basic address unit of the physical memory.

[0178] Optionally, the range determination module 804 is further configured to:

[0179] In the user space of memory management, traverse the virtual memory regions corresponding to at least one pre-configured process to determine the target virtual memory region covering the target virtual address, and modify the status flag of the target virtual memory region to the to-be-released state; in the user space of memory management, traverse from the target virtual memory region to obtain the target virtual address range to which the target virtual address belongs according to the preset memory unit;

[0180] Correspondingly, the release module 806 is further configured to:

[0181] Switch from the user space of memory management to the kernel space of memory management; in the kernel space of memory management, determine the target virtual memory region based on the status flags of the virtual memory regions corresponding to each process; in the kernel space of memory management, for the target virtual memory region, release the shared physical memory corresponding to the target virtual address range.

[0182] Optionally, the release module 806 is further configured to:

[0183] Based on the target virtual address range, query the physical address range corresponding to the target virtual address range from the page table; clear the cached data recorded in the shared physical memory corresponding to the physical address range.

[0184] Optionally, the release module 806 is further configured to:

[0185] Based on the target virtual address range, query the corresponding page table entry from the page table, where the page table entry is the mapping relationship between the virtual address and the physical address; extract the physical address range corresponding to the target virtual address range from the page table entry.

[0186] Optionally, the device further includes:

[0187] A clearing module, configured to clear the page table entry from the page table.

[0188] In the embodiment of this specification, the address determination module is configured to determine the target virtual address of the memory to be released in response to a memory adjustment request; the range determination module is configured to traverse the virtual memory regions corresponding to at least one pre-configured process to determine the target virtual address range to which the target virtual address belongs, where the virtual memory region includes multiple pre-divided virtual address ranges; the release module is configured to release the shared physical memory corresponding to the target virtual address range, where the shared physical memory includes the memory to be released. The product equipped with this device can achieve the following effects: traverse the virtual memory regions corresponding to each process, determine the smaller virtual address range where the target virtual address is located from them, release the shared physical memory corresponding to the target virtual address range, without releasing the shared physical memory corresponding to the entire virtual memory region, realizing memory release with a smaller granularity, reducing the latency of memory adjustment, and improving the efficiency of memory adjustment. At the same time, the memory release with a smaller granularity avoids the problem that the shared physical memory is likely to be used by other processes, resulting in the need to wait for memory adjustment, reducing the complexity of memory adjustment, and improving the efficiency of memory adjustment.

[0189] The above is a schematic solution of a memory adjustment device in this embodiment. It should be noted that the technical solution of this memory adjustment device and the technical solution of the above memory adjustment method belong to the same concept. For the details not described in the technical solution of the memory adjustment device, reference can be made to the description of the technical solution of the above memory adjustment method.

[0190] Corresponding to the above method embodiment, this specification also provides a data platform embodiment. Figure 9 It shows a schematic structural diagram of a data platform provided by an embodiment of this specification. As Figure 9 shown, the data platform includes a memory management unit 902 and physical memory, where the memory management unit 902 deploys a target operating system.

[0191] The memory management unit 902 is used to, in response to a memory adjustment request, call the target operating system to determine the target virtual address of the memory to be released; traverse the virtual memory regions corresponding to at least one pre-configured process to determine the target virtual address range to which the target virtual address belongs, where the virtual memory region includes multiple pre-divided virtual address ranges; determine the shared physical memory 904 corresponding to the target virtual address range from the physical memory, where the shared physical memory 904 includes the memory to be released; based on the target virtual address range, query the corresponding page table entry from the page table, clear the page table entry from the page table, and send a data clearing instruction to the shared physical memory 904, where the page table entry is the mapping relationship between the virtual address and the physical address.

[0192] A shared physical memory 904 is used to clear the cached data recorded in response to a data clearing instruction sent by a memory management unit 902.

[0193] In the embodiments of this specification, the data platform includes a memory management unit and a physical memory. Among them, the memory management unit deploys a target operating system. The memory management unit is used to, in response to a memory adjustment request, call the target operating system to determine the target virtual address of the memory to be released; traverse the virtual memory areas corresponding to at least one pre-configured process to determine the target virtual address range to which the target virtual address belongs, where the virtual memory area includes multiple pre-divided virtual address ranges; determine the shared physical memory corresponding to the target virtual address range from the physical memory, where the shared physical memory includes the memory to be released; based on the target virtual address range, query the corresponding page table entry from the page table, clear the page table entry from the page table, and send a data clearing instruction to the shared physical memory, where the page table entry is the mapping relationship between the virtual address and the physical address; the shared physical memory is used to clear the cached data recorded in response to the data clearing instruction sent by the memory management unit. Traverse the virtual memory areas corresponding to each process, determine the smaller virtual address range where the target virtual address is located from multiple pre-divided virtual address ranges, and release the shared physical memory corresponding to the target virtual address range, without releasing the shared physical memory corresponding to the entire virtual memory area, realizing memory release at a smaller granularity, reducing the latency of memory adjustment, and improving the efficiency of memory adjustment. At the same time, memory release at a smaller granularity avoids the problem that the shared physical memory is more likely to be used by other processes, resulting in the need to wait for memory adjustment, reduces the complexity of memory adjustment, and improves the efficiency of memory adjustment.

[0194] The above is a schematic solution of a memory adjustment device in this embodiment. It should be noted that the technical solution of this memory adjustment device and the technical solution of the above memory adjustment method belong to the same concept. For the details not described in the technical solution of the memory adjustment device, reference can be made to the description of the technical solution of the above memory adjustment method.

[0195] Figure 10 The block diagram of a computing device provided by an embodiment of this specification is shown. The components of the computing device 1000 include, but are not limited to, a memory 1010 and a processor 1020. The processor 1020 is connected to the memory 1010 through a bus 1030, and a database 1050 is used to store data.

[0196] The computing device 1000 also includes an access device 1040 that enables the computing device 1000 to communicate via one or more networks 1060. Examples of such networks include the Public Switched Telephone Network (PSTN), Local Area Network (LAN), Wide Area Network (WAN), Personal Area Network (PAN), or a combination of communication networks such as the Internet. The access device 1040 may include one or more of any type of wired or wireless network interface (e.g., a network interface controller (NIC)), such as an IEEE 802.11 Wireless Local Area Network (WLAN) wireless interface, a Worldwide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, a Near Field Communication (NFC) interface.

[0197] In one embodiment of the present specification, the above components of the computing device 1000 and Figure 10 other components not shown therein may also be connected to each other, for example, via a bus. It should be understood that Figure 10 the block diagram of the computing device shown is for illustrative purposes only and is not a limitation on the scope of the present specification. Those skilled in the art may add or replace other components as needed.

[0198] The computing device 1000 can be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smartphone), a wearable computing device (e.g., a smartwatch, smart glasses, etc.) or other types of mobile devices, or a stationary computing device such as a desktop computer or a Personal Computer (PC). The computing device 1000 can also be a mobile or stationary server.

[0199] Wherein, the processor 1020 is used to execute the following computer-executable instructions, and when the computer-executable instructions are executed by the processor, the steps of the above memory adjustment method or the database memory adjustment method are implemented.

[0200] The above is a schematic solution of a computing device according to this embodiment. It should be noted that the technical solution of this computing device and the technical solutions of the above-mentioned memory adjustment method and database memory adjustment method belong to the same concept. For the details not described in detail in the technical solution of the computing device, reference can be made to the descriptions of the technical solutions of the above-mentioned memory adjustment method or database memory adjustment method.

[0201] An embodiment of this specification also provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by a processor, the steps of the above-mentioned memory adjustment method or database memory adjustment method are implemented.

[0202] The above is a schematic solution of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium and the technical solutions of the above-mentioned memory adjustment method and database memory adjustment method belong to the same concept. For the details not described in detail in the technical solution of the storage medium, reference can be made to the descriptions of the technical solutions of the above-mentioned memory adjustment method or database memory adjustment method.

[0203] An embodiment of this specification also provides a computer program. When the computer program is executed on a computer, the computer is made to execute the steps of the above-mentioned memory adjustment method or database memory adjustment method.

[0204] The above is a schematic solution of a computer program according to this embodiment. It should be noted that the technical solution of this computer program and the technical solutions of the above-mentioned memory adjustment method and database memory adjustment method belong to the same concept. For the details not described in detail in the technical solution of the computer program, reference can be made to the descriptions of the technical solutions of the above-mentioned memory adjustment method or database memory adjustment method.

[0205] The above describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be executed in a different order than in the embodiments and still achieve the desired result. Additionally, the processes depicted in the figures do not necessarily require the particular order or sequential order shown to achieve the desired result. In certain implementations, multitasking and parallel processing are also possible or may be advantageous.

[0206] The computer instructions include computer program code, which may be in the form of source code, object code, executable files, or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, external hard drives, magnetic disks, optical discs, computer memories, read-only memories (ROMs), random access memories (RAMs), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium may be appropriately increased or decreased according to the requirements of patent practice. For example, in some regions, according to patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.

[0207] It should be noted that for the foregoing method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations. However, those skilled in the art should be aware that the embodiments of this specification are not limited by the described order of actions, because according to the embodiments of this specification, some steps may be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential for the embodiments of this specification.

[0208] In the above embodiments, the descriptions of the various embodiments have their own emphases. For the parts not detailed in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.

[0209] The preferred embodiments of this specification disclosed above are only used to help explain this specification. The alternative embodiments do not describe all the details in detail, nor do they limit the invention to the specific embodiments described. Obviously, many modifications and changes can be made according to the content of the embodiments of this specification. This specification selects and specifically describes these embodiments to better explain the principles and practical applications of the embodiments of this specification, so that those skilled in the art can understand and utilize this specification well. This specification is only limited by the claims and their full scope and equivalents.

Claims

1. A memory adjustment method, comprising: Responding to a memory adjustment request, determining a target virtual address of the memory to be released; Traversing virtual memory regions corresponding to at least one pre-configured process, determining a target virtual address range to which the target virtual address belongs, wherein the virtual memory regions include a plurality of pre-divided virtual address ranges; Releasing shared physical memory corresponding to the target virtual address range, wherein the shared physical memory includes the memory to be released.

2. The method according to claim 1, before the step of responding to a memory adjustment request and determining a target virtual address of the memory to be released, further comprising: Responding to a memory access request of any process, allocating a corresponding virtual memory region for the any process; Based on the virtual memory region, dividing to obtain a plurality of virtual address ranges.

3. The method according to claim 2, wherein the memory access request carries memory parameters of a target memory; The step of allocating a corresponding virtual memory region for the any process includes: Based on the memory parameters, allocating a corresponding virtual memory region for the any process.

4. The method according to claim 1, the step of traversing virtual memory regions corresponding to at least one pre-configured process and determining a target virtual address range to which the target virtual address belongs includes: Traversing virtual memory regions corresponding to at least one pre-configured process, determining a target virtual memory region covering the target virtual address; Traversing from the target virtual memory region to obtain the target virtual address range to which the target virtual address belongs according to a preset memory unit, wherein the preset memory unit is a basic address unit of physical memory.

5. The method according to claim 4, the step of traversing virtual memory regions corresponding to at least one pre-configured process and determining a target virtual memory region covering the target virtual address includes: In the user space of memory management, traversing virtual memory regions corresponding to at least one pre-configured process, determining a target virtual memory region covering the target virtual address, and modifying a status flag of the target virtual memory region to a to-be-released status; The step of traversing from the target virtual memory region to obtain the target virtual address range to which the target virtual address belongs according to a preset memory unit includes: In the user space of memory management, traversing from the target virtual memory region to obtain the target virtual address range to which the target virtual address belongs according to a preset memory unit; The step of releasing shared physical memory corresponding to the target virtual address range includes: Converting from the user space of memory management to the kernel space of memory management; In the kernel space of memory management, determining the target virtual memory region based on status flags of virtual memory regions corresponding to each process; In the kernel space of memory management, for the target virtual memory region, releasing shared physical memory corresponding to the target virtual address range.

6. The method according to any one of claims 1-4, the step of releasing shared physical memory corresponding to the target virtual address range includes: Query the physical address range corresponding to the target virtual address range from the page table based on the target virtual address range; Clear the cached data recorded in the shared physical memory corresponding to the physical address range.

7. The method according to claim 6, wherein the querying the physical address range corresponding to the target virtual address range from the page table based on the target virtual address range includes: Query a corresponding page table entry from the page table based on the target virtual address range, wherein the page table entry is a mapping relationship between a virtual address and a physical address; Extract the physical address range corresponding to the target virtual address range from the page table entry.

8. The method according to claim 7, further comprising, after the extracting the physical address range corresponding to the target virtual address range: Clear the page table entry from the page table.

9. A method for database memory adjustment, applied to a cloud database, the method comprising: Receive a memory release request for the memory to be released in the cloud database sent by the front end; Determine a target virtual address of the memory to be released based on the memory release request; Traverse the virtual memory areas corresponding to at least one pre-configured process to determine a target virtual address range to which the target virtual address belongs, wherein the virtual memory area includes a plurality of pre-divided virtual address ranges; Release the shared physical memory corresponding to the target virtual address range, wherein the shared physical memory includes the memory to be released; Feed back the release result of the shared physical memory to the front end.

10. A memory adjustment device, comprising: An address determination module, configured to determine a target virtual address of the memory to be released in response to a memory adjustment request; A range determination module, configured to traverse the virtual memory areas corresponding to at least one pre-configured process to determine a target virtual address range to which the target virtual address belongs, wherein the virtual memory area includes a plurality of pre-divided virtual address ranges; A release module, configured to release the shared physical memory corresponding to the target virtual address range, wherein the shared physical memory includes the memory to be released.

11. A data platform, comprising a memory management unit and a physical memory, wherein, The memory management unit deploys a target operating system; The memory management unit is configured to, in response to a memory adjustment request, call the target operating system to determine a target virtual address of the memory to be released; traverse the virtual memory areas corresponding to at least one pre-configured process to determine a target virtual address range to which the target virtual address belongs, wherein the virtual memory area includes a plurality of pre-divided virtual address ranges; determine the shared physical memory corresponding to the target virtual address range from the physical memory, wherein the shared physical memory includes the memory to be released; query a corresponding page table entry from the page table based on the target virtual address range, clear the page table entry from the page table, and send a data clearing instruction to the shared physical memory, wherein the page table entry is a mapping relationship between a virtual address and a physical address; The shared physical memory is configured to clear the recorded cached data in response to the data clearing instruction sent by the memory management unit.

12. A computing device, comprising: a memory and a processor; The memory is configured to store computer-executable instructions, and the processor is configured to execute the computer-executable instructions, and when the computer-executable instructions are executed by the processor, the steps of the method according to any one of claims 1 to 9 are implemented.

13. A computer-readable storage medium storing computer-executable instructions, and when the computer-executable instructions are executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.

Citation Information

Cited By

  • Memory management method and device, electronic equipment and medium

    CN120723482A