Memory organization method, electronic device and readable storage medium

By judging the CPU load in the electronic device and setting the regulation threshold and time interval, it determines whether to perform memory fragmentation and regulation, which solves the problem of excessive CPU consumption caused by memory fragmentation and regulation, and improves device performance and response speed.

CN116661988BActive Publication Date: 2024-08-23HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211725886.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-29
Publication Date
2024-08-23
Estimated Expiration
2042-12-29

AI Technical Summary

Technical Problem

When the existing technology performs memory fragmentation and organization, it may increase the consumption of the central processing unit (CPU), resulting in a decrease in the performance of the electronic device.

Method used

When receiving user-triggered operations, determine whether the CPU load is less than or equal to the load threshold. If so, perform memory fragmentation and regulation, and decide whether to perform regulation by setting the regulation threshold and time interval to avoid fragmentation operations under high CPU load. .

Benefits of technology

It effectively avoids the problem of excessive CPU load, reduces the possibility of performance degradation of electronic equipment, and improves the efficiency of memory allocation and user operation response time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116661988B
    Figure CN116661988B
Patent Text Reader

Abstract

The present application discloses a memory regularization method, an electronic device, and a readable storage medium, and belongs to the field of terminal technology. The method includes: receiving a trigger operation of a user on an electronic device; in response to the trigger operation, when the scenario triggered by the trigger operation does not belong to the memory regularization scenario, the memory of the electronic device is not fragmented and regularized, and the memory regularization scenario is a scenario that can perform memory fragmentation regularization; when the scenario triggered by the trigger operation belongs to the memory regularization scenario, if the current load value of the central processing unit CPU of the electronic device is less than or equal to the load threshold, the memory is fragmented and regularized. The present application considers the CPU load when performing fragmentation regularization, so that fragmentation regularization can be avoided when the CPU is under high load, thereby improving the impact on the CPU load and reducing the possibility of performance degradation of the electronic device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] With the development of terminal technology, the functions of electronic devices are becoming more and more abundant, and users are performing more and more operations on electronic devices. For example, users can start different applications in electronic devices, and each time an electronic device starts an application, it needs to allocate corresponding memory space for the started application. If such operations are performed frequently, the memory of the electronic device will be fragmented, which is not conducive to the subsequent memory allocation of the electronic device and affects the performance of the electronic device. Therefore, in order to facilitate the subsequent memory allocation and to ensure the performance of the electronic device, it is usually necessary to fragment the memory.

[0003] At present, when the memory fragmentation index is greater than or equal to the index threshold, the electronic device can perform memory fragmentation regularization, and the fragmentation index is used to measure the degree of memory fragmentation. In the process of performing memory fragmentation regularization, the electronic device regularizes as much continuous memory as possible.

[0004] However, each time an electronic device performs memory compaction, in order to compact as much continuous memory as possible, the electronic device usually compacts the memory over a larger range and the compaction takes a longer time, which may increase the consumption of the electronic device's central processing unit (CPU), thereby reducing the performance of the electronic device. Summary of the invention

[0005] The present application provides a memory organization method, an electronic device, and a readable storage medium, which can solve the problem in the related art that the fragmented memory organization leads to increased CPU consumption, thereby reducing the performance of the electronic device. The technical solution is as follows:

[0006] In a first aspect, a memory organization method is provided, which is applied to an electronic device, and the method comprises:

[0007] Receiving a trigger operation of the electronic device by a user;

[0008] In response to the trigger operation, if the scenario triggered by the trigger operation does not belong to the memory regularization scenario, the memory of the electronic device is not fragmented and regularized, and the memory regularization scenario is a scenario in which the fragmentation regularization of the memory can be performed, and the memory regularization scenario includes one or more of a scenario of clearing at least one application running in the electronic device, a scenario of returning to the desktop of the electronic device from an application interface of any application, and a scenario in which the electronic device enters a screen-off state;

[0009] In the case that the scenario triggered by the trigger operation belongs to the memory regularization scenario, if the current load value of the central processing unit CPU of the electronic device is less than or equal to the load threshold, the memory is fragmented and regularized.

[0010] In this way, since the CPU load is taken into consideration when performing fragmentation regularization, it is possible to avoid performing fragmentation regularization when the CPU is under high load, thereby improving the impact on the CPU load and reducing the possibility of performance degradation of the electronic device.

[0011] As an example of the present application, when the scenario triggered by the trigger operation belongs to the memory regularization scenario, if the current load value of the central processing unit CPU of the electronic device is less than or equal to the load threshold, the memory is fragmented and regularized, including:

[0012] In the case where the scenario triggered by the trigger operation belongs to the memory regularization scenario, if the current load value of the CPU is less than or equal to the load threshold, then obtaining a regularization threshold, where the regularization threshold is the maximum value that the continuous memory in the memory can reach after fragmentation regularization;

[0013] When the regularization threshold is not zero, the memory is fragmented and regularized.

[0014] In this way, by setting whether the regularization threshold is zero to decide whether to continue the fragmentation regularization, the triggering of the regularization instruction is more accurate, which solves the problem of poor real-time performance of the kernel layer triggering regularization instructions and easy satisfaction of triggering conditions, which causes the performance of electronic devices to decrease.

[0015] As an example of the present application, the electronic device includes a decision module, a communication module, a kernel node access control module and a regularization module;

[0016] The obtaining of the regularization threshold comprises:

[0017] The decision module sends a regularization instruction to the communication module, wherein the regularization instruction carries a first preset value, and the first preset value is not zero;

[0018] The communication module sends the regularization instruction to the core node access control module;

[0019] The kernel node access control module sends the regularization instruction to the regularization module;

[0020] The regularization module determines the first preset value as the regularization threshold.

[0021] In this way, by determining in the decision module whether to trigger the fragmentation regularization operation, and then the regularization module in the kernel layer performs fragmentation regularization, the triggering of the regularization instruction is made more accurate, solving the problem of poor real-time performance of the kernel layer triggering regularization instructions and the easy satisfaction of the triggering conditions, which causes the performance of the electronic device to be reduced.

[0022] As an example of the present application, when the regularization threshold is not zero, performing fragmentation regularization on the memory includes:

[0023] When the regularization threshold is not zero, obtaining a fragmentation index corresponding to the memory when the size of the continuous memory in the memory is a second preset value, wherein the fragmentation index is used to describe the degree of fragmentation of the memory;

[0024] When the fragmentation index is greater than or equal to a preset fragmentation threshold, the memory is fragmented and regularized with a continuous memory size of a third preset value.

[0025] In this way, by setting a higher preset fragmentation threshold, frequent fragmentation operations can be avoided, thereby avoiding the impact on the CPU load.

[0026] As an example of the present application, the method further includes:

[0027] In a case where the scene triggered by the trigger operation belongs to the memory regularization scene, obtaining a first time interval between the current time and the time when the fragmentation regularization was last performed;

[0028] When the first time interval is greater than or equal to a first interval threshold, the load of the CPU is obtained.

[0029] In this way, by obtaining the CPU load when the first time interval is greater than or larger than the first interval threshold, frequent memory fragmentation and regularization can be avoided, and an increase in the CPU load can also be avoided.

[0030] As an example of the present application, the electronic device includes a time monitoring module and a decision module;

[0031] In the case where the scene triggered by the trigger operation belongs to the memory regularization scene, obtaining a first time interval between the current time and the time when the fragmentation regularization was last performed includes:

[0032] In the case where the scenario triggered by the trigger operation belongs to the memory regularization scenario, the decision module sends a time acquisition message to the time monitoring module;

[0033] After receiving the time acquisition message, the time monitoring module determines the time interval between the current time and the time when the fragmentation was last regularized to obtain the first time interval;

[0034] The time monitoring module sends a time detection message to the decision module, wherein the time detection message carries the first time interval;

[0035] The decision module obtains the first time interval from the time detection message.

[0036] In this way, by determining the time interval between the current time and the time when the fragmentation was last regularized through the time monitoring module, the accuracy of determining the first time interval can be improved, and frequent memory fragmentation regularization can be effectively avoided.

[0037] As an example of the present application, the electronic device further includes a CPU monitoring module;

[0038] The acquiring the CPU load when the first time interval is greater than or equal to a first interval threshold includes:

[0039] When the first time interval is greater than or equal to the first interval threshold, the decision module sends a load acquisition message to the CPU monitoring module;

[0040] The CPU monitoring module sends a load detection message to the decision module, wherein the load detection message carries the load of the CPU;

[0041] The decision module obtains the load of the CPU from the load detection message.

[0042] In this way, the decision module obtains the CPU load through the CPU monitoring module, thereby improving the accuracy of obtaining the CPU load.

[0043] As an example of the present application, when the first time interval is greater than or equal to a first interval threshold, obtaining the load of the CPU includes:

[0044] When the first time interval is greater than or equal to a first interval threshold, performing load detection on the CPU at second time intervals within a first specified time period to obtain multiple load detection results;

[0045] The multiple load detection results are determined as the load of the CPU, or the minimum load detection result among the multiple load detection results is determined as the load of the CPU.

[0046] In this way, by detecting the CPU load within the first specified time period, the accuracy of the acquired CPU load is ensured.

[0047] As an example of the present application, when the scenario triggered by the trigger operation belongs to the memory regularization scenario, if the current load value of the central processing unit CPU of the electronic device is less than or equal to the load threshold, the memory is fragmented and regularized, including:

[0048] In the case where the scenario triggered by the trigger operation belongs to the memory regularization scenario, and when the load of the CPU includes the multiple load detection results, if at least one load detection result among the multiple load detection results is less than or equal to the load threshold, the memory is fragmented and regularized.

[0049] In this way, by performing memory fragmentation and regularization when the CPU load is light, the CPU performance can be better protected, thereby protecting the performance of the electronic device.

[0050] As an example of the present application, when the scenario triggered by the trigger operation belongs to the memory regularization scenario, if the current load value of the central processing unit CPU of the electronic device is less than or equal to the load threshold, then after the memory is fragmented and regularized, it also includes:

[0051] In the case of receiving a startup operation for any application in the electronic device, if the electronic device is performing the fragmentation regularization at a first time point, then the fragmentation regularization of the memory is terminated, the first time point is before a second time point and the time difference between the first time point and the second time point is a second specified time length, and the second time point is the time point of receiving the startup operation.

[0052] In this way, during the fragmentation and regularization process of the electronic device, if a startup operation for any application is received, the relevant operations of the fragmentation and regularization can be terminated in time when it is determined that the first time point is in the fragmentation and regularization stage, thereby improving the problem of application freezes caused by fragmentation operations and reducing the response time and delay to user operations.

[0053] In a second aspect, an electronic device is provided, wherein the structure of the electronic device includes a processor and a memory, wherein the memory is used to store a program that supports the electronic device to execute the memory organization method provided in the first aspect, and to store data involved in implementing the memory organization method described in the first aspect. The processor is configured to execute the program stored in the memory. The electronic device may also include a communication bus, which is used to establish a connection between the processor and the memory.

[0054] Wherein, the processor is configured to:

[0055] Receiving a trigger operation of the electronic device by a user;

[0056] In response to the trigger operation, if the scenario triggered by the trigger operation does not belong to the memory regularization scenario, the memory of the electronic device is not fragmented and regularized, and the memory regularization scenario is a scenario in which the fragmentation regularization of the memory can be performed, and the memory regularization scenario includes one or more of a scenario of clearing at least one application running in the electronic device, a scenario of returning to the desktop of the electronic device from an application interface of any application, and a scenario in which the electronic device enters a screen-off state;

[0057] In the case that the scenario triggered by the trigger operation belongs to the memory regularization scenario, if the current load value of the central processing unit CPU of the electronic device is less than or equal to the load threshold, the memory is fragmented and regularized.

[0058] As an example of the present application, the processor is configured to:

[0059] In the case where the scenario triggered by the trigger operation belongs to the memory regularization scenario, if the current load value of the CPU is less than or equal to the load threshold, then obtaining a regularization threshold, where the regularization threshold is the maximum value that the continuous memory in the memory can reach after fragmentation regularization;

[0060] When the regularization threshold is not zero, the memory is fragmented and regularized.

[0061] As an example of the present application, the electronic device includes a decision module, a communication module, a kernel node access control module and a regularization module;

[0062] The processor is configured to:

[0063] The decision module sends a regularization instruction to the communication module, wherein the regularization instruction carries a first preset value, and the first preset value is not zero;

[0064] The communication module sends the regularization instruction to the core node access control module;

[0065] The kernel node access control module sends the regularization instruction to the regularization module;

[0066] The regularization module determines the first preset value as the regularization threshold.

[0067] As an example of the present application, the processor is configured to:

[0068] When the regularization threshold is not zero, obtaining a fragmentation index corresponding to the memory when the size of the continuous memory in the memory is a second preset value, wherein the fragmentation index is used to describe the degree of fragmentation of the memory;

[0069] When the fragmentation index is greater than or equal to a preset fragmentation threshold, the memory is fragmented and regularized with a continuous memory size of a third preset value.

[0070] As an example of the present application, the processor is further configured to:

[0071] In a case where the scene triggered by the trigger operation belongs to the memory regularization scene, obtaining a first time interval between the current time and the time when the fragmentation regularization was last performed;

[0072] When the first time interval is greater than or equal to a first interval threshold, the load of the CPU is obtained.

[0073] As an example of the present application, the electronic device includes a time monitoring module and a decision module;

[0074] The processor is configured to:

[0075] In the case where the scenario triggered by the trigger operation belongs to the memory regularization scenario, the decision module sends a time acquisition message to the time monitoring module;

[0076] After receiving the time acquisition message, the time monitoring module determines the time interval between the current time and the time when the fragmentation was last regularized to obtain the first time interval;

[0077] The time monitoring module sends a time detection message to the decision module, wherein the time detection message carries the first time interval;

[0078] The decision module obtains the first time interval from the time detection message.

[0079] As an example of the present application, the electronic device further includes a CPU monitoring module;

[0080] The processor is configured to:

[0081] When the first time interval is greater than or equal to the first interval threshold, the decision module sends a load acquisition message to the CPU monitoring module;

[0082] The CPU monitoring module sends a load detection message to the decision module, wherein the load detection message carries the load of the CPU;

[0083] The decision module obtains the load of the CPU from the load detection message.

[0084] As an example of the present application, the processor is configured to:

[0085] When the first time interval is greater than or equal to a first interval threshold, performing load detection on the CPU at second time intervals within a first specified time period to obtain multiple load detection results;

[0086] The multiple load detection results are determined as the load of the CPU, or the minimum load detection result among the multiple load detection results is determined as the load of the CPU.

[0087] As an example of the present application, the processor is configured to:

[0088] In the case where the scenario triggered by the trigger operation belongs to the memory regularization scenario, and when the load of the CPU includes the multiple load detection results, if at least one load detection result among the multiple load detection results is less than or equal to the load threshold, the memory is fragmented and regularized.

[0089] As an example of the present application, the processor is further configured to:

[0090] In the case of receiving a startup operation for any application in the electronic device, if the electronic device is performing the fragmentation regularization at a first time point, then the fragmentation regularization of the memory is terminated, the first time point is before a second time point and the time difference between the first time point and the second time point is a second specified time length, and the second time point is the time point of receiving the startup operation.

[0091] According to a third aspect, a computer-readable storage medium is provided, wherein instructions are stored in the computer-readable storage medium, and when the computer-readable storage medium is executed on a computer, the computer executes the memory organization method according to the first aspect.

[0092] In a fourth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the memory organization method described in the first aspect.

[0093] The technical effects obtained by the above-mentioned second aspect, third aspect and fourth aspect are similar to the technical effects obtained by the corresponding technical means in the above-mentioned first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0094] Figure 1 This is a schematic diagram of a scenario of performing memory regularization in the kernel layer provided by an embodiment of the present application;

[0095] Figure 2 This is a flowchart of a method for memory regularization in a related technology provided by an embodiment of the present application;

[0096] Figure 3 This is a schematic diagram of the process time consumption in a related technology provided by an embodiment of the present application;

[0097] Figure 4 It is a time-consuming schematic diagram of another related technology provided in an embodiment of the present application;

[0098] Figure 5 It is a time-consuming schematic diagram of another related technology provided in an embodiment of the present application;

[0099] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0100] Figure 7 It is a schematic diagram of a software architecture of an electronic device provided in an embodiment of the present application;

[0101] Figure 8 It is a schematic diagram of an application scenario provided by an embodiment of the present application;

[0102] Fig. 9 This is a schematic diagram of a fragmentation index change provided in an embodiment of the present application;

[0103] Fig.10 is a schematic diagram of another application scenario provided by an embodiment of the present application;

[0104] Fig.11 is a schematic diagram of another application scenario provided by an embodiment of the present application;

[0105] Fig.12 is another schematic diagram of fragmentation index change provided in an embodiment of the present application;

[0106] Fig.13 is a schematic diagram of another application scenario provided by an embodiment of the present application;

[0107] Fig.14 is another schematic diagram of fragmentation index change provided in an embodiment of the present application;

[0108] Fig.15 This is a schematic diagram of a memory regularization method provided in an embodiment of the present application;

[0109] Fig.16 It is a flowchart of another memory regularization method provided in an embodiment of the present application;

[0110] Fig.17 It is a flowchart of another memory regularization method provided in an embodiment of the present application;

[0111] Fig.18 It is a flowchart of another memory regularization method provided in an embodiment of the present application;

[0112] Fig.19 It is a flowchart of another memory regularization method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0113] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.

[0114] It should be understood that the "multiple" mentioned in this application refers to two or more. In the description of this application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in order to facilitate the clear description of the technical solution of this application, the words "first" and "second" are used to distinguish between the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the words "first" and "second" do not limit the quantity and execution order, and the words "first" and "second" do not limit them to be different.

[0115] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0116] In one application scenario, multiple applications are usually installed in an electronic device. When a user uses an application, the electronic device will allocate corresponding memory to the application used by the user. For example, in the case where the electronic device is a mobile phone, the user may frequently open different applications while using the mobile phone, and each time the mobile phone starts an application under the trigger of the user, it is necessary to allocate corresponding memory to the started application. If the mobile phone finds that the continuous memory is insufficient during the memory allocation process, the mobile phone can fragment and regularize the memory in the kernel node of the kernel layer, where fragmenting and regularizing the memory refers to organizing a large number of discrete free pages in the memory to obtain continuous memory. The kernel nodes of the kernel layer include proc, sys, vm, and compaction_proactiveness, etc. Each kernel node includes a process for fragmentation and regularization, and the kernel process for page recovery in the kernel layer can wake up the process for fragmentation and regularization, see Figure 1, the kernel process for page recycling can be a kswapd process, and the process for performing fragmentation regularization can be a kcompactd process. When fragmentation regularization is required, the kswapd process can wake up the kcompactd process. Since the above-mentioned fragmentation regularization operation is triggered when memory allocation is required, the fragmentation regularization operation is a non-active fragmentation regularization. In the process of performing non-fragmentation regularization, the mobile phone can obtain non-active fragmentation parameters, such as obtaining the memory size to be allocated, and then the mobile phone can perform non-active fragmentation regularization in the kcompactd process according to the memory size to be allocated. In addition, the kernel's kcompactd process can not only perform non-active fragmentation regularization, but also perform active fragmentation regularization. In the case where the memory fragmentation index is greater than or equal to 20%, the mobile phone can obtain active fragmentation parameters through the kcompactd process, such as obtaining the size of the continuous memory to be regularized each time, and then the mobile phone can actively perform fragmentation regularization in the kcompactd process and sort out more continuous memory at one time. Among them, non-active fragmentation regularization and active fragmentation regularization share the same process.

[0117] For ease of understanding, the present application embodiment provides a flowchart of a mobile phone actively performing fragmentation and regularization in the kcompactd process of the kernel, see Figure 2, the operation of active fragmentation and regularization of the mobile phone in the kcompactd process of the kernel layer includes the following steps: Step 201. Determine whether the current fragmentation index is greater than or equal to 20%; Step 202. If the current fragmentation index is greater than or equal to 20%, determine whether the delay number is set, if not, perform the operation of the following step 203, if yes, perform the operation of the following step 204. Step 203: Delay 500ms, and perform the operation of the following step 206. Step 204. Determine whether the delay number is 0, if yes, perform the operation of the following step 206, if no, perform the operation of the following step 205. Step 205. Subtract 1 from the current value of the delay number, and return to the operation of step 204. Step 206. Perform fragmentation regularization for every 2MB (megabytes) of continuous memory. Step 207. After each cleanup, determine whether all memory has been cleaned up. If so, perform the operation of the following step 208; if not, perform the operation of the following step 209; Step 208. Determine whether the fragmentation index is less than 20%. If so, perform the operation of the following step 209; if not, return to the operation of step 206; Step 209. Determine whether the severity of memory fragmentation after cleanup is greater than the severity of memory fragmentation before cleanup. If so, perform the operation of step 210; if not, perform the operation of step 211. Step 210: Set the delay times to 64 times, and return to the operation of step 201. Step 211: End the active cleanup of memory fragmentation.

[0118] However, whether it is non-active defragmentation or active defragmentation, it is possible to increase the CPU load during the operation. For example, see Figure 3 , the embodiment of the present application provides a schematic diagram of process time consumption, which is composed of Figure 3 It can be seen that the kcompactd process takes a long time, which will affect the performance of the CPU (the figure of the embodiment of the present application takes 8 sub-CPUs as an example for explanation). In order to facilitate understanding of the negative effects of non-active fragmentation regularization and active fragmentation regularization in the related art, the embodiment of the present application also provides a time-consuming diagram of non-active fragmentation regularization and a time-consuming diagram of active fragmentation regularization, see Figure 4 In the process of non-active fragmentation, the continuous memory that is sorted out each time is small, which leads to lag when starting the application, thereby increasing the CPU load. Figure 5 In the process of active fragmentation regularization, since the index threshold is set to be small, usually 20%, the memory fragmentation index can easily reach the set index threshold, and the electronic device will frequently perform active fragmentation regularization, and the CPU will also frequently superimpose the load of the fragmentation regularization, causing the load performance to deteriorate.

[0119] Therefore, in order to improve the problem of excessive CPU load during the process of memory fragmentation and regularization, an embodiment of the present application provides a memory regularization method, in which, when an electronic device receives a trigger operation from a user, and the scene triggered by the trigger operation is a scene that can perform memory regularization, if the CPU is in a low-load state, the memory can be fragmented and regularized. Since the CPU load is taken into account when performing fragmentation regularization, it is possible to avoid performing fragmentation regularization when the CPU is in a high-load state, thereby improving the impact on the CPU load and reducing the possibility of performance degradation of the electronic device.

[0120] Before explaining the memory regularization method provided in the embodiment of the present application in detail, the electronic device involved in the embodiment of the present application is first explained. The method provided in the embodiment of the present application can be performed by an electronic device. As an example but not limited to, the electronic device can be but not limited to a mobile phone sports camera (GoPro), a digital camera, a tablet computer, a desktop, a laptop, a handheld computer, a notebook computer, a vehicle-mounted device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook, a cellular phone, a personal digital assistant (personal digital assistant, PDA), an augmented reality (augmented reality, AR)\virtual reality (virtual reality, VR) device, a mobile phone, a door lock, a smart appliance, etc., and the embodiment of the present application does not limit this.

[0121] Figure 6 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 6The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. Among them, the sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0122] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0123] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0124] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0125] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0126] In some embodiments, the processor 110 may include one or more interfaces, such as an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

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

[0128] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.

[0129] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.

[0130] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light emitting diode or an active-matrix organic light emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is an integer greater than 1.

[0131] The electronic device 100 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.

[0132] ISP is used to process the data fed back by camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to ISP for processing and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, ISP can be set in camera 193.

[0133] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is an integer greater than 1.

[0134] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.

[0135] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created by the electronic device 100 during use (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0136] The electronic device 100 can implement audio functions, such as music playback, recording, etc., through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone interface 170D and the application processor.

[0137] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure based on the change in capacitance. When a touch operation acts on the display screen 194, the electronic device 100 detects the touch operation intensity according to the pressure sensor 180A. The electronic device 100 can also calculate the touch position according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than a pressure threshold acts on a short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the pressure threshold acts on a short message application icon, an instruction to create a new short message is executed.

[0138] The magnetic sensor 180D includes a Hall sensor. The electronic device 100 can use the magnetic sensor 180D to detect the opening and closing of the flip leather case. In some embodiments, when the electronic device 100 is a flip phone, the electronic device 100 can detect the opening and closing of the flip cover according to the magnetic sensor 180D. The electronic device 100 sets features such as automatic unlocking of the flip cover according to the detected opening and closing state of the leather case or the opening and closing state of the flip cover.

[0139] The proximity light sensor 180G may include a light emitting diode (LED) and a light detector, such as a photodiode. The light emitting diode may be an infrared light emitting diode. The electronic device 100 emits infrared light outward through the light emitting diode. The electronic device 100 uses a photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, the electronic device 100 may determine that there is an object near the electronic device 100. When insufficient reflected light is detected, it may be determined that there is no object near the electronic device 100. The electronic device 100 may use the proximity light sensor 180G to detect when a user holds the electronic device 100 close to their ear to talk, so as to automatically turn off the screen to save power. The proximity light sensor 180G may also be used in leather case mode and pocket mode to automatically unlock and lock the screen.

[0140] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photography, fingerprint call answering, etc.

[0141] The touch sensor 180K is also called a "touch panel". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor 180K can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.

[0142] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key inputs and generate key signal inputs related to user settings and function control of the electronic device 100.

[0143] Indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, messages, missed calls, notifications, etc.

[0144] Next, the software system of the electronic device 100 will be described.

[0145] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software system of the electronic device 100.

[0146] Figure 7 1 is a block diagram of a software system of an electronic device 100 provided in an embodiment of the present application. Figure 7 The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: application layer, application framework layer, native layer (local service layer), and kernel layer.

[0147] The application layer can include a series of application packages. Figure 7 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.

[0148] The application framework layer provides application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions. Figure 7 As shown, the application framework layer may include a scene detection module, a CPU monitoring module, a time monitoring module, a decision module, an application startup monitoring module and a communication module. Among them, the scene detection module is used to detect the current scene of the electronic device, for example, monitoring the electronic device in a screen-off scene, the scene of the user cleaning up the running application, etc. The CPU monitoring module is used to monitor the operating status and load conditions of the CPU. The time monitoring module is used to determine the time of each operation of the electronic device, for example, determining the operation time of each memory fragmentation regularization operation, etc. The decision module is used to determine whether to perform memory fragmentation regularization. The application startup monitoring module is used to monitor whether an application is started. The communication module is used to realize communication between the application framework layer and other layers. For example, the communication module can send messages and / or instructions to the Native layer.

[0149] As an example of the present application, the Native layer includes a kernel node access control module, which is used to transmit messages between the application framework layer and the kernel layer. For example, the kernel node access control module can receive messages and / or instructions sent by the communication module, and send the received messages and / or instructions to the kernel layer.

[0150] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.

[0151] As an example of the present application, the kernel layer may also include a regularization module, which may regularize memory fragments.

[0152] The following is an illustrative description of the workflow of the software and hardware of the electronic device 100 in conjunction with capturing a photo scene.

[0153] When the touch sensor 180K receives a touch operation, the corresponding hardware interrupt is sent to the kernel layer. The kernel layer processes the touch operation into a raw input event (including touch coordinates, timestamp of the touch operation, and other information). The raw input event is stored in the kernel layer. The application framework layer obtains the raw input event from the kernel layer and identifies the control corresponding to the raw input event. For example, if the touch operation is a single-click operation and the control corresponding to the single-click operation is the control of the camera application icon, the camera application calls the interface of the application framework layer, starts the camera application, and then calls the kernel layer to start the camera driver to capture static images or videos through the camera 193.

[0154] To facilitate understanding, before introducing the method provided in the embodiment of the present application in detail, based on the execution subject provided in the above embodiment, the application scenario involved in the embodiment of the present application is introduced by taking the electronic device as a mobile phone and multiple cards stacked and displayed on the desktop of the mobile phone as an example.

[0155] Please refer to Figure 8 , Figure 8It is a schematic diagram of an application scenario shown according to an exemplary embodiment. In a possible scenario, when a user is using a mobile phone, it is very likely that the screen of the electronic device will be turned off. For example, when the mobile phone displays the desktop, if the user presses the screen-off button 1, the mobile phone responds to the pressing operation of the screen-off button 1, and the mobile phone enters the screen-off state. At the same time, the scene monitoring module 2 in the mobile phone can monitor the operation of the screen-off button. Therefore, the scene monitoring module 2 can send a scene change message to the decision module 3, and the scene change message carries the current scene as the scene of entering the screen-off state; after receiving the scene change message, the decision module 3 can determine whether the scene of entering the screen-off state is a scene that can be fragmented and regularized. If so, the decision module 3 can send a time acquisition message to the time monitoring module 4; the time monitoring module 4 determines the time interval between the current time and the time of the last fragmentation and regularization, obtains the first time interval, and sends a time detection message to the decision module 3, and the time detection message carries the first time interval; the decision module 3 can obtain the first time interval from the time detection message, and Determine whether the first time interval is greater than or equal to the first interval threshold. If so, send a load acquisition message to the CPU monitoring module 5; the CPU monitoring module 5 sends a load detection message to the decision module 3, and the load detection message carries the CPU load; the decision module 3 obtains the CPU load from the load detection message, and determines whether the CPU load is less than or equal to the load threshold. If so, send a regularization instruction to the communication module 6, and the regularization instruction carries a first preset value that is not zero; the communication module 6 sends the regularization instruction to the kernel node access control module 7; the kernel node access control module 7 sends the regularization instruction to the regularization module 8; the regularization module 8 determines the first preset value as the regularization threshold, and when the regularization threshold is not zero, regularizes the memory fragments.

[0156] In order to illustrate the interaction process, the multiple decision modules drawn in the drawings of the embodiments of the present application are the same decision module.

[0157] As an example, when the phone is in the screen-on state, if the user does not perform any operation on the phone for a long time, the phone will also enter the screen-off state. After the phone enters the screen-off state, the phone can follow the above Figure 8 The neatening process shown is used to neaten memory fragmentation.

[0158] It should be noted that the first interval threshold, the load threshold and the first preset value can all be set according to requirements. For example, the first interval threshold can be 20 seconds, 25 seconds or 30 seconds. The CPU load can be described by the number of currently running processes or the CPU usage rate. Therefore, the load threshold can be set according to the CPU load. When the CPU load is described by the CPU usage rate, the load threshold can be 50%, 40% or 35%; when the CPU load is described by the number of processes, the load threshold can be 5, 6 or 7. The first preset value can be a value other than 0, and the first preset value can be 20%, 30%, etc.

[0159] As an example, after the mobile phone enters the screen-off state, the fragmentation index changes as follows after the fragmentation regularization operation is performed in the above manner: Fig. 9 As shown, the Fig. 9 Curve 1 in the figure is the fragmentation index corresponding to different order indices before fragmentation regularization, where the order index is used to index the size of continuous memory, and curve 2 is the fragmentation index corresponding to different order indices after fragmentation regularization. Fig. 9 It can be seen that after fragmentation and regularization, the fragmentation index has been significantly reduced, indicating that the continuous memory in the memory has increased.

[0160] Please refer to Fig.10 , Fig.10It is a schematic diagram of an application scenario according to another exemplary embodiment. In another possible scenario, when a user is using a mobile phone, if there are multiple applications running in the background of the mobile phone, in order to avoid the mobile phone from freezing, the user may clean up the multiple applications running in the background. Exemplarily, when the mobile phone displays the desktop, the user can open the background running task on the mobile phone desktop. For example, the user can start from the bottom of the desktop, slide up on the desktop and pause. In response to the operation of sliding up and pausing on the desktop, if there are background running tasks, the background running interface is displayed. The application interface and the cleanup control 9 of the multiple background running applications are folded and displayed in the background running interface. The user can click the cleanup control 9; in response to the click operation on the cleanup control 9, the mobile phone can exit the multiple background running applications. At the same time, the scene monitoring module 2 in the mobile phone can monitor the triggering operation of the cleaning control. Therefore, the scene monitoring module 2 can send a scene change message to the decision module 3, and the scene change message carries the current scene as the scene of the cleaning application; after receiving the scene change message, the decision module 3 can determine whether the scene of cleaning all running applications is a scene that can be fragmented and regularized. If so, the decision module 3 can send a time acquisition message to the time monitoring module 4; the time monitoring module 4 determines the time interval between the current time and the time of the last fragmentation and regularization, obtains the first time interval, and sends a time detection message to the decision module 3, and the time detection message carries the first time interval; the decision module 3 can obtain the first time interval from the time detection message interval, and determines whether the first time interval is greater than or equal to the first interval threshold, if so, sends a load acquisition message to the CPU monitoring module 5; the CPU monitoring module 5 sends a load detection message to the decision module 3, and the load detection message carries the CPU load; the decision module 3 obtains the CPU load from the load detection message, and determines whether the CPU load is less than or equal to the load threshold, if so, sends a regularization instruction to the communication module 6, and the regularization instruction carries a first preset value that is not zero; the communication module 6 sends the regularization instruction to the kernel node access control module 7; the kernel node access control module 7 sends the regularization instruction to the regularization module 8; the regularization module 8 determines the first preset value as the regularization threshold, and when the regularization threshold is not zero, regularizes the fragmented memory.

[0161] Please refer to Fig.11 , Fig.11is a schematic diagram of an application scenario according to another exemplary embodiment. In another possible scenario, when a user is using a mobile phone, if there are multiple applications running in the background of the mobile phone, in order to completely exit a certain application, for example, in order to completely exit a social application, the user may completely exit the social application in the background running interface. Exemplarily, when the mobile phone displays the application interface of the social application, the user can open the background running task in the application interface of the social application. For example, the user can start from the bottom of the application interface of the social application, swipe up on the application interface and then pause. In response to the swiping up and pausing on the application interface, the background running interface is displayed, and the application interface of the social application is displayed in the background running interface. The user can swipe up on the application interface of the social application in the background running interface; in response to the swiping up on the application interface of the social application in the background running interface, the mobile phone can exit the social application from both the foreground and the background. At the same time, the scene monitoring module 2 in the mobile phone can monitor the cleaning operation of the video application in the background running interface. Therefore, the scene monitoring module 2 can send a scene change message to the decision module 3, and the scene change message carries the current scene as the scene for cleaning a single application; after receiving the scene change message, the decision module 3 can determine whether the scene for cleaning a single running application is a scene that can be fragmented and regularized. If so, the decision module 3 can send a time acquisition message to the time monitoring module 4; the time monitoring module 4 determines the time interval between the current time and the time of the last fragmentation and regularization, obtains the first time interval, and sends a time detection message to the decision module 3, and the time detection message carries the first time interval; the decision module 3 can obtain the first time interval from the time detection message Take a first time interval and determine whether the first time interval is greater than or equal to a first interval threshold. If so, send a load acquisition message to the CPU monitoring module 5; the CPU monitoring module 5 sends a load detection message to the decision module 3, and the load detection message carries the CPU load; the decision module 3 obtains the CPU load from the load detection message, and determines whether the CPU load is less than or equal to the load threshold. If so, send a regularization instruction to the communication module 6, and the regularization instruction carries a first preset value that is not zero; the communication module 6 sends the regularization instruction to the kernel node access control module 7; the kernel node access control module 7 sends the regularization instruction to the regularization module 8; the regularization module 8 determines the first preset value as the regularization threshold, and when the regularization threshold is not zero, regularizes the memory fragments.

[0162] As an example, in the scenario of cleaning up an application, after performing the fragmentation and regularization operation in the above manner, the fragmentation index changes as follows: Fig.12 As shown, the Fig.12 Curve 3 in the figure is the fragmentation index corresponding to different order indices before fragmentation regularization, and curve 4 is the fragmentation index corresponding to different order indices after fragmentation regularization. Fig.12 It can be seen that after fragmentation and regularization, the fragmentation index has been significantly reduced, indicating that the continuous memory in the memory has increased.

[0163] As an example, after the mobile phone performs fragmentation and regularization on a scenario where a single application is cleaned up, tens of megabytes of continuous memory can be regularized each time. For example, see Table 1, which describes the continuous memory obtained after fragmentation and regularization in scenarios where different applications are cleaned up individually.

[0164] Table 1

[0165]

[0166]

[0167] It should be noted that the data in Table 1 above are only used as an example in the embodiments of the present application, and do not constitute a limitation to the embodiments of the present application.

[0168] Please refer to Fig.13 , Fig.13is a schematic diagram of an application scenario according to another exemplary embodiment. In another possible scenario, during the process of using a mobile phone, the user may need to return to the desktop of the mobile phone from the application interface of any application. Exemplarily, when the mobile phone displays the application interface of the camera application, the user can slide up from the bottom of the application interface of the camera application, and the mobile phone can display the desktop of the mobile phone in response to the upward sliding operation. At the same time, the scene monitoring module 2 in the mobile phone can monitor the operation of returning to the desktop, so the scene monitoring module 2 can send a scene change message to the decision module 3, and the scene change message carries the current scene as the scene of returning to the desktop; after receiving the scene change message, the decision module 3 can determine whether the scene of returning to the desktop is a scene that can be fragmented and regularized, and then the decision module 3 can send a time acquisition message to the time monitoring module 4; the time monitoring module 4 determines the time interval between the current time and the time of the last fragmentation and regularization, obtains the first time interval, and sends a time detection message to the decision module 3, and the time detection message carries the first time interval; the decision module 3 can obtain the first time interval from the time detection message, and determine the first Whether the time interval is greater than or equal to the first interval threshold, if so, a load acquisition message is sent to the CPU monitoring module 5; the CPU monitoring module 5 sends a load detection message to the decision module 3, and the load detection message carries the CPU load; the decision module 3 obtains the CPU load from the load detection message, and determines whether the CPU load is less than or equal to the load threshold, if so, a regularization instruction is sent to the communication module 6, and the regularization instruction carries a first preset value that is not zero; the communication module 6 sends the regularization instruction to the kernel node access control module 7; the kernel node access control module 7 sends the regularization instruction to the regularization module 8; the regularization module 8 determines the first preset value as the regularization threshold, and when the regularization threshold is not zero, the memory is fragmented and regularized.

[0169] As an example, when a mobile phone exits the application interface of the camera application to the desktop, after performing the fragmentation and regularization operation in the above manner, the fragmentation index changes as follows: Fig.14 As shown, the Fig.14 Curve 5 in the figure is the fragmentation index corresponding to different order indices before fragmentation regularization, and curve 6 is the fragmentation index corresponding to different order indices after fragmentation regularization. Fig.14 It can be seen that after fragmentation and regularization, the fragmentation index has been significantly reduced, indicating that the continuous memory in the memory has increased.

[0170] It should be noted that, in the embodiments of the present application, only the above Figure 8-Figure 14 The application scenario shown is used as an example for illustration and does not constitute a limitation on the embodiments of the present application.

[0171] Based on the execution subjects and application scenarios provided in the above embodiments, the memory organization method provided in the embodiments of the present application is introduced below. Fig.15 , Fig.15 The following is a flow chart of a memory arrangement method according to an exemplary embodiment. As an example but not a limitation, the method is applied to an electronic device. The electronic device Figure 7 Taking the interaction of multiple modules shown in the figure as an example, the method may include some or all of the following contents:

[0172] Step 1501: The scene detection module detects the current scene.

[0173] Since users may perform various operations when using electronic devices, different operations may cause the electronic devices to enter different scenes, and the electronic devices may fragment and organize the memory in some specific scenes. Therefore, the scene detection module can detect the current scene of the electronic device.

[0174] As an example, the scene detection module can actively detect the scene that the electronic device is currently in, or can passively detect the scene that the electronic device is currently in. Where the scene detection module actively detects the scene that the electronic device is currently in, the scene detection module can perform detection in real time, or can perform detection at every third specified time interval. Where the scene detection module passively detects the scene that the electronic device is currently in, the scene detection module can detect the scene that the electronic device is currently in according to the user's trigger operation when the user performs any trigger operation on the electronic device.

[0175] It should be noted that the third specified time interval can be pre-set according to demand, for example, the third specified time interval can be 30 seconds, 60 seconds or 120 seconds.

[0176] Step 1502: The scene detection module sends a scene change message to the decision module.

[0177] It should be noted that the scene change message carries the current scene.

[0178] Step 1503: The decision module receives a scene change message.

[0179] Step 1504: The decision module determines whether fragmentation can be regularized based on the current scene carried in the scene change message.

[0180] Since not all scenes can perform memory fragmentation regularization, the decision module needs to determine whether to perform fragmentation regularization based on the current scene carried in the scene change message.

[0181] As an example, the decision module can match the current scene with the stored scenes, and if the scene that is the same as the scene that the electronic device is currently in exists in the stored scenes, it is determined that the scene that the electronic device is currently in can be fragmented and regularized. If the scene that is the same as the scene that the electronic device is currently in does not exist in the stored scenes, it is determined that the scene that the electronic device is currently in cannot be fragmented and regularized; if fragmentation and regularization cannot be performed, the decision module does not perform any operation.

[0182] It should be noted that the stored scenes are scenes that can perform fragmentation and regularization of memory, and these scenes can be called memory regularization scenes. Memory regularization scenes include at least scenes of cleaning up at least one application running in the electronic device, scenes of returning to the desktop of the electronic device from the application interface of any application, and scenes of the electronic device entering a screen-off state. That is, when the current scene is a cleaning operation on at least one application running in the electronic device, or when the current scene is a return operation from the application interface of any application to the desktop of the electronic device, or when the current scene is a screen-off operation on the electronic device, the decision module can determine that the current scene is capable of performing fragmentation and regularization of memory. Exemplarily, the scene can refer to the above-mentioned Figure 8-Figure 14 The application scenario shown in .

[0183] In some embodiments, the situation where there is no scene in the stored scenes that is the same as the scene currently in which the electronic device is located may mean that the scene triggered by the user's trigger operation does not belong to any of the memory regularization scenes. In this case, the decision module does not need to execute the following steps, that is, the electronic device will not perform fragmented memory regularization.

[0184] Step 1505: When the current scene can be fragmented and regularized, the decision module sends a time acquisition message to the time monitoring module.

[0185] In order to avoid frequent memory fragmentation and regularization, the decision module may also send a time acquisition message to the time monitoring module when determining that the current scene is capable of fragmentation and regularization.

[0186] Step 1506: The time monitoring module receives the time acquisition message.

[0187] Step 1507: The time monitoring module determines the time interval between the current time and the time when the fragmentation was last regularized, and obtains a first time interval.

[0188] Since the time monitoring module can record the time for fragmentation regularization, when the time monitoring module receives a time acquisition message, it can obtain the last time for fragmentation regularization and determine the time interval between the current time and the last time for fragmentation regularization to obtain the first time interval.

[0189] As an example, the last time the fragmentation was regularized can be recorded by the time monitoring module when the time monitoring module received the time recording message sent by the decision module last time. That is, each time the memory is regularized, the decision module can send a time recording message to the time monitoring module, and the time monitoring module can record the time of the fragmentation regularization each time it receives the time recording message.

[0190] Step 1508: The time monitoring module sends a time detection message to the decision module, and the time detection message carries the first time interval.

[0191] Step 1509: The decision module receives the time detection message.

[0192] Step 1510: The decision module obtains a first time interval from a time detection message.

[0193] Step 1511: When the first time interval is greater than or equal to the first interval threshold, the decision module sends a load acquisition message to the CPU monitoring module.

[0194] When the first time interval is greater than or equal to the first interval threshold, it means that it has been a long time since the last fragmentation regularization, and the current fragmentation regularization will not cause frequent fragmentation regularization. Therefore, the decision module can continue to further determine whether fragmentation regularization can be performed. However, since fragmentation regularization may further increase the consumption of the CPU when the CPU is under high load, thereby affecting the performance of the electronic device, in order to avoid fragmentation regularization under high CPU load, the decision module can send a load acquisition message to the CPU monitoring module.

[0195] As an example, when the first time interval is less than the first interval threshold, the decision module may no longer perform any operation.

[0196] Since when the first time interval is less than the first interval threshold, it means that the fragmentation regularization has been performed not long ago, in order to avoid frequent fragmentation regularization, the decision module does not need to perform any operation.

[0197] Step 1512: The CPU monitoring module receives a load acquisition message.

[0198] Step 1513: The CPU monitoring module obtains the CPU load.

[0199] As an example, after receiving the load acquisition message, the CPU monitoring module can perform load detection on the CPU at second time intervals within a first specified time period to obtain multiple load detection results; determine the multiple load detection results as the load of the CPU, or determine the minimum load detection result among the multiple load detection results as the load of the CPU.

[0200] It should be noted that the first specified time length can be pre-set according to the requirements, for example, the first specified time length can be 5 seconds, 6 seconds or 7 seconds, etc. The second time interval can also be pre-set according to the requirements, for example, the second time interval can be 0.2 seconds or 0.3 seconds, etc.

[0201] Step 1514: The CPU detection module sends a load detection message to the decision module, and the load detection message carries the CPU load.

[0202] Step 1515: The decision module receives the load detection message.

[0203] Step 1516: The decision module obtains the CPU load from the load detection message.

[0204] From the above, it can be seen that the CPU monitoring module can determine multiple load detection results as the CPU load, and can also determine the minimum load detection result among multiple load detection results as the CPU load. Therefore, the decision module may obtain multiple load detection results, or may obtain the minimum load detection result.

[0205] Step 1517: When the CPU load is less than or equal to the load threshold, the decision module sends a regularization instruction to the communication module and sends a time recording message to the time monitoring module.

[0206] It should be noted that the tidying instruction carries a first preset value which is not zero.

[0207] Since the CPU load may be multiple load detection results or a minimum load detection result, when the CPU load is different, the operation of the decision module to determine whether the CPU load is less than or equal to the load threshold is also different.

[0208] As an example, when the CPU load is the minimum load detection result, the decision module can directly determine whether the minimum load detection result is less than or equal to the load threshold, and when the minimum load detection result is less than or equal to the load threshold, determine that the CPU load is less than or equal to the load threshold.

[0209] As an example, when the load of the CPU includes multiple load detection results, if there is at least one load detection result among the multiple load detection results that is less than or equal to the load threshold, it is determined that the load of the CPU is less than or equal to the load threshold.

[0210] Since when the CPU load is less than or equal to the load threshold, it means that the CPU is in a low load state, and fragmentation regularization has little impact on the CPU load at this time, therefore, the decision module can send a regularization instruction to the communication module and send a time recording message to the time monitoring module.

[0211] Step 1518: The time monitoring module receives the time recording message.

[0212] Step 1519: The time monitoring module records the time for performing fragmentation regularization.

[0213] Step 1520: The communication module receives the regularization instruction.

[0214] It should be noted that there is no limitation on the execution order of step 1518 and step 1520 in the embodiment of the present application.

[0215] Step 1521: The communication module sends the regularization instruction to the kernel node access control module.

[0216] Step 1522: The kernel node access control module receives the regularization instruction.

[0217] Step 1523: The kernel node access control module sends the regularization instruction to the regularization module.

[0218] Step 1524: The regularization module receives the regularization instruction.

[0219] Step 1525: The regularization module determines the first preset value as the regularization threshold.

[0220] Since the tidying instruction carries the first preset value, the tidying module can obtain the first preset value from the tidying instruction and determine the first preset value as the tidying threshold.

[0221] It should be noted that the regularization threshold is the maximum value that the continuous memory in the memory can reach after fragmentation regularization.

[0222] Step 1526: When the regularization threshold is not zero, the regularization module obtains a fragmentation index corresponding to the memory when the size of the continuous memory in the memory is a second preset value.

[0223] It should be noted that the fragmentation index is used to describe the degree of memory fragmentation, wherein the fragmentation index may range from 0 to 100%, and the higher the memory fragmentation index, the more serious the degree of memory fragmentation described.

[0224] It should also be noted that continuous memory in the memory can usually be represented by order order (order index). For example, order9 represents 2 to the power of 9 continuous pages of physical memory, where each page is 4096 bytes, that is, 4MB of continuous physical memory. The fragmentation index of order9 can be determined by the following first formula (1).

[0225]

[0226] As an example, when the regularization threshold is 0, the regularization module does not perform fragmentation regularization.

[0227] Since the regularization threshold is the maximum value that the continuous memory in the memory can reach after the fragmentation regularization, when the regularization threshold is 0, it means that the continuous memory is not needed, and therefore, the fragmentation regularization is not needed.

[0228] Step 1527: When the fragmentation index is greater than or equal to the preset fragmentation threshold, the regularization module regularizes the memory fragments using a continuous memory size of a third preset value.

[0229] It should be noted that the third preset value can be set in advance, and the third preset value can be 2mb, 4mb, etc. The third preset value can be the same as the second preset value, or it can be different, and the embodiment of the present application does not impose specific restrictions on this. In addition, the preset fragmentation threshold can also be set in advance according to demand, for example, the preset fragmentation threshold can be 97%, 96%, or 95%, etc.

[0230] It is worth noting that by setting a higher preset fragmentation threshold, frequent fragmentation operations can be avoided, thereby avoiding the impact on the CPU load.

[0231] As an example, the operation of the regularization module to fragment and regularize the memory with a continuous memory size of a third preset value can refer to the relevant technology. For example, since the fragmentation regularization is performed in units of pages, the decision module can use a page migration mechanism to migrate the movable pages (occupied pages) in the memory to organize discrete free pages into continuous pages, thereby obtaining continuous memory.

[0232] Step 1528: After the regularization module regularizes the memory fragments with the memory size of the third preset value, it determines whether all the memory has been regularized.

[0233] Step 1529: After all memories have been organized, the organization module determines whether the fragmentation index is less than a preset fragmentation threshold.

[0234] Step 1530: When the fragmentation index is less than the preset fragmentation threshold, end the fragmentation regularization.

[0235] It should be noted that the regularization module can set the regularization threshold to zero to end the current fragmentation regularization.

[0236] In an embodiment of the present application, when the electronic device receives a trigger operation from a user, and the scenario triggered by the trigger operation belongs to a memory regularization scenario, if the CPU is in a low-load state, the memory can be fragmented and regularized. Since the CPU load is taken into account when performing fragmentation regularization, it is possible to avoid performing fragmentation regularization when the CPU is in a high-load state, thereby improving the impact on the CPU load and reducing the possibility of performance degradation of the electronic device.

[0237] During the fragmentation process, some operations of the user on the electronic device may interrupt the fragmentation of the memory. Therefore, the following embodiment of the present application explains how to terminate the fragmentation of the memory. Please refer to Fig.16 , Fig.16 FIG. 1 is a flow chart of a memory organization method according to another exemplary embodiment. As an example but not a limitation, the method is applied to an electronic device. The electronic device uses Figure 7 Taking the interaction of multiple modules shown in the figure as an example, the method may include some or all of the following contents:

[0238] The operations of step 1601 to step 1627 can refer to the operations of the above-mentioned step 1501 to step 1527, and the embodiment of the present application will not describe them one by one.

[0239] Step 1628: During the process of fragmentation and regularization, the application startup monitoring module detects that the electronic device receives a startup operation for any application program.

[0240] Step 1629: The application startup monitoring module sends an application startup message to the decision module.

[0241] Step 1630: The decision module receives an application startup message.

[0242] Step 1631: The decision module determines whether the electronic device performs memory fragmentation regularization at the first time point.

[0243] It should be noted that the first time point is before the second time point and the time difference between the first time point and the second time point is the second specified duration, and the second time point is the time point when the start operation is received.

[0244] Step 1632: If the electronic device is performing fragmentation regularization at the first time point, the decision module sends a termination instruction to the communication module.

[0245] It should be noted that the termination instruction carries a second preset value, which is zero.

[0246] Step 1633: The communication module receives the termination instruction.

[0247] Step 1634: The communication module sends a termination instruction to the kernel node access control module.

[0248] Step 1635: The kernel node access control module receives the termination instruction.

[0249] Step 1636: The kernel node access control module sends a termination instruction to the regularization module.

[0250] Step 1637: The regularization module receives the termination instruction.

[0251] Step 1638: The cleanup module terminates the cleanup of memory fragments.

[0252] As an example, the regularization module may determine the second preset value as the regularization threshold to terminate regularization of memory fragmentation.

[0253] Since the second preset value is zero, when the second preset value is determined as the regularization threshold, the regularization threshold is zero, and when the regularization threshold is zero, the regularization module does not perform fragmentation regularization. Therefore, by setting the second preset value as the regularization threshold, the regularization module can no longer perform fragmentation regularization.

[0254] As an example, if the neatening module has stopped performing the fragmentation neatening before receiving the termination instruction and has set the neatening threshold to zero, the neatening module will no longer perform any operation after receiving the termination instruction.

[0255] In an embodiment of the present application, during the fragmentation regularization process of the electronic device, if a startup operation for any application is received, the relevant operations of the fragmentation regularization can be terminated in time when it is determined that the first time point is in the fragmentation regularization stage, thereby improving the problem of application freezes caused by fragmentation operations and reducing the response time and delay to user operations.

[0256] Since the user may also perform some operations on the electronic device during the process of the electronic device acquiring the CPU load, these operations will also interrupt the acquisition of the CPU load. Therefore, next, the embodiment of the present application explains how to terminate the CPU load acquisition, please refer to Fig.17 , Fig.17 FIG. 1 is a flow chart of a memory organization method according to another exemplary embodiment. As an example but not a limitation, the method is applied to an electronic device. The electronic device uses Figure 7Taking the interaction of multiple modules shown in the figure as an example, the method may include some or all of the following contents:

[0257] The operations of step 1701 to step 1713 may refer to the operations of step 1501 to step 1513 described above, and will not be described in detail in the embodiment of the present application.

[0258] Step 1714: During the process of the CPU detection module acquiring the CPU, the application startup monitoring module detects that the electronic device receives a startup operation for any application program.

[0259] Step 1715: The application startup monitoring module sends an application startup message to the decision module.

[0260] Step 1716: The decision module receives the application startup message.

[0261] Step 1717: The decision module sends a stop detection message to the CPU monitoring module.

[0262] Step 1718: The CPU monitoring module receives a stop detection message.

[0263] Step 1719: The CPU monitoring module stops detecting the CPU load.

[0264] In an embodiment of the present application, during the fragmentation regularization process of the electronic device, if a startup operation for any application is received, the relevant operations of the fragmentation regularization can be terminated in time when it is determined that the first time point is in the fragmentation regularization stage, thereby improving the problem of application freezes caused by fragmentation operations and reducing the response time and delay to user operations.

[0265] It should be noted that the above is based on electronic equipment through Figure 7 The method for implementing memory organization by using multiple modules interacting as shown is described as an example. Next, in order to further understand the embodiment of the present application, the method is described as being executed by an electronic device. Please refer to Fig.18 , Fig.18 This is a flow chart of a memory organization method according to another exemplary embodiment. As an example but not a limitation, the method may include some or all of the following contents:

[0266] Step 1801: Receive a trigger operation of the user on the electronic device.

[0267] It should be noted that the trigger operation may include any operation on the electronic device.

[0268] Step 1802: In response to a trigger operation, determine whether the scene triggered by the trigger operation belongs to a memory organization scene; if so, execute the operation of the following step 1803; if not, execute the operation of step 1807.

[0269] Since the electronic device cannot perform memory fragmentation regularization under all triggering operations, in response to the triggering operation, the electronic device can determine whether the scene triggered by the triggering operation belongs to the memory regularization scene.

[0270] It should be noted that the memory cleanup scenario may include one or more of the following: cleaning up at least one application running in the electronic device, returning to the desktop of the electronic device from the application interface of any application, and the electronic device entering the screen-off state. Figure 8-Figure 14 The application scenario shown.

[0271] In some embodiments, when the scenario triggered by the trigger operation belongs to the memory regularization scenario, if the CPU of the electronic device is in a low load state, the memory can be fragmented and regularized. Wherein, when the scenario triggered by the trigger operation belongs to the memory regularization scenario, if the CPU of the electronic device is in a low load state, the operation of fragmenting and regularizing the memory can refer to the operations of steps 1803 to 1806 below.

[0272] It is worth noting that since the electronic device is in a memory consolidation scenario, the electronic device usually does not need to allocate memory, that is, the electronic device can perform memory fragmentation consolidation without the need for memory allocation, so that when the electronic device needs to perform fragmentation consolidation later, it can quickly allocate memory, reducing the response time and latency to user operations.

[0273] Step 1803: Obtain a first time interval between the current time and the last time the fragmentation was regularized.

[0274] In order to avoid frequent fragmentation and regularization of the memory, when the scenario triggered by the triggering operation belongs to the memory regularization scenario, the electronic device can obtain a first time interval between the current time and the time of the last fragmentation and regularization.

[0275] As an example, each time the electronic device performs fragmentation regularization, it can record the corresponding regularization time. Therefore, when the electronic device determines that the scene triggered by the trigger operation belongs to the memory regularization scene, it can determine the first time interval based on the last recorded regularization time and the current time.

[0276] From the above, it can be seen that the electronic device includes a CPU monitoring module, a time monitoring module and a decision module; in this way, when the electronic device determines that the scene triggered by the trigger operation belongs to the memory regularization scene, it obtains the first time interval between the current time and the time when the fragmentation regularization was last performed, including: when it is determined that the scene triggered by the trigger operation belongs to the memory regularization scene, the decision module sends a time acquisition message to the time monitoring module; the time monitoring module determines the time interval between the current time and the time when the fragmentation regularization was last performed, and obtains the first time interval; the time monitoring module sends a time detection message to the decision module, and the time detection message carries the first time interval; the decision module obtains the first time interval from the time detection message.

[0277] It should be noted that the operation of obtaining the first time interval through the CPU monitoring module, the time monitoring module and the decision module can refer to the operations of the above steps 1504 to 1510, and the embodiments of the present application will not be described in detail.

[0278] Step 1804: Determine whether the first time interval is greater than or equal to the first interval threshold. If so, execute the operation of the following step 1805. If not, terminate this operation, that is, execute step 1807.

[0279] Step 1805: When the first time interval is greater than or equal to the first interval threshold, obtain the CPU load.

[0280] It is worth noting that by obtaining the CPU load when the first time interval is greater than or larger than the first interval threshold, frequent memory fragmentation and regularization can be avoided, and an increase in the CPU load can also be avoided.

[0281] In some embodiments, the electronic device can obtain the CPU load when the first time interval is greater than or equal to the first interval threshold, or directly obtain the CPU load when it is determined that the scenario triggered by the trigger operation belongs to a memory regularization scenario. The embodiments of the present application do not impose specific restrictions on this.

[0282] From the above, it can be seen that the electronic device may include not only a decision-making module and a time monitoring module, but also a CPU monitoring module. In this way, when the first time interval is greater than or equal to the first interval threshold, the operation of the electronic device to obtain the CPU load includes: when the first time interval is greater than or equal to the first interval threshold, the decision module sends a load acquisition message to the CPU monitoring module; the CPU monitoring module sends a load detection message to the decision module, and the load detection message carries the CPU load; the decision module obtains the CPU load from the load detection message.

[0283] It should be noted that the operation of the electronic device obtaining the CPU load through the decision module and the CPU detection module can refer to the operations of the above steps 1511 to 1516, and the embodiments of the present application will not describe them one by one.

[0284] In some embodiments, when the first time interval is greater than or equal to the first interval threshold, the electronic device may determine the current load of the CPU as the load of the CPU, or the electronic device may detect the load of the CPU within a period of time, and obtain the load of the CPU according to the load detection result within the period of time. That is, when the first time interval is greater than or equal to the first interval threshold, the operation of the electronic device to obtain the load of the CPU includes: when the first time interval is greater than or equal to the first interval threshold, performing load detection on the CPU every second time interval within a first specified time length to obtain multiple load detection results; determining the multiple load detection results as the load of the CPU, or determining the minimum load detection result among the multiple load detection results as the load of the CPU.

[0285] It is worth noting that by detecting the CPU load within the first specified time period, the accuracy of the acquired CPU load is ensured.

[0286] In some embodiments, the electronic device may not only determine multiple load detection results as the CPU load, or determine the minimum load detection result among multiple load detection results as the CPU load, but the electronic device may also determine the CPU load in other ways. Exemplarily, the electronic device may also determine the average load detection result of multiple load detection results, and determine the average load detection result as the CPU load.

[0287] Step 1806: When the CPU load is less than or equal to the load threshold, the memory is fragmented and regularized.

[0288] When the CPU load is less than or equal to the load threshold, it means that the current CPU load is small. At this time, even if fragmentation is performed, it will not have a serious impact on the CPU performance. Therefore, the electronic device can fragment the memory when the CPU load is less than or equal to the load threshold.

[0289] It is worth mentioning that by performing memory fragmentation and regularization when the CPU load is small, the performance of the CPU can be better protected, thereby protecting the performance of the electronic device.

[0290] As can be seen from the above, the CPU load may be the current real-time load, or it may be the minimum load detection result within the first specified time period, or it may be multiple load detection results within the first specified time period. Depending on the CPU load, the operation of the electronic device to determine whether the CPU load is less than or equal to the load threshold is also different.

[0291] As an example, when the CPU load is the current real-time load, or is the minimum load detection result within the first specified time period, the electronic device can directly compare the CPU load with the load threshold; when the CPU load is less than or equal to the load threshold, the memory is fragmented and regularized.

[0292] As an example, in the case where the CPU load includes multiple load detection results, if there is at least one load detection result among the multiple load detection results that is less than or equal to the load threshold, the memory is fragmented and regularized.

[0293] It is worth noting that by fragmenting and regularizing the memory when at least one load detection result is less than or equal to the load threshold, fragmentation and regularization when the CPU is under high load is avoided, thereby reducing the impact on the performance of the electronic device.

[0294] In some embodiments, as can be seen from the above, when the load of the CPU includes multiple load detection results, the electronic device can also determine the average load detection result of the multiple load detection results as the load of the CPU. Therefore, when the load of the CPU is the average load detection result of the multiple load detection results, if the average load detection result is less than or equal to the load threshold, the electronic device can fragment and regularize the memory.

[0295] From the above, it can be seen that the electronic device also includes a communication module and a regularization module. In this way, the electronic device can send regularization instructions to the regularization module of the kernel through the communication module, so as to regularize the fragmented memory through the regularization module.

[0296] It should be noted that the operation of electronic devices to fragment and organize memory can refer to the following Fig.16 Flow chart of the method shown in .

[0297] It should also be noted that during the process of fragmentation and regularization of an electronic device, a user may start any application in the electronic device. In this case, the electronic device can terminate the fragmentation and regularization of the memory. This operation can refer to the operations of steps A to C below.

[0298] Step A: Determine whether a startup operation for any application in the electronic device is received. If so, execute the operation of the following step B; if not, continue to execute the operation of the above step 1806.

[0299] Step B: When receiving a start-up operation for any application in the electronic device, determine whether the electronic device performs memory fragmentation and regularization at the first time point, and if so, perform the following step C.

[0300] It should be noted that the first time point is before the second time point and the time difference between the first time point and the second time point is the second specified duration, and the second time point is the time point when the start operation is received.

[0301] It should also be noted that the second specified time length can be pre-set according to needs. For example, the second specified time length can be 2 seconds or 3 seconds.

[0302] Step C: If the electronic device is performing fragmentation and regularization at the first time point, then the fragmentation and regularization of the memory is terminated.

[0303] As can be seen from the above, the electronic device also includes an application startup monitoring module. In this way, the electronic device can monitor whether the startup operation of any application is received through the application startup monitoring module, or monitor whether an application startup event occurs, and send an application startup message to the decision module when it is detected that the startup operation of any application is received; the decision module can perform the operation of step B above when receiving the application startup message, that is, determine whether the electronic device performs memory fragmentation regularization at the first time point, and if so, the decision module can send a termination instruction to the kernel regularization module through the communication module, and the stop instruction carries a second preset value, which is zero; when the regularization module receives the termination instruction, it can obtain the second preset value from the stop instruction and determine the second preset value as the regularization threshold; when the regularization threshold is zero, the regularization module terminates the regularization of memory fragmentation.

[0304] As an example, if the electronic device is in the fragmentation regularization stage at the first time point, and the electronic device is in the process of obtaining the load state of the CPU, the electronic device can terminate the acquisition of the CPU load.

[0305] Exemplarily, when the application startup monitoring module detects that the electronic device receives a startup operation of any application, an application startup message can be sent to the decision module; if the decision module starts the load acquisition process of the CPU that is currently in the fragmentation and regularization stage of the memory, the decision module can send a stop detection message to the CPU detection module; when the CPU detection module receives the stop detection message, it can stop detecting the CPU load.

[0306] In some embodiments, after receiving the application startup message, if the decision module has not yet sent the regularization instruction, the decision module may stop sending the regularization instruction.

[0307] Step 1807: The electronic device does not perform memory fragmentation and regularization.

[0308] Because the scene triggered by the triggering operation does not belong to any of the memory organization scenes, it means that the current scene cannot perform memory fragmentation organization, and therefore, the electronic device does not perform memory fragmentation organization.

[0309] It is worth noting that since the scenario triggered by the triggering operation does not belong to any of the memory organization scenarios, the electronic device does not need to perform memory fragmentation organization, thereby avoiding the problem of untimely memory allocation during the fragmentation organization process, and further avoiding the problem of interface display jamming.

[0310] In an embodiment of the present application, when the electronic device receives a trigger operation from a user, and the scenario triggered by the trigger operation belongs to a memory regularization scenario, if the CPU is in a low-load state, the memory can be fragmented and regularized. Since the CPU load is taken into account when performing fragmentation regularization, it is possible to avoid performing fragmentation regularization when the CPU is in a high-load state, thereby improving the impact on the CPU load and reducing the possibility of performance degradation of the electronic device.

[0311] The above describes the operations performed by electronic devices in the application framework layer. Electronic devices usually perform memory fragmentation and regularization in the kernel. Therefore, the following will explain the operations of memory fragmentation and regularization performed by electronic devices in the kernel. Fig.19 , Fig.19 This is a flow chart of a memory organization method according to another exemplary embodiment. As an example but not a limitation, the method is executed by an electronic device, and the method may include some or all of the following contents:

[0312] Step 1901: When the scenario triggered by the trigger operation belongs to a memory regularization scenario, if the CPU of the electronic device is in a low-load state, a regularization threshold is obtained.

[0313] It should be noted that the trimming threshold is the maximum value that the continuous memory can reach after the fragmentation trimming. The CPU is in a low load state when the above Fig.18 The CPU load described in the description is less than or equal to the load threshold.

[0314] From the above, it can be seen that the electronic device may include a decision module, a communication module, a kernel node access control module and a regularization module; wherein the decision module and the communication module are modules in the application framework layer, and the regularization module is a module in the kernel layer. In order to enable the application framework layer to communicate with the kernel, a kernel node access control module may be set in the local layer of the electronic device, and the kernel node access control module may forward any message and / or instruction sent by the application framework layer to the kernel layer.

[0315] In some embodiments, the operation of an electronic device obtaining a regularization threshold includes: a decision module sends a regularization instruction to a communication module, the regularization instruction carries a first preset value, and the first preset value is not zero; the communication module sends the regularization instruction to a kernel node access control module; the kernel node access control module sends the regularization instruction to a regularization module; the regularization module determines the first preset value as the regularization threshold.

[0316] It should be noted that the first preset value is a value preset according to demand, and the first preset value may be 20%, 30%, etc.

[0317] It is worth noting that by determining whether to trigger the fragmentation regularization operation in the decision module, and then performing fragmentation regularization by the regularization module in the kernel layer, the triggering of the regularization instruction is made more accurate, thereby solving the problem of poor real-time performance of the kernel layer triggering regularization instructions and the easy satisfaction of the triggering conditions, which causes the performance of the electronic device to be reduced.

[0318] In some embodiments, determining whether the CPU of an electronic device is in a low-load state may be performed in an application framework layer or in a kernel layer, and the embodiments of the present application do not impose specific limitations on this.

[0319] Since the first preset value is not zero, after the first preset value is determined as the regularization threshold, the regularization threshold is also not zero, and when the regularization threshold is not zero, the memory can be regularized. Wherein, when the regularization threshold is not zero, the operation of the electronic device to regularize the memory can refer to the operations of the following steps 1902 to 1907.

[0320] Step 1902: when the regularization threshold is not zero, obtain a fragmentation index corresponding to the memory when the size of the continuous memory in the memory is a second preset value.

[0321] It should be noted that the fragmentation index is used to describe the degree of memory fragmentation. The second preset value is a value pre-set according to demand, and the second preset value can be represented by an order index, for example, the second preset value can be 2MB or 4MB.

[0322] It is worth noting that by obtaining the fragmentation index when the regularization threshold is not zero, the problem that the fragmentation regularization operation is easily triggered and affects the performance of the electronic device is solved.

[0323] It should also be noted that the operation of the electronic device obtaining the fragmentation index corresponding to the memory when the size of the continuous memory in the memory is the second preset value can refer to the above Fig.15 The operation of step 1526 will not be described in detail in this embodiment of the present application.

[0324] Step 1903: When the fragmentation index is greater than or equal to the preset fragmentation threshold, the memory is fragmented and regularized with a continuous memory size of a third preset value.

[0325] It should be noted that when the fragmentation index of the electronic device is greater than or equal to the preset fragmentation threshold, the operation of fragmenting and regularizing the memory with a continuous memory size of a third preset value can refer to the operation of the above-mentioned step 1527, and the embodiment of the present application will not elaborate on this one by one.

[0326] Step 1904: After the memory is fragmented and organized with the memory size of the third preset value, determine whether all the memory has been organized. If so, execute the operation of the following step 1907; if not, execute the operation of the following step 1905.

[0327] Step 1905: Determine whether the regularization threshold is zero. If so, execute the operation of the following step 1907; if not, execute the operation of the following step 1906.

[0328] From the above, it can be seen that in the process of memory fragmentation regularization of an electronic device, a user can trigger the startup operation of any application. When the electronic device receives the startup operation of any application, it can set the regularization threshold to zero to terminate the memory fragmentation regularization. Therefore, in the process of memory fragmentation regularization, the electronic device also needs to determine whether the regularization threshold is zero.

[0329] It should be noted that when the regularization threshold is zero, it means that the user has started any application. In this case, the electronic device needs to terminate the regularization of memory fragmentation. Therefore, the electronic device can perform the operation of step 1907 below. When the regularization threshold is not zero, the electronic device can continue to regularize memory fragmentation. Therefore, the electronic device can continue to perform the operation of step 1906 below.

[0330] Step 1906: Determine whether the fragmentation index is less than a preset fragmentation threshold. If so, execute the operation of the following step 1907; if not, return to the operation of step 1903.

[0331] Step 1907: End the memory fragmentation process.

[0332] It should be noted that, after the electronic device completes the fragmentation cleanup of the memory, the cleanup threshold may be set to zero.

[0333] In an embodiment of the present application, during the process of fragmentation regularization of an electronic device, whether to continue fragmentation regularization is determined by setting the regularization threshold to zero, thereby making the triggering of the regularization instruction more accurate, thereby solving the problem of poor real-time performance of the kernel layer triggering regularization instructions and the easy satisfaction of the triggering conditions, which causes the performance of the electronic device to be reduced.

[0334] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (such as: coaxial cable, optical fiber, data subscriber line (Digital Subscriber Line, DSL)) or wireless (such as: infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access, or a data storage device such as a server or data center that includes one or more available media integrations. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a digital versatile disc (DVD)), or a semiconductor medium (such as a solid state disk (SSD)).

[0335] The above are optional embodiments provided for the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the technical scope disclosed in the present application shall be included in the protection scope of the present application.

Claims

1. A method for organizing memory, characterized in that: Applied in an electronic device, the method comprises: Receiving a trigger operation of the user on the electronic device, wherein the trigger operation is used to make the electronic device enter a triggered scene; In response to the trigger operation, switching to the scene triggered by the trigger operation; In the case where the scenario triggered by the trigger operation does not belong to the memory regularization scenario, the memory of the electronic device is not fragmented and regularized, the memory regularization scenario is a scenario in which the memory can be fragmented and regularized, and the electronic device does not need to allocate memory when it is in the memory regularization scenario, and the memory regularization scenario includes one or more of a scenario of clearing at least one application running in the electronic device, a scenario of returning to the desktop of the electronic device from an application interface of any application, and a scenario in which the electronic device enters a screen-off state; When the current scene changes and the scene triggered by the trigger operation belongs to the memory regularization scene, if the current load value of the central processing unit (CPU) of the electronic device is less than or equal to the load threshold, then obtain the regularization threshold, where the regularization threshold is the maximum value that the continuous memory in the memory can reach after fragmentation regularization; When the regularization threshold is zero, no memory fragmentation regularization is performed; When the regularization threshold is not zero, obtaining a fragmentation index corresponding to the memory when the size of the continuous memory in the memory is a second preset value, wherein the fragmentation index is used to describe the degree of fragmentation of the memory; When the fragmentation index is greater than or equal to a preset fragmentation threshold, the memory is fragmented and regularized with a continuous memory size of a third preset value; When the fragmentation index is less than a preset fragmentation threshold, the regularization threshold is set to zero to end the current fragmentation regularization; In the case of receiving a startup operation for any application in the electronic device, if the electronic device is performing the fragmentation regularization at a first time point, the regularization threshold is set to zero to terminate the fragmentation regularization of the memory, the first time point is before the second time point and the time difference between the first time point and the second time point is a second specified time length, and the second time point is the time point of receiving the startup operation.

2. The method according to claim 1, characterized in that The electronic device includes a decision module, a communication module, a kernel node access control module and a regularization module; Get the normalization threshold, including: The decision module sends a regularization instruction to the communication module, wherein the regularization instruction carries a first preset value, and the first preset value is not zero; The communication module sends the regularization instruction to the core node access control module; The kernel node access control module sends the regularization instruction to the regularization module; The regularization module determines the first preset value as the regularization threshold.

3. The method according to claim 1 or 2, characterized in that The method further comprises: In a case where the scene triggered by the trigger operation belongs to the memory regularization scene, obtaining a first time interval between the current time and the time when the fragmentation regularization was last performed; When the first time interval is greater than or equal to a first interval threshold, the load of the CPU is obtained.

4. The method according to claim 3, characterized in that The electronic device comprises a time monitoring module and a decision-making module; When the current scene changes and the scene triggered by the trigger operation belongs to the memory regularization scene, obtaining a first time interval between the current time and the last time of performing fragmentation regularization includes: When the current scene changes and the scene triggered by the trigger operation belongs to the memory regularization scene, the decision module sends a time acquisition message to the time monitoring module; After receiving the time acquisition message, the time monitoring module determines the time interval between the current time and the time when the fragmentation was last regularized to obtain the first time interval; The time monitoring module sends a time detection message to the decision module, wherein the time detection message carries the first time interval; The decision module obtains the first time interval from the time detection message.

5. The method according to claim 4, characterized in that The electronic device also includes a CPU monitoring module; The acquiring the CPU load when the first time interval is greater than or equal to a first interval threshold includes: When the first time interval is greater than or equal to the first interval threshold, the decision module sends a load acquisition message to the CPU monitoring module; The CPU monitoring module sends a load detection message to the decision module, wherein the load detection message carries the load of the CPU; The decision module obtains the load of the CPU from the load detection message.

6. The method according to claim 4 or 5, characterized in that The acquiring the CPU load when the first time interval is greater than or equal to a first interval threshold includes: When the first time interval is greater than or equal to a first interval threshold, performing load detection on the CPU at second time intervals within a first specified time period to obtain multiple load detection results; The multiple load detection results are determined as the load of the CPU, or the minimum load detection result among the multiple load detection results is determined as the load of the CPU.

7. The method according to claim 6, characterized in that In the case where the current scene changes and the scene triggered by the trigger operation belongs to the memory regularization scene, if the current load value of the central processing unit CPU of the electronic device is less than or equal to the load threshold, obtaining the regularization threshold includes: When the current scene changes and the scene triggered by the trigger operation belongs to the memory regularization scene, when the load of the CPU includes the multiple load detection results, if there is at least one load detection result among the multiple load detection results that is less than or equal to the load threshold, the regularization threshold is obtained.

8. An electronic device, characterized in that: The electronic device comprises: a processor and a memory, the memory is used to store one or more programs, the one or more programs include instructions, and when the processor executes the instructions, the electronic device is used to execute the memory organization method as described in any one of claims 1-7.

9. A computer-readable storage medium for storing one or more programs, wherein the one or more programs are configured to be executed by one or more processors, and the one or more programs include instructions that enable an electronic device to execute the memory organization method as described in any one of claims 1-7.