Memory management method, electronic equipment and storage medium

By flexibly allocating physical pages according to the backend type, the problem of excessive page missing processing and compatibility between large page management technology in traditional page management technology is solved, which improves memory performance and reduces memory overhead.

CN119003142APending Publication Date: 2024-11-22HUAWEI TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202310554422.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-05-17
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

Traditional page management technology leads to excessive page missing processing in large-scale data processing, reduces the hit rate of page table cache, limits system performance, and the coupling between large page management technology and hardware memory management units is high, limiting the selection of large pages. Granularity leads to large memory overhead and compatibility problems also exist.

Method used

By determining different types of physical pages according to different backend types during memory allocation, establishing a mapping relationship between virtual memory intervals and physical pages, flexibly allocating physical pages, improving memory allocation efficiency and reducing memory overhead.

Benefits of technology

It improves memory performance, reduces memory overhead, solves the problem of excessive page missing processing in large-scale data processing by traditional page management technology, and reduces the overall service performance limitation of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119003142A_ABST
    Figure CN119003142A_ABST
Patent Text Reader

Abstract

The invention provides a memory management method, electronic equipment and a storage medium, and the method comprises the steps: responding to a received memory allocation request, and allocating a virtual memory; creating a virtual memory interval for the distributed virtual memory, and binding the virtual memory interval with a target rear end; wherein the rear end is used for representing the type of a data source; determining a physical page type according to the target back end, wherein the physical page type comprises a common physical page type and a large physical page type; and allocating or loading a physical page according to the physical page type, and establishing a first mapping relationship between the virtual memory interval and the allocated physical page or the loaded physical page. The method provided by the invention is beneficial to improving the performance of the memory and reducing the overhead of the memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] With the continuous development of computer hardware technology, in order to meet the needs of complex computing and processing, supporting larger and larger memories has become an important trend in the development of computer memory management.

[0003] Traditional page management technology has a small page granularity, which will lead to excessive page fault processing in large-scale data processing services. Large-scale data processing services involve a large range of memory accesses. Traditional page management technology will lead to a decrease in the page table cache hit rate, thereby limiting the overall service performance of the system.

[0004] Although large page management technology can manage memory with a larger page granularity in the operating system and can reduce the frequency of system page fault processing in large-scale data processing services to improve the overall performance of the system, the current large page management technology is highly coupled with the hardware memory management unit, which limits the selectable granularity of large pages and leads to large memory overhead. In addition, when using large page management technology, compatibility issues will arise for operating systems that only support traditional page management technology. Summary of the invention

[0005] The present application provides a memory management method, an electronic device and a storage medium, which are helpful to improve memory performance and reduce memory overhead.

[0006] In a first aspect, the present application provides a memory management method, comprising: allocating virtual memory in response to a received memory allocation request; creating a virtual memory interval for the allocated virtual memory, and binding the virtual memory interval to a target backend; wherein the backend is used to characterize the type of data source; determining a physical page type according to the target backend, the physical page type including a normal physical page type and a large physical page type; allocating or loading a physical page according to the physical page type, and establishing a first mapping relationship between the virtual memory interval and the allocated physical page or the loaded physical page.

[0007] In the present application, by determining different types of physical pages based on different backends when allocating memory, the allocated physical pages can better adapt to the currently required memory, which can help improve memory performance and reduce memory overhead.

[0008] In one possible implementation, after binding the virtual memory interval to the target backend, the method further includes: in response to detecting a page fault, searching for a corresponding target virtual memory interval according to a page fault address; and the target virtual memory interval determines the target backend.

[0009] In one possible implementation, after binding the virtual memory interval to the target backend, the method further includes: in response to receiving a mapping establishment request, searching for the corresponding target virtual memory interval according to the address of the mapping establishment request; and determining the target backend according to the target virtual memory interval.

[0010] In one possible implementation, determining the physical page type according to the target backend includes: determining a target intersection of a large page window and the target virtual memory interval, the large page window being used to characterize the memory space that can be accommodated by a large physical page; if the target intersection is equal to the memory space corresponding to the large physical page, determining the physical page type to be a large physical page type; or, if the target intersection is smaller than the memory space corresponding to the large physical page, determining the physical page type to be an ordinary physical page type; or, if the target intersection includes allocated physical pages or loaded physical pages, determining the physical page type to be an ordinary physical page type.

[0011] In one possible implementation, after allocating or loading a physical page according to the physical page type and establishing a first mapping relationship between the target virtual memory interval and the allocated physical page or the loaded physical page, the method further includes: updating, in response to a received update request, relevant information of the target virtual memory interval, the first mapping relationship and one or more of the physical page information.

[0012] In one possible implementation, the allocated physical page or the loaded physical page is a large physical page, and establishing a first mapping relationship between the target virtual memory interval and the allocated physical page or the loaded physical page includes: mapping the target virtual memory interval to a partial area of ​​the allocated physical page or a partial area of ​​the loaded physical page; or, mapping the target virtual memory interval to the entire area of ​​the allocated physical page or the entire area of ​​the loaded physical page.

[0013] In one possible implementation, after allocating or loading a physical page according to the physical page type and establishing a first mapping relationship between the target virtual memory interval and the allocated physical page or the loaded physical page, the method further includes: in response to detecting a reclaim request, selecting a reclaimable physical page from the allocated or loaded physical page, and releasing the first mapping relationship between the virtual memory interval and the reclaimable physical page; wherein the reclaimable physical page is a normal physical page or a large physical page.

[0014] In one possible implementation, the reclaimable physical page is a large physical page, and the virtual memory interval is mapped to a partial area of ​​the reclaimable physical page, or the virtual memory interval is mapped to the entire area of ​​the reclaimable physical page.

[0015] In one possible implementation, the reclaimable physical page is a large physical page, and releasing the first mapping relationship between the virtual memory interval and the reclaimable physical page includes: finding the virtual memory interval corresponding to the reclaimable physical page according to a second mapping relationship, wherein the second mapping relationship is used to characterize the mapping relationship between a physical page and one or more virtual memory intervals; releasing the first mapping relationship between the virtual memory interval corresponding to the reclaimable physical page and the reclaimable physical page.

[0016] In a second aspect, the present application provides a memory management device, comprising one or more functional modules, wherein the one or more functional modules are used to implement the memory management method as described in the first aspect.

[0017] In a third aspect, the present application provides an electronic device, comprising: a processor and a memory, wherein the memory is used to store a computer program; the processor is used to run the computer program to implement the memory management method as described in the first aspect.

[0018] In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer-readable storage medium is executed on a computer, the computer implements the memory management method as described in the first aspect.

[0019] In a fifth aspect, the present application provides a computer program, which, when executed on a processor of an electronic device, enables the electronic device to execute the memory management method as described in the first aspect.

[0020] In one possible design, the program in the fifth aspect may be stored in whole or in part on a storage medium packaged together with the processor, or may be stored in whole or in part on a memory not packaged together with the processor. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 A system architecture diagram provided for an embodiment of the present application;

[0022] Figure 2 A flowchart of an embodiment of the memory management method provided by the present application;

[0023] Figure 3 A flowchart of another embodiment of the memory management method provided by the present application;

[0024] Figure 4a-4c A schematic diagram of a page missing scenario provided in an embodiment of the present application;

[0025] Figure 5 A flowchart of another embodiment of the memory management method provided by the present application;

[0026] Figure 6 A schematic diagram of a large physical page splitting effect provided in an embodiment of the present application;

[0027] Figure 7 A schematic diagram of the structure of a memory management device provided in an embodiment of the present application;

[0028] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0029] In the embodiments of the present application, unless otherwise specified, the character " / " indicates that the objects before and after the association are in an or relationship. For example, A / B can represent A or B. "And / or" describes the association relationship of the associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone.

[0030] It should be pointed out that the words "first", "second", etc. involved in the embodiments of the present application are only used to distinguish the description purpose, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated, nor can they be understood as indicating or implying order.

[0031] In the embodiments of the present application, "at least one" refers to one or more, and "plurality" refers to two or more. In addition, "at least one of the following" or similar expressions refers to any combination of these items, which may include any combination of single items or plural items. For example, at least one of A, B, or C may represent: A, B, C, A and B, A and C, B and C, or A, B and C. Among them, each of A, B, and C may be an element itself, or a set containing one or more elements.

[0032] In the embodiments of the present application, "exemplary", "in some embodiments", "in another embodiment", etc. are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of the word "exemplary" is intended to present concepts in a concrete way.

[0033] In the embodiments of the present application, "of", "corresponding", and "corresponding" can sometimes be used interchangeably. It should be noted that when the distinction between them is not emphasized, the meanings to be expressed are consistent. In the embodiments of the present application, communication and transmission can sometimes be used interchangeably. It should be noted that when the distinction between them is not emphasized, the meanings to be expressed are consistent. For example, transmission can include sending and / or receiving, which can be a noun or a verb.

[0034] The equal to involved in the embodiments of the present application can be used in conjunction with greater than, and is applicable to the technical solution adopted when greater than, and can also be used in conjunction with less than, and is applicable to the technical solution adopted when less than. It should be noted that when equal to is used in conjunction with greater than, it cannot be used in conjunction with less than; when equal to is used in conjunction with less than, it cannot be used in conjunction with greater than.

[0035] Some terms involved in the embodiments of the present application are explained below to facilitate understanding by those skilled in the art.

[0036] 1. Virtual address space Vspace. The virtual address space in this application refers to the virtual memory address space corresponding to the user process in the computer operating system. The virtual address space is used to manage the memory resources of the user process. The virtual address allocated by the user process is mapped to the physical address to establish a page table to achieve memory access.

[0037] 2. Page table. In this application, the page table is a data structure table used to store the mapping relationship between user virtual memory and physical address. The virtual address space of each user process will correspond to a page table data.

[0038] 3. Memory mapping: The memory mapping in this application refers to the mapping relationship between the virtual address and the physical address of the application process.

[0039] 4. Defragmentation: Defragmentation in this application refers to the technology of merging scattered physical pages into continuous physical pages.

[0040] With the continuous development of computer hardware technology, in order to meet the needs of complex computing and processing, supporting larger and larger memories has become an important trend in the development of computer memory management.

[0041] Traditional page management technology has a small page granularity, which will lead to excessive page fault processing in large-scale data processing services. Large-scale data processing services involve a large range of memory accesses. Traditional page management technology will lead to a decrease in the page table cache hit rate, thereby limiting the overall service performance of the system.

[0042] Although large page management technology can manage memory with a larger page granularity in the operating system and reduce the frequency of system page fault processing in large-scale data processing services to improve the overall performance of the system, the current large page management technology is highly coupled with the hardware memory management unit, which limits the selectable granularity of large pages and leads to large memory overhead. In addition, when large page management technology is used on an operating system that only supports traditional page management technology, compatibility issues and other issues will arise.

[0043] Based on the above problems, an embodiment of the present application proposes a memory management method.

[0044] Now combined Figure 1-Figure 3 , Figure 4a-4c , Figure 5 The memory management method provided in the embodiment of the present application is described.

[0045] Figure 1 This is a system architecture diagram provided by the embodiment of this application. Figure 1 As shown, the above system architecture includes an application layer, an operating system layer and a hardware layer.

[0046] Among them, the application layer may include an application, which may be a system application, for example, a system application may be a driver; the application may also be a third-party application, which is not particularly limited in the embodiments of the present application.

[0047] The operating system layer may include a memory management unit (MMU), which may include a virtual address allocation module, a memory map backend module (MMB), a page table and a page allocator, wherein the virtual address allocation module is used to allocate a continuous virtual memory interval (Vregion) from a virtual address space (Vspace), and the continuous virtual memory interval (Vregion) may be represented by a virtual address. MMB may include multiple backend instances, and exemplarily, the backend instances may include anonymous instances, file instances, device instances, shared instances, etc., wherein the backend is used to represent the type of data source, and exemplarily, the backend may include an anonymous class backend, a file class backend, a device class backend, a shared class backend, etc.

[0048] Page table is a data structure table used to manage the mapping relationship between user virtual memory and physical address.

[0049] The page allocator is used to allocate physical pages corresponding to virtual addresses.

[0050] It is understandable that in the conventional technology, the page allocator is coupled with the hardware, that is, the page description between the page table and the page allocator is shared. For example, the page allocator allocates physical pages according to the page granularity of 4k, and the mapping relationship between the virtual address and the physical address in the page table is also mapped based on the 4k page table granularity, which results in low flexibility in allocating physical pages.

[0051] In the embodiment of the present application, the page description of the page table and the page description of the page allocator are independent, so that the granularity between the page table and the page allocator can remain independent and no longer have a coupling relationship, thereby improving the flexibility of physical page allocation and improving the efficiency of memory allocation. Exemplarily, the page allocator can allocate physical pages according to the page granularity of 64k, and the mapping relationship between the virtual address and the physical address in the page table can be mapped based on the page table granularity of 4k.

[0052] The hardware layer may include hardware such as a central processing unit (CPU) and a random access memory (RAM).

[0053] Figure 2 A flowchart of an embodiment of the memory management method provided in this application specifically includes the following steps:

[0054] Step 201: In response to a memory allocation request from an application program, the operating system allocates virtual memory from a virtual address space.

[0055] Specifically, the application may initiate a memory allocation request, which is used to request memory allocation. In response to the memory allocation request of the application, the operating system may allocate virtual memory from a virtual address space (Vspace).

[0056] Step 202: the operating system creates a corresponding virtual memory region (Vregion) for the allocated memory.

[0057] Specifically, after the operating system allocates virtual memory from the virtual address space (Vspace), a corresponding virtual memory interval (Vregion) can be created for the allocated virtual memory. It is understandable that the virtual memory interval (Vregion) may include relevant information such as interval information, access rights and recyclable attributes. Among them, the interval information may include information such as the starting address and the ending address of the virtual memory interval (Vregion). The access rights are used to characterize the rights to access the physical memory corresponding to the virtual memory interval (Vregion). Exemplarily, the access rights may include readable, writable, and readable & writable rights, and the embodiments of the present application do not specifically limit this. The recyclable attribute is used to characterize whether the physical memory corresponding to the virtual memory interval (Vregion) is recyclable. Exemplarily, when memory resources are tight, the allocated physical memory can be reclaimed. However, it does not constitute a limitation on the embodiments of the present application. In some embodiments, the virtual memory interval (Vregion) may also include other information.

[0058] Step 203: The operating system binds the allocated virtual memory region (Vregion) to the target backend instance.

[0059] Specifically, after the operating system creates a virtual memory range (Vregion), the created virtual memory range (Vregion) can be bound to the target backend instance based on a preset mapping relationship.

[0060] The target backend can be obtained by searching the above preset mapping relationship, which can be a mapping relationship between a request type and a backend instance. It is understandable that when the operating system receives a memory allocation request, it can obtain the request type of the memory allocation request, and thus can search in the preset mapping relationship according to the request type of the memory allocation request to obtain the corresponding backend instance.

[0061] It is understandable that after the virtual memory interval (Vregion) is bound to the target backend instance, physical memory can be allocated, and a first mapping relationship between the virtual memory interval (Vregion) and the required physical memory can be established, thereby enabling access to the physical memory through the virtual memory space (Vregion). The specific process of allocating physical memory and establishing the first mapping relationship between the virtual memory interval (Vregion) and the required physical memory can be referred to in the subsequent embodiments, and will not be repeated here.

[0062] In an embodiment of the present application, a virtual memory interval (Vregion) is allocated according to different types of memory allocation requests, and the virtual memory interval (Vregion) is bound to a backend instance, and a first mapping relationship between the required physical memory and the virtual memory interval (Vregion) is established, so that the application can use the virtual memory interval (Vregion) to access the corresponding physical memory through the first mapping relationship.

[0063] Next, combine Figure 3 An exemplary description is given of allocating physical memory and establishing a first mapping relationship between virtual memory and physical memory.

[0064] It is understandable that after the allocation of physical memory is completed and the first mapping relationship between virtual memory and physical memory is established, the memory allocation for the application is considered to be completed, and in the subsequent running process of the application, the physical memory can be accessed through the virtual address.

[0065] Figure 3 A flowchart of another embodiment of the memory management method provided by the present application specifically includes the following steps:

[0066] Step 301, the operating system determines a target virtual memory region (Vregion).

[0067] In some optional embodiments, after the allocated virtual memory interval (Vregion) is bound to the target backend instance, the physical page can be actively allocated. For example, the operating system can use the allocated virtual memory interval (Vregion) as the target virtual memory interval (Vregion) and execute step 302.

[0068] In some optional embodiments, after the allocated virtual memory interval (Vregion) is bound to the target backend instance, physical pages can also be allocated after receiving a mapping establishment request. Exemplarily, after being allocated to the virtual memory interval, the application can also actively initiate a mapping establishment request to request the allocation of the corresponding physical memory. In response to receiving the mapping establishment request, the operating system can search for the corresponding target virtual memory interval according to the address of the mapping establishment request; determine the target backend according to the target virtual memory interval, and determine the corresponding physical page type according to the target backend.

[0069] In some optional embodiments, after the allocated virtual memory range (Vregion) is bound to the target backend instance, the physical page can be passively allocated. For example, when a page fault is detected, the operating system can search for the corresponding target virtual memory range (Vregion) according to the page fault address and execute step 302.

[0070] In some optional embodiments, in a page fault scenario, the operating system may also perform a legality check on the access to the virtual memory address.

[0071] If the access to the virtual memory address is determined to be an illegal access, an abnormal page fault process may be performed, wherein the specific method of abnormal page fault process may refer to the prior art, and the present application embodiment will not repeat it.

[0072] If it is determined that the access to the virtual memory address is a legal access, normal page fault processing can be performed and step 302 is executed.

[0073] Step 302, the operating system determines whether the virtual memory region (Vregion) maps a large physical page.

[0074] Specifically, after the operating system determines the target virtual memory region (Vregion), it can obtain the target backend instance bound to the target virtual memory region (Vregion).

[0075] Next, it can be determined whether to map large physical pages based on the target backend instance.

[0076] In some optional embodiments, the backend instance may determine to map a common physical page according to the type of the backend instance and execute step 303 .

[0077] In some optional embodiments, the backend instance may determine the mapping large physical page according to the type of the backend instance and execute step 305 .

[0078] It is understandable that the page granularity of a large physical page is larger than that of an ordinary physical page. For example, the page granularity of an ordinary physical page may be 4k, and the page granularity of a large physical page may be 16k, 32k, 64k, 128k, 2M, 1G, etc. It is understandable that the above values ​​are only exemplary, and the specific settings may be based on actual conditions, and the embodiments of the present application do not specifically limit this.

[0079] In some optional embodiments, it can also be determined whether to map a large physical page according to a preset algorithm. The specific algorithm can be: the backend instance can obtain a large page window, which is used to characterize the memory space that can be accommodated by the large physical page. For example, the page granularity of the large physical page is 64k, and the size of the large page window is 64k.

[0080] Next, the intersection of the large page window and the target virtual memory range (Vregion) is calculated, and whether to map the large page is determined according to the intersection.

[0081] If the operating system determines to map a normal physical page, step 303 is executed. Or,

[0082] If the operating system determines to map a large physical page, step 305 is executed.

[0083] Now, a page fault scenario in which the page granularity of a common physical page is 4k and the page granularity of a large physical page is 64k is taken as an example for exemplary description.

[0084] Figure 4a This is one of the page fault scenarios. Figure 4a , V1 is the virtual memory range (Vregion) corresponding to the page fault address, and P is the page fault address. W is a large page window, that is, the size of W is 64k. Since V1 is larger than W, the intersection of V1 and W is W. Then, the operating system can determine the page granularity of the intersection as the page granularity of the current physical page to be allocated, that is, the page granularity of W is used as the page granularity of the current physical page to be allocated, for example, 64k. The operating system can determine the virtual memory range (Vregion) corresponding to W to map the large physical page according to the page granularity of the physical page to be allocated.

[0085] It is understandable that the large page windows may be aligned before calculating the intersection of V1 and W. The above-mentioned large page windows may be aligned in the following two ways:

[0086] Method 1, based on the offset of the virtual memory range (Vregion).

[0087] For backends without data source types, such as anonymous class backends, the page fault address can be offset in the virtual memory region (Vregion), and then the large page window can be aligned with the offset page fault address.

[0088] Method 2: based on the backend offset.

[0089] For a backend with a data source type, such as a file-type backend, a device-type backend, etc., the missing page address can be offset in the backend. Exemplarily, the missing page address can be converted to an address in the backend (such as an offset position in a file), and then the converted address is offset so that the large page window is aligned with the offset address.

[0090] Among them, the method of determining whether the page fault address needs to be offset can refer to the existing technology, and the embodiment of the present application will not be repeated here.

[0091] Figure 4b This is another page fault scenario. Figure 4b, V1 is the virtual memory region (Vregion) corresponding to the page fault address, and P is the page fault address. W is a large page window, that is, the size of W is 64k. The intersection of V1 and W is S. Since the large page part of W other than the size of S will cause waste, the operating system can use the page granularity of the ordinary page as the page granularity of the current physical page to be allocated, for example, 4k. The operating system can determine the virtual memory region (Vregion) corresponding to S to map the ordinary physical page according to the page granularity of the physical page to be allocated.

[0092] Figure 4c This is another page fault scenario. Figure 4c , V1 is the virtual memory range (Vregion) corresponding to the page fault address, R is the occupied virtual address, that is, R is the virtual address mapped to the existing physical page, and P is the page fault address. W is a large page window, that is, the size of W is 64k. S is the intersection of V1 and W. Since V1 is greater than W, S is W. However, W contains the occupied virtual address R, that is, S contains a physical page that cannot be allocated. Therefore, the operating system can use the page granularity of the ordinary page as the page granularity of the current physical page to be allocated, for example, 4k. The operating system can determine the virtual memory range (Vregion) corresponding to S to map the ordinary physical page according to the page granularity of the physical page to be allocated.

[0093] It is understandable that the page granularity decision algorithm is not limited to the type in the above example.

[0094] Different backend instances have different page granularity decision algorithms, which are not limited in the embodiments of the present application.

[0095] Step 303: the operating system allocates or loads a normal physical page.

[0096] Specifically, if the operating system determines to map a normal physical page, the operating system can allocate or load the normal physical page. For example, the normal physical page can be a 4k physical page, but this does not constitute a limitation on the embodiments of the present application. The normal physical page can also be a physical page of other granularities.

[0097] In some optional embodiments, if the operating system successfully allocates or loads a normal physical page, step 304 is executed. Alternatively,

[0098] If the operating system fails to allocate or load a normal physical page, the operating system can reclaim the allocated or loaded normal physical page, reallocate or load the normal physical page, or enter an exception handling process, wherein the specific processing method of the exception handling process can refer to the prior art and will not be repeated here.

[0099] Step 304: the operating system establishes a first mapping relationship between the target virtual memory region (Vregion) and the common physical page.

[0100] Specifically, the operating system can establish a first mapping relationship between a target virtual memory range (Vregion) and a common physical page, that is, a mapping relationship between a virtual address and a physical address, so as to complete the allocation or loading and mapping establishment of the common physical page.

[0101] Step 305: the operating system allocates or loads a large physical page.

[0102] Specifically, if the operating system determines to map a large physical page, the operating system may allocate or load the large physical page. For example, the large physical page may be a 64k physical page, but this does not constitute a limitation on the embodiments of the present application.

[0103] In some optional embodiments, if the operating system successfully allocates or loads the large physical page, step 306 is executed. Alternatively,

[0104] If the operating system fails to allocate or load a large physical page, the operating system may reclaim the allocated or loaded large physical page, reallocate or load the large physical page, or the operating system may perform defragmentation, and reallocate or load the large physical page after the defragmentation is successful, or the operating system changes to allocate or load a common physical page. The specific method of allocating or loading a common physical page can refer to the relevant description in the above embodiment, which will not be repeated here.

[0105] Step 306: the operating system establishes a first mapping relationship between the target virtual memory range (Vregion) and the large physical page.

[0106] Specifically, the operating system can establish a first mapping relationship between the target virtual memory range (Vregion) and the large physical page, that is, a mapping relationship between a virtual address and a physical address, so as to complete the allocation or loading and mapping establishment of the large physical page.

[0107] In some optional embodiments, the large physical page may also support mixed mapping, for example, the large physical page may be fully mapped, that is, the virtual memory interval (Vregion) maps the entire large physical page with a preset mapping granularity, wherein the preset mapping granularity may be the page granularity of an ordinary physical page, for example, 4k. Taking the preset mapping granularity of 4k and the page granularity of the large physical page as an example, when the mapping between the virtual memory interval (Vregion) and the entire large physical page is completed through 16 mappings, the reference count of the physical page is increased by 1, that is, the accumulation of physical pages is based on the page granularity of the large physical page.

[0108] Alternatively, the large physical page can be partially mapped, that is, the virtual memory interval (Vregion) maps a partial area of ​​the large physical page with a preset mapping granularity. Taking the page granularity of 4k as an example, a partial area in a 64k large page can be mapped with a granularity of 4k. Assuming that the virtual memory interval (Vregion) is 8k, the partial mapping of the virtual memory interval (Vregion) and the large physical page can be completed through 2 mappings. The virtual memory interval (Vregion) only maps an area of ​​8k in the large physical page. It can be understood that each time the mapping is completed through the preset mapping granularity, the reference count of the physical page is increased by 1, that is, the accumulation of physical pages is based on the preset mapping granularity.

[0109] The above Figure 3 An exemplary description is given of allocating or loading physical memory and establishing a mapping relationship between virtual memory and physical memory. During the use of the application, the application may also call a system interface to update the relevant information of the virtual memory interval (Vregion), the first mapping relationship, and the physical page information. Next, the following exemplifies the update of the relevant information of the virtual memory interval (Vregion), the first mapping relationship, and the physical page information through FIG. 4.

[0110] Figure 5 A flowchart of another embodiment of the memory management method provided in the present application specifically includes the following steps:

[0111] Step 501, in response to receiving an update request from an application, the operating system searches for a target virtual memory region (Vregion) in a virtual address space (Vspace).

[0112] Specifically, the application may initiate an update request to update one or more of the related information of the virtual memory range (Vregion), the first mapping relationship, and the physical page information.

[0113] In response to receiving an update request from an application, the operating system may determine a corresponding target virtual address space (Vspace) according to the update request, and then search for a target virtual memory region (Vregion) in the target virtual address space (Vspace).

[0114] Step 502, the operating system traverses all allocated virtual memory regions (Vregion) in the virtual address space (Vspace).

[0115] Specifically, during the traversal process, when traversing to any allocated virtual memory interval (Vregion), the relevant information of the allocated virtual memory interval (Vregion), the first mapping relationship and one or more of the physical page information can be updated, and step 403 is executed until all allocated virtual memory intervals (Vregion) in the target virtual address space (Vspace) are traversed.

[0116] In some optional embodiments, when traversing to any allocated virtual memory interval (Vregion), the legality of the update request of the allocated virtual memory interval (Vregion) can also be judged. For example,

[0117] If the update request for the allocated virtual memory interval (Vregion) is determined to be a legitimate update request, then one or more of the related information, the first mapping relationship, and the physical page information in the allocated virtual memory interval (Vregion) may be updated.

[0118] If it is determined that the update request for the allocated virtual memory range (Vregion) is an illegal update request, an abnormal update process can be performed, wherein the specific method of the abnormal update process can refer to the prior art, and the embodiments of the present application will not be described in detail.

[0119] Step 503: The operating system updates one or more of the information related to the allocated virtual memory range (Vregion), the first mapping relationship, and the physical page information.

[0120] Specifically, when updating the relevant information of any allocated virtual memory interval (Vregion), the first mapping relationship can be updated accordingly, and all physical pages mapped by the allocated virtual memory interval (Vregion) can be traversed, and the information of all physical pages mapped by the allocated virtual memory interval (Vregion) can be updated.

[0121] It is understandable that when the information of all physical pages is updated, after the current physical page is updated, the next physical page may be updated until all physical pages in the currently allocated virtual memory region (Vregion) are updated.

[0122] It can be understood that after traversing all physical pages mapped to the currently allocated virtual memory interval (Vregion) and updating the relevant information of the allocated virtual memory interval (Vregion), the first mapping relationship and one or more of the physical page information, it can be considered that the update of the currently allocated virtual memory interval (Vregion) has been completed, and the update of the next allocated virtual memory interval (Vregion) can be performed.

[0123] When updating any physical page, the page type of the physical page can be determined. The page type includes a common page type and a large page type. The common page type is used to indicate that the current physical page is a common physical page, and the large page type is used to indicate that the current physical page is a large physical page.

[0124] If the current physical page is an ordinary physical page, the operating system can update the page information in the ordinary physical page. Exemplarily, the page information may include information such as physical address information and a second mapping relationship, but does not constitute a limitation on the embodiments of the present application. In some embodiments, other information may also be included. Among them, the second mapping relationship can be considered to be a reverse mapping relationship corresponding to the first mapping relationship, and the second mapping relationship is used to characterize the mapping relationship between a physical address and one or more virtual memories. It can be understood that, contrary to the first mapping relationship, through the first mapping relationship, the corresponding physical memory can be accessed by the virtual memory interval (Vregion), and through the second mapping relationship, the corresponding virtual memory interval (Vregion) can be found by the current physical address.

[0125] If the current physical page is a large physical page, the operating system can determine the valid mapping area of ​​the large physical page. For example, if the virtual memory interval (Vregion) maps the entire large physical page, the valid mapping area is the entire large physical page; or if the virtual memory interval (Vregion) maps a partial area in the large physical page, the valid mapping area is a partial area in the large physical page.

[0126] Next, the operating system may update page information corresponding to the valid mapping area according to the determined valid mapping area.

[0127] In some optional embodiments, after the current large physical page is updated, it can also be determined whether the virtual memory interval (Vregion) corresponding to the current large physical page needs to be split. Exemplarily, when an update request updates a part of a large physical page, and the updated information such as access rights of the part of the physical page is inconsistent with other areas, the large physical page virtual memory interval (Vregion) can be split to obtain multiple virtual memory intervals (Vregion), and mapping information between multiple virtual memory intervals (Vregion) and physical pages can be created.

[0128] Figure 6 A diagram showing the effect of splitting a virtual memory range (Vregion) into multiple virtual memory ranges (Vregion). Figure 6 , V1 is the allocated virtual memory range (Vregion), V1 maps a large physical page, U1 is the area to be updated by the update request, and U2 and U3 are other areas in V1 except U1. It can be seen that the update request is to update part of the area in the large physical page. After U1 is updated, the access rights and other information of U1 may be inconsistent with those of U2 and U3. At this time, V1 can be split into three virtual memory ranges (Vregions) U1, U2 and U3. Since these three virtual memory ranges (Vregions) are not enough to map a large physical page, these three virtual memory ranges (Vregions) can be mapped to ordinary physical pages respectively.

[0129] Now, the updating of the relevant information of the virtual memory interval (Vregion) to reclaim the physical page is taken as an example for exemplary explanation. For example, when the operating system detects that the memory resources are tight, it can reclaim the allocated physical pages or the loaded physical pages to reclaim the physical memory. It can be understood that in addition to detecting that the memory resources are tight, the triggering of the reclaiming of the physical page can also include other scenarios. For example, the application can actively release the physical memory to reclaim the physical memory, or, as described above, when the operating system fails to allocate or load the physical page (including the ordinary physical page or the large physical page), the allocated or loaded physical page can be reclaimed. The embodiments of the present application do not make special limitations on this.

[0130] It is understandable that when any of the above scenarios occurs, the operating system can initiate a reclaim request to reclaim the allocated or loaded physical page. In addition, after the operating system determines the physical page to be reclaimed, it can search the virtual memory range (Vregion) corresponding to the physical page to be reclaimed through the second mapping relationship.

[0131] If the current physical page to be reclaimed is a common physical page, the mapping between the common physical page to be reclaimed and the virtual memory region (Vregion) can be released, and the reference count and the second mapping relationship of the common physical page to be reclaimed can be updated.

[0132] If the current physical page to be reclaimed is a large physical page, the mapping area of ​​the virtual memory interval (Vregion) in the large physical page to be reclaimed can be calculated, and the first mapping relationship between the mapping area and the virtual memory interval (Vregion) can be released based on the mapping area, and the reference count and the second mapping relationship of the large physical page to be reclaimed can be updated.

[0133] Exemplarily, the virtual memory interval corresponding to the large physical page to be reclaimed may be found according to the second mapping relationship, and then the first mapping relationship between the virtual memory interval corresponding to the physical page to be reclaimed and the physical page to be reclaimed may be released.

[0134] The updating method of the reference count of the large physical page may be determined according to whether the updated large physical page supports hybrid mapping. The specific implementation method of the reference count of the large physical page may refer to the relevant description in the above embodiment and will not be repeated here.

[0135] Figure 7 This is a schematic diagram of the structure of an embodiment of the memory management device of the present application, such as Figure 7 As shown, the memory management device 70 may include: an allocation module 71, a creation module 72, a determination module 73 and a mapping module 74; wherein,

[0136] The allocation module 71 is used to allocate virtual memory in response to the received memory allocation request;

[0137] A creation module 72, used to create a virtual memory interval for the allocated virtual memory, and bind the virtual memory interval to a target backend; wherein the backend is used to characterize the type of data source;

[0138] A determination module 73, configured to determine a physical page type according to the target backend, wherein the physical page type includes a common physical page type and a large physical page type;

[0139] The mapping module 74 is used to allocate or load a physical page according to the physical page type, and establish a first mapping relationship between the virtual memory interval and the allocated physical page or the loaded physical page.

[0140] In one possible implementation, the determination module 73 is further configured to, in response to detecting a page fault, search for a corresponding target virtual memory interval according to the page fault address; and the target virtual memory interval determines the target backend.

[0141] In one possible implementation, the determination module 73 is further configured to, in response to receiving a mapping establishment request, search for a corresponding target virtual memory interval according to an address of the mapping establishment request; and determine the target backend according to the target virtual memory interval.

[0142] In one possible implementation, the determination module 73 is further used to determine a target intersection of a large page window and the target virtual memory interval, wherein the large page window is used to represent a memory space that can be accommodated by a large physical page;

[0143] If the target intersection is equal to the memory space corresponding to the large physical page, determine that the physical page type is a large physical page type; or,

[0144] If the target intersection is smaller than the memory space corresponding to the large physical page, the physical page type is determined to be a common physical page type; or,

[0145] If the target intersection includes an allocated physical page or a loaded physical page, it is determined that the physical page type is a common physical page type.

[0146] In one possible implementation, the memory management device 70 further includes:

[0147] An update module is used to update, in response to a received update request, one or more of the relevant information of the target virtual memory interval, the first mapping relationship and the physical page information.

[0148] In one possible implementation, the allocated physical page or the loaded physical page is a large physical page.

[0149] In one possible implementation, the mapping module 74 is further configured to map the target virtual memory interval to a partial area of ​​the allocated physical page or the loaded physical page; or,

[0150] The target virtual memory interval is mapped to the entire area of ​​the allocated physical page or the loaded physical page.

[0151] In one possible implementation, the memory management device 70 further includes:

[0152] a release module, configured to select a reclaimable physical page from the allocated or loaded physical pages in response to detecting a reclaim request, and release the first mapping relationship between the virtual memory interval and the reclaimable physical page;

[0153] The recyclable physical page is a common physical page or a large physical page.

[0154] In one possible implementation, the reclaimable physical page is a large physical page, and the virtual memory interval is mapped to a partial area of ​​the reclaimable physical page, or the virtual memory interval is mapped to the entire area of ​​the reclaimable physical page.

[0155] In one possible implementation, the reclaimable physical page is a large physical page, and the release module is further used to find the virtual memory interval corresponding to the reclaimable physical page according to a second mapping relationship, wherein the second mapping relationship is used to represent a mapping relationship between a physical page and one or more virtual memory intervals;

[0156] The first mapping relationship between the virtual memory interval corresponding to the reclaimable physical page and the reclaimable physical page is released.

[0157] Figure 7 The memory management device 70 provided in the illustrated embodiment can be used to execute the technical solution of the method embodiment illustrated in the present application. Its implementation principle and technical effects can be further referred to the relevant description in the method embodiment.

[0158] It should be understood that the above Figure 7 The division of the various modules of the memory management device 70 shown is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software calling through processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software calling through processing elements, and some modules can be implemented in the form of hardware. For example, the detection module can be a separately established processing element, or it can be integrated in a chip of an electronic device. The implementation of other modules is similar. In addition, these modules can be fully or partially integrated together, or they can be implemented independently. In the implementation process, each step of the above method or the above modules can be completed by the hardware integrated logic circuit in the processor element or the instructions in the form of software.

[0159] For example, the above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASIC), or one or more microprocessors (DSP), or one or more field programmable gate arrays (FPGA). For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).

[0160] Combine the following Figure 8 The exemplary electronic device provided in the embodiments of the present application is further introduced. Figure 8 A schematic structural diagram of an electronic device 800 is shown.

[0161] The electronic device 800 may include: at least one processor; and at least one memory communicatively connected to the processor, wherein: the memory stores program instructions executable by the processor, and the processor calls the program instructions to execute the method provided in the embodiment shown in the present application.

[0162] Figure 8 A block diagram of an exemplary electronic device 800 suitable for implementing the embodiments of the present application is shown. Figure 8 The electronic device 800 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0163] like Figure 8 As shown, the electronic device 800 is in the form of a general computing device. The components of the electronic device 800 may include, but are not limited to: one or more processors 810, a memory 820, a communication bus 840 connecting different system components (including the memory 820 and the processor 810), and a communication interface 830.

[0164] The communication bus 840 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor or a local bus using any of a variety of bus structures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnection (PCI) bus.

[0165] The electronic device 800 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device, including volatile and non-volatile media, removable and non-removable media.

[0166] The memory 820 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) and / or cache memory. The electronic device may further include other removable / non-removable, volatile / non-volatile computer system storage media. Figure 8 Not shown, a disk drive for reading and writing a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing a removable non-volatile optical disk (e.g., a compact disc read only memory (CD-ROM), a digital versatile disc read only memory (DVD-ROM), or other optical media) may be provided. In these cases, each drive may be connected to the communication bus 840 via one or more data medium interfaces. The memory 820 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present application.

[0167] A program / utility having a set (at least one) of program modules may be stored in memory 820, such program modules including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules typically perform the functions and / or methods of the embodiments described herein.

[0168] The electronic device 800 may also communicate with one or more external devices (e.g., keyboards, pointing devices, displays, etc.), one or more devices that enable a user to interact with the electronic device, and / or any device that enables the electronic device to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed via the communication interface 830. Furthermore, the electronic device 800 may also communicate with a network adapter ( Figure 8 The network adapter can communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through the communication bus 840. It should be understood that although Figure 8Not shown, other hardware and / or software modules may be used in conjunction with the electronic device 800, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, disk arrays (Redundant Arrays of Independent Drives; hereinafter referred to as: RAID) systems, tape drives, and data backup storage systems.

[0169] The processor 810 executes various functional applications and data processing by running the programs stored in the memory 820, such as implementing the method provided in the embodiment of the present application.

[0170] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 800. In other embodiments of the present application, the electronic device 800 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0171] In the above embodiments, the processor involved may include, for example, a CPU, a DSP, a microcontroller or a digital signal processor, and may also include a GPU, an embedded neural network processor (Neural-network Process Units; hereinafter referred to as: NPU) and an image signal processor (Image Signal Processing; hereinafter referred to as: ISP). The processor may also include necessary hardware accelerators or logic processing hardware circuits, such as ASIC, or one or more integrated circuits for controlling the execution of the program of the technical solution of the present application. In addition, the processor may have the function of operating one or more software programs, and the software programs may be stored in a storage medium.

[0172] An embodiment of the present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer-readable storage medium is run on a computer, the computer executes the method provided by the embodiment shown in the present application.

[0173] An embodiment of the present application also provides a computer program product, which includes a computer program. When the computer program is run on a computer, it enables the computer to execute the method provided by the embodiment shown in the present application.

[0174] In the embodiments of the present application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent the existence of A alone, the existence of A and B at the same time, and the existence of B alone. Among them, A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" and similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b and c can be represented by: a, b, c, a and b, a and c, b and c, or a and b and c, where a, b, c can be single or multiple.

[0175] Those of ordinary skill in the art will appreciate that the various units and algorithm steps described in the embodiments disclosed herein can be implemented in a combination of electronic hardware, computer software, and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0176] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0177] In several embodiments provided in the present application, if any function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory; hereinafter referred to as: ROM), random access memory (Random Access Memory; hereinafter referred to as: RAM), disk or optical disk, and other media that can store program codes.

[0178] The above is only a specific implementation of the present application. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. The protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A memory management method, It is characterized in that The method comprises: In response to the received memory allocation request, allocating virtual memory; Creating a virtual memory interval for the allocated virtual memory, and binding the virtual memory interval to a target backend; wherein the backend is used to characterize the type of data source; Determine a physical page type according to the target backend, where the physical page type includes a common physical page type and a large physical page type; A physical page is allocated or loaded according to the physical page type, and a first mapping relationship between the virtual memory interval and the allocated physical page or the loaded physical page is established.

2. The method according to claim 1, It is characterized in that After binding the virtual memory interval to the target backend, the method further includes: In response to detecting a page fault, searching a corresponding target virtual memory interval according to the page fault address; The target backend is determined according to the target virtual memory interval.

3. The method according to claim 1, It is characterized in that After binding the virtual memory interval to the target backend, the method further includes: In response to receiving a mapping establishment request, searching for a corresponding target virtual memory interval according to an address of the mapping establishment request; and determining the target backend according to the target virtual memory interval.

4. The method according to claim 1, It is characterized in that Determining the physical page type according to the target backend includes: Determining a target intersection of a large page window and the target virtual memory interval, wherein the large page window is used to represent a memory space that can be accommodated by a large physical page; If the target intersection is equal to the memory space corresponding to the large physical page, determine that the physical page type is a large physical page type; or, If the target intersection is smaller than the memory space corresponding to the large physical page, the physical page type is determined to be a common physical page type; or, If the target intersection includes an allocated physical page or a loaded physical page, it is determined that the physical page type is a common physical page type.

5. The method according to any one of claims 1 to 4, It is characterized in that After allocating or loading a physical page according to the physical page type and establishing a first mapping relationship between the target virtual memory interval and the allocated physical page or the loaded physical page, the method further includes: In response to the received update request, one or more of the relevant information of the target virtual memory range, the first mapping relationship and the physical page information is updated.

6. The method according to any one of claims 1 to 5, It is characterized in that The allocated physical page or the loaded physical page is a large physical page, and the establishing of a first mapping relationship between the target virtual memory interval and the allocated physical page or the loaded physical page includes: Mapping the target virtual memory interval to a partial area of ​​the allocated physical page or a partial area of ​​the loaded physical page; or, The target virtual memory interval is mapped to the entire area of ​​the allocated physical page or the entire area of ​​the loaded physical page.

7. The method according to claim 1, It is characterized in that After allocating or loading a physical page according to the physical page type and establishing a first mapping relationship between the target virtual memory interval and the allocated physical page or the loaded physical page, the method further includes: In response to detecting a reclaim request, selecting a reclaimable physical page from the allocated or loaded physical pages, and releasing a first mapping relationship between the virtual memory interval and the reclaimable physical page; The recyclable physical page is a common physical page or a large physical page.

8. The method according to claim 7, It is characterized in that The reclaimable physical page is a large physical page, and the virtual memory interval is mapped to a partial area of ​​the reclaimable physical page, or the virtual memory interval is mapped to the entire area of ​​the reclaimable physical page.

9. The method according to claim 7, It is characterized in that The reclaimable physical page is a large physical page, and the releasing of the first mapping relationship between the virtual memory interval and the reclaimable physical page includes: Finding a virtual memory interval corresponding to the reclaimable physical page according to a second mapping relationship, wherein the second mapping relationship is used to represent a mapping relationship between a physical page and one or more virtual memory intervals; The first mapping relationship between the virtual memory interval corresponding to the reclaimable physical page and the reclaimable physical page is released.

10. An electronic device, It is characterized in that include: A processor and a memory, wherein the memory is used to store a computer program; and the processor is used to run the computer program to implement the method according to any one of claims 1 to 9.

11. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed on a computer, the method according to any one of claims 1 to 9 is implemented.

Citation Information

Cited By

  • Memory management method, electronic device, and storage medium

    EP4693044A1

  • Memory management method, electronic device, and storage medium

    WO2024234711A1