CN117724826A - Memory allocation method for interprocess communication, electronic equipment and storage medium - Google Patents

Memory allocation method for interprocess communication, electronic equipment and storage medium Download PDF

Info

Publication number
CN117724826A
CN117724826A CN202310703513.8A CN202310703513A CN117724826A CN 117724826 A CN117724826 A CN 117724826A CN 202310703513 A CN202310703513 A CN 202310703513A CN 117724826 A CN117724826 A CN 117724826A
Authority
CN
China
Prior art keywords
memory
preset
thread
communication
memory space
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
CN202310703513.8A
Other languages
Chinese (zh)
Inventor
马超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Honor Device Co Ltd
Original Assignee
Honor Device Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Honor Device Co Ltd filed Critical Honor Device Co Ltd
Priority to CN202310703513.8A priority Critical patent/CN117724826A/en
Publication of CN117724826A publication Critical patent/CN117724826A/en
Pending legal-status Critical Current

Links

Landscapes

  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The application provides a memory allocation method for interprocess communication, electronic equipment and a storage medium, and relates to the technical field of communication. The physical memory of the electronic device comprises a preset cache pool for the binder communication and a first memory space outside the preset cache pool. The electronic equipment receives a first binder communication instruction initiated by a first process. In response to the first binder communication instruction, the electronic device may obtain a load state of physical memory allocation and thread information of a working thread operated by the first process. If the load state is the first state and the working thread operated by the first process is the target thread, memory space required by communication between the first process and the second process is distributed in a preset buffer pool. Therefore, the time delay of the physical memory allocation of the binder communication under the high load state can be reduced, and the possibility that the physical memory allocation of the binder communication blocks a key process is reduced.

Description

Memory allocation method for interprocess communication, electronic equipment and storage medium
Technical Field
The embodiment of the application relates to the technical field of communication, in particular to a memory allocation method for interprocess communication, electronic equipment and a storage medium.
Background
The inter-process communication mechanism in the Android (Android) system architecture includes a plurality of types. Such as pipes, message queues, shared memory, etc. Binder communication is an interprocess communication mechanism in the Android system architecture.
By using the binder mechanism, each inter-process communication only involves copying communication data once, so that the performance of the inter-process communication can be improved. At present, the frequency of the occurrence of the binder communication in the Android system architecture is very high, and in some scenes, the occurrence frequency of the binder communication can reach more than 3000 times per second. During each binder communication, the binder driver applies a piece of physical memory for storing communication data. And then the destination process of the binder communication can access the communication data stored in the physical memory to realize inter-process communication.
However, in some cases, the delay of memory allocation in the binder communication process is relatively large, which may cause performance problems such as system blocking.
Disclosure of Invention
The embodiment of the application provides a memory allocation method, electronic equipment and a storage medium for interprocess communication, which can reduce the time delay of memory allocation in the binder communication and optimize the system performance.
In order to achieve the above purpose, the embodiments of the present application adopt the following technical solutions:
In a first aspect, a memory allocation method for interprocess communication is provided, and the memory allocation method is applied to an electronic device, where a physical memory of the electronic device includes a preset buffer pool for binder communication and a first memory space outside the preset buffer pool. The method comprises the following steps:
the electronic device receives a first binder communication instruction initiated by a first process to a second process. And responding to the first binder communication instruction, and the electronic equipment acquires the load state of physical memory allocation and the thread information of the working thread operated by the first process. The thread information is used to indicate whether the worker thread is a target thread. If the load state is the first state and the worker thread operated by the first process is the target thread, this indicates a high load state of the current physical memory allocation of the electronic device, and the worker thread in the first process operated by the electronic device is a critical process (e.g., some user threads affecting the user experience, etc.) that has a significant impact on the system performance of the electronic device. At this time, the idle memory amount of the electronic device is smaller than a first preset threshold, or the memory allocation delay parameter of the binder communication is larger than a second preset threshold. In this case, the electronic device may allocate a memory space required for communication between the first process and the second process in the preset buffer pool, so as to implement communication between the first process and the second process.
In this way, under the conditions of high load state of physical memory allocation and running key threads, such as a game scene, a shooting scene and the like, the electronic equipment can immediately allocate the memory space required by the binder communication (i.e. the memory space required by the communication between the first process and the second process) through the preset cache pool, so that the time delay of the physical memory allocation of the binder communication under the high load state can be reduced, the possibility that the key process is blocked by the physical memory allocation of the binder communication is reduced, the system blocking condition is improved, the system performance is optimized, and the user experience is provided.
In another possible implementation manner of the first aspect, before acquiring the load state of the physical memory allocation and the thread information of the working thread operated by the first process, the electronic device may further count a total duration consumed by memory allocation in the binder communication of a preset number of times before the current time, and average the total duration by using the preset number of times to obtain a memory allocation delay parameter of the binder communication.
In this implementation manner, a method for determining a delay parameter of memory allocation is provided, that is, the delay parameter of memory allocation may be an average delay of memory allocation for multiple binder communications, such as an average delay of memory allocation for 10 binder communications. In this way, the memory allocation delay parameter may reflect a central tendency of memory allocation time consumption in the binder communication.
In another possible implementation manner of the first aspect, the thread information includes a memory exhaustion parameter and a thread level. The memory exhaustion parameter is used to indicate a possibility that a thread is forcibly terminated in a case where the free memory amount of the first memory space is smaller than the first preset memory amount. The thread level is inversely related to the importance of the worker thread. If the memory exhaustion parameter of the working thread operated by the first process is smaller than or equal to a third preset threshold value, or the thread level of the working thread is smaller than or equal to a fourth preset threshold value, the working thread is a target thread. If the memory exhaustion parameter of the working thread is greater than the third preset threshold value and the thread level of the working thread is greater than the fourth preset threshold value, the working thread is not the target thread.
In this implementation manner, the electronic device may determine, through at least one of the memory exhaustion parameter and the thread level, whether the working thread currently operated by the first process is a target thread. The memory exhaustion parameter and the thread level are both related to the importance degree of the working thread, so that the target thread can be accurately identified through any one of the memory exhaustion parameter and the thread level.
In another possible implementation manner of the first aspect, if the working thread is not a target thread, a memory space required for the first process to communicate with the second process is allocated in the first memory space.
In this implementation, since the first process does not run the target thread, even if the memory allocation of the present binder communication may block the working thread that is run by the first process, the impact on the system performance is small, and the user is hard to perceive the impact. In this case, the electronic device may allocate, in the first memory space, a memory space required by the first process and the second process, so as to implement the binder communication between the first process and the second process.
In another possible implementation manner of the first aspect, after the communication between the first process and the second process is finished, the memory space allocated for the communication between the first process and the second process is reclaimed to the preset cache pool.
In this way, the electronic device can preferentially recycle the allocated memory space of the binder communication to the preset buffer pool, so that the allocable memory space exists in the preset buffer pool, and therefore, the electronic device can immediately allocate the memory space for the binder communication through the preset buffer pool under the condition that the electronic device is in a high-load state of physical memory allocation and operates with a target thread.
In another possible implementation manner of the first aspect, if the load state is the second state, a memory space required for the first process to communicate with the second process is allocated in the first memory space. The load state is a second state, which indicates that the idle memory amount of the first memory space is greater than or equal to a first preset threshold, and the memory allocation delay parameter is less than or equal to a second preset threshold.
In the implementation manner, the load state is a second state, which means that the electronic device is in a low load state of physical memory allocation, the memory space which can be allocated in the first memory space is sufficient, and the memory allocation delay of the binder communication is smaller. The electronic device provides the memory space required by the present binder communication through the first memory space, so that the time delay is smaller, and the influence on the system performance is smaller.
In another possible implementation manner of the first aspect, in a case that a load state of the physical memory allocation is the second state, the free memory amount of the preset cache pool is obtained. The load state is a second state, which indicates that the idle memory amount of the first memory space is greater than or equal to a first preset threshold, and the memory allocation delay parameter is less than or equal to a second preset threshold. If the free memory quantity of the preset cache pool is smaller than the fifth preset threshold value, adding part of the memory space in the first memory space from the first memory space to the preset cache pool through at least one adding operation of the preset cache pool.
In this way, the electronic device can add the free memory of the preset buffer pool through the first memory space if the free memory of the preset buffer pool is insufficient in the low-load state of physical memory allocation, so that the allocable memory space in the preset buffer pool is kept at a proper memory quantity, and meanwhile, the influence on the first memory space is reduced.
In another possible implementation manner of the first aspect, after at least one addition operation of the preset buffer pool, the electronic device adds a portion of the memory space in the first memory space from the first memory space to the preset buffer pool until an amount of free memory in the preset buffer pool reaches a sixth preset threshold. In each of the at least one adding operation of the preset cache pool, an amount of memory added in the preset cache pool is equal to a second preset memory amount.
In the implementation manner, in the process of filling the preset cache pool, the memory quantity increased by the preset cache pool each time is always equal to the second preset memory quantity. Thus, the preset cache pool can be quantitatively filled each time, so that the occurrence of the condition that the preset cache pool is added with excessive memory space at one time can be reduced.
In another possible implementation manner of the first aspect, if the free memory size of the preset cache pool is greater than the sixth preset threshold, releasing a portion of the memory space in the preset cache pool to the first memory space until the free memory size of the preset cache pool is less than or equal to the sixth preset threshold.
In the implementation manner, under the condition that the free memory amount of the preset cache pool is sufficient, the electronic equipment can actively release part of the memory space of the preset cache pool and release the part of the memory space to the first memory space, so that the phenomenon of memory space waste caused by overlarge free memory amount of the preset cache pool is reduced.
In another possible implementation manner of the first aspect, the electronic device receives a memory reclamation instruction. And responding to the memory reclamation instruction, and acquiring the idle memory quantity of the preset cache pool by the electronic equipment. And if the free memory quantity of the preset cache pool is larger than the sixth preset threshold value, recycling part of the memory space in the preset cache pool to the first memory space until the free memory quantity of the preset cache pool is smaller than or equal to the sixth preset threshold value.
In this implementation manner, the electronic device may further respond to the memory reclamation instruction to reclaim a portion of the memory space exceeding the sixth preset threshold in the preset cache pool to the first memory space, so as to increase the amount of free memory in the first memory space.
In a second aspect, the present application provides an electronic device, comprising: a memory and one or more processors. The memory is coupled to the processor. The physical memory of the memory includes a predetermined cache pool for the binder communication and a first memory space outside the predetermined cache pool. The memory has stored therein computer program code comprising computer instructions which, when executed by the processor, cause the electronic device to perform the steps of: receiving a first binder communication instruction initiated by a first process, wherein the first binder communication instruction is used for indicating communication with a second process; responding to a first binder communication instruction, and acquiring a load state allocated by a physical memory and thread information of a working thread operated by a first process; if the load state is the first state and the working thread operated by the first process is the target thread, memory space required by communication between the first process and the second process is distributed in a preset buffer pool; the load state is a first state, which means that the idle memory quantity of the first memory space is smaller than a first preset threshold value, or the memory allocation delay parameter of the binder communication is larger than a second preset threshold value; the thread information is used to indicate whether the worker thread is a target thread.
In a possible implementation manner of the second aspect, the computer instructions, when executed by the processor, cause the electronic device to further perform the steps of: counting the total time spent by memory allocation in the binder communication of the preset times before the current moment; and averaging the total duration by using the preset times to obtain the memory allocation delay parameter of the binder communication.
In another possible implementation manner of the second aspect, the thread information includes a memory exhaustion parameter and a thread level; the computer instructions, when executed by the processor, cause the electronic device to further perform the steps of: if the memory exhaustion parameter of the working thread is smaller than or equal to a third preset threshold value, or the thread level of the working thread is smaller than or equal to a fourth preset threshold value, the working thread is a target thread; the memory exhaustion parameter is used for indicating the possibility that one thread is forcedly terminated under the condition that the idle memory quantity of the first memory space is smaller than the first preset memory quantity; the thread level is inversely related to the importance of the work thread; if the memory exhaustion parameter of the working thread is greater than the third preset threshold value and the thread level of the working thread is greater than the fourth preset threshold value, the working thread is not the target thread.
In another possible implementation manner of the second aspect, the computer instructions, when executed by the processor, cause the electronic device to further perform the steps of: if the working thread is not the target thread, the memory space required by the communication between the first process and the second process is distributed in the first memory space.
In another possible implementation manner of the second aspect, the computer instructions, when executed by the processor, cause the electronic device to further perform the steps of: and after the communication of the first process and the second process is finished, the memory space allocated for the communication of the first process and the second process is recycled to a preset cache pool.
In another possible implementation manner of the second aspect, the computer instructions, when executed by the processor, cause the electronic device to further perform the steps of: if the load state is the second state, the memory space required by the communication between the first process and the second process is distributed in the first memory space; the load state being the second state indicates that the amount of free memory in the first memory space is greater than or equal to a first preset threshold, and the memory allocation delay parameter is less than or equal to a second preset threshold.
In another possible implementation manner of the second aspect, the computer instructions, when executed by the processor, cause the electronic device to further perform the steps of: under the condition that the load state of physical memory allocation is the second state, acquiring the idle memory quantity of a preset cache pool; the load state is a second state, which means that the idle memory quantity of the first memory space is larger than or equal to a first preset threshold value, and the memory allocation delay parameter is smaller than or equal to a second preset threshold value; if the free memory quantity of the preset cache pool is smaller than the fifth preset threshold value, adding part of the memory space in the first memory space from the first memory space to the preset cache pool through at least one adding operation of the preset cache pool.
In another possible implementation manner of the second aspect, the computer instructions, when executed by the processor, cause the electronic device to further perform the steps of: adding part of the memory space in the first memory space from the first memory space to the preset cache pool through at least one adding operation of the preset cache pool until the free memory quantity of the preset cache pool reaches a sixth preset threshold; wherein, in each adding operation in at least one adding operation of the preset cache pool, the increased memory amount in the preset cache pool is equal to the second preset memory amount.
In another possible implementation manner of the second aspect, the computer instructions, when executed by the processor, cause the electronic device to further perform the steps of: and if the free memory quantity of the preset cache pool is larger than the sixth preset threshold value, releasing part of the memory space in the preset cache pool to the first memory space until the free memory quantity of the preset cache pool is smaller than or equal to the sixth preset threshold value.
In another possible implementation manner of the second aspect, the computer instructions, when executed by the processor, cause the electronic device to further perform the steps of: receiving a memory reclamation instruction; responding to a memory recycling instruction, and acquiring the idle memory quantity of a preset cache pool; and if the free memory quantity of the preset cache pool is larger than the sixth preset threshold value, recycling part of the memory space in the preset cache pool to the first memory space until the free memory quantity of the preset cache pool is smaller than or equal to the sixth preset threshold value.
In a third aspect, the present application provides a computer readable storage medium comprising computer instructions which, when run on an electronic device, cause the electronic device to perform the method of the first aspect and any one of its possible implementations.
In a fourth aspect, the present application provides a computer program product comprising program instructions which, when run on a computer, enable the computer to perform the method of the first aspect and any one of its possible implementations. For example, the computer may be the electronic device described above.
In a fifth aspect, the present application provides a chip system, which is applied to an electronic device. The system-on-chip includes an interface circuit and a processor. The interface circuit and the processor are interconnected by a wire. The interface circuit is for receiving signals from the memory and transmitting signals to the processor, the signals including computer instructions stored in the memory. When the processor executes the computer instructions, the electronic device performs the method of the first aspect and any possible implementation manner thereof.
Drawings
FIG. 1 is a block diagram of an example of a binder communication provided by an embodiment of the present application;
Fig. 2 is a hardware structural block diagram of an electronic device configuration example provided in an embodiment of the present application;
fig. 3 is a software architecture block diagram of an electronic device configuration example provided in an embodiment of the present application;
fig. 4 is a flowchart of an example of a memory allocation method for interprocess communication according to an embodiment of the present application;
fig. 5 is a block diagram of an example of a memory allocation method for interprocess communication according to an embodiment of the present application;
FIG. 6 is a flowchart of another example of a memory allocation method for inter-process communication according to an embodiment of the present application;
FIG. 7 is a schematic diagram of an example of a register driver management default cache pool according to an embodiment of the present application;
fig. 8 is a schematic diagram of an example of a binder driver management preset cache Chi Lingyi according to an embodiment of the present application.
Detailed Description
The embodiment of the application provides a memory allocation method for inter-process communication, which can effectively reduce the memory allocation time delay of the binder communication of electronic equipment in a high-load state and improve the performance of the inter-process communication.
The virtual memory space of an electronic device may be divided into a user space and a kernel space. Wherein the user space is a runtime space of the user program code. The kernel space is the runtime of kernel (kernel) code. In order to improve the security of the processes, the user space addresses of different processes are different, and it is difficult for one process to directly access the user space of other processes. Kernel space is shared by all processes. Thus, data exchange between processes may pass through kernel space.
Binder communication is an inter-process communication mechanism. The communication between processes can be realized by only copying data once in each binder communication, and compared with other traditional communication modes requiring 2 times of data copying, such as pipelines, message queues and the like, the communication between processes has better communication performance.
By taking an example that the electronic device is a mobile phone and an operating system of the mobile phone is an Android system, the principle of the binder communication is introduced.
As shown in fig. 1, the virtual memory space of the mobile phone includes a user space and a kernel space. The core function of the binder communication is located in the kernel space of the mobile phone, and provides an interface for calling upper-layer programs in a binder driving mode.
When the process 1 communicates with the process 2, the binder driver applies a memory space in the physical memory of the mobile phone for storing the communication data between the process 1 and the process 2. The binder driver transfers communication data sent by process 1 to process 2 to the kernel space. For example, the binder driver may call copy_from_user () function to pass the communication data of process 1 from the user space of process 1 into the kernel space. The virtual memory address used for storing communication data in the kernel space has a mapping relation with the memory space applied by the binder driver in the physical memory. The communication data is actually stored in the memory space of the physical memory after being transferred into the kernel space. Meanwhile, the memory space has a mapping relation with the virtual memory address of the user space where the process 2 is located.
Because the virtual memory address of the kernel space where the communication data is located and the virtual memory address of the user space where the process 2 is located are mapped into the same memory space of the physical memory, the virtual memory address is equivalent to the copy of the communication data into the user space of the process 2 by the binder driver. When the process 2 accesses the virtual memory of the user space (actually accesses the memory space in the physical memory mapped by the virtual memory), the communication data sent by the process 1 can be acquired without copying again, so as to realize inter-process communication.
Of course, the process 1 may also return the communication data to the process 1 after receiving the communication data transmitted by the process 2. The process of returning the communication data from the process 2 to the process 1 is equivalent to the reverse process of sending the communication data from the process 1 to the process 2, and will not be described herein.
It can be seen that, in the above-mentioned process 1 and process 2, only one copy of communication data is involved, and the process communication has better inter-process communication performance than other inter-process communication modes requiring 2 copies of communication data.
Binder communications occur very frequently in electronic devices. During each binder communication, the electronic device allocates memory space in the physical memory for storing inter-process communication data. However, when the bandwidth communication requirement of the electronic device is high, the idle memory of the electronic device may be insufficient when the system load is high, which may cause the time delay of the electronic device for allocating the memory space to be increased sharply, thereby blocking the key process running in the electronic device and causing performance problems such as jamming of the electronic device.
In view of this, the embodiment of the application provides a memory allocation method for interprocess communication, which is applied to electronic equipment. The physical memory of the electronic device comprises a preset cache pool for the binder communication and a first memory space outside the preset cache pool.
Taking as an example that a first process in an electronic device initiates a binder communication to a second process in the electronic device. The electronic device may obtain a first binder communication instruction initiated by the first process to the second process. In response to the first binder communication instruction, the electronic device may obtain a load state of physical memory allocation and thread information of a working thread operated by the first process. If the load state is a high load state (which may be denoted as a first state), and the worker thread operated by the first process is a target thread, it indicates that the current physical memory allocation of the electronic device is high in load, and the worker thread in the first process operated by the electronic device is a critical process (e.g., some user threads affecting user experience, etc.) that has a significant impact on the system performance of the electronic device. At this time, the idle memory amount of the electronic device is smaller than a first preset threshold, or the memory allocation delay parameter of the binder communication is larger than a second preset threshold. In this case, the electronic device may allocate a memory space required for communication between the first process and the second process in the preset buffer pool, so as to implement communication between the first process and the second process.
In this way, under the conditions of high load state of physical memory allocation and running key threads, such as a game scene, a shooting scene and the like, the electronic equipment can immediately allocate the memory space required by the binder communication (i.e. the memory space required by the communication between the first process and the second process) through the preset cache pool, so that the time delay of the physical memory allocation of the binder communication under the high load state can be reduced, the possibility that the key process is blocked by the physical memory allocation of the binder communication is reduced, the system blocking condition is improved, the system performance is optimized, and the user experience is provided.
In this embodiment of the present application, the electronic device may first obtain a load state of physical memory allocation in response to the first binder communication instruction. If the load state is the first state, the electronic device further obtains thread information of a working thread operated by the first process. Or, the electronic device may first obtain thread information of a working thread operated by the first process in response to the first binder communication instruction. If the working thread operated by the first process is the target thread, the electronic device further obtains the load state of the physical memory allocation. Of course, in response to the first binder communication instruction, the electronic device may simultaneously obtain the load state of the physical memory allocation and thread information of the working thread operated by the first process. The embodiment of the application does not limit the load state of the physical memory allocation and the sequence of the thread information of the working thread operated by the first process.
By way of example, the electronic device described in embodiments of the present application may be a cell phone, tablet, desktop, laptop, handheld, notebook, ultra-mobile personal computer (UMPC), netbook, and cellular telephone, personal digital assistant (personal digital assistant, PDA), augmented reality (augmented reality, AR) \virtual reality (VR) device, media player, wearable device, etc. The embodiment of the application does not particularly limit the specific form of the electronic device.
In this embodiment, taking the mobile phone 100 as an example, the hardware structure of the electronic device is described by the mobile phone 100. As shown in fig. 2, the mobile phone 100 may include: processor 110, external memory interface 120, internal memory 121, universal serial bus (universal serial bus, USB) interface 130, charge management module 140, power management module 141, battery 142, antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, headset interface 170D, sensor module 180, keys 190, motor 191, indicator 192, camera 193, display 194, and subscriber identity module (subscriber identification module, SIM) card interface 195, etc.
The processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and/or a neural network processor (neural-network processing unit, NPU), a driver processor, and the like. Wherein the different processing units may be separate devices or may be integrated in one or more processors. The processor 110 may be a neural and command center of the cell phone 100. The processor 110 may generate operation control signals according to the instruction operation code and the timing signals to complete instruction fetching and instruction execution control.
A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may hold instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to reuse the instruction or data, it can be called directly from the memory. Repeated accesses are avoided and the latency of the processor 110 is reduced, thereby improving the efficiency of the system.
The external memory interface 120 may be used to connect an external memory card, such as a Micro SD card, to extend the memory capabilities of the handset 100. The external memory card communicates with the processor 110 through an external memory interface 120 to implement data storage functions. For example, files such as music, video, etc. are stored in an external memory card.
The internal memory 121 may be used to store computer executable program code including instructions. The processor 110 executes various functional applications of the cellular phone 100 and data processing by executing instructions stored in the internal memory 121. For example, in an embodiment of the present application, the processor 110 may include a storage program area and a storage data area by executing instructions stored in the internal memory 121, and the internal memory 121 may include a storage program area and a storage data area.
The storage program area may store, among other things, an application program (such as a sound playing function, an image playing function, etc.) required for at least one function of the operating system, a configuration file of the motor 191, etc. The storage data area may store data (e.g., audio data, phonebook, etc.) created during use of the handset 100, etc. In addition, the internal memory 121 may include a high-speed random access memory, and may further include a nonvolatile memory such as at least one magnetic disk storage device, a flash memory device, a universal flash memory (universal flash storage, UFS), and the like.
The charge management module 140 is configured to receive a charge input from a charger. The charger can be a wireless charger or a wired charger. The charging management module 140 may also supply power to the mobile phone 100 through the power management module 141 while charging the battery 142.
The power management module 141 is used for connecting the battery 142, and the charge management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and/or the charge management module 140 and provides power to the processor 110, the internal memory 121, the external memory, the display 194, the camera 193, the wireless communication module 160, and the like. In some embodiments, the power management module 141 and the charge management module 140 may also be provided in the same device.
The wireless communication function of the mobile phone 100 may be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, a modem processor, a baseband processor, and the like. In some embodiments, the antenna 1 and the mobile communication module 150 of the handset 100 are coupled, and the antenna 2 and the wireless communication module 160 are coupled, so that the handset 100 can communicate with a network and other devices through wireless communication technology.
The antennas 1 and 2 are used for transmitting and receiving electromagnetic wave signals. Each antenna in the handset 100 may be used to cover a single or multiple communication bands. Different antennas may also be multiplexed to improve the utilization of the antennas. For example: the antenna 1 may be multiplexed into a diversity antenna of a wireless local area network. In other embodiments, the antenna may be used in conjunction with a tuning switch.
The mobile communication module 150 may provide a solution for wireless communication including 2G/3G/4G/5G, etc. applied to the handset 100. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (low noise amplifier, LNA), etc. The mobile communication module 150 may receive electromagnetic waves from the antenna 1, perform processes such as filtering, amplifying, and the like on the received electromagnetic waves, and transmit the processed electromagnetic waves to the modem processor for demodulation.
The mobile communication module 150 can amplify the signal modulated by the modem processor, and convert the signal into electromagnetic waves through the antenna 1 to radiate. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be disposed in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be provided in the same device as at least some of the modules of the processor 110.
The wireless communication module 160 may provide solutions for wireless communication including wireless local area network (wireless local area networks, WLAN) (e.g., wi-Fi), bluetooth (BT), global navigation satellite system (global navigation satellite system, GNSS), frequency modulation (frequency modulation, FM), near field wireless communication technology (near field communication, NFC), infrared technology (IR), etc. applied to the mobile phone 100.
The wireless communication module 160 may be one or more devices that integrate at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the electromagnetic wave signals, filters the electromagnetic wave signals, and transmits the processed signals to the processor 110. The wireless communication module 160 may also receive a signal to be transmitted from the processor 110, frequency modulate it, amplify it, and convert it to electromagnetic waves for radiation via the antenna 2.
The handset 100 may implement audio functions through an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, an application processor, and the like. Such as music playing, recording, etc.
The sensor module 180 may include sensors such as a pressure sensor, a gyroscope sensor, a barometric pressure sensor, a magnetic sensor, an acceleration sensor, a hall sensor, a touch sensor, an ambient light sensor, and a bone conduction sensor. The cell phone 100 may collect various data through the sensor module 180.
The mobile phone 100 implements display functions through a GPU, a display 194, an application processor, and the like. The GPU is a microprocessor for image processing, and is connected to the display 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
The display screen 194 is used to display images, videos, and the like. The display 194 includes a display panel. The display panel may employ a liquid crystal display (liquid crystal display, LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED) or an active-matrix organic light-emitting diode (matrix organic light emitting diode), a flexible light-emitting diode (flex), a mini, micro led, micro-OLED, a quantum dot light-emitting diode (quantum dot light emitting diodes, QLED), or the like.
The mobile phone 100 may implement photographing functions through an ISP, a camera 193, a video codec, a GPU, a display 194, an application processor, and the like. The ISP is used to process data fed back by the camera 193. The camera 193 is used to capture still images or video. In some embodiments, the cell phone 100 may include 1 or more cameras 193.
The keys 190 include a power-on key, a volume key, etc. The keys 190 may be mechanical keys. Or may be a touch key. The motor 191 may generate a vibration cue. The motor 191 may be used for incoming call vibration alerting as well as for touch vibration feedback. The indicator 192 may be an indicator light, may be used to indicate a state of charge, a change in charge, a message indicating a missed call, a notification, etc.
The SIM card interface 195 is used to connect a SIM card. The SIM card may be inserted into the SIM card interface 195 or removed from the SIM card interface 195 to enable contact and separation with the handset 100. The handset 100 may support 1 or more SIM card interfaces. The SIM card interface 195 may support Nano SIM cards, micro SIM cards, and the like.
It should be understood that the connection relationship between the modules illustrated in this embodiment is only illustrative, and does not limit the structure of the electronic device. In other embodiments, the electronic device may also include more or fewer modules than provided in the foregoing embodiments, and different interfaces or a combination of multiple interfaces may be used between the modules in the foregoing embodiments. The hardware structure of the electronic device provided in the embodiment of the present application may also refer to the hardware structure of the mobile phone 100 as shown in the figure. The methods in the following embodiments may be implemented in an electronic device having the above-described hardware configuration.
The software system of the electronic device may employ a layered architecture, an event driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture. As shown in fig. 3, in the embodiment of the present application, the electronic device is the mobile phone 100, and a software system of the electronic device adopts a layered architecture of an Android system as an example, which illustrates a software structure of the electronic device.
The layered architecture of the handset 100 divides the software into several layers, each with distinct roles and divisions. The layers communicate with each other through a software interface. In some embodiments, the Android system may include an application layer, an application framework layer, an Zhuoyun row (Android run) and system libraries, and a kernel layer.
The application layer may include a series of application packages. For example, the application package may include applications such as cameras, gallery, calendar, talk, map, navigation, WLAN, bluetooth, music, video, short message, etc., without any limitation in the embodiments of the present application.
The application framework layer provides an application programming interface (application programming interface, API) and programming framework for application programs of the application layer. The application framework layer includes a number of predefined functions. For example, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like, which is not limited in any way by the embodiments of the present application.
The android runtime includes a core library and virtual machines. And the android running time is responsible for scheduling and managing an android system. The core library consists of two parts: one part is a function which needs to be called by java language, and the other part is a core library of android. The application layer and the application framework layer run in a virtual machine. The virtual machine executes java files of the application program layer and the application program framework layer as binary files. The virtual machine is used for executing the functions of object life cycle management, stack management, thread management, security and exception management, garbage collection and the like.
The system library may include a plurality of functional modules. For example: surface manager (surface manager), media Libraries (Media Libraries), three-dimensional graphics processing Libraries (e.g., openGL ES), two-dimensional graphics engines (e.g., SGL), etc.
The kernel layer is a layer between hardware and software. The kernel layer includes drivers and system services. The driver includes at least a display driver, an audio driver, a sensor driver, a binder driver, and the like.
Here, the user space of the mobile phone 100 may include the above-mentioned application layer, application framework layer, an Zhuoyun line and system library. The kernel space of the handset 100 includes a kernel layer. The first process and the second process may be two different processes in user space that may be in a binder communication. For example, the first process is a gallery application in the application layer and the second process is a system services process in the application architecture layer. In the case where the gallery application exposes images in response to user operations, the gallery application may call a window manager in the system service process to display images in a window of the gallery application. Binder communication may be employed between the gallery application and the system service process.
In the following implementation manner, the method provided in the embodiment of the present application is described by taking the example that the electronic device is a mobile phone. As shown in fig. 4, the method provided in the embodiment of the present application may include the following steps:
S401, configuring a preset cache pool for the binder communication by the mobile phone.
The handset may set a preset buffer pool for the binder communication in the physical memory. The preset buffer pool can be specially used for memory allocation in the binder communication. The mobile phone can divide a part of memory space in the physical memory as a preset cache pool. For example, as shown in fig. 5, the binder driver of the mobile phone may apply for a virtual memory corresponding to a preset cache pool in the kernel space, where the virtual memory of the preset cache pool corresponds to the preset cache pool in the physical memory of the mobile phone.
After the preset cache pool is configured, the physical memory of the mobile phone may include the preset cache pool for the binder communication and a first memory space outside the preset cache pool. The first memory space may be a general memory space, which may be used for memory allocation for binder communication, or for memory allocation for other requirements. Of course, the physical memory of the mobile phone may include other memory spaces for kernel operation and special purposes in addition to the preset buffer pool and the first memory space, which is not limited in the embodiment of the present application.
The memory amount of the preset cache pool (for example, as a binder_pool_count) can be set according to actual requirements or application scenes. For example, the amount of memory in the preset cache pool may be set to be smaller than the amount of the first memory space, so that the influence of the preset cache pool on other memory allocation requirements may be reduced. The amount of memory in the default buffer pool may be set to 1 gigabyte, for example.
For another example, the amount of memory in the default cache pool may be dynamically adjusted. If the memory quantity of the preset cache pool is larger, the mobile phone can shrink the preset cache pool. If the memory amount of the preset cache pool is smaller, the mobile phone can increase the memory amount of the preset cache pool.
The memory amount of the preset cache pool refers to the size of the space of the free memory in the preset cache pool, namely the size of the unallocated memory. The amount of memory in the preset cache pool may also be referred to as the free memory amount.
In order to facilitate management of the preset cache pool, in some implementations, the mobile phone may further set a reference value for the preset cache pool, where the reference value is used to measure the amount of free memory in the preset cache pool. For example, the handset may set a fifth preset threshold and a sixth preset threshold. The fifth preset threshold is smaller than the sixth preset threshold. The fifth preset threshold and the sixth preset threshold may be used to measure the amount of free memory in the preset cache pool.
The fifth predetermined threshold may be a low water line (e.g., designated binder_pool_min_watermark) of the predetermined cache pool. If the free memory quantity of the preset cache pool is smaller than the fifth preset threshold value, the free memory quantity of the preset cache pool is smaller. The sixth predetermined threshold may be a high water line (e.g., designated binder_pool_high_watermark) of the predetermined cache pool. And if the free memory quantity of the preset cache pool is larger than a sixth preset threshold value, indicating that the free memory of the preset cache pool is sufficient. If the free memory quantity of the preset cache pool is between the fifth preset threshold value and the sixth preset threshold value, the free memory of the preset cache pool is moderate.
The fifth preset threshold and the sixth preset threshold may be set according to actual application scenarios or requirements. For example, the fifth preset threshold may be 250 megabytes. The sixth preset threshold may be 750 megabytes.
S402, a binder driver of the mobile phone receives a first binder communication instruction initiated by a first process, wherein the first binder communication instruction is used for indicating communication with a second process.
The mobile phone is provided with a first process. The first process of the handset may initiate a first binder communication instruction by which to request communication with the second process. For example, the first process may be an application process. As shown in fig. 5, the first process may be any one of application processes of application 1, application 2, and application 3. The second process may be a different process in the handset than the first process.
The first process and the second process are difficult to directly communicate in the user space, and the first process can realize communication with the second process through a binder driver in the kernel space of the mobile phone. For example, in S601 of fig. 6, the first process of the handset initiates a first binder communication instruction to the binder driver. For another example, the binder driver of the mobile phone includes a memory allocation module. As shown in fig. 5, taking the example that the first process is application 1, application 1 may communicate with a memory allocation module driven by a binder, and send a first binder communication instruction to the memory allocation module.
S403, responding to the first binder communication instruction, and acquiring the load state of physical memory allocation by the mobile phone.
The load state of physical memory allocation may represent a requirement condition of physical memory allocation in the mobile phone, and may indicate that the mobile phone is currently in a high load state or a low load state of physical memory allocation. The load state of the physical memory allocation of the mobile phone can be a first state or a second state. The first state corresponds to a high load state and the second state corresponds to a low load state.
When the mobile phone is in a high load state of physical memory allocation, the allocable memory space (also called idle memory) in the first memory space of the physical memory of the mobile phone is insufficient. If memory space is allocated from the first memory space for the binder communication, latency of memory allocation in the binder communication may be increased. When the mobile phone is in a low-load state of physical memory allocation, the memory space which can be allocated in the first memory space of the physical memory of the mobile phone is sufficient. If the memory space for the binder communication is allocated from the first memory space, the delay of memory allocation in the binder communication is smaller.
The mobile phone responds to the first binder communication instruction and can acquire the load state of physical memory allocation. For example, in S602 shown in fig. 6, the binder driver of the mobile phone responds to the first binder communication instruction to obtain the load status of the physical memory allocation, and determines the load condition of the current physical memory allocation according to the load status of the physical memory allocation. As another example, as shown in FIG. 5, the binder driver may also include a load status identification module. The load status identification module may identify a load status of the physical memory allocation. The binder-driven memory allocation module may obtain the load status of the physical memory allocation by the load status identification module.
In some implementations, the load status may be represented by an information flag. For example, a first information flag (e.g., denoted as is_binder_alloc_highload) may be used to indicate the load status of physical memory allocation in the handset. The first information flag may be a first flag (e.g., true) or a second flag (e.g., false). The first information mark is a first mark, which can indicate that the load capacity allocated to the physical memory in the mobile phone is large, and the mobile phone is in a high load state (i.e. a first state) allocated to the physical memory. The first information mark is a second mark, which can indicate that the load capacity allocated to the physical memory in the mobile phone is smaller, and the mobile phone is in a low-load state (i.e. a second state) allocated to the physical memory.
To accurately represent the demand request for physical memory allocation by the load state, in some implementations, the handset may determine the load state by at least one of an amount of free memory in the first memory space (e.g., denoted as mem_free) and a memory allocation latency parameter for the binder communication (e.g., denoted as binder_alloc_delay_avg). The memory allocation delay parameter of the binder communication can reflect the time delay condition of the mobile phone on the memory allocation of the binder communication. The mobile phone can acquire the idle memory quantity of the first memory space and the memory allocation delay parameter of the binder communication through an interface provided by the kernel.
It will be appreciated that determining the load status by the handset via the amount of free memory in the first memory space and the memory allocation delay parameter of the binder communication may be performed prior to S402. For example, the handset may periodically (e.g., 5 ms, 10 ms, etc.) obtain at least one of an amount of free memory in the first memory space and a memory allocation delay parameter for the binder communication. The mobile phone further determines the load state according to at least one of the idle memory quantity of the first memory space and the memory allocation delay parameter of the binder communication. Alternatively, after S402, the mobile phone may obtain at least one of an amount of free memory in the first memory space and a memory allocation delay parameter of the binder communication in response to the first binder communication instruction. The mobile phone further determines the load state according to at least one of the idle memory quantity of the first memory space and the memory allocation delay parameter of the binder communication.
The manner in which the handset determines the load status is described below by way of some examples.
In one example of this implementation, the handset may determine a load state of the binder communication based on the amount of free memory in the first memory space. If the free memory size of the first memory space is less than the first predetermined threshold, it may be considered that the memory space allocable in the first memory space is insufficient. At this time, the load capacity of the physical memory allocation is large, and the mobile phone is in a high load state of the physical memory allocation. In this case, the handset may determine the load status of the binder communication as the first status. If the free memory size of the first memory space is greater than or equal to the first predetermined threshold, it may be considered that the memory space available for allocation in the first memory space is sufficient. At this time, the load amount of the physical memory allocation of the mobile phone is small, and the mobile phone is in a low load state of the physical memory allocation. In this case, the handset may determine the load status of the binder communication as the second status.
Here, the first preset threshold may be set according to an actual application scenario or a requirement. For example, the first preset threshold may be a low water line of the first memory space. The first preset threshold may be set to one fourth of the total number of first memory spaces. As another example, the first preset threshold may be set to a value of 750 megabytes, 1 gigabyte, or the like.
In another example of this implementation, the handset may determine the load status of the binder communication based on the memory allocation latency parameters of the binder communication. If the memory allocation delay parameter of the binder communication is greater than the second preset threshold, the mobile phone can be considered to have larger time delay for memory allocation in the process of executing the binder communication. At this time, the load capacity of the physical memory allocation is large, and the mobile phone is in a high load state of the physical memory allocation. In this case, the handset may determine the load status of the binder communication as the first status. If the memory allocation delay parameter of the binder communication is smaller than or equal to the second preset threshold, the time delay of the memory allocation in the process of executing the binder communication by the mobile phone can be considered to be smaller. At this time, the load amount of the physical memory allocation is small, and the mobile phone is in a low load state of the physical memory allocation. In this case, the handset may determine the load status of the binder communication as the second status.
Here, the second preset threshold may be set according to an actual application scenario or requirement. For example, the second preset threshold may be set to a value of 10 milliseconds, 15 milliseconds, or the like.
In another example of this implementation, the handset may determine the load state of the binder communication based on the amount of free memory in the first memory space and the memory allocation delay parameter of the binder communication. If the idle memory quantity of the first memory space is smaller than a first preset threshold value, or the memory allocation delay parameter of the binder communication is larger than a second preset threshold value, the load quantity of the physical memory allocation in the mobile phone is larger, and the mobile phone is in a high-load state of the physical memory allocation. In this case, the handset may determine the load status of the binder communication as the first status. If the idle memory amount of the first memory space is greater than or equal to a first preset threshold value, and the memory allocation delay parameter of the binder communication is smaller than or equal to a second preset threshold value, the load amount of physical memory allocation in the mobile phone is smaller, and the mobile phone is in a low-load state of the physical memory allocation. In this case, the handset may determine the load status of the binder communication as the second status.
Here, the mobile phone may allocate a certain memory space for each binder communication in each binder communication, and the memory allocation delay parameter of the binder communication may represent a time delay for allocating the memory in the mobile phone executing the binder communication. For example, the mobile phone may set a timer for memory allocation in each binder communication, and count the duration consumed by the memory allocation in each binder communication through the timer. The mobile phone can determine the memory allocation delay parameter of the binder communication according to the time length consumed by the memory allocation in the binder communication counted by the timer. Some ways of determining the memory allocation delay parameters are provided below.
In some implementations, the mobile phone may use the time period spent for the memory allocation of the last binder communication counted before the current time as the memory allocation delay parameter of the binder communication.
In other implementations, the mobile phone may use the total duration spent by at least one time of memory allocation of the binder communication counted in a preset time period before the current time as a memory allocation delay parameter of the binder communication. For example, the preset time period is 1 minute, and the handset has occurred 5 binder communications within 1 minute before the current time. The mobile phone can count the total time spent by memory allocation of 5 binder communications occurring within 1 minute before the current moment, and takes the total time as a memory allocation delay parameter of the binder communications.
Or, in order to embody the overall situation that the memory allocation of the binder communication is time-consuming in the preset time period, the mobile phone can also calculate the average time length consumed by the memory allocation in each binder communication in the preset time period. Specifically, the mobile phone may calculate a total duration consumed by at least one time of memory allocation of the binder communication counted in the preset time period, and a ratio between the times of the binder communication in the preset time period, so as to obtain an average duration consumed by the memory allocation of the binder communication in the preset time period. For example, the preset time period is 1 minute, and the handset has occurred 5 binder communications within 1 minute before the current time. The mobile phone can calculate the average time length consumed by each binder communication in the memory allocation of 5 binder communications within 1 minute, and takes the average time length as the memory allocation delay parameter of the binder communication.
In other implementations, the mobile phone may use a total duration consumed by memory allocation of the binder communication for a preset number of times before the current time as a memory allocation delay parameter of the binder communication. For example, the preset number of times is 10 times. The mobile phone can count the total time spent on memory allocation in 10 times of binder communication before the current moment, and takes the total time as a memory allocation delay parameter of binder communication.
Or, in order to embody the overall situation that the memory allocation in the binder communication of the preset times is time-consuming, the mobile phone can also calculate the average time spent in the memory allocation in each binder communication of the preset times. Specifically, the mobile phone calculates the ratio of the total time spent by memory allocation of the Binder communication of the preset times before the current moment to the preset times, and obtains the average time spent by the Binder communication of the preset times on the memory allocation. The mobile phone takes the average duration as a memory allocation delay parameter of the binder communication. For example, the preset number of times is 10 times. The handset may count the total time spent on memory allocation in 10 binder communications that occur before the current time. The mobile phone can average the total duration by using the preset times, and calculates the average duration consumed by each binder communication in the 10 times of binder communication on memory allocation.
S404, the mobile phone judges whether the load state of the physical memory allocation is the first state.
The handset may determine whether the current binder communication is in a high load state. For example, the driver of the mobile phone may determine whether the load state is the first state through the first information flag of the driver communication. If the first information flag is a first flag, such as "TRUE", the handset can confirm that the current binder communication is in a high load state (i.e., the first state). If the first information flag is a second flag, such as "FALSE", the handset may confirm that the current binder communication is in a low load state (i.e., second state).
If the load status of the physical memory allocation is the first status, the handset executes S405.
If the load status of the physical memory allocation is the second status, the handset performs S408.
S405, the mobile phone acquires thread information of a working thread operated by the first process.
If the mobile phone is in a high-load state of the binder communication, the mobile phone can acquire the thread information of the working thread currently operated by the first process. For example, as shown in S603 of fig. 6, if the mobile phone is in a high load state of the binder communication, the binder driver of the mobile phone obtains the thread information of the working thread operated by the first process. The thread information may be used to indicate whether a thread is a target thread. The target thread may be a critical thread that has a significant impact on the system performance of the handset. For example, the target thread may be a user interface thread, an application launch thread, or the like.
As another example, as shown in FIG. 5, the handset's binder driver may also include a thread identification module. The thread identifying module may be configured to identify a working thread currently operated by the first process, and indicate, through thread information, whether the working thread is a target thread. The binder-driven memory allocation module may obtain the thread information from the thread identification module.
In some implementations, the thread information can be threads ID (Identity Document) of the worker thread. The binder driver of the mobile phone can acquire the thread ID of the working thread currently operated by the first process. Further, the mobile phone may match the thread ID of the currently running working thread in the first process with a preset thread ID. The preset thread ID corresponds to the target thread. If the thread ID of the worker thread matches the preset thread ID, the worker process may be considered the target thread. If the thread ID of the worker thread does not match the preset thread ID, then the worker process may be deemed not to be the target thread.
To more accurately identify the target thread, in some implementations, the thread information may include at least one of a memory exhaustion parameter and a thread level. The mobile phone can judge whether the working thread currently operated by the first process is a target thread or not through at least one parameter in the memory exhaustion parameter and the thread level.
Memory exhaustion parameters can be configured for each process or thread in the kernel of the mobile phone. The Memory exhaustion parameter may represent a likelihood that a process or thread is forcibly terminated in the case Of Memory exhaustion (OOM) (e.g., the amount Of free Memory in the first Memory space is less than the first predetermined Memory amount). The first preset amount of memory may be set according to the actual scenario or requirement. For example, the first predetermined amount of memory may be less than or equal to a low water line of the first memory space.
If the available memory space in the handset is insufficient, memory exhaustion may occur. In this case, in order to make the system of the mobile phone operate normally, the mobile phone may forcibly terminate some processes or threads currently operating to release the memory space. The memory exhaustion parameter can be used as the basis of the process or thread of the mobile phone forced termination when the memory is exhausted. The greater the memory exhaustion parameter of a process or thread, the less important the process or thread is, and the greater the likelihood that the process or thread will be forced to terminate. The smaller the memory exhaustion parameter of a process or thread, the greater the importance of the process or thread, and the less likely the process or thread is forced to terminate.
It can be seen that the memory exhaustion parameter may reflect the importance of a process or thread. The memory exhaustion parameter is inversely related to the importance of a process or thread. The smaller the memory exhaustion parameter, the higher the importance of a process or thread. The handset may determine whether the worker thread is a target thread using the memory exhaustion parameter.
For example, the mobile phone may obtain, through a first kernel interface (such as oom _score_adj), a memory exhaustion parameter of a working thread currently running by the first process. If the memory exhaustion parameter of the working thread is smaller than or equal to the third preset threshold value, the importance of the working thread is considered to be higher, and the working thread is a target thread. In this case, the handset may set the thread information of the working thread to a third flag, for example, set to true, to indicate that the working thread is the target thread. If the memory exhaustion parameter of the working thread is greater than the third preset threshold, the importance of the working thread is considered to be lower, and the working thread is not the target thread. In this case, the handset may set the thread information of the working thread to a fourth flag, for example, to false, which indicates that the working thread is not the target thread.
Here, the third preset threshold may be set according to an actual application scenario or requirement. For example, the memory exhaustion parameter can be an integer ranging from-1000 to 1000. The third preset threshold may be set to 0.
The thread class may indicate the likelihood that the handset will schedule one thread in priority. Thread class is inversely proportional to priority scheduling order. For example, if multiple threads in a handset contend for processing resources in the handset at the same time, the handset may prioritize the thread with the smallest thread class. The handset may configure a corresponding thread class for each thread running. The greater the thread level of a thread, the less important the thread is, and the less likely the thread is to be preferentially scheduled. The smaller the thread level of a thread, the greater the importance of that thread, and the greater the likelihood that the thread will be preferentially scheduled.
It can be seen that thread level may also characterize the importance of a thread. The thread level is inversely related to the importance of a thread. The smaller the thread level of a thread, the higher the importance of that thread. The handset may use the thread level to determine whether the worker thread is a target thread.
For example, the handset may obtain, through a second kernel interface (such as task_prio), a thread level of a working thread currently running by the first process. If the thread level of the worker thread is less than or equal to the fourth preset threshold, the importance of the worker thread may be considered to be high, and the worker thread is the target thread. In this case, the handset may set the thread information of the working thread to a third flag, for example, set to true, to indicate that the working thread is the target thread. If the thread level of the worker thread is greater than the fourth predetermined threshold, the importance of the worker thread may be considered to be low, and the worker thread is not the target thread. In this case, the handset may set the thread information of the working thread to a fourth flag, for example, to false, which indicates that the working thread is not the target thread.
Here, the fourth preset threshold may be set according to an actual application scenario or requirement. For example, the range of thread levels is an integer from 0 to 144. The fourth preset threshold may be set to 100.
In some implementations, the mobile phone may also determine whether the worker thread is a target thread using the memory exhaustion parameter and the priority level of the worker thread.
For example, the mobile phone may obtain, through the first kernel interface, a memory exhaustion parameter of a working thread currently operated by the first process. The mobile phone can acquire the priority level of the working thread through the second kernel interface. If the memory exhaustion parameter of the working thread is smaller than or equal to the third preset threshold value, or the priority level of the working thread is smaller than or equal to the fourth preset threshold value, the importance of the working thread is considered to be higher, and the working thread is a target thread. In this case, the handset may set the thread information of the working thread to a third flag, for example, to true, to indicate that the working thread is the target thread. If the memory exhaustion parameter of the working thread is greater than the third preset threshold value and the priority level of the working thread is greater than the fourth preset threshold value, the importance level of the working thread is considered to be low, and the working thread is not the target thread. In this case, the handset may set the thread information of the working thread to a fourth flag, for example, to false, which indicates that the working thread is not the target thread.
S406, the mobile phone judges whether the thread information of the working thread indicates a target thread.
If the working thread operated by the first process is the target thread, the working thread operated by the first process can be considered as a key thread which has significant influence on the system performance of the mobile phone. Under the condition that the mobile phone is in a high-load state of physical memory allocation, the allocable memory space in the first memory space may be insufficient, the memory allocation of the binder communication may block a working thread operated by the first process, system performance of the mobile phone may be affected, a mobile phone blocking phenomenon occurs, and user experience is affected. In this case, the handset may perform S407.
If the working thread operated by the first process is not the target thread, the working thread operated by the first process can be considered to have less influence on the system performance of the mobile phone. Under the condition that the mobile phone is in a high-load state of physical memory allocation, even though the memory allocation of the binder communication may block a working thread operated by the first process, the blocking of the working thread is difficult to cause the perception of a user, and the influence on user experience is small. In this case, the handset may perform S408.
S407, the mobile phone allocates the memory space required by the communication between the first process and the second process in the preset cache pool.
The preset buffer pool is a memory space configured by the mobile phone for the memory allocation of the binder communication, and can be managed by the binder driver. In order to reduce the situation that the key thread is blocked due to insufficient memory space available in the mobile phone, the mobile phone may divide the memory space used for the memory allocation of the binder communication in the physical memory in advance, where the memory space is a preset buffer pool. After the physical memory of the mobile phone is divided into the preset cache pool, the physical memory may include the preset cache pool and a first memory space outside the preset cache pool. The first memory space may be a general memory space in the mobile phone.
Of course, in addition to the preset cache pool and the first memory space, the physical memory of the mobile phone may further include other memory spaces for other purposes, which is not limited in the embodiment of the present application.
In the case where the mobile phone is in a high load state of physical memory allocation and the first process runs a target thread, the allocatable memory space in the first memory space may be insufficient. If the memory space required by the binder communication between the first process and the second process is provided through the universal first memory space, the memory space needs to be released by other processes or the memory space needs to be recovered by the mobile phone, the memory allocation delay of the binder communication can be increased, and the target thread operated by the first process can be blocked. Therefore, in the high load state of physical memory allocation, if the mobile phone recognizes that the first process runs the target thread, the memory space required by the communication between the first process and the second process can be immediately allocated for the present binder communication in the preset buffer pool, and the binder communication between the first process and the second process is realized by storing the communication data between the first process and the second process in the memory space.
For example, as shown in S604 of fig. 6, if the working thread operated by the first process is the target thread, the binder driver allocates the memory space required for the present binder communication in the preset buffer pool. For another example, as shown in fig. 5, the memory allocation module in the binder driver may allocate, in a preset buffer pool, a memory space required for the first process and the second process to communicate for storing communication data, by a virtual memory of the preset buffer pool.
In this way, under the condition that the mobile phone is in a high load state of physical memory allocation and runs a key thread, the mobile phone can immediately allocate a memory space required by the binder communication (i.e. a memory space required by the first process and the second process communication) through the preset cache pool, so that the time delay of the memory allocation of the binder communication in the high load state can be reduced, the possibility that the key process is blocked by the memory allocation of the binder communication is reduced, the system blocking condition is improved, the system performance is optimized, and the user experience is provided.
S408, the mobile phone allocates the memory space required by the communication between the first process and the second process in the first memory space.
The first memory space may be a general memory space managed by the memory management system. The memory management system is a management mechanism in the kernel of the mobile phone for managing the memory space in the physical memory, for example, the memory management system may be a partner system. The handset's binder driver may request the memory management system for the memory space required for the first process's binder communication with the second process. And the memory management system of the mobile phone responds to the request of the binder drive, and allocates a memory space for storing communication data of the first process and the second process in the first memory space so as to realize binder communication of the first process and the second process. For example, as shown in fig. 5, the kernel space of the mobile phone further includes a memory management system. The binder driven memory allocation module may communicate with the memory management system, requesting memory space from the memory management system for the current binder communication.
If the mobile phone executes the step after executing S404, that is, if the mobile phone is currently in the low load state of physical memory allocation, the mobile phone allocates the memory space required by the first process and the second process in the first memory space. For example, as shown in fig. 6, in S607, if the mobile phone is currently in the low load state of physical memory allocation, the binder driver of the mobile phone requests the memory management system for the memory space required for the present binder communication. In S608, the memory management system of the mobile phone responds to the request of the binder driver to allocate the memory space required for the present binder communication in the first memory space.
Because the mobile phone is in a low-load state of physical memory allocation, the memory space which can be allocated in the first memory space is sufficient (if the free memory quantity of the first memory space is larger than or equal to a first preset threshold value), and the memory allocation delay of the binder communication is smaller (if the memory allocation delay parameter of the binder communication is smaller than or equal to a second preset threshold value). The mobile phone provides the memory space required by the binder communication through the first memory space, so that the time delay is smaller, and the influence on the system performance of the mobile phone is small.
If the mobile phone executes S406, the step is executed again, that is, if the first process of the mobile phone does not run the target thread, the mobile phone allocates the memory space required by the first process and the second process in the first memory space. For example, as shown in fig. 6, in S605, if the work thread operated by the first process is not the target thread, the binder driver requests the memory management system for the memory space required for the present binder communication. In S606, the memory management system allocates a memory space required for the present binder communication in the first memory space in response to the binder driver request.
In this case, even if the mobile phone is in a high load state of physical memory allocation, the allocatable memory space in the first memory space may be insufficient. However, since the first process does not run the target thread, even if the memory allocation of the current binder communication may block the working thread operated by the first process, the influence on the system performance of the mobile phone is small, and the user cannot perceive the influence. In this case, the mobile phone allocates a memory space required by the first process and the second process in the first memory space, so as to implement the binder communication between the first process and the second process.
S409, after the communication between the first process and the second process is finished, the mobile phone releases the memory space allocated for the communication between the first process and the second process to a preset cache pool.
After the communication between the first process and the second process is finished, the mobile phone can recycle the memory space used by the current binder communication to a preset cache pool. For example, as shown in fig. 6, in S609, the second process sends a second binder communication instruction to the binder driver, and notifies the binder driver of the end of the present binder communication by the second communication instruction. The second binder communication instruction is configured to trigger the binder driver to release the memory space allocated for communication between the first process and the second process. In S610, in response to the second binder communication instruction, the binder driver releases the memory space allocated for communication between the first process and the second process to the predetermined buffer pool.
It will be appreciated that the memory space for storing the communication data between the first process and the second process may be allocated in the preset buffer pool or may be allocated in the first memory space. After the communication between the first process and the second process is finished, whether the memory space allocated for the communication between the first process and the second process is from the preset cache pool or from the first memory space, the binder driver of the mobile phone can release the memory space to the preset cache pool.
In this way, the mobile phone can fill the preset buffer pool preferentially, so that the allocatable memory space exists in the preset buffer pool, and therefore, the mobile phone can immediately allocate the memory space for the binder communication through the preset buffer pool under the condition that the mobile phone is in a high-load state of physical memory allocation and a target thread is operated.
In the above implementation manner, after the communication between the first process and the second process ends, the mobile phone may release the memory space allocated for the communication between the first process and the second process to the preset buffer pool. In other implementations, the mobile phone may further release the memory space allocated for the communication between the first process and the second process to the preset cache pool under the condition that the communication between the first process and the second process is interrupted. The embodiment of the application does not limit the time for releasing the memory space allocated for the communication of the first process and the second process.
In this embodiment, a preset buffer pool for binder communication is configured in a physical memory of the mobile phone. Under the condition that the mobile phone is in a high load state of physical memory allocation and a target thread is operated in the present binder communication, the mobile phone can provide a memory space required by the present binder communication through a preset buffer pool, so that the time delay of the binder communication is reduced.
In order to effectively manage the preset cache pool, the memory space which can be allocated in the preset cache pool is kept at a proper memory quantity, and in some implementations, the mobile phone can also fill the preset cache pool to increase the idle memory quantity of the preset cache pool. As shown in fig. 7, the method provided in the embodiment of the present application further includes the following steps:
s701, a binder driver of the mobile phone acquires a load state of a physical memory.
The binder driver of the mobile phone can periodically acquire the load state of the physical memory. For example, the binder driver of the handset may acquire the load status of the physical memory allocation every 1 second.
Or, the binder driver of the mobile phone may obtain the load state of physical memory allocation after receiving the first binder communication instruction initiated by a process. For example, in S403, the binder driver of the mobile phone responds to the first binder communication instruction initiated by the first process to obtain the load state of the physical memory allocation.
S702, if the load state of the physical memory allocation is the second state, the binder driver of the mobile phone acquires the free memory amount of the preset cache pool.
And if the load state of the physical memory allocation is the second state, the current mobile phone is in a low load state of the physical memory allocation. For example, when the mobile phone is in a low-load state of physical memory allocation, the idle memory amount of the first memory space is greater than or equal to a first preset threshold, and the memory allocation delay parameter is less than or equal to a second preset threshold. In this case, the binder driver of the mobile phone may obtain the free memory size of the preset cache pool. As shown in fig. 5, the mobile phone binder-driven memory allocation module may obtain the free memory amount of the preset buffer pool. The free memory size of the preset buffer pool is understood to be the size of the memory space that can be allocated in the preset buffer pool.
S703, if the free memory size of the preset cache pool is smaller than the fifth preset threshold, the binder driver requests to add the preset cache pool to the memory management system.
After the binder driver obtains the free memory amount of the preset cache pool, it can be judged whether the current free memory amount of the preset cache pool is smaller than a fifth preset threshold. The fifth preset threshold may be a low water line of a preset cache pool.
If the free memory size of the preset cache pool is smaller than the fifth preset threshold, the fact that the available memory space in the current preset cache pool is insufficient can be indicated. In this case, the binder driver of the mobile phone may request the memory management system to add the preset cache pool, i.e. request to increase the free memory amount of the preset cache pool.
If the free memory size of the preset cache pool is greater than or equal to the fifth preset threshold, the available memory space in the current preset cache pool may be indicated to be appropriate or sufficient. In this case, the mobile phone may not perform the adding operation of the preset buffer pool. The adding operation of the preset buffer pool may be understood as increasing the free memory amount of the preset buffer pool, or may be also referred to as a filling operation.
For example, as shown in fig. 5, the memory allocation module of the mobile phone may determine whether the current free memory size of the preset cache pool is less than a fifth preset threshold. If the free memory amount of the preset cache pool is smaller than the fifth preset threshold, the binder-driven memory allocation module requests the memory management system to increase the free memory amount of the preset cache pool. If the free memory size of the preset cache pool is greater than or equal to the fifth preset threshold, the binder-driven memory allocation module does not request to increase the free memory size of the preset cache pool.
S704, the memory management system of the mobile phone responds to the request for adding the preset cache pool, and adds part of the memory space of the first memory space to the preset cache pool.
And the memory management system of the mobile phone receives a request for adding a preset cache pool sent by a binder driver. In response to a request for adding a preset cache pool, the memory management system of the mobile phone divides a part of memory space in the first memory space and adds the divided part of memory space into the preset cache pool so as to fill the preset cache pool. Through the adding operation of the preset cache pool, the memory space which can be allocated exists in the preset cache pool and can be used for providing the memory space required by the binder communication.
For example, as shown in fig. 5, the mobile phone binder driven memory allocation module may communicate with a memory management system, and request to the memory management system to add a preset cache pool. The memory management system responds to the request and communicates with the pre-stored cache pool, and adds part of the memory space of the first memory space from the first memory space to the pre-stored cache pool.
In the implementation manner, the mobile phone can add part of the memory space of the first memory space to the preset cache pool under the condition of low load of physical memory allocation, so that the allocable memory space in the preset cache pool can be kept in a proper memory amount, and the influence of the addition of the preset cache pool on the first memory space can be reduced.
In order to keep the allocable memory space in the preset buffer pool in a proper free memory amount, in some implementations, the memory management system of the mobile phone may fill a part of the memory space in the first memory space into the preset buffer pool through at least one addition operation of the preset buffer pool. The memory management system of the mobile phone can increase a fixed amount of memory space in the preset cache pool in each adding operation of the preset cache pool.
For example, the memory management system of the mobile phone responds to a request for adding a preset cache pool sent by the binder driver to execute an adding operation once, and fills part of the memory space of the second preset memory quantity in the first memory space into the preset cache pool. After one-time adding operation, the memory management system of the mobile phone does not continuously fill the memory space into the preset cache pool.
For another example, the memory management system of the mobile phone responds to a request for adding the preset cache pool sent by the binder driver, and executes multiple adding operations until the free memory quantity of the preset cache pool reaches a sixth preset threshold value, and stops filling the preset cache pool. In each filling operation, the memory management system of the mobile phone fills the memory space with the second preset memory quantity in the first memory space into the preset cache pool. The sixth preset threshold is a high water line of the preset cache pool. Through multiple filling operations, the available memory space in the preset cache pool is changed from insufficient to sufficient.
The second preset memory amount can be set according to actual application scenes or requirements. For example, the second predetermined amount of memory may be set to a value of 20 megabytes, 50 megabytes, or the like.
In the implementation manner, in the process of filling the preset cache pool, the memory quantity increased by the preset cache pool each time is always equal to the second preset memory quantity. Thus, the preset cache pool can be quantitatively filled each time, so that the occurrence of the condition that the preset cache pool is added with excessive memory space at one time can be reduced.
The first memory space is a general memory space. In addition to providing the memory space required for the binder communication, the first memory space also provides the memory space required for other needs (e.g., other inter-process communication modes, file caching, etc.). In order to make the preset buffer pool occupy the memory originally belonging to the first memory space excessively, the influence of the preset buffer pool on the first memory space is reduced, and in some implementations, if the free memory quantity of the preset buffer pool is greater than a certain memory quantity, the mobile phone can actively release the memory space of the preset buffer pool into the first memory space. Specifically, as shown in fig. 7, the method provided in the embodiment of the present application may further include the following steps:
And S705, if the free memory quantity of the preset cache pool is larger than a sixth preset threshold, releasing part of the memory space of the preset cache pool to the first memory space managed by the memory management system by the binder driver of the mobile phone until the free memory quantity of the preset cache pool is smaller than or equal to the sixth preset threshold.
The sixth preset threshold may be a high water line of the preset cache pool. If the free memory amount of the preset cache is greater than the sixth preset threshold, the free memory of the preset cache pool may be indicated to be greater. Since the predetermined buffer pool is a memory space dedicated for the binder communication, the memory allocation is less required than the first memory space. In order to reduce the waste of memory space caused by excessive free memory in the preset cache pool, when the free memory in the preset cache pool is greater than a sixth preset threshold, the binder driver of the mobile phone can actively release a part of memory space exceeding the sixth preset threshold in the preset cache pool, and add the part of memory space to the first memory space managed by the memory management system from the preset cache pool. The memory amount of the memory space is equal to the difference between the memory amount of the preset cache pool and a sixth preset threshold.
For example, as shown in fig. 5, the binder-driven memory allocation module communicates with the virtual memory of the preset cache pool, and releases a portion of the memory space in the preset cache pool to the first memory space managed by the memory management module.
Here, the binder driver may release, through a release operation, a portion of the memory space exceeding the sixth preset threshold in the preset cache pool to the first memory space. Or, the binder driver may release a certain amount of memory space in the preset buffer pool into the first memory space each time through multiple release operations until the free memory amount in the preset buffer pool is less than or equal to the sixth preset threshold.
In this implementation manner, the mobile phone may actively release a portion of the memory space in the preset buffer pool and release the portion of the memory space to the first memory space when the free memory amount in the preset buffer pool is greater than the sixth preset threshold, so as to reduce the phenomenon that the memory space is wasted due to the excessive free memory amount in the preset buffer pool.
In other implementations, the mobile phone may further respond to the memory reclamation instruction to reclaim a portion of the memory space in the preset buffer pool exceeding the sixth preset threshold to the first memory space, so as to increase the amount of free memory in the first memory space. As shown in fig. 8, the method provided in the embodiment of the present application may further include the following steps:
S801, a binder driver of the mobile phone receives a memory reclamation instruction.
In some cases, the memory management system of the mobile phone may recycle the allocated memory space to the first memory space, so that the first memory space has an empty memory space. For example, as shown in fig. 5, the kernel space of the mobile phone further includes a memory reclamation module. And under the condition that the free memory quantity of the first memory space is smaller than a first preset threshold value, or under the condition that the mobile phone fails to allocate the memory, the memory reclamation module of the mobile phone can send a memory reclamation instruction to the memory allocation module driven by the binder, and the memory reclamation instruction indicates to reclaim the memory space to the first memory space.
S802, responding to a memory recycling instruction, and obtaining the idle memory quantity of a preset cache pool by a binder driver of the mobile phone.
And the binder driver of the mobile phone responds to the memory recycling instruction to acquire the memory quantity of the current preset cache pool. Further, the binder driver may determine whether the current free memory amount of the preset cache pool is greater than a sixth preset threshold, and determine whether to perform a reclamation operation on the memory space in the preset cache pool according to a relationship between the current memory amount of the preset cache pool and the sixth preset threshold.
S803, if the free memory amount of the preset cache pool is larger than a sixth preset threshold, the binder driver of the mobile phone releases part of the memory space in the preset cache pool to the first memory space until the free memory amount of the preset cache pool is smaller than or equal to the sixth preset threshold.
If the memory quantity of the preset cache pool is larger than the sixth preset threshold value, the idle memory quantity of the current preset cache pool exceeds the high water line of the preset cache pool. The binder driver of the mobile phone can release part of the memory space exceeding the sixth preset threshold value in the preset cache pool to the first memory space managed by the memory management system, so that the memory space in the preset cache pool is recovered.
For example, as shown in fig. 5, the binder-driven memory allocation module responds to the memory reclamation instruction, and communicates with the virtual memory of the preset buffer pool when the memory amount of the preset buffer pool is greater than the sixth preset threshold, and releases a part of the memory space in the preset buffer pool to the first memory space managed by the memory management module until the free memory amount of the preset buffer pool is less than or equal to the sixth preset threshold.
S804, if the free memory size of the preset cache pool is smaller than or equal to the sixth preset threshold, the binder driver of the mobile phone does not execute the release operation of the preset cache pool.
If the free memory quantity of the preset cache pool is smaller than or equal to a sixth preset threshold value, the free memory quantity of the current preset cache pool does not exceed the high water line of the preset cache pool. The binder driver of the mobile phone can not release the memory space in the preset cache pool and not recycle the memory space in the preset cache pool.
In this implementation manner, the mobile phone may respond to the memory reclamation instruction, and release the portion of the memory space to the first memory space under the condition that the free memory amount of the preset buffer pool is greater than the sixth preset threshold value, so that the first memory space has an allocable memory space.
According to the method provided by the embodiment of the application, the buffer pool mechanism is introduced into the binder driver, the binder driver can dynamically manage filling, distributing and releasing of the preset buffer pool through key thread identification and load state identification of physical memory distribution, the memory distribution time delay of binder communication in a high load state can be effectively reduced, and the system performance is optimized.
In the above embodiment, the mobile phone responds to the first binder communication instruction to obtain the load state of the physical memory allocation. And under the condition that the load state is a high load state (namely a first state), the mobile phone acquires the thread information of the working thread operated by the first process.
In other embodiments of the present application, the mobile phone first obtains thread information of a working thread operated by the first process in response to the first binder communication instruction. If the thread information indicates that the working thread operated by the first process is the target thread, the mobile phone acquires the load state of the physical memory allocation. Of course, the mobile phone responds to the first binder communication instruction, and can also obtain the load state of physical memory allocation and the thread information of the working thread operated by the first process at the same time. The embodiment of the application does not limit the load state of the physical memory allocation and the sequence of the thread information of the working threads.
Other embodiments of the present application provide an electronic device, comprising: a memory and one or more processors. The memory is coupled to the processor. The physical memory of the memory includes a predetermined cache pool for the binder communication and a first memory space outside the predetermined cache pool.
The memory has stored therein computer program code comprising computer instructions. The electronic device, when executed by a processor, may perform the functions or steps of the method embodiments described above. Of course, the electronic device may also include other hardware structures such as other antennas for receiving signals. For example, the electronic device further includes a hardware structure such as a camera, a display screen, and the like. The structure of the electronic device may refer to the structure of the mobile phone 100 shown in fig. 2.
The embodiment of the application also provides a chip system which is applied to the electronic equipment. The system-on-chip includes at least one processor and at least one interface circuit. The processors and interface circuits may be interconnected by wires. For example, the interface circuit may be used to receive signals from other devices (e.g., memory). For another example, the interface circuit may be used to send signals to other devices (e.g., processors). The interface circuit may, for example, read instructions stored in the memory and send the instructions to the processor. The instructions, when executed by the processor, may cause the electronic device to perform the various steps of the embodiments described above. Of course, the chip system may also include other discrete devices, which are not specifically limited in this embodiment of the present application.
Embodiments of the present application also provide a computer-readable storage medium including computer instructions that, when executed on an electronic device described above, cause the electronic device to perform the functions or steps of the method embodiments described above.
Embodiments of the present application also provide a computer program product which, when run on a computer, causes the computer to perform the functions or steps of the method embodiments described above.
It will be apparent to those skilled in the art from this description that, for convenience and brevity of description, only the above-described division of the functional modules is illustrated, and in practical application, the above-described functional allocation may be performed by different functional modules according to needs, i.e. the internal structure of the apparatus is divided into different functional modules to perform all or part of the functions described above.
In the several embodiments provided in this application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the modules or units is merely a logical functional division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another apparatus, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and the parts displayed as units may be one physical unit or a plurality of physical units, may be located in one place, or may be distributed in a plurality of different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a readable storage medium. Based on such understanding, the technical solution of the embodiments of the present application may be essentially or a part contributing to the prior art or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium, including several instructions for causing a device (may be a single-chip microcomputer, a chip or the like) or a processor (processor) to perform all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read Only Memory (ROM), a random access memory (random access memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The foregoing is merely a specific embodiment of the present application, but the scope of the present application is not limited thereto, and any changes or substitutions within the technical scope of the present disclosure should be covered in the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (12)

1. The memory allocation method for interprocess communication is characterized by being applied to electronic equipment, wherein the physical memory of the electronic equipment comprises a preset cache pool for binder communication and a first memory space outside the preset cache pool; the electronic device further comprises a first process and a second process; the method comprises the following steps:
receiving a first binder communication instruction initiated by the first process, wherein the first binder communication instruction is used for indicating communication with the second process;
responding to the first binder communication instruction, and acquiring the load state of the physical memory allocation and the thread information of a working thread operated by the first process; the thread information is used for indicating whether the working thread is a target thread or not;
if the load state is a first state and the working thread operated by the first process is a target thread, memory space required by communication between the first process and the second process is distributed in the preset cache pool; the load state being a first state indicates that the idle memory amount of the first memory space is smaller than a first preset threshold value, or that a memory allocation delay parameter of the binder communication is larger than a second preset threshold value.
2. The method of claim 1, wherein before the obtaining the load status of the physical memory allocation and the thread information of the working thread operated by the first process, further comprises:
counting the total time spent by memory allocation in the binder communication of the preset times before the current moment;
and averaging the total duration by using the preset times to obtain the memory allocation delay parameter of the binder communication.
3. The method of claim 1 or 2, wherein the thread information includes a memory exhaustion parameter and a thread level;
if the memory exhaustion parameter of the working thread is smaller than or equal to a third preset threshold value, or the thread level of the working thread is smaller than or equal to a fourth preset threshold value, the working thread is the target thread; the memory exhaustion parameter is used for indicating the possibility that one thread is forcedly terminated under the condition that the idle memory quantity of the first memory space is smaller than a first preset memory quantity; the thread level is inversely related to the importance of the working thread;
and if the memory exhaustion parameter of the working thread is greater than the third preset threshold value and the thread level of the working thread is greater than the fourth preset threshold value, the working thread is not the target thread.
4. A method according to any one of claims 1-3, characterized in that the method further comprises:
and if the working thread is not the target thread, distributing the memory space required by the communication between the first process and the second process in the first memory space.
5. The method according to any one of claims 1-4, further comprising:
and after the communication between the first process and the second process is finished, recycling the memory space allocated for the communication between the first process and the second process to the preset cache pool.
6. The method according to any one of claims 1-5, further comprising:
if the load state is the second state, memory space required by the communication between the first process and the second process is distributed in the first memory space; the load state being a second state indicates that the idle memory amount of the first memory space is greater than or equal to the first preset threshold, and the memory allocation delay parameter is less than or equal to the second preset threshold.
7. The method according to any one of claims 1-6, further comprising:
Under the condition that the load state of the physical memory allocation is the second state, acquiring the idle memory quantity of the preset cache pool; the load state being a second state indicates that the idle memory amount of the first memory space is greater than or equal to the first preset threshold, and the memory allocation delay parameter is less than or equal to the second preset threshold;
and if the free memory quantity of the preset cache pool is smaller than a fifth preset threshold value, adding part of the memory space in the first memory space from the first memory space to the preset cache pool through at least one adding operation of the preset cache pool.
8. The method of claim 7, wherein the adding the portion of the first memory space from the first memory space to the predetermined cache pool after at least one addition operation of the predetermined cache pool comprises:
adding part of the memory space in the first memory space from the first memory space to the preset cache pool through at least one preset cache pool adding operation until the free memory quantity of the preset cache pool reaches a sixth preset threshold; in each adding operation in the adding operation of the at least one preset cache pool, the increased memory amount in the preset cache pool is equal to the second preset memory amount.
9. The method according to claim 7 or 8, characterized in that the method further comprises:
and if the free memory quantity of the preset cache pool is larger than a sixth preset threshold value, releasing part of the memory space in the preset cache pool to the first memory space until the free memory quantity of the preset cache pool is smaller than or equal to the sixth preset threshold value.
10. The method according to any one of claims 1-8, further comprising:
receiving a memory reclamation instruction;
responding to the memory recycling instruction, and acquiring the idle memory quantity of the preset cache pool;
and if the free memory quantity of the preset cache pool is larger than a sixth preset threshold value, recovering part of the memory space in the preset cache pool to the first memory space until the free memory quantity of the preset cache pool is smaller than or equal to the sixth preset threshold value.
11. An electronic device, comprising: a memory and one or more processors; the memory is coupled with the processor; the physical memory of the memory comprises a preset cache pool for the binder communication and a first memory space outside the preset cache pool; wherein the memory has stored therein computer program code comprising computer instructions which, when executed by the processor, cause the electronic device to perform the method of any of claims 1-10.
12. A computer readable storage medium comprising computer instructions which, when run on an electronic device, cause the electronic device to perform the method of any of claims 1-10.
CN202310703513.8A 2023-06-13 2023-06-13 Memory allocation method for interprocess communication, electronic equipment and storage medium Pending CN117724826A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310703513.8A CN117724826A (en) 2023-06-13 2023-06-13 Memory allocation method for interprocess communication, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310703513.8A CN117724826A (en) 2023-06-13 2023-06-13 Memory allocation method for interprocess communication, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117724826A true CN117724826A (en) 2024-03-19

Family

ID=90205801

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310703513.8A Pending CN117724826A (en) 2023-06-13 2023-06-13 Memory allocation method for interprocess communication, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117724826A (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111475299A (en) * 2020-04-03 2020-07-31 Oppo广东移动通信有限公司 Memory allocation method and device, storage medium and electronic equipment
CN111831438A (en) * 2020-07-01 2020-10-27 Oppo广东移动通信有限公司 Resource allocation method, device, storage medium and electronic equipment
CN111831435A (en) * 2020-07-01 2020-10-27 Oppo广东移动通信有限公司 Memory allocation method and device, storage medium and electronic equipment
CN114564315A (en) * 2022-03-15 2022-05-31 维沃移动通信有限公司 Memory allocation method and device, electronic equipment and medium
CN115718663A (en) * 2022-11-22 2023-02-28 Oppo广东移动通信有限公司 Binder drive memory management method, device, equipment and storage medium
CN115794361A (en) * 2021-09-10 2023-03-14 华为技术有限公司 Method for managing memory and electronic equipment
US20230127112A1 (en) * 2019-12-19 2023-04-27 Red Hat, Inc. Sub-idle thread priority class

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20230127112A1 (en) * 2019-12-19 2023-04-27 Red Hat, Inc. Sub-idle thread priority class
CN111475299A (en) * 2020-04-03 2020-07-31 Oppo广东移动通信有限公司 Memory allocation method and device, storage medium and electronic equipment
CN111831438A (en) * 2020-07-01 2020-10-27 Oppo广东移动通信有限公司 Resource allocation method, device, storage medium and electronic equipment
CN111831435A (en) * 2020-07-01 2020-10-27 Oppo广东移动通信有限公司 Memory allocation method and device, storage medium and electronic equipment
CN115794361A (en) * 2021-09-10 2023-03-14 华为技术有限公司 Method for managing memory and electronic equipment
CN114564315A (en) * 2022-03-15 2022-05-31 维沃移动通信有限公司 Memory allocation method and device, electronic equipment and medium
CN115718663A (en) * 2022-11-22 2023-02-28 Oppo广东移动通信有限公司 Binder drive memory management method, device, equipment and storage medium

Similar Documents

Publication Publication Date Title
US11301300B2 (en) Method for resource allocation and terminal device
US20230385112A1 (en) Memory Management Method, Electronic Device, and Computer-Readable Storage Medium
CN111555825B (en) Radio frequency resource allocation method and device
CN112817736B (en) Memory management method and electronic equipment
CN116107922A (en) Application management method and electronic device
CN114968836A (en) Garbage recycling method and electronic equipment
CN116126744B (en) Memory recycling method and device and terminal equipment
CN116166573B (en) Method for controlling memory reclamation, electronic device and storage medium
CN117724826A (en) Memory allocation method for interprocess communication, electronic equipment and storage medium
CN115640116B (en) Service processing method and related device
CN114253737B (en) Electronic device, memory recovery method thereof and medium
CN113950033B (en) Data transmission method and equipment
CN115756868A (en) Memory allocation method, device, equipment, storage medium and computer program product
CN117519959A (en) Memory management method and electronic equipment
US20200257558A1 (en) Processing Method and Apparatus
CN116541180B (en) Memory allocation method, electronic equipment and storage medium
CN116661985B (en) Method and device for managing daemon threads for garbage collection and electronic equipment
CN117130458B (en) Data processing method, electronic device and storage medium
CN116700944B (en) Memory recycling method and device and electronic equipment
CN116719633B (en) Method for managing memory exchange partition and electronic equipment
WO2023185684A1 (en) Process killing method for application, and electronic device
CN117130767B (en) Method for recycling memory, electronic equipment and storage medium
CN118467191A (en) Data transmission method, electronic equipment and storage medium
CN115934302A (en) Memory leak processing method and electronic equipment
CN118277120A (en) Method for managing system service and related 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