Memory management method and device, electronic equipment and readable medium

By setting up a preset memory pool in an electronic device and detecting the requesting node, directly selecting and allocating memory units from the preset memory pool, the problem of how to efficiently manage memory is solved, and memory management efficiency and overall performance are improved.

CN120162277APending Publication Date: 2025-06-17GODSON ZHONGKE (BEIJING) INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510192188.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-20
Publication Date
2025-06-17

AI Technical Summary

Technical Problem

How to efficiently manage memory to ensure that each node of an electronic device can effectively allocate and recycle memory.

Method used

By setting a preset memory pool in the electronic device, the first request node is detected in response to the memory request. If the node is detected as a specific node corresponding to the preset memory pool, an appropriate amount of memory units is selected from the preset memory pool as the target memory unit and allocated to the node for use.

Benefits of technology

Improves the efficiency of memory management, especially when drivers or subsystems frequently use memory, reducing memory waste and system overhead, and improving overall performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120162277A_ABST
    Figure CN120162277A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a memory management method and device, electronic equipment and a readable medium, and relates to the technical field of computers, in the method, in response to a memory application request, a first request node to which the memory application request belongs is detected; under the condition that the first request node is detected to be a specific node corresponding to a preset memory pool, namely under the condition that the specific node applies for a memory through a memory application request, selecting M memory units from the preset memory pool as target memory units according to the memory application request, the specific node is a node of which the required memory size is integral multiple of the memory unit size, and M is a positive integer. And the target memory unit in the preset memory pool is allocated to the first request node for the first request node to use, so that the memory management efficiency is improved in a specific scene that a driver or a subsystem uses a small amount of memory frequently and the like.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and particularly to a memory management method, apparatus, electronic device, and readable medium. Background Art

[0002] Currently, with the continuous development of computer technology, electronic devices are increasingly widely used. In an electronic device, the role of memory is crucial, which directly affects the running speed and task processing ability of the device. In related technologies, when each node (such as a subsystem, application program, system service, device driver, etc.) of an electronic device is running, it often needs to use memory to manage data. Correspondingly, the electronic device needs to manage the memory itself, allocate and recycle memory for each node object respectively, so as to ensure the normal operation of each node object.

[0003] Therefore, how to efficiently manage memory has become a technical problem that urgently needs to be solved. Summary of the Invention

[0004] Embodiments of the present invention provide a memory management method, apparatus, electronic device, and readable medium, which can solve the problem of how to efficiently manage memory.

[0005] To solve the above problems, embodiments of the present invention disclose a memory management method, the method comprising:

[0006] Detecting a first request node to which the memory application request belongs in response to the memory application request;

[0007] When it is detected that the first request node is a specific node corresponding to a preset memory pool, selecting M memory units as target memory units from the preset memory pool according to the memory application request; M is a positive integer;

[0008] Allocating the target memory units in the preset memory pool to the first request node for the first request node to use.

[0009] On the other hand, embodiments of the present invention disclose a memory management apparatus, the apparatus comprising:

[0010] A first detection module, configured to detect a first request node to which the memory application request belongs in response to the memory application request;

[0011] A selection module, configured to select M memory units as target memory units from the preset memory pool according to the memory application request when it is detected that the first request node is a specific node corresponding to a preset memory pool; M is a positive integer;

[0012] An allocation module is used to allocate the target memory unit in the preset memory pool to the first requesting node for use by the first requesting node.

[0013] On the other hand, an embodiment of the present invention discloses an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the aforementioned method.

[0014] The embodiment of the present invention further discloses a machine-readable medium on which instructions are stored. When executed by one or more processors, the processors are enabled to execute the method described above.

[0015] The embodiment of the present invention includes the following advantages: In the memory management method provided by the embodiment of the present invention, in response to a memory application request, the first request node to which the memory application request belongs is detected. In the case where it is detected that the first request node is a specific node corresponding to a preset memory pool, that is, in the case where the specific node applies for memory through a memory application request, M memory units are selected from the preset memory pool as target memory units according to the memory application request, where M is a positive integer. The target memory unit in the preset memory pool is allocated to the first request node for use by the first request node. Since the preset memory pool is used after a specific node requests it, and the memory size requested by the specific node is an integer multiple of the size of the memory unit in the preset memory pool, that is, the memory granularity required by the specific node is an integer multiple of the memory granularity provided in the preset memory pool. Therefore, directly selecting one or more memory units from the preset memory pool can meet the use requirements of a specific node, thereby improving the memory management efficiency in specific scenarios such as a driver or subsystem using a small amount of memory frequently. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0017] Figure 1 is a flowchart of a memory management method provided by an embodiment of the present invention;

[0018] Figure 2 It is a schematic diagram of a processing flow provided by an embodiment of the present invention;

[0019] Figure 3 is a block diagram of a memory management device provided by an embodiment of the present invention;

[0020] Figure 4 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0021] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0022] Figure 1 is a flowchart of a memory management method provided by an embodiment of the present invention. Figure 1 As shown, the memory management method may include the following steps:

[0023] Step 101: In response to a memory application request, a first requesting node to which the memory application request belongs is detected.

[0024] Step 102: When it is detected that the first requesting node is a specific node corresponding to a preset memory pool, select M memory units from the preset memory pool as target memory units according to the memory application request; the specific node is a node whose required memory size is an integer multiple of the memory unit size, and M is a positive integer.

[0025] Step 103: Allocate the target memory unit in a preset memory pool to the first requesting node for use by the first requesting node.

[0026] In the embodiment of the present invention, a node may refer to an object entity in an electronic device that needs to use memory. For example, a node may be a subsystem, device driver, application, system service, etc. in operation in the electronic device. Furthermore, a specific node may be some nodes in the electronic device, and some nodes may be designated as specific nodes according to actual needs.

[0027] Specifically, the nodes that can use the memory pool can be specified in advance for the preset memory pool, and these specified nodes are the specific nodes corresponding to the preset memory pool. In an embodiment of the present invention, the memory size required for the specific nodes corresponding to the preset memory pool is fixed, so that memory allocation can be achieved by allocating the same number of memory units to different specific nodes each time. Exemplarily, assuming that the size of the memory unit in the preset memory pool is 3M, the memory size required for the specific nodes corresponding to the preset memory pool is 9M. Accordingly, 3 memory units are selected as target memory units for allocation each time.

[0028] Alternatively, since the working states of different nodes such as subsystems, device drivers, applications, and system services in an electronic device are different, the memory sizes used are correspondingly different. Therefore, the memory requested by different nodes also often corresponds differently. The memory size required by a specific node corresponding to a preset memory pool may also not be fixed. In this way, different numbers of memory units are allocated from the preset memory pool for different specific nodes to achieve memory allocation. Exemplarily, assume that the size of a memory unit in the preset memory pool is 3M. Among the specific nodes corresponding to this preset memory pool, the memory size required by node a is 9M, and the memory size required by node b is 6M. Correspondingly, when node a requests 9M of memory, 3 memory units can be selected from the preset memory pool as target memory units and allocated to node a. When node b requests 6M of memory, 2 memory units are selected from the preset memory pool as target memory units and allocated to node b.

[0029] In the embodiments of the present invention, the number of memory units allocated to different specific nodes in the preset memory pool can be different. In this way, for a specific node with a relatively large required memory size, there is no need to apply multiple times. Only one request is needed to obtain the required memory size at one time. For example, the memory size required by node a is 9M, and the memory size required by node b is 6M. Correspondingly, 3 memory units are selected from the preset memory pool as target memory units and allocated to node a, so that node a only needs to apply once to obtain 9M of memory units at one time. In addition, 2 memory units are selected from the preset memory pool as target memory units and allocated to node b, so that node b only needs to apply once to obtain 6M of memory units at one time.

[0030] Exemplarily, in an application scenario, some subsystems or device drivers frequently apply for memory at the page level to handle workloads. For example, a network device driver often needs memory at the page level to process received and transmitted network packets. A block device driver (e.g., a hard disk drive) often needs memory at the page level for disk input / output (I / O) operations. A graphics processing subsystem often needs memory at the page level to process continuously loaded images. Correspondingly, the network device driver, the block device driver, and the graphics processing subsystem can be determined as specific nodes.

[0031] The first requesting node may be the node that triggers a memory application request, and the memory application request may be triggered by the node when it needs to use memory. Correspondingly, in response to the memory application request, the first requesting node of the memory application request may be detected first to determine whether the first requesting node is a specific node corresponding to a preset memory pool. The electronic device may include a preset memory pool created in advance, and the preset memory pool may be used by specific nodes. Correspondingly, since the memory size required by the specific node is an integer multiple of the memory unit size provided by the preset memory pool, therefore, if the first requesting node is the specific node corresponding to the preset memory pool, it means that the memory unit size provided by the preset memory pool can be divided evenly by the memory size required by the first requesting node. Therefore, allocating one or more memory units as target memory units to the first requesting node for use can meet the needs of the first requesting node, and at the same time, it can avoid the problem of memory waste caused by the fact that the memory unit size provided by the preset memory pool cannot be divided evenly by the memory size required by the first requesting node. For example, if the memory unit size provided by the preset memory pool is 3M and the required memory size is 10M, then 4 memory units need to be allocated, resulting in memory waste.

[0032] If the first requesting node is not a specific node, the memory units of the preset memory pool are not allocated to the first requesting node. Exemplarily, in the case where the first requesting node is not a specific node, a default memory allocation method may be used to allocate memory to the first requesting node, and the embodiments of the present invention do not limit this.

[0033] Furthermore, when creating the preset memory pool, the memory units in the memory pool may be created in advance according to the memory size required by specific nodes, so that the size of each memory unit can be divided evenly by the memory size required by the specific nodes, that is, the memory size required by the specific nodes is an integer multiple of the size of a single memory unit included in the preset memory pool. In this way, when allocating memory to different specific nodes, one or more memory units in the preset memory pool are respectively allocated to each specific node according to the memory application requests of the specific nodes, so as to meet the memory usage requirements of the corresponding specific nodes.

[0034] In summary, in the memory management method provided by the embodiment of the present invention, in response to a memory application request, the first request node to which the memory application request belongs is detected. In the case where it is detected that the first request node is a specific node corresponding to a preset memory pool, that is, in the case where the specific node applies for memory through a memory application request, M memory units are selected from the preset memory pool as target memory units according to the memory application request, where M is a positive integer. The target memory unit in the preset memory pool is allocated to the first request node for use by the first request node. Since the preset memory pool is used after a specific node requests it, and the memory size requested by the specific node is an integer multiple of the size of the memory unit in the preset memory pool, that is, the memory granularity required by the specific node is an integer multiple of the memory granularity provided in the preset memory pool. Therefore, directly selecting one or more memory units from the preset memory pool can meet the use requirements of a specific node, thereby improving the memory management efficiency in specific scenarios such as a driver or subsystem using a small amount of memory frequently.

[0035] At the same time, setting a preset memory pool for use only after a specific node requests it can further ensure the allocation efficiency of memory allocation for a specific node.

[0036] Optionally, the size of the memory unit in the preset memory pool can be equal to the memory size required by a specific node. When the memory size required by a specific node is N times the size of a single page, a memory unit can represent a page-level memory, and the page-level memory refers to N times the size of a single page, that is, the size of each memory unit in the preset memory pool is the number of memory pages N*single page size as the granularity of memory allocation. In this way, when M is a predetermined number of 1, each time 1 memory unit is selected as the target memory unit to be allocated to a specific node, the use requirements of the specific node can be met. Among them, the number of memory pages N can be a positive integer, and the specific value can be set as required. For example, the number of memory pages N can be 1 or 2, and the embodiment of the present invention does not limit this. Among them, the number of memory pages N can be less than the preset number threshold. The preset number threshold can be set as required. For example, the preset number threshold can be 10, or the preset number threshold can be 15, and the embodiment of the present invention does not limit this.

[0037] In a default memory allocation method, memory is allocated for each node by calling a preset allocation function, for example, mempool_alloc, kmalloc or kmem_cache_alloc function, and memory is allocated using the kmem_cache structure of the buddy subsystem or the object buffer allocator (Slab allocator).

[0038] In this way, it is often necessary to perform memory recycling in order to obtain the memory with the size required by the first requesting node, and then memory allocation can be carried out. Among them, memory recycling is used to manage and release the memory space that is no longer used, so as to provide sufficient memory resources for this node. The process of memory recycling often involves memory paging and memory swapping operations, which will cause additional system overhead to the electronic device, increase the complexity of memory allocation, and for nodes that frequently use page-level memory, it will increase unnecessary burdens.

[0039] In the embodiments of the present invention, the size of the memory cells in the preset memory pool can be equal to the size of the target memory cells required by a specific node. In this way, each time the memory cells in the preset memory pool can be directly allocated to the specific node, which can avoid operations such as memory swapping and memory paging, improve the memory allocation efficiency for the specific node, be able to respond more quickly to the memory application requests corresponding to the specific node, and reduce the memory allocation latency. At the same time, the system overhead of memory management in the preset memory pool can be reduced, the complexity of memory allocation can be reduced, the memory management can be made more efficient and reliable, and thus the overall performance of the electronic device can be improved.

[0040] Optionally, in some embodiments, the preset memory pool can be created through the following steps:

[0041] Step S21, obtain the number of memory pages N required when the specific node applies for memory and the total size of the preset memory pool.

[0042] Step S22, based on the number of memory pages N, the size of a single page of the operating system, and the total size of the memory pool, create the memory cells to obtain the preset memory pool. Wherein, the size of each single memory cell is N times the size of a single page of the operating system.

[0043] In the embodiments of the present invention, the total size of the memory units does not exceed the total size of the preset memory pool, so that the sum of the actually created memory units can be avoided from exceeding the preset memory pool. The above steps S21 to S22 can be executed before step 101. Specifically, after the system is initialized, a memory pool can be created for a specific node as the preset memory pool. The electronic device can initialize the system resources first when starting up, and then create the preset memory pool. When creating the preset memory pool, the pre-set number of memory pages N and the total size of the memory pool can be loaded from the configuration file. Among them, the specific value of the number of memory pages N in the configuration file can be set according to the number of pages of the memory size required by the specific node. Exemplarily, assuming that the memory required by a specific node each time is 4 memory pages, then the number of memory pages can be set to N = 4 in the configuration file. Among them, the configuration file can be stored in a preset specified storage location, which can be pre-set by the developer, and the configuration file can be represented by data structures such as key-value pairs, XML, etc. The total size of the memory pool corresponding to the preset memory pool can be set according to the actual needs of the memory application requests corresponding to each node. Exemplarily, the proportion of the total size of the memory pool in the available memory of the electronic device does not exceed a preset proportion threshold, and the total size of the memory pool is positively correlated with the number of specific nodes. In this way, while ensuring that the memory pool can meet the memory usage requirements of all specific nodes as much as possible, it is possible to avoid occupying too much memory in the electronic device, thereby avoiding affecting the normal use of memory by other nodes. Among them, the preset proportion threshold is pre-set by the developer, and the pre-set preset proportion threshold can be read. In the case of more specific nodes, the preset proportion threshold pre-set by the developer is often larger. Exemplarily, the preset proportion threshold can be set after determining the current available memory of the electronic device. Assuming that the current available memory of the electronic device is 1000M and the preset proportion threshold can be 10%, then directly use 1000M × 10% = 100M as the total size of the memory pool. Among them, the total size of the memory pool is a fixed value determined based on the current available memory of the electronic device.

[0044] Further, the single-page size of the operating system refers to the size of a single memory page. The single-page size is determined by the hardware and the operating system, and the single-page sizes of different operating systems may vary. Exemplarily, the single-page size of the operating system can be 4 kilobytes (KB). In the embodiments of the present invention, the page can be used as a unit, and each allocable unit can include N memory pages, that is, the allocation granularity is N memory pages. Specifically, the product of the number of memory pages N and the single-page size can be calculated to obtain the size of a single memory unit, that is, the size of a single memory unit is N times the single-page size. Assuming the number of memory pages N = 5, then the size of a single memory unit = 5 × 4KB = 20KB. In this way, a memory unit can provide the memory pages required for a specific node to use memory. Further, based on the total size of the memory pool and the size of a single memory unit, the number of memory units that can be created can be calculated. Specifically, the ratio of the total size of the memory pool to the size of a single memory unit can be calculated, and the ratio can be rounded down to obtain the number of memory units that can be created in the preset memory pool. In this way, it can be ensured that the total size of the memory units does not exceed the total size of the memory pool, and further, the problem that the preset memory pool created for a specific node is too large can be avoided.

[0045] Further, the size of a single memory unit and the number of memory units that can be created can be used as function parameters to call the memory pool creation function to create a memory pool including the corresponding number of memory units. Exemplarily, the memory pool creation function can be the mempool_create function. Assuming that the number of memory units that can be created is 50, then (20KB, 50) can be used as the parameter of the mempool_create function, and the mempool_create function is called to create a memory pool including 50 memory units with a size of 20KB. It should be noted that in the embodiments of the present invention, the memory units in the preset memory pool can be continuously allocated, which can reduce memory fragmentation and thus improve memory utilization. Alternatively, they can also be discontinuously allocated. Exemplarily, assuming that two memory units are created, then the address range of one memory unit can be from 0X1000 to 0X2000, and the address range of the other memory unit can be from 0X3000 to 0X4000.

[0046] In the embodiments of the present invention, for a preset memory pool, the memory sizes required by the specific node corresponding to the preset memory pool are the same, both being the number of memory pages N × the single-page size. In the created preset memory pool, the size of each memory unit is N times the single-page size. In this way, each time 1 memory unit can be selected and allocated to the specific node.

[0047] It should be noted that in the embodiments of the present invention, there may be one or more preset memory pools. For nodes whose memory application frequency is greater than a preset frequency threshold and the required memory size is less than a preset memory size threshold, that is, drivers or subsystems that require a small amount of memory and use it frequently, nodes with the same required memory size can be grouped as a set of specific nodes. Among them, the preset memory size threshold can be set in advance by developers. Exemplarily, the preset memory size threshold can be P × single-page size, that is, the specific nodes are nodes that frequently use page-level memory and are integer multiples of the single-page size.

[0048] For any set of specific nodes, create a preset memory pool according to the above steps S21 to S22. Use this set of specific nodes as the specific nodes corresponding to this preset memory pool, and record the node identifiers of each node in this set of specific nodes in the memory management table of this preset memory pool. Alternatively, it is also possible to create only one preset memory pool and create multiple memory units for any set of specific nodes, and these multiple memory units form a preset memory pool.

[0049] Correspondingly, use all specific nodes as the specific nodes corresponding to this preset memory pool, and record the node identifiers of all specific nodes in the memory management table of this preset memory pool.

[0050] Exemplarily, assume that there are two sets of specific nodes. The required memory size of one set of specific nodes is 9M, and the required memory size of the other set of specific nodes is 6M. Then, it is possible to create a preset memory pool that only includes memory units of size 9M, and a preset memory pool that only includes memory units of size 6M. Alternatively, it is also possible to create only one preset memory pool that includes memory units of size 9M and memory units of size 6M.

[0051] In the embodiments of the present invention, when creating a preset memory pool, obtain the number of memory pages N required by a specific node when applying for memory and the total size of the preset memory pool. Based on the number of memory pages N, the single-page size of the operating system, and the total size of the memory pool, create memory units to obtain a preset memory pool. Among them, the size of a single memory unit is N times the single-page size of the operating system. In this way, the size of the memory units in the preset memory pool is equal to the memory size required by a specific node when using memory, and further, when allocating memory for a specific node subsequently, it is possible to directly allocate one memory unit at a time, thereby ensuring the memory allocation efficiency.

[0052] Optionally, the above detection of the first request node to which the memory application request belongs may specifically be to detect whether the first request node is a specific node. In the embodiments of the present invention, the above step of detecting the first request node to which the memory application request belongs may specifically include:

[0053] Step 1011: Extract the node identifier in the memory application request as the target identifier; the node identifier is used to represent the first requesting node.

[0054] Step 1012: Compare the target identifier with each node identifier recorded separately in the memory management table of the preset memory pool.

[0055] Step 1013: If there is a node identifier that is the same as the target identifier, determine that the first requesting node is a specific node.

[0056] In the embodiments of the present invention, there can be multiple specific nodes, and the specific nodes can be pre-selected manually. If the first requesting node is a specific node, it means that the first requesting node itself is a specific node, and this memory application request is triggered by a specific node, and memory units in the preset memory pool can be allocated to it.

[0057] The parameters carried in the memory application request can include a node identifier. The node identifier is used to uniquely identify a node. Correspondingly, the node identifier in the memory application request can represent the first requesting node. Correspondingly, the value of the parameter representing the node identifier in the parameters carried in the memory application request can be extracted to obtain the target identifier. For example, the content of the bit field of the parameter used to represent the node identifier in the memory application request is extracted to obtain the target identifier. Exemplarily, a memory application request initiated by the first requesting node can be expressed as get_pool_page(node, size). Among them, node and size represent the parameters included in the memory application request, and the node parameter represents the node identifier. Assume that the bit field of the node parameter is from the 20th to the 25th bit, then the content from the 20th to the 25th bit in the memory application request can be extracted to obtain the value of the node parameter. Then, it is detected whether the value of the extracted node parameter is the same as the identifier of the specific node corresponding to the preset memory pool, so as to detect whether the first requesting node initiating the memory application is a specific node.

[0058] The memory management table can be generated for this memory pool after creating the preset memory pool. The memory management table can also be called a memory pool attribution quick search index table. The node identifiers of specific nodes that can use this memory pool can be recorded in this memory management table to facilitate determining which specific nodes this memory pool belongs to for use, and to facilitate controlling the application and release of memory units in the memory pool by specific nodes. Exemplarily, the data structure of the memory management table can be an array. Specifically, a one-dimensional array corresponding to this preset memory pool is created as the first array, and the node identifiers corresponding to the specific nodes in this preset memory pool are respectively written into the one-dimensional array as elements of the first array for storage.

[0059] Correspondingly, for the memory management table of any preset memory pool, the target identifier can be compared with each node identifier in the memory management table respectively. If there is a node identifier that is the same as the target identifier, it can be determined that the first requesting node is the specific node corresponding to the preset memory pool. If there is no node identifier that is the same as the target identifier in any of the memory management tables, it can be determined that the first requesting node is not a specific node. Exemplarily, assuming that the target identifier is node-015, then a search is performed in the memory management table. If a successful match is found in the memory management table, that is, the node identifier node-015 is recorded, it can be determined that the first requesting node is a specific node. If the node identifier node-015 is not recorded after the search in the memory management table, it can be determined that the first requesting node is not a specific node.

[0060] In an embodiment of the present invention, the node identifier in the memory application request is extracted as the target identifier. The target identifier is compared with each node identifier separately recorded in the memory management table of the preset memory pool. If there is a node identifier that is the same as the target identifier, it is determined that the first requesting node is a specific node. In this way, by using the node identifier of the specific node recorded in the memory management table to compare the node identifier in the memory application request with each node identifier recorded in the memory management table, it can be detected whether the first requesting node is a specific node, and thus the determination efficiency can be ensured to a certain extent.

[0061] Optionally, the step of selecting M memory units as target memory units from the preset memory pool according to the memory application request may specifically include:

[0062] Step 1021: Analyze the target size of the memory applied for in the memory application request.

[0063] Step 1022: Select M unallocated memory units from the preset memory pool as the target memory units based on the target size; the total size of the M unallocated memory units is equal to the target size.

[0064] In the embodiment of the present invention, the specific value of the parameter representing the required memory size can be extracted from the parameters carried in the memory application request initiated by the first request node to obtain the target size. For example, the content of the bit field of the parameter used to represent the memory size in the memory application request is extracted to obtain the target size. Exemplarily, assuming that the memory application request is get_pool_page(node, size), the value of the size parameter can be extracted as the target size. Assuming that the bit field corresponding to the size parameter in the memory application request is the 26th to the 30th bits, then the content of the 26th to the 30th bits can be extracted to obtain the value of the size parameter. Then, the target size is divided by the size of a single memory unit to obtain the number M of memory units corresponding to the memory application request. In this way, it can be ensured that the total size of M unallocated memory units is equal to the target size.

[0065] Further, in the embodiment of the present invention, for any memory unit, after the memory unit is allocated to a specific node, a corresponding relationship indicating the unit identifier of the memory unit and the node identifier of the allocated specific node can be recorded in the memory management table. The corresponding relationship includes the unit identifier of the memory unit and the node identifier of the specific node. In this way, it can be convenient to determine which memory units are allocated and to which specific node they are specifically allocated. The memory management table further includes a second array, and the second array can be a two-dimensional array. A corresponding relationship is represented in the second array, that is, the unit identifier of the memory unit and the node identifier of the allocated specific node are respectively stored in the second array. Exemplarily, assuming that memory unit 1 is allocated for use by a specific node with a node identifier of node-015, and the unit identifier of memory unit 1 is unit-1, then [unit-1, node-015] is added to the second array.

[0066] Correspondingly, the memory units whose node identifiers are not recorded in the memory management table can be determined as unallocated memory units. Then, M memory units are selected from the unallocated memory units as the target memory units and allocated to the first request node. In the embodiment of the present invention, the target size corresponding to the memory applied for in the memory application request is parsed. Selecting M unallocated memory units from the preset memory pool based on the target size can realize determining the target memory units for the first request node, and the selection efficiency is relatively high.

[0067] It should be noted that in the embodiment of the present invention, the preset memory pool can also be initialized through the init_memory_pool function to create the above-mentioned one-dimensional array and two-dimensional array. Among them, in the initial state, the one-dimensional array and the two-dimensional array are empty. Further, a third array can also be created to store the unit identifiers of each memory unit in the preset memory pool.

[0068] In an application scenario, the size of a single memory unit in the preset memory pool is equal to the memory size required by a specific node. Accordingly, M can be directly determined as 1. Alternatively, the extracted target size is verified, and when it is detected that the target size is equal to the size of a single memory unit, M is determined as 1. Accordingly, 1 memory unit can be selected as the target memory unit and allocated to the first requesting node. Specifically, each time, M memory units can be selected from the unallocated memory units in ascending order of page address. In this way, the memory units can be allocated in ascending order of page address, thereby ensuring the orderliness of memory unit allocation.

[0069] Optionally, in an embodiment of the present invention, the allocating the target memory unit in the preset memory pool to the first requesting node includes: providing the first requesting node with a page pointer corresponding to the target memory unit in the preset memory pool to transfer the target memory unit to the first requesting node.

[0070] Among them, the page pointer can be the page pointer page_ptr of the page structured information (struct page*). Page_ptr can point to the structured information, and one structured information corresponds to one memory unit, that is, the page pointer points to the memory unit. The first requesting node can use the target memory unit based on the page pointer. In an embodiment of the present invention, only by providing the first requesting node with the page pointer of the target memory unit can memory allocation be realized, enabling the first requesting node to use the target memory unit and simplifying the memory allocation operation.

[0071] Specifically, the first requesting node can obtain the address of the memory page represented by the struct page structured information pointed to by the page pointer, so as to use the memory page in the target memory unit for calling based on the address of the memory page. Specifically, read and write operations can be performed after converting the page pointer into a virtual address based on a first preset conversion function. The first preset conversion function is the page_to_virt function. The first requesting node can use the page pointer of the target memory unit as the parameter of the page_to_virt function, call the page_to_virt function to convert the page pointer into a virtual address, and then receive the virtual address returned by the page_to_virt function. Accordingly, memory copy operations can be performed based on this virtual address. For example, data can be copied into the memory page pointed to by this virtual address.

[0072] In other embodiments, the page pointer can also be converted into a physical address based on a second preset conversion function. The second preset conversion function is the page_to_phys function. The first request node can use the page pointer of the target memory unit as the parameter of the page_to_phys function, call the page_to_phys function to convert the page pointer into a physical address, and then receive the physical address returned by the page_to_phys function. Accordingly, data sending and receiving operations can be performed based on this physical address. For example, in a network device driver, network data packets can be sent or received based on the converted physical address.

[0073] Optionally, the embodiments of the present invention may further include the following steps to implement memory release:

[0074] Step S31: For any one of the preset memory pools, in response to a memory release request, detect whether the second request node to which the memory release request belongs is the specific node corresponding to the preset memory pool.

[0075] Step S32: When the second request node is the specific node corresponding to the preset memory pool, release the memory unit to be released into the preset memory pool; the memory unit to be released is the memory unit indicated by the memory release request.

[0076] In the embodiments of the present invention, the second request node may be the node that triggers the memory release request. The memory release request may be triggered when the second request node needs to release the memory after completing the relevant service logic using the allocated memory. Accordingly, in response to this memory release request, the second request node of this memory release request can be detected first to determine whether the second request node is a specific node. Specifically, the node identifier in the memory release request can be extracted. For example, the content of the bit field of the parameter used to represent the node identifier in the memory release request is extracted to obtain the node identifier in the memory release request. For the memory management table of any preset memory pool, the node identifier in the memory release request is compared with each node identifier recorded in this memory management table respectively; if there is a node identifier that is the same as the node identifier in the memory release request, it is determined that the second request node is the specific node corresponding to this preset memory pool. Among them, the implementation manners of the steps for detecting the second request node can refer to the implementation manners of the steps for detecting the first request node described above, and will not be elaborated here.

[0077] Further, if it is detected that the second request node is the specific node corresponding to the preset memory pool, the memory unit indicated by the memory release request can be used as the memory unit to be released, and the memory unit to be released is released into the preset memory pool, so that the preset memory pool completes the memory recovery corresponding to the second request node.

[0078] In the embodiments of the present invention, the memory units in the preset memory pool are used by corresponding specific nodes. Correspondingly, the memory pages used by other nodes do not belong to the preset memory pool. In response to a memory release request, for any preset memory pool, it is detected whether the second request node to which the memory release request belongs is the specific node corresponding to the preset memory pool. Only when the second request node is the specific node corresponding to the preset memory pool, the memory unit to be released is released to the preset memory pool. In this way, it is possible to avoid releasing the memory pages used by other nodes (for example, the memory pages corresponding to other available memory spaces that do not belong to the preset memory pool, or the memory pages belonging to other preset memory pools) to the preset memory pool, resulting in the problem that the memory pages used by other nodes are mixed into the preset memory pool. Furthermore, it is possible to ensure the isolation of the memory pages in the preset memory pool from the memory pages used by other nodes.

[0079] Optionally, in the embodiments of the present invention, the step of releasing the memory unit to be released to the preset memory pool may specifically include:

[0080] Step S32a: Obtain the association information corresponding to the memory unit to be released.

[0081] Step S32b: When the association information indicates that the memory unit to be released belongs to the preset memory pool, release the memory unit to be released to the preset memory pool.

[0082] In the embodiments of the present invention, only when it is detected that the second request node is a specific node, the memory ownership of the memory unit to be released is further detected, that is, it is determined whether the memory unit to be released belongs to the preset memory pool. In this way, unnecessary memory ownership detection operations can be avoided, and the accuracy of memory recovery can be ensured to a greater extent. Specifically, the memory release request can be expressed as put_pool_page(node, page_ptr). Among them, the parameters carried in the memory release request are (node, page_ptr), where node represents the node identifier and page_ptr represents the page pointer of the memory unit to be released. Correspondingly, the association information corresponding to the memory unit to be released can be obtained based on the page pointer carried in the memory release request. The association information may include the page address, page size, and page flag of the memory page in the memory unit. Correspondingly, based on the above first preset conversion function, the page pointer can be converted into a virtual address to obtain the page address. Then, the memory size represented by the page address is determined. At the same time, the page flag stored in the structured information pointed to by the page pointer can be read.

[0083] Exemplarily, the page pointer page_ptr carried in the memory release request can be used as the input of the page_to_virt function to convert page_ptr into a virtual address, that is, the output of the page_to_virt function is used as the page address. Assume that the page address output by the page_to_virt function is 0x1000 to 0x2000. The memory size represented by this page address is: 0x2000 - 0x1000 = 0x1000. Further, the page flag can be read from the structured information pointed to by the page pointer through keyword matching. Exemplarily, "unit-flag" can be used as the keyword to match the structured information pointed to by the page pointer, and the specific value of unit-flag can be extracted to obtain the stored page flag.

[0084] If the page address belongs to the page address range of the preset memory pool, the memory size is consistent with the size of the memory unit in the preset memory pool, and the page flag belongs to the page identifier of the memory unit in the preset memory pool, it can be determined that the memory unit related information indicates that the memory unit to be released belongs to the preset memory pool. Correspondingly, the memory unit to be released can be released to the preset memory pool through the memory release function, and the first preset identifier can be returned to indicate success. Specifically, the correspondence including the node identifier of the second request node and the unit identifier of the memory unit to be released can be deleted from the memory management table of the preset memory pool. In this way, the memory unit to be released will be regarded as an unallocated memory unit and participate in memory allocation again subsequently. Otherwise, it can be determined that the memory unit related information indicates that the memory unit to be released does not belong to the preset memory pool, and correspondingly, error handling can be performed. For example, an error message can be printed through the memory release interface, and the second preset identifier can be returned. The first preset identifier and the second preset identifier can be set according to actual needs. Exemplarily, the first preset identifier and the second preset identifier can be 0 and -1 respectively.

[0085] In the embodiment of the present invention, after the memory is used up, in response to the memory release request sent by the second request node, the memory unit to be released is correspondingly released back to the preset memory pool. In this way, the memory unit can be directly reused subsequently, ensuring that there are sufficient memory units in the preset memory pool for specific nodes to use and meeting the memory usage requirements of specific nodes. At the same time, by further detecting when releasing the memory, only when the memory unit related information indicates that the memory unit to be released belongs to the preset memory pool, the memory unit to be released is released to the preset memory pool, which can further ensure that the released memory unit belongs to the preset memory pool and avoid the problem of incorrect release.

[0086] Optionally, in the embodiments of the present invention, the memory application request is a first call request to the memory application interface, and the memory release request is a second call request to the memory release interface; the memory application interface and the memory release interface are pre-set when the preset memory pool is initialized. In this way, the memory units in the preset memory pool can be conveniently applied / released. Specifically, the memory application interface can be the get_pool_page interface, and the memory release interface can be the put_pool_page interface. The implementation codes of the memory application interface and the memory release interface can be pre-set by developers, and the implementation codes of the memory application interface and the memory release interface are installed in the electronic device, thereby facilitating the use of users. Memory can be applied from the preset memory pool by calling the get_pool_page interface, and then read / write operations can be performed on the applied memory. The memory that is no longer used is released back to the preset memory pool by calling the put_pool_page interface. Dedicated memory application interfaces and memory release interfaces are provided for the preset memory pool to quickly implement memory application and release.

[0087] The following is an exemplary description in combination with the running process of device driver X. Among them, by comparing the node identifier of device driver X with the node identifiers recorded in the memory management table of the preset memory pool, it is detected that device driver X belongs to a specific node. The running process may include:

[0088] Step a, Device driver X is initialized based on the initialization function. For example, operations such as registering the device and initializing the data structure are performed. Exemplarily, the initialization function can be device_driver_init().

[0089] Step b, When device driver X needs to use memory, device driver X triggers a memory application request to apply for memory. For example, it triggers a first call request (get_pool_page(node, size)) to the memory application interface and calls the get_pool_page interface corresponding to the preset memory pool. Correspondingly, based on the get_pool_page interface, the page pointer page_ptr corresponding to the target memory unit can be returned to this device driver X, so as to use the target memory unit allocated by the preset memory pool.

[0090] Step c: Device driver X uses the target memory unit based on the page pointer. Specifically, the page_to_virt function can be used to convert the page pointer page_ptr into a virtual address, and device driver X can use the returned virtual address to read and write data. Further, in order to send data from device driver X to the hardware device or receive data from the hardware device, device driver X can call the function: page_to_phys(page_ptr) to convert the page pointer into a physical address for data sending and receiving operations. Here, page_ptr in page_to_phys(page_ptr) represents the parameter of this function.

[0091] Step d: After use (for example, after completing a data reception or data transmission using the target memory unit), device driver X triggers a memory release request to the preset memory pool. For example, it triggers a second call request to the memory release interface: (put_pool_page(node, page_ptr)), and calls the put_pool_page interface to release the previously allocated target memory unit for subsequent reuse. If the release is successful, 0 can be returned; if the release fails, an error message is printed and -1 is returned. Further, when device driver X receives a new read / write request, it can jump back to step b to start a new round of memory allocation - memory use - memory release loop, so as to continue to allocate and recycle memory for device driver X.

[0092] Figure 2 is a schematic diagram of a processing flow provided by an embodiment of the present invention. As Figure 2 shown, system initialization can be performed first, and then a memory pool is created to obtain the preset memory pool. Next, a memory management table of the preset memory pool can be generated. Correspondingly, the memory application interface and memory release interface corresponding to each node can also be exported for subsequent sending of corresponding memory application requests and memory release requests. Exemplarily, the implementation codes of the memory application interface and memory release interface added to the code of the electronic device can be compiled to facilitate node calls. Correspondingly, a specific node can apply for memory, use memory, and apply for memory release from the preset memory pool. Specifically, when applying for memory release, it can be determined whether the memory unit to be released belongs to the preset memory pool based on the memory management table, that is, it is detected whether the second request node belongs to the specific node and whether the memory unit to be released belongs to the preset memory pool. If so, the memory unit to be released can be released to the preset memory pool. Otherwise, an error message can be output.

[0093] Referring to Figure 3 , a block diagram of a memory management device provided by an embodiment of the present invention is shown. As Figure 3 shown, the memory management device may specifically include:

[0094] The first detection module 201 is configured to detect a first request node to which the memory application request belongs in response to a memory application request;

[0095] The selection module 202 is configured to, when it is detected that the first request node is a specific node corresponding to a preset memory pool, select M memory units from the preset memory pool as target memory units according to the memory application request; M is a positive integer;

[0096] The allocation module 203 is configured to allocate the target memory units in the preset memory pool to the first request node for the first request node to use.

[0097] Optionally, the preset memory pool is created by the following modules:

[0098] The acquisition module is configured to acquire the number of memory pages required when the specific node applies for memory and the total size of the preset memory pool;

[0099] The creation module is configured to create the memory units based on the number of memory pages, the single-page size of the operating system, and the total size of the memory pool to obtain the preset memory pool; wherein the size of each single memory unit is an integer multiple of the single-page size of the operating system.

[0100] Optionally, the first detection module 201 is specifically configured to:

[0101] Extract the node identifier in the memory application request as the target identifier; the node identifier is used to represent the first request node;

[0102] Compare the target identifier with each node identifier respectively recorded in the memory management table of the preset memory pool;

[0103] If there is a node identifier that is the same as the target identifier, it is determined that the first request node belongs to a specific node.

[0104] Optionally, the selection module 202 is specifically configured to:

[0105] Analyze the target size corresponding to the applied memory in the memory application request;

[0106] Select M unallocated memory units from the preset memory pool as the target memory units based on the target size; the total size of the M unallocated memory units is equal to the target size;

[0107] The allocation module 203 is specifically configured to provide the first requesting node with a page pointer corresponding to the target memory unit in the preset memory pool, so as to transfer the target memory unit to the first requesting node.

[0108] Optionally, the device further comprises:

[0109] A second detection module is used for detecting, for any of the preset memory pools, in response to a memory release request, whether a second requesting node to which the memory release request belongs is a specific node corresponding to the preset memory pool;

[0110] A release module is used to release the memory unit to be released to the preset memory pool when the second requesting node is a specific node corresponding to the preset memory pool; the memory unit to be released is the memory unit indicated by the memory release request.

[0111] Optionally, the release module is specifically used to:

[0112] Obtaining association information corresponding to the memory unit to be released;

[0113] When the association information indicates that the memory unit to be released belongs to the preset memory pool, the memory unit to be released is released to the preset memory pool.

[0114] Optionally, the memory application request is a first call request to a memory application interface, and the memory release request is a second call request to a memory release interface;

[0115] The memory application interface and the memory release interface are preset when the preset memory pool is initialized.

[0116] In summary, in the memory management device provided by the embodiment of the present invention, in response to a memory application request, the first request node to which the memory application request belongs is detected. In the case where it is detected that the first request node is a specific node corresponding to the preset memory pool, that is, in the case where the specific node applies for memory through the memory application request, M memory units are selected from the preset memory pool as target memory units according to the memory application request, where M is a positive integer. The target memory unit in the preset memory pool is allocated to the first request node for use by the first request node. Since the preset memory pool is used after the specific node requests it, and the memory size requested by the specific node is an integer multiple of the size of the memory unit in the preset memory pool, that is, the memory granularity required by the specific node is an integer multiple of the memory granularity provided in the preset memory pool. Therefore, directly selecting one or more memory units from the preset memory pool can meet the use requirements of the specific node, thereby improving the memory management efficiency in specific scenarios such as a driver or subsystem using a small amount of memory frequently.

[0117] ReferenceFigure 4 , which is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. As Figure 4 shown, the electronic device includes: a processor, a memory, a communication interface, and a communication bus.

[0118] The processor, the memory, and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction causes the processor to execute the memory management method of the foregoing embodiment. The executable instructions can form a program.

[0119] An embodiment of the present invention provides a machine-readable medium, on which instructions are stored, and when executed by one or more processors, enable the processors to execute the memory management method of the foregoing embodiment.

[0120] Each embodiment in this specification is described in a progressive manner. The key point of each embodiment is to illustrate the differences from other embodiments. The same or similar parts among the embodiments can be referred to each other.

[0121] Those skilled in the art should understand that the embodiments of the present invention can be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention can take the form of completely hardware embodiments, completely software embodiments, or embodiments combining software and hardware aspects. Moreover, the embodiments of the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program codes.

[0122] It should be noted that all actions of obtaining signals, information, or data in this application are carried out on the premise of complying with the corresponding data protection regulations and policies of the country where it is located and obtaining the authorization given by the owner of the corresponding device.

[0123] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, and the combination of processes and / or blocks in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to the processors of general-purpose computers, special-purpose computers, embedded processors, or other programmable data processing terminal devices to generate a machine, so that the instructions executed by the processors of the computer or other programmable data processing terminal devices generate means for implementing the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.

[0124] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal device to work in a predictive manner, such that the instructions stored in the computer-readable memory produce a manufacture including an instruction device that implements the functions specified in one process Figure 1 or a plurality of processes and / or blocks Figure 1 specified in one block or a plurality of blocks.

[0125] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device, such that a series of operational steps are performed on the computer or other programmable terminal device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable terminal device provide steps for implementing the functions specified in one process Figure 1 or a plurality of processes and / or blocks Figure 1 specified in one block or a plurality of blocks.

[0126] Although the preferred embodiments of the embodiments of the present invention have been described, those skilled in the art can make additional changes and modifications once they learn the basic creative concept. Therefore, the appended claims are intended to be construed to include the preferred embodiments and all changes and modifications falling within the scope of the embodiments of the present invention.

[0127] Finally, it should also be noted that in this text, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations.

[0128] Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or terminal device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or terminal device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or terminal device comprising the element.

[0129] The above has introduced in detail a memory management method, a memory management device, an electronic device and one or more readable media provided by the present invention. Specific examples are used in this text to elaborate on the principles and implementation manners of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention; at the same time, for those of ordinary skill in the art, according to the idea of the present invention, there will be changes in the specific implementation manners and application scopes. In summary, the content of this specification should not be construed as a limitation to the present invention.

Claims

1. A memory management method, characterized in that: The method comprises: In response to a memory application request, detecting a first requesting node to which the memory application request belongs; In the case where it is detected that the first requesting node is a specific node corresponding to a preset memory pool, M memory units are selected from the preset memory pool as target memory units according to the memory application request; M is a positive integer; The target memory unit in the preset memory pool is allocated to the first requesting node for use by the first requesting node.

2. The method according to claim 1, characterized in that The preset memory pool is created in the following way: Obtaining the number of memory pages required by the specific node for memory application and the total size of the preset memory pool; Based on the number of memory pages, the single page size of the operating system and the total size of the memory pool, the memory unit is created to obtain the preset memory pool; The size of the single memory unit is an integer multiple of the single page size of the operating system.

3. The method according to claim 1, characterized in that The detecting the first requesting node to which the memory application request belongs includes: Extracting a node identifier in the memory application request as a target identifier; the node identifier is used to represent the first requesting node; Compare the target identifier with the node identifiers respectively recorded in the memory management table of the preset memory pool; If there is a node identifier that is consistent with the target identifier, it is determined that the first requesting node is a specific node.

4. The method according to claim 1, characterized in that: The selecting M memory units from the preset memory pool as target memory units according to the memory application request includes: Analyze the target size of the memory requested in the memory request; Selecting M unallocated memory units from the preset memory pool as the target memory units based on the target size; the total size of the M unallocated memory units is equal to the target size; Then, allocating the target memory unit in the preset memory pool to the first requesting node includes: A page pointer corresponding to the target memory unit in the preset memory pool is provided to the first requesting node to transfer the target memory unit to the first requesting node.

5. The method according to claim 1, characterized in that: The method further comprises: For any of the preset memory pools, in response to a memory release request, detecting whether a second requesting node to which the memory release request belongs is a specific node corresponding to the preset memory pool; In the case where the second requesting node is a specific node corresponding to the preset memory pool, the memory unit to be released is released to the preset memory pool; the memory unit to be released is the memory unit indicated by the memory release request.

6. The method according to claim 5, characterized in that The step of releasing the memory unit to be released to the preset memory pool includes: Obtaining association information corresponding to the memory unit to be released; When the association information indicates that the memory unit to be released belongs to the preset memory pool, the memory unit to be released is released to the preset memory pool.

7. The method according to claim 5, characterized in that The memory application request is a first call request for a memory application interface, and the memory release request is a second call request for a memory release interface; The memory application interface and the memory release interface are preset when the preset memory pool is initialized.

8. A memory management device, characterized in that: The device comprises: A first detection module, configured to detect, in response to a memory application request, a first requesting node to which the memory application request belongs; A selection module, configured to select M memory units from the preset memory pool as target memory units according to the memory application request when it is detected that the first requesting node is a specific node corresponding to the preset memory pool; wherein M is a positive integer; An allocation module is used to allocate the target memory unit in the preset memory pool to the first requesting node for use by the first requesting node.

9. An electronic device, characterized in that: include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store executable instructions, and the executable instructions enable the processor to execute the device according to any one of claims 1 to 7.

10. One or more machine-readable media, characterized in that Instructions are stored thereon, which, when executed by one or more processors, cause the processors to execute the device according to any one of claims 1 to 7.