CN116661988A - Memory normalization method, electronic device and readable storage medium - Google Patents

Memory normalization method, electronic device and readable storage medium Download PDF

Info

Publication number
CN116661988A
CN116661988A CN202211725886.7A CN202211725886A CN116661988A CN 116661988 A CN116661988 A CN 116661988A CN 202211725886 A CN202211725886 A CN 202211725886A CN 116661988 A CN116661988 A CN 116661988A
Authority
CN
China
Prior art keywords
memory
load
fragmentation
scene
cpu
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211725886.7A
Other languages
Chinese (zh)
Inventor
杨胜利
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Honor Device Co Ltd
Original Assignee
Honor Device Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Honor Device Co Ltd filed Critical Honor Device Co Ltd
Priority to CN202211725886.7A priority Critical patent/CN116661988A/en
Publication of CN116661988A publication Critical patent/CN116661988A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/505Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the load
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)
  • Techniques For Improving Reliability Of Storages (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The application discloses a memory regulating method, electronic equipment and a readable storage medium, and belongs to the technical field of terminals. The method comprises the following steps: receiving triggering operation of a user on the electronic equipment; responding to the triggering operation, and under the condition that the scene triggered by the triggering operation does not belong to a memory regular scene, not carrying out fragmentation and normalization on the memory of the electronic equipment, wherein the memory regular scene is a scene capable of carrying out fragmentation and normalization of the memory; and under the condition that the scene triggered by the triggering operation belongs to the memory regularization scene, if the current load value of the CPU of the electronic equipment is smaller than or equal to the load threshold value, the memory is fragmented and regulated. According to the application, the load condition of the CPU is considered when the fragmentation is regulated, so that the fragmentation is avoided when the CPU is in a high load state, the influence on the CPU load is improved, and the possibility of performance degradation of the electronic equipment is reduced.

Description

Memory normalization method, electronic device and readable storage medium
Technical Field
The present application relates to the field of terminal technologies, and in particular, to a memory management method, an electronic device, and a readable storage medium.
Background
With the development of terminal technology, the functions of the electronic devices are more and more abundant, and the operations performed on the electronic devices by users are more and more. For example, a user may perform a startup operation on different applications in the electronic device, and each time the electronic device starts one application, a corresponding memory space needs to be allocated for the started application. If such operations are frequently performed, the memory of the electronic device is fragmented, which is unfavorable for subsequent memory allocation of the electronic device and affects the performance of the electronic device. Therefore, in order to facilitate subsequent memory allocation and also to ensure performance of the electronic device, it is generally necessary to perform fragmentation and normalization on the memory.
Currently, under the condition that the fragmentation index of the memory is greater than or equal to an index threshold, the electronic device may perform fragmentation regulation of the memory, where the fragmentation index is used to measure the degree of fragmentation of the memory. In the memory fragmentation normalization process, the electronic device normalizes the continuous memory as much as possible.
However, when the electronic device performs memory normalization, in order to normalize the continuous memory as much as possible, the range of the regular memory is larger, and the time consumed for the normalization is longer, so that the consumption of the central processing unit (central processing unit, CPU) of the electronic device may be increased, thereby reducing the performance of the electronic device.
Disclosure of Invention
The application provides a memory regularization method, electronic equipment and a readable storage medium, which can solve the problem that CPU consumption is increased due to memory fragmentation regularization in the related technology, so that the performance of the electronic equipment is reduced. The technical scheme is as follows:
in a first aspect, a memory management method is provided, and is applied to an electronic device, where the method includes:
receiving triggering operation of a user on the electronic equipment;
responding to the triggering operation, and under the condition that a scene triggered by the triggering operation does not belong to a memory regular scene, not carrying out fragmentation regulation on a memory of the electronic equipment, wherein the memory regular scene is a scene capable of carrying out fragmentation regulation on the memory, and comprises one or more of a scene for cleaning at least one application program running in the electronic equipment, a scene for returning a desktop of the electronic equipment from an application interface of any application program and a scene for entering an off-screen state by the electronic equipment;
and if the current load value of the CPU of the electronic equipment is smaller than or equal to a load threshold value under the condition that the scene triggered by the triggering operation belongs to the memory regularization scene, fragmenting and regularizing the memory.
Therefore, the load condition of the CPU is considered when the fragmentation is regulated, so that the fragmentation is regulated in a high-load state of the CPU can be avoided, the influence on the load of the CPU is improved, and the possibility of performance degradation of the electronic equipment is reduced.
As an example of the present application, in the case where the scene triggered by the triggering operation belongs to the memory regularization scene, if a current load value of a central processing unit CPU of the electronic device is less than or equal to a load threshold, the performing fragmentation regularization on the memory includes:
under the condition that the scene triggered by the triggering operation belongs to the memory regularization scene, if the current load value of the CPU is smaller than or equal to the load threshold value, acquiring a regularization threshold value, wherein the regularization threshold value is the maximum value which can be reached by continuous memory in the memory after fragmentation regularization;
and under the condition that the normalization threshold value is not zero, fragmenting and normalizing the memory.
Therefore, whether the fragmentation regulation is continued is determined by setting whether the regulation threshold is zero, so that the triggering of the regulation instruction is more accurate, and the problem that the performance of the electronic equipment is reduced due to the fact that the real-time performance of the kernel layer triggering the regulation instruction is poor and the triggering condition is easy to meet is solved.
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 regulation module;
the acquiring the normalization threshold value comprises:
the decision module sends a regular instruction to the communication module, wherein the regular instruction carries a first preset value, and the first preset value is not zero;
the communication module sends the regular instruction to the kernel node access control module;
the kernel node access control module sends the regular instruction to the regular module;
the normalization module determines the first preset value as the normalization threshold.
Therefore, whether the fragmentation regulation operation is triggered or not is determined in the decision module, and then the fragmentation regulation is carried out by the regulation module in the kernel layer, so that the regulation instruction is triggered more accurately, and the problem that the performance of the electronic equipment is reduced due to the fact that the real-time performance of the kernel layer triggering regulation instruction is poor and the triggering condition is easy to meet is solved.
As an example of the present application, the performing fragmentation normalization on the memory in the case where the normalization threshold is not zero includes:
under the condition that the regular threshold is not zero, obtaining a fragmentation index corresponding to the memory under the condition that the size of the continuous memory in the memory is a second preset value, wherein the fragmentation index is used for describing the fragmentation degree of the memory;
And under the condition that the fragmentation index is larger than or equal to a preset fragmentation threshold, fragmenting and regulating the memory according to the continuous memory size of a third preset value.
Thus, by setting a higher preset fragmentation threshold, frequent fragmentation operations can be avoided, thereby avoiding the influence on the load of the CPU.
As an example of the present application, the method further comprises:
acquiring a first time interval between the current time and the last time of fragmentation regulation under the condition that the scene triggered by the triggering operation belongs to the memory regulation scene;
and acquiring the load of the CPU under the condition that the first time interval is greater than or equal to a first interval threshold value.
Therefore, under the condition that the first time interval is larger than or equal to the first interval threshold value, the CPU load is acquired, so that frequent fragmentation and regulation of the memory can be avoided, and the load of the CPU is prevented from being increased.
As one example of the application, the electronic device comprises a time monitoring module and a decision module;
and under the condition that the scene triggered by the triggering operation belongs to the memory regularization scene, acquiring a first time interval between the current time and the last time of fragmentation regularization, wherein the first time interval comprises the following steps:
When the scene triggered by the triggering operation belongs to the memory regular 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 a time interval between the current time and the last time of fragmentation regulation 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.
Therefore, the time interval between the current time and the last time of fragmentation regulation is determined by the time monitoring module, the accuracy of determining the first time interval can be improved, and the frequent fragmentation regulation of the memory is effectively avoided.
As an example of the present application, the electronic device further includes a CPU monitoring module;
the obtaining the load of the CPU when the first time interval is greater than or equal to a first interval threshold value includes:
the decision module sends a load acquisition message to the CPU monitoring module when the first time interval is greater than or equal to the first interval threshold;
The CPU monitoring module sends a load detection message to the decision module, wherein the load detection message carries the load of the CPU;
and the decision module acquires the load of the CPU from the load detection message.
Therefore, the decision module acquires the load of the CPU through the CPU monitoring module, thereby improving the accuracy of acquiring the load of the CPU.
As an example of the present application, the obtaining the load of the CPU when the first time interval is greater than or equal to a first interval threshold includes:
under the condition that the first time interval is larger than or equal to a first interval threshold value, carrying out load detection on the CPU at intervals of a second time interval within a first appointed duration to obtain a plurality of load detection results;
and determining the plurality of load detection results as the load of the CPU, or determining the minimum load detection result in the plurality of load detection results as the load of the CPU.
Therefore, the load of the CPU in the first appointed duration is detected, so that the accuracy of the obtained load of the CPU is ensured.
As an example of the present application, in the case where the scene triggered by the triggering operation belongs to the memory regularization scene, if a current load value of a central processing unit CPU of the electronic device is less than or equal to a load threshold, the performing fragmentation regularization on the memory includes:
And under the condition that the scene triggered by the triggering operation belongs to the memory regulation scene, under the condition that the load of the CPU comprises the plurality of load detection results, if at least one load detection result in the plurality of load detection results is smaller than or equal to the load threshold value, fragmentation regulation is carried out on the memory.
Therefore, the fragmentation of the memory is regular under the condition that the load of the CPU is small, so that the performance of the CPU can be better protected, and the performance of the electronic equipment is further protected.
As an example of the present application, when the scene triggered by the triggering operation belongs to the memory normalization scene, if a current load value of a central processing unit CPU of the electronic device is less than or equal to a load threshold, after performing fragmentation normalization on the memory, the method further includes:
and under the condition that the starting operation of any one application program in the electronic equipment is received, if the electronic equipment is subjected to the fragmentation regulation at a first time point, the fragmentation regulation of the memory is stopped, the time difference between the first time point and the second time point is long when the first time point is before a second time point, and the second time point is the time point for receiving the starting operation.
In this way, in the process of fragmenting the electronic device, if the starting operation of any one application program is received, the related operation of fragmenting the electronic device can be terminated in time under the condition that the first time point is determined to be in the stage of fragmenting the electronic device, so that the problem of application program blocking caused by the fragmenting operation is solved, and the response time and time delay to user operation are reduced.
In a second aspect, an electronic device is provided, where the electronic device includes a processor and a memory, where the memory is configured to store a program for supporting the electronic device to execute the method for managing memory provided in the first aspect, and store data related to the method for managing memory in the first aspect. The processor is configured to execute a program stored in the memory. The electronic device may further comprise a communication bus for establishing a connection between the processor and the memory.
Wherein the processor is configured to:
receiving triggering operation of a user on the electronic equipment;
responding to the triggering operation, and under the condition that a scene triggered by the triggering operation does not belong to a memory regular scene, not carrying out fragmentation regulation on a memory of the electronic equipment, wherein the memory regular scene is a scene capable of carrying out fragmentation regulation on the memory, and comprises one or more of a scene for cleaning at least one application program running in the electronic equipment, a scene for returning a desktop of the electronic equipment from an application interface of any application program and a scene for entering an off-screen state by the electronic equipment;
And if the current load value of the CPU of the electronic equipment is smaller than or equal to a load threshold value under the condition that the scene triggered by the triggering operation belongs to the memory regularization scene, fragmenting and regularizing the memory.
As one example of the application, the processor is configured to:
under the condition that the scene triggered by the triggering operation belongs to the memory regularization scene, if the current load value of the CPU is smaller than or equal to the load threshold value, acquiring a regularization threshold value, wherein the regularization threshold value is the maximum value which can be reached by continuous memory in the memory after fragmentation regularization;
and under the condition that the normalization threshold value is not zero, fragmenting and normalizing the memory.
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 regulation module;
the processor is configured to:
the decision module sends a regular instruction to the communication module, wherein the regular instruction carries a first preset value, and the first preset value is not zero;
the communication module sends the regular instruction to the kernel node access control module;
The kernel node access control module sends the regular instruction to the regular module;
the normalization module determines the first preset value as the normalization threshold.
As one example of the application, the processor is configured to:
under the condition that the regular threshold is not zero, obtaining a fragmentation index corresponding to the memory under the condition that the size of the continuous memory in the memory is a second preset value, wherein the fragmentation index is used for describing the fragmentation degree of the memory;
and under the condition that the fragmentation index is larger than or equal to a preset fragmentation threshold, fragmenting and regulating the memory according to the continuous memory size of a third preset value.
As an example of the present application, the processor is further configured to:
acquiring a first time interval between the current time and the last time of fragmentation regulation under the condition that the scene triggered by the triggering operation belongs to the memory regulation scene;
and acquiring the load of the CPU under the condition that the first time interval is greater than or equal to a first interval threshold value.
As one example of the application, the electronic device comprises a time monitoring module and a decision module;
The processor is configured to:
when the scene triggered by the triggering operation belongs to the memory regular 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 a time interval between the current time and the last time of fragmentation regulation 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.
As an example of the present application, the electronic device further includes a CPU monitoring module;
the processor is configured to:
the decision module sends a load acquisition message to the CPU monitoring module when the first time interval is greater than or equal to the first interval threshold;
the CPU monitoring module sends a load detection message to the decision module, wherein the load detection message carries the load of the CPU;
and the decision module acquires the load of the CPU from the load detection message.
As one example of the application, the processor is configured to:
under the condition that the first time interval is larger than or equal to a first interval threshold value, carrying out load detection on the CPU at intervals of a second time interval within a first appointed duration to obtain a plurality of load detection results;
and determining the plurality of load detection results as the load of the CPU, or determining the minimum load detection result in the plurality of load detection results as the load of the CPU.
As one example of the application, the processor is configured to:
and under the condition that the scene triggered by the triggering operation belongs to the memory regulation scene, under the condition that the load of the CPU comprises the plurality of load detection results, if at least one load detection result in the plurality of load detection results is smaller than or equal to the load threshold value, fragmentation regulation is carried out on the memory.
As an example of the present application, the processor is further configured to:
and under the condition that the starting operation of any one application program in the electronic equipment is received, if the electronic equipment is subjected to the fragmentation regulation at a first time point, the fragmentation regulation of the memory is stopped, the time difference between the first time point and the second time point is long when the first time point is before a second time point, and the second time point is the time point for receiving the starting operation.
In a third aspect, there is provided a computer readable storage medium having instructions stored therein, which when run on a computer, cause the computer to perform the memory management method of the first aspect.
In a fourth aspect, there is provided a computer program product comprising instructions which, when run on a computer, cause the computer to perform the memory management method of the first aspect described above.
The technical effects obtained by the second, third and fourth aspects are similar to the technical effects obtained by the corresponding technical means in the first aspect, and are not described in detail herein.
Drawings
Fig. 1 is a schematic diagram of a scenario in which memory is regulated in a kernel layer according to an embodiment of the present application;
FIG. 2 is a flow chart of a method for performing memory management in the related art according to an embodiment of the present application;
FIG. 3 is a schematic diagram illustrating a process time consumption in the related art according to an embodiment of the present application;
FIG. 4 is a time-consuming schematic diagram of another related art provided by an embodiment of the present application;
FIG. 5 is a time-consuming schematic diagram of another related art provided by an embodiment of the present application;
fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present application
Fig. 7 is a schematic software architecture of an electronic device according to an embodiment of the present application;
fig. 8 is a schematic diagram of an application scenario provided in an embodiment of the present application;
FIG. 9 is a graph illustrating a fragmentation index variation according to an embodiment of the present application;
fig. 10 is a schematic diagram of another application scenario provided in an embodiment of the present application;
FIG. 11 is a schematic diagram of another application scenario provided by an embodiment of the present application;
FIG. 12 is a schematic diagram of another fragmentation index variation provided by an embodiment of the present application;
fig. 13 is a schematic diagram of another application scenario provided in an embodiment of the present application;
FIG. 14 is a schematic diagram of another fragmentation index variation provided by an embodiment of the present application;
FIG. 15 is a flow chart of a method for memory management according to an embodiment of the present application;
FIG. 16 is a flow chart of another method for memory management according to an embodiment of the present application;
FIG. 17 is a flow chart of another method for memory management according to an embodiment of the present application;
FIG. 18 is a flow chart of another method for memory management according to an embodiment of the present application;
FIG. 19 is a flow chart of another method for memory management according to an embodiment of the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the present application more apparent, embodiments of the present application will be described in further detail below with reference to the accompanying drawings.
It should be understood that references to "a plurality" in this disclosure refer to two or more. In the description of the present application, "/" means or, unless otherwise indicated, for example, A/B may represent A or B; "and/or" herein is merely an association relationship describing an association object, and means that three relationships may exist, for example, a and/or B may mean: a exists alone, A and B exist together, and B exists alone. In addition, in order to facilitate the clear description of the technical solution of the present application, the words "first", "second", etc. are used to distinguish the same item or similar items having substantially the same function and function. It will be appreciated by those of skill in the art that the words "first," "second," and the like do not limit the amount and order of execution, and that the words "first," "second," and the like do not necessarily differ.
Reference in the specification to "one embodiment" or "some embodiments" or the like means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," and the like in the specification are not necessarily all referring to the same embodiment, but mean "one or more but not all embodiments" unless expressly specified otherwise. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless expressly specified otherwise.
In one application scenario, a plurality of applications are usually installed in an electronic device, and when a user uses an application, the electronic device allocates a corresponding memory for the application used by the user. For example, in the case that the electronic device is a mobile phone, a user may frequently open different application programs during the process of using the mobile phone, and each time the mobile phone starts the application program under the triggering of the user, a corresponding memory needs to be allocated to the started application program. If the mobile phone finds that the continuous memory is insufficient in the process of memory allocation, the mobile phone can perform fragmentation regulation on the memory in the kernel node of the kernel layer, wherein the fragmentation regulation on the memory refers to the arrangement of a large number of discrete idle pages in the memory so as to obtain the continuous memory. The kernel nodes of the kernel layer comprise proc, sys, vm and a fragmentation_process and the like, each kernel node comprises a process for fragmentation regulation, the kernel process for page recovery in the kernel layer can wake up the process for fragmentation regulation, and referring to fig. 1, the kernel process for page recovery can be a kswapd process, the process for fragmentation regulation can be a kcompact process, and the kswapd process can wake up the kcompact process under the condition that fragmentation regulation is required. Since the above-described fragmentation regulation operation is triggered when memory allocation is required, the fragmentation regulation operation is an inactive fragmentation regulation. In the process of performing the non-fragmentation regulation, the mobile phone may obtain the non-active fragmentation parameter, for example, obtain the memory size to be allocated, and then, the mobile phone may perform the non-active fragmentation regulation according to the memory size to be allocated in the kcompactd process. In addition, not only the inactive fragmentation regulation but also the active fragmentation regulation can be performed in the kcompactd process of the kernel, where under the condition that the fragmentation index of the memory is greater than or equal to 20%, the mobile phone can obtain the active fragmentation parameter through the kcompactd process, for example, obtain the size of the continuous memory of each regulation, and then, the mobile phone can actively perform the fragmentation regulation in the kcompactd process and sort more continuous memories at a time. Wherein the inactive and active defragmentation rules share a process.
In order to facilitate understanding, the embodiment of the present application provides a flow chart of active fragmentation regulation of a mobile phone in a kcompactd process of a kernel, referring to fig. 2, the active fragmentation regulation of the mobile phone in a kcompactd process of a kernel layer includes the following steps: step 201, determining 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%, determining whether the delay times are set, if not, executing the operation of step 203, and if so, executing the operation of step 204. Step 203: delayed by 500ms and performs the operations of step 206 described below. Step 204, determining whether the delay time is 0, if yes, executing the following operation in step 206, and if no, executing the following operation in step 205. Step 205. The number of delays is reduced by 1 from the current value, and the operation returns to step 204. Step 206, performing fragmentation normalization with every 2MB (megabits) of continuous memory. Step 207, after each time of normalization, determining whether all memories are normalized, if yes, executing the operation of the following step 208, and if not, executing the operation of the following step 209; step 208, determining whether the fragmentation index is less than 20%, if yes, executing the following operation in step 209, and if not, returning to the operation in step 206; step 209, determining whether the severity of the memory fragmentation after the normalization is greater than the severity of the memory fragmentation before the normalization, if so, executing the operation of step 210, and if not, executing the operation of step 211. Step 210: the number of times of delay is set to 64 times, and the operation of step 201 is returned. Step 211: and finishing the active fragmentation of the memory.
However, there is a possibility that the load of the CPU is increased during the operation, for example, referring to fig. 3, an embodiment of the present application provides a schematic time-consuming process, and as can be seen from fig. 3, the time-consuming process of kcompactd is long, which will affect the performance of the CPU (for example, 8 sub-CPUs are illustrated in the drawing of the embodiment of the present application). In order to facilitate understanding of the negative effects caused by the inactive defragmentation and the active defragmentation in the related art, the embodiments of the present application further provide a time-consuming schematic diagram of the inactive defragmentation and a time-consuming schematic diagram of the active defragmentation, respectively, see fig. 4, in the process of performing the inactive defragmentation, the continuous memory that is trimmed each time is less, so that a jam condition is easy to occur when an application program is started, thereby increasing the load of the CPU. Referring to fig. 5, in the process of performing active fragmentation alignment, since the set index threshold is smaller, usually 20%, the fragmentation index of the memory easily reaches the set index threshold, the electronic device will frequently perform active fragmentation alignment, and the CPU will also frequently superimpose the fragmented load, so that the load performance is deteriorated.
Therefore, in order to solve the problem of excessive load of a CPU in the process of performing memory fragmentation and regulation, the embodiment of the application provides a memory fragmentation and regulation method. Because the load condition of the CPU is considered when the fragmentation is performed, the fragmentation is performed in a high-load state of the CPU can be avoided, so that the influence on the load of the CPU is improved, and the possibility of performance degradation of the electronic equipment is reduced.
Before explaining the memory management method provided by the embodiment of the application in detail, the electronic device related to the embodiment of the application is explained. The method provided by the embodiment of the present application may be performed by an electronic device, which may be, by way of example and not limitation, a mobile phone camera (go pro), a digital camera, a tablet computer, a desktop, a laptop, a handheld computer, a notebook, a vehicle-mounted device, an ultra-mobile personal computer (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 (VR) device, a mobile phone, a door lock, a smart appliance, and the like, which is not limited in this embodiment of the present application.
Fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present application. Referring to fig. 6, the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (universal serial bus, USB) interface 130, a charge 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, keys 190, a motor 191, an indicator 192, a camera 193, a display 194, and a subscriber identity module (subscriber identification module, SIM) card interface 195, etc. 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 sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, and the like.
It should be understood that the illustrated structure of the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the application, electronic device 100 may include more or fewer components than shown, or certain components may be combined, or certain components may be split, or different arrangements of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
The processor 110 may include one or more processing units, such as: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and/or a neural network processor (neural-network processing unit, NPU), etc. Wherein the different processing units may be separate devices or may be integrated in one or more processors.
The controller may be a neural hub and a command center of the electronic device 100, among others. The controller can generate operation control signals according to the instruction operation codes and the time sequence signals to finish the control of instruction fetching and instruction execution.
A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may hold instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to reuse the instruction or data, it can be called directly from the memory. Repeated accesses are avoided and the latency of the processor 110 is reduced, thereby improving the efficiency of the system.
In some embodiments, the processor 110 may include one or more interfaces, such as may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous receiver transmitter (universal asynchronous receiver/transmitter, UART) interface, a mobile industry processor interface (mobile industry processor interface, MIPI), a general-purpose input/output (GPIO) interface, a subscriber identity module (subscriber identity module, SIM) interface, and/or a universal serial bus (universal serial bus, USB) interface, among others.
It should be understood that the interfacing relationship between the modules illustrated in the embodiments of the present application is only illustrative, and is not meant to limit the structure of the electronic device 100. In other embodiments of the present application, the electronic device 100 may also employ different interfacing manners in the above embodiments, or a combination of multiple interfacing manners.
The wireless communication function of the electronic device 100 may be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, a modem processor, a baseband processor, and the like.
The electronic device 100 implements display functions through a GPU, a display screen 194, an application processor, and the like. The GPU is a microprocessor for image processing, and is connected to the display 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
The display screen 194 is used to display images, videos, and the like. The display 194 includes a display panel. The display panel may employ a liquid crystal display (liquid crystal display, LCD), an organic light-emitting diode (OLED), an active-matrix organic light emitting diode (AMOLED), a flexible light-emitting diode (flex), a mini, a Micro-OLED, a quantum dot light-emitting diode (quantum dot light emitting diodes, QLED), or the like. In some embodiments, the electronic device 100 may include 1 or N display screens 194, N being an integer greater than 1.
The electronic device 100 may implement photographing functions through an ISP, a camera 193, a video codec, a GPU, a display screen 194, an application processor, and the like.
The ISP is used to process data fed back by the camera 193. For example, when photographing, the shutter is opened, light is transmitted to the camera photosensitive element through the lens, the light signal is converted into an electric signal, and the camera photosensitive element transmits the electric signal to the ISP for processing and is converted into an image visible to naked eyes. ISP can also optimize the noise, brightness and skin color of the image. The ISP can also optimize parameters such as exposure, color temperature and the like of a shooting scene. In some embodiments, the ISP may be provided in the camera 193.
The camera 193 is used to capture still images or video. The object generates an optical image through the lens and projects the optical image onto the photosensitive element. The photosensitive element may be a charge coupled device (charge coupled device, CCD) or a Complementary Metal Oxide Semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, which is then transferred 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 the like format. In some embodiments, electronic device 100 may include 1 or N cameras 193, N being an integer greater than 1.
The external memory interface 120 may be used to connect an external memory card, such as a Micro SD card, to enable expansion of the memory capabilities of the electronic device 100. The external memory card communicates with the processor 110 through an external memory interface 120 to implement data storage functions. Such as storing files of music, video, etc. in an external memory card.
The internal memory 121 may be used to store computer-executable program code that includes instructions. The processor 110 executes various functional applications of the electronic device 100 and data processing by executing instructions stored in the internal memory 121. The internal memory 121 may include a storage program area and a storage data area. The storage program area may store an application program (such as a sound playing function, an image playing function, etc.) required for at least one function of the operating system, etc. The storage data area may store data (e.g., audio data, phonebook, etc.) created by the electronic device 100 during use, and so forth. In addition, the internal memory 121 may include a high-speed random access memory, and may further include a nonvolatile memory such as at least one magnetic disk storage device, a flash memory device, a universal flash memory (universal flash storage, UFS), and the like.
The electronic device 100 may implement audio functions such as music playing, recording, etc. through the audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone interface 170D, and application processor, etc.
The pressure sensor 180A is used to sense a pressure signal, and may convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A may be disposed on the display screen 194. The pressure sensor 180A is of various types, such as a resistive pressure sensor, an inductive pressure sensor, a capacitive pressure sensor, and the like. The capacitive pressure sensor may be a capacitive pressure sensor comprising at least two parallel plates with conductive material. The capacitance between the electrodes changes when a force is applied to the pressure sensor 180A. The electronic device 100 determines the strength of the pressure from the change in capacitance. When a touch operation is applied to the display screen 194, the electronic apparatus 100 detects the touch operation intensity according to the pressure sensor 180A. The electronic device 100 may also calculate the location of the touch based on the detection signal of the pressure sensor 180A. In some embodiments, touch operations that act on the same touch location, but at different touch operation strengths, may correspond to different operation instructions. Such as: when a touch operation with the touch operation intensity smaller than the pressure threshold is applied to the short message application icon, executing an instruction for checking the short message. And executing the instruction of newly creating the short message when the touch operation with the touch operation intensity being larger than or equal to the pressure threshold acts on the short message application icon.
The magnetic sensor 180D includes a hall sensor. The electronic device 100 may detect the opening and closing of the flip cover using the magnetic sensor 180D. In some embodiments, when the electronic device 100 is a flip machine, the electronic device 100 may detect the opening and closing of the flip according to the magnetic sensor 180D. The electronic device 100 sets the characteristics of automatic unlocking of the flip cover according to the detected opening and closing state of the leather sheath or the detected opening and closing state of the flip cover.
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 detects infrared reflected light from nearby objects using a photodiode. When sufficient reflected light is detected, the electronic device 100 may determine that an object is in the vicinity of the electronic device 100. When insufficient reflected light is detected, it may be determined that there is no object in the vicinity of the electronic device 100. The electronic device 100 can detect that the user holds the electronic device 100 close to the ear by using the proximity light sensor 180G, so as to automatically extinguish the screen for the purpose of saving power. The proximity light sensor 180G may also be used in holster mode, pocket mode to automatically unlock and lock the screen.
The fingerprint sensor 180H is used to collect a fingerprint. The electronic device 100 may utilize the collected fingerprint feature to unlock the fingerprint, access the application lock, photograph the fingerprint, answer the incoming call, etc.
The touch sensor 180K, also referred to as a "touch panel". The touch sensor 180K may be disposed on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, which is also called a "touch screen". The touch sensor 180K is for detecting a touch operation acting thereon or thereabout. The touch sensor 180K may communicate the detected touch operation to the application processor to determine the touch event type. Visual output related to touch operations may be provided through the display 194. In other embodiments, the touch sensor 180K may also be disposed on the surface of the electronic device 100 at a different location than the display 194.
The keys 190 include a power-on key, a volume key, etc. The keys 190 may be mechanical keys or touch keys. The electronic device 100 may receive key inputs, generating key signal inputs related to user settings and function controls of the electronic device 100.
The indicator 192 may be an indicator light, may be used to indicate a state of charge, a change in charge, a message indicating a missed call, a notification, etc.
The software system of the electronic device 100 will be described next.
The software system of the electronic device 100 may employ a layered architecture, an event driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture. In the embodiment of the application, an Android (Android) system with a layered architecture is taken as an example, and a software system of the electronic device 100 is illustrated.
Fig. 7 is a block diagram of a software system of the electronic device 100 according to an embodiment of the present application. Referring to fig. 7, the hierarchical architecture divides the software into several layers, each with distinct roles and branches. The layers communicate with each other through a software interface. In some embodiments, the Android system is divided into four layers, from top to bottom, an application layer, an application framework layer, a native layer (local service layer), and a kernel layer, respectively.
The application layer may include a series of application packages. As shown in fig. 7, the application package may include applications for cameras, gallery, calendar, phone calls, maps, navigation, WLAN, bluetooth, music, video, short messages, etc.
The application framework layer provides an application programming interface (application programming interface, API) and programming framework for application programs of the application layer. The application framework layer includes a number of predefined functions. As shown in fig. 7, the application framework layer may include a scene detection module, a CPU monitoring module, a time monitoring module, a decision module, an application start monitoring module, and a communication module. The scene detection module is used for detecting a scene where the electronic equipment is currently located, for example, monitoring that the electronic equipment is in a screen-off scene, a scene of an application program which is cleaned and operated by a user, and the like. The CPU monitoring module is used for monitoring the running state, the load condition and the like of the CPU. The time monitoring module is used for determining time of each operation of the electronic device, for example, determining operation time of each time of regular fragmentation of the memory. The decision module is used for determining whether the fragmentation of the memory is regular. The application start monitoring module is used for monitoring whether an application program is started. The communication module is used for realizing communication between the application framework layer and other layers, for example, the communication module can send messages and/or instructions to the Native layer.
As an example of the present application, the Native layer includes a kernel node access control module, where the kernel node access control module is configured to transfer a message between the application framework layer and the kernel layer, for example, the kernel node access control module may receive a message and/or an instruction sent by the communication module, and send the received message and/or instruction to the kernel layer.
The kernel layer is a layer between hardware and software. The inner core layer at least comprises a display driver, a camera driver, an audio driver and a sensor driver.
As an example of the present application, a normalization module may also be included in the kernel layer, which may fragment the memory.
The workflow of the electronic device 100 software and hardware is illustrated below in connection with capturing a photo scene.
When touch sensor 180K receives a touch operation, a corresponding hardware interrupt is issued to the kernel layer. The kernel layer processes the touch operation into the original input event (including information such as touch coordinates, time stamp of touch operation, etc.). The original input event is stored at the kernel layer. The application framework layer acquires an original input event from the kernel layer, and identifies a control corresponding to the original input event. Taking the touch operation as a click operation, the control corresponding to the click operation is a control of a camera application icon as an example, the camera application calls an interface of an application program framework layer, starts the camera application, calls a kernel layer to start a camera driver, and captures a still image or video through a camera 193.
In order to facilitate understanding, before describing the method provided by the embodiment of the present application in detail, an application scenario related to the embodiment of the present application is described next by taking an example that the electronic device is a mobile phone and a plurality of cards are stacked and displayed in a desktop of the mobile phone based on an execution body provided by the embodiment of the present application.
Referring to fig. 8, fig. 8 is a schematic diagram illustrating an application scenario according to an exemplary embodiment. In one possible scenario, during the use of the mobile phone by the user, it is likely that the electronic device will be turned off, and, for example, in the case that the mobile phone displays a desktop, if the user presses the off-screen button 1, the mobile phone enters the off-screen state in response to the pressing operation of the off-screen button 1. Meanwhile, the scene monitoring module 2 in the mobile phone can monitor the operation of the screen-off key, so that the scene monitoring module 2 can send a scene transition message to the decision module 3, wherein the scene transition message carries a scene of which the current scene is in a screen-off state; after receiving the scene transition message, the decision module 3 can determine whether the scene entering the screen-off state is a scene capable of being fragmented and regular, 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 last time of fragmentation regulation to obtain a first time interval, and sends a time detection message to the decision module 3, wherein the time detection message carries the first time interval; the decision module 3 may acquire a first time interval from the time detection message, and determine whether the first time interval is greater than or equal to a first interval threshold, if yes, 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, wherein the load detection message carries the load of the CPU; the decision module 3 obtains the load of the CPU from the load detection message, determines whether the load of the CPU is smaller than or equal to a load threshold value, and if so, sends a regular instruction to the communication module 6, wherein the regular instruction carries a first preset value which is not zero; the communication module 6 sends the regular instruction to the kernel node access control module 7; the kernel node access control module 7 sends a regular instruction to the regular module 8; the normalization module 8 determines the first preset value as a normalization threshold value, and performs fragmentation normalization on the memory if the normalization threshold value is not zero.
For the purposes of illustrating the interaction process, the multiple decision modules depicted in the figures of the embodiments of the present application are the same decision module.
As an example, when the mobile phone is in the on-screen state, if the user does not perform any operation on the mobile phone for a long time, the mobile phone will also enter the off-screen state, and after the mobile phone enters the off-screen state, the mobile phone may perform memory fragmentation according to the rule flow shown in fig. 8.
It should be noted that, the first interval threshold, the load threshold, and the first preset value may be set according to requirements, for example, the first interval threshold may be 20 seconds, 25 seconds, or 30 seconds. The load of the CPU may be described by the number of processes currently running or the use rate of the CPU, and thus, the load threshold may be set according to the load of the CPU, and in the case where the load of the CPU is described by the use rate of the CPU, the load threshold may be 50%, 40%, 35%, or the like; in the case where the load of the CPU is described by the number of processes, the load threshold may be 5, 6, 7, or the like. The first preset value may be a value other than 0, and the first preset value may be 20%, 30%, etc.
As an example, after the mobile phone enters the off-screen state and performs the operation of fragmentation alignment according to the above manner, the change of the fragmentation index is shown in fig. 9, where curve 1 in fig. 9 is the fragmentation index corresponding to the different order indexes before the fragmentation alignment, the order indexes are used for the size of the index continuous memory, and curve 2 is the fragmentation index corresponding to the different order indexes after the fragmentation alignment. As can be seen from fig. 9, after the fragmentation is completed, the fragmentation index is significantly reduced, which indicates that the continuous memory in the memory is increased.
Referring to fig. 10, fig. 10 is a schematic diagram illustrating an application scenario according to another exemplary embodiment. In another possible scenario, if a plurality of application programs are running in the background of the mobile phone during the process of using the mobile phone by the user, in order to avoid the mobile phone from being blocked, the user may clean the plurality of application programs running in the background. For example, when the desktop is displayed on the mobile phone, the user may perform an operation of opening a background running task on the desktop of the mobile phone, for example, the user may perform an operation of stopping after sliding upwards on the desktop with the bottom of the desktop as a starting point, and in response to the operation of sliding upwards and stopping on the desktop, when the background running task exists, display a background running interface, where an application interface and a cleaning control 9 of a plurality of application programs running in the background are displayed in a folding manner, and the user may click on the cleaning control 9; the mobile phone responds to the clicking operation of the cleaning control 9, and can exit the operation of a plurality of application programs running in the background. Meanwhile, the scene monitoring module 2 in the mobile phone can monitor the triggering operation of the cleaning control, so that the scene monitoring module 2 can send a scene transition message to the decision module 3, wherein the scene transition message carries the scene of the cleaning application program as the current scene; after receiving the scene transition message, the decision module 3 can determine whether the scene of cleaning all the running application programs is a scene capable of being fragmented and regular, 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 last time of fragmentation regulation to obtain a first time interval, and sends a time detection message to the decision module 3, wherein the time detection message carries the first time interval; the decision module 3 may acquire a first time interval from the time detection message, and determine whether the first time interval is greater than or equal to a first interval threshold, if yes, 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, wherein the load detection message carries the load of the CPU; the decision module 3 obtains the load of the CPU from the load detection message, determines whether the load of the CPU is smaller than or equal to a load threshold value, and if so, sends a regular instruction to the communication module 6, wherein the regular instruction carries a first preset value which is not zero; the communication module 6 sends the regular instruction to the kernel node access control module 7; the kernel node access control module 7 sends a regular instruction to the regular module 8; the normalization module 8 determines the first preset value as a normalization threshold value, and performs fragmentation normalization on the memory if the normalization threshold value is not zero.
Referring to fig. 11, fig. 11 is a schematic diagram illustrating an application scenario according to another exemplary embodiment. In another possible scenario, if a user runs a plurality of applications in the background of the mobile phone during the use of the mobile phone, the user may perform a complete exit operation on the social application in the background running interface in order to completely exit a certain application, for example, to completely exit the social application. In an exemplary case that the mobile phone displays an application interface of the social application program, a user may perform an operation of opening a background running task on the application interface of the social application program, for example, the user may perform an operation of sliding upwards and then stopping on the application interface with the bottom of the application interface of the social application program as a starting point, and in response to the operation of sliding upwards and stopping on the application interface, display a background running interface in which the application interface of the social application program is displayed, and the user may perform an operation of sliding upwards on the application interface of the social application program in the background running interface; the mobile phone responds to the upward sliding operation of the application interface of the social application program in the background operation interface, and the social application program can be withdrawn from operation from the foreground and the background. Meanwhile, the scene monitoring module 2 in the mobile phone can monitor the cleaning operation of the video application program in the background operation interface, so the scene monitoring module 2 can send a scene transition message to the decision module 3, wherein the scene transition message carries the current scene as the scene for cleaning a single application program; after receiving the scene transition message, the decision module 3 can determine whether the scene of cleaning the single running application program is a scene capable of being fragmented and regular, 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 last time of fragmentation regulation to obtain a first time interval, and sends a time detection message to the decision module 3, wherein the time detection message carries the first time interval; the decision module 3 may acquire a first time interval from the time detection message, and determine whether the first time interval is greater than or equal to a first interval threshold, if yes, 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, wherein the load detection message carries the load of the CPU; the decision module 3 obtains the load of the CPU from the load detection message, determines whether the load of the CPU is smaller than or equal to a load threshold value, and if so, sends a regular instruction to the communication module 6, wherein the regular instruction carries a first preset value which is not zero; the communication module 6 sends the regular instruction to the kernel node access control module 7; the kernel node access control module 7 sends a regular instruction to the regular module 8; the normalization module 8 determines the first preset value as a normalization threshold value, and performs fragmentation normalization on the memory if the normalization threshold value is not zero.
As an example, after the mobile phone is in the cleaning scenario of the application program and performs the fragmentation alignment operation in the above manner, the change of the fragmentation index is shown in fig. 12, where a curve 3 in fig. 12 is the fragmentation index corresponding to the different order indexes before the fragmentation alignment is performed, and a curve 4 is the fragmentation index corresponding to the different order indexes after the fragmentation alignment is performed. As can be seen from fig. 12, after the fragmentation is completed, the fragmentation index is significantly reduced, which indicates that the continuous memory in the memory is increased.
As an example, after the mobile phone fragments and organizes the scene of cleaning a single application, tens of megabits of continuous memory can be organized each time. Illustratively, referring to table 1, table 1 describes the resulting continuous memory after fragmentation normalization in a single cleaned scenario for different applications.
TABLE 1
In the examples of the present application, the data shown in table 1 are merely examples, and the examples of the present application are not limited thereto.
Referring to fig. 13, fig. 13 is a schematic diagram of an application scenario shown according to another exemplary embodiment. In yet another possible scenario, the user may need to be returned to the desktop of the handset by the application interface of any one of the application programs during the user's use of the handset. For example, in a case where the mobile phone displays an application interface of the camera application, the user may perform an upward sliding operation from the bottom of the application interface of the camera application, and the mobile phone may display a desktop of the mobile phone in response to the upward sliding operation. Meanwhile, 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 transition message to the decision module 3, wherein the scene transition message carries the scene that the current scene is returned to the desktop; after the decision module 3 receives the scene transition message, it can determine whether the scene returned to the desktop is a scene capable of being fragmented and regular, 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 last time of fragmentation regulation to obtain a first time interval, and sends a time detection message to the decision module 3, wherein the time detection message carries the first time interval; the decision module 3 may acquire a first time interval from the time detection message, and determine whether the first time interval is greater than or equal to a first interval threshold, if yes, 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, wherein the load detection message carries the load of the CPU; the decision module 3 obtains the load of the CPU from the load detection message, determines whether the load of the CPU is smaller than or equal to a load threshold value, and if so, sends a regular instruction to the communication module 6, wherein the regular instruction carries a first preset value which is not zero; the communication module 6 sends the regular instruction to the kernel node access control module 7; the kernel node access control module 7 sends a regular instruction to the regular module 8; the normalization module 8 determines the first preset value as a normalization threshold value, and performs fragmentation normalization on the memory if the normalization threshold value is not zero.
As an example, when the mobile phone exits from the application interface of the camera application program to the desktop, after the operation of the fragmentation alignment is performed in the above manner, the change of the fragmentation index is shown in fig. 14, where a curve 5 in fig. 14 is the fragmentation index corresponding to the different order index before the fragmentation alignment is performed, and a curve 6 is the fragmentation index corresponding to the different order index after the fragmentation alignment is performed. As can be seen from fig. 14, after the fragmentation is completed, the fragmentation index is significantly reduced, which indicates that the continuous memory in the memory is increased.
It should be noted that, in the embodiment of the present application, the application scenario shown in fig. 8 to 14 is merely taken as an example and the embodiment of the present application is not limited to the above description.
Based on the execution body and the application scenario provided by the above embodiment, the method for managing the memory provided by the embodiment of the present application is described next. Referring to fig. 15, fig. 15 is a flow chart illustrating a method for organizing a memory according to an exemplary embodiment. By way of example, and not limitation, the method is applied to an electronic device, and the electronic device is illustrated by using a plurality of module interaction implementations shown in fig. 7, where the method may include some or all of the following:
Step 1501: the scene detection module detects a current scene.
Because various operations may be performed by the user during the use of the electronic device, different operations may enable the electronic device to enter different scenes, and the electronic device may fragment the memory in some specific scenes, so the scene detection module may detect the current scene of the electronic device.
As an example, the scene detection module may actively detect a scene in which the electronic device is currently located, or may passively detect a scene in which the electronic device is currently located. Under the condition that the scene detection module actively detects the scene where the electronic device is currently located, the scene detection module can detect the scene in real time or detect the scene at intervals of a third designated time. Under the condition that the scene detection module passively detects the current scene of the electronic equipment, the scene detection module can detect the current scene of the electronic equipment according to the triggering operation of the user under the condition that the user performs any triggering operation on the electronic equipment.
It should be noted that the third specified time interval may be preset according to the requirement, for example, the third specified time interval may be 30 seconds, 60 seconds, 120 seconds, or the like.
Step 1502: the scene detection module sends a scene transition message to the decision module.
It should be noted that, the scene transition message carries the current scene.
Step 1503: the decision module receives a scene transition message.
Step 1504: the decision module determines whether fragmentation can be performed according to the current scene carried in the scene transition message.
Because not all scenes can be subjected to the fragmentation regulation of the memory, the decision module needs to determine whether to perform the fragmentation regulation according to the current scene carried in the scene transition message.
As an example, the decision module may match the current scene with a stored scene, and determine that the current scene of the electronic device may be fragmented and structured if the same scene as the current scene of the electronic device exists in the stored scene. Under the condition that the stored scene does not have the same scene as the current scene of the electronic equipment, determining that the current scene of the electronic equipment cannot be fragmented and regular; in case fragmentation is not possible, the decision module does nothing.
It should be noted that, the stored scenes are memory-capable fragmentation-structured scenes, and these scenes may be referred to as memory-structured scenes. The memory regular scene at least comprises a scene of cleaning at least one application program running in the electronic equipment, a scene of returning to the desktop of the electronic equipment from an application interface of any application program, a scene of entering an off-screen state of the electronic equipment and the like. That is, in the case where the current scene is a cleaning operation for at least one application running in the electronic device, or in the case where the current scene is a return operation for returning the desktop of the electronic device from the application interface of any one application, or in the case where the current scene is a screen-off operation for the electronic device received, the decision module may determine that the current scene is capable of performing fragmentation normalization of the memory. For example, the scenario may refer to the application scenario shown in fig. 8-14 described above.
In some embodiments, the fact that the stored scene does not have the same scene as the current scene of the electronic device may refer to a situation that a scene triggered by a trigger operation of a user does not belong to any one of the memory-regular scenes, and in this case, the decision module does not need to execute the following steps, that is, the electronic device does not perform fragmentation-normalization of the memory.
Step 1505: and the decision module sends a time acquisition message to the time monitoring module under the condition that the current scene can be fragmented and regular.
In order to avoid frequent memory fragmentation, the decision module may further send a time acquisition message to the time monitoring module when determining that the current scene is capable of fragmentation.
Step 1506: the time monitoring module receives the time acquisition message.
Step 1507: the time monitoring module determines a time interval between the current time and the last time of defragmentation normalization to obtain a first time interval.
Because the time monitoring module can record the time for carrying out the fragmentation regulation, under the condition that the time monitoring module receives the time acquisition message, the time for carrying out the fragmentation regulation last time can be acquired, and the time interval between the current time and the time for carrying out the fragmentation regulation last time is determined, so that the first time interval is obtained.
As an example, the last time the fragmentation was performed may be recorded by the time monitoring module when the last time the time recording message sent by the decision module was received. That is, each time the fragmentation of the memory is performed, the decision module may send a time recording message to the time monitoring module, and the time monitoring module may record the time for performing the fragmentation when each time the time recording message is received.
Step 1508: the time monitoring module sends a time detection message to the decision module, wherein the time detection message carries a first time interval.
Step 1509: the decision module receives a time detection message.
Step 1510: the decision module obtains a first time interval from the time detection message.
Step 1511: and the decision module sends a load acquisition message to the CPU monitoring module under the condition that the first time interval is greater than or equal to a first interval threshold value.
Under the condition that the first time interval is greater than or equal to the first interval threshold, the fact that the last time of fragmentation is longer is indicated, frequent fragmentation is not caused by the current time of fragmentation, and therefore the decision module can continuously and further judge whether the fragmentation can be performed. In addition, since the fragmentation regulation is performed under the high load state of the CPU, the consumption of the CPU may be further increased, so as to affect the performance of the electronic device, so that in order to avoid the fragmentation regulation performed under the high load state of the CPU, the decision module may send a load acquisition message to the CPU monitoring module.
As one example, in the event that the first time interval is less than the first interval threshold, the decision module may no longer perform any operations.
Since in case the first time interval is smaller than the first interval threshold, it is stated that the fragmentation normalization has been performed a short time ago, the decision module does not need to perform any operation in order to avoid frequent fragmentation normalization.
Step 1512: the CPU monitoring module receives the load acquisition message.
Step 1513: the CPU monitoring module acquires the load of the CPU.
As an example, the CPU monitoring module may perform load detection on the CPU at intervals of a second time within a first specified duration after receiving the load acquisition message, to obtain a plurality of load detection results; the plurality of load detection results are determined as the load of the CPU, or the smallest load detection result among the plurality of load detection results is determined as the load of the CPU.
It should be noted that the first specified duration may be preset according to the requirement, for example, the first specified duration may be 5 seconds, 6 seconds, 7 seconds, or the like. The second time interval may also be preset according to requirements, for example, the second time interval may be 0.2 seconds or 0.3 seconds.
Step 1514: the CPU detection module sends a load detection message to the decision module, wherein the load detection message carries the load of the CPU.
Step 1515: the decision module receives a load detection message.
Step 1516: the decision module obtains the load of the CPU from the load detection message.
From the above, the CPU monitoring module may determine that the plurality of load detection results are the load of the CPU, or may determine that the minimum load detection result of the plurality of load detection results is the load of the CPU, so the decision module may acquire the plurality of load detection results, or may acquire the minimum load detection result.
Step 1517: and the decision module sends a regular instruction to the communication module and sends a time recording message to the time monitoring module under the condition that the load of the CPU is smaller than or equal to the load threshold value.
It should be noted that the regular instruction carries a first preset value that is not zero.
Since the load of the CPU may be a plurality of load detection results or a minimum load detection result, the operation of the decision module to determine whether the load of the CPU is less than or equal to the load threshold is different in the case that the load of the CPU is different.
As one example, in the case where the load of the CPU is the minimum load detection result, the decision module may directly determine whether the minimum load detection result is less than or equal to the load threshold, and in the case where the minimum load detection result is less than or equal to the load threshold, determine that the load of the CPU is less than or equal to the load threshold.
As one example, in a case where the load of the CPU includes a plurality of load detection results, if at least one load detection result of the plurality of load detection results is less than or equal to the load threshold value, it is determined that the load of the CPU is less than or equal to the load threshold value.
Under the condition that the load of the CPU is smaller than or equal to the load threshold value, the CPU is in a low-load state, and at the moment, the influence of fragmentation regulation on the load of the CPU is small, so that the decision module can send a regulation instruction to the communication module and send a time recording message to the time monitoring module.
Step 1518: the time monitoring module receives the time recording message.
Step 1519: the time monitoring module records the time for carrying out fragmentation regulation.
Step 1520: the communication module receives the regular instruction.
It should be noted that, in the embodiment of the present application, the execution sequence of the step 1518 and the step 1520 is not limited.
Step 1521: the communication module sends the regular instruction to the kernel node access control module.
Step 1522: the kernel node access control module receives the regular instruction.
Step 1523: the kernel node access control module sends the normalization instruction to the normalization module.
Step 1524: the normalization module receives the normalization instructions.
Step 1525: the normalization module determines a first preset value as a normalization threshold.
Because the first preset value is carried in the regular instruction, the regular module can acquire the first preset value from the regular instruction and determine the first preset value as a regular threshold.
The normalization threshold is the maximum value that can be reached by the continuous memory in the memory after the fragmentation normalization.
Step 1526: and the normalization module acquires the fragmentation index corresponding to the memory under the condition that the size of the continuous memory in the memory is a second preset value under the condition that the normalization threshold value is not zero.
It should be noted that, the fragmentation index is used to describe the fragmentation degree of the memory. The fragmentation index may range from 0 to 100%, and the higher the fragmentation index of the memory, the more severe the fragmentation of the memory is described.
It should be further noted that the continuous memory in the memory can be generally represented by an order (order index). Illustratively, order9 represents the 9 th order of continuous page physical memory of 2, where each page is 4096 bytes, i.e., 4MB of continuous physical memory, and the fragmentation index of order9 can be determined by the following first equation (1).
/>
As an example, in the case where the normalization threshold is 0, the normalization module does not perform fragmentation normalization.
Since the normalization threshold is the maximum value that can be reached by the continuous memory in the memory after the fragmentation normalization is performed, when the normalization threshold is 0, the continuous memory is not required, and therefore, the fragmentation normalization is not required.
Step 1527: and under the condition that the fragmentation index is larger than or equal to a preset fragmentation threshold, the fragmentation regulation module fragments and regulates the memory according to the continuous memory size of a third preset value.
It should be noted that the third preset value may be preset, and the third preset value may be 2mb, 4mb, or the like. The third preset value may be the same as or different from the second preset value, which is not particularly limited in the embodiment of the present application. In addition, the preset fragmentation threshold may also be preset according to requirements, for example, the preset fragmentation threshold may be 97%, 96%, or 95%.
It should be noted that, by setting a higher preset fragmentation threshold, frequent fragmentation operations can be avoided, thereby avoiding the influence on the load of the CPU.
As an example, the operation of the regularization module for performing the fragmentation of the memory with the continuous memory size of the third preset value may refer to the related art, for example, since the fragmentation is performed in units of pages, the decision module may use a page migration mechanism to migrate the movable pages (occupied pages) in the memory to sort the discrete free pages into continuous pages, so as to obtain the continuous memory.
Step 1528: the normalization module is used for determining whether all the memories are normalized after the memory is fragmented and normalized according to the memory size of the third preset value.
Step 1529: and after all memories are regulated, the regulation module determines whether the fragmentation index is smaller than a preset fragmentation threshold.
Step 1530: and ending the current fragmentation regulation under the condition that the fragmentation index is smaller than a preset fragmentation threshold value.
It should be noted that, the normalization module may set the normalization threshold to zero to end the current fragmentation normalization.
In the embodiment of the application, when the electronic equipment receives the triggering operation of the user and the scene triggered by the triggering operation belongs to the memory regularization scene, if the CPU is in a low-load state, the memory can be fragmented and regulated. Because the load condition of the CPU is considered when the fragmentation is performed, the fragmentation is performed in a high-load state of the CPU can be avoided, so that the influence on the load of the CPU is improved, and the possibility of performance degradation of the electronic equipment is reduced.
In the process of performing the fragmentation, some operations of the electronic device by the user may break the fragmentation of the memory, so next, the embodiment of the present application will be explained for the termination of the fragmentation of the memory, and referring to fig. 16, fig. 16 is a flowchart of a memory management method according to another exemplary embodiment. By way of example, and not limitation, the method is applied to an electronic device, and the electronic device is illustrated by using a plurality of module interaction implementations shown in fig. 7, where the method may include some or all of the following:
The operations of steps 1601 to 1627 may refer to the operations of steps 1501 to 1527, which are not described in detail in the embodiments of the present application.
Step 1628: in the process of fragmentation regulation, the application start monitoring module monitors that the electronic equipment receives a start operation of any one application program.
Step 1629: the application start monitoring module sends an application start message to the decision module.
Step 1630: the decision module receives an application launch message.
Step 1631: the decision module judges whether the electronic equipment performs memory fragmentation normalization at the first time point.
It should be noted that, the time difference between the first time point and the second time point is a second specified duration before the second time point, and the second time point is a time point when the start operation is received.
Step 1632: if the electronic equipment is in fragmentation regulation at the first time point, the decision module sends a termination instruction to the communication module.
It should be noted that the termination instruction carries a second preset value, where the second preset value is zero.
Step 1633: the communication module receives a termination instruction.
Step 1634: the communication module sends a termination instruction to the kernel node access control module.
Step 1635: the kernel node access control module receives a termination instruction.
Step 1636: the kernel node access control module sends a termination instruction to the normalization module.
Step 1637: the normalization module receives a termination instruction.
Step 1638: the normalization module terminates the fragmentation normalization of the memory.
As one example, the normalization module may determine the second preset value as a normalization threshold to terminate the fragmentation normalization of the memory.
Since the second preset value is zero, the normalization threshold is zero if the second preset value is determined as the normalization threshold, and the normalization module does not perform fragmentation normalization if the normalization threshold is zero. Therefore, by setting the second preset value as the normalization threshold value, the normalization module can be made to not perform fragmentation normalization any more.
As one example, if the normalization module has stopped performing fragmentation normalization before receiving the termination instruction and set the normalization threshold to zero, the normalization module does not perform any more operations after receiving the termination instruction.
In the embodiment of the application, in the process of fragmenting and regulating the electronic equipment, if the starting operation of any one application program is received, the related operation of fragmenting and regulating can be terminated in time under the condition that the first time point is determined to be in the stage of fragmenting and regulating, thereby improving the problem of application program blocking caused by fragmenting operation and reducing the response time and time delay for user operation.
Since the user may also perform some operations on the electronic device during the process of acquiring the load of the CPU, these operations may also interrupt the acquisition of the load of the CPU. Therefore, next, the embodiment of the present application will be explained for terminating the load acquisition of the CPU, please refer to fig. 17, fig. 17 is a flowchart illustrating a method for managing the memory according to another exemplary embodiment. By way of example, and not limitation, the method is applied to an electronic device, and the electronic device is illustrated by using a plurality of module interaction implementations shown in fig. 7, where the method may include some or all of the following:
the operations of steps 1701 to 1713 may refer to the operations of steps 1501 to 1513, which are not described in detail in the embodiments of the present application.
Step 1714: in the process that the CPU detection module acquires the CPU, the application start monitoring module monitors that the electronic equipment receives a start operation of any one application program.
Step 1715: the application start monitoring module sends an application start message to the decision module.
Step 1716: the decision module receives an application launch message.
Step 1717: and the decision module sends a stop detection message to the CPU monitoring module.
Step 1718: the CPU monitoring module receives the stop detection message.
Step 1719: the CPU monitoring module stops the load detection of the CPU.
In the embodiment of the application, in the process of fragmenting and regulating the electronic equipment, if the starting operation of any one application program is received, the related operation of fragmenting and regulating can be terminated in time under the condition that the first time point is determined to be in the stage of fragmenting and regulating, thereby improving the problem of application program blocking caused by fragmenting operation and reducing the response time and time delay for user operation.
It should be noted that, the foregoing describes an example of a method for implementing memory management by the electronic device through interaction of the modules shown in fig. 7, and in order to further understand the embodiments of the present application, the method is described by using the electronic device as an example, please refer to fig. 18, and fig. 18 is a flow chart of a memory management method according to another exemplary embodiment. By way of example and not limitation, the method may include some or all of the following:
step 1801: and receiving triggering operation of the user on the electronic equipment.
It should be noted that the triggering operation may include any operation on the electronic device.
Step 1802: responding to the triggering operation, and determining whether a scene triggered by the triggering operation belongs to a memory regular scene; if yes, the following operation of step 1803 is performed, and if not, the operation of step 1807 is performed.
Because the electronic device may not perform memory fragmentation normalization under all trigger operations, in response to the trigger operations, the electronic device may determine whether a scene triggered by the trigger operations belongs to a memory normalization scene.
It should be noted that the memory-organized scene may include one or more of a scene of cleaning up at least one application running in the electronic device, a scene of returning to the desktop of the electronic device from an application interface of any one application, and a scene of the electronic device entering an off-screen state. For example, the scenario may refer to the application scenario shown in fig. 8-14 described above.
In some embodiments, if the CPU of the electronic device is in a low load state, the memory may be fragmented and ordered under the condition that the scene triggered by the triggering operation belongs to the memory ordering scene. Under the condition that the scene triggered by the triggering operation belongs to the memory normalization scene, if the CPU of the electronic device is in a low-load state, the operation of performing fragmentation normalization on the memory may refer to the following operations from step 1803 to step 1806.
It is worth to say that, because the electronic device is in the situation of regular memory, the electronic device does not need to perform memory allocation generally, that is, the electronic device can perform fragmentation of the memory under the situation that the electronic device does not need to perform memory allocation, so that the electronic device can perform memory allocation quickly under the situation that the electronic device subsequently needs to perform fragmentation, and response time and time delay to user operation are reduced.
Step 1803: a first time interval between the current time and the last time the fragmentation normalization was performed is obtained.
In order to avoid frequently performing fragmentation regulation on the memory, the electronic device may acquire a first time interval between a current time and a time of performing the last fragmentation regulation when a scene triggered by the triggering operation belongs to the memory regulation scene.
As an example, when the electronic device performs fragmentation normalization each time, the corresponding normalization time may be recorded, so that when the electronic device determines that the scene triggered by the triggering operation belongs to the memory normalization scene, the first time interval may be determined according to the last recorded normalization time and the current time.
The electronic equipment comprises a CPU monitoring module, a time monitoring module and a decision module; in this way, when determining that the scene triggered by the triggering operation belongs to the memory regular scene, the electronic device obtains a first time interval between the current time and the last time of fragmentation and normalization, including: under the condition that the scene triggered by the triggering operation is determined to belong to a memory regular scene, the decision module sends a time acquisition message to the time monitoring module; the time monitoring module determines a time interval between the current time and the last time of defragmentation normalization to obtain a first time interval; the time monitoring module sends a time detection message to the decision module, wherein the time detection message carries a first time interval; the decision module obtains a first time interval from the time detection message.
It should be noted that, through the CPU monitoring module, the time monitoring module, and the decision module, the operation of obtaining the first time interval may refer to the operations of steps 1504-1510, which are not described in detail in the embodiment of the present application.
Step 1804: determining whether the first time interval is greater than or equal to the first interval threshold, if so, executing the operation of step 1805, and if not, terminating the operation, i.e. executing step 1807.
Step 1805: and under the condition that the first time interval is greater than or equal to a first interval threshold value, acquiring the load of the CPU.
It should be noted that, by acquiring the CPU load when the first time interval is greater than or greater than the first interval threshold, frequent fragmentation of the memory can be avoided, and an increase in the load on the CPU is avoided.
In some embodiments, the electronic device may obtain the load of the CPU when the first time interval is greater than or equal to the first interval threshold, or may directly obtain the load of the CPU when it is determined that the scene triggered by the triggering operation belongs to the memory-regulated scene, which is not particularly limited in the embodiments of the present application.
As can be seen from the foregoing, the electronic device may include not only the decision module and the time monitoring module, but also the CPU monitoring module, so, 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: under the condition that the first time interval is greater than or equal to a first interval threshold value, 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.
It should be noted that, the operation of the electronic device to obtain the load of the CPU through the decision module and the CPU detection module may refer to the operations of the steps 1511 to 1516, which are not described in detail in the embodiment of the present application.
In some embodiments, in a case where 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 also detect the load of the CPU in a period of time, and obtain the load of the CPU according to the load detection result in the period of time. That is, in the case where the first time interval is greater than or equal to the first interval threshold, the operation of the electronic device to acquire the load of the CPU includes: under the condition that the first time interval is greater than or equal to a first interval threshold value, carrying out load detection on the CPU at intervals of a second time interval within a first appointed duration to obtain a plurality of load detection results; the plurality of load detection results are determined as the load of the CPU, or the smallest load detection result among the plurality of load detection results is determined as the load of the CPU.
It is worth to say that, through detecting the load of CPU in the first appointed duration, thereby guaranteed the accuracy of the load of CPU who acquires.
In some embodiments, the electronic device may determine not only the plurality of load detection results as the load of the CPU, or the minimum load detection result of the plurality of load detection results as the load of the CPU, but also the electronic device may determine the load of the CPU in other manners. The electronic device may also determine an average load detection result of the plurality of load detection results, and determine the average load detection result as the load of the CPU, for example.
Step 1806: and under the condition that the load of the CPU is smaller than or equal to the load threshold value, the memory is fragmented and regulated.
Because the current load of the CPU is smaller under the condition that the load of the CPU is smaller than or equal to the load threshold, the performance of the CPU is not seriously affected even if the fragmentation is performed, and therefore, the electronic equipment can perform the fragmentation on the memory under the condition that the load of the CPU is smaller than or equal to the load threshold.
It is worth to say that, by performing the fragmentation normalization of the memory under the condition of smaller load of the CPU, the performance of the CPU can be better protected, and the performance of the electronic device is further protected.
From the above, the load of the CPU may be the current real-time load, the minimum load detection result in the first specified duration, or a plurality of load detection results in the first specified duration. Depending on the load of different CPUs, the electronic device determines whether the load of the CPU is less than or equal to the load threshold is also different.
As one example, in the case where the load of the CPU is the current real-time load or is the minimum load detection result within the first specified duration, the electronic device may directly compare the load of the CPU with the load threshold; and under the condition that the load of the CPU is smaller than or equal to the load threshold value, the memory is fragmented and regulated.
As an example, in a case where the load of the CPU includes a plurality of load detection results, if at least one load detection result of the plurality of load detection results is less than or equal to a load threshold value, the memory is fragmented and normalized.
It is worth to say that, by performing fragmentation normalization on the memory under the condition that at least one load detection result is smaller than or equal to the load threshold value, the situation that the fragmentation normalization is performed under the high load state of the CPU is avoided, and the influence on the performance of the electronic equipment is reduced.
In some embodiments, as can be seen from the foregoing, in a case where the load of the CPU includes a plurality of load detection results, the electronic device may further determine an average load detection result of the plurality of load detection results as the load of the CPU, and therefore, in a case where the load of the CPU is the average load detection result of the plurality of load detection results, if the average load detection result is less than or equal to the load threshold, the electronic device may perform fragmentation normalization on the memory.
As can be seen from the above, the electronic device further includes a communication module and a normalization module, so that the electronic device may send a normalization instruction to the normalization module of the kernel through the communication module, so as to perform fragmentation normalization of the memory through the normalization module.
It should be noted that, the operation of the electronic device for defragmentation and normalization of the memory may refer to a method flowchart shown in fig. 16 below.
It should be further noted that, during the process of performing the fragmentation alignment on the electronic device, the user may start any one application program in the electronic device, in which case, the electronic device may terminate the fragmentation alignment on the memory, and the operation may refer to the following operations of steps a to C.
Step A: and judging whether a starting operation of any application program in the electronic equipment is received, if yes, executing the operation of the following step B, and if not, continuing to execute the operation of the step 1806.
And (B) step (B): and C, judging whether the electronic equipment is subjected to memory fragmentation regulation at a first time point under the condition that the starting operation of any one application program in the electronic equipment is received, and if so, executing the operation of the following step C.
It should be noted that, the time difference between the first time point and the second time point is a second specified duration before the second time point, and the second time point is a time point when the start operation is received.
It should be further noted that the second specified duration may be preset according to the requirement, for example, the second specified duration may be 2 seconds or 3 seconds.
Step C: if the electronic equipment is performing fragmentation regulation at the first time point, the fragmentation regulation of the memory is terminated.
As can be seen from the above, the electronic device further includes an application start monitoring module, so that the electronic device may monitor whether a start operation of any one application program is received through the application start monitoring module, or monitor whether an application start event occurs, and send an application start message to the decision module when it is monitored that a start operation of any one application program is received; the decision module can execute the operation in the step B under the condition of receiving the application starting message, namely judging whether the electronic equipment performs memory fragmentation normalization at the first time point, if so, the decision module can send a termination instruction to the normalization module of the kernel through the communication module, the termination instruction carries a second preset value, and the second preset value is zero; under the condition that the regulation module receives the termination instruction, a second preset value can be obtained from the stop instruction, and the second preset value is determined as a regulation threshold value; in the case where the normalization threshold is zero, the normalization module terminates the fragmentation normalization of the memory.
As one example, if at a first point in time the electronic device is in the process of performing the fragmentation normalization stage and the electronic device is in the process of acquiring the load state of the CPU, the electronic device may terminate the acquisition of the load of the CPU.
For example, in the case that the electronic device receives the starting operation of any one application program through the application starting monitoring module, an application starting message may be sent to the decision module; if the decision module starts the load acquisition process of the CPU in the fragmentation regulation stage of the memory, the decision module can send a detection stopping message to the CPU detection module; in the case where the CPU detection module receives the stop detection message, the detection of the load of the CPU may be stopped.
In some embodiments, after receiving the application start message, the decision module may stop sending the regular instruction if the regular instruction has not been sent.
Step 1807: the electronic device does not perform fragmentation normalization of the memory.
Under the condition that the scene triggered by the triggering operation does not belong to any one of the memory regular scenes, the fact that the current scene cannot be subjected to memory fragmentation regular is indicated, and therefore the electronic equipment does not carry out memory fragmentation regular.
It is worth to say that, under the condition that the scene triggered by the triggering operation does not belong to any one of the memory regularization scenes, the electronic equipment does not need to carry out memory fragmentation regularization, so that the problem that memory allocation is not timely in the process of carrying out the fragmentation regularization is avoided, and the problem of interface display blocking is further avoided.
In the embodiment of the application, when the electronic equipment receives the triggering operation of the user and the scene triggered by the triggering operation belongs to the memory regularization scene, if the CPU is in a low-load state, the memory can be fragmented and regulated. Because the load condition of the CPU is considered when the fragmentation is performed, the fragmentation is performed in a high-load state of the CPU can be avoided, so that the influence on the load of the CPU is improved, and the possibility of performance degradation of the electronic equipment is reduced.
The above description has been made on the operation of the electronic device in the application framework layer, and the electronic device generally performs fragmentation of the memory in the kernel, so the following explanation will be made on the operation of the electronic device in the kernel for fragmentation of the memory. Referring to fig. 19, fig. 19 is a flow chart illustrating a method for organizing a memory according to another exemplary embodiment. By way of example, and not limitation, the method is performed by an electronic device, and the method may include some or all of the following:
Step 1901: and under the condition that the scene triggered by the triggering operation belongs to the memory regularity scene, if the CPU of the electronic equipment is in a low-load state, acquiring the regularity threshold.
The normalization threshold is the maximum value that can be reached by the continuous memory in the memory after the fragmentation normalization. The CPU being in the low load state refers to the case where the load of the CPU described in fig. 18 is less than or equal to the load threshold.
From the above, the electronic device may include a decision module, a communication module, a kernel node access control module, and a regulation module; the decision module and the communication module are modules in the application framework layer, the regular module is a module in the kernel layer, and in order to enable the application framework layer to communicate with the kernel, a kernel node access control module can be arranged in the local layer in the electronic device, and the kernel node access control module can forward any one message and/or instruction sent by the application framework layer to the kernel layer.
In some embodiments, the operation of the electronic device to obtain the normalization threshold comprises: the decision module sends a regular instruction to the communication module, wherein the regular instruction carries a first preset value, and the first preset value is not zero; the communication module sends the regular instruction to the kernel node access control module; the kernel node access control module sends a normalization instruction to the normalization module; the normalization module determines a first preset value as a normalization threshold.
It should be noted that, the first preset value is a preset value according to the requirement, and the first preset value may be 20%, 30% or the like.
It is worth to say that, whether the operation of fragmentation regulation is triggered is determined in the decision module, and then the fragmentation regulation is carried out by the regulation module in the kernel layer, so that the triggering of the regulation instruction is more accurate, and the problem that the performance of the electronic equipment is reduced due to the fact that the real-time performance of the kernel layer triggering regulation instruction is poor and the triggering condition is easy to meet is solved.
In some embodiments, determining that the CPU of the electronic device is in a low-load state may be performed in an application framework layer or in a kernel layer, which is not particularly limited in the embodiments of the present application.
Since the first preset value is not zero, after the first preset value is determined as the regular threshold, the regular threshold is also not zero, and the memory can be fragmented and regular under the condition that the regular threshold is not zero. In the case where the normalization threshold is not zero, the operation of the electronic device for defragmentation normalization of the memory may refer to the following operations of steps 1902-1907.
Step 1902: and under the condition that the regular threshold value is not zero, obtaining a fragmentation index corresponding to the memory under the condition that the size of the continuous memory in the memory is a second preset value.
It should be noted that, the fragmentation index is used to describe the fragmentation degree of the memory. The second preset value is preset according to the requirement, and the second preset value can be represented by an order index, for example, the second preset value can be 2MB or 4 MB.
It is worth to say that, through obtaining the fragmentation index under the condition that the regular threshold value is not zero, thereby solve the problem that the regular operation of fragmentation is easy to trigger, influences the electronic equipment performance.
It should be further noted that, the operation of the electronic device to obtain the fragmentation index corresponding to the memory under the condition that the size of the continuous memory in the memory is the second preset value may refer to the operation of step 1526 in fig. 15, which is not described in detail in the embodiment of the present application.
Step 1903: and under the condition that the fragmentation index is larger than or equal to a preset fragmentation threshold, the memory is fragmented and regulated according to the continuous memory size of a third preset value.
It should be noted that, when the fragmentation index is greater than or equal to the preset fragmentation threshold, the operation of performing fragmentation normalization on the memory with the continuous memory size of the third preset value may refer to the operation of step 1527, which is not described in detail in the embodiment of the present application.
Step 1904: after the memory is fragmented and normalized by the memory size of the third preset value, determining whether all the memories are normalized, if so, performing the operation of step 1907, and if not, performing the operation of step 1905.
Step 1905: it is determined whether the regularity threshold is zero, if so, the following operation of step 1907 is performed, and if not, the following operation of step 1906 is performed.
As can be seen from the above, in the process of performing memory fragmentation alignment by the electronic device, the user may trigger the start operation of any one application program, and the electronic device may set the alignment threshold to zero when receiving the start operation of any one application program, so as to terminate the memory fragmentation alignment.
Note that, in the case where the regularity threshold is zero, it is stated that the user starts any one of the application programs, and in this case, the electronic apparatus needs to terminate the fragmentation of the memory, so the electronic apparatus may perform the operation of step 1907 described below, and in the case where the regularity threshold is not zero, the electronic apparatus may continue to perform the fragmentation of the memory, so the electronic apparatus may continue to perform the operation of step 1906 described below.
Step 1906: determining whether the fragmentation index is less than a preset fragmentation threshold, if so, executing the operation of step 1907, and if not, returning to the operation of step 1903.
Step 1907: and finishing fragmentation regulation of the memory.
It should be noted that, after the electronic device finishes the fragmentation normalization of the current memory, the normalization threshold may be set to zero.
In the embodiment of the application, in the process of carrying out fragmentation regulation on the electronic equipment, whether the fragmentation regulation is continued is determined by setting whether the regulation threshold is zero, so that the triggering of the regulation instruction is more accurate, and the problem of performance reduction of the electronic equipment caused by poor instantaneity of the kernel layer triggering regulation instruction and easy satisfaction of triggering conditions is solved.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may 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 processes or functions described in accordance with embodiments of the present application are produced in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. 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 one website, computer, server, or data center to another website, computer, server, or data center by a wired (e.g., coaxial cable, fiber optic, data subscriber line (Digital Subscriber Line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable 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 Disk (Digital Versatile Disc, DVD), or a semiconductor medium such as a Solid State Disk (SSD), etc.
The above embodiments are not intended to limit the present application, and any modifications, equivalent substitutions, improvements, etc. within the technical scope of the present application should be included in the scope of the present application.

Claims (12)

1. The memory regulating method is characterized by being applied to the electronic equipment, and comprises the following steps:
receiving triggering operation of a user on the electronic equipment;
responding to the triggering operation, and under the condition that a scene triggered by the triggering operation does not belong to a memory regular scene, not carrying out fragmentation regulation on a memory of the electronic equipment, wherein the memory regular scene is a scene capable of carrying out fragmentation regulation on the memory, and comprises one or more of a scene for cleaning at least one application program running in the electronic equipment, a scene for returning a desktop of the electronic equipment from an application interface of any application program and a scene for entering an off-screen state by the electronic equipment;
and if the current load value of the CPU of the electronic equipment is smaller than or equal to a load threshold value under the condition that the scene triggered by the triggering operation belongs to the memory regularization scene, fragmenting and regularizing the memory.
2. The method of claim 1, wherein, in the case where the scene triggered by the triggering operation belongs to the memory-ordering scene, if the current load value of the central processing unit CPU of the electronic device is less than or equal to a load threshold, performing fragmentation-ordering on the memory comprises:
under the condition that the scene triggered by the triggering operation belongs to the memory regularization scene, if the current load value of the CPU is smaller than or equal to the load threshold value, acquiring a regularization threshold value, wherein the regularization threshold value is the maximum value which can be reached by continuous memory in the memory after fragmentation regularization;
and under the condition that the normalization threshold value is not zero, fragmenting and normalizing the memory.
3. The method of claim 2, wherein the electronic device comprises a decision module, a communication module, a kernel node access control module, and a normalization module;
the acquiring the normalization threshold value comprises:
the decision module sends a regular instruction to the communication module, wherein the regular instruction carries a first preset value, and the first preset value is not zero;
the communication module sends the regular instruction to the kernel node access control module;
The kernel node access control module sends the regular instruction to the regular module;
the normalization module determines the first preset value as the normalization threshold.
4. A method as claimed in claim 2 or 3, wherein said fragmenting the memory if the regularity threshold is not zero, comprises:
under the condition that the regular threshold is not zero, obtaining a fragmentation index corresponding to the memory under the condition that the size of the continuous memory in the memory is a second preset value, wherein the fragmentation index is used for describing the fragmentation degree of the memory;
and under the condition that the fragmentation index is larger than or equal to a preset fragmentation threshold, fragmenting and regulating the memory according to the continuous memory size of a third preset value.
5. The method of any one of claims 1-4, wherein the method further comprises:
acquiring a first time interval between the current time and the last time of fragmentation regulation under the condition that the scene triggered by the triggering operation belongs to the memory regulation scene;
and acquiring the load of the CPU under the condition that the first time interval is greater than or equal to a first interval threshold value.
6. The method of claim 5, wherein the electronic device comprises a time monitoring module and a decision module;
and under the condition that the scene triggered by the triggering operation belongs to the memory regularization scene, acquiring a first time interval between the current time and the last time of fragmentation regularization, wherein the first time interval comprises the following steps:
when the scene triggered by the triggering operation belongs to the memory regular 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 a time interval between the current time and the last time of fragmentation regulation 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.
7. The method of claim 6, wherein the electronic device further comprises a CPU monitoring module;
the obtaining the load of the CPU when the first time interval is greater than or equal to a first interval threshold value includes:
The decision module sends a load acquisition message to the CPU monitoring module when the first time interval is greater than or equal to the first interval threshold;
the CPU monitoring module sends a load detection message to the decision module, wherein the load detection message carries the load of the CPU;
and the decision module acquires the load of the CPU from the load detection message.
8. The method of any of claims 6-7, wherein the obtaining the load of the CPU if the first time interval is greater than or equal to a first interval threshold comprises:
under the condition that the first time interval is larger than or equal to a first interval threshold value, carrying out load detection on the CPU at intervals of a second time interval within a first appointed duration to obtain a plurality of load detection results;
and determining the plurality of load detection results as the load of the CPU, or determining the minimum load detection result in the plurality of load detection results as the load of the CPU.
9. The method of claim 8, wherein, in the case where the scene triggered by the triggering operation belongs to the memory-ordering scene, if the current load value of the central processing unit CPU of the electronic device is less than or equal to a load threshold, performing fragmentation-ordering on the memory comprises:
And under the condition that the scene triggered by the triggering operation belongs to the memory regulation scene, under the condition that the load of the CPU comprises the plurality of load detection results, if at least one load detection result in the plurality of load detection results is smaller than or equal to the load threshold value, fragmentation regulation is carried out on the memory.
10. The method according to any one of claims 1-9, wherein, in the case where the scene triggered by the triggering operation belongs to the memory-ordering 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, after performing fragmentation-ordering on the memory, further comprising:
and under the condition that the starting operation of any one application program in the electronic equipment is received, if the electronic equipment is subjected to the fragmentation regulation at a first time point, the fragmentation regulation of the memory is stopped, the time difference between the first time point and the second time point is long when the first time point is before a second time point, and the second time point is the time point for receiving the starting operation.
11. An electronic device, the electronic device comprising: a processor and a memory for storing one or more programs, the one or more programs comprising instructions, which when executed by the processor, the electronic device is for performing the memory management method of any of claims 1-10.
12. A computer readable storage medium storing one or more programs, wherein the one or more programs are configured to be executed by one or more processors, the one or more programs comprising instructions that cause an electronic device to perform the memory ordering method of any of claims 1-10.
CN202211725886.7A 2022-12-29 2022-12-29 Memory normalization method, electronic device and readable storage medium Pending CN116661988A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211725886.7A CN116661988A (en) 2022-12-29 2022-12-29 Memory normalization method, electronic device and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211725886.7A CN116661988A (en) 2022-12-29 2022-12-29 Memory normalization method, electronic device and readable storage medium

Publications (1)

Publication Number Publication Date
CN116661988A true CN116661988A (en) 2023-08-29

Family

ID=87708562

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211725886.7A Pending CN116661988A (en) 2022-12-29 2022-12-29 Memory normalization method, electronic device and readable storage medium

Country Status (1)

Country Link
CN (1) CN116661988A (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108228342A (en) * 2017-08-10 2018-06-29 珠海市魅族科技有限公司 Terminal equipment control method and device, terminal device and computer readable storage medium
CN110377527A (en) * 2018-04-13 2019-10-25 华为技术有限公司 A kind of method and relevant device of memory management
CN110968523A (en) * 2019-12-03 2020-04-07 深圳传音控股股份有限公司 Memory defragmentation method and device
CN112717370A (en) * 2019-03-18 2021-04-30 荣耀终端有限公司 Control method and electronic equipment
CN115269108A (en) * 2021-04-30 2022-11-01 华为云计算技术有限公司 Data processing method, device and equipment
CN115292052A (en) * 2022-09-27 2022-11-04 荣耀终端有限公司 Memory recovery method, electronic device and computer-readable storage medium
CN115421909A (en) * 2022-08-19 2022-12-02 Oppo广东移动通信有限公司 Memory management method and device, electronic equipment and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108228342A (en) * 2017-08-10 2018-06-29 珠海市魅族科技有限公司 Terminal equipment control method and device, terminal device and computer readable storage medium
CN110377527A (en) * 2018-04-13 2019-10-25 华为技术有限公司 A kind of method and relevant device of memory management
CN112717370A (en) * 2019-03-18 2021-04-30 荣耀终端有限公司 Control method and electronic equipment
CN110968523A (en) * 2019-12-03 2020-04-07 深圳传音控股股份有限公司 Memory defragmentation method and device
CN115269108A (en) * 2021-04-30 2022-11-01 华为云计算技术有限公司 Data processing method, device and equipment
CN115421909A (en) * 2022-08-19 2022-12-02 Oppo广东移动通信有限公司 Memory management method and device, electronic equipment and storage medium
CN115292052A (en) * 2022-09-27 2022-11-04 荣耀终端有限公司 Memory recovery method, electronic device and computer-readable storage medium

Similar Documents

Publication Publication Date Title
EP3936992A1 (en) Control method and electronic device
RU2615320C2 (en) Method, apparatus and terminal device for image processing
CN111158910B (en) Memory management method and device, storage medium and electronic equipment
US11328044B2 (en) Dynamic recognition method and terminal device
EP3964932A1 (en) Learning-based keyword search method, and electronic device
WO2023284415A1 (en) Power key mistouch detection method and electronic device
CN111543042A (en) Notification message processing method and electronic equipment
WO2019024641A1 (en) Data synchronization method and apparatus, storage medium and electronic device
CN113805797B (en) Processing method of network resource, electronic equipment and computer readable storage medium
EP4209906A1 (en) Memory management method, electronic device, and computer-readable storage medium
CN115292052B (en) Memory recycling method, electronic device and computer readable storage medium
CN115687035A (en) Memory leak detection method and electronic equipment
US11995317B2 (en) Method and apparatus for adjusting memory configuration parameter
US20200090310A1 (en) Method for picture processing, computer-readable storage medium, and electronic device
WO2022068477A1 (en) Event processing method, and device
CN111381996B (en) Memory exception handling method and device
CN116700816A (en) Resource management method and electronic equipment
CN116661988A (en) Memory normalization method, electronic device and readable storage medium
CN114461589B (en) Method for reading compressed file, file system and electronic equipment
CN113050864B (en) Screen capturing method and related equipment
WO2021151341A1 (en) Distorted-fingerprint-based touch-control method and electronic device
CN116052609B (en) Voltage control method, electronic device and readable storage medium
CN114168065B (en) Method and device for adjusting memory configuration parameters
CN116303110B (en) Memory garbage recycling method and electronic equipment
CN115016921B (en) Resource scheduling method, device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination