Memory application method and related device
By selecting efficient or inefficient storage units for memory application in electronic devices based on memory requirements, the problem of low memory application efficiency is solved and the user experience is improved.
Patent Information
- Application Number
- CN202411183336.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-21
- Publication Date
- 2025-01-10
AI Technical Summary
In electronic devices, memory application efficiency is low, especially when there are many programs running in the background and insufficient memory, which causes memory application to take too long and affects the user experience.
After receiving the system message, determine the memory requirement required to store data, and apply for memory from the high-efficiency second-class storage unit or the low-efficiency first-class storage unit according to the demand, and give priority to the high-efficiency storage unit. To improve memory application efficiency.
In the case of insufficient memory, the efficiency of memory application is improved, the time-consuming of memory application is reduced, and the user experience is improved, especially when rapid memory application is required, such as animation display and sound effect playback.
Smart Images

Figure CN119292761A_ABST
Abstract
Description
[0001] This application is a divisional application of the invention patent application with application number 202310745337.4 submitted to the China Patent Office, application date June 21, 2023, and invention name “Memory application method and related device”. Technical Field
[0002] The present application relates to the field of computer technology, and in particular to a memory application method and related devices. Background Art
[0003] With the continuous development of computer science and technology, there are more and more types of software (application, APP) in electronic devices. There are many data processing in the operation process of APP in electronic devices. For example, in order to make the electronic device look smoother, dynamic effects can be displayed when opening / closing the application. Therefore, the electronic device needs to process the effect parameters related to the dynamic effect display. For example, in order to enhance the user's auditory experience, the user can choose different sound effects to play music in the music player software. Therefore, the electronic device needs to process the effect parameters related to the sound effect playback.
[0004] Before processing data, the electronic device needs to apply for memory for storing data. When there are many programs running in the background of the electronic device and the memory is insufficient, the memory application efficiency is low. Summary of the invention
[0005] The embodiment of the present application provides a memory application method and a related device. After receiving a system message indicating the storage of data to be stored, the present application first determines the memory requirement required to store the data to be stored, and applies for memory from a first type of storage unit when the memory requirement is greater than a first threshold. The operating efficiency of the first type of storage unit is lower than that of the second type of storage unit, and the probability of applying for memory from the first type of storage unit is higher. Therefore, the present application can improve the memory application efficiency when the memory is insufficient, that is, the required memory can be applied for faster.
[0006] In a first aspect, an embodiment of the present application provides a memory application method, which is applied to an electronic device, wherein the memory of the electronic device includes a first type of storage unit and a second type of storage unit, and the operation efficiency of the second type of storage unit is higher than the operation efficiency of the first type of storage unit. The method includes:
[0007] Receiving a system message, wherein the system message is used to instruct to store the data to be stored;
[0008] Determine the memory requirement required to store the data to be stored;
[0009] When the memory demand is greater than the first threshold, memory is requested from the first type of storage unit.
[0010] In this embodiment, the execution subject of the above method can be an electronic device or a program in the electronic device. The program in the electronic device can be a kernel program, which can be understood as the Android kernel in the embodiment of the present application; it can also be other programs other than the kernel program, such as the memory application function in the embodiment of the present application.
[0011] In the embodiment of the present application, the system message can be understood as any message for indicating the storage of data to be stored, triggering the execution subject to apply for memory to store the data to be stored. Exemplarily, the system message can be a message sent by the upper layer of the kernel layer to the kernel program in the kernel layer, or it can be a message sent by the kernel program to the memory application function. Therefore, in the case where the execution subject is the kernel program, the system message can be a message sent by the upper layer of the kernel layer to the kernel program in the kernel layer, and in the case where the execution subject is the memory application function, the system message can be a message sent by the kernel program to the memory application function.
[0012] In the embodiment of the present application, the system message can be the data to be stored itself, or it can be the message to be parsed, and the data to be stored can be obtained after parsing the system message. Exemplarily, when the execution subject is a memory application function and the system message needs to be parsed, the memory application function can receive the system message to be parsed sent by the kernel program, and then parse the system message to obtain the data to be stored; or the kernel program can parse the system message to obtain the data to be stored, and then send the data to be stored as the system message to the memory application function.
[0013] In an embodiment of the present application, the data to be stored may be any data that can be stored in both the first type of storage unit and the second type of storage unit, such as effect parameters or other data, which is not limited in the present application.
[0014] In the embodiment of the present application, the first type of storage unit and the second type of storage unit are both storage resources of the electronic device, wherein the operating efficiency of the second type of storage unit is lower than the operating efficiency of the first type of storage unit. In one implementation, the first type of storage unit and the second type of storage unit can be storage units of different levels in the hierarchical storage, and the level of the second type of storage unit is lower than the level of the first type of storage unit, for example, the second type of storage unit is a primary memory, and the first type of storage unit is a secondary memory, and other levels can be deduced by analogy. In another implementation, the first type of storage unit is a virtual memory, and the second type of storage unit is a physical memory.
[0015] The memory requirement required to store the data to be stored can be understood as the memory size, and the specific unit can be bits, bytes, etc. It can be understood that after applying for memory from the first type of storage unit, a memory (referred to as a target memory) can be obtained, and the size of the target memory matches the memory requirement. After obtaining the target memory, the data to be stored can be stored in the target memory, and then the data to be stored can be subsequently processed.
[0016] In the embodiment of the present application, the first threshold value can be determined based on the success rate of applying for memory from the first type of storage unit and the second type of storage unit. Since the operating efficiency of the first type of storage unit is lower than that of the second type of storage unit, that is, it is easier to apply for memory from the first type of storage unit than from the second type of storage unit, assuming that the statistical results reflect that the success rate of applying for memory less than A bytes from the second type of storage unit is high (for example, higher than 80%), but the success rate of applying for memory greater than A bytes is very low (for example, lower than 20%), then the above-mentioned first threshold value can be set to A bytes. In some embodiments, the first threshold value can also be adjusted according to the memory usage. For example, if insufficient memory is detected (the number of running processes the day after tomorrow is greater than a certain number), the initially set first threshold value can be adjusted down.
[0017] In combination with the first aspect, in a possible implementation manner, the method further includes:
[0018] When the memory demand is less than the first threshold, memory is requested from the second type of storage unit.
[0019] In this embodiment, the memory demand is first determined, and then the method of applying for memory is selected based on the size of the memory demand. When the memory demand is greater than a first threshold, memory is applied from a first type of storage unit that is easy to apply for memory. When the memory demand is less than the first threshold, memory is directly applied from a second type of storage unit, which can improve memory application efficiency.
[0020] It can be understood that when the memory demand is equal to the first threshold, memory can be applied from the above-mentioned second type of storage unit, or from the first type of storage unit. The specific setting can be based on actual conditions, and this application does not limit this.
[0021] In combination with the first aspect, in a possible implementation manner, the method further includes:
[0022] In case that the memory application from the second type storage unit fails, the memory is applied from the first type storage unit.
[0023] It can be understood that the second type of storage unit itself is a memory unit with high operating efficiency. Although memory is requested from the second type of storage unit only when the memory demand is less than 100%, it is inevitable that there is a serious shortage of memory, resulting in a situation where it is difficult to request memory even if the memory demand is small. Therefore, in this embodiment, if the memory request from the second type of storage unit fails, the memory is requested from the first type of storage unit, which can reduce the probability of memory request failure.
[0024] In the embodiment of the present application, when the first type of storage unit is virtual memory and the second type of storage unit is physical memory, the vmalloc function can be used to apply for memory from the first type of storage unit to obtain virtual memory; and the kmalloc function can be used to apply for memory from the second type of storage unit to obtain physical memory. Optionally, in the above embodiment, when applying for memory from the second type of storage unit, if the application for memory from the second type of storage unit fails, the application for memory from the above first type of storage unit can be implemented by the kvmalloc function. In the above case, the first threshold can be set to 4KB.
[0025] When the execution subject is an electronic device or a kernel program, the specific implementation example of this embodiment can be found in Figure 5 .
[0026] In combination with the first aspect, in a possible implementation manner, the kernel program of the electronic device includes a hook function; and the receiving of the system message includes:
[0027] The memory request function receives the system message sent by the hook function, and the memory request function is other programs outside the kernel program.
[0028] In this embodiment, the kernel program includes a hook function, which can be understood as the kernel program includes a hook point. For the relevant description of the hook point, please refer to the introduction of Figure 7(a), which will not be repeated here.
[0029] Optionally, the operating environment of the hook function includes a function declaration of the hook function and an export function of the hook function; the function declaration is used to define the function name, function type and input parameters of the above hook function, and the export function is used to enable the above hook function to be called by the above kernel program.
[0030] Optionally, the operating environment of the above-mentioned memory application function includes a registration function of the above-mentioned memory application function, and the above-mentioned registration function is used to bind the above-mentioned memory application function with the above-mentioned hook function.
[0031] In this embodiment, the execution subject is a memory request function, and the hook function in the kernel program is bound to the memory request function. The memory request function receives a system message through the hook function to instruct the memory request function to determine the memory demand and from which storage unit to request the memory. For example, when the memory demand is greater than a first threshold, the memory is requested from a first type of storage unit; when the memory demand is less than the first threshold, the memory is requested from a second type of storage unit; and when the memory request from the second type of storage unit fails, the memory is requested from the first type of storage unit.
[0032] It can be understood that the hook function belongs to the kernel program, and the memory request function is a program other than the kernel program. It can be understood that the memory request function is located in the self-developed code warehouse. For the exemplary method of registering the function and binding the hook function and the memory request function, please refer to the relevant introduction of Figure 7(b). When the first type of storage unit is virtual memory and the second type of storage unit is physical memory, the specific implementation example of this embodiment can be referred to Figure 6 .
[0033] It is understandable that in some areas the code logic in the kernel program cannot be directly modified. Therefore, this embodiment decouples the memory application function through a hook function and implements the memory application function through a memory application function, which can adapt to scenarios where the kernel program cannot be modified.
[0034] In combination with the first aspect, in a possible implementation manner, the method further includes:
[0035] When the memory request function fails to request memory from the first type of storage unit and fails to request memory from the second type of storage unit, the kernel program requests memory from the second type of storage unit, or the kernel program requests memory from the first type of storage unit.
[0036] It is understandable that the memory application function is located outside the kernel program, such as in the self-developed code warehouse. There may be a situation where the hook function is included in the kernel program, but the memory application function does not exist in the self-developed code warehouse. In this embodiment, when the memory application function fails to apply for memory, the kernel program continues to apply for memory, thereby reducing the probability of memory application failure caused by the failure of the pseudo-kernel program to call the memory application function.
[0037] When the first type of storage unit is virtual memory and the second type of storage unit is physical memory, the kernel program applies for memory from the second type of storage unit, or the kernel program applies for memory from the first type of storage unit can be implemented by using the kvmalloc function. For specific implementation examples, see Figure 8 .
[0038] In a second aspect, an embodiment of the present application provides a device, comprising a unit for executing the method in the first aspect or any possible implementation of the first aspect.
[0039] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory; the internal memory of the memory comprises a first type of storage unit and a second type of storage unit, and the operating efficiency of the second type of storage unit is higher than the operating efficiency of the first type of storage unit; the memory is coupled to the processor, and the memory is used to store computer program code, and the computer program code comprises computer instructions, and the processor calls the computer instructions so that the method in the first aspect or any possible implementation of the first aspect is executed.
[0040] In a fourth aspect, an embodiment of the present application provides a chip, including a logic circuit and an interface, wherein the logic circuit and the interface are coupled; the interface is used to input and / or output code instructions, and the logic circuit is used to execute the code instructions, so that the method in the first aspect or any possible implementation of the first aspect is executed. It can be understood that the first type of storage unit and the second type of storage unit can both be in the chip, or the second type of storage unit is located in the chip and the first type of storage unit is located outside the chip.
[0041] In a fifth aspect, an embodiment of the present application provides a computer program product, wherein the computer program product includes program instructions, and when the program instructions are executed by a processor, the method in the first aspect or any possible implementation of the first aspect is executed.
[0042] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer program runs on a processor, the method in the first aspect or any possible implementation of the first aspect is executed. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0044] Figure 1 It is a schematic diagram of memory fragmentation formed in memory allocation provided by an embodiment of the present application;
[0045] Figure 2 is a structural diagram of an electronic device 100 provided in an embodiment of the present application;
[0046] Figure 3 It is a software structure diagram provided by the embodiment of the application itself;
[0047] Figure 4 It is a flowchart of a memory allocation method provided in an embodiment of the present application;
[0048] Figure 5 It is a flowchart of a memory application method provided in an embodiment of the present application;
[0049] Figure 6 It is a flowchart of another memory application method provided in an embodiment of the present application;
[0050] FIG. 7( a ) is an execution flow chart of a program including a hook point provided in an embodiment of the present application;
[0051] FIG7( b ) is a flowchart of binding a memory request function to a hook function provided by an embodiment of the present application;
[0052] Figure 8 This is a flowchart of another memory application method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] The terms used in the following embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to be used as limitations to the present application. As used in the specification and appended claims of the present application, the singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to also include plural expressions, unless there is a clear indication to the contrary in the context. It should also be understood that the term "and / or" used in the present application refers to and includes any or all possible combinations of one or more listed items.
[0054] The terms "first" and "second" in the specification, claims and drawings of this application are used to distinguish different objects, rather than to describe a specific order. It should also be understood that in the embodiments of this application, the numbers before the steps are made for ease of understanding and scheme description, and should not be understood as limiting the order in which the steps are executed.
[0055] The memory application method and related devices provided in the embodiments of the present application enable an electronic device to first calculate the memory requirement for storing the data when applying for memory to store data, and then apply for memory in different ways based on the memory requirement. The present application can improve the efficiency of memory application, that is, apply for memory faster.
[0056] To facilitate understanding, the following first introduces the terms involved in the embodiments of the present application.
[0057] 1. Effect parameters
[0058] In the embodiments of the present application, the effect parameters can be understood as parameters used to affect the sensory experience of the user. For example, the effect parameters can be effect parameters for dynamic display, such as color data for dynamic display; they can also be effect parameters for audio playback, such as setting parameters for an equalizer; they can also be effect parameters for video playback, such as setting parameters for an equalizer during video playback, color data, etc.
[0059] Take the effect parameters of the dynamic display in mobile phones as an example. With the popularity of mobile phones, people have higher and higher requirements for the stability, smoothness and aesthetics of mobile phone systems. In order to improve the aesthetics of mobile phone systems, mobile phone manufacturers will add dynamic effects when the mobile phone starts / exits applications (applications, APPs), making the mobile phone look smoother and better, thereby improving the user experience.
[0060] During the animation playback process, the upper layer of the mobile phone system will send down the effect parameters, and then pass the effect parameters to the bottom layer, and the display driver will control the screen to display a better effect according to the effect parameters. For example, the effect parameters sent down during the animation playback process can be the color parameters of the animation.
[0061] Take the effect parameters of audio playback in a mobile phone as an example. Users can play songs through the music player application in the mobile phone. In order to enhance the user's auditory experience, the mobile phone provides a variety of sound effects, and users can choose different sound effects to play songs. It can be understood that different sound effects correspond to different effect parameters. After the user selects a certain sound effect, the upper layer of the mobile phone system will send down the effect parameters, and then pass the effect parameters to the bottom layer, and the audio driver will control the playback effect of the song according to the effect parameters.
[0062] 2. Memory
[0063] The running memory provides storage functions for the operating system and various programs during the operation of the electronic device, which can be figuratively understood as the memory required when the program is running. Exemplarily, the running memory can be a random access memory (RAM), and the RAM can directly exchange data with the central processing unit (CPU). In the embodiment of the present application, the running memory can also be referred to as memory or main memory.
[0064] For example, after a user opens an application, the electronic device will allocate a certain amount of memory space for the application and then create a process for the application. During the running of the application, the application will occupy the allocated memory until the application is closed, and the electronic device will release the memory allocated for the application. Therefore, it can be understood that the size of the running memory can determine the programs that the electronic device can run. The larger the running memory, the more programs the electronic device can run at the same time.
[0065] Physical memory can be understood as the memory space obtained through the physical memory stick, or it can be understood as the memory space that can be directly addressed by the CPU. It can be understood that in the process of memory allocation, electronic devices will give priority to allocating physical memory with continuous addresses, that is, continuous physical memory. After multiple continuous physical memory allocations and the release of part of the continuous physical memory, the unallocated memory space between the allocated memory may form memory fragments.
[0066] For ease of understanding, please refer to Figure 1 , Figure 1 Schematic diagram of memory fragmentation in memory allocation provided by an embodiment of the present application. Assume that the electronic device has allocated continuous physical memory to process A, process B and process C respectively. Figure 1 As shown in (a), process A occupies memory space 0-2, process B occupies memory space 3-6, and process C occupies memory space 7-13. After releasing process B, the memory space 3-6 originally occupied by process B is released, as shown in Figure 1 As shown in (b) in .
[0067] After the memory space occupied by process B is released, if the newly created process D requires a memory space of size 10, the memory space 3-6 freed up by releasing process B will not be able to adapt to process D, resulting in memory fragmentation.
[0068] It is understandable that as more and more programs are run on electronic devices, the number of memory fragments will increase, and the allocable continuous physical memory resources will be insufficient. In order to alleviate the above problems, virtual memory technology can be used. Electronic devices can allocate virtual memory to programs through virtual memory technology, so that programs believe that they have continuous physical memory. But in fact, virtual memory is memory fragments in the running memory or logical memory virtualized by using disk space.
[0069] In the embodiment of the present application, the effect parameters may be stored in the physical memory or in the virtual memory.
[0070] The method provided in the embodiment of the present application can be executed by an electronic device. The electronic device provided in the embodiment of the present application is described below. Figure 2 , Figure 2 It is a structural diagram of an electronic device 100 provided in an embodiment of the present application.
[0071] The electronic device 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 camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an acceleration sensor 180C, a fingerprint sensor 180D, a temperature sensor 180E, a touch sensor 180F, an ambient light sensor 180G, etc.
[0072] It is understandable that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0073] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0074] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0075] 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.
[0076] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0077] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple groups of I2C buses. The processor 110 may be coupled to the touch sensor 180F, the charger, the flash, the camera 193, etc. through different I2C bus interfaces. For example: the processor 110 may be coupled to the touch sensor 180F through the I2C interface, so that the processor 110 communicates with the touch sensor 180F through the I2C bus interface, thereby realizing the touch function of the electronic device 100.
[0078] The I2S interface can be used for audio communication. In some embodiments, the processor 110 can include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to achieve communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 can transmit an audio signal to the wireless communication module 160 via the I2S interface to achieve the function of answering a call through a Bluetooth headset.
[0079] The PCM interface can also be used for audio communication, sampling, quantizing and encoding analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 can be coupled via a PCM bus interface. In some embodiments, the audio module 170 can also transmit audio signals to the wireless communication module 160 via the PCM interface to realize the function of answering calls via a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
[0080] The UART interface is a universal serial data bus for asynchronous communication. The bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some embodiments, the UART interface is generally used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 through the UART interface to implement the Bluetooth function. In some embodiments, the audio module 170 can transmit an audio signal to the wireless communication module 160 through the UART interface to implement the function of playing music through a Bluetooth headset.
[0081] The MIPI interface can be used to connect the processor 110 with peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. In some embodiments, the processor 110 and the camera 193 communicate via the CSI interface to implement the shooting function of the electronic device 100. The processor 110 and the display screen 194 communicate via the DSI interface to implement the display function of the electronic device 100.
[0082] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or as a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 with the camera 193, the display 194, the wireless communication module 160, the audio module 170, the sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.
[0083] The USB interface 130 is an interface that complies with the USB standard specification, and specifically can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 can be used to connect a charger to charge the electronic device 100, and can also be used to transfer data between the electronic device 100 and a peripheral device. It can also be used to connect headphones to play audio through the headphones. The interface can also be used to connect other electronic devices, such as AR devices, etc.
[0084] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0085] The charging management module 140 is used to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive wireless charging input through a wireless charging coil of the electronic device 100. While the charging management module 140 is charging the battery 142, it may also power the electronic device through the power management module 141.
[0086] 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. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle number, battery health status (leakage, impedance), etc. In some other embodiments, the power management module 141 can also be set in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 can also be set in the same device.
[0087] The wireless communication function of the electronic device 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.
[0088] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 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.
[0089] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 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, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.
[0090] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 170A, a receiver 170B, etc.), or displays a picture or video through a display screen 194. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.
[0091] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can 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 frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0092] In some embodiments, the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology. The GNSS may include a global positioning system (GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS) and / or a satellite based augmentation system (SBAS).
[0093] The electronic device 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.
[0094] The display screen 194 is used to display pictures, 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. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1. In some embodiments, the display screen 194 can be used for dynamic effect display.
[0095] 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 electronic device 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.
[0096] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, a picture or video playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 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.
[0097] In some embodiments, the internal memory 121 may also be referred to as a memory, and the storage resources in the memory may be allocated to various programs as continuous physical memory. Optionally, part of the storage resources in the memory and part of the storage resources in the external memory card may be allocated to various programs as virtual memory.
[0098] The electronic device 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 headphone jack 170D, and the application processor.
[0099] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.
[0100] The speaker 170A, also called a horn, is used to convert audio electrical signals into sound signals.
[0101] The receiver 170B, also called an earpiece, is used to convert an audio signal into a sound signal. When the electronic device 100 receives a call or a voice message, the voice can be received by placing the receiver 170B close to the ear.
[0102] Microphone 170C, also known as a microphone or a microphone, is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can make a sound by approaching the microphone 170C with his mouth to input the sound signal into the microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In other embodiments, the electronic device 100 can be provided with two microphones 170C, which can not only collect sound signals but also realize noise reduction function. In other embodiments, the electronic device 100 can also be provided with three, four or more microphones 170C to realize the collection of sound signals, noise reduction, identification of sound sources, realization of directional recording function, etc.
[0103] The earphone interface 170D is used to connect a wired earphone and can be a USB interface 130 or a 3.5 mm open mobile terminal platform (OMTP) standard interface.
[0104] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be disposed on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. A capacitive pressure sensor can be a device including at least two parallel plates with conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes.
[0105] The electronic device 100 can determine the intensity of the pressure based on the change in capacitance. Exemplarily, when a touch operation acts on the display screen 194, the electronic device 100 detects the touch operation intensity based on the pressure sensor 180A. Also exemplarily, the electronic device 100 can also calculate the touch position based on the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than a first pressure threshold acts on a short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on a short message application icon, an instruction to create a new short message is executed.
[0106] The gyro sensor 180B can be used to determine the motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (i.e., x, y, and z axes) can be determined by the gyro sensor 180B. The gyro sensor 180B can be used for anti-shake shooting. For example, when the shutter is pressed, the gyro sensor 180B detects the angle of the electronic device 100 shaking, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to offset the shaking of the electronic device 100 through reverse movement to achieve anti-shake. The gyro sensor 180B can also be used for navigation and somatosensory game scenes.
[0107] The acceleration sensor 180C can detect the magnitude of the acceleration of the electronic device 100 in all directions (generally three axes). When the electronic device 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of the electronic device and is applied to applications such as horizontal and vertical screen switching and pedometers.
[0108] The fingerprint sensor 180D is used to collect fingerprints. The electronic device 100 can use the collected fingerprint characteristics to achieve fingerprint unlocking, access application locks, fingerprint photography, fingerprint call answering, etc.
[0109] The temperature sensor 180E is used to detect temperature. In some embodiments, the electronic device 100 uses the temperature detected by the temperature sensor 180E to execute a temperature processing strategy. For example, when the temperature reported by the temperature sensor 180E exceeds a threshold, the electronic device 100 reduces the performance of a processor located near the temperature sensor 180E to reduce power consumption and implement thermal protection. In other embodiments, when the temperature is lower than another threshold, the electronic device 100 heats the battery 142 to avoid abnormal shutdown of the electronic device 100 due to low temperature. In other embodiments, when the temperature is lower than another threshold, the electronic device 100 boosts the output voltage of the battery 142 to avoid abnormal shutdown caused by low temperature.
[0110] The touch sensor 180F is also called a "touch panel". The touch sensor 180F can be arranged on the display screen 194, and the touch sensor 180F and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180F is used to detect touch operations acting on or near it. The touch sensor 180F can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180F can also be arranged on the surface of the electronic device 100, which is different from the position of the display screen 194.
[0111] The ambient light sensor 180G is used to sense the ambient light brightness. The electronic device 100 can adaptively adjust the brightness of the display screen 194 according to the perceived ambient light brightness. The ambient light sensor 180G can also be used to automatically adjust the white balance when taking pictures. The ambient light sensor 180G can also cooperate with the proximity light sensor 180G to detect whether the electronic device 100 is in a pocket to prevent accidental touches.
[0112] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to and separated from the electronic device 100 by inserting it into the SIM card interface 195 or pulling it out from the SIM card interface 195. The electronic device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, and the like. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The electronic device 100 interacts with the network through the SIM card to implement functions such as calls and data communications. In some embodiments, the electronic device 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100.
[0113] In other embodiments, the processor 110 may call computer instructions stored in the internal memory 121 to implement the memory application method provided in the embodiments of the present application.
[0114] Exemplarily, the processor 110 can call the computer instructions stored in the internal memory 121, calculate the memory requirement required for storing the effect parameters, and then apply for memory in different ways according to the size of the memory requirement. Exemplarily, the computer instructions can apply for continuous physical memory or virtual memory.
[0115] It is understandable that the software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture, and this application does not limit this. Figure 3 , Figure 3 This is a software structure diagram provided by the embodiment of the present application. Figure 3 The layered architecture shown divides the software into several layers. Each layer has a clear role and division of labor, and the layers can communicate through software interfaces.
[0116] In some embodiments, the system of the electronic device can be divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the system runtime layer, the hardware abstraction layer (HAL) and the kernel layer. The description of each of the above layers is as follows:
[0117] The application layer may include a series of application packages. For example, the application packages of the application layer may include applications such as camera, gallery, calendar, call, map, navigation, browser, music, video, and short message.
[0118] The application framework layer can provide an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer can include some predefined functions.
[0119] Exemplarily, the application framework layer may include an activity manager, a window manager, a content provider, a view system, a telephony manager, a resource manager, a notification manager, and an accelerated graphics port (AGP). Among them:
[0120] The activity manager can be used to manage the individual application lifecycles as well as general navigation back functionality.
[0121] The window manager can be used to manage window programs. For example, the window manager can obtain the display screen size of the electronic device 100, lock the screen, capture the screen, and determine whether there is a status bar.
[0122] Content providers can be used to store and retrieve data and make the data accessible to applications so that different applications can access or share data. For example, the data may include videos, images, audio, calls made and received, browsing history and bookmarks, and phone books.
[0123] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0124] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including answering a call, hanging up a call, etc.).
[0125] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, etc.
[0126] The notification manager enables applications to display notification information in the status bar, which can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager can be used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the top status bar of the system in the form of a chart or scroll bar text, such as a notification of an application running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is prompted in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0127] AGP in the application framework layer can be used to improve the rendering performance of the graphics card, such as providing the graphics card with more cache capacity to achieve faster image processing speed.
[0128] The system runtime layer may include system libraries and Android runtime.
[0129] The Android runtime includes 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 object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0130] The system library can be understood as the support of the application framework, and is an important link between the application framework layer and the kernel layer. The system layer can include multiple functional modules, such as surface managers, media libraries, 3D graphics processing libraries (such as OpenGL ES), 2D graphics engines (such as SGL), etc. Among them:
[0131] The surface manager can be used to manage the display subsystem, for example, when the electronic device 100 executes multiple applications, it is responsible for managing the interaction between display and access operations. The surface manager can also be used to provide fusion of two-dimensional and three-dimensional layers for multiple applications.
[0132] The media library can support playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0133] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing.
[0134] A two-dimensional graphics engine can be understood as a drawing engine for two-dimensional drawing.
[0135] The hardware abstraction layer provides a standard interface, such as the HAL interface definition language (HIDL) interface or the Android interface definition language (AIDL) interface.
[0136] The kernel layer can be understood as an abstract layer between hardware and software. The kernel layer may include system services such as security, memory management, process management, power management, network protocol management, and driver management. Exemplarily, the kernel layer may include display drivers, camera drivers, audio drivers, and sensor drivers. Optionally, the kernel layer may also be called an Android kernel. Exemplarily, the hardware layer of an electronic device may include a touch panel (TP), a liquid crystal display (LCD), and the like.
[0137] In some embodiments, a sensor driver (such as a touch sensor driver) is used to respond to user operations (such as click operations to open / close an application), generate events to trigger the activity manager in the application framework layer to open or close an application, and generate events to trigger the view system in the application framework layer to create a view. The display driver can control the display screen to display the created view.
[0138] In other embodiments, a sensor driver (such as a touch sensor driver) is used to respond to user operations (such as a click operation to open / close an application) and generate events to trigger the AGP in the application framework layer to generate effect parameters. Optionally, the AGP can send the effect parameters to the Android kernel. After receiving the effect parameters, the Android kernel can apply to the system for memory for storing the effect parameters, and then the display driver can process the effect parameters and control the display screen to display according to the effect parameters.
[0139] When the Android kernel requests memory for storing the effect parameters of the dynamic effect display, you can use the following method: Figure 4 The method shown, Figure 4 is a flowchart of a memory allocation method provided in an embodiment of the present application. Figure 4 As shown, the method includes:
[0140] 401: APP dynamic effect display.
[0141] In this step, the APP can be any APP installed in the electronic device, it can be a system APP or a third-party APP, and this application does not limit this.
[0142] Exemplarily, the electronic device can start or exit an APP according to the user operation. Exemplarily, the touch sensor driver of the electronic device can detect the user operation of opening or closing the APP. During the startup or exit process, the electronic device can display animation effects, such as flip animation effects, sliding animation effects, gradient animation effects, etc. It can be understood that in addition to displaying animation effects when starting or exiting an APP, animation effects can also be displayed in the case of hiding and displaying interface elements, interface buffering, and interface transitions, and AGP can also generate effect parameters accordingly.
[0143] It can be understood that the APP is located in the application layer of the software architecture. Therefore, the APP dynamic effect display can be understood as the APP in the application layer is ready to start the dynamic effect display.
[0144] 402: Generate effect parameters.
[0145] When the touch sensor driver detects that the APP needs to display dynamic effects, it can trigger the AGP of the application framework layer to generate effect parameters. The effect parameters can be understood as display content parameters of the dynamic effect display, such as color parameters during the dynamic effect display process, etc., which can be specifically a list, and this application does not limit this.
[0146] In this step, the effect parameter should be understood as a collection (or collective name) of multiple parameters used to reflect the display content, and should not be understood as one parameter.
[0147] 403: Use the kvmalloc function to allocate memory.
[0148] After AGP generates the effect parameters, it can send them to the kernel layer. At the kernel layer, the Android kernel will use the kvmalloc function to apply for memory to store the effect parameters. Figure 4 Apply for memory in steps 4031 to 4034:
[0149] 4031: Use the kmalloc function to apply for continuous physical memory.
[0150] It can be understood that the kvmalloc function and the kmalloc function are two functions. In the implementation logic of the kvmalloc function to apply for memory, the kmalloc function will be used first to apply for continuous physical memory. Therefore, the kmalloc function can be understood as a part of the implementation logic of the kvmalloc function.
[0151] 4032: Determine whether the continuous physical memory is successfully applied for.
[0152] If the result of the judgment in step 4032 is no, execute step 4033: apply for virtual memory using the vmalloc function.
[0153] After step 4033, step 4034 is executed: get the allocated memory. In this case, the memory applied for by the Android kernel is virtual memory, that is, the allocated memory is virtual memory. It can be understood that the virtual address space of the memory allocated using the vmalloc function is continuous, and the corresponding physical memory may not be continuous.
[0154] If the result of the judgment in step 4032 is yes, step 4034 is executed: obtaining the allocated memory. In this case, the memory applied for by the Android kernel is continuous physical memory, that is, the allocated memory is continuous physical memory.
[0155] In some embodiments, after applying for memory (which can be understood as obtaining address information of the memory space), a binary large object (blob) can be used to transfer the applied memory, and then the effect parameters of the animation can be processed and displayed.
[0156] 404: Create blob.
[0157] In the embodiment of the present application, blob can be understood as a container for storing binary files. It can be understood that the address information of the memory space obtained after applying for the memory is also data, and the address information of the memory space can be passed to the relevant driver by creating a blob.
[0158] 405: Processing effect parameters.
[0159] In this step, the display driver of the kernel layer can process the effect parameters and display the result on the display screen. It is understandable that after the dynamic effect is displayed, the kernel layer can release the memory allocated in step 4034.
[0160] The essence of the kvmalloc function is to first use the kmalloc function to apply for continuous physical memory, and then use the vmalloc function to apply for virtual memory if it fails. It can be understood that after using the kmalloc function to apply for continuous physical memory in step 4031, there will be a waiting period. If the continuous physical memory is not successfully applied for within the waiting period, the Android kernel will use the vmalloc function to apply for virtual memory.
[0161] It is easy to understand that if there are too many applications running in the background, the Android kernel will take too long to apply for memory when playing animations due to insufficient memory, resulting in frame drops and stuttering, which seriously affects the user experience. Similarly, if there are too many applications running in the background, the Android kernel will take too long to apply for memory after selecting sound effects due to insufficient memory, resulting in stuttering, which seriously affects the user experience.
[0162] In order to improve the efficiency of memory application, the present application embodiment provides a memory application method. Figure 3 The memory application method provided in the embodiment of the present application can be implemented by the memory application module in the kernel layer.
[0163] In a possible implementation, the memory application module can be coupled to the Android kernel. For ease of understanding, for example, please refer to Figure 5 , Figure 5 It is a flowchart of a memory application method provided in an embodiment of the present application.
[0164] 501: APP dynamic effect display.
[0165] 502: Generate effect parameters.
[0166] For the above steps 501 and 502, reference may be made to the related introduction of the above steps 401 and 402, which will not be repeated here.
[0167] 503: Determine the memory requirement for storing the effect parameters.
[0168] In this step, after receiving the effect parameter, the Android kernel determines the memory requirement required to store the effect parameter. Exemplarily, the storage space required for the effect parameter in the memory can be obtained through the keyword sizeof.
[0169] 504: Determine whether the memory requirement is greater than or equal to the target threshold.
[0170] In this step, the target threshold value may be a value set in advance, which may be determined specifically based on the performance of the kvmalloc function. For example, the kvmalloc function is faster when applying for continuous physical memory within 4KB, but slower when applying for continuous physical memory above 4KB, then the target threshold value may be set to 4KB. Optionally, when setting the target threshold value, the value may be appropriately increased or decreased according to the needs.
[0171] If the result of the determination in step 504 is no, step 505 is executed: applying for memory using the kvmalloc function.
[0172] It can be understood that when the memory requirement is less than the target threshold, it can be considered that the memory requirement for storing the effect parameters is small. At this time, it is more efficient to apply for memory using the kvmalloc function. The specific implementation method of using the kvmalloc function to apply for memory in this step can refer to the introduction of steps 4031-4034, which will not be repeated here. According to the introduction of steps 4031-4034, it can be understood that the memory applied for in this step may be continuous physical memory or virtual memory.
[0173] If the result of the determination in step 504 is yes, step 506 is executed: applying for virtual memory using the vmalloc function.
[0174] It is understandable that when the memory requirement is greater than or equal to the target threshold, it can be considered that the memory requirement for storing the effect parameters is large and the probability of applying for continuous physical memory is small. In this embodiment, when the judgment result of step 504 is yes, the vmalloc function is used to apply for virtual memory.
[0175] It is understandable that in the above case, if continuous physical memory is applied first, and virtual memory is applied after the continuous physical memory application fails, the waiting time for applying continuous physical memory during this period is a waste. Therefore, in this embodiment, it is more efficient to directly use the vmalloc function to apply for virtual memory.
[0176] After the memory is applied for in step 505 or step 506, step 507 is executed: creating a blob.
[0177] 508: Processing effect parameters.
[0178] For the above steps 507 and 508, reference may be made to the related introduction of the above steps 404 and 405, which will not be repeated here.
[0179] It is understandable that in some regions, the code logic in the Android kernel cannot be directly modified. Therefore, in another possible implementation method, the memory application function of the memory application module can be decoupled through a hook mechanism and implemented in the self-developed code repository. Among them, the self-developed code repository can be understood as a program other than the official Android kernel.
[0180] For ease of understanding, please refer to Figure 6 , Figure 6 It is a flowchart of another memory application method provided in an embodiment of the present application.
[0181] 601: APP dynamic effect display.
[0182] 602: Generate effect parameters.
[0183] 603: Call the memory allocation function through the hook function.
[0184] To facilitate understanding of the hook mechanism, illustratively, please refer to FIG. 7( a ), which is an execution flow chart of a program including a hook point provided in an embodiment of the present application.
[0185] It is understandable that programs such as application trigger events and background logic processing are executed step by step according to the event flow. When the program includes a hook point, if the program is executed to the hook point according to the original execution path of the program, the target function bound to the hook point will be called, and after the target function is executed, it will return and execute the program after the hook point, thereby restoring the original execution path.
[0186] In the embodiment of the present application, the hook point can also be understood as the location of the hook function in the program. It can be understood that after the hook function is bound to the memory application function, when the program executes to the hook point, the corresponding memory application function will be automatically called. In this embodiment, the memory application function is used to implement the memory application function of the memory application module. The processing flow of the memory application function includes steps 604-607:
[0187] 604: Determine the memory requirement for storing the effect parameters.
[0188] 605: Determine whether the memory requirement is greater than or equal to the target threshold.
[0189] If the result of the determination in step 605 is no, step 606 is executed: applying for memory using the kvmalloc function.
[0190] If the result of the determination in step 605 is yes, step 607 is executed: applying for virtual memory using the vmalloc function.
[0191] For the introduction of step 604-step 607, please refer to the above step 503-step 506, which will not be repeated here. For the specific implementation method of using the kvmalloc function to apply for memory in this step, please refer to the introduction of step 4031-step 4034, which will not be repeated here. It can be understood that after applying for memory using the memory application function in this embodiment, the memory obtained may be continuous physical memory or virtual memory.
[0192] After the memory is applied for in step 606 or step 607, step 608 is executed: creating a blob.
[0193] 609: Processing effect parameters.
[0194] For the introduction of step 608 and step 609, please refer to the above steps 404 and 405, which will not be repeated here.
[0195] In this embodiment, the memory application function in the Android kernel is decoupled through the hook function, and the memory application logic is optimized in the memory application function of the self-developed code warehouse, that is, different memory application methods are used according to effect parameters of different sizes, which can improve the efficiency of memory application without affecting the code logic of the official Android kernel. Therefore, the method provided in this embodiment can be used in areas where the Android kernel is allowed to be modified, and can also be used in areas where the Android kernel is not allowed to be modified, thereby improving the user experience in various regions.
[0196] It can be understood that before calling the memory application function through the hook function (step 603), the memory application function is also bound to the hook function. The specific implementation of binding the memory application function to the hook function is introduced below. For example, please refer to Figure 7(b), which is a flowchart of binding a memory application function to a hook function provided by an embodiment of the present application. It includes:
[0197] 701: Add a custom header file in the include / trace / hooks / directory and declare the hook function in the custom header file.
[0198] The include / trace / hooks / directory can be figuratively understood as a hook folder, which is used to store the created hooks. In this step, the custom header file is a .h file, which is used to store function declarations, macro definitions, and function prototypes. Exemplarily, the name of the custom file can be drm_property.h. It should be understood that the name of the custom header file can be modified according to actual needs, and this application does not limit this.
[0199] Optionally, if a module (such as a display module, audio module, or video module) has already implemented a hook function decoupling solution to solve other problems, then the include / trace / hooks / directory must already include a header file that declares the hook function. In this case, you can directly add code to the existing header file to implement memory request-related code.
[0200] In this step, after adding a custom header file in the include / trace / hooks / directory, you also need to declare the hook function in the custom header file, or it can be understood as defining the hook interface required by the memory application solution in this application. For example, the content in the custom header file can be:
[0201] 1.#undef TRACE_SYSTEM
[0202] 2.#define TRACE_SYSTEM drm_property
[0203] 3. #undef TRACE_INCLUDE_PATH
[0204] 4.#define TRACE_INCLUDE_PATH trace / hooks
[0205] 5. #if! defined(_TRACE_HOOK_DRM_PROPERTY_H)||defined(TRACE_HEADER_MULTI_READ)
[0206] 6.#define_TRACE_HOOK_DRM_PROPERTY_H
[0207] 7. #include<trace / hooks / vendor_hooks.h>
[0208] 8.DECLARE_HOOK(android_vh_drm_property_alloc,
[0209] TP_PROTO(size_t size,void*drm_property),
[0210] TP_ARGS(size,drm_property));
[0211] 9.#endif
[0212] 10. #include<trace / define_trace.h>
[0213] It should be understood that the numbering before each line of code in the embodiments of the present application is for the convenience of description and should not be understood as the content that must be included in the code, nor should it be understood as the execution order of the code. The first and second lines of code above are macro definitions. The first line of code indicates that when TRACE_SYSTEM is defined, the definition is removed; the second line of code indicates that the drm_property macro is defined as TRACE_SYSTEM to avoid repeated definitions. Similarly, the third and fourth lines of code above are also macro definitions. The third line of code indicates that when TRACE_INCLUDE_PATH is defined, the definition is removed; the fourth line of code indicates that the dtrace / hooks macro is defined as TRACE_INCLUDE_PATH.
[0214] The code from lines 5 to 9 above is conditional compilation, and the format used is:
[0215] #if! defined(condition)
[0216] Statements
[0217] #endif
[0218] If the condition is met, the above statement is compiled, where the above statement can be understood as a general term for multiple statements; if the condition is not met, it ends directly. Therefore, the above code lines 5 to 9 mean that the code lines 6 to 8 are compiled when _TRACE_HOOK_DRM_PROPERTY_H and TRACE_HEADER_MULTI_READ are not defined.
[0219] The sixth line of code indicates the macro definition _TRACE_HOOK_DRM_PROPERTY_H. The seventh line of code indicates that the trace / hooks / vendor_hooks.h header file is included in the include / trace / hooks / drm_property.h file. The eighth line of code indicates the declaration of the hook function. The format of the DECLARE_HOOK function is:
[0220] DECLARE_HOOK(hook function name,
[0221] TP_PROTO (hook function input parameter type),
[0222] TP_ARGS (name of hook function input parameter));
[0223] Therefore, the 8th line of code is used to declare a hook function named android_vh_drm_property_alloc, and the hook function has two input parameters, the first input parameter type is an unsigned integer data type size_t, named size; the second input parameter type is an untyped pointer data type void*, named drm_property. In the embodiment of the present application, the first input parameter size is the memory requirement required to store the effect parameters, and the second input parameter is a flag bit, which is used to indicate whether the hook function is successfully called. If the call is successful, it is set to 1, and if the call is unsuccessful, it is set to 0.
[0224] Similarly, the 10th line of code above indicates that the trace / define_trace.h header file is included in the include / trace / hooks / drm_property.h file.
[0225] 702: Declare the custom header file in the drivers / android / vendor_hooks.c file, and export the hook function.
[0226] Exemplarily, this step can be implemented by the following code:
[0227] 11. #include<trace / hooks / drm_property.h>
[0228] 12.EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_drm_property_alloc);
[0229] The 11th line of code is used to include the header file trace / hooks / drm_property.h added in step 701, so as to include the hook function declared therein, namely, the android_vh_drm_property_alloc function. The 12th line of code is used to export the android_vh_drm_property_alloc function so that the hook function can be called.
[0230] 703: Add a memory request function in the self-developed code repository and register the memory request function.
[0231] In this step, the specific implementation of the memory allocation function can be found in Figure 6 Steps 604 to 607 in the above are not described in detail here. For example, registering the memory request function can be implemented by the following code:
[0232] 13.register_trace_android_vh_drm_property_alloc(memory application function name, NULL);
[0233] 704: Call the custom hook function in the Android kernel code.
[0234] For example, the code for calling the hook function can be added to the code module for memory application, for example, it can be:
[0235] 14.trace_android_vh_drm_property_alloc(size,drm_property);
[0236] It can be understood that the memory request function can be bound to the hook function through the 13th code. After adding the above line 14 of code in the Android kernel, when the program executes to this point, it will call the memory request function bound to the hook function through the hook function, and then execute the code contained in the memory request function, and then return to the original execution order of the Android kernel.
[0237] In the embodiment of the present application, the above-mentioned memory request function may also be referred to as a callback function, and the above-mentioned hook function may also be referred to as a hook interface, that is, the Android kernel may implement the callback function bound to the hook interface through the hook interface.
[0238] It can be understood that the above content about adding hook functions needs to be applied to Google. After the application is approved, the Android kernel can include the codes included in the above steps 701, 702, and 704, and the code of the memory application function in step 703 is stored in the self-developed code warehouse. Exemplarily, the code for registering the memory application function in step 703 can be placed in the Android kernel or in the self-developed code warehouse. In the case of placing it in the self-developed code warehouse, the trace / hooks / drm_property.h header file needs to be included.
[0239] It is understandable that after successfully applying for the hook point, the code in the Android kernel will be modified adaptively, but the memory application function is in the self-developed code repository, not included in the Android kernel code. Therefore, in order to reduce the probability of memory application failure caused by the failure of the Android kernel to call the memory application function, you can use Figure 8 The method shown is used to apply for memory. Figure 8 : is a flowchart of another memory application method provided in an embodiment of the present application, including:
[0240] 801: APP dynamic effect display.
[0241] 802: Generate effect parameters.
[0242] 803: Call the memory allocation function through the hook function.
[0243] 804: Determine the memory requirement for storing the effect parameters.
[0244] 805: Determine whether the memory requirement is greater than or equal to the target threshold.
[0245] If the result of the determination in step 805 is no, step 806 is executed: using the kvmalloc function to apply for memory.
[0246] If the result of the determination in step 805 is yes, step 807 is executed: applying for virtual memory using the vmalloc function.
[0247] 808: Determine whether the memory is successfully applied for through the memory application function.
[0248] In this step, the return value of the memory application function can be used to determine whether the memory is successfully applied for. If the return value is empty, it can be considered that the memory application function has failed to apply for memory. If the return value is valid, it can be considered that the memory application function has successfully applied for memory.
[0249] If the result of the determination in step 808 is no, execute step 809: apply for memory using the kvmalloc function.
[0250] If the result of the determination in step 808 is yes, it can be considered that the memory is successfully applied for through the memory application function, and then step 810 is executed: creating a blob.
[0251] Step 811: Process effect parameters.
[0252] In this embodiment, after the memory application function is called through the hook interface to apply for memory and fails, the memory application function is used. Figure 4 The method shown re-applies for memory, that is, directly uses the kvmalloc function to apply for memory. After successfully applying for memory by calling the memory application function through the hook interface, a blob is created based on the applied memory, and then the effect parameters are processed. The above method can reduce the probability of memory application failure caused by the failure of the Android kernel to call the memory application function.
[0253] It can be understood that the above steps 801 to 805, and the introduction of steps 810 to 811 can be found in Figure 4 The relevant description will not be repeated here.
[0254] It is understandable that the above Figure 4 , Figure 5 , Figure 6 as well as Figure 8 The method shown is introduced by taking the effect parameters of the dynamic effect display as an example, but the application scenario of the method provided by the present application is not limited to this. For example, the effect parameters can also be the sound effect parameters of the music player software or the video player software, or the effect parameters used to modify the picture during the picture editing process, etc.
[0255] The present application also provides a computer-readable storage medium, in which computer codes are stored. When the computer codes are executed on a computer, the computer executes the method of the above embodiment.
[0256] The present application also provides a chip, including a logic circuit and an interface, wherein the logic circuit and the interface are coupled; the interface is used to input and / or output code instructions, and the logic circuit is used to execute the code instructions so that the method in the method of the above embodiment is executed.
[0257] The present application also provides a computer program product, which includes a computer code or a computer program. When the computer code or the computer program runs on a computer, the method in the above embodiment is executed.
[0258] As used in the above embodiments, the term "when..." may be interpreted to mean "if..." or "after..." or "in response to determining..." or "in response to detecting...", depending on the context. Similarly, the phrases "upon determining..." or "if (the stated condition or event) is detected" may be interpreted to mean "if determining..." or "in response to determining..." or "upon detecting (the stated condition or event)" or "in response to detecting (the stated condition or event)", depending on the context.
[0259] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that contains one or more available media integration. The available medium can be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk), etc.
[0260] Those skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by computer programs to instruct related hardware, and the programs can be stored in computer-readable storage media. When the programs are executed, they can include the processes of the above-mentioned method embodiments. The aforementioned storage media include: ROM or random access memory RAM, magnetic disk or optical disk and other media that can store program codes.
[0261] It should also be understood that the above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the above claims.
Claims
1. A memory application method, characterized in that: The method is applied to an electronic device, the electronic device comprising a first type of storage unit and a second type of storage unit, and the method comprises: receiving a system message, wherein the system message is used to instruct storage of data to be stored; Determining the memory requirement required to store the data to be stored; If the memory requirement is greater than or equal to a first threshold, applying for memory from the first type of storage unit; If the memory requirement is less than the first threshold, memory is requested from the second type of storage unit.
2. The method according to claim 1, characterized in that If the memory requirement is less than the first threshold, after applying for memory from the second type of storage unit, the method further includes: If the memory application from the second-type storage unit fails, the memory is applied from the first-type storage unit.
3. The method according to claim 1 or 2, characterized in that: The operating efficiency of the second type of storage cells is higher than the operating efficiency of the first type of storage cells.
4. The method according to any one of claims 1 to 3, characterized in that The first type of storage unit is a virtual memory, and the second type of storage unit is a physical memory.
5. The method according to claim 4, characterized in that: The applying for memory from the second type of storage unit comprises: Use the vmalloc function to apply for memory from the first type of storage unit.
6. The method according to claim 4 or 5, characterized in that: The applying for memory from the first type of storage unit includes: Use the kmalloc function to apply for memory from the second type of storage unit.
7. The method according to any one of claims 1 to 6, characterized in that The first threshold is 4 KB.
8. The method according to any one of claims 1 to 7, characterized in that The data to be stored are effect parameters of dynamic effect display, effect parameters of audio playback or effect parameters of video playback.
9. The method according to any one of claims 1 to 3, characterized in that: The electronic device further comprises a kernel program and a memory application function, wherein the kernel program comprises a hook function; The receiving of the system message includes: the memory application function receiving the system message sent by the hook function.
10. The method according to claim 9, characterized in that: The operating environment of the hook function includes a function declaration of the hook function and an export function of the hook function; the function declaration is used to define the function name, function type and input parameters of the hook function, and the export function is used to enable the hook function to be called by the kernel program.
11. The method according to claim 9 or 10, characterized in that: The operating environment of the memory application function includes a registration function of the memory application function, and the registration function is used to bind the memory application function to the hook function.
12. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory is used to store a computer program, and the memory comprises a first type of storage unit and a second type of storage unit; the computer program comprises program instructions, and the processor is configured to call the program instructions so that the method as described in any one of claims 1 to 11 is executed.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the method according to any one of claims 1 to 11 is executed.