Memory management method and computer equipment

By using large page granularity to create page frame metadata in computer systems and refine physical pages according to process needs, the problem of large memory management overhead in the existing technology is solved, and efficient physical page allocation and low waste are achieved.

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

Patent Information

Application Number
CN202310545650.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-05-15
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

When existing computer systems are in memory management, static page frame metadata based on physical pages leads to high management overhead, especially in large page scenarios, which is difficult to meet the allocation needs of different granularities.

Method used

Use large-page granularity to create page frame metadata, and decide whether to further refine the physical pages based on the physical memory requirements of the process, thereby saving management overhead and achieving granular flexible physical page allocation.

Benefits of technology

It effectively saves the management overhead of page frame metadata, realizes rapid allocation of physical pages that meet process needs, reduces memory waste, and is suitable for allocation needs of different granularities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118964227A_ABST
    Figure CN118964227A_ABST
Patent Text Reader

Abstract

The invention provides a memory management method which is characterized by comprising the steps that a physical memory is divided into N first physical pages according to first granularity, N first page frame metadata corresponding to the N first physical pages are created, and the first granularity is larger than the minimum granularity supported by computer equipment; determining the size of a physical memory required by the first process according to the request of the first process; and according to the size of the physical memory required by the first process, selecting the first granularity to allocate O first physical pages for the first process or selecting the second granularity to allocate Q second physical pages for the first process, or selecting the first granularity to allocate W first physical pages for the first process and selecting the second granularity to allocate T second physical pages for the first process. According to the method and the device, the page frame metadata is created for the physical memory according to the large page granularity, and whether the physical page is further refined or not is determined according to the size of the physical memory required by the first process, so that the management overhead of the page frame metadata can be saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computers, and more specifically, to a memory management method and a computer device. Background Art

[0002] The memory of a computer system is usually managed by physical pages, and the size of a physical page is usually 4K. When the computer system starts, it divides the physical pages according to the minimum granularity supported by the hardware and creates page frame metadata, and then manages the physical memory through the page frame metadata. The performance overhead of this static creation of page frame metadata is small, but there is the following problem: when the computer manages memory in this way, it will generate management overhead proportional to the total amount of physical memory. For example, the base page size is 4KB, the page frame metadata size is 64Byte, and the computer's memory management overhead is about 64 / (4*1024)=1.5%. In the large page scenario, the memory management overhead is determined by the base page. For example, the base page size is 4KB, the large page size is 2MB, and the page frame metadata size is 64Byte. The large page consists of 512 base pages, corresponding to 512 page frame metadata. After merging, 511 of the page frame metadata will be wasted, and the waste rate is as high as 99.8%. Based on this, there is an urgent need for a memory management method that can save the waste of page frame metadata and meet allocation requirements of different granularities. Summary of the invention

[0003] The present application provides a memory management method and a computer device, which can first create page frame metadata for physical memory according to the large page granularity, and then determine whether to further refine the physical page according to the size of the physical memory required by the first process, thereby saving the management overhead of the page frame metadata and realizing the rapid allocation of physical pages that meet the granularity of the first process.

[0004] In a first aspect, a memory management method is provided, characterized in that the method is applied to a computer device, and the method comprises: dividing a physical memory into N first physical pages according to a first granularity and creating N first page frame metadata corresponding to the N first physical pages, the first granularity being greater than a minimum granularity supported by the computer device, N ≥ 1 and being an integer, each of the N first page frame metadata comprising a first field to indicate a size of a corresponding first physical page; determining a size of a physical memory required by the first process according to a request of the first process; and determining a size of a physical memory required by the first process according to the first granularity. The size of the physical memory required by a process is selected by allocating O first physical pages to the first process at a first granularity or by allocating Q second physical pages to the first process at a second granularity, or by allocating W first physical pages to the first process at the first granularity and T second physical pages to the first process at the second granularity, wherein the second granularity is smaller than the first granularity, the second granularity is greater than or equal to the minimum granularity supported by the computer device, N≥O≥1, and O is an integer, Q≥1, and Q is an integer, N≥W≥1, and W is an integer, and T≥1, and T is an integer.

[0005] In an embodiment of the present application, page frame metadata is first created for the physical memory at a large page granularity, and then it is determined whether to further refine the physical pages based on the size of the physical memory required by the first process, thereby saving the management overhead of the page frame metadata and achieving rapid allocation of physical pages that meet the granularity of the first process.

[0006] In combination with the first aspect, in certain implementations of the first aspect, the selection allocates Q second physical pages to the first process at a second granularity, including: selecting M first physical pages from the N first physical pages, N≥M≥1, and M is an integer; converting the M first physical pages into P second physical pages according to the second granularity, and creating corresponding P second page frame metadata, P>M≥1, and P is an integer, each of the P second page frame metadata including a first field to indicate the size of the corresponding second physical page; selecting the Q second physical pages from the P second physical pages and allocating them to the first process.

[0007] In combination with the first aspect, in certain implementations of the first aspect, each of the N first page frame metadata includes a second field to indicate that the N first page frame metadata are valid page frame metadata, and after converting the M first physical pages into P second physical pages according to the second granularity, the method also includes: changing the value of the second field of each of the M first page frame metadata corresponding to the M first physical pages to indicate that the M first physical pages are invalid page frame metadata.

[0008] In combination with the first aspect, in certain implementations of the first aspect, the method also includes: detecting that the first preset condition is met, reclaiming the Q second physical pages; reconverting the P second physical pages into the M first physical pages, and releasing the P second page frame metadata; changing the value of the second field of each first page frame metadata of the M first page frame metadata corresponding to the M first physical pages to indicate that the M first physical pages are valid page frame metadata.

[0009] In combination with the first aspect, in certain implementations of the first aspect, the selection to allocate W first physical pages to the first process at the first granularity and to allocate T second physical pages to the first process at the second granularity includes: selecting W first physical pages from the N first physical pages to allocate to the first process, N≥W≥1, and W is an integer; selecting S first physical pages from the NW first physical pages, NW≥S≥1, and S is an integer; converting the S first physical pages into D second physical pages according to the second granularity, and creating corresponding D second page frame metadata, D>S>1, and D is an integer, each of the D second page frame metadata including a first field to indicate the size of the corresponding second physical page; selecting the T second physical pages from the D second physical pages to allocate to the first process.

[0010] In combination with the first aspect, in certain implementations of the first aspect, each of the N first page frame metadata includes a second field to indicate that the N first page frame metadata are valid page frame metadata, and before selecting to allocate O first physical pages to the first process at the first granularity, the method also includes: converting the N first physical pages into L physical blocks through a partner algorithm, the L physical blocks corresponding to L third page frame metadata, each of the L third page frame metadata includes a first field to indicate the size of the corresponding physical block, and each of the L third page frame metadata includes a second field to indicate that each third page frame metadata is valid page frame metadata; the selection to allocate O first physical pages to the first process at the first granularity includes: selecting a first physical block from the L physical blocks to allocate to the first process, and the first physical block includes O first physical pages.

[0011] In combination with the first aspect, in certain implementations of the first aspect, the L third page frame metadata are obtained based on L first page frame metadata among the N first page frame metadata, and the method also includes: changing the value of the second field of each of the NL first page frame metadata to indicate that the NL first page frame metadata are invalid page frame metadata.

[0012] In combination with the first aspect, in certain implementations of the first aspect, each of the P second page frame metadata includes a second field to indicate that the P second page frame metadata is valid page frame metadata, and before selecting the Q second physical pages from the P second physical pages and assigning them to the first process, the method also includes: converting the P second physical pages into R physical blocks through a partner algorithm, the R physical blocks corresponding to R fourth page frame metadata, each of the R fourth page frame metadata includes a first field to indicate the size of the corresponding physical block, and each of the R fourth page frame metadata includes a second field to indicate that each fourth page frame metadata is valid page frame metadata; selecting the Q second physical pages from the P second physical pages and assigning them to the first process includes: selecting a second physical block from the R physical blocks and assigning it to the first process, the first physical block including Q second physical pages.

[0013] In combination with the first aspect, in certain implementations of the first aspect, the R fourth page frame metadata are obtained based on the R second page frame metadata among the P second page frame metadata, and the method further includes: changing the value of the second field of each second page frame metadata among the PR second page frame metadata to indicate that the PR second page frame metadata is invalid page frame metadata. 10. The method according to claim 8 or 9, characterized in that each first page frame metadata among the N first page frame metadata includes a fourth field to indicate whether the first physical page corresponding to the N first page frame metadata is divided, and after converting the M first physical pages to the P second physical pages, the method further includes: changing the value of the fourth field of each page frame metadata of the M first page frame metadata corresponding to the M first physical pages to indicate that the M first physical pages have been divided.

[0014] In combination with the first aspect, in some implementations of the first aspect, the P second page frame metadata are stored in any one of the P second physical pages.

[0015] In combination with the first aspect, in some implementations of the first aspect, when it is selected to allocate O first physical pages to the first process at a first granularity, the method further includes: when it is detected that a first preset condition is met, reclaiming the O first physical pages.

[0016] In combination with the first aspect, in some implementations of the first aspect, each of the N first page frame metadata includes a third field to indicate that the N first page frame metadata are created by a main page frame manager.

[0017] In a second aspect, a method for a memory manager is provided, the method being applied to a computer device, the computer device comprising a main page frame manager, a first secondary page frame manager and a page allocator, the main page frame manager being used to manage a first physical page of a first granularity, the first secondary page frame manager being used to manage a second physical page of a second granularity, wherein the main page frame manager is used to divide a physical memory into N first physical pages according to the first granularity and to create N first page frame metadata corresponding to the N first physical pages, the first granularity being greater than a minimum granularity supported by the computer device, N ≥ 1 and being an integer, each of the N first page frame metadata comprising a first field to indicate a size of a corresponding first physical page ; The page allocator is used to determine the size of the physical memory required by the first process according to the request of the first process; the page allocator is also used to select, according to the size of the physical memory required by the first process, to allocate O first physical pages to the first process at the first granularity or to allocate Q second physical pages to the first process at the second granularity, or to allocate W first physical pages to the first process at the first granularity and T second physical pages to the first process at the second granularity, wherein the second granularity is smaller than the first granularity, the second granularity is greater than or equal to the minimum granularity supported by the computer device, N≥O≥1, and O is an integer, Q≥1 and Q is an integer, N≥W≥1, and W is an integer, and T≥1 and T is an integer.

[0018] In an embodiment of the present application, page frame metadata is first created for the physical memory at a large page granularity, and then it is determined whether to further refine the physical pages based on the size of the physical memory required by the first process, thereby saving the management overhead of the page frame metadata and achieving rapid allocation of physical pages that meet the granularity of the first process.

[0019] In combination with the second aspect, in certain implementations of the second aspect, when the page allocator chooses to allocate Q second physical pages to the first process at the second granularity, the first secondary page frame manager is used to: select M first physical pages from the N first physical pages, N≥M≥1, and M is an integer; convert the M first physical pages into P second physical pages according to the second granularity, and create corresponding P second page frame metadata, P>M≥1, and P is an integer, each of the P second page frame metadata includes a first field to indicate the size of the corresponding second physical page; the page allocator is specifically used to select the Q second physical pages from the P second physical pages and allocate them to the first process.

[0020] In combination with the second aspect, in certain implementations of the second aspect, each of the N first page frame metadata includes a second field to indicate that the N first page frame metadata are valid page frame metadata, and after converting the M first physical pages into P second physical pages according to the second granularity, the main page frame manager is further used to change the value of the second field of each of the M first page frame metadata corresponding to the M first physical pages to indicate that the M first physical pages are invalid page frame metadata.

[0021] In combination with the second aspect, in certain implementations of the second aspect, when the page allocation chooses to allocate Q second physical pages to the first process at a second granularity, the page allocator is further used to detect that a first preset condition is satisfied and determine the first secondary page frame manager; the first secondary page frame manager is further used to: recycle the Q second physical pages; reconvert the P second physical pages into the M first physical pages, and release the P second page frame metadata; the main page frame manager is further used to change the value of the second field of each of the M first page frame metadata corresponding to the M first physical pages to indicate that the M first physical pages are valid page frame metadata.

[0022] In combination with the second aspect, in certain implementations of the second aspect, when the page allocator chooses to allocate W first physical pages to the first process at the first granularity and allocate T second physical pages to the first process at the second granularity, the page allocator is specifically used to select W first physical pages from the N first physical pages and allocate them to the first process, N≥W≥1, and W is an integer; the first secondary page frame manager is used to: select S first physical pages from the NW first physical pages, NW≥S≥1, and S is an integer; convert the S first physical pages into D second physical pages according to the second granularity, and create corresponding D second page frame metadata, D>S>1, and D is an integer, each of the D second page frame metadata includes a first field to indicate the size of the corresponding second physical page; the page allocator is specifically used to select the T second physical pages from the D second physical pages and allocate them to the first process.

[0023] In combination with the second aspect, in certain implementations of the second aspect, each of the N first page frame metadata includes a second field to indicate that the N first page frame metadata are valid page frame metadata, and before the page allocator selects to allocate O first physical pages to the first process at the first granularity, the main page frame manager is also used to convert the N first physical pages into L physical blocks through a partner algorithm, the L physical blocks correspond to L third page frame metadata, each of the L third page frame metadata includes a first field to indicate the size of the corresponding physical block, and each of the L third page frame metadata includes a second field to indicate that each third page frame metadata is valid page frame metadata; the page allocator is specifically used to select a first physical block from the L physical blocks to allocate to the first process, and the first physical block includes O first physical pages.

[0024] In combination with the second aspect, in some implementations of the second aspect, the main page frame manager is further used to change the value of the second field of each of the NL first page frame metadata to indicate that the NL first page frame metadata are invalid page frame metadata.

[0025] In combination with the second aspect, in certain implementations of the second aspect, each of the P second page frame metadata includes a second field to indicate that the P second page frame metadata is valid page frame metadata, and before the page allocator selects the Q second physical pages from the P second physical pages to allocate to the first process, the first main page frame manager is further used to convert the P second physical pages into R physical blocks through a buddy algorithm, the R physical blocks correspond to R fourth page frame metadata, each of the R fourth page frame metadata includes a first field to indicate the size of the corresponding physical block, and each of the R fourth page frame metadata includes a second field to indicate that each fourth page frame metadata is valid page frame metadata; the main page frame manager is specifically used to select a second physical block from the R physical blocks and allocate it to the first process, and the first physical block includes Q second physical pages.

[0026] In combination with the second aspect, in some implementations of the second aspect, the first secondary page frame manager is further used to change the value of the second field of each of the PR second page frame metadata to indicate that the PR second page frame metadata are invalid page frame metadata.

[0027] In combination with the second aspect, in certain implementations of the second aspect, each of the N first page frame metadata includes a fourth field to indicate whether the first physical page corresponding to the N first page frame metadata is divided, and after the first secondary page frame manager converts the M first physical pages into the P second physical pages, the main page frame manager is also used to change the value of the fourth field of each of the M first page frame metadata corresponding to the M first physical pages to indicate that the M first physical pages have been divided.

[0028] In combination with the second aspect, in some implementations of the second aspect, the P second page frame metadata are stored in any one of the P second physical pages.

[0029] In combination with the second aspect, in certain implementations of the second aspect, when the page allocator chooses to allocate O first physical pages to the first process at a first granularity, the page allocator is further used to detect that a first preset condition is met and select the home page frame manager; the home page frame manager is further used to recycle the O first physical pages.

[0030] In combination with the second aspect, in some implementations of the second aspect, each of the N first page frame metadata includes a third field to indicate that the N first page frame metadata are created by a main page frame manager.

[0031] In a third aspect, a device for managing memory is provided, the device comprising: a storage module for storing programs; a processing module for executing the programs stored in the storage module, when the programs stored in the storage module are executed, the processing module is used to execute the methods provided in the above aspects.

[0032] According to a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable medium stores a program code for execution by a device, wherein the program code includes code for executing the methods provided in the above aspects.

[0033] According to a fifth aspect, a computer program product comprising instructions is provided. When the computer program product is run on a computer, the computer is used to execute the methods provided in the above aspects.

[0034] In a sixth aspect, a chip is provided, which includes a processing module and a communication interface. The processing module reads instructions stored in a memory through the communication interface to execute the methods provided in the above aspects.

[0035] Optionally, as an implementation method, the chip may also include a storage module, in which instructions are stored, and the processing module is used to execute the instructions stored on the storage module. When the instructions are executed, the processing module is used to execute the methods provided by the above aspects.

[0036] In a seventh aspect, a chip is provided, comprising a processing core for executing the method provided in the first aspect and a memory management unit for executing the method provided in the second aspect.

[0037] In an eighth aspect, a computer device is provided, which includes the chip shown in the seventh aspect.

[0038] In a ninth aspect, a computer device is provided, comprising one or more processors; one or more memories; the one or more memories storing one or more computer programs, the one or more computer programs comprising instructions, which, when executed by the one or more processors, enable the computer to execute the method provided in the above aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 It is a schematic hardware structure diagram of a computer device (or a computer system) to which the method for memory management according to an embodiment of the present application is applicable.

[0040] Figure 2 A schematic diagram of converting the page frame metadata of a basic page into the page frame metadata of a composite page is shown.

[0041] Figure 3 It is a schematic diagram of the system architecture provided in an embodiment of the present application.

[0042] Figure 4 It is a schematic flowchart of the memory management method provided in an embodiment of the present application.

[0043] Figure 5 It is a schematic diagram of converting a first physical page into a second physical page provided by an embodiment of the present application.

[0044] Figure 6 It is a schematic flowchart of a method for determining a physical address based on page frame metadata provided in an embodiment of the present application.

[0045] Figure 7 It is a schematic diagram of determining a physical address based on page frame metadata provided by an embodiment of the present application.

[0046] Figure 8 An embodiment of the present application provides a schematic flowchart of a method for determining page frame metadata according to a physical address.

[0047] Fig. 9 It is a schematic flowchart of the memory management method provided in an embodiment of the present application.

[0048] Fig.10 It is a schematic flowchart of the memory management method provided in an embodiment of the present application.

[0049] Fig.11 It is a structural schematic diagram of a chip system provided in an embodiment of the present application.

[0050] Fig.12 It is a conceptual partial view of the computer program product provided by the embodiment of the present application. DETAILED DESCRIPTION

[0051] The following describes the embodiments of the present application in conjunction with the accompanying drawings. Obviously, the described embodiments are only embodiments of a part of the present application, rather than all embodiments. It is known to those skilled in the art that with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0052] The method for accessing memory provided in the embodiment of the present application is applied to a computer system, which may be a server, a terminal device, a virtual machine (VM) or a container. The architecture of the computer system can be found at Figure 1 To understand. Figure 1 A schematic diagram of the computer system architecture.

[0053] A computing device may also be referred to as a computer system. From a logical hierarchical point of view, a computing device may include a hardware layer, an operating system layer running on the hardware layer, and an application layer running on the operating system layer. The hardware layer includes hardware such as a processing unit, a memory, and a memory control unit, and the functions and structures of the hardware are subsequently described in detail. The operating system may be any one or more computer operating systems that implement business processing through a process, such as a Linux operating system, a Unix operating system, an Android operating system, an iOS operating system, or a Windows operating system. The application layer includes applications such as a browser, an address book, a word processing software, and an instant messaging software. Furthermore, in an embodiment of the present application, the computer system may be a handheld device such as a smart phone, or a terminal device such as a personal computer. The present application is not particularly limited, as long as the program code of the method of memory management behavior of the embodiment of the present application can be read and run. The execution subject of the method of memory management in the embodiment of the present application may be a computer device, or a functional module in a computer system that can call and execute a program.

[0054] In this application, a program or program code refers to a set of ordered instructions (or codes) used to implement a relatively independent function. A process is a process in which a program and its data are run on a computer device. Programs are usually designed in a modular manner, that is, the functions of the program are broken down into multiple smaller functional modules. A program contains at least one function, which is a code segment that implements a functional module. Therefore, a function is the basic unit of program function modularization and can also be regarded as a subroutine.

[0055] Figure 1 1 is a schematic diagram of the architecture of a computing device 100 provided in an embodiment of the present application. The computing device 100 may include: at least one processor 110 and a memory 120.

[0056] Optionally, the computer device 110 may further include a system bus, wherein the processor 110 and the memory 120 are respectively connected to the system bus. The processor 110 can access the memory 120 through the system bus. For example, the processor 110 can read and write data or execute code in the memory 120 through the system bus.

[0057] The function of the processor 110 is mainly to interpret the instructions (or codes) of the computer program and process the data in the computer software. The instructions of the computer program and the data in the computer software can be stored in the memory 120 or the cache unit 116.

[0058] In the embodiment of the present application, the processor 110 may be an integrated circuit chip with signal processing capabilities. As an example and not a limitation, the processor 110 may be a general-purpose processor, a system on chip (System On Chip, SOC), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, or any combination of the above devices. Among them, the general-purpose processor may be a microprocessor, etc. Among them, each processor 110 includes a memory control unit 114 and at least one processing unit 112. The processing unit 112 may also be referred to as a core or a kernel or a processing core or a central processing unit (CPU), which is the most important component of the processor. The processing unit 112 may be manufactured from single crystal silicon with a certain production process, and all calculations, command acceptance, command storage, and data processing of the processor are performed by the core. The processing unit can run program instructions independently and use the ability of parallel computing to speed up the running speed of the program. Various processing units have a fixed logical structure. For example, the processing unit includes logical units such as an execution unit, an instruction level unit, and a bus interface.

[0059] The memory control unit 114 is used to control the data interaction between the memory 120 and the processing unit 112. Specifically, the memory control unit 114 can receive a memory access request from the processing unit 112, and control the access to the memory based on the memory access request. As an example but not a limitation, in the embodiment of the present application, the memory control unit can be a device such as a memory management unit (MMU).

[0060] In the embodiment of the present application, each memory control unit 114 can address the memory 120 through the system bus. In addition, an arbiter (not shown) can be configured in the system bus, and the arbiter can be responsible for processing and coordinating the contention access of multiple processing units 112.

[0061] In the embodiment of the present application, the processing unit 112 and the memory control unit 114 can be connected to each other through the connection lines inside the chip, such as address lines, so as to achieve communication between the processing unit 112 and the memory control unit 114.

[0062] Optionally, each processor 110 may also include a cache unit 116, wherein the cache is a buffer for data exchange (called cache). When the processing unit 112 wants to read data, it will first search for the required data from the cache. If it is found, it will be executed directly. If it is not found, it will be searched from the memory. Since the running speed of the cache is much faster than that of the memory, the role of the cache is to help the processing unit 112 run faster.

[0063] The memory 120 can provide a running space for the processes in the computing device 100. For example, the computer program (specifically, the program code) used to generate the process can be stored in the memory 120, and the data generated during the running of the process, such as intermediate data or process data, can be stored in the memory 120. The memory can also be called internal memory, and its function is to temporarily store the calculation data in the processor 110 and the data exchanged with the external memory such as the hard disk. As long as the computer is running, the processor 110 will transfer the data to be calculated to the memory for calculation, and when the calculation is completed, the processing unit 112 will transmit the result.

[0064] As an example and not limitation, in the present application, the memory 120 may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memory. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchlink DRAM (SLDRAM), and direct rambus RAM (DR RAM). It should be noted that the memory 120 of the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.

[0065] It should be understood that the structure of the computing device 100 listed above is only an example, and the present application is not limited thereto. The computing device 100 of the embodiment of the present application may include various hardware in the computer system in the prior art. For example, the computing device 110 may also include other storage devices besides the memory 120, such as disk storage devices, etc.

[0066] To facilitate understanding of the embodiments of the present application, some basic concepts involved in the present application are briefly described.

[0067] 1. Virtual address: It is an address in the address space that the operating system can recognize or generate. Its size range can be determined by the number of bits of the operating system running in the processor. For example, if the operating system running in the processor is 32 bits, the virtual address is also 32 bits, and its virtual address range is 0-0xFFFFFFFF (4GB); if the operating system running in the processor is 64 bits, the virtual address is also 64 bits, and its address space is 0-0xFFFFFFFFFFFFFFFF (16EB).

[0068] Virtual addresses can be divided into multiple virtual address spaces according to actual needs, such as user-mode address space and kernel-mode address space. User-mode address space can be accessed by user-mode programs (such as reading, writing, opening, closing or drawing) and kernel-mode programs (such as process management, storage management, file management or device management), and kernel-mode address space can only be accessed by kernel-mode programs at runtime. Each process in the operating system will correspond to a virtual address space.

[0069] 2. Physical address: It can be an address in the address space actually possessed by a hardware storage device such as an internal memory.

[0070] 3. Virtual page: It can also be called page. MMU can use paging mechanism to manage virtual address space in units of virtual pages. Each page can include a virtual address space of a preset size. Virtual address space can include more than one virtual address, and a virtual address space can correspond to a page table set. The page table set can be used to determine the physical address corresponding to the virtual address of the virtual address space.

[0071] Accordingly, the MMU can determine the physical address corresponding to the virtual address through a set of page tables.

[0072] 4. Physical page: In the Linux kernel, the main function of MMU is to map "virtual address" to real "physical address". Specifically, MMU uses physical page as the basic unit of memory management. The size of physical page is directly related to hardware capability support and architecture. Currently, all architectures support physical page with granularity of 4KB, and some architectures also support physical page with granularity of 16KB and 64KB.

[0073] There are usually requirements for the division of physical pages. 4KB pages are usually called basic pages, and pages larger than 4KB are usually called "large pages" or "compound pages". For example, 2 megabyte (MB) pages and 1 gigabyte (GB) pages are called large pages. Of course, large pages can have other specifications, but they are usually integer multiples of 4KB. The basic page can be understood as the smallest granularity supported by computer devices.

[0074] 5. Page table: A special data structure stored in memory. The page table can be used as an index of the virtual address space and can include multiple page table entries, each of which includes the association between the page table entry index address and the physical address, where the physical address can be carried in the page table descriptor of the page table entry, which can be used to indicate the base address of the next level page table or the base address of the physical address corresponding to the virtual address.

[0075] 6. Page table translation: When the processing core in the processor needs to access the memory when running a process, the processing core usually sends the virtual address of the process to the memory management unit (MMU) so that the MMU can convert the virtual address of the process into the physical address of the memory according to the page table corresponding to the process. This process is called page table translation (or address translation, address conversion, etc.).

[0076] 7. Page Table Entry (PTE): A page table consists of multiple page table entries, that is, each row in the page table is a page table entry. Taking a 64-bit system as an example, the size of a page table entry is 8 bytes (byte, B). The information recorded in a page table entry includes:

[0077] Page frame number: records the specific physical page corresponding to the virtual page;

[0078] Valid bit (V): indicates whether the virtual page corresponding to the page table entry is read into the memory, otherwise it is on the disk;

[0079] Access bit: reference bit, indicating whether the virtual page has been accessed;

[0080] Modification bit: whether this virtual page has been modified in memory. If it has been modified, it will be persisted to disk in the future. This flag bit is for this purpose.

[0081] Protection bit: identifies the read and write permissions of the virtual page.

[0082] In addition, in order to facilitate understanding of the embodiments of the present application, the following explanations are made.

[0083] First, "at least one" shown in the present application refers to one or more, and "multiple" refers to two or more. In addition, in the embodiments of the present application, "first", "second" and various digital numbers (for example, "#1", "#2", etc.) are only for the convenience of description, and are not used to limit the scope of the embodiments of the present application. The size of the sequence number of each process below does not mean the order of execution. The execution order of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application. It should be understood that the objects described in this way can be interchanged in appropriate circumstances, so as to be able to describe the schemes outside the embodiments of the present application. In addition, in the embodiments of the present application, words such as "S310" are only for the convenience of description, and are not intended to limit the order of execution steps.

[0084] Second, in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0085] Third, the "storage" involved in the embodiments of the present application may refer to storage in one or more memories. The one or more memories may be separately set or integrated in an encoder or decoder, a processor, or a communication device. The one or more memories may also be partially separately set and partially integrated in a decoder, a processor, or a communication device. The type of memory may be any form of storage medium, and the present application is not limited thereto.

[0086] Fourth, the term “comprising” (also referred to as “includes”, “including”, “comprises” and / or “comprising”) involved in the embodiments of the present application when used in this specification specifies the existence of stated features, integers, steps, operations, elements, and / or parts, but does not exclude the existence or addition of one or more other features, integers, steps, operations, elements, parts, and / or groups thereof.

[0087] Fifth, the "if" involved in the embodiments of the present application can be interpreted as meaning "when" or "upon" or "in response to determining" or "in response to detecting". Similarly, depending on the context, the phrase "if it is determined that..." or "if [the stated condition or event] is detected" can be interpreted as meaning "when determining..." or "in response to determining..." or "when [the stated condition or event] is detected" or "in response to detecting [the stated condition or event]".

[0088] Sixth, the terms used in the description of various examples in the embodiments of the present application are only for describing specific examples and are not intended to be limiting. As used in the description of various examples and in the appended claims, the number forms "a", "an" and "the" are intended to include plural forms as well, unless the context clearly indicates otherwise.

[0089] Seventh, the term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0090] Combination of the above Figure 1 The present invention briefly introduces the applicable scenarios of the method for accessing memory provided by the present application, and introduces the basic concepts involved in the present application. Before using the physical memory, the computer device needs to determine that the corresponding page frame has been established. When the operating system starts, the page frame metadata can be created for the physical memory with the base page as the granularity. The page frame metadata can also be called the page frame structure, that is, the struct page structure is used to store the metadata of each page frame, and the page frame metadata is used to manage the physical memory during the operation of the operating system. When the computer manages the memory by this method, it will generate a management overhead proportional to the total amount of physical memory. For example, the base page size is 4KB, the page frame metadata size is 64Byte, and the computer's memory management overhead is about 64 / (4*1024)=1.5%. In the large page scenario, the memory management overhead is determined by the base page. For example, the base page size is 4KB, the large page size is 2MB, the page frame metadata size is 64Byte, and the large page consists of 512 base pages, corresponding to 512 page frame metadata. After merging, 511 of the page frame metadata will be wasted, and the waste rate is as high as 99.8%.

[0091] In order to solve the above problem, a method for converting the page frame metadata of a basic page into the page frame metadata of a composite page is currently proposed. Taking the conversion of 512 basic pages into one composite page as an example, Figure 2 As shown in (a), the composite page includes 512 base pages, and the 512 base pages correspond to 512 page frame metadata. Assuming that the size of the page frame metadata is 64B, before merging, the page frame metadata of the 512 base pages can be stored in 8 metadata pages, namely metadata page #1-metadata page #8 in the figure. When merging the above metadata pages, the page frame metadata of the first base page can be used as the page frame metadata of the first page of the composite page. The page frame metadata of the first page is used as the core metadata to store the page frame data information of the composite page. The page frame metadata of the last page (that is, other base pages except the first base page) is changed to be used only to store a pointer to the first page. Since the page frame metadata of the last page are all pointers to the first page, the page frame metadata of the last page can be mapped to the same physical page. As shown in Figure 2 As shown in (b), when the page frame metadata of the last page is changed, since the page frame metadata of the 2nd to 64th base pages and the page frame metadata of the 1st base page (i.e., the first page) are mapped in the same metadata page #1, the page frame metadata of the 2nd to 64th base pages cannot be merged.

[0092] Based on the above description, it can be seen that the above technical solution has the following shortcomings: (1) There is still a waste of memory overhead for the page frame metadata of some tail pages; (2) Since the page frame metadata of the composite page does not store the information of the page frame metadata of the base page, the composite page cannot support mapping at the base page granularity during use, and the ecological compatibility is poor.

[0093] Based on this, an embodiment of the present application provides a memory management method that can achieve rapid allocation of physical pages that meet the task granularity, with low memory overhead and good ecological compatibility, and is suitable for scenarios with mixed large and small pages.

[0094] Figure 3 A schematic diagram of the system architecture provided by an embodiment of the present application is shown.

[0095] like Figure 3 As shown, the system architecture can be divided into a hardware module and a software module, wherein the hardware module includes a processor and a memory, and the software module includes a memory management module and an application. The memory management module includes a page allocator, a primary page manager (PPM) and at least one secondary page manager (SPM).

[0096] Home Frame Manager: It is used to manage physical memory at large page granularity. When the operating system starts, it completes the creation of page frame metadata at large page granularity of physical memory. The page frame metadata created by the home frame manager can be called home frame manager metadata or first page frame metadata.

[0097] It is understandable that the large page granularity is larger than the minimum granularity supported by the system. For example, the minimum granularity supported by the system is 4KB, and the large page granularity is 16KB, 64KB, 1MB, 2MB, etc.

[0098] Secondary page frame manager: used to implement the management of physical memory smaller than the large page granularity. The secondary page frame manager can communicate with the primary page frame manager to convert the large page into the physical page of the granularity corresponding to the secondary page frame manager, and create page frame metadata. In other words, the page frame metadata of the physical page smaller than the large page granularity in the embodiment of the present application is dynamically created. The secondary page frame manager is also used to convert the idle page back to the large page, and release the corresponding page frame metadata. The page frame metadata created by the secondary page frame manager can be called secondary page frame manager metadata or second page frame metadata.

[0099] The system architecture provided in the embodiment of the present application may include one or more secondary page frame managers, and the granularity corresponding to the one or more secondary page frame managers may be different. For example, the system architecture includes two secondary page frame managers, namely secondary page frame manager #1 and secondary page frame manager #2, wherein the granularity corresponding to secondary page frame manager #1 is 16KB, and the granularity corresponding to secondary page frame manager #2 is 4KB.

[0100] Optionally, in some embodiments, when the system architecture includes only one secondary page frame manager, the granularity corresponding to the secondary page frame manager may be the minimum granularity supported by the system architecture.

[0101] Optionally, in some embodiments, when the system architecture includes multiple secondary page frame managers, the multiple secondary page frame managers include at least one secondary page frame manager whose corresponding granularity is the minimum granularity supported by the system architecture. For example, the minimum granularity supported by the system architecture is 4KB, and the system architecture includes three secondary page frame managers, namely secondary page frame manager #1, secondary page frame manager #2, and secondary page frame manager #3, wherein the granularity corresponding to secondary page frame manager #1 is 16KB, the granularity corresponding to secondary page frame manager #2 is 8KB, and the granularity corresponding to secondary page frame manager #3 is 4KB, or the granularity corresponding to secondary page frame manager #1 is 16KB, and the granularities corresponding to secondary page frame manager #2 and secondary page frame manager #3 are 4KB, or the granularities corresponding to secondary page frame manager #1, secondary page frame manager #2, and secondary page frame manager #3 are all 4KB.

[0102] Optionally, in some embodiments, when the system includes multiple secondary page frame managers, each of the multiple secondary page frame managers may communicate with the primary page manager to convert a large page into a physical page of a granularity corresponding to the secondary page frame manager.

[0103] The page allocator is used to select different page frame managers to implement the allocation and recovery of physical memory of different granularities.

[0104] It can be seen from the above description that the embodiment of the present application provides multiple page frame managers for managing physical pages of different granularities. In order to adapt to physical pages of different granularities and page frame managers, the embodiment of the present application improves the page frame metadata.

[0105] Optionally, in some embodiments, the page frame metadata includes a first field, which may be named an order field, and the first field is used to indicate the size of the physical page corresponding to the page frame metadata.

[0106] Exemplarily, the size of the first field is 8 bits, and the size of the physical page corresponding to the page frame metadata can be determined by formula (1).

[0107] A=2 B ×C (1)

[0108] Among them, A is the size of the physical page corresponding to the page frame metadata, B is the value of the second field, and C is the minimum granularity of the physical page supported by the computer device.

[0109] For example, if the value of the first field is "00000100", and the minimum granularity of the physical page supported by the computer is 4K, then the size of the physical page corresponding to the page frame metadata is 2 4 ×4K=64K.

[0110] It should be noted that the above formula (1) is only an example. In other embodiments of the present application, the value of the first field may be substituted into other formulas to calculate the size of the physical page corresponding to the page frame metadata.

[0111] Optionally, in some embodiments, the page frame metadata includes a second field, which can be named a valid field, and the second field is used to indicate whether the page frame metadata is valid page frame metadata, that is, whether the page frame metadata corresponds to a physical page. Specifically, the second field can be used to indicate whether the page frame metadata is valid page frame metadata when managing physical pages through a buddy algorithm. For details, please refer to the following text, which will not be described in detail here.

[0112] Exemplarily, the size of the second field is 1 bit. When the second field is "0", the page frame metadata is invalid page frame metadata, that is, there is no corresponding physical page. When the second field is "1", the page frame metadata is valid page frame metadata, that is, there is a corresponding physical page.

[0113] Optionally, in some embodiments, the page frame metadata includes a third field, which may be named a secondary field, and is used to indicate whether the page frame metadata is page frame metadata created by a secondary page frame management layer.

[0114] Exemplarily, the size of the third field is 1 bit. When the third field is "0", the page frame metadata is page frame metadata created by the main page frame manager. When the third field is "1", the page frame metadata is page frame metadata created by the secondary page frame manager.

[0115] It is understandable that during the process of physical page recycling and allocation, the values ​​of the first field, the second field and / or the third field of the page frame metadata corresponding to the physical page may change. Please refer to the following text for details.

[0116] Figure 4A schematic flow chart of a memory management method provided by an embodiment of the present application is shown, the method is applied to a computer device, the computer device includes a home page frame manager, a first secondary page frame manager and a page allocator, the home page frame manager corresponds to a first granularity, the first secondary page frame manager corresponds to a second granularity, such as Figure 4 As shown, the method includes:

[0117] S401: A main page frame manager divides a physical memory into N first physical pages according to a first granularity and creates N first page frame metadata.

[0118] Specifically, when the operating system starts, a running instance of the home frame manager is created and initialized, so that the home frame manager can scan the physical memory in the computer device, divide the physical memory into N first physical pages according to the first granularity, and create N first page frame metadata, the N first page frame metadata correspond one-to-one to the N first physical pages, and N≥1 is an integer.

[0119] Optionally, each of the N first page frame metadata includes a first field, and the first field is used to indicate the size of a physical page corresponding to each of the first page frame metadata.

[0120] For example, the value of the first field of each first page frame metadata is "00000100", and the size of the physical page corresponding to each first page frame metadata is 64 KB.

[0121] Optionally, each of the N first page frame metadata includes a second field, and the second field is used to indicate the validity of each of the first page frame metadata.

[0122] For example, if the value of the second field of each first page frame metadata is "1", it can indicate that each first page frame metadata is valid metadata.

[0123] Optionally, each of the N first page frame metadata includes a third field, and the third field is used to indicate whether the first page frame metadata is created by the main page frame manager.

[0124] For example, if the value of the third field of each first page frame metadata is "0", it can indicate that each first page frame metadata is page frame metadata created by the main page frame manager.

[0125] S402, the first secondary page frame manager is bound to the main page frame manager.

[0126] Specifically, when the operating system starts, a first secondary page frame manager running instance is created and initialized, so that the first secondary page frame manager is bound to the main page frame manager, so that the first secondary page frame manager can communicate with the main page frame manager to obtain large pages from the main page frame manager.

[0127] S403, the page distributor is bound to the first secondary page frame manager and the main page frame manager.

[0128] Specifically, when the operating system starts, a page allocator can be created and initialized, and the main page frame manager and the first secondary page frame manager can be registered in the page allocator, that is, the page allocator is bound to the first secondary page frame manager and the main page frame manager. After the page allocator is bound to the first secondary page frame manager and the main page frame manager, the page allocator can dynamically allocate physical memory through the first secondary page frame manager and the main page frame manager.

[0129] S404: The page allocator determines a page frame manager according to the request of the first process.

[0130] Specifically, the page allocator may determine the size of the physical memory required by the first process according to the request of the first process, thereby determining the page frame manager according to the size of the physical memory required by the first process.

[0131] Optionally, in some embodiments, when the size of the physical memory required by the first process is greater than or equal to the first granularity, the page allocator selects the home frame manager, and when the page allocator selects the home frame manager, S405 is executed.

[0132] Optionally, in some embodiments, when the size of the physical memory required by the first process is smaller than the first granularity, the page allocator selects the first secondary page frame manager, and when the page allocator selects the first secondary page frame manager, the first secondary page frame manager is triggered to execute S406 and S407.

[0133] Optionally, in some embodiments, when the size of the physical memory required by the first process is greater than or equal to the first granularity, the page allocator may select the main page frame manager and the first secondary page frame manager at the same time. In this case, the page allocator executes S409 and the first secondary page frame manager executes S410 and S411.

[0134] S405: The page allocator allocates O first physical pages to the first process.

[0135] Specifically, after the page allocator selects the home page frame manager, N first physical pages can be determined through the home page frame manager, and the granularity of the N first physical pages is the first granularity, so that the page allocator can allocate O first physical pages to the first process according to the N first physical pages, 1≤O≤N, and O is an integer.

[0136] For example, the first granularity is 64 KB, and the size of the physical memory required by the first process is 128 KB, then the page allocator may allocate 2 physical pages with a granularity of 64 KB to the first process.

[0137] For another example, the first granularity is 64 KB, and the size of the physical memory required by the first process is 145 KB, then the page allocator may allocate 3 physical pages with a granularity of 64 KB to the first process.

[0138] Optionally, when the page allocator allocates O first physical pages to the first process, it needs to be divided into O times, each time allocating one first physical page.

[0139] It should be noted that the O first physical pages allocated by the page allocator to the first process can be continuous physical pages or discontinuous physical pages. When the home frame manager adopts the buddy algorithm to manage the first physical page, the page allocator allocates continuous physical pages. For specific instructions, please see below and will not be expanded here.

[0140] S406: The first secondary page frame manager obtains M first physical pages.

[0141] Specifically, since the page allocator selects the first secondary page frame manager, but since the first secondary page frame manager does not manage any physical pages, the first secondary page frame manager can communicate with the main page frame manager to obtain M first physical pages, where N≥M≥1, and M is an integer.

[0142] The first secondary page frame manager can determine the number of first physical pages to be obtained, that is, determine the size of M, in the following ways.

[0143] A possible implementation manner: the first secondary page frame management may determine the number of first physical pages that need to be obtained according to the second granularity and the size of the page frame metadata.

[0144] Exemplarily, the first secondary page frame manager determines the number of first physical pages that need to be obtained according to formula (2).

[0145]

[0146] Wherein, E is the second granularity, F is the size of the page frame metadata, and G is the first granularity. For example, the second granularity is 4KB, the size of the page frame metadata is 64B, and the first granularity is 64KB. According to formula (2), M=4, that is, the first secondary page frame manager obtains 4 first physical pages, and the 4 first physical pages are continuous.

[0147] A possible implementation manner: the number of the first physical pages obtained by the first secondary page frame manager is a fixed value.

[0148] Since the first secondary page frame manager obtains the first physical page when it is determined that the size of the physical memory required by the first process is smaller than the first granularity, the first secondary page frame manager can obtain any number of first physical pages to meet the needs of the first process. Therefore, in this implementation, the number of first physical pages obtained by the first secondary page frame manager can be a fixed value, for example, m=2.

[0149] S407 : The first secondary page frame manager divides the M first physical pages into P second physical pages according to the second granularity, and creates corresponding P second page frame metadata.

[0150] Specifically, after the first-level page frame manager obtains M first physical pages, it can convert the M first physical pages into P second physical pages and create corresponding P second page frame metadata, where P>M≥1 and P is an integer, and the granularity of the P second physical pages is the second granularity.

[0151] Optionally, each of the P second page frame metadata includes a first field, where the first field is used to indicate the size of a physical page corresponding to each of the second page frame metadata.

[0152] For example, the value of the first field of each second page frame metadata is “00000000”, and the size of the physical page corresponding to each second page frame metadata is 4 KB.

[0153] Optionally, each of the P second page frame metadata includes a second field, and the second field is used to indicate the validity of each second page frame metadata.

[0154] For example, if the value of the second field of each second page frame metadata is “1”, it may indicate that each second page frame metadata is valid page frame metadata.

[0155] Optionally, each of the P second page frame metadata includes a third field, and the third field is used to indicate whether the second page frame metadata is created by the main page frame manager.

[0156] For example, if the value of the third field of each second page frame metadata is "1", it may indicate that each second page frame metadata is page frame metadata created by the secondary page frame manager.

[0157] Figure 5 A schematic diagram of converting a first physical page into a second physical page is shown.

[0158] like Figure 5As shown, the first secondary page frame manager obtains 4 first physical pages, the granularity of the first physical page is 64KB, and the first secondary page frame management can convert each first physical page into 16 second physical pages, the granularity of the second physical page is 4KB, that is, the first secondary page frame manager can convert 4 first physical pages into 64 second physical pages.

[0159] When converting M first physical pages into P second physical pages, it is necessary to create page frame metadata for each second physical page, that is, to create P second page frame metadata.

[0160] Optionally, in some embodiments, the P second page frame metadata may be stored in any one of the P second physical pages.

[0161] For example, the first secondary page frame manager obtains 4 first physical pages, and the granularity of the first physical pages is 64KB. The first secondary page frame manager can convert the 4 first physical pages into 64 second physical pages, and the granularity of the second physical pages is 4KB, and create corresponding 64 second page frame metadata for the 64 second physical pages. The 64 second page frame metadata can be stored in any page of the 64 second physical pages (for example, the first page of the 64 second physical pages).

[0162] Optionally, in some embodiments, the first secondary page frame manager may use a bitmap to manage the status of the P second physical pages, that is, determine whether the P second physical pages are used through the bitmap. For example, when the P second physical pages are not allocated, the corresponding value of the P second physical pages in the bitmap is "0", and when the P second physical pages are all allocated, the corresponding value of the P second physical pages in the bitmap is "1".

[0163] It should be noted that when the page frame manager does not use the buddy algorithm to manage physical pages, after the first secondary page frame manager divides the M first physical pages into P second physical pages according to the second granularity and creates the corresponding P second page frame metadata, the main page frame manager can change the value of the second field of each of the M first page frame metadata corresponding to the M first physical pages to indicate that the M first page frame metadata are invalid metadata.

[0164] When the page frame manager uses a buddy algorithm to manage physical pages, a fourth field can be added to the page frame metadata of each first physical page. The fourth field is used to indicate whether the physical page is divided. After the first secondary page frame manager divides M first physical pages into P second physical pages according to the second granularity and creates the corresponding P second page frame metadata, the main page frame manager can change the value of the fourth field of each first page frame metadata in the M first page frame metadata corresponding to the M first physical pages to indicate that the M first physical pages have been divided.

[0165] The description of the partner algorithm can be found below and will not be elaborated here.

[0166] S408: The page allocator allocates Q second physical pages to the first process.

[0167] Specifically, after the first secondary page frame manager converts M first physical pages into P second physical pages, the page allocator may allocate Q second physical pages to the first process according to the size of the physical memory required by the first process, where P≥Q≥1, and Q is an integer.

[0168] For example, the granularity of the second physical page is 4 KB, and the size of the physical memory required by the first process is 3 KB, then the page allocator may allocate 1 physical page to the first process, that is, Q=1.

[0169] For another example, the granularity of the second physical page is 4 KB, and the size of the physical memory required by the first process is 7 KB, then the page allocator may allocate 2 physical pages to the first process, that is, Q=2.

[0170] For another example, the granularity of the second physical page is 4 KB, and the size of the physical memory required by the first process is 18 KB, then the page allocator may allocate 5 physical pages to the first process, that is, Q=5.

[0171] Optionally, when the page allocator allocates Q second physical pages to the first process, it needs to divide the allocation into Q times, each time allocating a second physical page.

[0172] Similarly, the Q second physical pages allocated by the page allocator to the first process may be continuous physical pages or discontinuous physical pages. It is understandable that, after the page allocator allocates the Q second physical pages to the first process, the first secondary page frame manager changes the values ​​of the Q second physical pages in the bitmap (e.g., from "0" to "1") to indicate that the Q second physical pages are allocated.

[0173] S409: The page allocator allocates W first physical pages to the first process.

[0174] Specifically, the page allocator can select the main page frame manager and the first secondary page frame manager at the same time, and allocate W first physical pages to the first process according to the size of the physical memory required by the first process, 1≤W≤N, and W is an integer. In this case, the physical memory of W first physical pages is less than the physical memory required by the first process, and the physical memory of W+1 first physical pages is greater than the physical memory required by the first process.

[0175] For example, the first granularity is 64 KB, and the size of the physical memory required by the first process is 132 KB, then the page allocator may first allocate 2 first physical pages to the first process.

[0176] For another example, the first granularity is 64KB, and the size of the physical memory required by the first process is 128KB, then the page allocator may first allocate one first physical page to the first process, and the remaining 64KB may be allocated at the second granularity.

[0177] S410: The first secondary page frame manager obtains S first physical pages.

[0178] S411 , the first secondary page frame manager divides the S first physical pages into D second physical pages according to the second granularity, and creates corresponding D second page frame metadata.

[0179] It should be understood that the description of S410 and S411 can refer to the description of S406 and S407, and for the sake of brevity, they are not repeated here.

[0180] S412: The page allocator allocates T second physical pages to the first process.

[0181] Specifically, in some embodiments, the page allocator has allocated W first physical pages to the first process in S409. Although the physical memory size of the W first physical pages is smaller than the physical memory required by the first process, it is close to the physical memory required by the first process. If another first physical page is allocated to the first process, it may cause a waste of physical memory. Therefore, the page allocator can allocate T second physical pages to the first process to reduce the overhead of physical memory.

[0182] For example, the first granularity is 64KB, and the size of the physical memory required by the first process is 132KB. If the page allocator can allocate 3 first physical pages to the first process, 60KB of physical memory will be wasted. Therefore, the page allocator can allocate 2 first physical pages and 1 second physical page to the first process.

[0183] In some other embodiments, the page allocator has allocated W first physical pages to the first process in S409, and the W first physical pages are all free first physical pages, but there may be some free second physical pages in the system, so the page allocator can allocate T second physical pages to the first process to meet the needs of the first process. It can be understood that in this embodiment, S410 and S411 may not be present, that is, the first secondary page frame manager has converted some first physical pages into second physical pages before the page allocator allocates W first physical pages to the first process.

[0184] In an embodiment of the present application, page frame metadata is first created for the physical memory at a large page granularity, and then it is determined whether to further refine the physical pages based on the size of the physical memory required by the first process, thereby saving the management overhead of the page frame metadata and achieving rapid allocation of physical pages that meet the granularity of the first process.

[0185] In the above technical solution, there is a one-to-one linear mapping relationship between the page frame metadata and the physical address, and the linear mapping relationship can be established when the operating system is started, so that the offset in the physical memory can be determined by the offset of the page frame metadata in all current page frame metadata, and then the physical address corresponding to the page frame metadata can be determined. After determining the physical address corresponding to each page frame metadata, a page table can be established.

[0186] Figure 6 A schematic flowchart of a method for determining a physical address based on page frame metadata provided by an embodiment of the present application is shown.

[0187] S601, determining whether page frame metadata #1 is the first page frame metadata.

[0188] Page frame metadata #1 includes a third field, and the third field can be used to determine whether page frame metadata #1 is created by the main page frame manager or by the secondary page frame manager. When it is determined that page frame metadata #1 is created by the main page frame manager, proceed to S602; when it is determined that page frame metadata #1 is created by the secondary page frame manager, proceed to S603.

[0189] S602, determining a physical address according to the offset of the page frame metadata #1 in the first page frame metadata.

[0190] For example, Figure 7 As shown in (a), the main page frame manager manages 8 first physical pages, and the 8 first physical pages correspond to 8 first page frame metadata, among which the offset of page frame metadata #1 in all first page frame metadata is 4. The physical address corresponding to page frame metadata #1 can be determined according to the set linear mapping relationship.

[0191] S603, determining the offset of the page frame metadata #1 in the second page frame metadata.

[0192] For example, Figure 7 As shown in (b), it is assumed that the page frame metadata #1 is created by the secondary page frame manager #1, and the secondary page frame manager creates 16 second page frame metadata, wherein the offset of the page frame metadata #1 in the 16 second page frame metadata is 4, that is, the offset of the page frame metadata #1 in the second page frame metadata.

[0193] S604, determining the first page frame metadata corresponding to the page frame metadata #1.

[0194] For example, Figure 7As shown in (b), the secondary page frame manager obtains the first physical page #1 managed by the primary page frame manager, and converts the first physical page #1 into 16 second physical pages. The first page frame metadata corresponding to the first physical page #1 is the first page frame metadata #1, that is, the first page frame metadata #1 is determined in S604.

[0195] S605 , determining the offset of the first page frame metadata # 1 in the first page frame metadata.

[0196] For example, Figure 7 As shown in (b), the main page frame manager manages 8 first physical pages, and the 8 first physical pages correspond to 8 first page frame metadata, wherein the offset of the first page frame metadata #1 in all the first page frame metadata is 1, that is, the offset of the first page frame metadata #1 in the first page frame metadata is determined.

[0197] S606: Determine a physical address according to the offset of the page frame metadata #1 in the second page frame metadata and the offset of the first page frame metadata #1 in the first page frame metadata.

[0198] After determining the offset of page frame metadata #1 in the second page frame metadata and the offset of first page frame metadata #1 in the first page frame metadata, a large physical address can be first determined based on the offset of first page frame metadata #1 in the first page frame metadata, and then the physical address corresponding to the page frame metadata can be further determined based on the offset of page frame metadata #1 in the second page frame metadata.

[0199] It should be noted that in the embodiment of the present application, the execution order of S603 and S604 is not limited, and S603 and S604 can be executed simultaneously, or S603 can be executed first and then S604, or S604 can be executed first and then S603.

[0200] Optionally, in some embodiments, the main frame manager may manage the N first physical pages with a buddy algorithm to divide the N first physical pages into L physical blocks.

[0201] Specifically, the home frame manager can group N first physical pages into multiple linked lists. Taking 11 linked lists as an example, each linked list includes 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 and 1024 consecutive first physical pages. Taking the first granularity of 64KB as an example, the corresponding sizes are 64KB, 128KB, 256KB, 512KB, 1MB, 2MB, 4MB, 8MB, 16MB, 32MB and 64MB. That is, the home frame manager divides the N first physical pages into L physical blocks through the buddy algorithm. The L physical blocks include physical blocks of different sizes, so that the page allocator can select a suitable block according to the size of the physical memory required by the first process and allocate the block to the first process, where N≥L≥1, and L is an integer. The physical block can be understood as a physical memory composed of multiple consecutive physical pages. In other words, when the first process requires continuous physical memory, the home frame manager may manage the first physical page through the buddy algorithm to convert the first physical page into a physical block and allocate the physical block to the first process.

[0202] For example, the first process requests four first physical pages, and the page allocator may allocate a physical block having a size of four first physical pages to the first process.

[0203] For another example, the first process requests five first physical pages, and the page allocator may allocate a physical block of eight first physical pages to the first process.

[0204] For another example, the first process requests 5 first physical pages. If all blocks of 8 first physical pages have been used, the page allocator can divide the physical block of 16 first physical pages into 2 physical blocks of 8 first physical pages, and then allocate one of them to the first process and insert the other into the linked list of 8 first physical pages.

[0205] It should be noted that when the main page frame manager divides N first physical pages into L physical blocks, in order to allocate the L physical blocks, the L physical blocks need to correspond to L page frame metadata. In the embodiment of the present application, the page frame metadata corresponding to the physical blocks managed by the main page frame manager is referred to as the third page frame metadata. The L third page frame metadata can be generated in the following ways.

[0206] In a possible implementation, the main page frame manager creates L third page frame metadata.

[0207] When converting N first physical pages into L physical blocks, the main page frame manager may create corresponding L third page frame metadata.

[0208] Optionally, each of the L third page frame metadata includes a first field to indicate a size of a physical block corresponding to each of the third page frame metadata.

[0209] Optionally, each of the L third page frame metadata includes a second field to indicate that each of the third page frame metadata is valid page frame metadata.

[0210] Optionally, each of the L third page frame metadata includes a third field to indicate that each of the third page frame metadata is created by a main page frame manager.

[0211] It is understandable that in this implementation, the main page frame manager can change the value of the second field of the original N first page frame metadata (for example, from "0" to "1") to indicate that the N first page frame metadata are invalid page frame metadata.

[0212] In a possible implementation, the main page frame manager obtains L third page frame metadata according to L first page frame metadata.

[0213] Since the main page frame manager divides N first physical pages into L physical blocks, then N≥L. In order to save the number of page frame metadata, no new page frame metadata may be added, but L first page frame metadata among the original N first page frame metadata may be reused. When reusing the L first page frame metadata, the main page frame manager may change the value of the first field of the L first page frame metadata to indicate the size of the physical block corresponding to the L first page frame metadata (i.e., the L third page frame metadata). In addition, the main page frame manager may also change the value of the second field of the NL first page frame metadata that are not reused (for example, from "1" to "0") to indicate that the NL first page frame metadata are invalid metadata.

[0214] For example, the main home frame manager divides the first physical page #1 and the first physical page #2 into one physical block, the first physical page #1 corresponds to the first page frame metadata #1, the first physical page #2 corresponds to the first page frame metadata #2, and the granularity of the first physical page #1 and the first physical page #2 is 8KB, then the value of the first field of the first page frame metadata #1 and the first page frame metadata #2 can be "00000010", and the value of the second field of the first page frame metadata #1 and the first page frame metadata #2 can be "1". After the first physical page #1 and the first physical page #2 are divided into physical blocks, the value of the first field of the first page frame metadata #1 can be changed to "00000100", and the value of the second field of the first page frame metadata #2 can be changed to "0".

[0215] Optionally, in some embodiments, the first secondary page frame manager may manage the P first physical pages in a buddy algorithm to divide the P second physical pages into R physical blocks.

[0216] Specifically, the first secondary page frame manager can group P second physical pages into multiple linked lists. Taking 11 linked lists as an example, each linked list includes 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 and 1024 consecutive first physical pages. Taking the second granularity of 4KB as an example, the corresponding sizes are 4KB, 8KB, 16KB, 32KB, 64KB, 128KB, 256KB, 512KB, 1MB, 2MB and 4MB. That is, the first secondary page frame manager divides P second physical pages into R physical blocks through the buddy algorithm. The R physical blocks include physical blocks of different sizes, so that the page allocator can select a suitable block according to the size of the physical memory required by the first process and allocate the block to the first process, where P≥R≥1, and R is an integer. A physical block can be understood as a physical memory composed of multiple consecutive physical pages.

[0217] For example, the first process requests four second physical pages, and the page allocator may allocate a physical block having a size of four second physical pages to the first process.

[0218] For another example, the first process requests five second physical pages, and the page allocator may allocate a physical block having a size of eight second physical pages to the first process.

[0219] For another example, the first process requests 5 second physical pages. If all blocks of 8 second physical pages have been used, the page allocator can divide the physical block of 16 second physical pages into 2 physical blocks of 8 second physical pages, and then allocate one of them to the first process and insert the other into the linked list of 8 second physical pages.

[0220] It should be noted that when the first secondary page frame manager divides P second physical pages into R physical blocks, in order to allocate the R physical blocks, the R physical blocks need to correspond to R page frame metadata. In the embodiment of the present application, the page frame metadata corresponding to the physical blocks managed by the secondary page frame manager is referred to as the fourth page frame metadata. The method of generating the R fourth page frame metadata is similar to the method of generating the L third page frame metadata. For the sake of brevity, it will not be repeated here.

[0221] Optionally, in some embodiments, the method 400 further includes:

[0222] S413: The page distributor detects that a first preset condition is met and determines a page frame manager.

[0223] Specifically, the page allocator detects that the first preset condition is met, that is, the page allocator determines that physical memory recovery needs to be performed. The page allocator can perform S414 when it is determined that the physical page belongs to the main page frame manager according to the page frame manager to which the physical page belongs, and perform S415 when it is determined that the physical page belongs to the first secondary page frame manager. In this embodiment, the page allocator allocates O first physical pages to the first process, or allocates Q second physical pages to the first process, or allocates W first physical pages and T second physical pages to the first process. Therefore, when reclaiming physical pages, if the page allocator allocates O first physical pages or W first physical pages to the first process, O first physical pages or W first physical pages can be reclaimed, that is, S414 is performed, and if the page allocator allocates Q second physical pages or T second physical pages to the first process, Q second physical pages or T second physical pages can be reclaimed, that is, S415 is performed.

[0224] In the embodiment of the present application, the first preset condition for the page allocator to execute physical memory reclamation is not limited. For example, the first preset condition may be that the second process initiates a physical memory reclamation request. That is, when the page allocator detects that the second process initiates a physical memory reclamation request, physical memory reclamation may be executed.

[0225] Exemplarily, the first preset condition may be that the page allocator detects insufficient physical memory when allocating physical memory. For example, the page allocator allocates physical pages to the third process according to the request of the third process, but detects that there is insufficient free physical memory, and physical memory recovery may be performed.

[0226] Exemplarily, the first preset condition may be that the physical memory usage exceeds a threshold value. For example, if the page allocator detects that the physical memory usage exceeds 90%, physical memory reclamation may be performed.

[0227] The page allocator can determine the page frame manager to which the physical page corresponding to the page frame metadata belongs through the third field of the page frame metadata. For example, if the third field of the page frame metadata is "0", the physical page corresponding to the page frame metadata belongs to the primary page frame manager, and if the third field of the page frame metadata is "1", the physical page corresponding to the page frame metadata belongs to the first secondary page frame manager.

[0228] It can be seen from the above description that the page frame metadata is needed when determining the page frame manager to which the physical page belongs, so the page allocator needs to determine the corresponding page frame metadata through the physical address of the physical page.

[0229] Figure 8 A schematic flow chart of a method for determining page frame metadata according to a physical address provided in an embodiment of the present application is shown. Figure 8 As shown, the method includes:

[0230] S801, determining first page frame metadata #1 according to the offset of physical address #1.

[0231] Specifically, as can be seen from the above description, there is a one-to-one linear mapping relationship between the page frame metadata and the physical address. Therefore, the page allocator can determine the offset of the first page frame metadata corresponding to the physical address #1 in all the first page frame metadata based on the offset of the physical address #1, and then determine the first page frame metadata #1.

[0232] S802 , determining whether the first physical page corresponding to the first page frame metadata # 1 is divided.

[0233] There are several possible implementations for determining whether the first physical page corresponding to the first page frame metadata #1 is divided:

[0234] In a possible implementation, when the buddy algorithm is not used, the page allocator can determine whether the first page frame metadata #1 is valid page frame metadata according to the second field of the first page frame metadata #1. If it is valid page frame metadata, S803 is performed; if it is not valid page frame metadata, S804 is performed. If the first page frame metadata #1 is not valid page frame metadata, it indicates that the physical page corresponding to the first page frame metadata #1 has been divided into multiple physical pages of the second granularity by the first secondary page frame manager. If the first page frame metadata #1 is valid page frame metadata, it indicates that the first page frame metadata #1 is the page frame metadata corresponding to the physical address #1.

[0235] A possible implementation method is that after using the buddy algorithm, since the second field of the other physical pages except the first physical page in the multiple physical pages will be changed when merging multiple physical pages into one physical block, it is impossible to judge whether the first physical page corresponding to the first page frame metadata #1 is divided through the second field. Therefore, when the page frame manager uses the buddy algorithm to manage the physical page, a fourth field can be added to the page frame metadata of each first physical page, and the fourth field is used to indicate whether the physical page is divided (for example, when the physical page is not divided, the fourth field of the page frame metadata of the physical page is "0", and when the physical page is divided, the fourth field of the page frame metadata of the physical page is "1"). The page allocator can judge whether the first physical page corresponding to the first page frame metadata #1 is divided through the fourth field of the first page frame metadata #1. S803, determine that the first page frame metadata #1 is the page frame metadata corresponding to the physical address #1.

[0236] The first page frame metadata #1 is valid page frame metadata, that is, the physical page corresponding to the first page frame metadata #1 is not divided, indicating that the first page frame metadata #1 is the page frame metadata corresponding to the physical address #1, that is, the physical page corresponding to the physical address #1 is managed by the main page manager.

[0237] S804, determining the offset in the metadata of the second page frame.

[0238] Specifically, after the page allocator determines that the first page frame metadata #1 is invalid page frame metadata, that is, the physical page corresponding to the first page frame metadata is divided, the physical address #2 can be determined according to the first page frame metadata #1. For a specific description, see S602. For the sake of brevity, it will not be repeated here. It can be understood that the physical address #2 includes the physical address #1. The page allocator can determine the offset of the physical address #1 in the physical address #2, and the offset is the offset in the second page frame metadata.

[0239] S805 , determining the second page frame metadata # 1 according to the offset in the second page frame metadata.

[0240] Specifically, after the page allocator determines the offset of physical address #1 in physical address #2, it then determines the second page frame metadata #1 from all second page frame metadata according to the offset. The second page frame metadata #1 is the page frame metadata corresponding to physical address #1.

[0241] Through the above method, the page frame metadata corresponding to the physical page can be determined, and then the corresponding page frame manager can be determined.

[0242] S414: The main frame manager reclaims O first physical pages or W first physical pages.

[0243] Specifically, the page allocator determines, through the page frame metadata, that the O first physical pages or the W first physical pages belong to the main page frame manager, and the main page frame manager may reclaim the O first physical pages or the W first physical pages.

[0244] Optionally, the home frame manager may include a first free page pool, and the home frame manager may put the reclaimed O first physical pages or W first physical pages into the first free page pool to wait for the next allocation.

[0245] S415: The first secondary page frame manager reclaims Q second physical pages or T second physical pages.

[0246] Specifically, the page allocator determines through the page frame metadata that the Q second physical pages or the T second physical pages belong to the first secondary page frame manager, and the first secondary page frame manager can reclaim the Q second physical pages or the T second physical pages.

[0247] Optionally, the first secondary page frame manager may include a second free page pool, and the first secondary page frame manager may put the reclaimed Q second physical pages or T second physical pages into the second free page pool for next allocation.

[0248] It can be understood that, in this embodiment, after the first secondary page frame manager recycles Q second physical pages or T second physical pages, the number of free second physical pages managed by the first secondary page frame manager is P or D.

[0249] S416, the first secondary page frame manager converts P second physical pages into M first physical pages and releases P second page frame metadata corresponding to the P second physical pages, or converts D second physical pages into S first physical pages and releases D second page frame metadata corresponding to the D second physical pages.

[0250] Specifically, the first-level page frame manager determines according to the bitmap that P second physical pages or D second physical pages are all idle, then the P second physical pages can be converted back to M first physical pages, or the D second physical pages can be converted into S first physical pages, and the P second page frame metadata corresponding to the P second physical pages can be released, or the D second page frame metadata corresponding to the D second physical pages can be released.

[0251] S417: The main page frame manager obtains M first physical pages or S first physical pages from the first secondary page frame manager.

[0252] Specifically, after the first secondary page frame manager converts the P second physical pages back to M first physical pages, the main page frame manager can communicate with the first secondary page frame manager to obtain the M first physical pages, or after converting the D second physical pages into S first physical pages, the main page frame manager can communicate with the first secondary page frame manager to obtain the S first physical pages.

[0253] Optionally, the home frame manager may include a first free page pool, and the home frame manager may put the acquired M first physical pages or S first physical pages into the first free page pool for next allocation.

[0254] In some embodiments, when the page frame manager does not use the buddy algorithm, after the main page frame manager obtains M first physical pages or S first physical pages from the first secondary page frame manager, the main page frame manager may change the second field of the M first page frame metadata corresponding to the M first physical pages or change the second field of the S first page frame metadata corresponding to the S first physical pages to indicate that the M first page frame metadata or the S first page frame metadata are valid page frame metadata, that is, the M first physical pages or the S first physical pages are not divided.

[0255] In other embodiments, after the page frame manager uses the buddy algorithm, after the main page frame manager obtains M first physical pages or S first physical pages from the first secondary page frame manager, the main page frame manager may change the fourth field of the M first page frame metadata corresponding to the M first physical pages or change the fourth field of the S first page frame metadata corresponding to the S first physical pages to indicate that the M first page frame metadata or the S first page frame metadata are valid page frame metadata, that is, the M first physical pages or the S first physical pages are not divided. In the above implementation, the number of secondary page frame managers is taken as 1 as an example, but the embodiments of the present application are not limited to this. In other embodiments of the present application, the number of secondary page frame managers may be 2 or more. The memory management method provided by the embodiments of the present application is introduced below by taking the number of secondary page frame managers as 2 as an example.

[0256] Fig. 9 A schematic flow chart of a memory management method provided by an embodiment of the present application is shown, the method is applied to a computer device, the computer device includes a home page frame manager, a first sub-page frame manager, a second sub-page frame manager and a page allocator, the home page frame manager corresponds to a first granularity, the first sub-page frame manager corresponds to a second granularity, and the second sub-page frame manager corresponds to a third granularity, wherein the third granularity is the minimum granularity supported by the computer device, such as Fig. 9 As shown, the method includes:

[0257] S901: A main page frame manager divides a physical memory into N first physical pages according to a first granularity and creates N first page frame metadata.

[0258] S902, the first secondary page frame manager is bound to the main page frame manager.

[0259] S903, the second secondary page frame manager is bound to the main page frame manager.

[0260] S904, the page distributor is bound to the first secondary page frame manager, the second secondary page frame manager and the main page frame manager.

[0261] It should be understood that the description of S901-S904 can be found above, and for the sake of brevity, it will not be repeated here.

[0262] S905: The page allocator determines a page frame manager according to the request of the first process.

[0263] Specifically, the page allocator may determine the size of the physical memory required by the first process according to the request of the first process, thereby determining the page frame manager according to the size of the physical memory required by the first process.

[0264] Optionally, in some embodiments, when the size of the physical memory required by the first process is greater than or equal to the first granularity, the page allocator selects the home frame manager, and when the page allocator selects the home frame manager, S906 is executed.

[0265] Optionally, in some embodiments, when the size of the physical memory required by the first process is less than the first granularity and greater than or equal to the second granularity, the page allocator selects the first secondary page frame manager. When the page allocator selects the first secondary page frame manager, the first secondary page frame manager is triggered to execute S907 and S908, and then the page allocator executes S911.

[0266] Optionally, in some embodiments, when the size of the physical memory required by the first process is smaller than the second granularity, the page allocator selects a second secondary page frame manager. When the page allocator selects the second secondary page frame manager, the first secondary page frame manager is triggered to execute S909 and S910, and then the page allocator executes S912.

[0267] S906: The page allocator allocates O first physical pages to the first process.

[0268] S907: The first secondary page frame manager obtains M first physical pages.

[0269] S908 : The first secondary page frame manager divides the M first physical pages into P second physical pages according to the second granularity, and creates corresponding P second page frame metadata.

[0270] S909: The second secondary page frame manager obtains K first physical pages.

[0271] S910 , the second secondary page frame manager divides the K first physical pages into H third physical pages according to a third granularity, and creates corresponding H second page frame metadata.

[0272] S911, the page allocator allocates Q second physical pages to the first process.

[0273] S912: The page allocator allocates G third physical pages to the first process.

[0274] It should be understood that the description of S906-S912 can be found above, and for the sake of brevity, it will not be repeated here.

[0275] Optionally, the main page frame manager, the first secondary page frame manager and the second secondary page frame manager can divide the managed physical pages into physical blocks of different sizes through a buddy algorithm, so that the page allocator allocates suitable physical blocks to the first process according to the size of the physical memory required by the first process. The specific description can be found above and will not be repeated here for the sake of brevity.

[0276] In the above, the memory management method provided in the embodiment of the present application is introduced from the perspective of each functional module in the computer device. In the following, the memory management method provided in the embodiment of the present application will be introduced from the perspective of the computer device.

[0277] Fig.10 A schematic flow chart of a memory management method provided in an embodiment of the present application is shown, and the method is applied to a computer device, such as Fig.10 As shown, the method includes:

[0278] S1001, dividing a physical memory into N first physical pages according to a first granularity and creating N first page frame metadata.

[0279] Specifically, when the operating system starts, the computer device can scan the physical memory, divide the physical memory into N first physical pages according to the first granularity, and create N first page frame metadata, the N first page frame metadata correspond one-to-one to the N first physical pages, and N≥1 is an integer.

[0280] Optionally, each of the N first page frame metadata includes a first field, and the first field is used to indicate the size of a physical page corresponding to each of the first page frame metadata.

[0281] For example, the value of the first field of each first page frame metadata is "00000100", and the size of the physical page corresponding to each first page frame metadata is 64 KB.

[0282] Optionally, each of the N first page frame metadata includes a second field, and the second field is used to indicate the validity of each of the first page frame metadata.

[0283] For example, if the value of the second field of each first page frame metadata is "1", it can indicate that each first page frame metadata is valid metadata.

[0284] Optionally, each of the N first page frame metadata includes a third field, and the third field is used to indicate whether the first page frame metadata is created by the computer device through a main page frame manager.

[0285] For example, if the value of the third field of each first page frame metadata is "0", it can indicate that each first page frame metadata is created by the computer device through the main page frame manager.

[0286] S1002: Determine the size of the physical memory required by the first process according to a request of the first process.

[0287] Specifically, when the first process initiates a memory request, the computer device may determine the size of the physical memory required by the first process according to the request of the first process.

[0288] S1003, according to the size of the physical memory required by the first process, select to allocate O first physical pages to the first process at the first granularity, or select to allocate Q second physical pages to the first process at the second granularity, or select to allocate W first physical pages to the first process at the first granularity and allocate T second physical pages to the first process at the second granularity, wherein the second granularity is smaller than the first granularity and greater than or equal to the minimum granularity supported by the computer device.

[0289] Specifically, the computer device may select physical pages of different granularities for the first process according to the size of the physical memory required by the first process.

[0290] Optionally, in some embodiments, the size of the physical memory required by the first process is greater than or equal to the first granularity, and the computer device may choose to allocate O second physical pages to the first process at the first granularity.

[0291] For example, the first granularity is 64 KB, and the size of the physical memory required by the first process is 128 KB, then the page allocator may allocate 2 physical pages with a granularity of 64 KB to the first process.

[0292] Optionally, in some embodiments, when the size of the physical memory required by the first process is smaller than the first granularity, the computer device may choose to allocate Q second physical pages to the first process at a second granularity.

[0293] For example, the first granularity is 64 KB, the second granularity is 4 KB, and the size of the physical memory required by the first process is 32 KB, then the page allocator may allocate 8 physical pages with a granularity of 4 KB to the first process.

[0294] Optionally, in some embodiments, when the size of the physical memory required by the first process is larger than the first granularity, the computer device may choose to allocate W first physical pages to the first process at the first granularity and allocate T second physical pages to the first process at the second granularity.

[0295] For example, the first granularity is 64KB, the second granularity is 4KB, and the size of the physical memory required by the first process is 132KB. The page allocator can allocate 2 physical pages with a granularity of 64KB and 1 physical page with a granularity of 4KB to the first process.

[0296] It should be noted that when the computer allocates physical pages to the first process at the second granularity, the size of the second granularity may be determined according to the secondary page frame manager configured therein.

[0297] For example, the first granularity is 64KB, the size of the physical memory required by the first process is 16KB, the computer device is configured with 1 secondary page frame manager, and the granularity corresponding to the secondary page frame manager is 4KB, then the computer device can allocate 4 physical pages with a granularity of 4KB to the first process.

[0298] For another example, the first granularity is 64KB, the size of the physical memory required by the first process is 16KB, and the computer device is configured with two secondary page frame managers, and the granularities corresponding to the two secondary page frame managers are 8KB and 4KB respectively. Then, the computer device can allocate two physical pages with a granularity of 8KB to the first process, or it can also allocate four physical pages with a granularity of 4KB to the first process.

[0299] In an embodiment of the present application, page frame metadata is first created for the physical memory at a large page granularity, and then it is determined whether to further refine the physical pages based on the size of the physical memory required by the first process, thereby saving the management overhead of the page frame metadata and achieving rapid allocation of physical pages that meet the granularity of the first process.

[0300] Optionally, in some embodiments, selecting to allocate Q second physical pages to the first process at a second granularity includes:

[0301] Selecting M first physical pages from N first physical pages, where N≥M≥1, and M is an integer;

[0302] Converting the M first physical pages into P second physical pages according to a second granularity, and creating corresponding P second page frame metadata, where P>M>1, and P is an integer, and each of the P second page frame metadata includes a first field to indicate a size of a physical page corresponding to each second page frame metadata;

[0303] Q second physical pages are selected from the P second physical pages and allocated to the first process.

[0304] Specifically, the computer device can select M first physical pages from N first physical pages, then convert the selected M first physical pages into P second physical pages according to the second granularity, create corresponding P second page frame metadata, and then select Q second physical pages from the P second physical pages to allocate to the first process.

[0305] Optionally, in some embodiments, selecting to allocate W first physical pages to the first process at a first granularity and to allocate T second physical pages to the first process at a second granularity includes:

[0306] Select W first physical pages from N first physical pages and allocate them to the first process, where N≥W≥1, and W is an integer;

[0307] Select S first physical pages from NW first physical pages, NW≥S≥1, and S is an integer;

[0308] Convert the S first physical pages into D second physical pages according to the second granularity, and create corresponding D second page frame metadata, where D>S>1, and D is an integer, and each of the D second page frame metadata includes a first field to indicate the size of the physical page corresponding to each second page frame metadata;

[0309] T second physical pages are selected from the D second physical pages and allocated to the first process.

[0310] Specifically, when the physical memory required by the first process is greater than the first granularity, the computer device may allocate W first physical pages to the first process from the N first physical pages. In this case, the physical memory of the W first physical pages is less than the physical memory required by the first process, and the physical memory of the W+1 first physical pages is greater than the physical memory required by the first process. Since the physical memory of the W first physical pages is less than the physical memory required by the first process, the computer device may select S first physical pages from the NW first physical pages, then convert the S first physical pages into D second physical pages, and then allocate T second physical pages to the first process from the D second physical pages.

[0311] In the embodiment of the present application, a suitable physical page can be allocated to the first process according to the size of the physical memory required by the first process. When the physical memory required by the first process is greater than the first granularity, physical pages of different granularities can be allocated to the first process, that is, the physical memory requirement of the first process is met, and the waste of physical memory can be avoided, thereby improving the allocation rate of physical memory. Optionally, each of the P second page frame metadata includes a first field, and the first field is used to indicate the size of the physical page corresponding to each second page frame metadata.

[0312] For example, the value of the first field of each second page frame metadata is “00000000”, and the size of the physical page corresponding to each second page frame metadata is 4 KB.

[0313] Optionally, each of the P second page frame metadata includes a second field, and the second field is used to indicate the validity of each second page frame metadata.

[0314] For example, if the value of the second field of each second page frame metadata is "1", it can indicate that each second page frame metadata is valid metadata.

[0315] Optionally, each of the P second page frame metadata includes a third field, and the third field is used to indicate whether the second page frame metadata is created by the computer device through the main page frame manager.

[0316] For example, if the value of the third field of each second page frame metadata is "1", it can indicate that each second page frame metadata is created by the computer device through the secondary page frame manager.

[0317] Optionally, in some embodiments, the P second page frame metadata may be stored in any one of the P second physical pages.

[0318] Optionally, in some embodiments, the computer device may use a bitmap to manage the status of the P second physical pages, that is, determine whether the P second physical pages are used through the bitmap. For example, when the P second physical pages are not allocated, the corresponding value of the P second physical pages in the bitmap is "0", and when the P second physical pages are all allocated, the corresponding value of the P second physical pages in the bitmap is "1".

[0319] It should be understood that the description of the D second page frame metadata can be included in the description of the P second page frame metadata, and for the sake of brevity, it will not be repeated here.

[0320] It should be noted that when the computer device does not use the buddy algorithm, after the computer device divides the M first physical pages into P second physical pages according to the second granularity and creates corresponding P second page frame metadata, the computer device can change the value of the second field of each of the M first page frame metadata corresponding to the M first physical pages to indicate that the M first page frame metadata are invalid metadata, that is, the M first physical pages have been divided.

[0321] When the computer device uses the buddy algorithm, the computer device can add a fourth field to the page frame metadata of each first physical page, and the fourth field is used to indicate whether the physical page is divided. After the computer device divides M first physical pages into P second physical pages according to the second granularity and creates the corresponding P second page frame metadata, the computer device can change the value of the fourth field of each first page frame metadata in the M first page frame metadata corresponding to the M first physical pages to indicate that the M first physical pages have been divided.

[0322] Optionally, in some embodiments, before selecting Q second physical pages from the P second physical pages and allocating them to the first process, the method further includes:

[0323] The P second physical pages are converted into R physical blocks by using a buddy algorithm, the R physical blocks correspond to R fourth page frame metadata, each of the R fourth page frame metadata includes a first field to indicate the size of the physical block corresponding to each fourth page frame metadata, and each of the R fourth page frame metadata includes a second field to indicate that each fourth page frame metadata is valid metadata;

[0324] Selecting Q second physical pages from P second physical pages and allocating them to the first process includes:

[0325] A second physical block is selected from the R physical blocks and allocated to the first process, where the second physical block includes Q second physical pages.

[0326] Specifically, the computer device may group P second physical pages into multiple linked lists. Taking 11 linked lists as an example, each linked list includes 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 and 1024 consecutive first physical pages. Taking the second granularity of 4KB as an example, the corresponding sizes are 4KB, 8KB, 16KB, 32KB, 64KB, 128KB, 256KB, 512KB, 1MB, 2MB and 4MB. That is, the computer device divides the P second physical pages into R physical blocks through the buddy algorithm. The R physical blocks include physical blocks of different sizes, so that the computer device can select a suitable block according to the size of the physical memory required by the first process and allocate the block to the first process, where P≥R≥1, and R is an integer. A physical block can be understood as a physical memory composed of multiple consecutive physical pages.

[0327] For example, if the first process requests four second physical pages, the computer device may allocate a physical block having a size of four second physical pages to the first process.

[0328] For another example, the first process requests five second physical pages, and the computer device may allocate a physical block having a size of eight second physical pages to the first process.

[0329] The R fourth page frame metadata may be generated in the following ways.

[0330] In a possible implementation, the computer device creates R fourth page frame metadata.

[0331] Optionally, each fourth page frame metadata of the R fourth page frame metadata includes a first field to indicate the size of a physical block corresponding to each fourth page frame metadata.

[0332] Optionally, each fourth page frame metadata of the R fourth page frame metadata includes a second field to indicate that each fourth page frame metadata is valid page frame metadata.

[0333] Optionally, each of the R fourth page frame metadata includes a third field to indicate that each fourth page frame metadata is created by a main page frame manager.

[0334] It is understandable that in this implementation, the main page frame manager can change the value of the second field of the original P second page frame metadata (for example, from "0" to "1") to indicate that the P second page frame metadata are invalid page frame metadata.

[0335] In a possible implementation manner, the main page frame manager obtains R fourth page frame metadata according to R second page frame metadata among P second page frame metadata.

[0336] The computer device reuses R second page frame metadata among the original P second page frame metadata. When reusing the R second page frame metadata, the computer device may change the value of the first field of the R second page frame metadata to indicate the size of the physical block corresponding to the R second page frame metadata (i.e., the R fourth page frame metadata). In addition, the main page frame manager may also change the value of the second field of the unreused PR second page frame metadata (e.g., from "1" to "0") to indicate that the PR second page frame metadata is invalid page frame metadata.

[0337] Optionally, in some embodiments, before selecting to allocate 0 first physical pages to the first process at the first granularity, the method further includes:

[0338] Converting the N first physical pages into L physical blocks by using a buddy algorithm, the L physical blocks corresponding to L third page frame metadata, each of the L third page frame metadata including a first field to indicate the size of the physical block corresponding to each third page frame metadata, and each of the L third page frame metadata including a second field to indicate that each third page frame metadata is valid metadata;

[0339] Selecting to allocate O first physical pages to the first process at a first granularity includes:

[0340] A first physical block is selected from the L physical blocks and allocated to the first process, where the first physical block includes O first physical pages.

[0341] Specifically, the computer device may group N first physical pages into multiple linked lists. For example, 11 linked lists are divided into each linked list, each of which includes 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 and 1024 consecutive first physical pages. For example, the first granularity is 64KB, and the corresponding sizes are 64KB, 128KB, 256KB, 512KB, 1MB, 2MB, 4MB, 8MB, 16MB, 32MB and 64MB. That is, the computer device divides the N first physical pages into L physical blocks through the buddy algorithm. The L physical blocks include physical blocks of different sizes, so that the computer device can select a suitable block according to the size of the physical memory required by the first process, and allocate the block to the first process, where N≥L≥1, and L is an integer.

[0342] For example, the first process requests four first physical pages, and the page allocator may allocate a physical block having a size of four first physical pages to the first process.

[0343] For another example, the first process requests five first physical pages, and the page allocator may allocate a physical block of eight first physical pages to the first process.

[0344] The L third page frame metadata may be generated in the following ways.

[0345] In a possible implementation, the main page frame manager creates L third page frame metadata.

[0346] Optionally, each of the L third page frame metadata includes a first field to indicate a size of a physical block corresponding to each of the third page frame metadata.

[0347] Optionally, each of the L third page frame metadata includes a second field to indicate that each of the third page frame metadata is valid page frame metadata.

[0348] Optionally, each of the L third page frame metadata includes a third field to indicate that each of the third page frame metadata is created by a main page frame manager.

[0349] It is understandable that in this implementation, the main page frame manager can change the value of the second field of the original N first page frame metadata (for example, from "0" to "1") to indicate that the N first page frame metadata are invalid page frame metadata.

[0350] In a possible implementation, the main page frame manager obtains L third page frame metadata according to L first page frame metadata.

[0351] Since the computer device reuses L first page frame metadata among the original N first page frame metadata. When the L first page frame metadata are reused, the main page frame manager can change the value of the first field of the L first page frame metadata to indicate the size of the physical block corresponding to the L first page frame metadata (i.e., the L third page frame metadata). In addition, the main page frame manager can also change the value of the second field of the NL first page frame metadata that are not reused (for example, from "1" to "0") to indicate that the NL first page frame metadata are invalid metadata.

[0352] Optionally, in some embodiments, the computer device allocates 0 first physical pages to the first process at a first granularity, and the method further includes:

[0353] It is detected that a first preset condition is met, and the O first physical pages are recycled.

[0354] Specifically, when the computer device detects that the first preset condition is met, it may reclaim O first physical pages.

[0355] The description of the first preset condition can be found above, and for the sake of brevity, it will not be repeated here.

[0356] Optionally, in some embodiments, the computer device allocates Q second physical pages to the first process at a second granularity, and the method further includes:

[0357] It is detected that the first preset condition is met, and Q second physical pages are recycled.

[0358] Optionally, in some embodiments, the method further comprises:

[0359] The P second physical pages are converted back into M first physical pages, and P second page frame metadata are released.

[0360] Specifically, after the computer device recycles the Q second physical pages, there are P unallocated second physical pages. The computer device may reconvert the P second physical pages into M first physical pages, and then release the P second page frame metadata.

[0361] It is understandable that after the computer device reconverts the P second physical pages into M first physical pages, it can change the second field of the M first page frame metadata corresponding to the M first physical pages to indicate that the M first page frame metadata are valid page frame metadata.

[0362] It should be understood that the Figures 4 to 10The specific examples shown are only to help those skilled in the art better understand the embodiments of the present application, and are not intended to limit the scope of the embodiments of the present application. It should also be understood that the sequence numbers of the above-mentioned processes do not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0363] It should also be understood that in the various embodiments of the present application, unless otherwise specified or there is a logical conflict, the terms and / or descriptions between different embodiments are consistent and can be referenced to each other, and the technical features in different embodiments can be combined to form new embodiments according to their internal logical relationships.

[0364] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of the method. In order to realize the above functions, it includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware 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 exceed the scope of the present application.

[0365] The present application embodiment also provides a chip system 1100, such as Fig.11 As shown, the chip system 1100 includes at least one processor and at least one interface circuit. As an example, when the chip system 1100 includes a processor and an interface circuit, the processor may be Fig.11 The processor 1110 shown in the solid line frame (or the processor 110 shown in the dotted line frame) may be Fig.11 The interface circuit 1120 is shown in the solid line box (or the interface circuit 1120 is shown in the dotted line box).

[0366] When the chip system 1100 includes two processors and two interface circuits, the two processors include Fig.11 The processor 1110 shown in the solid line frame and the processor 1110 shown in the dotted line frame, the two interface circuits include Fig.11 The interface circuit 1120 shown in the solid line frame and the interface circuit 1120 shown in the dotted line frame. This is not limited. The processor 1110 and the interface circuit 1120 can be interconnected through a line. For example, the interface circuit 1120 can be used to receive a signal (such as an instruction stored in a memory). For another example, the interface circuit 1120 can be used to send a signal to another device (such as the processor 1110).

[0367] Exemplarily, the interface circuit 1120 can read the instruction stored in the memory and send the instruction to the processor 1110. When the instruction is executed by the processor 1110, the device for accessing the memory or the device for accessing the memory can perform the various steps in the above embodiment. Of course, the chip system 1100 can also include other discrete devices, which is not specifically limited in the embodiment of the present application.

[0368] Another embodiment of the present application also provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a device for accessing memory, the device for accessing memory executes the various steps executed by the device for accessing memory in the method flow shown in the above method embodiment. In some embodiments, the disclosed method can be implemented as computer program instructions encoded in a machine-readable format on a computer-readable storage medium or encoded on other non-transitory media or products.

[0369] Fig.12 A conceptual partial view of a computer program product provided by an embodiment of the present application is schematically shown, where the computer program product includes a computer program for executing a computer process on a computing device.

[0370] In one embodiment, the computer program product is provided using a signal bearing medium 1200. The signal bearing medium 1200 may include one or more program instructions, which when executed by one or more processors may perform the memory management method provided in the embodiment of the present application.

[0371] In some examples, the signal bearing medium 1200 may include a computer readable medium 1201, such as, but not limited to, a hard drive, a compact disk (CD), a digital video disk (DVD), a digital tape, a memory, a read-only memory (ROM), or a random access memory (RAM), and the like.

[0372] In some implementations, the signal bearing medium 1200 may include a computer recordable medium 1202 such as, but not limited to, a memory, a read / write (R / W) CD, a R / W DVD, or the like.

[0373] In some embodiments, the signal bearing medium 1200 may include a communication medium 1203, such as, but not limited to, a digital and / or analog communication medium (e.g., a fiber optic cable, a waveguide, a wired communication link, a wireless communication link, etc.). The signal bearing medium 1200 may be communicated by a wireless form of the communication medium 1203 (e.g., a wireless communication medium complying with the IEEE 1502.11 standard or other transmission protocol). The one or more program instructions may be, for example, computer executable instructions or logic implementation instructions.

[0374] In some examples, the apparatus for memory management may be configured to provide various operations, functions, or actions in response to one or more program instructions via computer-readable medium 1201 , computer-recordable medium 1202 , and / or communication medium 1203 .

[0375] It should be understood that the arrangement described here is only for illustrative purposes. Thus, it will be appreciated by those skilled in the art that other arrangements and other elements (e.g., machines, interfaces, functions, sequences, and functional groups, etc.) can be used instead, and some elements can be omitted together according to the desired result. In addition, many of the described elements can be implemented as discrete or distributed components, or in any appropriate combination and position to combine other components to implement functional entities.

[0376] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using a software program, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer executes the instructions on the computer and when the computer executes the instructions, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.

[0377] Computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center via wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. Computer-readable storage media can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that includes one or more available media integrated therein. Available media can be magnetic media (e.g., floppy disks, hard disks, tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid state drives (SSDs)).

[0378] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A memory management method, characterized in that: The method is applied to a computer device, and the method comprises: Divide the physical memory into N first physical pages according to a first granularity and create N first page frame metadata corresponding to the N first physical pages, wherein the first granularity is greater than a minimum granularity supported by the computer device, N ≥ 1 and is an integer, and each of the N first page frame metadata includes a first field to indicate a size of a corresponding first physical page; Determining the size of the physical memory required by the first process according to a request of the first process; According to the size of the physical memory required by the first process, select to allocate O first physical pages to the first process at the first granularity, or select to allocate Q second physical pages to the first process at the second granularity, or select to allocate W first physical pages to the first process at the first granularity and allocate T second physical pages to the first process at the second granularity, wherein the second granularity is smaller than the first granularity, the second granularity is greater than or equal to the minimum granularity supported by the computer device, N≥O≥1, and O is an integer, Q≥1 and Q is an integer, N≥W≥1, and W is an integer, and T≥1 and T is an integer.

2. The method according to claim 1, characterized in that The selecting to allocate Q second physical pages to the first process at a second granularity includes: Selecting M first physical pages from the N first physical pages, where N≥M≥1, and M is an integer; converting the M first physical pages into P second physical pages according to the second granularity, and creating corresponding P second page frame metadata, where P>M>1, and P is an integer, and each of the P second page frame metadata includes a first field to indicate a size of the corresponding second physical page; The Q second physical pages are selected from the P second physical pages and allocated to the first process.

3. The method according to claim 2, characterized in that Each of the N first page frame metadata includes a second field to indicate that the N first page frame metadata is valid page frame metadata, and after converting the M first physical pages into P second physical pages according to the second granularity, the method further includes: The value of the second field of each of the M first page frame metadata corresponding to the M first physical pages is changed to indicate that the M first physical pages are invalid page frame metadata.

4. The method according to claim 3, characterized in that The method further comprises: When it is detected that a first preset condition is met, reclaiming the Q second physical pages; Reconverting the P second physical pages into the M first physical pages, and releasing the P second page frame metadata; The value of the second field of each of the M first page frame metadata corresponding to the M first physical pages is changed to indicate that the M first physical pages are valid page frame metadata.

5. The method according to claim 1, characterized in that The selecting to allocate W first physical pages to the first process at the first granularity and to allocate T second physical pages to the first process at the second granularity includes: Select W first physical pages from the N first physical pages and allocate them to the first process, where N≥W≥1, and W is an integer; Select S first physical pages from NW first physical pages, NW≥S≥1, and S is an integer; converting the S first physical pages into D second physical pages according to the second granularity, and creating corresponding D second page frame metadata, where D>S>1, and D is an integer, and each of the D second page frame metadata includes a first field to indicate a size of the corresponding second physical page; The T second physical pages are selected from the D second physical pages and allocated to the first process.

6. The method according to any one of claims 1 to 5, characterized in that Each of the N first page frame metadata includes a second field to indicate that the N first page frame metadata is valid page frame metadata, and before selecting to allocate O first physical pages to the first process at the first granularity, the method further includes: Convert the N first physical pages into L physical blocks by using a buddy algorithm, the L physical blocks correspond to L third page frame metadata, each of the L third page frame metadata includes a first field to indicate the size of the corresponding physical block, and each of the L third page frame metadata includes a second field to indicate that each third page frame metadata is valid page frame metadata; The selecting to allocate O first physical pages to the first process at the first granularity includes: A first physical block is selected from the L physical blocks and allocated to the first process, wherein the first physical block includes O first physical pages.

7. The method according to claim 6, characterized in that The L third page frame metadata are obtained based on L first page frame metadata among the N first page frame metadata, and the method further includes: The value of the second field of each of the NL first page frame metadata is changed to indicate that the NL first page frame metadata is invalid page frame metadata.

8. The method according to claim 2, characterized in that: Each of the P second page frame metadata includes a second field to indicate that the P second page frame metadata is valid page frame metadata. Before selecting the Q second physical pages from the P second physical pages and assigning them to the first process, the method further includes: The P second physical pages are converted into R physical blocks by a buddy algorithm, the R physical blocks correspond to R fourth page frame metadata, each of the R fourth page frame metadata includes a first field to indicate the size of the corresponding physical block, and each of the R fourth page frame metadata includes a second field to indicate that each fourth page frame metadata is valid meta-frame metadata; The selecting the Q second physical pages from the P second physical pages and allocating them to the first process comprises: A second physical block is selected from the R physical blocks and allocated to the first process, wherein the first physical block includes Q second physical pages.

9. The method according to claim 8, characterized in that The R fourth page frame metadata are obtained based on R second page frame metadata among the P second page frame metadata, and the method further includes: The value of the second field of each of the PR second page frame metadata is changed to indicate that the PR second page frame metadata is invalid page frame metadata.

10. The method according to claim 8 or 9, characterized in that: Each of the N first page frame metadata includes a fourth field to indicate whether the first physical page corresponding to the N first page frame metadata is divided. After converting the M first physical pages into the P second physical pages, the method further includes: The value of the fourth field of each of the M first page frame metadata corresponding to the M first physical pages is changed to indicate that the M first physical pages have been divided.

11. The method according to any one of claims 2 to 4 or 8 to 10, characterized in that The P second page frame metadata are stored in any one of the P second physical pages.

12. The method according to any one of claims 1 to 11, characterized in that When it is selected to allocate 0 first physical pages to the first process at the first granularity, the method further includes: It is detected that a first preset condition is met, and the O first physical pages are recycled.

13. The method according to any one of claims 1 to 12, characterized in that Each of the N first page frame metadata includes a third field to indicate that the N first page frame metadata are created by a main page frame manager.

14. A memory management method, characterized in that: The method is applied to a computer device, the computer device comprising a main page frame manager, a first secondary page frame manager and a page distributor, the main page frame manager is used to manage a first physical page of a first granularity, the first secondary page frame manager is used to manage a second physical page of a second granularity, wherein: The main page frame manager is used to divide the physical memory into N first physical pages according to the first granularity and create N first page frame metadata corresponding to the N first physical pages, the first granularity is greater than the minimum granularity supported by the computer device, N ≥ 1 and is an integer, and each of the N first page frame metadata includes a first field to indicate the size of the corresponding first physical page; The page allocator is used to determine the size of the physical memory required by the first process according to the request of the first process; The page allocator is further used to select, according to the size of the physical memory required by the first process, to allocate O first physical pages to the first process at the first granularity or to allocate Q second physical pages to the first process at the second granularity, or to allocate W first physical pages to the first process at the first granularity and T second physical pages to the first process at the second granularity, wherein the second granularity is smaller than the first granularity, the second granularity is greater than or equal to the minimum granularity supported by the computer device, N≥O≥1, and O is an integer, Q≥1 and Q is an integer, N≥W≥1, and W is an integer, and T≥1 and T is an integer.

15. The method according to claim 14, characterized in that When the page allocator chooses to allocate Q second physical pages to the first process at the second granularity, the first secondary page frame manager is configured to: Selecting M first physical pages from the N first physical pages, where N≥M≥1, and M is an integer; converting the M first physical pages into P second physical pages according to the second granularity, and creating corresponding P second page frame metadata, where P>M>1, and P is an integer, and each of the P second page frame metadata includes a first field to indicate a size of the corresponding second physical page; The page allocator is specifically configured to select the Q second physical pages from the P second physical pages and allocate them to the first process.

16. The method according to claim 15, characterized in that Each of the N first page frame metadata includes a second field to indicate that the N first page frame metadata are valid page frame metadata. After converting the M first physical pages into P second physical pages according to the second granularity, the main page frame manager is further used to change the value of the second field of each of the M first page frame metadata corresponding to the M first physical pages to indicate that the M first physical pages are invalid page frame metadata.

17. The method according to claim 16, characterized in that When the page allocation selects to allocate Q second physical pages to the first process at a second granularity, the page allocator is further used to detect that a first preset condition is met and determine the first secondary page frame manager; The first secondary page frame manager is further used for: Reclaiming the Q second physical pages; Reconverting the P second physical pages into the M first physical pages, and releasing the P second page frame metadata; The main page frame manager is further used to change the value of the second field of each of the M first page frame metadata corresponding to the M first physical pages to indicate that the M first physical pages are valid page frame metadata.

18. The method according to claim 14, characterized in that When the page allocator selects to allocate W first physical pages to the first process at the first granularity and allocate T second physical pages to the first process at the second granularity, the page allocator is specifically configured to select W first physical pages from the N first physical pages and allocate them to the first process, where N≥W≥1, and W is an integer; The first secondary page frame manager is used to: Select S first physical pages from NW first physical pages, NW≥S≥1, and S is an integer; converting the S first physical pages into D second physical pages according to the second granularity, and creating corresponding D second page frame metadata, where D>S>1, and D is an integer, and each of the D second page frame metadata includes a first field to indicate a size of the corresponding second physical page; The page allocator is specifically configured to select the T second physical pages from the D second physical pages and allocate them to the first process.

19. The method according to any one of claims 14 to 18, characterized in that Each of the N first page frame metadata includes a second field to indicate that the N first page frame metadata is valid page frame metadata, and before the page allocator selects to allocate O first physical pages to the first process at the first granularity, the main page frame manager is further used to convert the N first physical pages into L physical blocks through a buddy algorithm, the L physical blocks correspond to L third page frame metadata, each of the L third page frame metadata includes a first field to indicate the size of the corresponding physical block, and each of the L third page frame metadata includes a second field to indicate that each third page frame metadata is valid page frame metadata; The page allocator is specifically used to select a first physical block from the L physical blocks and allocate it to the first process, wherein the first physical block includes O first physical pages.

20. The method according to claim 19, characterized in that The main page frame manager is further used to change the value of the second field of each of the NL first page frame metadata to indicate that the NL first page frame metadata are invalid page frame metadata.

21. The method according to claim 15, characterized in that Each of the P second page frame metadata includes a second field to indicate that the P second page frame metadata is valid page frame metadata, and before the page allocator selects the Q second physical pages from the P second physical pages to allocate to the first process, the first main page frame manager is further used to convert the P second physical pages into R physical blocks through a buddy algorithm, the R physical blocks correspond to R fourth page frame metadata, each of the R fourth page frame metadata includes a first field to indicate the size of the corresponding physical block, and each of the R fourth page frame metadata includes a second field to indicate that each fourth page frame metadata is valid page frame metadata; The home frame manager is specifically used to select a second physical block from the R physical blocks and allocate it to the first process, wherein the first physical block includes Q second physical pages.

22. The method according to claim 21, characterized in that The first secondary page frame manager is further used to change the value of the second field of each second page frame metadata in PR second page frame metadata to indicate that the PR second page frame metadata are invalid page frame metadata.

23. The method according to claim 21 or 22, characterized in that Each of the N first page frame metadata includes a fourth field to indicate whether the first physical page corresponding to the N first page frame metadata is divided. After the first secondary page frame manager converts the M first physical pages into the P second physical pages, the main page frame manager is further used to change the value of the fourth field of each of the M first page frame metadata corresponding to the M first physical pages to indicate that the M first physical pages have been divided.

24. The method according to any one of claims 15 to 17 or 21 to 23, characterized in that The P second page frame metadata are stored in any one of the P second physical pages.

25. The method according to any one of claims 14 to 24, characterized in that When the page allocator selects to allocate O first physical pages to the first process at a first granularity, the page allocator is further configured to detect that a first preset condition is satisfied and select the home frame manager; The home frame manager is further used to recycle the O first physical pages.

26. The method according to any one of claims 14 to 25, characterized in that Each of the N first page frame metadata includes a third field to indicate that the N first page frame metadata are created by a main page frame manager.

27. A computer device, characterized in that: The method comprises one or more processors; one or more memories; the one or more memories store one or more computer programs, the one or more computer programs include instructions, and when the instructions are executed by the one or more processors, the method according to any one of claims 1 to 13 is executed.

28. A chip, characterized in that: The chip includes a processor and a communication interface, wherein the communication interface is used to receive a signal and transmit the signal to the processor, and the processor processes the signal so that the method according to any one of claims 1 to 13 is executed.

29. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed on a computer device, the method according to any one of claims 1 to 13 is executed.

Citation Information

Cited By

  • Memory management method and computer device

    EP4693052A1

  • Memory management method and computer device

    WO2024234778A1