Memory allocation method, electronic device and storage medium for inter-process communication

By using a combination of preset cache pool and first memory space in the Android system, the memory allocation is dynamically managed, and the memory allocation delay problem caused by the high binder communication frequency is solved, improving system performance and user experience.

CN117724826BActive Publication Date: 2024-12-10HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310703513.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-13
Publication Date
2024-12-10
Estimated Expiration
2043-06-13

AI Technical Summary

Technical Problem

In Android systems, the high frequency of binder communication leads to a large memory allocation delay, which may cause system lag and performance problems.

Method used

The combination scheme of preset cache pool and first memory space is adopted to dynamically allocate and recycle memory space based on physical memory allocation load status and worker thread information to reduce the memory allocation delay of binder communication and optimize system performance.

Benefits of technology

In high load state, memory is quickly allocated through preset cache pools, reducing the delay of binder communication, reducing blockage of critical processes, and improving system performance and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117724826B_ABST
    Figure CN117724826B_ABST
Patent Text Reader

Abstract

The present application provides a memory allocation method, an electronic device and a storage medium for inter-process communication, and relates to the field of communication technology. The physical memory of the electronic device includes a preset cache pool for binder communication and a first memory space outside the preset cache pool. The electronic device receives a first binder communication instruction initiated by a first process. In response to the first binder communication instruction, the electronic device can obtain the load status of the physical memory allocation and the thread information of the working thread run by the first process. If the load status is the first state, and the working thread run by the first process is the target thread, the memory space required for the communication between the first process and the second process is allocated in the preset cache pool. In this way, the delay of the physical memory allocation of the binder communication under high load conditions can be reduced, and the possibility of the physical memory allocation of the binder communication blocking the key process can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of communication technology, and in particular to a memory allocation method, electronic device, and storage medium for inter-process communication. Background Art

[0002] There are many inter-process communication mechanisms in the Android system architecture, such as pipes, message queues, and shared memory. Binder communication is an inter-process communication mechanism in the Android system architecture.

[0003] By using the binder mechanism, each inter-process communication only involves the replication of communication data once, which can improve the performance of inter-process communication. Currently, binder communication occurs very frequently in the Android system architecture. In some scenarios, the frequency of binder communication can reach more than 3,000 times per second. During each binder communication, the binder driver will apply for a piece of physical memory to store communication data. Then the destination process of the binder communication can access the communication data stored in the physical memory to achieve inter-process communication.

[0004] However, in some cases, the memory allocation delay during binder communication is large, which may cause performance issues such as system freezes. Summary of the invention

[0005] The embodiments of the present application provide a memory allocation method, electronic device and storage medium for inter-process communication, which can reduce the latency of memory allocation in binder communication and optimize system performance.

[0006] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:

[0007] In a first aspect, a memory allocation method for inter-process communication is provided, which is applied to an electronic device, wherein the 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 includes:

[0008] The electronic device receives a first binder communication instruction initiated by a first process to a second process. In response to the first binder communication instruction, the electronic device obtains the load state of the physical memory allocation and the thread information of the working thread run by the first process. The thread information is used to indicate whether the working thread is a target thread. If the load state is the first state and the working thread run by the first process is the target thread, it indicates that the current physical memory allocation of the electronic device is in a high load state, and the working thread in the first process run by the electronic device is a key process that has a significant impact on the system performance of the electronic device (for example, some user threads that affect the user experience, etc.). At this time, the amount of free memory of the electronic device is less than the first preset threshold, or the memory allocation delay parameter of the binder communication is greater than the second preset threshold. In this case, the electronic device can allocate the memory space required for communication between the first process and the second process in the preset cache pool to realize inter-process communication between the first process and the second process.

[0009] In this way, in scenarios where physical memory allocation is in a high-load state and critical threads are running, such as gaming scenarios, photo-taking scenarios, etc., the electronic device can immediately allocate the memory space required for binder communication (i.e., the memory space required for communication between the first process and the second process) through a preset cache pool, thereby reducing the delay in physical memory allocation for binder communication under high-load conditions, reducing the possibility of physical memory allocation for binder communication blocking critical processes, improving system freezes, optimizing system performance, and providing user experience.

[0010] In another possible implementation of the first aspect, before obtaining the load status of the physical memory allocation and the thread information of the working thread run by the first process, the electronic device can also count the total time consumed for memory allocation in the binder communication for a preset number of times before the current moment, and then average the total time using the preset number of times to obtain the memory allocation delay parameter of the binder communication.

[0011] This implementation provides a method for determining a memory allocation delay parameter, that is, the memory allocation delay parameter can 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 can reflect the concentration trend of memory allocation time consumption in binder communication.

[0012] In another possible implementation of the first aspect, the above-mentioned thread information includes a memory exhaustion parameter and a thread level. The memory exhaustion parameter is used to indicate the possibility that a thread is forcibly terminated when the amount of free memory in the first memory space is less than the first preset memory amount. The thread level is negatively correlated with the importance of the working thread. If the memory exhaustion parameter of the working thread run by the first process is less than or equal to the third preset threshold, or the thread level of the working thread is less than or equal to the fourth preset threshold, the working thread is the target thread. If the memory exhaustion parameter of the working thread is greater than the third preset threshold, and the thread level of the working thread is greater than the fourth preset threshold, the working thread is not the target thread.

[0013] In this implementation, the electronic device can determine whether the working thread currently running in the first process is the target thread by using at least one of the memory exhaustion parameter and the thread level. Both the memory exhaustion parameter and the thread level are related to the importance of the working thread, so that the target thread can be accurately identified by using any one of the memory exhaustion parameter and the thread level.

[0014] In another possible implementation manner of the first aspect, if the working thread is not the target thread, memory space required for the first process to communicate with the second process is allocated in the first memory space.

[0015] In this implementation, since the first process does not run the target thread, even if the memory allocation of this binder communication may block the working thread run by the first process, the impact on system performance is small and the user is unlikely to notice the impact. In this case, the electronic device can allocate the memory space required by the first process and the second process in the first memory space to implement the binder communication between the first process and the second process.

[0016] In another possible implementation manner of the first aspect, after the communication between the first process and the second process ends, the memory space allocated for the communication between the first process and the second process is recycled to a preset cache pool.

[0017] In this way, the electronic device can give priority to reclaiming the allocated memory space for binder communication to the preset cache pool, so that there is allocatable memory space in the preset cache pool. Therefore, when the electronic device is in a high-load state of physical memory allocation and running a target thread, it can immediately allocate memory space for binder communication through the preset cache pool.

[0018] In another possible implementation of the first aspect, if the load state is the second state, memory space required for communication between the first process and the second process is allocated 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.

[0019] In this implementation, the load state is the second state, which means that the electronic device is in a low load state of physical memory allocation, the memory space that can be allocated in the first memory space is sufficient, and the memory allocation delay of the binder communication is small. The electronic device provides the memory space required for this binder communication through the first memory space, which is small in time delay and has little impact on system performance.

[0020] In another possible implementation of the first aspect, when the load state of the physical memory allocation is the second state, the amount of free memory of the preset cache pool is obtained. The load state being the second state indicates that the amount of free memory 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. If the amount of free memory of the preset cache pool is less than the fifth preset threshold, then after at least one operation of adding the preset cache pool, part of the memory space in the first memory space is added from the first memory space to the preset cache pool.

[0021] In this way, when the electronic device is in a low-load state of physical memory allocation, if the amount of free memory in the preset cache pool is insufficient, the free memory of the preset cache pool can be added through the first memory space, so that the allocatable memory space in the preset cache pool is maintained at an appropriate amount of memory while reducing the impact on the first memory space.

[0022] In another possible implementation of the first aspect, after at least one adding operation to the preset buffer pool, the electronic device adds part of the memory space in the first memory space from the first memory space to the preset buffer pool until the amount of free memory in the preset buffer pool reaches a sixth preset threshold. In each adding operation in the at least one adding operation to the preset buffer pool, the amount of memory added in the preset buffer pool is equal to the second preset memory amount.

[0023] In this implementation, during the process of filling the preset buffer pool, the amount of memory added to the preset buffer pool each time is always equal to the second preset memory amount. In this way, the preset buffer pool can be quantitatively filled each time, thereby reducing the occurrence of too much memory space being added to the preset buffer pool at one time.

[0024] In another possible implementation manner of the first aspect, if the amount of free memory in the preset buffer pool is greater than a sixth preset threshold, part of the memory space in the preset buffer pool is released to the first memory space until the amount of free memory in the preset buffer pool is less than or equal to the sixth preset threshold.

[0025] In this implementation, when the amount of free memory in the preset cache pool is relatively sufficient, the electronic device can actively release part of the memory space in the preset cache pool and release the part of the memory space to the first memory space to reduce the phenomenon of wasting memory space due to excessive free memory in the preset cache pool.

[0026] In another possible implementation of the first aspect, the electronic device receives a memory reclaiming instruction. In response to the memory reclaiming instruction, the electronic device obtains the amount of free memory in the preset cache pool. If the amount of free memory in the preset cache pool is greater than a sixth preset threshold, part of the memory space in the preset cache pool is reclaimed to the first memory space until the amount of free memory in the preset cache pool is less than or equal to the sixth preset threshold.

[0027] In this implementation, the electronic device may also respond to the memory recycling instruction to recycle part of the memory space in the preset cache pool that exceeds the sixth preset threshold into the first memory space to increase the amount of free memory in the first memory space.

[0028] 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 preset cache pool for binder communication and a first memory space outside the preset cache pool. The memory stores a computer program code, and the computer program code includes a computer instruction. When the computer instruction is executed by the processor, the electronic device performs the following steps: receiving a first binder communication instruction initiated by a first process, the first binder communication instruction is used to indicate communication with a second process; in response to the first binder communication instruction, obtaining the load state of the physical memory allocation and the thread information of the working thread run by the first process; if the load state is the first state, and the working thread run by the first process is the target thread, the memory space required for the communication between the first process and the second process is allocated in the preset cache pool; wherein the load state is the first state, indicating that the amount of free memory in the first memory space is less than the first preset threshold, or the memory allocation delay parameter of the binder communication is greater than the second preset threshold; the thread information is used to indicate whether the working thread is the target thread.

[0029] In a possible implementation manner of the second aspect, when the above-mentioned computer instructions are executed by the processor, the electronic device further performs the following steps: counting the total time consumed for memory allocation in a preset number of binder communications before the current moment; averaging the total time using the preset number of times to obtain a memory allocation delay parameter for the binder communication.

[0030] In another possible implementation of the second aspect, the above-mentioned thread information includes a memory exhaustion parameter and a thread level; when the above-mentioned computer instructions are executed by the processor, the electronic device further performs the following steps: if the memory exhaustion parameter of the above-mentioned working thread is less than or equal to a third preset threshold, or the thread level of the working thread is less than or equal to a fourth preset threshold, then the working thread is a target thread; wherein the memory exhaustion parameter is used to indicate the possibility of a thread being forcibly terminated when the amount of free memory in the first memory space is less than the first preset memory amount; the thread level is negatively correlated with the importance of the working thread; if the memory exhaustion parameter of the above-mentioned working thread is greater than the third preset threshold, and the thread level of the working thread is greater than the fourth preset threshold, then the working thread is not a target thread.

[0031] In another possible implementation of the second aspect, when the above-mentioned computer instructions are executed by the processor, the electronic device further performs the following steps: if the above-mentioned working thread is not the target thread, the memory space required for the first process to communicate with the second process is allocated in the first memory space.

[0032] In another possible implementation of the second aspect, when the above-mentioned computer instructions are executed by the processor, the electronic device further performs the following steps: after the communication between the first process and the second process is completed, the memory space allocated for the communication between the first process and the second process is recycled to a preset cache pool.

[0033] In another possible implementation of the second aspect, when the above-mentioned computer instructions are executed by the processor, the electronic device further performs the following steps: if the load state is the second state, the memory space required for the first process to communicate with the second process is allocated in the first memory space; wherein 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.

[0034] In another possible implementation manner of the second aspect, when the above-mentioned computer instructions are executed by the processor, the electronic device further performs the following steps: when the load state of the physical memory allocation is the second state, obtaining the free memory amount of the preset cache pool; wherein the load state being the second state indicates that the free 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; if the free memory amount of the preset cache pool is less than the fifth preset threshold, then after at least one preset cache pool addition operation, adding part of the memory space in the first memory space from the first memory space to the preset cache pool.

[0035] In another possible implementation manner of the second aspect, when the above-mentioned computer instructions are executed by the processor, the electronic device further performs the following steps: after at least one adding operation to the preset cache pool, a part of the memory space in the first memory space is added from the first memory space to the preset cache pool until the free memory amount of the preset cache pool reaches a sixth preset threshold; wherein, in each adding operation in the at least one adding operation to the preset cache pool, the memory amount increased in the preset cache pool is equal to the second preset memory amount.

[0036] In another possible implementation manner of the second aspect, when the above-mentioned computer instructions are executed by the processor, the electronic device further performs the following steps: if the amount of free memory in the preset cache pool is greater than a sixth preset threshold, releasing part of the memory space in the preset cache pool to the first memory space until the amount of free memory in the preset cache pool is less than or equal to the sixth preset threshold.

[0037] In another possible implementation of the second aspect, when the above-mentioned computer instructions are executed by the processor, the electronic device further performs the following steps: receiving a memory reclaiming instruction; in response to the memory reclaiming instruction, obtaining the amount of free memory of a preset cache pool; if the amount of free memory of the preset cache pool is greater than a sixth preset threshold, reclaiming part of the memory space in the preset cache pool to the first memory space until the amount of free memory in the preset cache pool is less than or equal to the sixth preset threshold.

[0038] In a third aspect, the present application provides a computer-readable storage medium, including computer instructions, which, when executed on an electronic device, enables the electronic device to execute the method described in the first aspect and any possible implementation thereof.

[0039] In a fourth aspect, the present application provides a computer program product including program instructions, which, when executed on a computer, enables the computer to execute the method described in the first aspect and any possible implementation thereof. For example, the computer may be the electronic device described above.

[0040] In a fifth aspect, the present application provides a chip system, which is applied to an electronic device. The chip system includes an interface circuit and a processor. The interface circuit and the processor are interconnected by a line. The interface circuit is used to receive a signal from a memory and send a signal to the processor, the signal including a computer instruction stored in the memory. When the processor executes the computer instruction, the electronic device executes the method described in the first aspect and any possible implementation thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 A block diagram of a binder communication example provided in an embodiment of the present application;

[0042] Figure 2 A hardware structure block diagram of an example of an electronic device provided in an embodiment of the present application;

[0043] Figure 3 A software structure block diagram of an example of an electronic device provided in an embodiment of the present application;

[0044] Figure 4 A flowchart of an example of a memory allocation method for inter-process communication provided in an embodiment of the present application;

[0045] Figure 5 A block diagram of an example of a memory allocation method for inter-process communication provided in an embodiment of the present application;

[0046] Figure 6 A flowchart of another example of a memory allocation method for inter-process communication provided in an embodiment of the present application;

[0047] Figure 7 A schematic diagram of an example of a binder driver managing a preset cache pool provided in an embodiment of the present application;

[0048] Figure 8 A schematic diagram of another example of a binder driver managing a preset cache pool provided in an embodiment of the present application. DETAILED DESCRIPTION

[0049] An embodiment of the present application provides a memory allocation method for inter-process communication, which can effectively reduce the memory allocation delay of binder communication of electronic devices under high load conditions and improve the performance of inter-process communication.

[0050] The virtual memory space of an electronic device can be divided into user space and kernel space. The user space is the running space of the user program code. The kernel space is the running space of the kernel code. In order to improve the security of the process, 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. The kernel space is shared by all processes. Therefore, data exchange between processes will pass through the kernel space.

[0051] Binder communication is an inter-process communication mechanism. Each binder communication only requires one data copy to achieve inter-process communication. Compared with other traditional inter-process communication methods such as pipes and message queues that require two data copies, it has better inter-process communication performance.

[0052] Exemplarily, the electronic device is a mobile phone, and the operating system of the mobile phone is an Android system, and the principle of binder communication is introduced.

[0053] like Figure 1 As shown in Figure 1, the virtual memory space of the mobile phone includes user space and kernel space. The core function of binder communication is located in the kernel space of the mobile phone, providing an interface for upper-level program calls in the form of binder driver.

[0054] When process 1 communicates with process 2, the binder driver will apply for a memory space in the physical memory of the mobile phone to store the communication data between process 1 and process 2. The binder driver transfers the communication data sent by process 1 to process 2 to the kernel space. For example, the binder driver can call the copy_from_user() function to transfer the communication data of process 1 from the user space of process 1 to the kernel space. There is a mapping relationship between the virtual memory address used to store communication data in the kernel space and the memory space applied for by the binder driver in the physical memory. After the communication data is transferred to the kernel space, it is actually stored in the memory space of the physical memory. At the same time, this memory space also has a mapping relationship with the virtual memory address of the user space where process 2 is located.

[0055] Since the virtual memory address of the kernel space where the communication data is located and the virtual memory address of the user space where process 2 is located are mapped to the same memory space of the physical memory, it is equivalent to the binder driver copying the communication data to the user space of process 2. When process 2 accesses the virtual memory of the user space (actually accessing the memory space in the physical memory mapped by the virtual memory), it can obtain the communication data sent by process 1 without copying it again, thus realizing inter-process communication.

[0056] Of course, after receiving the communication data sent by process 2, process 1 can also return the communication data to process 1. The process of process 2 returning communication data to process 1 is equivalent to the reverse process of process 1 sending communication data to process 2 above, which will not be repeated here.

[0057] It can be seen that in the above binder communication process between process 1 and process 2, only one communication data replication is involved. Compared with other inter-process communication methods that require two data replications, binder communication has better inter-process communication performance.

[0058] Binder communication occurs 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, the demand for binder communication in electronic devices is large. When the system load is high, the free memory of the electronic device may be insufficient, which may cause the delay of allocating memory space for the electronic device to increase sharply, thereby blocking the key processes running in the electronic device and causing performance problems such as electronic device freezes.

[0059] In view of this, an embodiment of the present application provides a memory allocation method for inter-process communication, which is applied to an electronic device. The physical memory of the electronic device includes a preset buffer pool for binder communication and a first memory space outside the preset buffer pool.

[0060] Take the first process in an electronic device initiating a binder communication to the second process in the electronic device as an example. The electronic device can 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 can obtain the load state of the physical memory allocation and the thread information of the working thread run by the first process. If the load state is a high load state (which can be expressed as a first state), and the working thread run by the first process is a target thread, it indicates that the load amount of the current physical memory allocation of the electronic device is high, and the working thread in the first process run by the electronic device is a key process that has a significant impact on the system performance of the electronic device (for example, some user threads that affect the user experience, etc.). At this time, the amount of free memory of the electronic device is less than the first preset threshold, or the memory allocation delay parameter of the binder communication is greater than the second preset threshold. In this case, the electronic device can allocate the memory space required for communication between the first process and the second process in the preset cache pool to realize inter-process communication between the first process and the second process.

[0061] In this way, in scenarios where physical memory allocation is in a high-load state and critical threads are running, such as gaming scenarios, photo-taking scenarios, etc., the electronic device can immediately allocate the memory space required for binder communication (i.e., the memory space required for communication between the first process and the second process) through a preset cache pool, thereby reducing the delay in physical memory allocation for binder communication under high-load conditions, reducing the possibility of physical memory allocation for binder communication blocking critical processes, improving system freezes, optimizing system performance, and providing user experience.

[0062] In an embodiment of the present application, the electronic device may first obtain the load status of the physical memory allocation in response to the first binder communication instruction. If the load status is the first status, the electronic device further obtains the thread information of the working thread run by the first process. Alternatively, the electronic device may first obtain the thread information of the working thread run by the first process in response to the first binder communication instruction. If the working thread run by the first process is the target thread, the electronic device further obtains the load status of the physical memory allocation. Of course, in response to the first binder communication instruction, the electronic device may simultaneously obtain the load status of the physical memory allocation and the thread information of the working thread run by the first process. The embodiment of the present application does not limit the order of obtaining the load status of the physical memory allocation and the thread information of the working thread run by the first process.

[0063] For example, the electronic device described in the embodiments of the present application may be a mobile phone, a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) / virtual reality (VR) device, a media player, a wearable device, etc. The embodiments of the present application do not impose any special restrictions on the specific form of the electronic device.

[0064] In the embodiment of the present application, the electronic device is a mobile phone 100 as an example, and the hardware structure of the electronic device is introduced through the mobile phone 100. Figure 2As shown, the mobile phone 100 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.

[0065] Among them, 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, etc. Among them, different processing units can be independent devices or integrated in one or more processors. The processor 110 can be the nerve center and command center of the mobile phone 100. The processor 110 can generate an operation control signal according to the instruction opcode and the timing signal to complete the control of fetching and executing instructions.

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

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

[0068] The internal memory 121 may be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the mobile phone 100 by running the instructions stored in the internal memory 121. For example, in an embodiment of the present application, the processor 110 may execute the instructions stored in the internal memory 121, and the internal memory 121 may include a program storage area and a data storage area.

[0069] The program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), a configuration file of the motor 191, etc. The data storage area may store data created during the use of the mobile phone 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0070] The charging management module 140 is used to receive charging input from a charger. The charger can be a wireless charger or a wired charger. While the charging management module 140 charges the battery 142, it can also power the mobile phone 100 through the power management module 141.

[0071] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and supplies power to the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, and the wireless communication module 160. In some embodiments, the power management module 141 and the charging management module 140 can also be set in the same device.

[0072] The wireless communication function of the mobile phone 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor. In some embodiments, the antenna 1 of the mobile phone 100 is coupled with the mobile communication module 150, and the antenna 2 is coupled with the wireless communication module 160, so that the mobile phone 100 can communicate with the network and other devices through wireless communication technology.

[0073] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in mobile phone 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.

[0074] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the mobile phone 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, etc. the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation.

[0075] The mobile communication module 150 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 150 can be set in the same device as at least some modules of the processor 110.

[0076] The wireless communication module 160 can provide wireless communication solutions for application in the mobile phone 100, including wireless local area networks (WLAN) (such as Wi-Fi), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared technology (IR), etc.

[0077] The wireless communication module 160 may be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 may also receive a signal to be sent from the processor 110, modulate the signal, amplify the signal, and convert it into an electromagnetic wave for radiation via the antenna 2.

[0078] The mobile phone 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor.

[0079] The sensor module 180 may include sensors such as a pressure sensor, a gyro sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a Hall sensor, a touch sensor, an ambient light sensor, and a bone conduction sensor. The mobile phone 100 may collect various data through the sensor module 180 .

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

[0081] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLED, Micro-OLED, a quantum dot light-emitting diode (QLED), etc.

[0082] The mobile phone 100 can realize the shooting function through the ISP, the camera 193, the video codec, the GPU, the display screen 194 and the application processor. The ISP is used to process the data fed back by the camera 193. The camera 193 is used to capture a still image or a video. In some embodiments, the mobile phone 100 may include one or more cameras 193.

[0083] The button 190 includes a power button, a volume button, etc. The button 190 may be a mechanical button. It may also be a touch button. The motor 191 may generate a vibration prompt. The motor 191 may be used for an incoming call vibration prompt or for touch vibration feedback. The indicator 192 may be an indicator light, which may be used to indicate the charging status, the change in power, or may be used to indicate messages, missed calls, notifications, etc.

[0084] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to or disconnected from the mobile phone 100 by inserting the SIM card interface 195 or pulling the SIM card interface 195 out. The mobile phone 100 can support one or more SIM card interfaces. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, etc.

[0085] It is understandable that the interface connection relationship between the modules illustrated in this embodiment is only a schematic illustration and does not constitute a structural limitation on the electronic device. In other embodiments, the electronic device may also include more or fewer modules than those provided in the above embodiments, and different interface connection methods in the above embodiments may be used between the modules, or a combination of multiple interface connection methods. The hardware structure of the electronic device provided in the embodiments of the present application can also refer to the hardware structure of the mobile phone 100 as shown in the figure. The methods in the following embodiments can all be implemented in an electronic device having the above hardware structure.

[0086] The software system of electronic devices can adopt layered architecture, event-driven architecture, micro-kernel architecture, micro-service architecture or cloud architecture. Figure 3 As shown, in the embodiment of the present application, the electronic device is the above-mentioned mobile phone 100, and the software system of the electronic device adopts the layered architecture of the Android system as an example to illustrate the software structure of the electronic device.

[0087] The layered architecture of the mobile phone 100 divides the software into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system may include an application layer, an application framework layer, an Android runtime (Android runtime) and a system library and a kernel layer.

[0088] The application layer may include a series of application packages. For example, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications, and the present application embodiment does not impose any restrictions on this.

[0089] The application framework layer provides an application programming interface (API) and a programming framework for the application programs of the application layer. The application framework layer includes some 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, and a notification manager, etc., and the embodiments of the present application do not impose any restrictions on this.

[0090] The Android runtime consists of a core library and a virtual machine. The Android runtime is responsible for scheduling and management of the Android system. The core library consists of two parts: one is the function that the Java language needs to call, and the other is the Android core library. The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0091] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0092] The kernel layer is the layer between hardware and software. The kernel layer includes drivers and system service programs. Drivers include at least display drivers, audio drivers, sensor drivers, binder drivers, etc.

[0093] Here, the user space of the mobile phone 100 may include the above-mentioned application layer, application framework layer, Android runtime and system library. The kernel space of the mobile phone 100 includes the kernel layer. The first process and the second process may be two different processes in the user space that can perform binder communication. For example, the first process is a gallery application in the application layer, and the second process is a system service process in the application architecture layer. When the gallery application displays an image in response to a user operation, the gallery application may call a window manager in the system service process to display the image in the window of the gallery application. Binder communication may be used between the gallery application and the system service process.

[0094] In the following implementation, the electronic device is a mobile phone as an example to introduce the method provided by the embodiment of the present application. Figure 4 As shown, the method provided in the embodiment of the present application may include the following steps:

[0095] S401, the mobile phone configures a preset cache pool for binder communication.

[0096] The mobile phone can set a preset buffer pool for binder communication in the physical memory. The preset buffer pool can be used exclusively for memory allocation in binder communication. The mobile phone can allocate a portion of memory space in the physical memory as the preset buffer pool. For example, Figure 5 As shown, the binder driver of the mobile phone can apply for the virtual memory corresponding to the preset buffer pool in the kernel space, and the virtual memory of the preset buffer pool corresponds to the preset buffer pool in the physical memory of the mobile phone.

[0097] After configuring the preset buffer pool, the physical memory of the mobile phone may include the preset buffer pool for binder communication and the first memory space outside the preset buffer pool. The first memory space may be a general memory space, which can be used for memory allocation for binder communication and for memory allocation for other needs. Of course, in addition to the preset buffer pool and the first memory space, the physical memory of the mobile phone may also include other memory spaces for kernel operation and special purposes, which is not limited in the embodiments of the present application.

[0098] The memory amount of the preset buffer pool (e.g., denoted as binder_pool_count) can be set according to actual needs or application scenarios. For example, the memory amount of the preset buffer pool can be set to be smaller than the amount of the first memory space, so as to reduce the impact of the preset buffer pool on other memory allocation requirements. For example, the memory amount of the preset buffer pool can be set to 1 gigabyte.

[0099] For another example, the memory capacity of the preset buffer pool can be adjusted dynamically. If the memory capacity of the preset buffer pool is large, the mobile phone can reduce the preset buffer pool. If the memory capacity of the preset buffer pool is small, the mobile phone can increase the memory capacity of the preset buffer pool.

[0100] The memory size of the preset cache pool refers to the size of the free memory space in the preset cache pool, that is, the size of the unallocated memory space. The memory size of the preset cache pool can also be called the free memory size.

[0101] In order to facilitate the management of the preset cache pool, in some implementations, the mobile phone may also set a reference value for the preset cache pool for measuring the amount of free memory in the preset cache pool. For example, the mobile phone may set a fifth preset threshold and a sixth preset threshold. The fifth preset threshold is less 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.

[0102] The fifth preset threshold may be a low watermark of the preset buffer pool (e.g., recorded as binder_pool_min_watermark). If the amount of free memory of the preset buffer pool is less than the fifth preset threshold, it indicates that the free memory of the preset buffer pool is small. The sixth preset threshold may be a high watermark of the preset buffer pool (e.g., recorded as binder_pool_high_watermark). If the amount of free memory of the preset buffer pool is greater than the sixth preset threshold, it indicates that the free memory of the preset buffer pool is sufficient. If the amount of free memory of the preset buffer pool is between the fifth preset threshold and the sixth preset threshold, it indicates that the free memory of the preset buffer pool is moderate.

[0103] The fifth preset threshold and the sixth preset threshold can be set according to actual application scenarios or requirements. For example, the fifth preset threshold can be 250 megabytes. The sixth preset threshold can be 750 megabytes.

[0104] S402: A binder driver of a mobile phone receives a first binder communication instruction initiated by a first process, where the first binder communication instruction is used to instruct communication with a second process.

[0105] A first process is running in the mobile phone. The first process of the mobile phone can initiate a first binder communication instruction and request to communicate with the second process through the first binder communication instruction. For example, the first process can be an application process. Figure 5 As shown, the first process may be any one of application processes of application 1, application 2, and application 3. The second process may be a process in the mobile phone that is different from the first process.

[0106] It is difficult for the first process and the second process to communicate directly in the user space. The first process can communicate with the second process through the binder driver in the kernel space of the mobile phone. For example, Figure 6 In S601, the first process of the mobile phone 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. Figure 5 As shown, taking the first process as application 1 as an example, application 1 can communicate with the memory allocation module driven by the binder and send a first binder communication instruction to the memory allocation module.

[0107] S403: In response to the first binder communication instruction, the mobile phone obtains the load status of the physical memory allocation.

[0108] The load state of physical memory allocation can indicate the demand for physical memory allocation in the mobile phone, and can indicate whether the mobile phone is currently in a high load state or a low load state of physical memory allocation. The load state of physical memory allocation in 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.

[0109] When the mobile phone is in a high-load state of physical memory allocation, the memory space (also called free memory) that can be allocated in the first memory space of the mobile phone's physical memory is insufficient. If the memory space for binder communication is allocated from the first memory space, the delay of memory allocation in binder communication may increase. When the mobile phone is in a low-load state of physical memory allocation, the memory space that can be allocated in the first memory space of the mobile phone's physical memory is sufficient. If the memory space for binder communication is allocated from the first memory space, the delay of memory allocation in binder communication is small.

[0110] The mobile phone can obtain the load status of the physical memory allocation in response to the first binder communication instruction. Figure 6 In S602 shown, the binder driver of the mobile phone responds to the first binder communication instruction, obtains the load status of the physical memory allocation, and determines the current load status of the physical memory allocation through the load status of the physical memory allocation. Figure 5 As shown, the binder driver may further include a load state identification module. The load state identification module may identify the load state of the physical memory allocation. The memory allocation module of the binder driver may obtain the load state of the physical memory allocation from the load state identification module.

[0111] In some implementations, the load state can be represented by an information flag. For example, a first information flag (such as is_binder_alloc_highload) can be used to indicate the load state of physical memory allocation in a mobile phone. The first information flag can be a first flag (such as true) or a second flag (such as false). The first information flag is a first flag, which can indicate that the load amount of physical memory allocation in the mobile phone is large, and the mobile phone is in a high load state of physical memory allocation (i.e., a first state). The first information flag is a second flag, which can indicate that the load amount of physical memory allocation in the mobile phone is small, and the mobile phone is in a low load state of physical memory allocation (i.e., a second state).

[0112] In order to accurately represent the demand request for physical memory allocation through the load status, in some implementations, the mobile phone can determine the load status through at least one of the free memory amount of the first memory space (such as mem_free) and the memory allocation delay parameter of the binder communication (such as binder_alloc_delay_avg). The memory allocation delay parameter of the binder communication can reflect the time delay of the mobile phone in the memory allocation of the binder communication. The mobile phone can obtain the free memory amount of the first memory space and the memory allocation delay parameter of the binder communication through the interface provided by the kernel.

[0113] It is understandable that the mobile phone can determine the load state through the free memory amount of the first memory space and the memory allocation delay parameter of the binder communication before S402. For example, the mobile phone can periodically (such as 5 milliseconds, 10 milliseconds, etc.) obtain at least one of the free memory amount of the first memory space and the memory allocation delay parameter of the binder communication. The mobile phone further determines the load state based on at least one of the free memory amount of the first memory space and the memory allocation delay parameter of the binder communication. Alternatively, the mobile phone can also obtain at least one of the free memory amount of the first memory space and the memory allocation delay parameter of the binder communication in response to the first binder communication instruction after S402. The mobile phone further determines the load state based on at least one of the free memory amount of the first memory space and the memory allocation delay parameter of the binder communication.

[0114] The following describes how the mobile phone determines the load status through some examples.

[0115] In one example of this implementation, the mobile phone can determine the load state of the binder communication based on the amount of free memory in the first memory space. If the amount of free memory in the first memory space is less than the first preset threshold, it can be considered that the memory space that can be allocated in the first memory space is insufficient. At this time, the load amount 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 mobile phone can determine the load state of the binder communication as the first state. If the amount of free memory in the first memory space is greater than or equal to the first preset threshold, it can be considered that the memory space that can be allocated 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 mobile phone can determine the load state of the binder communication as the second state.

[0116] Here, the first preset threshold value can be set according to the actual application scenario or demand. For example, the first preset threshold value can be a low water mark of the first memory space. The first preset threshold value can be set to one quarter of the total amount of the first memory space. For another example, the first preset threshold value can be set to a value such as 750 megabytes, 1 gigabyte, etc.

[0117] In another example of this implementation, the mobile phone can determine the load state of the binder communication according to the memory allocation delay parameter of the binder communication. If the memory allocation delay parameter of the binder communication is greater than the second preset threshold, it can be considered that the time delay of the memory allocation in the process of the binder communication executed by the mobile phone is large. At this time, the load amount 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 mobile phone can determine the load state of the binder communication as the first state. If the memory allocation delay parameter of the binder communication is less than or equal to the second preset threshold, it can be considered that the time delay of the memory allocation in the process of the binder communication executed by the mobile phone is small. 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 mobile phone can determine the load state of the binder communication as the second state.

[0118] Here, the second preset threshold value can be set according to actual application scenarios or requirements. For example, the second preset threshold value can be set to a value such as 10 milliseconds or 15 milliseconds.

[0119] In another example of this implementation, the mobile phone can 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 amount of free memory in the first memory space is less than the first preset threshold, or the memory allocation delay parameter of the binder communication is greater than the second preset threshold, it can be considered that the load amount of the physical memory allocation in the mobile phone is large at this time, and the mobile phone is in a high load state of the physical memory allocation. In this case, the mobile phone can determine the load state of the binder communication as the first state. If the amount of free memory in the first memory space is greater than or equal to the first preset threshold, and the memory allocation delay parameter of the binder communication is less than or equal to the second preset threshold, it can be considered that the load amount of the physical memory allocation in the mobile phone is small at this time, and the mobile phone is in a low load state of the physical memory allocation. In this case, the mobile phone can determine the load state of the binder communication as the second state.

[0120] Here, the mobile phone can allocate a certain amount of memory space for each binder communication, and the memory allocation delay parameter of the binder communication can represent the time delay of the mobile phone in executing the memory allocation in the binder communication. For example, the mobile phone can set a timer for the memory allocation of each binder communication, and use the timer to count the time consumed by the memory allocation in each binder communication. The mobile phone can determine the memory allocation delay parameter of the binder communication based on the time consumed by the memory allocation in the binder communication counted by the timer. The following provides some methods for determining the memory allocation delay parameter.

[0121] In some implementations, the mobile phone may use the duration of memory allocation for the last binder communication counted before the current moment as the memory allocation delay parameter for the binder communication.

[0122] In other implementations, the mobile phone can use the total time consumed by memory allocation of at least one binder communication counted within a preset time period before the current moment as the memory allocation delay parameter of the binder communication. For example, the preset time period is 1 minute, and the mobile phone has 5 binder communications within 1 minute before the current moment. The mobile phone can count the total time consumed by memory allocation of the 5 binder communications that occurred within 1 minute before the current moment, and use the total time as the memory allocation delay parameter of the binder communication.

[0123] Alternatively, in order to reflect the overall situation of memory allocation time consumption of binder communication within a preset time period, the mobile phone can also calculate the average time consumed for memory allocation in each binder communication within the preset time period. Specifically, the mobile phone can calculate the total time consumed for memory allocation of at least one binder communication counted within the preset time period, and the ratio between the number of binder communications within the preset time period, to obtain the average time consumed for memory allocation of binder communication within the preset time period. For example, the preset time period is 1 minute, and the mobile phone has 5 binder communications within 1 minute before the current moment. The mobile phone can calculate the average time consumed by each binder communication in memory allocation for the 5 binder communications that occurred within this 1 minute, and use the average time as the memory allocation delay parameter for binder communication.

[0124] In other implementations, the mobile phone can use the total time spent on memory allocation for a preset number of binder communications before the current moment as the memory allocation delay parameter for binder communication. For example, the preset number is 10 times. The mobile phone can count the total time spent on memory allocation in the 10 binder communications that occurred before the current moment, and use the total time as the memory allocation delay parameter for binder communication.

[0125] Alternatively, in order to reflect the overall situation of memory allocation time consumption in a preset number of binder communications, the mobile phone can also calculate the average time consumed for memory allocation in each binder communication in the preset number of times. Specifically, the mobile phone calculates the ratio of the total time consumed for memory allocation of the preset number of binder communications before the current moment to the preset number of times, and obtains the average time consumed for memory allocation of the preset number of binder communications. The mobile phone uses the average time as the 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 consumed for memory allocation in the 10 binder communications that occurred before the current moment. The mobile phone can use the preset number of times to average the total time and calculate the average time consumed for memory allocation in each of the 10 binder communications.

[0126] S404, the mobile phone determines whether the load state of the physical memory allocation is the first state.

[0127] The mobile phone can determine whether the current binder communication is in a high-load state. For example, the binder driver of the mobile phone can determine whether the load state is the first state through the first information flag of the binder communication. If the first information flag is the first flag, such as "TRUE", the mobile phone can confirm that the current binder communication is in a high-load state (i.e., the first state). If the first information flag is the second flag, such as "FALSE", the mobile phone can confirm that the current binder communication is in a low-load state (i.e., the second state).

[0128] If the load state of the physical memory allocation is the first state, the mobile phone executes S405.

[0129] If the load state of the physical memory allocation is the second state, the mobile phone executes S408.

[0130] S405: The mobile phone obtains thread information of a working thread running in the first process.

[0131] If the mobile phone is in a high-load state of binder communication, the mobile phone can obtain thread information of the working thread currently running in the first process. Figure 6 In S603, if the mobile phone is in a high-load state of binder communication, the binder driver of the mobile phone obtains thread information of the working thread run by the first process. The thread information can be used to indicate whether a thread is a target thread. The target thread can be a key thread that has a significant impact on the system performance of the mobile phone. For example, the target thread can be a user interface thread, an application startup thread, etc.

[0132] For example, Figure 5 As shown, the binder driver of the mobile phone may also include a thread identification module. The thread identification module may be used to identify the working thread currently running in the first process, and indicate whether the working thread is the target thread through thread information. The memory allocation module of the binder driver may obtain thread information from the thread identification module.

[0133] In some implementations, the thread information may be the thread ID (Identity Document) of the working thread. The binder driver of the mobile phone may obtain the thread ID of the working thread currently running in the first process. Furthermore, the mobile phone may match the thread ID of the working thread currently running in the first process with a preset thread ID. The preset thread ID corresponds to the target thread. If the thread ID of the working thread matches the preset thread ID, the working process may be considered to be the target thread. If the thread ID of the working thread does not match the preset thread ID, the working process may be considered not to be the target thread.

[0134] To more accurately identify the target thread, in some implementations, the thread information may include a memory exhaustion parameter and at least one parameter of a thread level. The mobile phone may determine whether the working thread currently running in the first process is the target thread by using the memory exhaustion parameter and at least one parameter of the thread level.

[0135] The kernel of the mobile phone may be configured with a memory exhaustion parameter for each process or thread. The memory exhaustion parameter may indicate the possibility that a process or thread is forcibly terminated when memory is exhausted (Out Of Memory, OOM) (e.g., the amount of free memory in the first memory space is less than the first preset memory amount). The first preset memory amount may be set according to actual scenarios or requirements. For example, the first preset memory amount may be less than or equal to the low water mark of the first memory space.

[0136] If the available memory space in the phone is insufficient, memory exhaustion may occur. In this case, in order to ensure the normal operation of the phone system, the phone can forcibly terminate some currently running processes or threads to free up memory space. The memory exhaustion parameter can be used as the basis for the phone to forcibly terminate the process or thread when the memory is exhausted. The larger the memory exhaustion parameter of a process or thread, the less important the process or thread is, and the more likely it is that the process or thread will be forcibly terminated. The smaller the memory exhaustion parameter of a process or thread, the more important the process or thread is, and the less likely it is that the process or thread will be forcibly terminated.

[0137] It can be seen that the memory exhaustion parameter can reflect the importance of a process or thread. The memory exhaustion parameter is negatively correlated with the importance of a process or thread. The smaller the memory exhaustion parameter, the more important a process or thread is. The mobile phone can use the memory exhaustion parameter to determine whether the working thread is the target thread.

[0138] For example, the mobile phone can obtain the memory exhaustion parameter of the working thread currently running in the first process through the first kernel interface (such as oom_score_adj). If the memory exhaustion parameter of the working thread is less than or equal to the third preset threshold, it can be considered that the importance of the working thread is relatively high, and the working thread is the target thread. In this case, the mobile phone can set the thread information of the working thread to the third flag, such as setting it to true, indicating that the working thread is the target thread. If the memory exhaustion parameter of the working thread is greater than the third preset threshold, it can be considered that the importance of the working thread is relatively low, and the working thread is not the target thread. In this case, the mobile phone can set the thread information of the working thread to the fourth flag, such as setting it to false, indicating that the working thread is not the target thread.

[0139] Here, the third preset threshold value can be set according to the actual application scenario or requirement. For example, the value range of the memory exhaustion parameter is an integer from -1000 to 1000. The third preset threshold value can be set to 0.

[0140] The above thread level can indicate the possibility that the mobile phone will prioritize a thread. The thread level is inversely proportional to the priority scheduling order. For example, if multiple threads in a mobile phone compete for processing resources in the mobile phone at the same time, the mobile phone can prioritize the thread with the smallest thread level. The mobile phone can configure a corresponding thread level for each running thread. The larger the thread level of a thread, the less important the thread is, and the less likely the thread is to be prioritized. The smaller the thread level of a thread, the greater the importance of the thread, and the more likely the thread is to be prioritized.

[0141] It can be seen that the thread level can also represent the importance of a thread. The thread level is negatively correlated with the importance of a thread. The smaller the thread level of a thread, the higher the importance of the thread. The mobile phone can use the thread level to determine whether the working thread is the target thread.

[0142] For example, the mobile phone can obtain the thread level of the working thread currently running in the first process through the second kernel interface (such as task_prio). If the thread level of the working thread is less than or equal to the fourth preset threshold, it can be considered that the importance of the working thread is relatively high, and the working thread is the target thread. In this case, the mobile phone can set the thread information of the working thread to the third flag, such as setting it to true, indicating that the working thread is the target thread. If the thread level of the working thread is greater than the fourth preset threshold, it can be considered that the importance of the working thread is relatively low, and the working thread is not the target thread. In this case, the mobile phone can set the thread information of the working thread to the fourth flag, such as setting it to false, indicating that the working thread is not the target thread.

[0143] Here, the fourth preset threshold value can be set according to actual application scenarios or requirements. For example, the value range of the thread level is an integer from 0 to 144. The fourth preset threshold value can be set to 100.

[0144] In some implementations, the mobile phone may also use the memory exhaustion parameter and the priority level of the working thread to jointly determine whether the working thread is the target thread.

[0145] For example, the mobile phone can obtain the memory exhaustion parameter of the working thread currently running in the first process through the first kernel interface. The mobile phone can obtain the priority level of the working thread through the second kernel interface. If the memory exhaustion parameter of the working thread is less than or equal to the third preset threshold, or the priority level of the working thread is less than or equal to the fourth preset threshold, it can be considered that the importance of the working thread is high, and the working thread is the target thread. In this case, the mobile phone can set the thread information of the working thread to the third flag, for example, to true, indicating that the working thread is the target thread. If the memory exhaustion parameter of the working thread is greater than the third preset threshold, and the priority level of the working thread is greater than the fourth preset threshold, it can be considered that the importance of the working thread is low, and the working thread is not the target thread. In this case, the mobile phone can set the thread information of the working thread to the fourth flag, such as false, indicating that the working thread is not the target thread.

[0146] S406: The mobile phone determines whether the thread information of the working thread indicates the target thread.

[0147] If the working thread running in the first process is the target thread, it can be considered that the working thread running in the first process is a key thread that has a significant impact on the system performance of the mobile phone. When the mobile phone is in a high-load state of physical memory allocation, the memory space that can be allocated in the first memory space may be insufficient, and the memory allocation of binder communication may block the working thread running in the first process, which will affect the system performance of the mobile phone, cause the mobile phone to freeze, and affect the user experience. In this case, the mobile phone can execute S407.

[0148] If the working thread of the first process is not the target thread, it can be considered that the working thread of the first process has little impact on the system performance of the mobile phone. When the mobile phone is in a high load state of physical memory allocation, even if the memory allocation of binder communication may block the working thread of the first process, the blocking of the working thread is difficult to cause the user to notice, and has little impact on the user experience. In this case, the mobile phone can execute S408.

[0149] S407, the mobile phone allocates memory space required for the first process to communicate with the second process in a preset cache pool.

[0150] The preset buffer pool is the memory space configured by the mobile phone for memory allocation for binder communication, which can be managed by the binder driver. In order to reduce the situation where key threads are blocked due to insufficient allocatable memory space in the mobile phone, the mobile phone can pre-allocate memory space for memory allocation for binder communication in the physical memory, and this memory space is the preset buffer pool. After the preset buffer pool is divided, the physical memory of the mobile phone may include the preset buffer pool and a first memory space outside the preset buffer pool. The first memory space may be a common memory space in the mobile phone.

[0151] Of course, in addition to the preset cache pool and the first memory space, the physical memory of the mobile phone may also include memory space for other purposes, and the embodiments of the present application are not limited to this.

[0152] When the mobile phone is in a high-load state of physical memory allocation and the first process is running a target thread, the memory space that can be allocated in the first memory space may be insufficient. If the memory space required for the binder communication between the first process and the second process is provided through the common first memory space, it is necessary to wait for other processes to release memory space or wait for the mobile phone to reclaim memory space. The memory allocation delay of this binder communication will increase, which may block the target thread running the first process. Therefore, in the high-load state of physical memory allocation, if the mobile phone recognizes that the first process is running a target thread, the memory space required for the communication between the first process and the second process can be immediately allocated in the preset cache pool for this binder communication, and the communication data between the first process and the second process is stored through this memory space, so as to realize the binder communication between the first process and the second process.

[0153] For example, Figure 6 In S604, if the working thread running in the first process is the target thread, the binder driver allocates the memory space required for this binder communication in the preset buffer pool. Figure 5 As shown, the memory allocation module in the binder driver can allocate the memory space required for the communication between the first process and the second process for storing communication data in the preset buffer pool through the virtual memory of the preset buffer pool.

[0154] In this way, when the mobile phone is in a high-load state of physical memory allocation and running critical threads, the mobile phone can immediately allocate the memory space required for binder communication (that is, the memory space required for communication between the first process and the second process) through a preset cache pool, thereby reducing the delay of memory allocation for binder communication under high-load conditions, reducing the possibility of memory allocation for binder communication blocking critical processes, improving system freezes, optimizing system performance, and providing user experience.

[0155] S408: The mobile phone allocates memory space required for the first process to communicate with the second process in the first memory space.

[0156] The first memory space may be a general memory space managed by a memory management system. The memory management system is a management mechanism in the kernel of a mobile phone for managing memory space in physical memory. For example, the memory management system may be a partner system. The binder driver of the mobile phone may request the memory management system for the memory space required for binder communication between the first process and the second process. In response to the request of the binder driver, the memory management system of the mobile phone allocates memory space in the first memory space for storing communication data between the first process and the second process, so as to implement binder communication between the first process and the second process. For example, Figure 5 As shown, the kernel space of the mobile phone also includes a memory management system. The memory allocation module of the binder driver can communicate with the memory management system and request the memory management system for the memory space required for this binder communication.

[0157] If the mobile phone executes this step after executing S404, that is, when the mobile phone is currently in a 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. Figure 6 As shown, in S607, if the mobile phone is currently in a 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 this binder communication. In S608, the memory management system of the mobile phone responds to the request of the binder driver and allocates the memory space required for this binder communication in the first memory space.

[0158] Since the mobile phone is in a low-load state of physical memory allocation, the memory space that can be allocated in the first memory space is sufficient (such as the amount of free memory in the first memory space is greater than or equal to the first preset threshold), and the memory allocation delay of the binder communication is small (such as the memory allocation delay parameter of the binder communication is less than or equal to the second preset threshold). The mobile phone provides the memory space required for this binder communication through the first memory space, and the time delay is small, which has little impact on the system performance of the mobile phone.

[0159] If the mobile phone executes this step after executing S406, that is, when 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. Figure 6As shown, in S605, if the working thread running in the first process is not the target thread, the binder driver requests the memory management system for the memory space required for this binder communication. In S606, the memory management system allocates the memory space required for this binder communication in the first memory space in response to the request of the binder driver.

[0160] In this case, even if the mobile phone is in a high-load state of physical memory allocation, the memory space that can be allocated 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 this binder communication may block the working thread run by the first process, the impact on the system performance of the mobile phone is small, and the user is unlikely to notice the impact. In this case, the mobile phone allocates the memory space required by the first process and the second process in the first memory space to achieve binder communication between the first process and the second process.

[0161] S409, after the first process and the second process finish receiving the communication, the mobile phone releases the memory space allocated for the communication between the first process and the second process to a preset cache pool.

[0162] After the communication between the first process and the second process ends, the mobile phone can recycle the memory space used by this binder communication to a preset cache pool. Figure 6 As shown, in S609, the second process sends a second binder communication instruction to the binder driver, and notifies the binder driver of the end of this binder communication through the second communication instruction. The second binder communication instruction is used to trigger the binder driver to release the memory space allocated for the 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 the communication between the first process and the second process to the preset cache pool.

[0163] It is understandable that the memory space used to store the communication data between the first process and the second process may be allocated in the preset cache pool or in the first memory space. After the communication between the first process and the second process ends, no matter whether the memory space allocated for the communication between the first process and the second process comes 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.

[0164] In this way, the mobile phone can prioritize filling the preset buffer pool so that there is allocatable memory space in the preset buffer pool, so that the mobile phone can immediately allocate memory space for binder communication through the preset buffer pool when the physical memory allocation is in a high load state and the target thread is running.

[0165] In the above implementation, the mobile phone can release the memory space allocated for the communication between the first process and the second process to the preset cache pool after the communication between the first process and the second process ends. In other implementations, the mobile phone can also release the memory space allocated for the communication between the first process and the second process to the preset cache pool when the inter-process communication between the first process and the second process is interrupted. The embodiment of the present application does not limit the timing of the mobile phone releasing the memory space allocated for the communication between the first process and the second process.

[0166] In the embodiment of the present application, a preset buffer pool for binder communication is configured in the physical memory of the mobile phone. When the mobile phone is in a high load state of physical memory allocation and a target thread is running in this binder communication, the mobile phone can provide the memory space required for this binder communication through the preset buffer pool, thereby reducing the delay of the binder communication.

[0167] In order to effectively manage the preset cache pool and keep the allocatable memory space in the preset cache pool at an appropriate amount, in some implementations, the mobile phone can also fill the preset cache pool to increase the free memory amount of the preset cache pool. Figure 7 As shown, the method provided in the embodiment of the present application also includes the following steps:

[0168] S701, the binder driver of the mobile phone obtains the load status of the physical memory.

[0169] The binder driver of the mobile phone can periodically obtain the load status of the physical memory. For example, the binder driver of the mobile phone can obtain the load status of the physical memory allocation every 1 second.

[0170] Alternatively, the binder driver of the mobile phone may obtain the load status of the 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 obtains the load status of the physical memory allocation in response to the first binder communication instruction initiated by the first process.

[0171] S702: If the load state of the physical memory allocation is the second state, the binder driver of the mobile phone obtains the free memory amount of the preset cache pool.

[0172] If the load state of physical memory allocation is the second state, it means that the current mobile phone is in a low load state of physical memory allocation. For example, when the mobile phone is in a low load state of physical memory allocation, the amount of free memory in 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. In this case, the binder driver of the mobile phone can obtain the amount of free memory in the preset cache pool. Figure 5As shown, the memory allocation module of the mobile phone binder driver can obtain the free memory amount of the preset cache pool. The free memory amount of the preset cache pool can be understood as the size of the memory space that can be allocated in the preset cache pool.

[0173] S703: If the amount of free memory in the preset buffer pool is less than a fifth preset threshold, the binder driver requests the memory management system to add a preset buffer pool.

[0174] After the binder driver obtains the free memory amount of the preset cache pool, it can determine whether the current free memory amount of the preset cache pool is less than a fifth preset threshold. The fifth preset threshold can be a low water mark of the preset cache pool.

[0175] If the free memory of the preset buffer pool is less than the fifth preset threshold, it may indicate that the available memory space in the current preset buffer pool is insufficient. In this case, the binder driver of the mobile phone may request the memory management system to add a preset buffer pool, that is, request to increase the free memory of the preset buffer pool.

[0176] If the amount of free memory in the preset buffer pool is greater than or equal to the fifth preset threshold, it may indicate that the memory space that can be allocated in the current preset buffer pool is appropriate or sufficient. In this case, the mobile phone may not perform the operation of adding the preset buffer pool. The operation of adding the preset buffer pool may be understood as increasing the amount of free memory in the preset buffer pool, or may also be referred to as a filling operation.

[0177] For example, Figure 5 As shown, the memory allocation module of the mobile phone can determine whether the current free memory amount of the preset cache pool is less than the fifth preset threshold. If the free memory amount of the preset cache pool is less than the fifth preset threshold, the memory allocation module driven by the binder requests the memory management system to increase the free memory amount of the preset cache pool. If the free memory amount of the preset cache pool is greater than or equal to the fifth preset threshold, the memory allocation module driven by the binder does not request to increase the free memory amount of the preset cache pool.

[0178] S704: In response to the request to add a preset cache pool, the memory management system of the mobile phone adds part of the memory space of the first memory space to the preset cache pool.

[0179] The memory management system of the mobile phone receives a request from the binder driver to add a preset buffer pool. In response to the request to add the preset buffer pool, the memory management system of the mobile phone divides a portion of the memory space in the first memory space, and adds the divided portion of the memory space to the preset buffer pool to fill the preset buffer pool. After the operation of adding the preset buffer pool, there is allocatable memory space in the preset buffer pool, which can be used to provide the memory space required for binder communication.

[0180] For example, Figure 5 As shown, the memory allocation module of the mobile phone binder driver can communicate with the memory management system and request the memory management system to add a preset cache pool. In response to the request, the memory management system 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 preset cache pool.

[0181] In this implementation, the mobile phone can add part of the memory space of the first memory space to the preset cache pool when the physical memory allocation is under low load. This can not only keep the allocatable memory space in the preset cache pool at an appropriate amount of memory, but also reduce the impact of the addition of the preset cache pool on the first memory space.

[0182] In order to keep the allocable memory space in the preset buffer pool at an appropriate amount of free memory, in some implementations, the memory management system of the mobile phone can fill part of the memory space in the first memory space into the preset buffer pool through at least one operation of adding the preset buffer pool. The memory management system of the mobile phone can add a fixed amount of memory space to the preset buffer pool in each operation of adding the preset buffer pool.

[0183] For example, in response to the request for adding a preset buffer pool sent by the binder driver, the memory management system of the mobile phone performs an adding operation to fill the preset buffer pool with a portion of the memory space of the second preset memory amount in the first memory space. After the adding operation, the memory management system of the mobile phone no longer continues to fill the memory space into the preset buffer pool.

[0184] For another example, the memory management system of the mobile phone responds to the request sent by the binder driver to add a preset cache pool, performs multiple adding operations, and stops filling the preset cache pool until the amount of free memory in the preset cache pool reaches a sixth preset threshold. In each filling operation, the memory management system of the mobile phone fills the memory space of the second preset memory amount in the first memory space into the preset cache pool. The sixth preset threshold is the high water mark of the preset cache pool. After multiple filling operations, the allocable memory space in the preset cache pool changes from insufficient to sufficient.

[0185] The second preset memory capacity can be set according to actual application scenarios or requirements. For example, the second preset memory capacity can be set to values ​​such as 20 megabytes, 50 megabytes, etc.

[0186] In this implementation, during the process of filling the preset buffer pool, the amount of memory added to the preset buffer pool each time is always equal to the second preset memory amount. In this way, the preset buffer pool can be quantitatively filled each time, thereby reducing the occurrence of too much memory space being added to the preset buffer pool at one time.

[0187] The first memory space is a general memory space. In addition to providing the memory space required for binder communication, the first memory space also provides memory space required for other needs (such as other inter-process communication methods, file cache, etc.). In order to prevent the preset cache pool from occupying too much memory originally belonging to the first memory space and reduce the impact of the preset cache pool on the first memory space, in some implementations, if the amount of free memory in the preset cache pool is greater than a certain amount of memory, the mobile phone can actively release the memory space of the preset cache pool to the first memory space. Specifically, if Figure 7 The method provided in the embodiment of the present application may further include the following steps:

[0188] S705: If the amount of free memory in the preset cache pool is greater 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 managed by the memory management system until the amount of free memory in the preset cache pool is less than or equal to the sixth preset threshold.

[0189] The sixth preset threshold may be the high water mark of the preset cache pool. If the amount of free memory in the preset cache is greater than the sixth preset threshold, it may indicate that the amount of free memory in the preset cache pool is relatively large. Since the preset cache pool is a memory space specifically used for binder communication, the demand for memory allocation is relatively small compared to 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 amount of free memory in the preset cache pool is greater than the sixth preset threshold, the binder driver of the mobile phone may actively release part of the memory space in the preset cache pool that exceeds the sixth preset threshold, and add the part of the memory space from the preset cache pool to the first memory space managed by the memory management system. The amount of memory in this part of the memory space is equal to the difference between the amount of memory in the preset cache pool and the sixth preset threshold.

[0190] For example, Figure 5 As shown, the memory allocation module driven by the binder communicates with the virtual memory of the preset buffer pool, and releases part of the memory space in the preset buffer pool to the first memory space managed by the memory management module.

[0191] Here, the binder driver may release the part of the memory space in the preset cache pool that exceeds the sixth preset threshold to the first memory space through a release operation. Alternatively, the binder driver may release a certain amount of memory space in the preset cache pool to the first memory space through multiple release operations each time, until the free memory amount of the preset cache pool is less than or equal to the sixth preset threshold.

[0192] In this implementation, when the amount of free memory in the preset cache pool is greater than the sixth preset threshold, the mobile phone can actively release part of the memory space in the preset cache pool and release the part of the memory space to the first memory space, so as to reduce the phenomenon of wasting memory space due to excessive free memory in the preset cache pool.

[0193] In other implementations, the mobile phone may also respond to the memory recycling instruction and recycle part of the memory space in the preset cache pool that exceeds the sixth preset threshold into the first memory space to increase the free memory amount of the first memory space. Figure 8 As shown, the method provided in the embodiment of the present application may also include the following steps:

[0194] S801, the binder driver of the mobile phone receives a memory recycling instruction.

[0195] In some cases, the memory management system of the mobile phone can reclaim the allocated memory space to the first memory space so that there is free memory space in the first memory space. Figure 5 As shown, the kernel space of the mobile phone also includes a memory recovery module. When the amount of free memory in the first memory space is less than a first preset threshold, or when the mobile phone fails to allocate memory, the memory recovery module of the mobile phone can send a memory recovery instruction to the memory allocation module driven by the binder, and instruct to reclaim the memory space to the first memory space through the memory recovery instruction.

[0196] S802: In response to the memory reclaiming instruction, the binder driver of the mobile phone obtains the amount of free memory in the preset cache pool.

[0197] The binder driver of the mobile phone responds to the memory recycling instruction and obtains the memory amount of the current preset cache pool. Further, the binder driver can determine whether the current free memory amount of the preset cache pool is greater than the sixth preset threshold, and determine whether to perform a recycling operation on the memory space in the preset cache pool based on the relationship between the current memory amount of the preset cache pool and the sixth preset threshold.

[0198] S803: If the amount of free memory in the preset cache pool is greater 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 amount of free memory in the preset cache pool is less than or equal to the sixth preset threshold.

[0199] If the amount of memory in the preset cache pool is greater than the sixth preset threshold, it means that the amount of free memory in the current preset cache pool exceeds the high water mark of the preset cache pool. The binder driver of the mobile phone can release part of the memory space in the preset cache pool that exceeds the sixth preset threshold to the first memory space managed by the memory management system, thereby reclaiming the memory space in the preset cache pool.

[0200] For example, Figure 5 As shown, the memory allocation module driven by the binder responds to the memory reclaim instruction, and when the memory amount of the preset cache pool is greater than the sixth preset threshold, communicates with the virtual memory of the preset cache pool, and releases part of the memory space in the preset cache pool to the first memory space managed by the memory management module until the free memory amount of the preset cache pool is less than or equal to the sixth preset threshold.

[0201] S804: If the amount of free memory in the preset buffer pool is less than or equal to a sixth preset threshold, the binder driver of the mobile phone does not execute a release operation of the preset buffer pool.

[0202] If the free memory amount of the preset buffer pool is less than or equal to the sixth preset threshold, it means that the free memory amount of the current preset buffer pool does not exceed the high water mark of the preset buffer pool. The binder driver of the mobile phone may not release the memory space in the preset buffer pool and may not recycle the memory space of the preset buffer pool.

[0203] In this implementation, the mobile phone can respond to the memory reclaim instruction and release the portion of memory space to the first memory space when the amount of free memory in the preset cache pool is greater than the sixth preset threshold, so that the first memory space has allocatable memory space.

[0204] The method provided in the embodiment of the present application introduces a cache pool mechanism in the binder driver. The binder driver can dynamically manage the filling, allocation and release of the preset cache pool through key thread identification and load status identification of physical memory allocation, which can effectively reduce the memory allocation delay of binder communication under high load conditions and optimize system performance.

[0205] In the above embodiment, the mobile phone first obtains the load state of the physical memory allocation in response to the first binder communication instruction. When the load state is a high load state (ie, the first state), the mobile phone then obtains the thread information of the working thread running by the first process.

[0206] In other embodiments of the present application, the mobile phone responds to the first binder communication instruction and first obtains the thread information of the working thread run by the first process. If the thread information indicates that the working thread run by the first process is the target thread, the mobile phone then obtains the load status of the physical memory allocation. Of course, the mobile phone can also simultaneously obtain the load status of the physical memory allocation and the thread information of the working thread run by the first process in response to the first binder communication instruction. The embodiments of the present application do not limit the order of obtaining the load status of the physical memory allocation and the thread information of the working thread.

[0207] Some other embodiments of the present application provide an electronic device, the electronic device comprising: a memory and one or more processors. The memory is coupled to the processor. The physical memory of the memory comprises a preset buffer pool for binder communication and a first memory space outside the preset buffer pool.

[0208] The memory stores a computer program code, which includes computer instructions. When the computer instructions are executed by the processor, the electronic device can perform the functions or steps in the above method embodiment. Of course, the electronic device can also include other hardware structures such as other antennas for receiving signals. For example, the electronic device also includes hardware structures such as a camera and a display screen. The structure of the electronic device can refer to Figure 2 The structure of the mobile phone 100 is shown.

[0209] The embodiment of the present application also provides a chip system, which is applied to an electronic device. The chip system includes at least one processor and at least one interface circuit. The processor and the interface circuit can be interconnected by lines. For example, the interface circuit can be used to receive signals from other devices (such as memory). For another example, the interface circuit can be used to send signals to other devices (such as processors). Exemplarily, the interface circuit can read instructions stored in the memory and send the instructions to the processor. When the instruction is executed by the processor, the electronic device can perform the various steps in the above embodiments. Of course, the chip system can also include other discrete devices, which are not specifically limited in the embodiment of the present application.

[0210] An embodiment of the present application also provides a computer-readable storage medium, which includes computer instructions. When the computer instructions are executed on the above-mentioned electronic device, the electronic device executes each function or step in the above-mentioned method embodiment.

[0211] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute each function or step in the above method embodiment.

[0212] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0213] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0214] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0215] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0216] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0217] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims

1. A memory allocation method for inter-process communication, characterized in that: Applied to an electronic device, the 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 electronic device also includes a first process and a second process; the method includes: receiving a first binder communication instruction initiated by the first process, where the first binder communication instruction is used to instruct communication with the second process; In response to the first binder communication instruction, acquiring the load state of the physical memory allocation and the thread information of the working thread run by the first process; wherein the thread information is used to indicate whether the working thread is a target thread; If the load state is the first state, and the working thread running in the first process is the target thread, the memory space required for the first process to communicate with the second process is allocated in the preset cache pool; wherein the load state being the first state indicates that the amount of free memory in the first memory space is less than a first preset threshold, or the memory allocation delay parameter of the binder communication is greater than a second preset threshold; If the load state is the second state or if the load state is the first state and the working thread running in the first process is not the target thread, the memory space required for the first process to communicate with the second process is allocated in the first memory space; wherein 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 of the binder communication is less than or equal to a second preset threshold; Among them, the memory allocation delay parameter of the binder communication represents the time delay for memory allocation in the electronic device performing binder communication, and the memory allocation delay parameter of the binder communication is the total time consumed for memory allocation in the binder communication within a preset number of times before the current moment or the average time consumed for memory allocation in each binder communication, or, it is the total time consumed for memory allocation of at least one binder communication counted within a preset time period before the current moment or the average time consumed for memory allocation in each binder communication, or, it is the time consumed for memory allocation of the last binder communication counted before the current moment.

2. The method according to claim 1, characterized in that The memory allocation delay parameter of the binder communication is the average duration consumed by memory allocation in each binder communication within a preset number of times before the current moment, and the method further includes: Count the total time spent on memory allocation in the preset number of binder communications before the current moment; The total duration is averaged using the preset number of times to obtain a memory allocation delay parameter for the binder communication.

3. The method according to claim 1 or 2, characterized in that: The thread information includes a memory exhaustion parameter and a thread level; If the memory exhaustion parameter of the working thread is less than or equal to a third preset threshold, or the thread level of the working thread is less than or equal to a fourth preset threshold, then the working thread is the target thread; wherein the memory exhaustion parameter is used to indicate the possibility that a thread is forcibly terminated when the amount of free memory in the first memory space is less than a first preset memory amount; and the thread level is negatively correlated with the importance of the working thread; If the memory exhaustion parameter of the working thread is greater than the third preset threshold, and the thread level of the working thread is greater than the fourth preset threshold, then the working thread is not the target thread.

4. The method according to claim 1, characterized in that: The method further comprises: After the communication between the first process and the second process ends, the memory space allocated for the communication between the first process and the second process is recycled to the preset cache pool.

5. The method according to claim 4, characterized in that The method further comprises: When the load state of the physical memory allocation is the second state, obtaining the amount of free memory of the preset cache pool; If the amount of free memory in the preset buffer pool is less than a fifth preset threshold, a portion of the memory space in the first memory space is added from the first memory space to the preset buffer pool through at least one operation of adding the preset buffer pool.

6. The method according to claim 5, characterized in that The adding of part of the memory space in the first memory space from the first memory space to the preset buffer pool after at least one adding operation to the preset buffer pool comprises: After at least one adding operation to the preset buffer pool, part of the memory space in the first memory space is added from the first memory space to the preset buffer pool until the amount of free memory in the preset buffer pool reaches a sixth preset threshold; wherein, in each adding operation in the at least one adding operation to the preset buffer pool, the amount of memory added in the preset buffer pool is equal to the second preset memory amount.

7. The method according to claim 5 or 6, characterized in that: The method further comprises: If the amount of free memory in the preset buffer pool is greater than a sixth preset threshold, part of the memory space in the preset buffer pool is released to the first memory space until the amount of free memory in the preset buffer pool is less than or equal to the sixth preset threshold.

8. The method according to claim 7, characterized in that The method further comprises: Receive memory reclaim instructions; In response to the memory reclaim instruction, obtaining the amount of free memory in the preset cache pool; If the amount of free memory in the preset buffer pool is greater than a sixth preset threshold, part of the memory space in the preset buffer pool is reclaimed to the first memory space until the amount of free memory in the preset buffer pool is less than or equal to the sixth preset threshold.

9. An electronic device, characterized in that: include: memory and one or more processors; The memory is coupled to the processor; The physical memory of the memory includes a preset cache pool for binder communication and a first memory space outside the preset cache pool; wherein, the memory stores computer program code, and the computer program code includes computer instructions, and when the computer instructions are executed by the processor, the electronic device executes the method as described in any one of claims 1-8.

10. A computer-readable storage medium, characterized in that: The method comprises computer instructions, which, when executed on an electronic device, cause the electronic device to execute the method as claimed in any one of claims 1 to 8.