CN116955215A - Garbage recycling method and device and electronic equipment - Google Patents

Garbage recycling method and device and electronic equipment Download PDF

Info

Publication number
CN116955215A
CN116955215A CN202310944146.0A CN202310944146A CN116955215A CN 116955215 A CN116955215 A CN 116955215A CN 202310944146 A CN202310944146 A CN 202310944146A CN 116955215 A CN116955215 A CN 116955215A
Authority
CN
China
Prior art keywords
time
garbage collection
collection instruction
ith
instruction
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
CN202310944146.0A
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.)
Vivo Mobile Communication Co Ltd
Original Assignee
Vivo Mobile Communication 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 Vivo Mobile Communication Co Ltd filed Critical Vivo Mobile Communication Co Ltd
Priority to CN202310944146.0A priority Critical patent/CN116955215A/en
Publication of CN116955215A publication Critical patent/CN116955215A/en
Pending legal-status Critical Current

Links

Classifications

    • 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
    • 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/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • 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/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • 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/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources
    • 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/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45583Memory management, e.g. access or allocation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System (AREA)

Abstract

The application discloses a garbage recycling method and device and electronic equipment, and belongs to the technical field of computers. The method comprises the following steps: receiving an ith garbage collection instruction sent by a target process, wherein i is a positive integer; acquiring the first time of receiving the ith garbage collection instruction and the second time of executing the ith-1 th garbage collection instruction of completing the target process; and under the condition that the difference value between the first time and the second time is smaller than the first time length, executing a target garbage collection instruction at a third time, wherein the target garbage collection instruction is the garbage collection instruction received between the first time and the third time, and the difference value between the third time and the second time is larger than or equal to the first time length.

Description

Garbage recycling method and device and electronic equipment
Technical Field
The application belongs to the technical field of computers, and particularly relates to a garbage recycling method and device and electronic equipment.
Background
A native garbage collection (Garbage Collection, GC) of an operating environment (Android RunTime, ART) virtual machine on an Android operating system is thresholded according to the amount of increase in the java heap size in the virtual machine.
For example: the current process heap occupies 20M memory, and when the heap grows to around 40M, a GC is triggered. Assuming that 10M garbage is reclaimed after GC is completed, i.e., 30M memory is left, the next GC threshold may be around 50M, and when heap memory grows to 50M, a GC is triggered again.
However, if heap memory grows rapidly in a short period of time, GC is continuously triggered. For example: the current process is rapidly increased from 20M to 70M in the size of the heap within 3 seconds, and about 10M of garbage can be recovered each time of garbage collection, so that GC can be triggered at 40M, 50M, 60M and 70M nodes respectively. Such frequent GC wastes a lot of central processor (Central Processing Unit, CPU) resources and is prone to cause stuck.
Disclosure of Invention
The embodiment of the application aims to provide a garbage recycling method, a garbage recycling device and electronic equipment, which can solve the problems that the existing GC wastes a large amount of CPU resources and is easy to cause clamping.
In order to solve the technical problems, the application is realized as follows:
in a first aspect, an embodiment of the present application provides a method for recycling garbage, including:
receiving an ith garbage collection instruction sent by a target process, wherein i is a positive integer;
Acquiring the first time of receiving the ith garbage collection instruction and the second time of executing the ith-1 th garbage collection instruction of completing the target process;
and under the condition that the difference value between the first time and the second time is smaller than the first time length, executing a target garbage collection instruction at a third time, wherein the target garbage collection instruction is the garbage collection instruction received between the first time and the third time, and the difference value between the third time and the second time is larger than or equal to the first time length.
In a second aspect, an embodiment of the present application provides a garbage collection and treatment device, including:
the receiving module is used for receiving an ith garbage collection instruction sent by the target process, wherein i is a positive integer;
the acquisition module is used for acquiring the first time when the ith garbage collection instruction is received and the second time when the ith-1 th garbage collection instruction of the target process is completed;
and the execution module is used for executing a target garbage collection instruction at a third time under the condition that the difference between the first time and the second time is smaller than the first time, wherein the target garbage collection instruction is the garbage collection instruction received between the first time and the third time, and the difference between the third time and the second time is larger than or equal to the first time.
In a third aspect, an embodiment of the present application provides an electronic device comprising a processor and a memory storing a program or instructions executable on the processor, which when executed by the processor, implement the steps of the method as described in the first aspect.
In a fourth aspect, embodiments of the present application provide a readable storage medium having stored thereon a program or instructions which when executed by a processor perform the steps of the method according to the first aspect.
In a fifth aspect, an embodiment of the present application provides a chip, where the chip includes a processor and a communication interface, where the communication interface is coupled to the processor, and where the processor is configured to execute a program or instructions to implement a method according to the first aspect.
In a sixth aspect, embodiments of the present application provide a computer program product stored in a storage medium, the program product being executable by at least one processor to implement the method according to the first aspect.
In the embodiment of the application, the ith garbage collection instruction sent by the target process is received, the first time for receiving the ith garbage collection instruction and the second time for executing the ith-1 th garbage collection instruction for completing the target process are obtained, if the time difference between the first time and the second time is smaller than the first time, the interval time between the ith-1 th garbage collection instruction and the ith garbage collection instruction is shorter, the third time after the first time is determined, and the target garbage collection instruction received between the first time and the third time is delayed to be executed at the third time, so that the number of times of garbage collection in a period of time is reduced, the garbage collection frequency is reduced, and the purposes of saving CPU (central processing unit) calculation power and reducing blocking are achieved.
Drawings
FIG. 1 is a schematic flow chart of a garbage recycling method according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a garbage collection process provided by an embodiment of the present application;
fig. 3 is a schematic structural diagram of a garbage recycling device according to an embodiment of the present application;
fig. 4 is a block diagram of an electronic device according to an embodiment of the present application;
fig. 5 is a block diagram of another electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions of the embodiments of the present application will be clearly described below with reference to the drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which are obtained by a person skilled in the art based on the embodiments of the present application, fall within the scope of protection of the present application.
The terms first, second and the like in the description and in the claims, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged, as appropriate, such that embodiments of the present application may be implemented in sequences other than those illustrated or described herein, and that the objects identified by "first," "second," etc. are generally of a type, and are not limited to the number of objects, such as the first object may be one or more. Furthermore, in the description and claims, "and/or" means at least one of the connected objects, and the character "/", generally means that the associated object is an "or" relationship.
The garbage recycling method provided by the embodiment of the application is described in detail below through specific embodiments and application scenes thereof with reference to the accompanying drawings.
As shown in fig. 1, the embodiment of the application provides a garbage recycling method, which specifically includes the following steps:
step 101, receiving an ith garbage collection instruction sent by a target process, wherein i is a positive integer.
Specifically, the device is provided with a plurality of processes, and for a target process in the plurality of processes, an ith garbage collection instruction sent by the target process is received, wherein the ith garbage collection instruction refers to an instruction for carrying out ith garbage collection on the target process.
Step 102, obtaining a first time when the ith garbage collection instruction is received and a second time when the ith-1 th garbage collection instruction of the target process is executed.
Specifically, under the condition that the ith garbage collection instruction sent by the target process is received, acquiring the time (namely, the first time) when the ith garbage collection instruction is received, and acquiring the time (namely, the second time) when the last garbage collection instruction of the target process is executed, wherein the last garbage collection instruction is the ith-1 th garbage collection instruction.
If i is 1, the second time is 0. If i is an integer greater than 1, the second time is the time when the execution of the i-1 th garbage collection instruction is completed.
Step 103, executing a target garbage collection instruction at a third time when the time difference between the first time and the second time is smaller than the first time, wherein the target garbage collection instruction is a garbage collection instruction received between the first time and the third time, and the difference between the third time and the second time is larger than or equal to the first time.
Specifically, after the first time and the second time are acquired, a time difference between the first time and the second time, that is, a difference obtained by subtracting the second time from the first time is calculated, and since the first time is a time after the second time, the difference obtained by subtracting the second time from the first time is a positive integer.
After the difference value between the first time and the second time is obtained, the magnitude relation between the difference value and the first duration is judged. And if the difference value is greater than or equal to the first duration, immediately executing the ith garbage collection instruction. If the time length difference is smaller than the first time length, the interval time between the ith-1 th garbage collection instruction and the ith garbage collection instruction is short, the third time after the first time is determined, and the target garbage collection instruction received between the first time and the third time is delayed to be executed in the third time, so that the number of garbage collection times in a period of time is reduced, the garbage collection frequency is reduced, and the purposes of saving CPU calculation power and reducing blocking are achieved.
The first time length is a limit value for measuring whether the time interval between the first time and the second time is shorter, and if the difference between the first time and the second time is smaller than the first time length, the time interval between the first time and the second time is shorter, so that the garbage recovery frequency needs to be reduced; if the difference between the first time and the second time is greater than or equal to the first duration, the time interval between the first time and the second time is longer, and the time interval between the garbage collection instructions of two adjacent times is longer, so that the garbage collection instruction (i-th garbage collection instruction) of the first time can be immediately executed.
The term "between the first time and the third time" includes not only the time after the first time and before the third time, but also the first time and the third time. In other words, the target garbage collection instruction may be a garbage collection instruction received at the first time, a garbage collection instruction received at the third time, or a garbage collection log received after the first time and before the third time.
In the above embodiment of the present application, the ith garbage collection instruction sent by the target process is received, the first time when the ith garbage collection instruction is received and the second time when the ith-1 th garbage collection instruction of the target process is executed are obtained, if the time difference between the first time and the second time is smaller than the first time, the interval time between the ith-1 th garbage collection instruction and the ith garbage collection instruction is shorter, the third time after the first time is determined, and the target garbage collection instruction received between the first time and the third time is delayed to be executed until the third time, thereby reducing the number of garbage collection times in a period of time, reducing the garbage collection frequency, and achieving the purposes of saving the CPU calculation power and reducing the blocking.
In the case that the target garbage collection instruction is the ith garbage collection instruction, the step 103 may specifically include two embodiments of executing the target garbage collection instruction at a third time if the difference between the first time and the second time is less than a first duration:
embodiment one:
acquiring memory information of the equipment under the condition that the difference value between the first time and the second time is smaller than a first duration;
and executing the ith garbage collection instruction at the third time under the condition that the memory information of the equipment meets the first condition.
Specifically, after the first time and the second time are obtained, calculating a difference value between the first time and the second time, and judging the relation between the difference value and the first duration. If the time difference is smaller than the first time length, the memory information of the equipment is obtained, whether the memory information of the equipment meets the first condition is judged, and if the memory information of the equipment meets the first condition, the execution time of the ith garbage collection instruction is delayed to a third time, namely the ith garbage collection instruction is executed at the third time. If the first condition is not met, the ith garbage collection instruction is immediately executed, so that the condition that the memory is not used enough can not occur while the GC frequency is reduced.
Wherein, the first condition may include the following three items:
a first item: the heap memory of the target process is less than a first proportion of a memory threshold of the target process.
In the first item, after the memory information of the device is obtained, judging whether the heap memory of the target process is smaller than a first proportion of the memory threshold of the target process, namely judging whether the proportion of the heap memory of the target process to the memory threshold of the target process is smaller than the first proportion, if the proportion of the heap memory of the target process to the memory threshold of the target process is larger than or equal to the first proportion (for example, 75%), immediately executing the ith garbage collection instruction, and not delaying the execution time of the subsequent garbage collection instruction.
For example: the first proportion is 75%, the heap memory of the target process is 400M, the memory threshold of the target process is 500M, and the heap memory is greater than 75% of the memory threshold, so that the first proportion of the heap memory is greater than the memory threshold of the target process, the ith garbage collection instruction is immediately executed, and the execution time of the subsequent garbage collection instruction is not delayed.
The second item: the target process increases memory less than a second proportion of the memory threshold for the first duration.
In the second term, after the memory information of the device is obtained, judging whether the memory added by the target process in the first time period is smaller than a second proportion of the memory threshold value, namely judging whether the proportion of the memory added by the target process in the first time period to the memory threshold value is smaller than the second proportion, if the memory added by the target process in the first time period is larger than or equal to the second proportion (for example, 20%) of the memory threshold value, indicating that the memory is faster to increase, immediately executing the ith garbage collection instruction, and not delaying the execution time of the subsequent garbage collection instruction.
For example: the first time length is 3 seconds, the memory of the target process growing in 3 seconds is 200M, the memory threshold is 500M, the memory of the target process growing in 3 seconds is greater than 20% of the memory threshold, the memory growing is faster, the ith garbage collection instruction needs to be executed immediately, and the execution time of the subsequent garbage collection instruction is not delayed.
Third item: the device uses memory less than a third proportion of the device memory threshold.
In the third item, after the memory information of the device is obtained, judging whether the used memory of the whole machine of the device is smaller than a third proportion of the memory threshold of the device (namely, the whole machine memory threshold of the device), namely, whether the proportion of the used memory of the device to the memory threshold of the device is smaller than the third proportion, if the used memory of the device is larger than or equal to the third proportion (such as 90%) of the memory threshold of the device, the whole machine memory of the device is insufficient, immediately executing the ith garbage collection instruction, and not delaying the execution time of the subsequent garbage collection instruction until the condition of insufficient memory of the whole machine is relieved.
For example: the threshold value of the equipment memory is 8000M, the using memory of the equipment is 7800M, and the using memory of the equipment is larger than 90% of the threshold value of the equipment memory, the ith garbage collection instruction is immediately executed, and the execution time of the subsequent garbage collection instruction is not delayed.
The first ratio, the second ratio, and the third ratio may be set as needed, and are not particularly limited.
The second embodiment may further include the following two cases:
case one:
monitoring the running state of the central processing unit between a fourth time and a fifth time when the difference between the first time and the second time is smaller than the first time, wherein the difference between the fourth time and the second time is equal to the first time, and the difference between the fifth time and the second time is larger than the first time;
and if the running state of the central processing unit at the third time is an idle state, executing the ith garbage collection instruction at the third time, wherein the third time is the time between the fourth time and the fifth time.
For the first case, if the difference between the first time and the second time is smaller than the first duration, the running state of the central processing unit between the fourth time and the fifth time is monitored, and if the running state of the central processing unit between the fourth time and the fifth time is monitored to be in an idle state, the ith garbage collection instruction is executed at the third time.
It can be understood that the execution time of the ith garbage collection instruction can be at least delayed to a fourth time, and the fourth time and the fifth time are used as waiting time periods, if the central processor is in an idle state in the waiting time periods, the ith garbage collection instruction is executed in the idle state of the central processor, so that the operation efficiency of the central processor is ensured, and the problem of the clamping caused by load increase in the process of executing the ith garbage collection instruction in a non-idle state of the central processor is avoided.
The third time may be the fourth time, the third time may be the fifth time, and the third time may be a time after the fourth time and before the fifth time.
And a second case:
monitoring the running state of the central processing unit between a fourth time and a fifth time when the difference between the first time and the second time is smaller than the first time, wherein the difference between the fourth time and the second time is equal to the first time, and the difference between the fifth time and the second time is larger than the first time;
and if the running states of the central processing unit between the fourth time and the fifth time are all non-idle states, executing the ith garbage collection instruction at the third time, wherein the third time is the fifth time.
For the second case, if the difference between the first time and the second time is smaller than the first duration, the running state of the central processing unit between the fourth time and the fifth time is monitored, and if the running states of the central processing unit between the fourth time and the fifth time are both non-idle states, the ith garbage collection instruction is executed at the fifth time (namely, the third time).
It is understood that the execution time of the ith garbage collection instruction may be delayed at least until the fourth time, and the fourth time and the fifth time are used as waiting time periods, and if the cpu is always in a non-idle state during the waiting time periods, the ith garbage collection instruction is executed at the latest fifth time (i.e. the third time).
The following is an illustration of case one and case two:
for example: the second time is 1 st second, the first time is 3 rd second, the first time is 5 seconds, the fourth time is 6 th second when the difference between the fourth time and the second time is equal to the first time, the difference between the fifth time and the second time is larger than the first time, and the fifth time is 6.5 seconds.
Since the difference between the first time and the second time is 2 seconds, and the 2 seconds is less than 5 seconds of the first duration, the running state of the central processing unit between the 6 th and the 6.5 th seconds is monitored, and if the running state of the central processing unit between the 6 th and the 6.5 th seconds (such as 6.25 seconds) is monitored to be in an idle state, the ith garbage collection instruction is executed in the 6.25 th second. And if the running states of the central processing unit are not idle states between the 6 th second and the 6.5 th second, executing the ith garbage collection instruction in the 6.5 th second.
In another specific embodiment, the operation state of the central processing unit is monitored after the third time is determined and before the third time is reached, that is, during the process of delaying the ith garbage collection instruction, if the central processing unit has a time when the following preset condition is satisfied before the third time is reached, the ith garbage collection instruction may be immediately executed at the time when the preset condition is satisfied, and the garbage collection frequency may be reduced without increasing the load of the central processing unit.
Wherein the preset conditions include at least one of the following without limitation:
the electric quantity of the equipment is larger than the preset electric quantity;
the device is in a charged state and the charging time exceeds a preset charging duration.
It can be understood that, in the case that the central processor meets the preset condition, it indicates that the current central processor is idle and has sufficient electric quantity, and the load of the central processor is smaller. Since the resources required for garbage collection are mainly central processing units, a problem that may occur in occupying the central processing units is to increase power consumption and preempt other threads that need to use the central processing units. That is, the best timing for executing garbage collection instructions is: the current central processing unit is idle and has sufficient power.
As an optional specific embodiment, in a case where the first time and the second time are acquired, and a difference between the first time and the second time is smaller than the first duration, and the third time for executing the target garbage collection instruction is determined, the method may further include:
and determining the jth garbage collection instruction as an invalid instruction when the jth garbage collection instruction is received after the first time, at the third time and before the third time, wherein j is an integer larger than i.
Specifically, under the condition that the first time and the second time are acquired, the difference value between the first time and the second time is smaller than the first duration, and the third time for executing the target garbage collection instruction is determined, whether other garbage collection instructions are received in the time periods after the first time, the third time and before the third time is monitored. If the jth garbage collection instruction is received in the time period after the first time, the third time and before the third time, the jth garbage collection instruction is received before the target garbage collection instruction is executed, and the jth garbage collection instruction needs to be determined to be an invalid instruction, which is equivalent to merging multiple garbage collection instructions continuously triggered in a period of time, so that the garbage collection frequency can be further reduced while the effect of final garbage collection is ensured, and the aims of saving CPU calculation power and reducing blocking are fulfilled.
Further, the determining the jth garbage collection instruction as the invalid instruction may specifically include:
determining the jth garbage collection instruction as an invalid instruction in the case that the ith garbage collection instruction and the jth garbage collection instruction meet a second condition;
wherein the second condition includes any one of:
the jth garbage collection instruction and the ith garbage collection instruction are part of garbage collection instructions;
the jth garbage collection instruction and the ith garbage collection instruction are all garbage collection instructions;
the ith garbage collection instruction is a full garbage collection instruction, and the jth garbage collection instruction is a partial garbage collection instruction.
In an ART virtual machine of the device, the ART virtual machine is divided into a partial garbage collection stick GC instruction (i.e., an instruction for garbage collection of a partial memory of a target process) and an entire garbage collection Full GC instruction (i.e., an instruction for garbage collection of an entire memory of the target process). Wherein, the partial memory characterizes a new memory which is newly allocated after the execution of the last garbage collection instruction is completed; all the memory characterizes the sum of the memory left after the last garbage collection instruction is executed and the allocated new memory, namely all the memory comprises partial memory and the memory left after the last garbage collection instruction is executed.
If the jth garbage collection instruction is received in the time period after the first time, the third time and before the third time, the jth garbage collection instruction is received before the target garbage collection instruction is executed, whether the ith garbage collection instruction and the jth garbage collection instruction meet the second condition is judged, and if yes, the jth garbage collection instruction is determined to be an invalid instruction.
In other words, if the ith garbage collection instruction is an all garbage collection instruction, the jth garbage collection instruction is received after the ith garbage collection instruction, and the jth garbage collection instruction is also an all garbage collection instruction, the jth garbage collection instruction is taken as an invalid instruction in order to reduce the garbage collection frequency. Similarly, if the ith garbage collection instruction is a partial garbage collection instruction, the jth garbage collection instruction is received after the ith garbage collection instruction, and the jth garbage collection instruction is also a partial garbage collection instruction, in order to reduce the garbage collection frequency, the jth garbage collection instruction is used as an invalid instruction. And if the ith garbage collection instruction is a full garbage collection instruction, receiving the jth garbage collection instruction after the ith garbage collection instruction, wherein the jth garbage collection instruction is a partial garbage collection instruction, and the jth garbage collection instruction is taken as an invalid instruction in order to reduce the garbage collection frequency because the full garbage collection instruction comprises an instruction for garbage collection of partial memory (namely, a partial garbage collection instruction).
The above scheme is described below by way of a specific example:
for example: as shown in fig. 2, the first duration is 3 seconds, and all of the 1 st to 5 th GC instructions are garbage collection instructions. The 1 st GC instruction is received at 0 seconds and execution is complete at 1 second. If the GC is run four more times within 3 seconds after the 1 st second, the 2 nd GC instruction is executed at the 4 th second, and the 3 rd, 4 th and 5 th GC instructions are regarded as invalid instructions, which corresponds to running the GC instruction only once within 3 seconds.
Since the ART virtual machine of the device adopts a GC mode for identifying the available memory, the running time of each GC is substantially the same under the condition that the amount of the available memory is the same. For example:
1 st time: the total memory 40M comprises available memory 30M and garbage 10M;
2 nd time: the total memory 50M comprises available memory 40M and garbage 10M;
3 rd time: the total memory 60M comprises available memory 50M and garbage 10M;
4 th time: the total memory 70M comprises available memory 60M and garbage 10M;
the 5 th time: total memory 100M, including available memory 60M, garbage 40M.
The GC operating speeds in these five cases were substantially the same, and the GC method of the prior art performed four times for steps 2 through 5, eventually recovering 70M memory. Assuming that the above four steps occur within 3 seconds, the GC method of the present application can delay the GC execution time of the 2 nd GC by 3 seconds, and can execute the GC until 100M, and the GC is performed only once within 3 seconds, and finally 70M memory is recovered, which is equivalent to 75% GC reduction, and can reduce GC frequency while ensuring the effect of the final GC.
In an optional specific embodiment, in a case where the target garbage collection instruction is the kth garbage collection instruction, the step 103 may specifically include:
when the ith garbage collection instruction is a part of garbage collection instructions and the kth garbage collection instruction is a whole garbage collection instruction, canceling execution of the ith garbage collection instruction and executing the kth garbage collection instruction at a third time;
the kth garbage collection instruction is a garbage collection instruction received after the first time, before the third time and the third time, and k is an integer greater than i.
Specifically, if the ith garbage collection instruction is a partial garbage collection instruction and the kth garbage collection instruction is received after the first time, before the third time or before the third time, judging whether the kth garbage collection instruction is a partial garbage collection instruction or a full garbage collection instruction. If the kth garbage collection instruction is a full garbage collection instruction, and the full garbage collection instruction comprises a garbage collection instruction (namely a partial garbage collection instruction) for partial memory, canceling to execute the ith garbage collection instruction and executing the kth garbage collection instruction at a third time.
Further, if the first duration corresponding to all the garbage collection instructions is different from the first duration corresponding to part of the garbage collection instructions, the third time corresponding to all the garbage collection instructions is also different from the third time corresponding to part of the garbage collection instructions.
In the garbage recycling process, the method can be roughly divided into the stages of initialization, marking, copying and cleaning. The two stages of marking and copying are time-consuming, and generally occupy more than 80% of the time, and the two stages occupy approximately half of the time respectively, namely about 40% of the time. The part of garbage collection is only aimed at the memory newly allocated after the last garbage collection, so that the marking time is very short, the quantity of the memory to be copied is also small, and the execution time of the part of garbage collection is not equal to half of the whole garbage collection. Therefore, the first time length corresponding to all garbage collection instructions can be set to be longer than the first time length corresponding to part of garbage collection instructions.
For example: the first duration corresponding to all garbage collection instructions is 3 seconds, and the first duration corresponding to part of garbage collection instructions is 1 second. The last garbage collection is completed at 9:00:00, and if the garbage collection instruction is a partial garbage collection instruction, the third time corresponding to the garbage collection instruction is equal to or later than 9:00:01. If the garbage collection instruction is the whole garbage collection instruction, the third time corresponding to the garbage collection instruction is equal to or later than 9:00:03.
And if the ith garbage collection instruction is a partial garbage collection instruction, receiving the kth garbage collection instruction after the first time, at the third time corresponding to the partial garbage collection instruction or before the third time, and judging whether the kth garbage collection instruction is the partial garbage collection instruction or the full garbage collection instruction. If the kth garbage collection instruction is the whole garbage collection instruction, and the garbage collection instruction (namely, part of the garbage collection instruction) of the part of the memory is included in the whole garbage collection instruction, the execution of the ith garbage collection instruction is canceled, and the kth garbage collection instruction is executed at a third time corresponding to the whole garbage collection instruction or a third time corresponding to the part of the garbage collection instruction.
The above scheme is described below by way of a specific example:
if the ith garbage collection instruction is a part of garbage collection instruction, the first time length corresponding to the part of garbage collection instruction is 3 seconds, the first time length corresponding to all the garbage collection instructions is 5 seconds, and the difference value between the third time and the second time is equal to the first time length. If the ith garbage collection instruction is being delayed to be executed, in the delayed process, if the kth garbage collection instruction is received before the third time and the kth garbage collection instruction is all the garbage collection instructions, directly canceling the ith garbage collection instruction, executing only the kth garbage collection instruction, and starting to count according to the second time, executing the kth garbage collection instruction at a time 5 seconds after the second time (namely, a third time corresponding to all the garbage collection instructions), or executing the kth garbage collection instruction at a time 3 seconds after the second time (namely, a third time corresponding to part of the garbage collection instructions).
Wherein, the i-th garbage collection instruction is being executed in a delayed manner, namely, the current time is between the first time and the third time, but does not contain the first time and the third time in the process that the i-th garbage collection instruction is delayed from the first time to the third time.
In summary, in the above embodiment of the present application, the ith garbage collection instruction sent by the target process is received, the first time when the ith garbage collection instruction is received and the second time when the ith-1 th garbage collection instruction of the target process is executed are obtained, if the time difference between the first time and the second time is smaller than the first time, the interval time between the ith-1 th garbage collection instruction and the ith garbage collection instruction is shorter, the third time after the first time is determined, and the target garbage collection instruction received between the first time and the third time is delayed to be executed at the third time, thereby reducing the number of garbage collection times in a period of time, reducing the garbage collection frequency, and achieving the purposes of saving the CPU calculation power and reducing the card.
According to the garbage recycling method provided by the embodiment of the application, the execution main body can be a garbage recycling device. In the embodiment of the application, the garbage recycling method performed by the garbage recycling device is taken as an example, and the garbage recycling device provided by the embodiment of the application is described.
As shown in fig. 3, an embodiment of the present application further provides a garbage recycling device 300, including:
the receiving module 301 is configured to receive an ith garbage collection instruction sent by a target process, where i is a positive integer;
an obtaining module 302, configured to obtain a first time when the ith garbage collection instruction is received, and a second time when the ith-1 th garbage collection instruction of the target process is executed;
and an execution module 303, configured to execute a target garbage collection instruction at a third time when the difference between the first time and the second time is smaller than the first duration, where the target garbage collection instruction is a garbage collection instruction received between the first time and the third time, and the difference between the third time and the second time is greater than or equal to the first duration.
In the above embodiment of the present application, the ith garbage collection instruction sent by the target process is received, the first time when the ith garbage collection instruction is received and the second time when the ith-1 th garbage collection instruction of the target process is executed are obtained, if the time difference between the first time and the second time is smaller than the first time, the interval time between the ith-1 th garbage collection instruction and the ith garbage collection instruction is shorter, the third time after the first time is determined, and the target garbage collection instruction received between the first time and the third time is delayed to be executed until the third time, thereby reducing the number of garbage collection times in a period of time, reducing the garbage collection frequency, and achieving the purposes of saving the CPU calculation power and reducing the blocking.
Optionally, the target garbage collection instruction is the ith garbage collection instruction;
the execution module 303 is specifically configured to:
acquiring memory information of the equipment under the condition that the difference value between the first time and the second time is smaller than a first duration;
executing the ith garbage collection instruction at the third time under the condition that the memory information of the equipment meets a first condition;
wherein the first condition includes:
the heap memory of the target process is smaller than a first proportion of a memory threshold of the target process;
the memory increased by the target process in the first duration is smaller than a second proportion of the memory threshold value;
the device uses memory less than a third proportion of the device memory threshold.
Optionally, the target garbage collection instruction is the ith garbage collection instruction;
the execution module 303 is specifically configured to:
monitoring the running state of the central processing unit between a fourth time and a fifth time when the difference between the first time and the second time is smaller than the first time, wherein the difference between the fourth time and the second time is equal to the first time, and the difference between the fifth time and the second time is larger than the first time;
If the running state of the central processing unit at the third time is an idle state, executing the ith garbage collection instruction at the third time, wherein the third time is the time between the fourth time and the fifth time;
and if the running states of the central processing unit between the fourth time and the fifth time are all non-idle states, executing the ith garbage collection instruction at the third time, wherein the third time is the fifth time.
Optionally, the target garbage collection instruction is a kth garbage collection instruction;
the execution module 303 is specifically configured to:
when the difference between the first time and the second time is smaller than a first duration, the ith garbage collection instruction is a part of garbage collection instructions, and the kth garbage collection instruction is a whole garbage collection instruction, the execution of the ith garbage collection instruction is canceled, and the kth garbage collection instruction is executed at a third time;
the kth garbage collection instruction is a garbage collection instruction received after the first time, before the third time and before the third time, k is an integer greater than i, and the difference between the third time and the second time is greater than or equal to the first time.
Optionally, the apparatus further includes:
and the determining module is used for determining the jth garbage collection instruction as an invalid instruction when the jth garbage collection instruction for the target process is received after the first time, before the third time and before the third time, wherein j is an integer larger than i.
Optionally, the determining module is specifically configured to:
determining the jth garbage collection instruction as an invalid instruction in the case that the ith garbage collection instruction and the jth garbage collection instruction meet a second condition;
wherein the second condition includes any one of:
the jth garbage collection instruction and the ith garbage collection instruction are part of garbage collection instructions;
the jth garbage collection instruction and the ith garbage collection instruction are all garbage collection instructions;
the ith garbage collection instruction is a full garbage collection instruction, and the jth garbage collection instruction is a partial garbage collection instruction.
In summary, in the above embodiment of the present application, the ith garbage collection instruction sent by the target process is received, the first time when the ith garbage collection instruction is received and the second time when the ith-1 th garbage collection instruction of the target process is executed are obtained, if the time difference between the first time and the second time is smaller than the first time, the interval time between the ith-1 th garbage collection instruction and the ith garbage collection instruction is shorter, the third time after the first time is determined, and the target garbage collection instruction received between the first time and the third time is delayed to be executed at the third time, thereby reducing the number of garbage collection times in a period of time, reducing the garbage collection frequency, and achieving the purposes of saving the CPU calculation power and reducing the card.
The garbage recycling device in the embodiment of the application can be electronic equipment or a component in the electronic equipment, such as an integrated circuit or a chip. The electronic device may be a terminal, or may be other devices than a terminal. By way of example, the electronic device may be a mobile phone, tablet computer, notebook computer, palm computer, vehicle-mounted electronic device, mobile internet appliance (Mobile Internet Device, MID), augmented reality (augmented reality, AR)/Virtual Reality (VR) device, robot, wearable device, ultra-mobile personal computer, UMPC, netbook or personal digital assistant (personal digital assistant, PDA), etc., but may also be a server, network attached storage (Network Attached Storage, NAS), personal computer (personal computer, PC), television (TV), teller machine or self-service machine, etc., and the embodiments of the present application are not limited in particular.
The garbage collection and treatment device in the embodiment of the application can be a device with an operating system. The operating system may be an Android operating system, an ios operating system, or other possible operating systems, and the embodiment of the present application is not limited specifically.
The garbage recycling device provided by the embodiment of the application can realize each process realized by the method embodiments of fig. 1 to 2, and in order to avoid repetition, the description is omitted here.
Optionally, as shown in fig. 4, the embodiment of the present application further provides an electronic device 400, including a processor 401 and a memory 402, where the memory 402 stores a program or an instruction that can be executed on the processor 401, and the program or the instruction implements each step of the above-mentioned garbage collection processing method embodiment when executed by the processor 401, and the steps achieve the same technical effects, so that repetition is avoided, and no further description is given here.
The electronic device in the embodiment of the application includes the mobile electronic device and the non-mobile electronic device.
Fig. 5 is a schematic hardware structure of an electronic device implementing an embodiment of the present application.
The electronic device 1000 includes, but is not limited to: radio frequency unit 1001, network module 1002, audio output unit 1003, input unit 1004, sensor 1005, display unit 1006, user input unit 1007, interface unit 1008, memory 1009, and processor 1010.
Those skilled in the art will appreciate that the electronic device 1000 may also include a power source (e.g., a battery) for powering the various components, which may be logically connected to the processor 1010 by a power management system to perform functions such as managing charge, discharge, and power consumption by the power management system. The electronic device structure shown in fig. 5 does not constitute a limitation of the electronic device, and the electronic device may include more or less components than shown, or may combine certain components, or may be arranged in different components, which are not described in detail herein.
The processor 1010 is configured to receive an ith garbage collection instruction sent by a target process, where i is a positive integer;
acquiring the first time of receiving the ith garbage collection instruction and the second time of executing the ith-1 th garbage collection instruction of completing the target process;
and under the condition that the difference value between the first time and the second time is smaller than the first time length, executing a target garbage collection instruction at a third time, wherein the target garbage collection instruction is the garbage collection instruction received between the first time and the third time, and the difference value between the third time and the second time is larger than or equal to the first time length.
In the above embodiment of the present application, the ith garbage collection instruction sent by the target process is received, the first time when the ith garbage collection instruction is received and the second time when the ith-1 th garbage collection instruction of the target process is executed are obtained, if the time difference between the first time and the second time is smaller than the first time, the interval time between the ith-1 th garbage collection instruction and the ith garbage collection instruction is shorter, the third time after the first time is determined, and the target garbage collection instruction received between the first time and the third time is delayed to be executed until the third time, thereby reducing the number of garbage collection times in a period of time, reducing the garbage collection frequency, and achieving the purposes of saving the CPU calculation power and reducing the blocking.
Optionally, the target garbage collection instruction is the ith garbage collection instruction;
the processor 1010 is specifically configured to, when executing the target garbage collection instruction at the third time, if the difference between the first time and the second time is less than the first duration:
acquiring memory information of the equipment under the condition that the difference value between the first time and the second time is smaller than a first duration;
executing the ith garbage collection instruction at the third time under the condition that the memory information of the equipment meets a first condition;
wherein the first condition includes:
the heap memory of the target process is smaller than a first proportion of a memory threshold of the target process;
the memory increased by the target process in the first duration is smaller than a second proportion of the memory threshold value;
the device uses memory less than a third proportion of the device memory threshold.
Optionally, the target garbage collection instruction is the ith garbage collection instruction;
the processor 1010 is specifically configured to, when executing the target garbage collection instruction at the third time, if the difference between the first time and the second time is less than the first duration:
Monitoring the running state of the central processing unit between a fourth time and a fifth time when the difference between the first time and the second time is smaller than the first time, wherein the difference between the fourth time and the second time is equal to the first time, and the difference between the fifth time and the second time is larger than the first time;
if the running state of the central processing unit at the third time is an idle state, executing the ith garbage collection instruction at the third time, wherein the third time is the time between the fourth time and the fifth time;
and if the running states of the central processing unit between the fourth time and the fifth time are all non-idle states, executing the ith garbage collection instruction at the third time, wherein the third time is the fifth time.
Optionally, the target garbage collection instruction is a kth garbage collection instruction;
the processor 1010 is specifically configured to, when executing the target garbage collection instruction at the third time:
when the ith garbage collection instruction is a part of garbage collection instructions and the kth garbage collection instruction is a whole garbage collection instruction, canceling execution of the ith garbage collection instruction and executing the kth garbage collection instruction at a third time;
The kth garbage collection instruction is a garbage collection instruction received after the first time, before the third time and the third time, and k is an integer greater than i.
Optionally, the processor 1010 is further configured to:
and determining the jth garbage collection instruction as an invalid instruction when the jth garbage collection instruction is received after the first time, at the third time and before the third time, wherein j is an integer larger than i.
Optionally, when determining the jth garbage collection instruction as an invalid instruction, the processor 1010 is specifically configured to:
determining the jth garbage collection instruction as an invalid instruction in the case that the ith garbage collection instruction and the jth garbage collection instruction meet a second condition;
wherein the second condition includes any one of:
the jth garbage collection instruction and the ith garbage collection instruction are part of garbage collection instructions;
the jth garbage collection instruction and the ith garbage collection instruction are all garbage collection instructions;
the ith garbage collection instruction is a full garbage collection instruction, and the jth garbage collection instruction is a partial garbage collection instruction.
In summary, in the above embodiment of the present application, the ith garbage collection instruction sent by the target process is received, the first time when the ith garbage collection instruction is received and the second time when the ith-1 th garbage collection instruction of the target process is executed are obtained, if the time difference between the first time and the second time is smaller than the first time, the interval time between the ith-1 th garbage collection instruction and the ith garbage collection instruction is shorter, the third time after the first time is determined, and the target garbage collection instruction received between the first time and the third time is delayed to be executed at the third time, thereby reducing the number of garbage collection times in a period of time, reducing the garbage collection frequency, and achieving the purposes of saving the CPU calculation power and reducing the card.
It should be appreciated that in an embodiment of the present application, the input unit 1004 may include a graphics processor (Graphics Processing Unit, GPU) 10041 and a microphone 10042, and the graphics processor 10041 processes image data of still pictures or video obtained by an image capturing device (e.g., a camera) in a video capturing mode or an image capturing mode. The display unit 1006 may include a display panel 10061, and the display panel 10061 may be configured in the form of a liquid crystal display, an organic light emitting diode, or the like. The user input unit 1007 includes at least one of a touch panel 10071 and other input devices 10072. The touch panel 10071 is also referred to as a touch screen. The touch panel 10071 can include two portions, a touch detection device and a touch controller. Other input devices 10072 may include, but are not limited to, a physical keyboard, function keys (e.g., volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, and so forth, which are not described in detail herein.
The memory 1009 may be used to store software programs as well as various data. The memory 1009 may mainly include a first memory area storing programs or instructions and a second memory area storing data, wherein the first memory area may store an operating system, application programs or instructions (such as a sound playing function, an image playing function, etc.) required for at least one function, and the like. Further, the memory 1009 may include volatile memory or nonvolatile memory, or the memory 1009 may include both volatile and nonvolatile memory. The nonvolatile Memory may be a Read-Only Memory (ROM), a Programmable ROM (PROM), an Erasable PROM (EPROM), an Electrically Erasable EPROM (EEPROM), or a flash Memory. The volatile memory may be random access memory (Random Access Memory, RAM), static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (ddr SDRAM), enhanced SDRAM (Enhanced SDRAM), synchronous DRAM (SLDRAM), and Direct RAM (DRRAM). Memory 1009 in embodiments of the application includes, but is not limited to, these and any other suitable types of memory.
The processor 1010 may include one or more processing units; optionally, the processor 1010 integrates an application processor that primarily processes operations involving an operating system, user interface, application programs, and the like, and a modem processor that primarily processes wireless communication signals, such as a baseband processor. It will be appreciated that the modem processor described above may not be integrated into the processor 1010.
The embodiment of the application also provides a readable storage medium, on which a program or an instruction is stored, which when executed by a processor, implements each process of the above garbage collection and processing method embodiment, and can achieve the same technical effects, and in order to avoid repetition, the description is omitted here.
Wherein the processor is a processor in the electronic device described in the above embodiment. The readable storage medium includes computer readable storage medium such as computer readable memory ROM, random access memory RAM, magnetic or optical disk, etc.
The embodiment of the application further provides a chip, which comprises a processor and a communication interface, wherein the communication interface is coupled with the processor, and the processor is used for running programs or instructions to realize the processes of the garbage collection and treatment method embodiment, and the same technical effects can be achieved, so that repetition is avoided, and the description is omitted here.
It should be understood that the chips referred to in the embodiments of the present application may also be referred to as system-on-chip chips, chip systems, or system-on-chip chips, etc.
Embodiments of the present application provide a computer program product stored in a storage medium, where the program product is executed by at least one processor to implement the processes of the embodiments of the garbage collection method, and achieve the same technical effects, and are not described herein in detail to avoid repetition.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element. Furthermore, it should be noted that the scope of the methods and apparatus in the embodiments of the present application is not limited to performing the functions in the order shown or discussed, but may also include performing the functions in a substantially simultaneous manner or in an opposite order depending on the functions involved, e.g., the described methods may be performed in an order different from that described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a computer software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) comprising instructions for causing a terminal (which may be a mobile phone, a computer, a server, or a network device, etc.) to perform the method according to the embodiments of the present application.
The embodiments of the present application have been described above with reference to the accompanying drawings, but the present application is not limited to the above-described embodiments, which are merely illustrative and not restrictive, and many forms may be made by those having ordinary skill in the art without departing from the spirit of the present application and the scope of the claims, which are to be protected by the present application.

Claims (13)

1. A method for recycling waste, comprising:
receiving an ith garbage collection instruction sent by a target process, wherein i is a positive integer;
acquiring the first time of receiving the ith garbage collection instruction and the second time of executing the ith-1 th garbage collection instruction of completing the target process;
and under the condition that the difference value between the first time and the second time is smaller than the first time length, executing a target garbage collection instruction at a third time, wherein the target garbage collection instruction is the garbage collection instruction received between the first time and the third time, and the difference value between the third time and the second time is larger than or equal to the first time length.
2. The method of claim 1, wherein the target garbage collection instruction is the ith garbage collection instruction;
and executing a target garbage collection instruction at a third time under the condition that the difference value between the first time and the second time is smaller than the first duration, wherein the target garbage collection instruction comprises:
acquiring memory information of the equipment under the condition that the difference value between the first time and the second time is smaller than a first duration;
executing the ith garbage collection instruction at the third time under the condition that the memory information of the equipment meets a first condition;
Wherein the first condition includes:
the heap memory of the target process is smaller than a first proportion of a memory threshold of the target process;
the memory increased by the target process in the first duration is smaller than a second proportion of the memory threshold value;
the device uses memory less than a third proportion of the device memory threshold.
3. The method of claim 1, wherein the target garbage collection instruction is the ith garbage collection instruction;
and executing a target garbage collection instruction at a third time under the condition that the difference value between the first time and the second time is smaller than the first duration, wherein the target garbage collection instruction comprises:
monitoring the running state of the central processing unit between a fourth time and a fifth time when the difference between the first time and the second time is smaller than the first time, wherein the difference between the fourth time and the second time is equal to the first time, and the difference between the fifth time and the second time is larger than the first time;
if the running state of the central processing unit at the third time is an idle state, executing the ith garbage collection instruction at the third time, wherein the third time is the time between the fourth time and the fifth time;
And if the running states of the central processing unit between the fourth time and the fifth time are all non-idle states, executing the ith garbage collection instruction at the third time, wherein the third time is the fifth time.
4. The method of claim 1, wherein the target garbage collection instruction is a kth garbage collection instruction;
the executing the target garbage collection instruction at the third time includes:
when the ith garbage collection instruction is a part of garbage collection instructions and the kth garbage collection instruction is a whole garbage collection instruction, canceling execution of the ith garbage collection instruction and executing the kth garbage collection instruction at a third time;
the kth garbage collection instruction is a garbage collection instruction received after the first time, before the third time and the third time, and k is an integer greater than i.
5. The method according to claim 1, wherein the method further comprises:
and determining the jth garbage collection instruction as an invalid instruction when the jth garbage collection instruction is received after the first time, at the third time and before the third time, wherein j is an integer larger than i.
6. The method of claim 5, wherein said determining the jth garbage collection instruction as an invalid instruction comprises:
determining the jth garbage collection instruction as an invalid instruction in the case that the ith garbage collection instruction and the jth garbage collection instruction meet a second condition;
wherein the second condition includes any one of:
the jth garbage collection instruction and the ith garbage collection instruction are part of garbage collection instructions;
the jth garbage collection instruction and the ith garbage collection instruction are all garbage collection instructions;
the ith garbage collection instruction is a full garbage collection instruction, and the jth garbage collection instruction is a partial garbage collection instruction.
7. A garbage collection and treatment device, comprising:
the receiving module is used for receiving an ith garbage collection instruction sent by the target process, wherein i is a positive integer;
the acquisition module is used for acquiring the first time when the ith garbage collection instruction is received and the second time when the ith-1 th garbage collection instruction of the target process is completed;
and the execution module is used for executing a target garbage collection instruction at a third time under the condition that the difference between the first time and the second time is smaller than the first time, wherein the target garbage collection instruction is the garbage collection instruction received between the first time and the third time, and the difference between the third time and the second time is larger than or equal to the first time.
8. The apparatus of claim 7, wherein the target garbage collection instruction is the ith garbage collection instruction;
the execution module is specifically configured to:
acquiring memory information of the equipment under the condition that the difference value between the first time and the second time is smaller than a first duration;
executing the ith garbage collection instruction at the third time under the condition that the memory information of the equipment meets a first condition;
wherein the first condition includes:
the heap memory of the target process is smaller than a first proportion of a memory threshold of the target process;
the memory increased by the target process in the first duration is smaller than a second proportion of the memory threshold value;
the device uses memory less than a third proportion of the device memory threshold.
9. The apparatus of claim 7, wherein the target garbage collection instruction is the ith garbage collection instruction;
the execution module is specifically configured to:
monitoring the running state of the central processing unit between a fourth time and a fifth time when the difference between the first time and the second time is smaller than the first time, wherein the difference between the fourth time and the second time is equal to the first time, and the difference between the fifth time and the second time is larger than the first time;
If the running state of the central processing unit at the third time is an idle state, executing the ith garbage collection instruction at the third time, wherein the third time is the time between the fourth time and the fifth time;
and if the running states of the central processing unit between the fourth time and the fifth time are all non-idle states, executing the ith garbage collection instruction at the third time, wherein the third time is the fifth time.
10. The apparatus of claim 7, wherein the target garbage collection instruction is a kth garbage collection instruction;
the execution module is specifically configured to:
when the difference between the first time and the second time is smaller than a first duration, the ith garbage collection instruction is a part of garbage collection instructions, and the kth garbage collection instruction is a whole garbage collection instruction, the execution of the ith garbage collection instruction is canceled, and the kth garbage collection instruction is executed at a third time;
the kth garbage collection instruction is a garbage collection instruction received after the first time, before the third time and before the third time, k is an integer greater than i, and the difference between the third time and the second time is greater than or equal to the first time.
11. The apparatus of claim 7, wherein the apparatus further comprises:
and the determining module is used for determining the jth garbage collection instruction as an invalid instruction when the jth garbage collection instruction for the target process is received after the first time, before the third time and before the third time, wherein j is an integer larger than i.
12. The apparatus according to claim 11, wherein the determining module is specifically configured to:
determining the jth garbage collection instruction as an invalid instruction in the case that the ith garbage collection instruction and the jth garbage collection instruction meet a second condition;
wherein the second condition includes any one of:
the jth garbage collection instruction and the ith garbage collection instruction are part of garbage collection instructions;
the jth garbage collection instruction and the ith garbage collection instruction are all garbage collection instructions;
the ith garbage collection instruction is a full garbage collection instruction, and the jth garbage collection instruction is a partial garbage collection instruction.
13. An electronic device comprising a processor and a memory storing a program or instructions executable on the processor, which when executed by the processor, implement the steps of the garbage collection method of any of claims 1-6.
CN202310944146.0A 2023-07-28 2023-07-28 Garbage recycling method and device and electronic equipment Pending CN116955215A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310944146.0A CN116955215A (en) 2023-07-28 2023-07-28 Garbage recycling method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310944146.0A CN116955215A (en) 2023-07-28 2023-07-28 Garbage recycling method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN116955215A true CN116955215A (en) 2023-10-27

Family

ID=88458015

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310944146.0A Pending CN116955215A (en) 2023-07-28 2023-07-28 Garbage recycling method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN116955215A (en)

Similar Documents

Publication Publication Date Title
CN111158910B (en) Memory management method and device, storage medium and electronic equipment
CN109740732B (en) Neural network processor, convolutional neural network data multiplexing method and related equipment
CN105159776B (en) Process handling method and device
CN105335099A (en) Memory cleaning method and terminal
CN111274039B (en) Memory recycling method and device, storage medium and electronic equipment
CN111475299B (en) Memory allocation method and device, storage medium and electronic equipment
CN112711387A (en) Method and device for adjusting capacity of buffer area, electronic equipment and readable storage medium
US20240152439A1 (en) Detection Method and Electronic Device
CN113268438B (en) Memory recycling method and device and electronic equipment
CN116955215A (en) Garbage recycling method and device and electronic equipment
CN115964180A (en) Task scheduling method and device and electronic equipment
CN115617518A (en) Thread management method and device, electronic equipment and storage medium
CN104699513A (en) File processing method and device
CN113010004A (en) Abnormal power consumption processing method and device and electronic equipment
CN111767153B (en) Resource access method and device and electronic equipment
CN117311967A (en) Memory processing method and device and electronic equipment
CN115994032A (en) Cache management method, device, electronic equipment and medium
CN116795538A (en) Compiling process management method and device and electronic equipment
CN116643891A (en) Application process control method and device and electronic equipment
CN116701242A (en) Memory recycling method and device, electronic equipment and readable storage medium
CN116991605A (en) Process processing method, device, electronic equipment and readable storage medium
CN117149391A (en) Thread management method and device and electronic equipment
CN117111721A (en) Method and device for managing power consumption, electronic equipment and storage medium
CN116954911A (en) Memory processing method, memory processing device, electronic equipment and readable storage medium
CN116302541A (en) Resource performance adjusting method and device

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