CN114564315A - Memory allocation method and device, electronic equipment and medium - Google Patents
Memory allocation method and device, electronic equipment and medium Download PDFInfo
- Publication number
- CN114564315A CN114564315A CN202210254377.4A CN202210254377A CN114564315A CN 114564315 A CN114564315 A CN 114564315A CN 202210254377 A CN202210254377 A CN 202210254377A CN 114564315 A CN114564315 A CN 114564315A
- Authority
- CN
- China
- Prior art keywords
- memory
- memory allocation
- pool
- application process
- allocation
- 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
Links
- 230000015654 memory Effects 0.000 title claims abstract description 446
- 238000000034 method Methods 0.000 title claims abstract description 109
- 238000013467 fragmentation Methods 0.000 claims description 11
- 238000006062 fragmentation reaction Methods 0.000 claims description 11
- 230000008447 perception Effects 0.000 claims description 10
- 230000001105 regulatory effect Effects 0.000 claims description 4
- 230000000875 corresponding effect Effects 0.000 description 10
- 230000006870 function Effects 0.000 description 9
- 230000000694 effects Effects 0.000 description 7
- 238000004891 communication Methods 0.000 description 5
- 230000001360 synchronised effect Effects 0.000 description 5
- 238000010586 diagram Methods 0.000 description 4
- 230000001960 triggered effect Effects 0.000 description 3
- 238000005056 compaction Methods 0.000 description 2
- 238000004590 computer program Methods 0.000 description 2
- 238000010606 normalization Methods 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 238000005457 optimization Methods 0.000 description 2
- 230000003068 static effect Effects 0.000 description 2
- 239000002699 waste material Substances 0.000 description 2
- 230000003190 augmentative effect Effects 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 230000002596 correlated effect Effects 0.000 description 1
- 238000001514 detection method Methods 0.000 description 1
- 238000007599 discharging Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000012544 monitoring process Methods 0.000 description 1
- 238000004064 recycling Methods 0.000 description 1
- 230000002441 reversible effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation 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/5016—Allocation 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
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation 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/5022—Mechanisms to release resources
-
- Y—GENERAL 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
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE 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/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
The application discloses a memory allocation method, a memory allocation device, electronic equipment and a memory allocation medium, and belongs to the technical field of electronics. The specific scheme comprises the following steps: acquiring a memory allocation request; under the condition that continuous memories meeting the memory allocation requests are not allocated in a first allocation mode, allocating the memories in the reserved memory pool to meet the memory allocation requests; wherein the first formula comprises at least one of: a fast memory allocation path and a slow memory allocation path.
Description
Technical Field
The present application relates to the field of electronic technologies, and in particular, to a method and an apparatus for allocating memory, an electronic device, and a medium.
Background
With the continuous upgrade of the application programs in the electronic equipment, the functions of the application programs are more and more abundant, and after a user uses the electronic equipment for a long time, the number of the started application programs is more and more, and the memory pressure of a system is also more and more.
In the related art, when a system needs to apply for a memory, if the remaining continuous memory is not enough to meet the memory application requirement, the system is triggered to perform memory _ compact (memory _ compact), however, the memory-compaction is successful on the premise that there is a free memory, so when the memory pressure is large, the memory-compaction usually fails. Once Memory normalization fails, an Out of Memory (OOM) mechanism of the system is triggered, and since the OOM mechanism can end running most processes except the system, foreground applications in use by users are killed by mistake, so that the problem of application flash back occurs, and the use experience of the users is influenced.
Disclosure of Invention
An object of the embodiments of the present application is to provide a memory allocation method, an apparatus, an electronic device, and a medium, which can solve the problem of application flash back caused by insufficient memory.
In a first aspect, an embodiment of the present application provides a memory allocation method, where the method includes: acquiring a memory allocation request; under the condition that continuous memories meeting the memory allocation requests are not allocated in a first allocation mode, allocating the memories in the reserved memory pool to meet the memory allocation requests; wherein the first formula comprises at least one of: a fast memory allocation path and a slow memory allocation path.
In a second aspect, an embodiment of the present application provides a memory allocation apparatus, including: an acquisition module and a distribution module; the acquisition module is used for acquiring a memory allocation request; the allocation module is used for allocating the memory in the reserved memory pool to meet the memory allocation request under the condition that the continuous memory meeting the memory allocation request is not allocated in a first allocation mode; wherein the first formula comprises at least one of: a fast memory allocation path and a slow memory allocation path.
In a third aspect, embodiments of the present application provide an electronic device, which includes a processor and a memory, where the memory stores a program or instructions executable on the processor, and the program or instructions, when executed by the processor, implement the steps of the method according to the first aspect.
In a fourth aspect, embodiments of the present application provide a readable storage medium, on which a program or instructions are stored, which when executed by a processor implement 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 the processor is configured to execute a program or instructions to implement the method according to the first aspect.
In a sixth aspect, embodiments of the present application provide a computer program product, stored on a storage medium, for execution by at least one processor to implement the method according to the first aspect.
In the embodiment of the application, a memory allocation request can be obtained; under the condition that continuous memories meeting the memory allocation requests are not allocated in a first allocation mode, allocating the memories in the reserved memory pool to meet the memory allocation requests; wherein the first formula comprises at least one of: a fast memory allocation path and a slow memory allocation path. According to the scheme, under the condition that the continuous memory meeting the memory allocation request is not allocated in the first allocation mode, the memory in the reserved memory pool can be allocated to meet the memory allocation request, namely, the memory in the reserved memory pool can be used, so that the problem that the foreground application process is finished to run due to the fact that the memory cannot be applied can be solved, the occurrence of application flash back is reduced, and the stability of the system under the critical pressure is improved.
Drawings
Fig. 1 is a schematic flow chart of a memory allocation method according to an embodiment of the present disclosure;
fig. 2 is a second schematic flowchart of a memory allocation method according to an embodiment of the present application;
fig. 3 is a third schematic flowchart of a memory allocation method according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a memory allocation apparatus according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of an electronic device provided in an embodiment of the present application;
fig. 6 is a hardware schematic diagram of an electronic device provided in an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be described clearly below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments that can be derived by one of ordinary skill in the art from the embodiments given herein are intended to be within the scope of the present disclosure.
The terms first, second and the like in the description and in the claims of the present application are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that embodiments of the application are capable of operation in sequences other than those illustrated or described herein, and that the terms "first," "second," etc. are generally used in a generic sense and do not limit the number of terms, e.g., a first term can be one or more than one. In addition, "and/or" in the specification and claims means at least one of connected objects, a character "/", and generally means that the former and latter related objects are in an "or" relationship.
The memory allocation method provided in the embodiments of the present application is described in detail below with reference to the accompanying drawings through specific embodiments and application scenarios thereof.
In the memory allocation method provided in the embodiment of the present application, an execution main body of the memory allocation method may be an electronic device or a functional module or a functional entity capable of implementing the memory allocation method in the electronic device, the electronic device mentioned in the embodiment of the present application includes, but is not limited to, a mobile phone, a tablet computer, a camera, a wearable device, and the like, and the memory allocation method provided in the embodiment of the present application is described below with the electronic device as the execution main body.
As shown in fig. 1, an embodiment of the present application provides a memory allocation method, which may include steps 101 to 102:
Specifically, as shown in fig. 2, the electronic device may obtain a memory allocation request of the application, and then the electronic device may first respond to the memory allocation request through a first allocation manner, where the first allocation manner may include at least one of the following: a fast memory allocation path and a slow memory allocation path. That is, when the remaining continuous memory of the system sufficiently satisfies the memory allocation request, the electronic device may directly allocate the remaining continuous memory to the application program through the fast memory allocation path; when the remaining continuous memory of the system is not enough to satisfy the memory allocation request, the electronic device may allocate memory through a slow memory allocation path, that is, trigger memory recycling and memory organizing operations of the system, organize the received fragmented memory blocks into continuous memory, and then allocate the organized continuous memory to the application program.
Optionally, the memory requirement of the memory allocation request may be a non-fragmented continuous memory requirement, for example, at least an order3 memory, that is, a continuous memory greater than or equal to 32K.
With continued reference to fig. 2, if the continuous memory satisfying the memory allocation request cannot be allocated through both the fast memory allocation path and the slow memory allocation path, that is, the normalized continuous memory is still insufficient to satisfy the memory requirement of the memory allocation request, the electronic device may allocate the memory in the reserved memory pool to the application program.
In the embodiment of the present application, under the condition that the continuous memory meeting the memory allocation request is not allocated in the first allocation manner, the memory in the reserved memory pool may be allocated to meet the memory allocation request, that is, the memory in the reserved memory pool may be used, so that the problem that the foreground application process is finished running due to the fact that the memory cannot be applied is solved, thereby reducing the occurrence of the application flash back situation, and further improving the stability of the system under the critical pressure.
Optionally, in order to meet the operation requirement of the application program in the electronic device, the memory size of the reserved memory pool may be determined in the following two ways:
in the method 1, when a system of an electronic device is in a starting state, the electronic device may obtain a first configuration file of a reserved memory pool; determining an initial memory of the reserved memory pool by reading the first configuration file; and then, initializing the reserved memory pool based on the initial memory, wherein the first configuration file is a configuration file issued by the server to the electronic equipment. That is to say, the server may modify the memory size of the reserved memory pool by issuing the first configuration file, and when the electronic device is restarted, the newly issued first configuration file may take effect.
Based on the scheme, the initial memory of the reserved memory pool can be determined according to the first configuration file, so that a background developer can flexibly control the size of the initial memory of the reserved memory pool through the server, and the reserved memory pool can meet memory requirements of different scenes.
In the mode 2, since the application programs installed in the electronic devices of each user are different and the application scenarios are also different, the memory size of the reserved memory pool in different electronic devices can be dynamically adjusted in order to meet the personalized memory requirements of the users. Specifically, under the condition that a system of the electronic device is in an operating state, after the electronic device applies for the memory to the reserved memory pool according to the memory requirement of the memory allocation request, under the condition that the reserved memory pool does not meet the memory requirement, the electronic device may adjust the initial memory corresponding to the first configuration file to obtain a second configuration file; then, updating the first configuration file into a second configuration file; and the initial memory corresponding to the second configuration file is less than or equal to a fourth threshold, and the fourth threshold has an association relation with the system physical memory. That is, the size of the fourth threshold may be determined according to the system physical memory, where the larger the system physical memory is, the larger the fourth threshold is, the smaller the system physical memory is, and the smaller the fourth threshold is.
It should be noted that the second configuration file may be valid after the electronic device is restarted.
Optionally, under the condition that the reserved memory pool does not meet the memory requirement, the electronic device may adjust the initial memory corresponding to the first configuration file according to a preset multiple to obtain a second configuration file.
Illustratively, as shown in fig. 3, the preset multiple is 2 as an example. When the electronic device is started for the first time, the initialization of the system can be completed firstly, then the configuration file in the electronic device is read, at this time, the configuration file is the first configuration file issued by the server, so that the current initial memory of the reserved memory pool is determined to be X, after the electronic device runs for a period of time, if the remaining memory in the reserved memory pool cannot meet the current memory requirement, the electronic device can generate a second configuration file in a self-adaptive manner, and the second configuration file is used for indicating that the initial memory of the reserved memory pool is 2X. Then, the electronic device may update the configuration file to a second configuration file, and then when the electronic device is started for the second time, the second configuration file may be directly read, so as to determine that the current initial memory of the reserved memory pool is 2X.
It should be noted that the electronic device needs to adjust the initial memory of the reserved memory pool according to the system physical memory, and the adjusted initial memory of the reserved memory pool needs to be smaller than a fourth threshold, where the fourth threshold is positively correlated with the system physical memory. For example, take the minimum memory unit of the electronic device as 4G, the fourth threshold valueWherein, memotal is the physical memory of the electronic device, the unit is G, and the fourth threshold value poollimitIs M, the calculation result can be rounded down.
Based on the above scheme, under the condition that the remaining memory in the reserved memory pool does not meet the memory requirement, the electronic device may obtain the second configuration file according to the initial memory corresponding to the first configuration file, and therefore, the initial memory in the reserved memory pool may be flexibly adjusted according to the use scene requirement of the user, so that not only memory waste may be avoided, but also the optimization effect of memory management may be improved.
Optionally, the allocating, by the electronic device, the memory in the reserved memory pool to meet the memory allocation request may specifically include: the electronic equipment applies for the memory from the reserved memory pool according to the memory requirement of the memory allocation request; under the condition that the remaining memory in the reserved memory pool can meet the memory requirement, the electronic device can allocate the memory in the reserved memory pool to meet the memory allocation request. That is, when the remaining memory in the reserved memory pool is greater than or equal to the memory requirement corresponding to the memory allocation request, the electronic device may successfully allocate the memory through the reserved memory pool.
Based on the above scheme, the electronic device can allocate the memory in the reserved memory pool to satisfy the memory allocation request under the condition that the remaining memory in the reserved memory pool can satisfy the memory requirement, so that the memory pressure of the system can be relieved through the memory in the reserved memory pool, and the occurrence of the application flash back condition is reduced.
Optionally, after allocating the memory in the reserved memory pool to satisfy the memory allocation request, the electronic device may further monitor a memory consumption speed of the reserved memory pool; under the condition that the memory consumption speed is greater than a first threshold value, determining a target application process, and finishing running the target application process, wherein the target application process is an application process with user perception smaller than a second threshold value, and the user perception is the probability of being perceived by a user after the application process is finished running; and finally, performing regularization treatment on the memory released by the target application process after the operation is finished to obtain a continuous memory.
When the memory consumption speed of the reserved memory pool is greater than the first threshold, the memory consumption speed of the reserved memory pool is high, if the remaining memory of the reserved memory pool is increasingly tense, new memory cannot be released, and the remaining memory is insufficient to meet the next memory requirement, the OOM mechanism still may be triggered.
Optionally, the user perception of the application process may be determined according to at least one of: whether it is running in the background, the time it is running from the foreground, the frequency and time the user uses the application process, etc.
Based on the scheme, when the memory consumption speed of the reserved memory pool is greater than the first threshold, the memory can be released by ending the running of the target application process, and the continuous memory is obtained through the regularization processing.
Alternatively, the electronic device may determine the memory consumption rate of the reserved memory pool according to the average time interval of the plurality of memory allocation requests. For example, the electronic device may obtain the total time consumption of 10 memory allocation requests, then calculate an average time interval of the 10 memory allocation requests, and finally compare the obtained average time interval with a first threshold, so as to grasp the memory consumption speed of the reserved memory pool, thereby reducing the monitoring pressure of the electronic device.
Optionally, before ending running the target application process, the electronic device may determine a fragmentation degree of a system memory; and if the fragmentation degree is larger than a third threshold value, ending the running of the target application process.
Specifically, the electronic device may monitor the memory consumption speed of the reserved memory pool, report an exception to the upper layer lmkd thread when the memory consumption speed is greater than a first threshold, calculate the memory state of the current system after the lmkd thread receives the exception report sent by the bottom layer, determine, through the process scheduling mechanism, a target application process whose user perception is less than a second threshold if the fragmentation degree is greater than a third threshold, and after the target application process is finished running, send a process killing success signal to the kcompact thread in the kernel, so as to trigger the kcompact thread to perform a process on the memory released by the target application process that is finished running.
Based on the scheme, the judgment of the fragmentation degree of the memory can be carried out before the target application process is finished, so that the success rate of the subsequent memory arrangement processing can be improved.
In the memory allocation method provided by the embodiment of the present application, the execution main body may be a memory allocation device. In the embodiment of the present application, a memory allocation device executing a memory allocation method is taken as an example to describe the memory allocation device provided in the embodiment of the present application.
As shown in fig. 4, an embodiment of the present invention further provides a memory allocation apparatus 400, including: an acquisition module 401 and a distribution module 402. The obtaining module 401 may be configured to obtain a memory allocation request; the allocating module 402 may be configured to allocate, in the case that the continuous memory that meets the memory allocation request is not allocated in the first allocation manner, the memory in the reserved memory pool to meet the memory allocation request; wherein the first formula comprises at least one of: a fast memory allocation path and a slow memory allocation path.
Optionally, with continued reference to fig. 4, the apparatus 400 may further include a processing module 403. The processing module 403 may be configured to determine a target application process and end running the target application process when the memory consumption speed is greater than a first threshold, where the target application process is an application process with a user perception smaller than a second threshold, and the user perception is a probability of being perceived by a user after the application process is ended running; and regulating the memory released by the target application process after the operation is finished to obtain a continuous memory.
Optionally, the processing module 403 may be further configured to determine a fragmentation degree of a system memory; the processing module 403 may be specifically configured to, in a case that the fragmentation degree is greater than a third threshold, end running the target application process.
Optionally, the obtaining module 401 may be further configured to obtain the first configuration file of the reserved memory pool when the system is in a starting state; the processing module 403 may be configured to determine an initial memory of the reserved memory pool according to the first configuration file; initializing the reserved memory pool based on the initial memory; the first configuration file is a configuration file issued by a server.
Optionally, the allocating module 402 may be specifically configured to apply for the memory from the reserved memory pool according to a memory requirement of the memory allocation request; and under the condition that the residual memory in the reserved memory pool meets the memory requirement, allocating the memory in the reserved memory pool to meet the memory allocation request.
Optionally, the processing module 403 may be further configured to, when the remaining memory in the reserved memory pool does not meet the memory requirement, adjust an initial memory corresponding to the first configuration file to obtain a second configuration file; updating the first configuration file to the second configuration file; and the initial memory corresponding to the second configuration file is less than or equal to a fourth threshold, and the fourth threshold has an association relation with the system physical memory.
In the embodiment of the present application, under the condition that the continuous memory meeting the memory allocation request is not allocated in the first allocation manner, the memory in the reserved memory pool may be allocated to meet the memory allocation request, that is, the memory in the reserved memory pool may be used, so that the problem that the foreground application process is finished running due to the fact that the memory cannot be applied is solved, thereby reducing the occurrence of the application flash back situation, and further improving the stability of the system under the critical pressure.
The memory allocation apparatus in the embodiment of the present application may be an electronic device, or may be a component in an electronic device, such as an integrated circuit or a chip. The electronic device may be a terminal, or may be a device other than a terminal. The electronic Device may be, for example, a Mobile phone, a tablet computer, a notebook computer, a palm top computer, a vehicle-mounted electronic Device, a Mobile Internet Device (MID), an Augmented Reality (AR)/Virtual Reality (VR) Device, a robot, a wearable Device, an ultra-Mobile personal computer (UMPC), a netbook or a Personal Digital Assistant (PDA), and the like, and may also be a server, a Network Attached Storage (NAS), a Personal Computer (PC), a Television (TV), a teller machine, a self-service machine, and the like, and the embodiments of the present application are not particularly limited.
The memory allocation device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system (Android), an iOS operating system, or other possible operating systems, which is not specifically limited in the embodiments of the present application.
The memory allocation device provided in the embodiment of the present application can implement each process implemented by the method embodiments in fig. 1 to fig. 3, and is not described here again to avoid repetition.
Optionally, as shown in fig. 5, an electronic device 500 is further provided in the embodiment of the present application, and includes a processor 501 and a memory 502, where the memory 502 stores a program or an instruction that can be executed on the processor 501, and when the program or the instruction is executed by the processor 501, the steps of the memory allocation method embodiment are implemented, and the same technical effects can be achieved, and are not described again to avoid repetition.
It should be noted that the electronic device in the embodiment of the present application includes the mobile electronic device and the non-mobile electronic device described above.
Fig. 6 is a schematic diagram of a hardware structure of an electronic device implementing the embodiment of the present application.
The electronic device 1000 includes, but is not limited to: a radio frequency unit 1001, a network module 1002, an audio output unit 1003, an input unit 1004, a sensor 1005, a display unit 1006, a user input unit 1007, an interface unit 1008, a memory 1009, and a processor 1010.
Those skilled in the art will appreciate that the electronic device 1000 may further comprise a power supply (e.g., a battery) for supplying power to the various components, and the power supply may be logically connected to the processor 1010 through a power management system, so as to implement functions of managing charging, discharging, and power consumption through the power management system. The electronic device structure shown in fig. 6 does not constitute a limitation of the electronic device, and the electronic device may include more or less components than those shown, or combine some components, or arrange different components, and thus, the description is omitted here.
The interface unit 1008 may be configured to obtain a memory allocation request; a processor 1010, configured to allocate a memory in a reserved memory pool to meet the memory allocation request when a continuous memory meeting the memory allocation request is not allocated in a first allocation manner; wherein the first formula comprises at least one of: a fast memory allocation path and a slow memory allocation path.
In the embodiment of the present application, under the condition that the continuous memory meeting the memory allocation request is not allocated in the first allocation manner, the memory in the reserved memory pool may be allocated to meet the memory allocation request, that is, the memory in the reserved memory pool may be used, so that the problem that the foreground application process is finished running due to the fact that the memory cannot be applied is solved, thereby reducing the occurrence of the application flash back situation, and further improving the stability of the system under the critical pressure.
Optionally, the processor 1010 may be configured to, when the memory consumption speed is greater than a first threshold, determine a target application process, and end running the target application process, where the target application process is an application process whose user perceptibility is less than a second threshold, and the user perceptibility is a probability that a user perceives after the application process is ended running; and regulating the memory released by the target application process after the operation is finished to obtain a continuous memory.
In the embodiment of the application, when the memory consumption speed of the reserved memory pool is greater than the first threshold, the memory can be released by ending running the target application process, and the continuous memory is obtained through the regularization processing.
Optionally, the processor 1010 may be further configured to determine a fragmentation degree of a system memory; the processor 1010 may be specifically configured to end the running of the target application process when the fragmentation degree is greater than a third threshold.
In the embodiment of the application, the judgment of the fragmentation degree of the memory can be carried out before the target application process is finished, so that the success rate of the subsequent memory normalization processing can be improved.
Optionally, the interface unit 1008 may be further configured to obtain a first configuration file of the reserved memory pool when the system is in a start state; a processor 1010, configured to determine an initial memory of the reserved memory pool according to the first configuration file; initializing the reserved memory pool based on the initial memory; the first configuration file is a configuration file issued by a server.
In the embodiment of the application, the initial memory of the reserved memory pool can be determined according to the first configuration file, so that a background developer can flexibly control the size of the initial memory of the reserved memory pool through the server, and the reserved memory pool can meet the memory requirements of different scenes.
Optionally, the processor 1010 may be specifically configured to apply for the memory from the reserved memory pool according to the memory requirement of the memory allocation request; and under the condition that the residual memory in the reserved memory pool meets the memory requirement, responding the memory allocation request through the memory in the reserved memory pool.
In the embodiment of the application, because the electronic device can allocate the memory in the reserved memory pool to meet the memory allocation request under the condition that the remaining memory in the reserved memory pool can meet the memory requirement, the memory pressure of the system can be relieved through the memory in the reserved memory pool, and the occurrence of the application flash back condition is reduced.
Optionally, the processor 1010 may be further configured to adjust an initial memory corresponding to the first configuration file to obtain a second configuration file when the remaining memory in the reserved memory pool does not meet the memory requirement; updating the first configuration file to the second configuration file; and the initial memory corresponding to the second configuration file is less than or equal to a fourth threshold, and the fourth threshold has an association relation with the system physical memory.
In the embodiment of the application, under the condition that the remaining memory in the reserved memory pool does not meet the memory requirement, the electronic device may adjust the initial memory corresponding to the first configuration file to obtain the second configuration file, and therefore, the initial memory in the reserved memory pool may be flexibly adjusted according to the use scene requirement of the user, so that not only memory waste may be avoided, but also the optimization effect of memory management may be improved.
It should be understood that, in the embodiment of the present application, the input Unit 1004 may include a Graphics Processing Unit (GPU) 10041 and a microphone 10042, and the Graphics Processing Unit 10041 processes image data of a still picture or a video obtained by an image capturing device (such as 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 may include two parts, 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, and a joystick, 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 storage area storing a program or an instruction and a second storage area storing data, wherein the first storage area may store an operating system, an application program or an instruction (such as a sound playing function, an image playing function, and the like) 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 non-volatile Memory may be a Read-Only Memory (ROM), a Programmable ROM (PROM), an Erasable PROM (EPROM), an Electrically Erasable PROM (EEPROM), or a flash Memory. The volatile Memory may be a Random Access Memory (RAM), a Static Random Access Memory (Static RAM, SRAM), a Dynamic Random Access Memory (Dynamic RAM, DRAM), a Synchronous Dynamic Random Access Memory (Synchronous DRAM, SDRAM), a Double Data Rate Synchronous Dynamic Random Access Memory (Double Data Rate SDRAM, ddr SDRAM), an Enhanced Synchronous SDRAM (ESDRAM), a Synchronous Link DRAM (SLDRAM), and a Direct Memory bus RAM (DRRAM). The memory 1009 in the embodiments of the present application includes, but is not limited to, these and any other suitable types of memory.
The embodiments of the present application further provide a readable storage medium, where a program or an instruction is stored, and when the program or the instruction is executed by a processor, the program or the instruction implements each process of the foregoing memory allocation method embodiment, and can achieve the same technical effect, and in order to avoid repetition, details are not repeated here.
The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read only memory ROM, a random access memory RAM, a magnetic or optical disk, and the like.
The embodiment of the present application further provides a chip, where the chip includes a processor and a communication interface, the communication interface is coupled to the processor, and the processor is configured to execute a program or an instruction to implement each process of the memory allocation method embodiment, and can achieve the same technical effect, and the details are not repeated here to avoid repetition.
It should be understood that the chips mentioned in the embodiments of the present application may also be referred to as system-on-chip, system-on-chip or system-on-chip, etc.
Embodiments of the present application provide a computer program product, where the program product is stored in a storage medium, and the program product is executed by at least one processor to implement the processes of the foregoing memory allocation method embodiments, and can achieve the same technical effects, and in order to avoid repetition, details are not described here again.
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 an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element. Further, it should be noted that the scope of the methods and apparatus of the embodiments of the present application is not limited to performing the functions in the order illustrated or discussed, but may include performing the functions in a substantially simultaneous manner or in a reverse order based on the functions involved, e.g., the methods described may be performed in an order different than that described, and various steps may be added, omitted, or combined. In addition, features described with reference to certain examples may be combined in other examples.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present application may be embodied in the form of a computer software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present application.
While the present embodiments have been described with reference to the accompanying drawings, it is to be understood that the invention is not limited to the precise embodiments described above, which are meant to be illustrative and not restrictive, and that various changes may be made therein by those skilled in the art without departing from the spirit and scope of the invention as defined by the appended claims.
Claims (10)
1. A method for allocating memory, comprising:
acquiring a memory allocation request;
under the condition that continuous memories meeting the memory allocation requests are not allocated in a first allocation mode, allocating the memories in the reserved memory pool to meet the memory allocation requests;
wherein the first formula comprises at least one of: a fast memory allocation path and a slow memory allocation path.
2. The memory allocation method of claim 1, wherein after the allocating the memory in the reserved memory pool to satisfy the memory allocation request, the method further comprises:
under the condition that the memory consumption speed of the reserved memory pool is greater than a first threshold, determining a target application process, and finishing running the target application process, wherein the target application process is an application process with user perception smaller than a second threshold, and the user perception is the probability perceived by a user after the running of the application process is finished;
and regulating the memory released by the target application process after the operation is finished to obtain a continuous memory.
3. The memory allocation method according to claim 2, wherein before the ending of the running of the target application process, the method further comprises:
determining the fragmentation degree of a system memory;
the ending of the running of the target application process comprises:
and under the condition that the fragmentation degree is larger than a third threshold value, ending the running of the target application process.
4. The memory allocation method according to claim 1, wherein before the obtaining the memory allocation request, the method further comprises:
under the condition that the system is in a starting state, acquiring a first configuration file of the reserved memory pool;
determining an initial memory of the reserved memory pool according to the first configuration file;
initializing the reserved memory pool based on the initial memory;
the first configuration file is a configuration file issued by a server.
5. The method according to any of claims 1-4, wherein the allocating memory in the reserved memory pool to satisfy the memory allocation request comprises:
applying for the memory from the reserved memory pool according to the memory requirement of the memory allocation request;
and under the condition that the reserved memory pool meets the memory requirement, allocating the memory in the reserved memory pool to meet the memory allocation request.
6. The memory allocation method according to claim 5, wherein after applying for the memory from the reserved memory pool according to the memory requirement of the memory allocation request, the method further comprises:
under the condition that the reserved memory pool does not meet the memory requirement, adjusting an initial memory corresponding to a first configuration file to obtain a second configuration file;
updating the first configuration file to the second configuration file;
and the initial memory corresponding to the second configuration file is less than or equal to a fourth threshold, and the fourth threshold has an association relation with the system physical memory.
7. A memory allocation apparatus, comprising: an acquisition module and a distribution module;
the acquisition module is used for acquiring the memory allocation request;
the allocation module is used for allocating the memory in the reserved memory pool to meet the memory allocation request under the condition that the continuous memory meeting the memory allocation request is not allocated in a first allocation mode;
wherein the first formula comprises at least one of: a fast memory allocation path and a slow memory allocation path.
8. The memory allocation arrangement of claim 7, further comprising a processing module;
the processing module is configured to determine a target application process and end running the target application process when the memory consumption speed is greater than a first threshold, where the target application process is an application process with a user perception degree smaller than a second threshold, and the user perception degree is a probability of being perceived by a user after the running of the application process is ended;
and regulating the memory released by the target application process after the operation is finished to obtain a continuous memory.
9. An electronic device comprising a processor and a memory, the memory storing a program or instructions executable on the processor, the program or instructions when executed by the processor implementing the memory allocation method of any one of claims 1-6.
10. A readable storage medium, on which a program or instructions are stored, which program or instructions, when executed by a processor, carry out the memory allocation method according to any one of claims 1-6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210254377.4A CN114564315A (en) | 2022-03-15 | 2022-03-15 | Memory allocation method and device, electronic equipment and medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210254377.4A CN114564315A (en) | 2022-03-15 | 2022-03-15 | Memory allocation method and device, electronic equipment and medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114564315A true CN114564315A (en) | 2022-05-31 |
Family
ID=81719401
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210254377.4A Pending CN114564315A (en) | 2022-03-15 | 2022-03-15 | Memory allocation method and device, electronic equipment and medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114564315A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116361012A (en) * | 2023-06-01 | 2023-06-30 | 荣耀终端有限公司 | Memory page allocation method and electronic equipment |
CN117724826A (en) * | 2023-06-13 | 2024-03-19 | 荣耀终端有限公司 | Memory allocation method for interprocess communication, electronic equipment and storage medium |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101937398A (en) * | 2010-09-14 | 2011-01-05 | 中兴通讯股份有限公司 | Configuration method and device for built-in system memory pool |
CN105302738A (en) * | 2015-12-09 | 2016-02-03 | 北京东土科技股份有限公司 | Method and device for distributing memory |
CN106155699A (en) * | 2016-07-29 | 2016-11-23 | 维沃移动通信有限公司 | The management method of a kind of background process and mobile terminal |
CN108255941A (en) * | 2017-12-08 | 2018-07-06 | 佛吉亚好帮手电子科技有限公司 | A kind of method of the raising picture loading velocity of low EMS memory occupation |
CN108334440A (en) * | 2017-01-19 | 2018-07-27 | 阿里巴巴集团控股有限公司 | A kind of processing method and processing device, client obtaining application performance test result |
CN111078587A (en) * | 2019-12-10 | 2020-04-28 | Oppo(重庆)智能科技有限公司 | Memory allocation method and device, storage medium and electronic equipment |
CN112631773A (en) * | 2020-12-23 | 2021-04-09 | 苏州三六零智能安全科技有限公司 | Data dynamic release method, device, equipment and storage medium |
-
2022
- 2022-03-15 CN CN202210254377.4A patent/CN114564315A/en active Pending
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101937398A (en) * | 2010-09-14 | 2011-01-05 | 中兴通讯股份有限公司 | Configuration method and device for built-in system memory pool |
CN105302738A (en) * | 2015-12-09 | 2016-02-03 | 北京东土科技股份有限公司 | Method and device for distributing memory |
CN106155699A (en) * | 2016-07-29 | 2016-11-23 | 维沃移动通信有限公司 | The management method of a kind of background process and mobile terminal |
CN108334440A (en) * | 2017-01-19 | 2018-07-27 | 阿里巴巴集团控股有限公司 | A kind of processing method and processing device, client obtaining application performance test result |
CN108255941A (en) * | 2017-12-08 | 2018-07-06 | 佛吉亚好帮手电子科技有限公司 | A kind of method of the raising picture loading velocity of low EMS memory occupation |
CN111078587A (en) * | 2019-12-10 | 2020-04-28 | Oppo(重庆)智能科技有限公司 | Memory allocation method and device, storage medium and electronic equipment |
CN112631773A (en) * | 2020-12-23 | 2021-04-09 | 苏州三六零智能安全科技有限公司 | Data dynamic release method, device, equipment and storage medium |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116361012A (en) * | 2023-06-01 | 2023-06-30 | 荣耀终端有限公司 | Memory page allocation method and electronic equipment |
CN116361012B (en) * | 2023-06-01 | 2023-10-24 | 荣耀终端有限公司 | Memory page allocation method and electronic equipment |
CN117724826A (en) * | 2023-06-13 | 2024-03-19 | 荣耀终端有限公司 | Memory allocation method for interprocess communication, electronic equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110888746B (en) | Memory management method and device, storage medium and electronic equipment | |
CN114564315A (en) | Memory allocation method and device, electronic equipment and medium | |
CN110895492A (en) | Device control method, device, storage medium and electronic device | |
CN107562645B (en) | Memory page management method and computing device | |
CN111475299B (en) | Memory allocation method and device, storage medium and electronic equipment | |
CN115509953A (en) | Memory recovery method and device | |
CN115357389A (en) | Memory management method and device and electronic equipment | |
CN116578422A (en) | Resource allocation method and electronic equipment | |
CN105260138A (en) | Read/write control system and method | |
CN111444117B (en) | Method and device for realizing fragmentation of storage space, storage medium and electronic equipment | |
CN117170872A (en) | Memory management method, device, equipment and storage medium | |
CN111078407B (en) | Memory management method and device, storage medium and electronic equipment | |
US10725932B2 (en) | Optimizing headless virtual machine memory management with global translation lookaside buffer shootdown | |
CN113032290B (en) | Flash memory configuration method, flash memory configuration device, electronic equipment and storage medium | |
CN115934276A (en) | Memory management method and device and electronic equipment | |
CN115220565A (en) | Dormancy control method and device for base frequency processor BP and electronic equipment | |
CN114996014A (en) | Memory allocation method and device based on ION (input/output) allocator and electronic equipment | |
CN112130994B (en) | Resource allocation method, device, electronic equipment and storage medium | |
CN117311966A (en) | Memory processing method and device and electronic equipment | |
CN112243152A (en) | Method for adjusting picture size, intelligent terminal and storage medium | |
CN114928765B (en) | Control method, control device, electronic equipment and readable storage medium | |
CN115686786A (en) | Resource allocation method and device | |
CN117311967A (en) | Memory processing method and device and electronic equipment | |
CN116560837A (en) | Cache resource adjustment method and device, electronic equipment and readable storage medium | |
CN114490438A (en) | Memory recovery method and device for application program |
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 |