Memory processing method and related device
By differentiating different memory spaces in electronic devices and dynamically adjusting memory allocation and release according to demand, the problem of wasted memory resources is solved, and the efficiency and success rate of memory management are improved.
Patent Information
- Application Number
- CN202311775040.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-24
- Publication Date
- 2025-01-24
AI Technical Summary
In electronic devices, the problem of wasted memory resources arises because the actual amount of memory needed is less than the minimum amount requested, leading to wasted resources.
By distinguishing between the first memory space and the second memory space, memory is requested and released from different memory spaces according to the size of memory demand, ensuring that the amount of memory requested matches the amount of memory demand and reducing resource waste.
It effectively reduces the waste of memory resources, improves the success rate of memory allocation, and optimizes the efficiency of memory management.
Smart Images

Figure CN119357073A_ABST
Abstract
Description
[0001] This application is a divisional application of the invention patent application with application number 202310906332.5 submitted to the China Patent Office, application date July 24, 2023, and invention name “Memory processing method and related device”. Technical Field
[0002] The present application relates to the field of computer technology, and in particular to a memory processing method and related devices. Background Art
[0003] With the continuous development of computer science and technology, the application software functions in electronic devices are becoming more and more powerful. For example, the camera application can provide multiple shooting modes, such as portrait mode, night scene mode, long exposure mode and large aperture mode, etc. Different shooting modes use different shooting parameters to adapt to different shooting scenes and obtain better quality photos.
[0004] Before adopting a certain shooting mode to collect pictures, it is necessary to apply for memory to store the shooting parameters corresponding to the shooting mode. However, the memory applied for is often larger than the memory required for the actual data to be stored, resulting in a waste of memory resources. Summary of the invention
[0005] The embodiments of the present application provide a memory processing method and related devices, which can reduce the waste of memory resources.
[0006] In a first aspect, an embodiment of the present application provides a memory processing method, which is applied to an electronic device, wherein the memory of the electronic device includes a first memory space and a second memory space, and the minimum memory application amount of the first memory space is greater than the minimum memory application amount of the second memory space. The method includes:
[0007] Obtaining a first system message, where the first system message is used to indicate a memory requirement required to store data to be stored;
[0008] When the memory demand is less than the minimum memory application amount of the first memory space, memory is applied for from the second memory space.
[0009] In this embodiment, the execution subject of the memory processing method can be an electronic device or a program in the electronic device, such as a driver or a memory request function in the embodiment of the present application. Where the execution subject is a driver, different types of drivers can be used, which can be determined based on the application scenario. For example, in the storage scenario of shooting parameters, the execution subject can be a camera driver; in the storage scenario of sound effect parameters, the execution subject can be an audio driver.
[0010] In an embodiment of the present application, the memory of the electronic device includes a first memory space and a second memory space, wherein the physical address range included in the first memory space does not overlap with the physical address range included in the second memory space, and therefore, the physical address of the memory requested from the first memory space is different from the physical address of the memory requested from the second memory space.
[0011] The minimum memory application amount of a memory space can be understood as the minimum memory application amount obtained when applying for memory from the memory space. For example, if the minimum memory application amount of memory space A is 10KB, then when applying for memory from memory space A, even if only 5KB of memory is needed, 10KB of memory will be obtained. In the embodiment of the present application, the minimum memory application amount of the first memory space is greater than the minimum memory application amount of the second memory space.
[0012] In an embodiment of the present application, the data to be stored may be any data that can be stored in both the first memory space and the second memory space, such as shooting parameters, sound effect parameters, etc., and the present application does not limit this.
[0013] In the embodiment of the present application, the first system message can be the data to be stored itself, or the amount of data to be stored, or other indication information indicating the amount of data to be stored, and the present application does not limit this. In the embodiment of the present application, the amount of data to be stored can be understood as the memory demand, that is, the amount of memory required to store the data to be stored.
[0014] It should be understood that the memory requirement and the final memory application amount are not necessarily the same. When the memory requirement is less than the minimum memory application amount of the first memory space, the final memory application amount will be greater than the memory requirement, resulting in a waste of memory resources. In this embodiment, when the memory requirement is less than the minimum memory application amount of the first memory space, memory is applied from the second memory space. Since the minimum memory application amount of the second memory space is smaller than the minimum memory application amount of the second memory space, the method provided in this embodiment can reduce the waste of memory resources.
[0015] Optionally, the memory requirement can also be understood as follows Figure 6 and Figure 7 Memory allocation in the illustrated embodiment.
[0016] In combination with the first aspect, in a possible implementation manner, the method further includes:
[0017] When the memory demand is greater than the minimum memory application amount of the first memory space, memory is applied for from the first memory space.
[0018] It can be understood that the larger the minimum memory application amount of the memory space, the more suitable the memory space is for allocating large blocks of memory. In this embodiment, when the memory demand is less than the minimum memory application amount of the first memory space, memory is applied from the second memory space; when the memory demand is greater than the minimum memory application amount of the first memory space, memory is applied from the first memory space, which can reduce resource waste and improve the success rate of memory application when memory is insufficient.
[0019] In some embodiments, when the memory demand is equal to the minimum memory application amount of the first memory space, memory can be applied from the first memory space or from the second memory space, depending on the specific situation.
[0020] In combination with the first aspect, in a possible implementation manner, the kernel program of the electronic device includes a driver and a memory application function, and the memory application function is other programs in the kernel program except the driver; the obtaining of the first system message includes:
[0021] The memory application function receives the first system message sent by the driver.
[0022] In this embodiment, the memory request function receives the system message sent by the driver function, and then requests memory from the second memory space when the memory requirement is less than the minimum memory request amount of the first memory space; or requests memory from the first memory space when the memory requirement is greater than the minimum memory request amount of the first memory space. It can be understood that in one execution process, there will only be one of the above two branches, and the above two branches will be included in multiple executions.
[0023] For a detailed description of this embodiment, please refer to Figure 7 In this embodiment, the memory application function applies for memory according to the memory demand, so memory applications in different scenarios can use the memory application function to reduce memory resource waste, and the operation is simple.
[0024] In combination with the first aspect, in a possible implementation manner, the kernel program of the electronic device further includes a memory release function, and the memory release function is another program in the kernel program except the driver program; the method further includes:
[0025] The memory release function receives a second system message, where the second system message is used to indicate a virtual address of the memory to be released;
[0026] The memory release function determines the physical address of the memory to be released according to the virtual address of the memory to be released;
[0027] In a case where the physical address of the memory to be released is within the physical address range of the first memory space, the memory release function releases the memory to be released from the first memory space.
[0028] It is understandable that the memory applied for according to the memory demand after receiving the first system message may be obtained from the first memory space or from the second memory space. Therefore, in the embodiment of the present application, before releasing the memory to be released, it is necessary to determine which memory space the memory comes from, and then release the memory to be released based on the release method of the memory space, so as to avoid the failure of memory release resulting in long-term memory occupation and waste of resources. Optionally, the above-mentioned memory to be released can be understood as the memory applied for by the method in the above embodiment.
[0029] It is understandable that the address situations of different types of memory are different. For example, the physical address of continuous physical memory is continuous, the virtual address is also continuous, and the offset relationship between the physical address and the virtual address is determined. For example, the physical address of non-continuous physical memory is discontinuous, and a mapping relationship needs to be established between the physical address and the virtual address. For upper-level applications, what is processed is the virtual address of the memory. However, no matter what type of memory it is, after knowing the virtual address of the memory, the corresponding physical address can be determined through the offset relationship or mapping relationship.
[0030] The memory release function releases the memory to be released from the first memory space, which can be understood as releasing the memory to be released based on the release method of the first memory space. Exemplarily, the first memory space is a non-direct mapping area, and the memory applied for from the first memory space is a non-continuous physical memory. When the physical address of the memory to be released is within the physical address range of the first memory space, the memory release function releases the memory to be released including: setting the physical address and virtual address of the memory to be released to an idle state, and releasing the mapping relationship between the physical address and virtual address of the memory to be released.
[0031] In this embodiment, memory is applied for by a memory application function, and the applied memory is released by a memory release function. This can be directly called by various scenarios without modifying the codes of various driver programs, and the operation is simple.
[0032] In combination with the first aspect, in a possible implementation manner, the method further includes:
[0033] In a case where the physical address of the memory to be released is within the physical address range of the second memory space, the memory release function releases the memory to be released from the second memory space.
[0034] The memory release function releases the above-mentioned memory to be released from the above-mentioned second memory space, which can be understood as releasing the memory to be released based on the release method of the second memory space. Exemplarily, the second memory space is a direct mapping area, and the memory applied for from the second memory space is a continuous physical memory. When the physical address of the memory to be released is within the physical address range of the second memory space, the memory release function releases the memory to be released, including: setting the physical address of the memory to be released to an idle state. Since the mapping between the physical address and the virtual address of the continuous physical memory is obtained by direct offset, there is no need to release the mapping relationship.
[0035] The description of the above two embodiments can also be found in the following embodiments. Fig. 9 , I will not go into details here.
[0036] In conjunction with the first aspect, in a possible implementation manner, the kernel program in the electronic device includes a driver, and the method further includes:
[0037] The driver receives a second system message, where the second system message is used to indicate a virtual address of the memory to be released;
[0038] The driver determines the physical address of the memory to be released according to the virtual address of the memory to be released;
[0039] In a case where the physical address of the memory to be released is within the physical address range of the first memory space, the driver program releases the memory to be released from the first memory space.
[0040] In combination with the first aspect, in a possible implementation manner, the method further includes:
[0041] In a case where the physical address of the memory to be released is within the physical address range of the second memory space, the driver program releases the memory to be released from the second memory space.
[0042] In this embodiment, the driver applies for memory and releases the applied memory. For details, please refer to the following Figure 6 and Figure 8 The relevant description will not be repeated here.
[0043] Optionally, the first system message can be understood as a memory request message in the following embodiments, and the second system message can be understood as a memory release message in the following embodiments. The first memory space can be understood as a non-direct mapping area in the following embodiments, and the second memory space can be understood as a direct mapping area in the following embodiments.
[0044] In a second aspect, an embodiment of the present application provides a memory processing device, comprising a unit for executing the method in the first aspect or any possible implementation of the first aspect.
[0045] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory; the memory of the memory comprises a first memory space and a second memory space, the minimum memory application amount of the first memory space is greater than the minimum memory application amount of the second memory space; the memory is coupled to the processor, the memory is used to store computer program code, 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.
[0046] 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 when the chip is the execution subject, the chip is used to execute the steps, and the above-mentioned limitation on the memory can be understood as the limitation of the operating environment. Exemplarily, the above-mentioned first memory space and the above-mentioned second memory space can both be in the chip, or the above-mentioned first memory space is outside the chip, and the above-mentioned second memory space is in the chip.
[0047] 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.
[0048] 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
[0049] 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.
[0050] Figure 1 is a schematic diagram of a mapping relationship between a linear address and a physical address provided in an embodiment of the present application;
[0051] Figure 2It is a schematic diagram of a memory partition provided in an embodiment of the present application;
[0052] Figure 3 is a structural diagram of an electronic device 100 provided in an embodiment of the present application;
[0053] Figure 4 It is a software structure diagram provided by the embodiment of the application itself;
[0054] Figure 5 is a schematic diagram of a process of allocating memory for a camera application provided by an embodiment of the present application;
[0055] Figure 6 It is a flowchart of a memory application method provided in an embodiment of the present application;
[0056] Figure 7 It is a flowchart of another memory application method provided in an embodiment of the present application;
[0057] Figure 8 It is a flowchart of a memory release method provided in an embodiment of the present application;
[0058] Fig. 9 It is a flowchart of another memory release method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0059] 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.
[0060] 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.
[0061] The minimum memory application amount of different memory spaces in electronic devices is different. The embodiments of the present application provide a memory processing method and a related device. The electronic device determines the memory space to apply for memory according to the memory application amount for storing data to be stored, which can reduce the waste of memory resources in the memory application process. Subsequently, when it is necessary to release memory, the electronic device can also release memory according to the type of memory to be released.
[0062] To facilitate understanding, the following first introduces the terms involved in the embodiments of the present application.
[0063] In an operating system, the storage devices that the central processing unit (CPU) can directly access include the memory of the electronic device and the registers in the CPU. For example, program instructions can use memory addresses as parameters, but not disk addresses. Therefore, the execution instructions and the data used by the instructions must be on a storage device that the CPU can directly access. If the data is not in the memory, then the CPU must move the data to the memory before using it.
[0064] 1. User space and kernel space
[0065] In the operating system of the electronic device, the memory space may include a user space and a kernel space, wherein the user space may be understood as a memory space for running user processes, and the kernel space may be understood as a memory space for running operating system kernel programs.
[0066] Taking a CPU with a 32-bit address bus as an example, the total memory capacity of the user space is 3GB, and its address range is from 0x00000000 to 0xBFFFFFFF; the total memory capacity of the kernel space is 1GB, and its address range is from 0xC0000000 to 0xFFFFFFFF. Therefore, it can be understood that the address space of 0-3GB in the memory is the user space, and the address space of 3GB-4GB is the kernel space.
[0067] 2. Linear address and physical address
[0068] The physical address can be understood as the address in the physical memory bar, and the linear address can be understood as the address obtained after converting the physical address. The mapping relationship between the physical address and the linear address can be maintained by the memory management unit (MMU). For example, the mapping relationship can be stored through mapping. Then, when the linear address is known, the corresponding physical address can be determined through the mapping table, thereby accessing the corresponding physical memory space.
[0069] Optionally, a linear address may also be referred to as a virtual address, which is not limited in this application.
[0070] Linear addresses are continuous addresses, but the physical addresses mapped by linear addresses can be continuous or non-continuous. For ease of understanding, please refer to Figure 1 , Figure 1 It is a schematic diagram of a mapping relationship between a linear address and a physical address provided in an embodiment of the present application.
[0071] like Figure 1 As shown in the figure, the linear address of the memory space allocated to process A is 0x30-0x36. After the conversion of the mapping relationship in the MMU, the physical address corresponding to the linear address 0x30-0x36 is 0x80-0x0D. It is easy to understand that the linear address of the memory space allocated to process A is continuous, and the physical address mapped by the linear address is also continuous.
[0072] The linear address of the memory space allocated to process B is 0x50-0x60. After the conversion of the mapping relationship in the MMU, the physical addresses corresponding to the linear addresses 0x50-0x60 are 0x38-0x40 and 0x70-0x78. It is easy to understand that the linear address of the memory space allocated to process B is continuous, but the physical address mapped by the linear address is non-continuous.
[0073] Therefore, it can be understood that although the linear addresses are continuous, Figure 1 The memory allocated to process A shown in the figure is continuous physical memory, while the memory allocated to process B is non-contiguous physical memory.
[0074] 3. Memory partition
[0075] The kmalloc function can be used to apply for continuous physical memory from the kernel space, and the vmalloc function can be used to apply for non-contiguous physical memory from the kernel space. In the kernel space, different memory spaces support different allocation methods. For example, see Figure 2 , Figure 2 Schematic diagram of a memory partition provided by an embodiment of the present application. Figure 2 As shown, the kernel space may include a direct mapping area and a non-direct mapping area, wherein there is a linear conversion relationship between the linear address and the physical address of the direct mapping area, such as the above Figure 1 The memory allocated to process A in the above example can be considered to be obtained from the direct mapping area. The linear addresses of the non-direct mapping area are continuous, but the physical addresses corresponding to the linear addresses are not necessarily continuous. For example, Figure 1 The memory allocated to process B can be considered to be obtained from the non-direct mapping area.
[0076] Therefore, it can be understood that the memory requested by the kmalloc function belongs to the direct mapping area, and the memory requested by the vmalloc function belongs to the indirect mapping area. The address segment included in the direct mapping area is different from the address segment included in the indirect mapping area, and the address segment included in the direct mapping area does not overlap with the address segment included in the indirect mapping area. For ease of understanding, taking a CPU with a 32-bit address bus as an example, in a kernel space of 1GB in size, the interval from 0xC0000000 (i.e. 3GB) to a maximum of 896M can be understood as a direct mapping area, and the interval from vmalloc_start to vmalloc_end can be understood as a indirect mapping area. Among them, the indirect mapping area from vmalloc_start to vmalloc_end does not overlap with the direct mapping area, that is, vmalloc_start is outside the direct mapping area, and vmalloc_end is within 0xFFFFFFFF (i.e. 4GB). For example Figure 2 As shown, a buffer may be included between the non-direct mapping area and the direct mapping area to prevent out-of-bounds memory requests.
[0077] It is understandable that the specific locations of the direct mapping area and the indirect mapping area in different electronic devices may be different, but for a certain electronic device, the direct mapping area and the indirect mapping area in the memory are fixed. Therefore, if an address falls within the memory address range of the direct mapping area, then the memory can be considered to be physical memory, which is obtained by applying for the kmalloc function. Similarly, if the address falls within the memory address range of the indirect mapping area, then the memory can be considered to be non-contiguous physical memory, which is obtained by applying for the vmalloc function.
[0078] Optionally, the direct mapping area may also be called a kmalloc area, a physical memory mapping area, etc.; the indirect mapping area may also be called a dynamic mapping area, a virtual memory mapping area, a vmalloc area, etc.
[0079] In summary, the memory requested by the kmalloc function is continuous physical memory in the direct mapping area, and its linear address and physical address are continuous; while the memory requested by the vmalloc function is non-continuous physical memory in the non-direct mapping area, and its linear address is continuous, but the physical address is not necessarily continuous.
[0080] The kmalloc function and the vmalloc function both apply for memory in bytes. Among them, the minimum memory application amount of the kmalloc function is 64 bytes, but the unit of memory application of the vmalloc function is page (PAGE_SIZE), and the size of each page is 4KB, that is, 4096 bytes. Exemplarily, when the vmalloc function is called to apply for 4MB of memory, 1024 non-contiguous pages will be obtained. When the vmalloc function is called to apply for memory less than 4KB, the actual memory applied for is 4KB, which will lead to a waste of storage resources.
[0081] This application can reduce the waste of memory resources. The method provided by this application can be executed by an electronic device. Next, the electronic device provided by the embodiment of this application is introduced. Figure 3 , Figure 3 It is a structural diagram of an electronic device 100 provided in an embodiment of the present application.
[0082] 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.
[0083] 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.
[0084] 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.
[0085] 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.
[0086] 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.
[0087] 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.
[0088] 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.
[0089] 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.
[0090] 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.
[0091] 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.
[0092] 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.
[0093] 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.
[0094] 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.
[0095] 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.
[0096] 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.
[0097] 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.
[0098] 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.
[0099] 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.
[0100] 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.
[0101] 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.
[0102] 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.
[0103] 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).
[0104] 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.
[0105] 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.
[0106] 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.
[0107] 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.
[0108] In some embodiments, the internal memory 121 may also be referred to as a memory, and may include the above-mentioned user space and the above-mentioned kernel space, wherein the kernel space may include the above-mentioned direct mapping area and the above-mentioned indirect mapping area.
[0109] 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.
[0110] 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.
[0111] The speaker 170A, also called a horn, is used to convert audio electrical signals into sound signals.
[0112] 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.
[0113] 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.
[0114] 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.
[0115] 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.
[0116] 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.
[0117] 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.
[0118] 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.
[0119] 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.
[0120] 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.
[0121] 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.
[0122] 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.
[0123] 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.
[0124] In other embodiments, the processor 110 may call computer instructions stored in the internal memory 121 to implement the memory processing method provided in the embodiments of the present application.
[0125] Exemplarily, the processor 110 may call a computer instruction stored in the internal memory 121 to determine the memory size to be applied for, and then apply for memory from different memory spaces according to the memory size. Exemplarily, the computer instruction may apply for continuous physical memory from a direct mapping area, or may apply for non-continuous physical memory from a non-continuous mapping area.
[0126] 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 4 , Figure 4 This is a software structure diagram provided by the embodiment of the present application. Figure 4 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.
[0127] In some embodiments, the system of the electronic device can be divided into five 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:
[0128] 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, video, music, and short message.
[0129] 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.
[0130] 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:
[0131] The activity manager can be used to manage the individual application lifecycles as well as general navigation back functionality.
[0132] 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.
[0133] 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.
[0134] 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.
[0135] 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.).
[0136] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, etc.
[0137] 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.
[0138] 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.
[0139] The system runtime layer may include system libraries and Android runtime.
[0140] 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.
[0141] 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:
[0142] 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.
[0143] 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.
[0144] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing.
[0145] A two-dimensional graphics engine can be understood as a drawing engine for two-dimensional drawing.
[0146] 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.
[0147] 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 drivers, such as display drivers, camera drivers, audio drivers, and sensor drivers. Optionally, the kernel layer may also be called an Android kernel or kernel program. Exemplarily, the hardware layer of an electronic device may include a touch panel (TP), a liquid crystal display (LCD), and the like.
[0148] In some embodiments, the kernel layer can be understood as kernel state, and the other four layers (ie, application layer, application framework layer, system runtime layer, and HAL) can be understood as user state.
[0149] It is understandable that the camera application in the application layer supports multiple shooting modes, such as portrait mode, night scene mode, large aperture mode and long exposure mode, and each shooting mode uses different shooting parameters, where the above-mentioned shooting parameters can be aperture value, shutter speed, sensitivity, exposure, focal length and depth of field, etc. The shooting parameters will affect the image quality of the pictures collected by the camera application in a certain specific rule.
[0150] For example, the shooting modes supported by the camera application and the shooting parameters corresponding to each shooting mode can be stored in a sensor binary file (sensor bin), and the sensor bin file can be stored in an external memory, such as a disk or a hard disk. After the user selects a shooting mode, the camera application reads the shooting parameters corresponding to the shooting mode into the memory, so that the camera application can collect pictures that meet the user's requirements.
[0151] For ease of understanding, please refer to Figure 5 , Figure 5 FIG. 1 is a flow chart of allocating memory for a camera application provided by an embodiment of the present application. Figure 5 As shown, including:
[0152] 501: The camera application switches the shooting mode.
[0153] When the user opens the camera application, there will be a default photo mode, and the user can switch the current shooting mode, such as switching from the default shooting mode to the portrait mode. Exemplarily, the sensor driver (such as the touch sensor driver) can respond to user operations, such as sliding operations or clicking operations, to switch from the current shooting mode to other shooting modes. The camera application then passes the identification information of the switched shooting mode to the camera HIDL / AIDL. Among them, the identification information of the shooting mode can be any information that can uniquely identify the shooting mode, such as a number, and this application does not limit this.
[0154] 502: The camera HIDL / AIDL transmits identification information of the shooting mode.
[0155] In this step, the camera HIDL / AIDL passes the identification information of the shooting mode to the camera driver in the kernel state, and the camera driver applies for memory for the shooting parameters of the shooting mode, including:
[0156] 503: Read the shooting parameters corresponding to the shooting mode from the sensor bin file.
[0157] In this step, the camera driver reads the sensor bin file, which stores the shooting modes and corresponding shooting parameters supported by the camera application. The shooting parameters corresponding to the shooting mode can be obtained according to the identification information of the shooting mode.
[0158] 504: Determine the data volume of the shooting parameter.
[0159] In this step, the camera driver determines the data volume of the shooting parameters, which can also be understood as the storage space required to store the shooting parameters. Exemplarily, the storage space required for the shooting parameters in the memory can be obtained through the keyword sizeof.
[0160] 505: Call the vmalloc function to apply for memory.
[0161] It can be understood that the memory requested by the vmalloc function is non-contiguous physical memory. The specific process may include:
[0162] 5051: Determine the amount of memory requested.
[0163] It can be understood that when calling the vmalloc function, the camera driver can pass the memory size to be applied for as a parameter to the vmalloc function. Therefore, the vmalloc function can determine the memory application amount according to the passed-in parameter.
[0164] 5052: Based on the memory request amount, determine the page to be requested, and then request physical memory with discontinuous physical addresses from the vmalloc area to obtain the physical address.
[0165] After determining the memory size (i.e., memory application amount) of the memory to be applied for, the vmalloc function calculates the pages to be applied for. Since the size of each page is 4KB, the memory application amount can be divided by 4KB to obtain the pages to be applied for. For example, if the memory application amount is 8KB, then 2 pages need to be applied for. Then, the vmalloc function applies for non-continuous physical memory, i.e., memory with discontinuous physical addresses, based on the determined pages, and obtains the physical addresses of the non-continuous physical memory.
[0166] 5053: Apply for a virtual address for this physical address.
[0167] 5054: Establish a mapping relationship between the physical address and the virtual address.
[0168] It can be understood that in the vmalloc function, the physical address applied for is discontinuous, but the virtual address applied for is continuous. Therefore, it is necessary to establish a mapping relationship between the physical address and the virtual address so that after determining a virtual address, the corresponding physical address can be obtained through the mapping relationship.
[0169] 5055: Returns a pointer to a virtual address.
[0170] It can be understood that the pointer stores the virtual address of the requested memory. The physical address can be obtained through the virtual address and the mapping relationship, so that the data can be stored in the memory.
[0171] 506: The shooting parameters are stored in the applied memory.
[0172] 507: Configure the shooting parameters to the camera register.
[0173] In this step, after the shooting parameters are configured into the camera register, the camera application can capture pictures based on the shooting parameters.
[0174] When using the vmalloc function to apply for memory, if the memory application amount is small, it will lead to a waste of memory resources. In the embodiment of the present application, the memory application amount can be understood as the amount of memory required for the data to be stored, but the memory actually applied for by the kernel layer (referred to as the memory allocation amount for ease of distinction) may be different. Exemplarily, taking the minimum application amount of the vmalloc area as 4KB as an example, if the memory application amount determined in step 5051 is 3KB, then the driver will apply for 4KB of memory from the vmalloc area, that is, the memory allocation amount is 4KB, and the memory allocation amount 4KB is different from the memory application amount 3KB, resulting in a waste of 1KB of memory resources.
[0175] The memory processing method provided in the embodiment of the present application can reduce the waste of memory resources. Figure 4 The memory processing method provided in the embodiment of the present application can be implemented by a memory processing module in the kernel layer. The memory processing module may include a memory application module and a memory release module, wherein the memory application module is used to apply for memory, and the memory release module is used to release the memory applied by the memory application module. Next, the method for implementing the memory application module is introduced.
[0176] In some embodiments, the memory application module may be coupled to a driver, that is, may be implemented by a driver in the kernel layer. Figure 6 , Figure 6 : is a flowchart of a memory application method provided in an embodiment of the present application. The method can be executed by a driver in the kernel layer, including:
[0177] 601: Receive a memory request message sent by an upper layer of the kernel layer, and determine the memory request amount.
[0178] In this step, the upper layer of the inner core layer can be understood as any layer above the inner core layer, such as Figure 4The application layer, application framework layer, system runtime layer and HAL layer in it, or it can also be understood as the above-mentioned user state. Exemplarily, when the application has a memory application requirement, the application sends a memory application message to the lower layer, and then passes it to the driver, such as through the above-mentioned HIDL / AIDL interface. Exemplarily, the scenario in which the application has a memory application requirement can be the camera application switching shooting mode, or adjusting shooting parameters without changing the shooting; it can also be the scene in which the player switches the sound effect mode, etc.
[0179] In an embodiment of the present application, the memory request message can be the data to be stored itself, or the size of the data to be stored (for example, 5KB), or other information indicating the data to be stored or the size of the data to be stored, as long as the driver can determine the memory request amount based on the memory request message.
[0180] 602: Determine whether the memory application amount is greater than the minimum application amount of the vmalloc area.
[0181] It can be understood that when the hardware resources of the electronic device do not change, the kmalloc area and the vmalloc area in the memory are fixed, the address range they each include is also fixed, the respective memory allocation principles are also fixed, and therefore, the respective minimum application amounts are also fixed. Exemplarily, memory allocation is performed in the vmalloc area in units of pages, and therefore, the minimum application amount of the vmalloc area is the size of a page, such as 4KB.
[0182] If the result of the determination in step 602 is yes, execute step 603: apply for memory from the kmalloc area.
[0183] It can be understood that the kmalloc area is a direct mapping area in the memory, the physical address of the allocated memory is continuous, the virtual address is also continuous, and the physical address and the virtual address are simply offset (such as offset), and in electronic devices, the address offset is fixed. Therefore, after applying for the physical address from the kmalloc area, the virtual address can be uniquely determined, and there is no need to establish a mapping relationship between the physical address and the virtual address separately. Optionally, step 603 may specifically include:
[0184] 6031: Determine the amount of memory requested.
[0185] 6032: Based on the memory request amount, apply for memory with continuous physical address from the kmalloc area to obtain the physical address.
[0186] 6033: Returns a pointer to the virtual address corresponding to this physical address.
[0187] If the result of the determination in step 602 is no, step 604 is executed: applying for memory from the vmalloc area.
[0188] In this step, the introduction of applying for memory from the vmalloc area can be referred to the above steps 5051 to 5055, which will not be repeated here. It can be understood that in the method of the present application, for a certain memory application, the obtained memory may be a memory with a continuous physical address in the kmalloc area, or a memory with a discontinuous physical address in the vmalloc area. The key lies in the size of the memory application amount, that is, the judgment result of step 602 determines the type of memory finally obtained.
[0189] In order to Figure 5 In contrast to the method shown in the figure, we still take the minimum application size of the vmalloc area as 4KB and the memory application size as 3KB as an example. Figure 6 In the method shown, since the memory application amount determined in step 601 is 3KB, the judgment result of step 602 should be no, and the driver will apply for memory from the kmalloc area, and the memory allocation amount is 3KB (instead of Figure 5 The method shown in FIG. 4 obtains a memory allocation amount of 4KB), and the memory allocation amount of 3KB is the same as the memory application amount of 3KB, thereby avoiding waste of memory resources.
[0190] In other embodiments, the function of the memory application module may also be implemented by a program other than the driver, for example, by a memory application function in the kernel layer, which is a program other than the driver. Figure 7 , Figure 7 : is a flowchart of another memory application method provided in an embodiment of the present application. The above method can be executed by a memory application function in the kernel layer, including:
[0191] 701: Receive the memory request message sent by the driver and determine the memory request amount.
[0192] In this embodiment, the memory request function receives a memory request message from the driver, wherein the driver may receive a memory request message sent by an upper layer (such as an application) of the kernel layer, and then forward the memory request message to the memory request function, for example, the memory request message may be used as a parameter to call the memory request function, so that the memory request function obtains the memory request message. The memory request message may be the data to be stored itself, or the data size of the data to be stored (such as 5KB), or other information indicating the data to be stored or the data size of the data to be stored.
[0193] Optionally, the driver may process the received memory request message and then send it to the memory request function. For example, the driver may determine the memory request amount based on the received memory request message and then send the memory request amount as the memory request message to the memory request function.
[0194] 702: Determine whether the memory application amount is greater than the minimum application amount of the vmalloc area.
[0195] If the result of the determination in step 702 is yes, execute step 703: apply for memory from the kmalloc area.
[0196] If the result of the determination in step 702 is no, step 704 is executed: applying for memory from the vmalloc area.
[0197] In this embodiment, the introduction of step 702 to step 704 can refer to the above step 602 to step 604, which will not be repeated here.
[0198] It is understandable that if the driver applies for memory according to the memory application amount, then different scenarios need to modify the corresponding drivers, for example, the memory application in the shooting mode switching needs to modify the camera driver, and the memory application in the audio effect switching needs to modify the audio driver, etc., which is cumbersome. In this embodiment, the memory application function applies for memory according to the memory application amount, so the memory application in different scenarios can use the memory application function to reduce the waste of memory resources, and the operation is simple.
[0199] Next, we will introduce how to implement the memory release module.
[0200] It can be understood that the memory requested from the vmalloc area is different from the memory requested from kmalloc. The memory requested from the vmalloc area has discontinuous physical addresses, and the mapping relationship between physical addresses and virtual addresses requires a mapping table to maintain; the memory requested from the kmalloc area has continuous physical addresses, and the relationship between physical addresses and virtual addresses is fixed, and does not require a mapping table to maintain. Generally, you can use the vmalloc function to request memory from the vmalloc area (vmalloc memory for short), and then use the vfree function to release the vmalloc memory; you can use the kmalloc function to request memory from the kmalloc area (kmalloc memory for short), and then use the kfree function to release the kmalloc memory.
[0201] In the present application, since the memory applied for each time is related to the memory application amount, the memory obtained may be vmalloc memory or kmalloc memory. Therefore, the present application embodiment provides a memory release method, which releases memory according to the memory type. The method can be implemented by a memory release module in a memory processing module, and is used to release the memory applied for by the memory application module in the memory processing module.
[0202] In some embodiments, the memory application module may be coupled to a driver, that is, may be implemented by a driver in the kernel layer. Figure 8 , Figure 8 : is a flowchart of a memory release method provided in an embodiment of the present application. The method can be executed by a startup program in the kernel layer, including:
[0203] 801: Receive a memory release message sent by an upper layer of the kernel layer, and determine a virtual address of the memory to be released.
[0204] In this step, the upper layer of the inner core layer can be understood as any layer above the inner core layer, such as Figure 4 The application layer, application framework layer, system runtime layer and HAL layer in the system may also be understood as the above-mentioned user state. For example, when the application has a memory release requirement, the application sends a memory release message to the lower layer, and then passes it to the driver, such as through the above-mentioned HIDL / AIDL interface. For example, the scenario in which the application has a memory release requirement may be when the camera application is closed or the music player is closed.
[0205] In an embodiment of the present application, the memory release message may be indication information pointing to the memory to be released, or may be the address of the memory to be released itself, for example, may be a pointer pointing to the virtual address of the memory to be released.
[0206] 802: Determine whether the physical address corresponding to the virtual address belongs to the vmalloc area.
[0207] It can be understood that the memory to be released may be the memory requested from the vmalloc area, or it may be the memory requested from the kmalloc area. After obtaining the virtual address of the memory to be released, it can be determined which area the memory to be released belongs to based on the virtual address. Exemplarily, if there is a mapping table for the virtual address, then the memory to be released can be considered to be vmalloc memory, and whether the physical address corresponding to the virtual address belongs to the vmalloc area; otherwise, it can be considered that the memory to be released is kmalloc memory, and whether the physical address corresponding to the virtual address belongs to the kmalloc area.
[0208] If the judgment result of step 802 is no, execute step 803: release the memory from the kmalloc area.
[0209] It can be understood that when the judgment result of step 802 is no, the memory to be released is kmalloc memory, and therefore, releasing memory from the kmalloc area can be understood as releasing the memory to be released in the kmalloc area.
[0210] When the memory to be released is kmalloc memory, the physical address of the memory to be released is continuous, and the offset between the physical address of the memory to be released and the virtual address is also fixed. Therefore, when the memory to be released is kmalloc memory, the physical address of the memory to be released can be released.
[0211] Exemplarily, the physical address corresponding to the virtual address may be marked as available, so that other processes can use these memory resources to achieve the purpose of memory release.
[0212] If the result of the determination in step 802 is yes, step 804 is executed: releasing memory from the vmalloc area.
[0213] It can be understood that when the judgment result of step 802 is yes, the memory to be released is vmalloc memory, and therefore, releasing memory from the vmalloc area can be understood as releasing the memory to be released in the vmalloc area.
[0214] When the memory to be released is vmalloc memory, the physical address of the memory to be released is discontinuous, and the mapping relationship between the physical address and the virtual address of the memory to be released is maintained by a mapping table. Therefore, when the memory to be released is vmalloc memory, the physical address, the virtual address and the mapping table need to be released.
[0215] Exemplarily, the physical address corresponding to the virtual address can be marked as available, so that other processes can use these memory resources to achieve the purpose of memory release. Exemplarily, the physical address of the memory to be released can be added to the available list first, and then the virtual address of the memory to be released can be marked as available, and then the corresponding mapping table can be deleted to achieve the purpose of memory release.
[0216] In some embodiments, the function of the memory release module can also be implemented by a program other than the driver, for example, it can be implemented by a memory release function in the kernel layer, and the memory release function is a program other than the driver. Fig. 9 , Fig. 9: is a flowchart of another memory release method provided in an embodiment of the present application. The above method can be executed by a memory release function in the kernel layer, including:
[0217] 901: Receive a memory release message sent by a driver and determine a virtual address of the memory to be released.
[0218] In this embodiment, the memory release function receives a memory release message from the driver, wherein the driver may receive a memory release message sent by an upper layer (such as an application) of the kernel layer, and then forward the memory release message to the memory release function, such as calling the memory release function with the memory release message as a parameter, so that the memory release function obtains the memory release message. The memory release message may be indication information pointing to the memory to be released, or may be the address of the memory to be released, such as a pointer to the virtual address of the memory to be released.
[0219] Optionally, the driver may process the received memory release message before sending it to the memory release function. For example, the driver may first determine the virtual address of the memory to be released based on the received memory release message, and then send the virtual address of the memory to be released as the memory release message to the memory release function.
[0220] 902: Determine whether the physical address corresponding to the virtual address belongs to the vmalloc area.
[0221] If the judgment result of step 902 is no, execute step 903: release the memory from the kmalloc area.
[0222] If the result of the determination in step 902 is yes, execute step 904: release memory from the vmalloc area.
[0223] In this embodiment, the introduction of step 902 to step 904 can refer to the above step 802 to step 804, which will not be repeated here.
[0224] With the previous article Figure 7 Similar to the embodiment shown, in this embodiment, the memory release function releases the memory according to the virtual address of the memory to be released, so different scenarios can use the memory release function to realize memory release instead of modifying each driver, which is simple to operate.
[0225] It can be understood that the above-mentioned memory to be released may be the memory applied for by the above-mentioned memory application module.
[0226] 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.
[0227] 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.
[0228] 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.
[0229] 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.
[0230] 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.
[0231] 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.
Claims
1. A memory processing method, characterized in that: The method is applied to an electronic device, and the method comprises: Receive memory request message; Determine a memory request amount corresponding to the memory request message; In response to the memory application amount being less than a minimum memory application amount of the first memory space, memory is applied from the second memory space, wherein the minimum memory application amount of the first memory space is greater than the minimum memory application amount of the second memory space.
2. The method according to claim 1, characterized in that The method further comprises: In response to the memory application amount being not less than the minimum memory application amount of the first memory space, memory is applied from the first memory space.
3. The method according to claim 1, characterized in that The applying for memory from the second memory space includes: calling a kmalloc function to apply for memory from the second memory space.
4. The method according to claim 3, characterized in that After applying for memory from the second memory space, the method further includes: A memory release message is received, and memory is released from the second memory space.
5. The method according to claim 4, characterized in that The releasing memory from the second memory space includes: calling a kfree function to release memory from the second memory space.
6. The method according to claim 2, characterized in that The applying for memory from the first memory space includes: calling a vmalloc function to apply for memory from the first memory space.
7. The method according to claim 6, characterized in that After applying for memory from the first memory space, the method further includes: A memory release message is received, and memory is released from the first memory space.
8. The method according to claim 7, characterized in that The releasing memory from the first memory space includes: calling a vfree function to release memory from the first memory space.
9. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions so that the method according to any one of claims 1 to 8 is executed.
10. 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 8 is executed.