Memory arrangement method and device and electronic equipment

By dynamically determining the sorting mode according to the free memory conditions and size after memory garbage cleaning, decoupling of garbage cleaning and memory sorting, the problem of waste of memory sorting resources in the existing technology is solved, and memory recycling efficiency and system performance are improved.

CN120407435APending Publication Date: 2025-08-01VIVO MOBILE COMM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510511303.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-22
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

The existing memory sorting solution needs to execute the memory sorting process after each triggering the garbage cleaning process, resulting in large resource overhead and low efficiency, resulting in problems such as heating and lag in electronic equipment.

Method used

After the memory is garbage cleaned, memory sorting will be triggered only when the free memory meets certain conditions, and the target sorting mode will be dynamically determined based on the free and used memory sizes, decoupling the garbage cleaning and memory sorting process, and improving the flexibility of memory sorting methods.

Benefits of technology

Effectively reduce unnecessary memory sorting resource overhead, improve memory recycling efficiency, save system resources, and optimize system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407435A_ABST
    Figure CN120407435A_ABST
Patent Text Reader

Abstract

The invention discloses a memory arrangement method and device and electronic equipment, and belongs to the technical field of electronic equipment. The memory arrangement method comprises the steps that memory information of a first memory partition is obtained, the first memory partition is a memory partition after garbage cleaning in a target memory, and the memory information comprises the memory size of an idle memory and the memory size of a used memory; under the condition that the memory size of the free memory meets a first condition, determining a target arrangement mode according to the memory size of the free memory and the memory size of the used memory; and sorting the first memory partition according to the target sorting mode.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the technical field of electronic devices, and particularly relates to a memory consolidation method, apparatus, and electronic device. Background Art

[0002] Memory consolidation is a memory management mechanism. Through memory consolidation, fragmented memory released by garbage collection can be eliminated to obtain contiguous memory, which can then be reused.

[0003] In the currently adopted memory consolidation scheme, the memory consolidation process needs to be executed after each garbage collection process is triggered. For example, in a 512MB memory, assuming that there is 1MB = 1024KB = 1048576 bytes of free memory after garbage collection, and each byte of the free memory is fragmented and distributed throughout the 512MB memory, then in order to eliminate these fragments, 1048576 memory move operations need to be performed, and finally only 1MB of contiguous memory is obtained. It can be seen that the existing memory consolidation scheme has the problem of low recycling efficiency. Summary of the Invention

[0004] The purpose of the embodiments of this application is to provide a memory consolidation method, apparatus, and electronic device to improve the memory recycling efficiency.

[0005] In a first aspect, the embodiments of this application provide a memory consolidation method, including:

[0006] Obtain the memory information of the first memory partition, where the first memory partition is the memory partition after garbage collection in the target memory, and the memory information includes the memory size of the free memory and the memory size of the used memory;

[0007] When the memory size of the free memory meets the first condition, determine the target consolidation mode of the free memory according to the memory size of the free memory and the memory size of the used memory;

[0008] Consolidate the free memory in the first memory partition according to the target consolidation mode.

[0009] In a second aspect, the embodiments of this application provide a memory consolidation apparatus, including:

[0010] An obtaining module, configured to obtain the memory information of the first memory partition, where the first memory partition is the memory partition after garbage collection in the target memory, and the memory information includes the memory size of the free memory and the memory size of the used memory;

[0011] A determining module, configured to determine the target consolidation mode of the free memory according to the memory size of the free memory and the memory size of the used memory when the memory size of the free memory meets the first condition;

[0012] A sorting module, configured to sort the free memory in the first memory partition according to a target sorting mode.

[0013] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor and a memory. The memory stores a program or instruction that can run on the processor. When the program or instruction is executed by the processor, the steps of the method described in the first aspect are implemented.

[0014] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.

[0015] In a fifth aspect, an embodiment of the present application provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor, and the processor is configured to run a program or instruction to implement the steps of the method described in the first aspect.

[0016] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the steps of the method described in the first aspect.

[0017] This embodiment decouples garbage collection and memory sorting. After garbage collection of the memory, only when the free memory meets certain conditions will memory sorting be considered. In this way, the resource overhead caused by unnecessary memory sorting can be effectively reduced, and the memory recycling efficiency can be improved. Moreover, in this embodiment, when the free memory meets certain conditions, the target sorting mode of the free memory is further dynamically determined according to the memory sizes of the free memory and the used memory, which improves the flexibility of the memory sorting method and can further save system resources. That is, this embodiment can improve the memory recycling efficiency. Description of the Drawings

[0018] Figure 1 A schematic diagram of memory after garbage collection provided by the related art;

[0019] Figure 2 A schematic diagram of memory with added marks provided by the related art;

[0020] Figure 3 A schematic diagram of memory after memory sorting provided by the related art;

[0021] Figure 4 A flowchart of a memory sorting method provided by an embodiment of the present application;

[0022] Figure 5 A schematic diagram of a first memory partition provided by an embodiment of the present application;

[0023] Figure 6 Flowchart of another memory reorganization method provided by an embodiment of this application;

[0024] Figure 7 Schematic diagram of another first memory partition provided by an embodiment of this application;

[0025] Figure 8 Schematic diagram of a second memory partition provided by an embodiment of this application;

[0026] Figure 9 Schematic diagram of memory after object mapping provided by an embodiment of this application;

[0027] Figure 10 Schematic diagram of memory after object movement provided by an embodiment of this application;

[0028] Figure 11 Schematic diagram of memory after object copying provided by an embodiment of this application;

[0029] Figure 12 Flowchart of a memory reorganization solution provided by an embodiment of this application;

[0030] Figure 13 Schematic diagram of the structure of a memory reorganization device provided by an embodiment of this application;

[0031] Figure 14 Schematic diagram of the structure of an electronic device provided by an embodiment of this application;

[0032] Figure 15 Schematic diagram of the hardware structure of an electronic device provided by an embodiment of this application. Detailed implementation manners

[0033] Next, the technical solutions in the embodiments of this application will be clearly described in conjunction with the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are some, but not all, of the embodiments of this application. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art fall within the scope of protection of this application.

[0034] The terms "first", "second", etc. in the specification of this application are used to distinguish similar objects, rather than to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances so that the embodiments of this application can be implemented in an order different from those illustrated or described here, and the objects distinguished by "first", "second", etc. are usually of the same type, and the number of objects is not limited. For example, the first object can be one or multiple. In addition, "and / or" in the specification means at least one of the connected objects, and the character " / ", generally represents an "or" relationship between the associated objects before and after.

[0035] In the Android system, the currently adopted memory recycling scheme is mainly implemented based on the Concurrent Mark Compact (CMC) algorithm. The principle of the CMC algorithm is as follows:

[0036] Taking a memory block representing 1MB as an example, assume that initially there are 30 free memory blocks, that is, there is 30MB of free memory. As the code runs, this free memory is gradually used until there is no free memory left.

[0037] During the process of memory usage, the memory recycling process will be triggered under certain conditions. The recycling process is divided into two steps:

[0038] (1) Garbage cleaning

[0039] When performing garbage cleaning, objects that are no longer needed can be cleaned up. After cleaning, the memory is as shown in the following figure. Among them, the shaded memory block 101 represents the memory block that has not been cleaned, and the white memory block 102 represents the memory block that has been cleaned, that is, free memory. Figure 1 As shown, the shaded memory block 101 represents the memory block that has not been cleaned, and the white memory block 102 represents the memory block that has been cleaned, that is, free memory.

[0040] (2) Memory compaction

[0041] As shown in the following figure, before memory compaction, the free memory is fragmented. Assume that there is an object that needs to occupy 5MB of continuous memory, that is, 5 consecutive free memory blocks. Although there are a total of 15 free memory blocks in the memory, that is, 15MB of memory is free for allocation, due to severe fragmentation of the free memory, there is no 5MB of continuous memory, which will lead to memory allocation failure. Figure 1 As shown, before memory compaction, the free memory is fragmented. Assume that there is an object that needs to occupy 5MB of continuous memory, that is, 5 consecutive free memory blocks. Although there are a total of 15 free memory blocks in the memory, that is, 15MB of memory is free for allocation, due to severe fragmentation of the free memory, there is no 5MB of continuous memory, which will lead to memory allocation failure.

[0042] Therefore, just performing garbage cleaning is not enough, and memory compaction must be carried out. The process of the CMC algorithm is as follows:

[0043] (1) Calculate the number of free memory and the number of used memory, and number the used memory blocks, as shown in the following figure. Figure 2 As shown

[0044] (2) Move the objects in the figure, and finally obtain a complete memory, as shown in the following figure. The valid objects are consecutive in sequence, and the free memory blocks are consecutive in sequence. Thus, 15 free memory blocks can be obtained, eliminating the fragmentation of free memory and meeting larger memory allocation requirements. Figure 2 in the figure Figure 3 As shown, the valid objects are consecutive in sequence, and the free memory blocks are consecutive in sequence. Thus, eliminating the fragmentation of free memory and meeting larger memory allocation requirements.

[0045] Every time the above-mentioned scheme triggers the memory recycling process, it will execute a garbage cleaning process and a memory compaction process. As a result, a large amount of resource overhead will be caused, leading to situations such as overheating, lagging, and high power consumption of the electronic device.

[0046] To this end, the embodiments of the present application provide a memory reorganization method, apparatus, and electronic device, which can effectively solve the problem of resource waste caused by inefficient memory recycling and improve the memory recycling efficiency.

[0047] The following describes the memory reorganization method provided by the embodiments of the present application in conjunction with the accompanying drawings and specific embodiments.

[0048] Figure 4 FIG. is a flowchart of a memory reorganization method provided by an embodiment of the present application. The memory reorganization method can be applied to electronic devices such as handheld devices, in-vehicle devices, wearable devices, and laptop computers. The handheld device can include, for example, a mobile phone, a tablet computer, etc. The operating system of the electronic device can be the Android operating system, the iOS operating system, or other possible operating systems. The present application takes the Android system as an example to illustrate the memory reorganization method.

[0049] As Figure 4 shown, the memory reorganization method can include the following steps:

[0050] S410. Obtain the memory information of the first memory partition.

[0051] Among them, the first memory partition is the memory partition after garbage cleaning in the target memory, and the memory information includes the memory size of the free memory and the memory size of the used memory.

[0052] S420. When the memory size of the free memory meets the first condition, determine the target reorganization mode of the free memory according to the memory size of the free memory and the memory size of the used memory.

[0053] S430. Reorganize the free memory in the first memory partition according to the target reorganization mode.

[0054] This embodiment decouples garbage cleaning and memory reorganization. After garbage cleaning of the memory, only when the free memory meets certain conditions will memory reorganization be considered. In this way, the resource overhead caused by unnecessary memory reorganization can be effectively reduced, and the memory recycling efficiency can be improved. Moreover, when the free memory meets certain conditions in this embodiment, the target reorganization mode of the free memory is further dynamically determined according to the memory sizes of the free memory and the used memory, which improves the flexibility of the memory reorganization method and can further save system resources. That is, this embodiment can improve the memory recycling efficiency.

[0055] The above steps are described in detail below, as follows:

[0056] In S410, the target memory may be virtual machine memory, such as Java virtual machine memory. That is, the embodiments of the present application can organize the virtual machine memory. In practical applications, the target memory may include one or more memory partitions, and each memory partition may include one or more memory blocks. When there are multiple memory partitions, the number of memory blocks included in different memory partitions may be the same or different.

[0057] The first memory partition is a memory partition in the target memory and is used to store different objects. In some embodiments, the first memory partition may be a memory partition after garbage collection, that is, the first memory partition only contains valid objects. The size of the first memory partition can be established as needed.

[0058] In some embodiments, to facilitate subsequent memory organization, a second memory partition may also be established in the target memory. For example, when performing memory organization, the valid objects in the first memory partition can be mapped to the second memory partition, the valid objects are moved in the second memory partition, and the moved valid objects are copied to the first memory partition. The size of the second memory partition can be dynamically adjusted.

[0059] The memory information of the first memory partition may be information characterizing the characteristics of the first memory partition. For example, it may include but is not limited to the memory size of the free memory, the location of the free memory in the first memory partition, the memory size of the used memory, and the location of the used memory in the first memory partition. The memory size and location of the free memory and the used memory can be recorded during garbage collection to provide a basis for subsequent determination of whether memory organization is required.

[0060] The free memory here may be the memory released after garbage collection or the memory in the unallocated area. The unallocated area may be the area in the first memory partition where objects are not temporarily allocated. In practical applications, the memory allocation of the virtual machine is sequential. For example, if the 10th memory block was applied for last time, then the next application needs to start from the 11th memory block. Taking the first memory partition including 30 memory blocks as an example, assuming that before garbage collection, the first 21 memory blocks have been used, the unallocated area is the area where the remaining 9 memory blocks are located.

[0061] Exemplarily, as Figure 5 shown, area 501 is the allocated area in the first memory partition, and area 502 is the unallocated area in the first memory partition. In some embodiments, the above free memory may be the free memory released from area 501, or the free memory in area 502, or may also include the free memory released from area 501 and the free memory in area 502 at the same time.

[0062] The used memory may be the memory in the allocated area that has not been released.Figure 5 For example, the used memory is the memory blocks filled with shading in area 501, specifically 11 memory blocks.

[0063] In S420, the first condition may be a condition for which memory rearrangement is required. That is, in this embodiment, only when the memory size of the free memory satisfies the first condition will memory rearrangement be performed; otherwise, only the garbage collection process will be executed. In this way, the decoupling of the garbage collection process and the memory rearrangement process is achieved, reducing the resource overhead caused by unnecessary memory rearrangement and improving the memory recycling efficiency.

[0064] Exemplarily, when the free memory includes the free memory released from the allocated area, the first condition may include that the total memory size of the released free memory is greater than threshold 1.

[0065] Exemplarily, when the free memory includes the free memory in the unallocated area, the first condition may include that the memory size of the free memory in the unallocated area is less than threshold 2.

[0066] Exemplarily, when the free memory includes the free memory released from the allocated area and the free memory in the unallocated area, the first condition may include that the total memory size of the released free memory is greater than threshold 1, and the memory size of the free memory in the unallocated area is less than threshold 2.

[0067] The target rearrangement mode is the mode adopted for memory rearrangement, and the target rearrangement mode can be dynamically determined according to the memory sizes of the free memory and the used memory. In this way, the flexibility of the memory rearrangement mode is improved.

[0068] Exemplarily, the memory rearrangement mode may include but is not limited to the local rearrangement mode and the global rearrangement mode. The local rearrangement mode is used to perform memory rearrangement on a part of the first memory partition, thereby further saving system resources. The global rearrangement mode is used to perform memory rearrangement on the whole of the first memory partition, so as to meet larger memory allocation requirements.

[0069] Exemplarily, the target rearrangement mode can be found by looking up a table that stores the correspondence between the memory sizes of the free memory and the used memory and the memory rearrangement mode.

[0070] Exemplarily, the target rearrangement mode can also be determined by a machine learning model or a deep learning model, which takes the memory sizes of the free memory and the used memory as inputs and the memory rearrangement mode as the output.

[0071] Exemplarily, the target defragmentation mode can also be determined according to the type of free memory, the memory size of the free memory, and the memory size of the used memory. The specific determination process can be seen in the following embodiments.

[0072] In S430, after the target defragmentation mode is determined, the free memory in the first memory partition can be defragmented according to the target defragmentation mode to obtain continuous free memory. The memory size of the continuous free memory is associated with the target defragmentation mode. For example, when the target defragmentation mode is the global defragmentation mode, the memory size of the continuous free memory is the maximum value. When the target defragmentation mode is the local defragmentation mode, the memory size of the continuous free memory is non-maximum, and the specific size is related to the memory sizes of the free memory and the used memory.

[0073] In this embodiment, when memory defragmentation is required, the target defragmentation mode can be dynamically determined according to the memory sizes of the free memory and the used memory, and then the free memory in the first memory partition can be defragmented according to the target defragmentation mode to obtain continuous free memory of a certain size. Under the condition of meeting the memory allocation requirements, resource consumption can be minimized as much as possible, and the memory recycling efficiency can be improved.

[0074] In some embodiments, the above free memory may include a first free memory and a second free memory, where the first free memory is the memory released after garbage cleaning of the allocated area of the first memory partition, and the second free memory is the memory in the unallocated area of the first memory partition.

[0075] As Figure 5 shown, the first free memory is the free memory in area 501, also known as fragmented free memory, which is the free memory released after garbage cleaning. The second free memory is the free memory in area 502, also known as remaining free memory.

[0076] Based on this, the memory size of the free memory satisfying the first condition may include: the memory size of the second free memory is less than the first threshold, and the total memory size of the first free memory is greater than the second threshold, where the first threshold is less than the second threshold.

[0077] Exemplarily, the size of the first threshold can be determined according to the memory allocation requirements in different scenarios. For example, if usually, 128MB of free memory remaining in the unallocated area can meet the memory allocation requirements in most scenarios, the first threshold can be set to 128MB. In actual applications, the first threshold can also be flexibly adjusted according to needs.

[0078] Exemplarily, the size of the second threshold can be dynamically set according to the foreground and background conditions of the process. For example, if the process is in the foreground, the second threshold can be set to 50MB, and if the process is in the background, the second threshold can be set to 20MB. The process here refers to the process corresponding to the allocation object. In actual applications, the second threshold can also be dynamically adjusted based on this.

[0079] Exemplarily, if the memory size of the second free memory is greater than or equal to the first threshold, it indicates that the second free memory is sufficient and there is no need to perform memory rearrangement.

[0080] Exemplarily, if the memory size of the second free memory is less than the first threshold, but the total memory size of the first free memory is less than or equal to the second threshold, even if memory rearrangement is performed, the continuous memory obtained by rearrangement is less and it is difficult to meet the allocation requirements. Therefore, memory rearrangement can be not performed.

[0081] When determining whether memory rearrangement is required in this embodiment, not only the free memory released in the allocated area is considered, but also the free memory in the unallocated area is considered. Only when the free memory released in the allocated area and the free memory in the unallocated area both meet certain conditions, will memory rearrangement be performed on the first memory partition. Thus, the resource overhead caused by unnecessary memory rearrangement can be greatly reduced, and the memory recycling efficiency can also be improved.

[0082] Assume that the memory size of the free memory meets the first condition. Taking the free memory including the first free memory and the second free memory as an example, Figure 6 Exemplarily provides a flowchart of a memory rearrangement method. Figure 6 Different from Figure 4 is that Figure 4 S420 in Figure 6 can be refined into

[0083] S610. Determine the fragmentation rate according to the total memory size of the first free memory and the memory size of the allocated area.

[0084] The total memory size of the first free memory can be determined according to the number of the first free memories and the memory size of a single first free memory. For example, in the case where the memory of each first free memory is the same, the total memory size of the first free memory is equal to the product value of the number of the first free memories and the memory size of a single first free memory.

[0085] The fragmentation rate is used to characterize the dispersion degree of the first free memory in the first memory partition. The higher the fragmentation rate, the higher the dispersion degree of the first free memory, that is, the more dispersed the first free memory is in the allocated area.

[0086] Exemplarily, the ratio of the total memory size of the first free memory to the memory size of the allocated area can be determined as the fragmentation rate of the first free memory. For example, if the first free memory includes a total of 10 memory blocks and the allocated area includes 21 memory blocks, and the size of each memory block is the same, then the fragmentation rate of the first free memory = 10 / 21 ≈ 48%.

[0087] Exemplarily, the fragmentation rate of the first free memory can also be determined based on the total memory size of the first free memory, the memory size of the allocated area, and the positions of the first free memories in the allocated area. For example, the total memory size of the first free memory, the memory size of the allocated area, and the positions of the first free memories in the allocated area can be input into a machine learning model or a deep learning model to obtain the fragmentation rate of the first free memory.

[0088] S620. When the fragmentation rate is greater than or equal to the third threshold, determine that the target defragmentation mode is the global defragmentation mode.

[0089] In this embodiment, the target defragmentation mode can be dynamically determined according to the fragmentation rate. Exemplarily, if the fragmentation rate is high, that is, there is more first free memory, correspondingly, the number of used memories that need to be moved is less, and the system resources consumed are less, that is, the cost of memory defragmentation is lower. At this time, the full defragmentation mode can be adopted to meet as many memory allocation requirements as possible.

[0090] The size of the third threshold can be set according to requirements. For example, in some embodiments, the third threshold can be set to 50%.

[0091] S630. When the fragmentation rate is less than the third threshold, determine the target defragmentation mode according to the memory size of the second free memory.

[0092] Exemplarily, if the fragmentation rate is low, that is, there is less first free memory, in order to more accurately determine the memory defragmentation mode, the memory size of the second free memory can also be further combined to determine the target defragmentation mode.

[0093] For example, when the memory size of the second free memory is greater than or equal to a certain threshold, it means that the free memory in the unallocated area is large. At this time, local defragmentation of the first memory partition can meet the memory allocation requirements. That is, when the memory size of the second free memory is greater than a certain threshold, the target defragmentation mode can be determined as the local defragmentation mode.

[0094] For another example, when the memory size of the second free memory is less than a certain threshold, it means that the free memory in the unallocated area is small. At this time, the target defragmentation mode can be determined as the global defragmentation mode. Or, when the memory size of the second free memory is less than a certain threshold, the total memory size of the first free memory can also be further combined to determine the target defragmentation mode.

[0095] In this embodiment, when the memory size of the free memory meets the first condition, the memory consolidation mode is dynamically determined according to the fragmentation rate of the first free memory. When the fragmentation rate of the first free memory is relatively large, the global consolidation mode is adopted. Under the condition of ensuring low cost, the maximum continuous free memory can be obtained to meet more memory allocation requirements. When the fragmentation rate of the first free memory is relatively low, the target consolidation mode is further determined according to the memory size of the second free memory, which can improve the memory recycling efficiency.

[0096] In some embodiments, the above S630 may include the following steps:

[0097] When the memory size of the second free memory is greater than or equal to the fourth threshold, the target consolidation mode is determined to be the first local consolidation mode, and the first local consolidation mode is used to indicate that the memory size of the continuous free memory sorted out is the same as the second threshold;

[0098] When the memory size of the second free memory is less than the fourth threshold, the target consolidation mode is determined according to the sum of the memory size of the second free memory and the total memory size of the first free memory.

[0099] Exemplarily, the fourth threshold can be determined according to the first threshold and the second threshold. For example, the fourth threshold = the first threshold - the second threshold.

[0100] The first local consolidation mode is also called the minimized local consolidation mode. By performing memory consolidation on the first memory partition according to the minimized local consolidation mode, continuous free memory of the second threshold size can be obtained.

[0101] Exemplarily, when the memory size of the second free memory is greater than or equal to the fourth threshold, it indicates that the minimized local consolidation can meet the memory allocation requirements. Therefore, the memory consolidation of the first memory partition can be performed according to the minimized local consolidation mode.

[0102] Exemplarily, when the memory size of the second free memory is less than the fourth threshold, it indicates that the minimized local consolidation, that is, the memory size of the continuous free memory sorted out is equal to the second threshold, cannot meet the memory allocation requirements. At this time, the target consolidation mode can be further determined comprehensively according to the sum of the total memory size of the first free memory and the memory size of the second free memory.

[0103] For example, the target consolidation mode can be determined according to the sum of the total memory size of the first free memory and the memory size of the second free memory, that is, the total memory size of the free memory.

[0104] When the fragmentation rate of the first free memory is relatively small in this embodiment, the target management mode is further dynamically determined according to the memory size of the second free memory. In particular, when the memory size of the second free memory is relatively large, the minimum partial rearrangement mode is adopted to perform memory rearrangement on the first memory partition, which can further save system resources. When the memory size of the second free memory is relatively small, the target management mode is further determined in combination with the total memory size of the first free memory, improving the accuracy and flexibility of the memory rearrangement mode.

[0105] In some embodiments, the above "determining the target rearrangement mode according to the sum of the memory size of the second free memory and the total memory size of the first free memory" may include the following steps:

[0106] When the sum of the memory size of the second free memory and the total memory size of the first free memory is greater than or equal to the first threshold, the target rearrangement mode is determined to be the second partial rearrangement mode, and the second partial rearrangement mode is used to indicate that the memory size of the continuous free memory sorted out is the same as the first threshold;

[0107] When the sum of the memory size of the second free memory and the total memory size of the first free memory is less than the first threshold, the target rearrangement mode is determined to be the global rearrangement mode.

[0108] Compared with the first partial rearrangement mode, the second partial rearrangement mode obtains a larger memory size of the continuous free memory, but smaller than the memory size of the continuous free memory obtained by the global rearrangement mode.

[0109] Exemplarily, when the sum of the memory size of the second free memory and the total memory size of the first free memory is greater than or equal to the first threshold, that is, when the total memory size of the free memory is greater than or equal to the first threshold, the second partial rearrangement mode can be triggered to perform partial rearrangement on the first memory partition until continuous free memory of the first threshold size is obtained.

[0110] Exemplarily, when the total memory size of the free memory is less than the first threshold, the global rearrangement mode can be triggered to perform global rearrangement on the first memory partition.

[0111] In this embodiment, when the memory size of the second free memory is relatively small, the memory rearrangement mode is further dynamically determined according to the sum of the total memory sizes of the first free memory and the second free memory, ensuring the accuracy and flexibility of the memory rearrangement mode.

[0112] In some embodiments, the above S430 may include the following steps:

[0113] Determine the target memory partition from the first memory partition according to the target rearrangement mode;

[0114] Map the objects in the target memory partition to the second memory partition, where the second memory partition is the memory partition in the target memory other than the first memory partition, the memory size of the second memory partition is the same as the memory size of the target memory partition, and the position of the object in the second memory partition is the same as the position of the object in the target memory partition;

[0115] Move the object in the second memory partition so that the position of the moved object is continuous in the second memory partition;

[0116] Copy the moved object to the target position in the target memory partition.

[0117] The target memory partition is the memory partition in the allocated area of the first memory partition that needs memory compaction. The target memory partition can be a part or all of the allocated area, which is specifically related to the target compaction mode.

[0118] For example, when the target compaction mode is the global compaction mode, the target memory partition is the entire allocated area. When the target compaction mode is the first local compaction mode, the starting position and ending position of the target memory partition can be determined according to the size of the second threshold. When the target compaction mode is the second local compaction mode, the starting position and ending position of the target memory partition can be determined according to the size of the first threshold.

[0119] Exemplarily, when the target memory partition is a part of the allocated area, exemplarily, the target memory partition can be determined from the allocated area from front to back. For example, the target memory partition can be determined backward from the starting position of the allocated area. Exemplarily, the target memory partition can also be determined from the allocated area from back to front. For example, the target memory partition can be determined forward from the ending position of the allocated area.

[0120] Figure 7 Taking the case where the first memory partition only contains the allocated area as an example, that is, before garbage collection, all memory has been allocated. The situation of each memory block after garbage collection is as Figure 7 shown.

[0121] Assume that the target compaction mode is the local compaction mode and 5 consecutive free memory blocks need to be compacted. Considering that memory is allocated in sequence from front to back during memory allocation, in some embodiments, the target memory partition can be determined from back to front. To obtain 5 consecutive free memories, the last 9 memory blocks need to be determined as the target memory partition 701.

[0122] The second memory partition is the memory partition in the target memory other than the first memory partition, the memory size of the second memory partition is the same as the memory size of the target memory partition, and the position of the object in the second memory partition is the same as the position of the object in the target memory partition.

[0123] The object here is a valid object. The second memory partition can be constructed according to the target memory partition. In this embodiment, the memory size of the second memory partition is the same as that of the target memory partition. Taking Figure 7 the target memory partition 701 in Figure 8 as an example, illustratively, the constructed second memory partition 702 is as shown in

[0124] Map the objects in the target memory partition to the second memory partition, that is, cut the objects in the target memory partition to the second memory partition. The positions of the mapped objects in the second memory partition are the same as the positions of the objects in the target memory partition before mapping. The schematic diagram after mapping can be seen in Figure 9 .

[0125] After object mapping, the objects can be moved in the second memory partition until the moved objects are consecutive in the second memory partition. When moving the objects, illustratively, the objects can be moved from front to back or from back to front. Which specific method to adopt can be determined according to the system resources consumed by moving the objects. For example, if the system resources consumed by moving the objects from front to back are higher than the system resources consumed by moving the objects from back to front, the moving method from back to front can be adopted to save system resources.

[0126] Taking Figure 8 as an example, when moving the objects from front to back, it needs to be moved 5 times to make the moved objects consecutive. When moving the objects from back to front, it needs to be moved 15 times. Obviously, the system resources consumed by moving 5 times are less than the system resources consumed by moving 15 times. Therefore, the objects can be moved from front to back. The schematic diagram after the objects are moved is as shown in Figure 10 .

[0127] The target position can be a position starting from the starting position of the target memory partition. For example, in Figure 11 , the target position can be a position starting from memory block 110. After obtaining consecutive objects, the consecutive objects can be copied to the target memory. Thus, 5 consecutive free memory blocks can be obtained.

[0128] In this embodiment, first map the objects in the target memory partition to another memory partition, move the objects in the other memory partition to make them consecutive, and then copy the consecutive objects to the target memory partition, saving system resources when obtaining consecutive free memory that meets the requirements.

[0129] In some embodiments, before mapping the objects in the target memory partition to the second memory partition, the memory arrangement method may further include the following steps:

[0130] Establish a second memory partition from the target memory according to the memory size of the target memory partition;

[0131] Correspondingly, after copying the moved object to the target position in the target memory partition, the memory compaction method may further include the following steps:

[0132] Delete the second memory partition.

[0133] In this embodiment, when memory compaction is required, a second memory partition is established in the target memory according to the memory size of the target memory partition to assist in memory compaction, saving system resources. After copying the object to the target memory partition, the second memory partition is deleted in a timely manner, which can reduce memory occupancy, meet more memory allocation requirements, and at the same time ensure the uniqueness of the object, avoiding unexpected behaviors and errors caused by duplicate objects.

[0134] Next, in conjunction with Figure 12 A memory compaction solution provided by an embodiment of the present application will be described as follows:

[0135] S1. Whether a memory management instruction is received. If a memory management instruction is received, execute S2; otherwise, execute S3, that is, dynamically determine whether to perform memory compaction according to the memory sizes of free memory and used memory.

[0136] S2. Perform memory compaction on the first memory partition according to the memory management instruction. The memory management instruction includes the memory size of the required continuous free memory.

[0137] S3. Whether the memory size of the second free memory is greater than a first threshold. If so, execute S4; if not, execute S5.

[0138] S4. Do not perform memory compaction.

[0139] S5. Whether the total memory size of the first free memory is less than a second threshold. If so, execute S6; if not, execute S7.

[0140] S6. Do not perform memory compaction.

[0141] S7. Whether the fragmentation rate of the first free memory is greater than a third threshold. If so, execute S8; if not, execute S9.

[0142] S8. Global memory management. That is, perform memory compaction on the first memory partition in the global compaction mode.

[0143] S9. Whether the memory size of the second free memory is greater than a fourth threshold. If so, execute S10; if not, execute S11.

[0144] S10. Minimized memory management. That is, perform memory compaction on the first memory partition in the first local compaction mode.

[0145] S11. Whether the total memory size of the free memory is greater than a first threshold. If so, execute S12; if not, execute S13.

[0146] S12. Local memory reorganization. That is, perform memory reorganization on the first memory partition using a second local reorganization mode.

[0147] S13. Global memory management.

[0148] This embodiment optimizes the memory recycling process, decouples garbage cleaning and memory reorganization. After garbage cleaning of the memory, only when the free memory meets certain conditions will the memory reorganization process be triggered to perform memory reorganization, without the need to perform memory reorganization every time, reducing the resource overhead caused by unnecessary memory reorganization. Moreover, when memory reorganization is required, the memory reorganization mode can be further dynamically determined according to the memory sizes of the free memory and the used memory, and different memory reorganization modes consume different resources. In this way, the memory reorganization process can be further optimized to save system resources.

[0149] Suppose 5 memory recycles are triggered. According to the solutions of the related art, 5 garbage cleanings and 5 memory reorganizations need to be performed. After using the above solution, 5 garbage cleanings and less than 5 memory reorganizations are performed.

[0150] Suppose that a complete garbage cleaning and a global memory reorganization consume 1 unit of system resources, and garbage cleaning and memory reorganization account for 60% and 40% respectively. Then a complete garbage cleaning consumes 0.6 units of system resources, and a global memory reorganization consumes 0.4 units of system resources. The related art consumes 5 units of system resources after performing 5 memory recycles. Additionally, suppose a local memory reorganization consumes 0.2 units of system resources. After using the above solution, the following situations may occur:

[0151] (1) 5 garbage cleanings, without memory reorganization, that is, 0.6 * 5 = 3 (optimal case), which is approximately 40% optimized compared to the solution of the related art;

[0152] (2) 5 garbage cleanings, 1 local memory reorganization, that is, 0.6 * 5 + 0.2 = 3.2, which is approximately 36% optimized compared to the solution of the related art;

[0153] (3) 5 garbage cleanings, 1 complete memory reorganization, that is, 0.6 * 5 + 0.4 = 3.4, which is approximately 32% optimized compared to the solution of the related art.

[0154] It can be seen that the embodiments of the present application can control the resource consumption of memory recycling within the range of 60%-100% of the original, with a maximum optimization of 40%. This can avoid resource waste caused by ineffective memory sorting, save CPU computing power, and optimize system performance.

[0155] It should be noted that for the memory sorting method provided by the embodiments of the present application, the execution subject can be a memory sorting device, or a processing module in the memory sorting device for executing the memory sorting method. In the embodiments of the present application, taking the memory sorting device as the execution subject of the memory sorting method as an example, the memory sorting device provided by the embodiments of the present application is described.

[0156] Figure 13 It is a schematic structural diagram of a memory sorting device provided by an embodiment of the present application.

[0157] As Figure 13 shown, the memory sorting device 1300 may include:

[0158] An acquisition module 1301, configured to acquire memory information of a first memory partition, where the first memory partition is a memory partition after garbage collection in the target memory, and the memory information includes the memory size of free memory and the memory size of used memory;

[0159] A determination module 1302, configured to determine a target sorting mode of the free memory according to the memory size of the free memory and the memory size of the used memory when the memory size of the free memory meets a first condition;

[0160] A sorting module 1303, configured to sort the free memory in the first memory partition according to the target sorting mode.

[0161] In this embodiment, garbage collection and memory sorting are decoupled. After garbage collection is performed on the memory, memory sorting is only considered when the free memory meets certain conditions, which can effectively reduce the resource overhead caused by unnecessary memory sorting and improve the memory recycling efficiency. Moreover, in this embodiment, when the free memory meets certain conditions, the target sorting mode of the free memory is further dynamically determined according to the memory sizes of the free memory and the used memory, which improves the flexibility of the memory sorting method and can further save system resources. That is, this embodiment can improve the memory recycling efficiency.

[0162] In some possible implementations of the embodiments of the present application, the free memory includes first free memory and second free memory, where the first free memory is the memory released after garbage collection of the allocated area of the first memory partition, and the second free memory is the memory in the unallocated area of the first memory partition;

[0163] The memory size of the free memory meeting the first condition includes:

[0164] The memory size of the second free memory is less than the first threshold, and the total memory size of the first free memory is greater than the second threshold, where the first threshold is less than the second threshold.

[0165] In some possible implementations of the embodiments of the present application, the free memory includes a first free memory and a second free memory. The first free memory is the memory released after garbage collection of the allocated area of the first memory partition, and the second free memory is the memory in the unallocated area of the first memory partition;

[0166] The determining module 1302 is specifically configured to:

[0167] Determine a fragmentation rate according to the total memory size of the first free memory and the memory size of the allocated area;

[0168] When the fragmentation rate is greater than or equal to the third threshold, determine that the target fragmentation mode is the global fragmentation mode;

[0169] When the fragmentation rate is less than the third threshold, determine the target fragmentation mode according to the memory size of the second free memory.

[0170] In some possible implementations of the embodiments of the present application, the determining module 1302 is specifically configured to:

[0171] When the memory size of the second free memory is greater than or equal to the fourth threshold, determine that the target fragmentation mode is the first local fragmentation mode, and the first local fragmentation mode is used to indicate that the memory size of the continuous free memory sorted out is the same as the second threshold;

[0172] When the memory size of the second free memory is less than the fourth threshold, determine the target fragmentation mode according to the sum of the memory size of the second free memory and the total memory size of the first free memory.

[0173] In some possible implementations of the embodiments of the present application, the determining module 1302 is specifically configured to:

[0174] When the sum of the memory size of the second free memory and the total memory size of the first free memory is greater than or equal to the first threshold, determine that the target fragmentation mode is the second local fragmentation mode, and the second local fragmentation mode is used to indicate that the memory size of the continuous free memory sorted out is the same as the first threshold;

[0175] When the sum of the memory size of the second free memory and the total memory size of the first free memory is less than the first threshold, determine that the target fragmentation mode is the global fragmentation mode.

[0176] The memory consolidation device in the embodiments of the present application can be a device or a component in an electronic device, such as an integrated circuit or a chip. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a handheld computer, a vehicle-mounted electronic device, a Mobile Internet Device (MID), an augmented reality (AR) / virtual reality (VR) device, a robot, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc. It can also be a server, a Network Attached Storage (NAS), a personal computer (PC), a television (TV), a teller machine, or a self-service machine, etc. The embodiments of the present application do not make specific limitations.

[0177] The electronic device in the embodiments of the present application can be a terminal with an operating system. The operating system can be an Android operating system, an iOS operating system, or other possible operating systems. The embodiments of the present application do not make specific limitations.

[0178] The memory recovery device provided in the embodiments of the present application can implement Figures 4 to 12 each process in the memory consolidation method embodiments and achieve the same technical effects. To avoid repetition, it will not be elaborated here.

[0179] As Figure 14 shown, the embodiments of the present application also provide an electronic device 1400, including a processor 1401 and a memory 1402. The memory 1402 stores a program or instructions that can run on the processor 1401. When the program or instructions are executed by the processor 1401, each step of the above-mentioned memory consolidation method embodiments is implemented and the same technical effects can be achieved. To avoid repetition, it will not be elaborated here.

[0180] It should be noted that the electronic devices in the embodiments of the present application include the above-mentioned mobile terminals and non-mobile terminals.

[0181] Figure 15 is a schematic diagram of the hardware structure of an electronic device provided in the embodiments of the present application.

[0182] The electronic device 1500 includes, but is not limited to, components such as a radio frequency unit 1501, a network module 1502, an audio output unit 1503, an input unit 1504, a sensor 1505, a display unit 1506, a user input unit 1507, an interface unit 1508, a memory 1509, and a processor 1510, etc.

[0183] Those skilled in the art can understand that the electronic device 1500 may further include a power source (such as a battery) for supplying power to each component. The power source can be logically connected to the processor 1510 through a power management system, so as to implement functions such as management of charging, discharging, and power consumption management through the power management system. Figure 15 The structure of the electronic device 1500 shown does not constitute a limitation on the electronic device 1500. The electronic device 1500 may include more or fewer components than those shown, or combine certain components, or have different component arrangements, which will not be elaborated here.

[0184] Among them, the processor 1510 is used to obtain the memory information of the first memory partition. The first memory partition is the memory partition after garbage collection in the target memory. The memory information includes the memory size of the free memory and the memory size of the used memory. When the memory size of the free memory meets the first condition, determine the target reorganization mode of the free memory according to the memory size of the free memory and the memory size of the used memory. Reorganize the free memory in the first memory partition according to the target reorganization mode.

[0185] This embodiment decouples garbage collection and memory reorganization. After garbage collection of the memory, only when the free memory meets certain conditions will memory reorganization be considered. In this way, the resource overhead caused by unnecessary memory reorganization can be effectively reduced, and the memory recycling efficiency can be improved. Moreover, in this embodiment, when the free memory meets certain conditions, the target reorganization mode of the free memory is further dynamically determined according to the memory sizes of the free memory and the used memory, which improves the flexibility of the memory reorganization method and can further save system resources. That is, this embodiment can improve the memory recycling efficiency.

[0186] In some possible implementations of the embodiments of the present application, the free memory includes a first free memory and a second free memory. The first free memory is the memory released after garbage collection of the allocated area of the first memory partition, and the second free memory is the memory in the unallocated area of the first memory partition;

[0187] The memory size of the free memory meeting the first condition includes:

[0188] The memory size of the second free memory is less than a first threshold, and the total memory size of the first free memory is greater than a second threshold, where the first threshold is less than the second threshold.

[0189] In some possible implementations of the embodiments of the present application, the free memory includes a first free memory and a second free memory. The first free memory is the memory released after garbage collection of the allocated area of the first memory partition, and the second free memory is the memory in the unallocated area of the first memory partition;

[0190] The processor 1510 is specifically configured to:

[0191] When the memory size of the free memory meets the first preset condition, determine the fragmentation rate according to the total memory size of the first free memory and the memory size of the allocated area;

[0192] When the fragmentation rate is greater than or equal to the third threshold, determine that the target defragmentation mode is the global defragmentation mode;

[0193] When the fragmentation rate is less than the third threshold, determine the target defragmentation mode according to the memory size of the second free memory.

[0194] In some possible implementations of the embodiments of the present application, the processor 1510 is specifically configured to:

[0195] When the memory size of the second free memory is greater than or equal to the fourth threshold, determine that the target defragmentation mode is the first local defragmentation mode, and the first local defragmentation mode is used to indicate that the memory size of the continuous free memory sorted out is the same as the second threshold;

[0196] When the memory size of the second free memory is less than the fourth threshold, determine the target defragmentation mode according to the sum of the memory size of the second free memory and the total memory size of the first free memory.

[0197] In some possible implementations of the embodiments of the present application, the processor 1510 is specifically configured to:

[0198] When the sum of the memory size of the second free memory and the total memory size of the first free memory is greater than or equal to the first threshold, determine that the target defragmentation mode is the second local defragmentation mode, and the second local defragmentation mode is used to indicate that the memory size of the continuous free memory sorted out is the same as the first threshold;

[0199] When the sum of the memory size of the second free memory and the total memory size of the first free memory is less than the first threshold, determine that the target defragmentation mode is the global defragmentation mode.

[0200] It should be understood that in the embodiments of the present application, the input unit 1504 may include a Graphics Processing Unit (GPU) 15041 and a microphone 15042. The graphics processor 15041 processes the image data of static pictures or videos obtained by an image capturing device (such as a camera) in a video capture mode or an image capture mode. The display unit 1506 may include a display panel 15061, and the display panel 15061 may be configured in the form of, for example, a liquid crystal display, an organic light emitting diode, etc. The user input unit 1507 includes at least one of a touch panel 15071 and other input devices 15072. The touch panel 15071 is also referred to as a touch screen. The touch panel 15071 may include two parts: a touch detection device and a touch controller. The other input devices 15072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be elaborated here.

[0201] The memory 1509 can be used to store software programs and various data. The memory 1509 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data. Among them, the first storage area can store an operating system, application programs or instructions required for at least one function (such as a sound playback function, an image playback function, etc.). In addition, the memory 1509 can include a volatile memory or a non-volatile memory, or the memory 1509 can include both a volatile and a non-volatile memory. Among them, the non-volatile memory can be a Read-Only Memory (ROM), a Programmable ROM (PROM), an Erasable PROM (EPROM), an Electrically Erasable PROM (EEPROM), or a flash memory. The volatile memory can be a Random Access Memory (RAM), a Static RAM (SRAM), a Dynamic RAM (DRAM), a Synchronous DRAM (SDRAM), a Double Data Rate SDRAM (DDR SDRAM), an Enhanced SDRAM (ESDRAM), a Synchlink DRAM (SLDRAM), and a Direct Rambus RAM (DRRAM). The memory 1509 in the embodiments of the present application includes, but is not limited to, these and any other suitable types of memories.

[0202] The processor 1510 may include one or more processing units; optionally, the processor 1510 integrates an application processor and a modem processor. Among them, the application processor mainly processes operations related to the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communication signals, such as a baseband processor. It can be understood that the above modem processor may not be integrated into the processor 1510 either.

[0203] The embodiments of the present application also provide a readable storage medium. A program or instructions are stored on the readable storage medium. When the program or instructions are executed by the processor, each process of the above embodiment of the memory sorting method is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be elaborated here.

[0204] Among them, the processor is the processor in the electronic device described in the foregoing embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory ROM, random access memory RAM, magnetic disks, or optical discs, etc.

[0205] Another embodiment of the present application 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 each process of the foregoing embodiment of the memory sorting method, and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.

[0206] It should be understood that the chip mentioned in the embodiments of the present application may also be referred to as a system-on-chip, system chip, chip system, or system-on-chip, etc.

[0207] The embodiments of the present application provide a computer program product. The program product is stored in a storage medium and is executed by at least one processor to implement each process of the foregoing embodiment of the memory sorting method, and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.

[0208] It should be noted that in this article, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of additional identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the methods and devices in the embodiments of the present application are not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in a reverse order according to the functions involved. For example, the described methods may be performed in an order different from that described, and various steps may be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0209] Through the description of the above embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the related technology, can be embodied in the form of a computer software product. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc), and includes several instructions for causing a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in various embodiments of the present application.

[0210] The embodiments of the present application have been described above in conjunction with the accompanying drawings. However, the present application is not limited to the above specific embodiments. The above specific embodiments are merely illustrative rather than restrictive. Under the inspiration of the present application, those of ordinary skill in the art can also make many forms without departing from the purpose of the present application and the scope protected by the claims, and all of them fall within the protection scope of the present application.

Claims

1. A memory sorting method, characterized in that, Including: Obtain the memory information of the first memory partition, where the first memory partition is the memory partition after garbage collection in the target memory, and the memory information includes the memory size of the free memory and the memory size of the used memory; When the memory size of the free memory meets the first condition, determine the target sorting mode of the free memory according to the memory size of the free memory and the memory size of the used memory; Sort the free memory in the first memory partition according to the target sorting mode.

2. The method according to claim 1, characterized in that, The free memory includes first free memory and second free memory. The first free memory is the memory released after garbage collection in the allocated area of the first memory partition, and the second free memory is the memory in the unallocated area of the first memory partition; The memory size of the free memory meets the first condition, including: The memory size of the second free memory is less than the first threshold, and the total memory size of the first free memory is greater than the second threshold, where the first threshold is less than the second threshold.

3. The method according to claim 1, characterized in that, The free memory includes first free memory and second free memory. The first free memory is the memory released after garbage collection in the allocated area of the first memory partition, and the second free memory is the memory in the unallocated area of the first memory partition; The determining the target sorting mode of the free memory according to the memory size of the free memory and the memory size of the used memory includes: Determine the fragmentation rate according to the total memory size of the first free memory and the memory size of the allocated area; When the fragmentation rate is greater than or equal to the third threshold, determine that the target sorting mode is the global sorting mode; When the fragmentation rate is less than the third threshold, determine the target sorting mode according to the memory size of the second free memory.

4. The method according to claim 3, wherein The determining the target sorting mode according to the memory size of the second free memory includes: When the memory size of the second free memory is greater than or equal to the fourth threshold, determine that the target sorting mode is the first local sorting mode, and the first local sorting mode is used to indicate that the memory size of the continuous free memory sorted out is the same as the second threshold; When the memory size of the second free memory is less than the fourth threshold, determine the target sorting mode according to the sum of the memory size of the second free memory and the total memory size of the first free memory.

5. The method according to claim 4, characterized in that, The determining the target sorting mode according to the sum of the memory size of the second free memory and the total memory size of the first free memory includes: When the sum of the memory size of the second free memory and the total memory size of the first free memory is greater than or equal to the first threshold, determine that the target sorting mode is the second local sorting mode, and the second local sorting mode is used to indicate that the memory size of the continuous free memory sorted out is the same as the first threshold; When the sum of the memory size of the second free memory and the total memory size of the first free memory is less than the first threshold, determine that the target sorting mode is the global sorting mode.

6. A memory reorganization device, characterized in that, Including: An acquisition module, configured to acquire memory information of a first memory partition, where the first memory partition is a memory partition in a target memory after garbage collection, and the memory information includes the memory size of free memory and the memory size of used memory; A determination module, configured to determine a target fragmentation mode of the free memory according to the memory size of the free memory and the memory size of the used memory when the memory size of the free memory meets a first condition; A fragmentation module, configured to fragment the free memory in the first memory partition according to the target fragmentation mode.

7. The device according to claim 6, characterized in that, The free memory includes first free memory and second free memory, where the first free memory is the memory released after garbage collection in the allocated area of the first memory partition, and the second free memory is the memory in the unallocated area of the first memory partition; The memory size of the free memory meeting the first condition includes: The memory size of the second free memory is less than a first threshold, and the total memory size of the first free memory is greater than a second threshold, where the first threshold is less than the second threshold.

8. The device according to claim 6, characterized in that, The free memory includes first free memory and second free memory, where the first free memory is the memory released after garbage collection in the allocated area of the first memory partition, and the second free memory is the memory in the unallocated area of the first memory partition; The determination module is specifically configured to: Determine a fragmentation rate according to the total memory size of the first free memory and the memory size of the allocated area; When the fragmentation rate is greater than or equal to a third threshold, determine that the target fragmentation mode is a global fragmentation mode; When the fragmentation rate is less than the third threshold, determine the target fragmentation mode according to the memory size of the second free memory.

9. The device according to claim 8, characterized in that, The determination module is specifically configured to: When the memory size of the second free memory is greater than or equal to a fourth threshold, determine that the target fragmentation mode is a first local fragmentation mode, where the first local fragmentation mode is used to indicate that the memory size of the continuous free memory fragmented is the same as the second threshold; When the memory size of the second free memory is less than the fourth threshold, determine the target fragmentation mode according to the sum of the memory size of the second free memory and the total memory size of the first free memory.

10. The device according to claim 9, characterized in that, The determination module is specifically configured to: When the sum of the memory size of the second free memory and the total memory size of the first free memory is greater than or equal to the first threshold, determine that the target fragmentation mode is a second local fragmentation mode, where the second local fragmentation mode is used to indicate that the memory size of the continuous free memory fragmented is the same as the first threshold; When the sum of the memory size of the second free memory and the total memory size of the first free memory is less than the first threshold, determine that the target fragmentation mode is a global fragmentation mode.

11. An electronic device, characterized in that, The electronic device includes a processor and a memory, where the memory stores a program or instruction that can run on the processor, and when the program or instruction is executed by the processor, the steps of the method according to any one of claims 1 to 5 are implemented.

12. A readable storage medium, characterized in that, The program or instructions are stored on the readable storage medium, and when the program or instructions are executed by the processor, the steps of the method according to any one of claims 1 to 5 are implemented.

13. A computer program product, characterized in that, The program product is stored in the storage medium, and the program product is executed by at least one processor to implement the steps of the method according to any one of claims 1 to 5.