Memory management method, electronic device, and readable storage medium
By introducing the interleaved mapping relationship between interleaved memory and affinity memory in the dual-end memory allocation system, memory allocation conflict detection is performed, which solves the problem of low memory management efficiency and achieves more efficient memory access and management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MOFFETT AI TECHNOLOGY SHENZHEN CO LTD
- Filing Date
- 2026-03-02
- Publication Date
- 2026-05-26
AI Technical Summary
In a dual-end memory allocation system, the management mechanisms of interleaved memory and linear memory are independent of each other, lacking dynamic memory allocation conflict detection and mutual exclusion verification mechanisms, resulting in low memory management efficiency.
By designing an interleaved mapping relationship between interleaved memory and multiple affinity memories, and combining the current allocated memory size of interleaved memory and affinity memory to detect memory allocation conflicts, global and dynamic management of memory allocation is achieved.
It improves memory access speed, avoids memory allocation failures and subsequent memory access blockages, and enhances memory management efficiency.
Smart Images

Figure CN121764689B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a memory management method, an electronic device, and a readable storage medium. Background Technology
[0002] In the current dual-end memory allocation system, the management mechanisms of interleaved memory and linear memory are independent of each other. Due to the lack of dynamic memory allocation conflict detection and mutual exclusion verification mechanisms, the memory management efficiency is low. Summary of the Invention
[0003] This application provides a memory management method, an electronic device, and a readable storage medium that can improve memory management efficiency.
[0004] To solve the above-mentioned technical problems, this application is implemented as follows:
[0005] In a first aspect, a memory management method is provided, applied to a memory management system, the memory management system including interleaved memory and multiple affinity memory, wherein the interleaved memory and each affinity memory have an interleaved mapping relationship, the method comprising: determining an object to be allocated and a size of memory to be allocated according to a memory allocation request, wherein the object to be allocated is interleaved memory or any affinity memory; performing memory allocation conflict detection on the size of the memory to be allocated according to the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and the currently allocated memory corresponding to at least one of the affinity memories; and, in response to passing the memory allocation conflict detection, performing a memory allocation operation on the object to be allocated according to the size of the memory to be allocated.
[0006] Secondly, a memory management device is provided, comprising: a determining module, configured to determine an object to be allocated and a size of memory to be allocated based on a memory allocation request, wherein the object to be allocated is interleaved memory or any affinity memory; a detecting module, configured to perform memory allocation conflict detection on the size of memory to be allocated based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and at least one currently allocated memory corresponding to the affinity memory; and an allocating module, configured to perform a memory allocation operation on the object to be allocated based on the size of memory to be allocated in response to the memory allocation conflict detection passing.
[0007] Thirdly, an electronic device is provided, including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the method described in the first aspect.
[0008] Fourthly, a readable storage medium is provided, on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.
[0009] Fifthly, a computer program product is provided, the computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions that, when executed by a computer, cause the computer to perform the steps of the method described in the first aspect.
[0010] In this embodiment, the object to be allocated and the size of the memory to be allocated are determined according to the memory allocation request. The object to be allocated is interleaved memory or any affinity memory. Interleaved memory has an interleaved mapping relationship with each affinity memory. Based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and the currently allocated memory corresponding to at least one affinity memory, memory allocation conflict detection is performed on the size of the memory to be allocated. In response to the memory allocation conflict detection passing, memory allocation operation is performed on the object to be allocated according to the size of the memory to be allocated. By designing interleaved memory and affinity memory and establishing the interleaved mapping relationship between interleaved memory and multiple affinity memories, the memory access speed can be improved. At the same time, when performing memory allocation, memory allocation conflict detection is performed based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and the currently allocated memory corresponding to at least one affinity memory. This realizes global and dynamic management of dual-end memory allocation, effectively avoiding memory allocation failure and subsequent memory access obstruction caused by memory allocation conflicts, thereby improving memory management efficiency.
[0011] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description
[0012] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0013] Figure 1 One of the flowcharts of the memory management method provided in the embodiments of this application is shown;
[0014] Figure 2 This illustration shows an interleaving mapping diagram provided in an embodiment of this application;
[0015] Figure 3 A second schematic flowchart of the memory management method provided in an embodiment of this application is shown;
[0016] Figure 4One of the schematic diagrams of memory allocation provided in the embodiments of this application is shown;
[0017] Figure 5 This is a second schematic diagram of memory allocation provided in an embodiment of this application;
[0018] Figure 6 The third schematic diagram of memory allocation provided in the embodiments of this application is shown;
[0019] Figure 7 The fourth illustration shows a schematic diagram of memory allocation provided in an embodiment of this application;
[0020] Figure 8 One of the schematic diagrams of memory release provided in the embodiments of this application is shown;
[0021] Figure 9 This is a second schematic diagram illustrating memory release provided in an embodiment of this application;
[0022] Figure 10 The third illustration shows a memory release diagram provided in an embodiment of this application;
[0023] Figure 11 This paper shows a schematic diagram of a memory management device provided in an embodiment of the present application;
[0024] Figure 12 A schematic diagram of the structure of an electronic device provided in an embodiment of this application is shown. Detailed Implementation
[0025] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0026] Figure 1 This illustration shows a flowchart of a memory management method provided in an embodiment of this application. The method is applied to a memory management system, which includes interleaved memory and multiple affinity memories. The interleaved memory and each affinity memory have an interleaved mapping relationship. Interleaved memory is a memory unit that maps memory addresses to different affinity memories. Affinity memory is physical memory with an affinity relationship to the kernel. It can be understood that interleaved memory corresponds to a logical address space, and affinity memory corresponds to a physical address space. This interleaved mapping relationship is used to indicate the mutual mapping relationship between the logical address space corresponding to the interleaved memory and the physical address space corresponding to the affinity memory, that is, the mutual mapping relationship between logical addresses and physical addresses. For example, as shown... Figure 2 As shown, assuming that a virtual memory block with a base address of 0x3_00_0000_0000 and a size of 4KB is allocated from interleaved memory, it is equivalent to allocating a physical memory block with a base address of 0x2_28_0000_0000 and a size of 1KB from affinity memory 0, allocating a physical memory block with a base address of 0x2_68_0000_0000 and a size of 1KB from affinity memory 1, allocating a physical memory block with a base address of 0x2_a8_0000_0000 and a size of 1KB from affinity memory 2, and allocating a physical memory block with a base address of 0x2_e8_0000_0000 and a size of 1KB from affinity memory 3. In this embodiment, by designing the logical address space corresponding to interleaved memory and the physical address space corresponding to affinity memory, user-mode memory access and kernel-mode memory access can be distinguished. This allows for the actual access of multiple affinity memory blocks during user-mode memory access, improving access efficiency and avoiding the situation of accessing only a single affinity memory block, thus improving memory utilization. During kernel-mode memory access, both interleaved and affinity memory can be accessed, and the principle of locality of reference can determine which type of memory to access, improving access speed and memory utilization.
[0027] In some embodiments, each affinity memory has the same memory size.
[0028] In some embodiments, the size of the interleaved memory is the sum of the sizes of all affinity memories.
[0029] Figure 1 The method shown may include the following steps:
[0030] S110: Determine the object to be allocated and the size of the memory to be allocated based on the memory allocation request.
[0031] The object to be allocated is either interleaved memory or any affinity memory, and the interleaved memory has an interleaved mapping relationship with each of the affinity memories.
[0032] In some embodiments, S110 may include:
[0033] S102: Receive a memory allocation request sent by the target object.
[0034] The memory allocation request includes the requested memory size.
[0035] S104: In response to the target object being a user-mode process, determine that the object to be allocated is interleaved memory; or, in response to the target object being an operating system kernel, determine that the object to be allocated is any affinity memory.
[0036] S106: The requested memory size is determined as the memory size to be allocated.
[0037] S120: Based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and at least one currently allocated memory corresponding to the affinity memory, perform memory allocation conflict detection on the size of the memory to be allocated.
[0038] It is understandable that interleaved memory allocation maps virtual addresses to multiple independent affinity memories to achieve parallel access. Affinity memory allocation is performed on a contiguous address space basis. Therefore, allocation conflicts may exist between affinity memory allocation and interleaved memory allocation. Thus, allocation conflict checks are necessary during memory allocation to avoid conflicts. If the object to be allocated is any affinity memory, a contiguous address space will be allocated. If the allocatable memory corresponding to the interleaved memory cannot meet the size of the memory to be allocated, the memory allocation will fail. Similarly, if the object to be allocated is interleaved memory, the address mapping rules of interleaved memory will distribute contiguous addresses to different affinity memories. During memory interleaving mapping, if the allocatable memory corresponding to each affinity memory cannot meet the average size of the memory to be allocated, the memory allocation will also fail. Therefore, to avoid memory allocation conflicts, memory allocation conflict detection can be performed on the size of the memory to be allocated based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and the currently allocated memory corresponding to at least one affinity memory.
[0039] S130: In response to the passing of the memory allocation conflict detection, perform a memory allocation operation on the object to be allocated according to the size of the memory to be allocated.
[0040] In some embodiments, the memory allocation operation on the object to be allocated is performed according to the size of the memory to be allocated, including: performing the memory allocation operation on the object to be allocated according to the first-adaptive memory allocation strategy.
[0041] In this embodiment, the object to be allocated and the size of the memory to be allocated are determined according to the memory allocation request. The object to be allocated is interleaved memory or any affinity memory. Interleaved memory has an interleaved mapping relationship with each affinity memory. Based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and the currently allocated memory corresponding to at least one affinity memory, memory allocation conflict detection is performed on the size of the memory to be allocated. In response to the memory allocation conflict detection passing, memory allocation operation is performed on the object to be allocated according to the size of the memory to be allocated. By designing interleaved memory and affinity memory and establishing the interleaved mapping relationship between interleaved memory and multiple affinity memories, the memory access speed can be improved. At the same time, when performing memory allocation, memory allocation conflict detection is performed based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and the currently allocated memory corresponding to at least one affinity memory. This realizes global and dynamic management of dual-end memory allocation, effectively avoiding memory allocation failure and subsequent memory access obstruction caused by memory allocation conflicts, thereby improving memory management efficiency.
[0042] In some embodiments, in response to the object to be allocated being any of the affinity memory, the currently allocated memory corresponding to at least one of the affinity memory includes the currently allocated memory corresponding to the object to be allocated; the above S120 may include:
[0043] S122: Determine the first memory size based on the currently allocated memory corresponding to the interleaved memory, the currently allocated memory corresponding to the object to be allocated, and the affinity memory size.
[0044] S124: In response to the first memory size being less than or equal to the memory size to be allocated, determine that the memory allocation conflict detection fails; or, in response to the first memory size being greater than the memory size to be allocated, determine that the memory allocation conflict detection passes.
[0045] It is understandable that if the object to be allocated is affinity memory, then at least one currently allocated memory corresponding to affinity memory includes the currently allocated memory corresponding to that affinity memory. In other words, the first memory size is determined based on the currently allocated memory corresponding to the interleaved memory, the currently allocated memory corresponding to the affinity memory, and the size of the affinity memory.
[0046] Further, in some embodiments, S122 may include: determining the first memory size as the difference between the affinity memory size and a first value, wherein the first value is the sum of a second value and the currently allocated memory corresponding to the object to be allocated, the second value is the ratio of the currently allocated memory corresponding to the interleaved memory to a third value, and the third value is the quantity of affinity memory.
[0047] For example, the first memory size can be determined by the following formula:
[0048]
[0049] in, Indicates the first memory size; Indicates the affinity memory size; Indicates the first value. Indicates the second value. This represents the currently allocated memory corresponding to interleaved memory, where n represents the third value, i.e., the amount of affinity memory. This indicates the currently allocated memory corresponding to the object to be allocated.
[0050] In this embodiment, the second value is... This is used to represent the size of the interleaved memory that is currently mapped to this affinity memory. This represents the currently allocated memory for the affinity memory. Therefore, by subtracting the size of the currently mapped interleaved memory from the size of the affinity memory, and then subtracting the currently allocated memory, the remaining allocatable memory space, i.e., the first memory size, can be determined. If the first memory size is less than or equal to the size of the memory to be allocated, the memory allocation conflict detection is determined to fail; if the first memory size is greater than the size of the memory to be allocated, the memory allocation conflict detection is determined to pass.
[0051] It should be noted that the currently allocated memory does not include mapped memory. In other words, the currently allocated memory corresponding to interleaved memory does not include the memory size of affinity memory mapped to the interleaved memory, and the currently allocated memory corresponding to affinity memory does not include the memory size of interleaved memory mapped to the affinity memory. This will not be elaborated further.
[0052] In some embodiments, in response to the object to be allocated being the interleaved memory, the currently allocated memory corresponding to at least one of the affinity memories includes the currently allocated memory corresponding to each of the affinity memories;
[0053] The above-mentioned S120 may include:
[0054] S126: Determine the second memory size based on the currently allocated memory corresponding to the interleaved memory, the affinity memory size, and the currently allocated memory corresponding to each affinity memory;
[0055] S128: In response to the second memory size being less than or equal to the memory size to be allocated, determine that the memory allocation conflict detection fails; or, in response to the second memory size being greater than the memory size to be allocated, determine that the memory allocation conflict detection passes.
[0056] It is understandable that if the object to be allocated is interleaved memory, then the currently allocated memory corresponding to at least one affinity memory includes the currently allocated memory corresponding to each affinity memory. That is, the first memory size is determined based on the currently allocated memory corresponding to the interleaved memory, the currently allocated memory corresponding to each affinity memory, and the size of the affinity memory.
[0057] Furthermore, in some other embodiments, determining the second memory size based on the currently allocated memory corresponding to the interleaved memory, the affinity memory size, and the currently allocated memory corresponding to each affinity memory includes: determining the second memory size as the difference between a fourth value and a fifth value, wherein the fourth value is the product of the affinity memory size and a third value, the fifth value is the sum of the currently allocated memory corresponding to the interleaved memory and a sixth value, the sixth value is the product of a seventh value and the third value, the seventh value is the maximum value among the currently allocated memory corresponding to multiple affinity memories, and the third value is the number of affinity memories.
[0058] For example, the second memory size can be determined by the following formula:
[0059]
[0060] in, Indicates the second memory size; This indicates the fourth value, which represents the size of the interleaved memory. This indicates the affinity memory size, and n represents the third value, namely the amount of affinity memory. Indicates the fifth value. This indicates the currently allocated memory corresponding to the interleaved memory. Indicates the sixth value. This represents the seventh value, which corresponds to the maximum value in the currently allocated memory among the n affinity memory values. This represents the currently allocated memory corresponding to the i-th affinity memory.
[0061] In this embodiment, the fourth value is... Used to represent the size of interleaved memory. This represents the currently allocated memory of the interleaved memory. Therefore, by subtracting the currently allocated memory of the interleaved memory from its size, we obtain the allocatable memory corresponding to the interleaved memory. Then, by subtracting the sixth value from the allocatable memory, we obtain... This verifies whether the allocatable memory corresponding to the interleaved memory can satisfy the peak mapping of n affinity memories.
[0062] In some embodiments, the memory allocation operation on the object to be allocated based on the size of the memory to be allocated may include the following steps:
[0063] Step 1: According to the memory allocation strategy corresponding to the object to be allocated, query the free memory list corresponding to the object to be allocated to find the target free memory block that meets the size of the memory to be allocated.
[0064] It is understandable that affinity memory and interleaved memory can correspond to different memory allocation strategies, so it is necessary to find the target free memory block according to the corresponding memory allocation strategy.
[0065] In some other embodiments, the step of querying the free memory list corresponding to the object to be allocated, according to the memory allocation strategy corresponding to the object to be allocated, to find a target free memory block that meets the size of the memory to be allocated includes: in response to the object to be allocated being any of the affinity memory, searching the free memory list from low address to high address for the target free memory block; or, in response to the object to be allocated being the interleaved memory, searching the free memory list from high address to low address for the target free memory block.
[0066] It is understood that the dual-end memory allocation strategy of this application is as follows: affinity memory is allocated from low address to high address, while interleaved memory is allocated from high address to low address, in order to avoid possible allocation conflicts between affinity memory allocation and interleaved memory allocation. Therefore, for affinity memory, the target free memory block is searched from low address to high address in the corresponding free memory list; for interleaved memory, the target free memory block is searched from high address to low address in the corresponding free memory list.
[0067] Step 2: In response to the free memory list including the target free memory block, memory allocation is performed in the target free memory block based on the size of the memory to be allocated.
[0068] In some embodiments, such as Figure 3 As shown, the memory allocation operation for the object to be allocated, based on the size of the memory to be allocated, may include the following steps:
[0069] S310: Input target parameters, including the size of the memory to be allocated.
[0070] S320: Determine whether the target parameters are compliant.
[0071] If compliant, proceed to S330; otherwise, the process ends.
[0072] S330: Determine whether the first available free memory node has been found in the free memory linked list.
[0073] If yes, proceed to S340; otherwise, end.
[0074] S340: Allocate memory within a free memory block based on the size of the memory to be allocated.
[0075] S350: Update the free memory list.
[0076] S360: Returns information about the allocated memory block.
[0077] For example, such as Figure 4 As shown, the free memory list includes four free memory blocks: Block1, Block2, Block3, and Block4. Block1 corresponds to 10KB of memory, Block2 to 20KB, Block3 to 25KB, and Block4 to 6KB. Assuming the memory to be allocated is 15KB, the first available free memory node is Block2, and 15KB of memory space is allocated within Block2. After memory allocation, the free memory list is updated.
[0078] In some embodiments, after allocating memory based on the size of the memory to be allocated within the target free memory block, the method further includes one of the following:
[0079] (1) In response to the object to be allocated being the interleaved memory, the currently allocated memory corresponding to the interleaved memory is updated based on the size of the memory to be allocated, and the size of the memory to be allocated is sequentially mapped to the high address space corresponding to the multiple affinity memories in a cyclic interleaving manner.
[0080] For example, if the object to be allocated is interleaved memory, then after memory allocation is completed, such as Figure 5 As shown, update the currently allocated memory corresponding to this interleaved memory, i.e. ,in, Indicates the size of the memory to be allocated. This represents the currently allocated memory corresponding to the interleaved memory; and the size of the memory to be allocated is sequentially mapped to the high address space corresponding to multiple affinity memories in a cyclic interleaving manner, for example, as follows Figure 6 As shown, assuming the size of the memory to be allocated is 16KB and there are 4 affinity memory locations, then 4KB of memory will be allocated in the high address space corresponding to each affinity memory location.
[0081] (2) In response to the object to be allocated being any of the affinity memory, update the currently allocated memory corresponding to the affinity memory based on the size of the memory to be allocated, and map the size of the memory to be allocated to the low address space corresponding to the interleaved memory.
[0082] For example, such as Figure 7As shown, assuming the size of the memory to be allocated is 16KB, if the object to be allocated is the first affinity memory among multiple affinity memory locations, then after the memory allocation is completed, the currently allocated memory corresponding to this first affinity memory location is updated, that is... ,in, Indicates the size of the memory to be allocated. This indicates the currently allocated memory corresponding to the first affinity memory; and the size of the memory to be allocated is mapped to the low address space corresponding to the interleaved memory, so 16KB of memory is allocated in the low address space corresponding to the interleaved memory.
[0083] In some embodiments, this application also provides a memory release method, which may include: according to the size of the memory to be released, querying the corresponding free memory list for at least one free memory block adjacent to the memory block corresponding to the size of the memory to be released; if a match is found, merging the at least one free memory block with the memory block corresponding to the size of the memory to be released into one free memory block, and updating the free memory list. For example, as shown... Figure 8 and Figure 9 As shown. If no match is found, the memory block corresponding to the size of the memory to be released is added as a separate free memory block to the free memory list, and the free memory list is updated. For example, as shown... Figure 10 As shown.
[0084] Figure 11 This invention provides a schematic diagram of the structure of a memory management device according to an embodiment of the present application, as shown below. Figure 11 As shown, the memory management device 1100 may include: a determination module 1110, a detection module 1120, and an allocation module 1130.
[0085] In this embodiment, the determining module 1110 is used to determine the object to be allocated and the size of the memory to be allocated according to the memory allocation request, wherein the object to be allocated is interleaved memory or any affinity memory; the detecting module 1120 is used to perform memory allocation conflict detection on the size of the memory to be allocated based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and at least one currently allocated memory corresponding to the affinity memory; the allocating module 1130 is used to perform memory allocation operation on the object to be allocated according to the size of the memory to be allocated in response to the memory allocation conflict detection passing.
[0086] In some embodiments, in response to the object to be allocated being any of the affinity memory, the currently allocated memory corresponding to at least one of the affinity memory includes the currently allocated memory corresponding to the object to be allocated; the detection module 1120 performs memory allocation conflict detection on the size of the memory to be allocated based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and the currently allocated memory corresponding to at least one of the affinity memory, including: determining a first memory size based on the currently allocated memory corresponding to the interleaved memory, the currently allocated memory corresponding to the object to be allocated, and the size of the affinity memory; in response to the first memory size being less than or equal to the size of the memory to be allocated, determining that the memory allocation conflict detection fails, or in response to the first memory size being greater than the size of the memory to be allocated, determining that the memory allocation conflict detection passes.
[0087] In some embodiments, the detection module 1120 determines a first memory size based on the currently allocated memory corresponding to the interleaved memory, the currently allocated memory corresponding to the object to be allocated, and the affinity memory size, including: determining the first memory size as the difference between the affinity memory size and a first value, wherein the first value is the sum of a second value and the currently allocated memory corresponding to the object to be allocated, the second value is the ratio of the currently allocated memory corresponding to the interleaved memory to a third value, and the third value is the quantity of affinity memory.
[0088] In some embodiments, in response to the object to be allocated being the interleaved memory, the currently allocated memory corresponding to the at least one affinity memory includes the currently allocated memory corresponding to each affinity memory; the detection module 1120 performs memory allocation conflict detection on the size of the memory to be allocated based on the currently allocated memory corresponding to the interleaved memory, the affinity memory size, and the currently allocated memory corresponding to at least one affinity memory, including: determining a second memory size based on the currently allocated memory corresponding to the interleaved memory, the affinity memory size, and the currently allocated memory corresponding to each affinity memory; in response to the second memory size being less than or equal to the size of the memory to be allocated, determining that the memory allocation conflict detection fails, or in response to the second memory size being greater than the size of the memory to be allocated, determining that the memory allocation conflict detection passes.
[0089] In some embodiments, the detection module 1120 determines a second memory size based on the currently allocated memory corresponding to the interleaved memory, the affinity memory size, and the currently allocated memory corresponding to each affinity memory, including: determining the second memory size as the difference between a fourth value and a fifth value, wherein the fourth value is the product of the affinity memory size and a third value, the fifth value is the sum of the currently allocated memory corresponding to the interleaved memory and a sixth value, the sixth value is the product of a seventh value and the third value, the seventh value is the maximum value among the currently allocated memory corresponding to multiple affinity memories, and the third value is the number of affinity memories.
[0090] In some embodiments, the allocation module 1130 performs a memory allocation operation on the object to be allocated according to the size of the memory to be allocated, including: querying a target free memory block that meets the size of the memory to be allocated in the free memory list corresponding to the object to be allocated, according to the memory allocation strategy corresponding to the object to be allocated; and in response to the free memory list including the target free memory block, performing memory allocation in the target free memory block based on the size of the memory to be allocated.
[0091] In some embodiments, the allocation module 1130 queries the free memory list corresponding to the object to be allocated, according to the memory allocation strategy corresponding to the object to be allocated, to find a target free memory block that meets the size of the memory to be allocated, including: in response to the object to be allocated being any of the affinity memory, searching the free memory list from low address to high address for the target free memory block; or, in response to the object to be allocated being the interleaved memory, searching the free memory list from high address to low address for the target free memory block.
[0092] In some embodiments, the allocation module 1130 is further configured to: in response to the object to be allocated being the interleaved memory, update the currently allocated memory corresponding to the interleaved memory based on the size of the memory to be allocated, and sequentially map the size of the memory to be allocated to the high address space corresponding to multiple affinity memories in a cyclic interleaving manner; or, in response to the object to be allocated being any of the affinity memories, update the currently allocated memory corresponding to the affinity memory based on the size of the memory to be allocated, and map the size of the memory to be allocated to the low address space corresponding to the interleaved memory.
[0093] The memory management device provided in this application embodiment can implement the various processes implemented in the embodiments of the memory management method shown. To avoid repetition, it will not be described again here.
[0094] The memory management device in this application embodiment can be a device, or it can be a component, integrated circuit, or chip in an electronic device. This application embodiment does not impose specific limitations.
[0095] One memory management device in this application embodiment can be a device with an operating system. The operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system.
[0096] like Figure 12 As shown in the figure, this application embodiment also provides an electronic device 1200, including a processor 1210 and a memory 1220. The memory 1220 stores a program or instructions that can run on the processor 1210. When the program or instructions are executed by the processor 1210, they implement the various processes of the above-described memory management method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.
[0097] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described memory management method embodiments and achieve the same technical effects. To avoid repetition, they will not be described again here.
[0098] The processor mentioned above is the processor in the terminal described in the above embodiments. The readable storage medium may include a computer read-only memory (ROM), random access memory (RAM), a magnetic disk, or an optical disk, etc. In some examples, the readable storage medium may be a non-transient computer-readable storage medium.
[0099] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described memory management method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0100] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0101] This application also provides a computer program / program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, which, when executed by a computer, cause the computer to perform the various processes of the above-described memory management method embodiments and achieve the same technical effect. To avoid repetition, these will not be described again here.
[0102] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0103] From the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of computer software products plus necessary general-purpose hardware platforms, and of course, they can also be implemented by hardware. The computer software product is stored in a storage medium (such as ROM, RAM, magnetic disk, optical disk, etc.) and includes several instructions to cause the terminal or network-side device to execute the methods described in the various embodiments of this application.
[0104] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other implementations under the guidance of this application without departing from the spirit and scope of the claims. All of these implementations are within the protection scope of this application.
Claims
1. A memory management method, characterized in that, Applied to a memory management system, the memory management system including interleaved memory and multiple affinity memory, wherein the interleaved memory has an interleaved mapping relationship with each of the affinity memory, the method includes: The object to be allocated and the size of the memory to be allocated are determined according to the memory allocation request, wherein the object to be allocated is the interleaved memory or any of the affinity memory; Based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and at least one currently allocated memory corresponding to the affinity memory, a memory allocation conflict detection is performed on the size of the memory to be allocated; In response to the passing of the memory allocation conflict detection, a memory allocation operation is performed on the object to be allocated according to the size of the memory to be allocated; Wherein, the interleaved memory is a memory unit that maps memory addresses to different affinity memories, the interleaved memory corresponds to a logical address space, the affinity memory corresponds to a physical address space, and the interleaved mapping relationship is used to indicate the mutual mapping relationship between the logical address space corresponding to the interleaved memory and the physical address space corresponding to the affinity memory.
2. The method according to claim 1, characterized in that, In response to the object to be allocated being any of the affinity memory, the currently allocated memory corresponding to at least one of the affinity memory includes the currently allocated memory corresponding to the object to be allocated; The step of performing memory allocation conflict detection on the size of the memory to be allocated based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and at least one currently allocated memory corresponding to the affinity memory includes: The first memory size is determined based on the currently allocated memory corresponding to the interleaved memory, the currently allocated memory corresponding to the object to be allocated, and the affinity memory size; If the first memory size is less than or equal to the memory size to be allocated, the memory allocation conflict detection is determined to fail; or if the first memory size is greater than the memory size to be allocated, the memory allocation conflict detection is determined to pass.
3. The method according to claim 2, characterized in that, The step of determining the first memory size based on the currently allocated memory corresponding to the interleaved memory, the currently allocated memory corresponding to the object to be allocated, and the affinity memory size includes: The first memory size is determined to be the difference between the affinity memory size and the first value, wherein the first value is the sum of the second value and the currently allocated memory corresponding to the object to be allocated, the second value is the ratio of the currently allocated memory corresponding to the interleaved memory to the third value, and the third value is the number of affinity memories.
4. The method according to claim 1, characterized in that, In response to the object to be allocated being the interleaved memory, the currently allocated memory corresponding to at least one of the affinity memories includes the currently allocated memory corresponding to each of the affinity memories; The step of performing memory allocation conflict detection on the size of the memory to be allocated based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and at least one currently allocated memory corresponding to the affinity memory includes: The second memory size is determined based on the currently allocated memory corresponding to the interleaved memory, the size of the affinity memory, and the currently allocated memory corresponding to each affinity memory. If the second memory size is less than or equal to the memory size to be allocated, the memory allocation conflict detection is determined to fail; or if the second memory size is greater than the memory size to be allocated, the memory allocation conflict detection is determined to pass.
5. The method according to claim 4, characterized in that, The step of determining the second memory size based on the currently allocated memory corresponding to the interleaved memory, the affinity memory size, and the currently allocated memory corresponding to each affinity memory includes: The second memory size is determined to be the difference between the fourth and fifth values, wherein the fourth value is the product of the affinity memory size and the third value, the fifth value is the sum of the currently allocated memory corresponding to the interleaved memory and the sixth value, the sixth value is the product of the seventh value and the third value, the seventh value is the maximum value among the currently allocated memory corresponding to multiple affinity memories, and the third value is the number of affinity memories.
6. The method according to claim 1, characterized in that, The step of allocating memory to the object to be allocated based on the size of the memory to be allocated includes: According to the memory allocation strategy corresponding to the object to be allocated, a target free memory block that meets the size of the memory to be allocated is queried from the free memory linked list corresponding to the object to be allocated. In response to the free memory list including the target free memory block, memory allocation is performed in the target free memory block based on the size of the memory to be allocated.
7. The method according to claim 6, characterized in that, The step of querying the free memory block that meets the size of the memory to be allocated in the free memory list corresponding to the object to be allocated, according to the memory allocation strategy corresponding to the object to be allocated, includes: In response to the object to be allocated being any of the affinity memory, the target free memory block is searched from low address to high address in the free memory list; or, In response to the object to be allocated being the interleaved memory, the target free memory block is searched from high address to low address in the free memory list.
8. The method according to claim 6, characterized in that, After allocating memory within the target free memory block based on the size of the memory to be allocated, the method further includes: In response to the fact that the object to be allocated is the interleaved memory, the currently allocated memory corresponding to the interleaved memory is updated based on the size of the memory to be allocated, and the size of the memory to be allocated is sequentially mapped to the high address space corresponding to multiple affinity memories in a cyclic interleaving manner; or, In response to the object to be allocated being any of the affinity memory, the currently allocated memory corresponding to the affinity memory is updated based on the size of the memory to be allocated, and the size of the memory to be allocated is mapped to the low address space corresponding to the interleaved memory.
9. An electronic device, characterized in that, It includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the memory management method as described in any one of claims 1-8.
10. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the memory management method as described in any one of claims 1-8.