Method and device for adjusting memory configuration parameters

By comprehensively considering multiple resource pressures and adjusting memory configuration parameters, the problem of poor memory management in the existing technology is solved, system performance optimization and resource efficient utilization are achieved, and stable operation of the system under different loads is ensured.

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

Patent Information

Application Number
CN202410601534.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2020-09-10
Filing Date
2020-12-25
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

When existing technologies manage memory resources, the effect still needs to be improved, and it is difficult to achieve optimal system performance, especially in memory configuration adjustment under pressure from multiple resources.

Method used

By obtaining a variety of resource pressure information, including processor pressure, I/O pressure, memory recycling pressure and memory swap space pressure, memory configuration parameters such as swappiness and extra_free_kbytes can be adjusted to achieve optimal system performance. Specific methods include setting appropriate memory swap parameters and additional free memory configuration parameters according to different resource pressures, balancing memory swap space pressure and I/O pressure to ensure efficient operation of the system in different scenarios.

Benefits of technology

By comprehensively considering multiple resource pressures and adjusting memory configuration parameters, the effect of memory management is significantly improved, system performance is improved, I/O pressure and computing resource consumption caused by insufficient memory are reduced, and the stability of the system under different loads is ensured. run.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118626005A
    Figure CN118626005A
Patent Text Reader

Abstract

The invention provides a method and device for adjusting memory configuration parameters. The method comprises the following steps: acquiring a plurality of resource pressures, wherein the plurality of resource pressures are used for indicating a plurality of requirements on memory compression; and adjusting memory configuration parameters according to the plurality of resource pressures, wherein a preset corresponding relationship exists between the memory configuration parameters and the plurality of resource pressures. The resource pressure is such as processor pressure, I / O pressure, memory recovery pressure or memory exchange space pressure, different types of resource pressure correspond to different memory compression requirements, the method for adjusting the memory comprehensively considers various information, the system performance can be optimal, and the effect of managing the memory is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of storage, and in particular to a method and device for adjusting memory configuration parameters. Background Art

[0002] Memory is a component of a computer. When a computer runs a program, data related to the program can be temporarily stored in the memory, waiting for the processor to call it. If the memory resources are insufficient, the processor may need to wait for a while to obtain the data required for the program to run. Therefore, the usage of memory resources is associated with the program running status (such as startup rate).

[0003] In order to improve the utilization of memory resources, it is necessary to manage the usage of memory resources. One method of managing memory resources is to adjust the memory based on the size of available memory. For example, when the available memory is less than the preset value, the value of the extra free memory configuration parameter (extra_free_kbytes) can be increased to prompt the memory management module to more actively recycle memory to meet the program's demand for memory resources. However, the effect of using this method to manage memory still needs to be improved. Summary of the invention

[0004] The present application provides a method, device, computer program product and computer-readable storage medium for adjusting memory configuration parameters, which can improve the effect of memory management.

[0005] In a first aspect, a method for adjusting memory is provided, comprising: obtaining multiple resource pressures, wherein the multiple resource pressures are used to indicate multiple requirements for memory compression; adjusting memory configuration parameters according to the multiple resource pressures, and there is a preset corresponding relationship between the memory configuration parameters and the multiple resource pressures.

[0006] Resource pressure includes, for example, processor pressure, input / output (I / O) pressure, memory reclaim pressure or memory swap space pressure, wherein the processor pressure, I / O pressure and memory reclaim pressure can be determined by processor pressure stall information (PSI), I / O PSI and memory reclaim PSI, respectively, and the memory swap space pressure can be determined by available swap space (swap free) and / or the number of anonymous pages (anon pages). Different types of resource pressures have different memory compression requirements. It is difficult to achieve optimal system performance by adjusting memory configuration parameters based on one type of resource pressure. For example, when swap free is low and anon pages are low, it means that the use of zRAM (an example of memory compression technology) is not profitable. At this time, the value of the memory swap parameter (swappiness) should be reduced to reduce the frequency of zRAM use. However, if the I / O pressure is large, the swappiness value should be increased. A larger swappiness can increase the frequency of zRAM use, thereby reclaiming more anon pages and avoiding the continuous increase in I / O pressure caused by excessive recycling of file pages when memory is insufficient. The reason for the continuous increase in I / O pressure is that excessive recycling of file pages will cause a decrease in cache hit rate, and file pages need to be read from the disk into the cache again, which increases the refault I / O phenomenon. Refault I / O will cause the I / O pressure to continue to increase. Considering the above two types of information, swappiness needs to be set to a suitable value to balance the pressure of memory swap space and I / O pressure to achieve optimal system performance. Compared to adjusting memory based on one type of information, the method for adjusting memory provided in the present application comprehensively considers multiple types of information, can achieve optimal system performance, and improve the effect of managing memory.

[0007] Optionally, the memory configuration parameter includes swappiness, the multiple resource pressures include I / O pressure and memory swap space pressure, and adjusting the memory configuration parameter according to the multiple resource pressures includes: when the I / O pressure decreases and when the memory swap space pressure decreases, reducing the memory swap parameter; or when the I / O pressure increases and when the memory swap space pressure decreases, adjusting the memory swap parameter to a preset value.

[0008] Swap free reflects the remaining capacity of the zRAM device, and anon pages reflects the amount of data that can be input into the zRAM device. When swap free is low and / or anon pages is low (i.e., the memory swap space pressure is low), the use of zRAM is not profitable, and the frequency of zRAM use can be reduced. When I / O pressure is low, the frequency of zRAM use can be reduced to save computing resources. Considering the memory swap space pressure and I / O pressure comprehensively, the swappiness value can be reduced to achieve optimal system performance and improve the effect of memory management.

[0009] When swap free is low and / or anon pages is low (i.e., memory swap space pressure is low), the use of zRAM is not beneficial, and the frequency of zRAM use can be reduced. When I / O pressure is high, the swappiness value should be increased. A larger swappiness can increase the frequency of zRAM use, thereby reclaiming more anon pages and avoiding excessive file page reclaim when memory is insufficient, which leads to continuous increase in I / O pressure. You can set swappiness to a suitable value (e.g., a preset value) to balance memory swap space pressure and I / O pressure, thereby achieving optimal system performance and improving the effect of memory management.

[0010] Optionally, the memory configuration parameters include swappiness, the multiple resource pressures include processor pressure and memory swap space pressure, and adjusting the memory configuration parameters according to the multiple resource pressures includes: increasing the swappiness when the processor pressure decreases and when the memory swap space pressure increases.

[0011] When the processor pressure is low, increasing swappiness can reduce the probability of cache thrashing when the memory is insufficient, while not affecting the computing resource requirements of other tasks; when the memory swap space pressure is high, it means that the use of zRAM is more profitable, and swappiness should be increased. Considering the processor pressure and memory swap space pressure, the swappiness value can be increased to increase the frequency of zRAM use, thereby achieving optimal system performance and improving the effect of memory management.

[0012] Optionally, the memory configuration parameter includes swappiness, the multiple resource pressures include processor pressure and I / O pressure, and adjusting the memory configuration parameter according to the multiple resource pressures includes: when the I / O pressure decreases and when the processor pressure increases, reducing the memory swap parameter; or when the I / O pressure increases and when the processor pressure increases, adjusting the memory swap parameter to a preset value.

[0013] When the I / O pressure is small, the frequency of zRAM usage can be reduced to save computing resources. When the processor pressure is large, it means that the current computing pressure is large and swappiness should be reduced to save computing resources. Considering the I / O pressure and processor pressure comprehensively, swappiness can be reduced to save computing resources, thereby achieving optimal system performance and improving the effect of memory management.

[0014] When I / O pressure is high, the swappiness value should be increased. A larger swappiness can increase the frequency of zRAM usage, thereby reclaiming more anon pages and avoiding excessive file page reclaim when memory is insufficient, which leads to continuous increase in I / O pressure. When processor pressure is high, swappiness should be reduced to save computing resources. You can set swappiness to a suitable value (such as a preset value) to balance I / O pressure and processor pressure, thereby achieving optimal system performance and improving the effect of memory management.

[0015] Optionally, adjusting the memory configuration parameters according to the multiple resource pressures includes: when the current application running scenario indicated by the scenario information does not conform to a preset scenario, adjusting the memory configuration parameters according to the multiple resource pressures.

[0016] The scenario information is, for example, information indicating application startup or application switching. When the preset scenario is the application startup scenario, the various resource requirements of the application startup scenario are relatively fixed. The system performance can be optimized by adjusting the memory according to the preset swappiness, without collecting PSI and memory swap space pressure information for calculation, thereby reducing the complexity of memory adjustment.

[0017] Optionally, the method further includes: when the memory reclaim pressure increases, reducing the extra free memory configuration parameter (extra_free_kbytes); or, when the memory reclaim pressure decreases, increasing extra_free_kbytes.

[0018] The value of extra_free_kbytes is positively correlated with the size of memory reserved by the kernel, that is, the larger the value of extra_free_kbytes, the larger the memory reserved by the kernel. When the memory recovery pressure increases, it means that there are more memory recovery tasks at present and third-party apps have a greater demand for memory. You can reduce extra_free_kbytes to reserve more memory for third-party apps. When the memory recovery pressure decreases, it means that there are fewer memory recovery tasks at present and third-party apps have a smaller demand for memory. You can increase extra_free_kbytes to reserve more memory for the kernel.

[0019] Optionally, adjusting the memory configuration parameters according to the multiple resource pressures includes: when the available memory is less than a memory threshold, adjusting the memory configuration parameters according to the multiple resource pressures.

[0020] Adjusting memory configuration parameters will consume computing resources. Therefore, when the available memory is large, there is no need to adjust the memory configuration parameters. When the available memory is small, the memory configuration parameters can be adjusted according to the multiple resource pressures, thereby saving computing resources without affecting application operation.

[0021] Optionally, the ratio of the memory threshold to the physical memory is negatively correlated with the size of the physical memory.

[0022] You can set the memory threshold according to the size of the physical memory. If the terminal device has a large amount of physical memory, you can set the memory threshold to a value with a low percentage; if the terminal device has a small amount of physical memory, you can set the memory threshold to a value with a high percentage.

[0023] For example, if the physical memory of terminal device A is 12GB and the physical memory of terminal device B is 6GB, the memavailable watermark of terminal device A can be set to one-third of the physical memory, that is, 4GB; the memavailable watermark of terminal device B can be set to one-half of the physical memory, that is, 3GB. In this way, the terminal device with a larger physical memory (terminal device A) can reduce the consumption of computing resources by memory adjustment while ensuring sufficient available memory; the terminal device with a smaller physical memory (terminal device B) can adjust the memory in advance to reduce the probability of problems such as insufficient memory.

[0024] In a second aspect, a device for adjusting memory is provided, comprising a unit for executing any one of the methods in the first aspect. The device may be a terminal device or a chip in the terminal device. The device may include an input unit and a processing unit.

[0025] When the device is a terminal device, the processing unit may be a processor, and the input unit may be a touch screen, keyboard, mouse, camera, microphone or other input device; the terminal device may also include a memory for storing computer program code, and when the processor executes the computer program code stored in the memory, the terminal device executes any one of the methods in the first aspect.

[0026] When the device is a chip in a terminal device, the processing unit may be a processing unit inside the chip, and the input unit may be an input / output interface, a pin or a circuit, etc.; the chip may also include a memory, which may be a memory inside the chip (for example, a register, a cache, etc.) or a memory located outside the chip (for example, a read-only memory, a random access memory, etc.); the memory is used to store computer program code, and when the processor executes the computer program code stored in the memory, the chip executes any one of the methods in the first aspect.

[0027] According to a third aspect, a computer program product is provided, the computer program product comprising: a computer program code, when the computer program code is executed by a device for adjusting memory, the device executes any one of the methods according to the first aspect.

[0028] According to a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program code, and when the computer program code is executed by a device that adjusts memory, the device executes any one of the methods in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 It is a schematic diagram of a hardware system of a terminal device provided by the present application;

[0030] Figure 2 It is a schematic diagram of a software system of a terminal device provided by the present application;

[0031] Figure 3 is a schematic diagram of a system for adjusting memory provided by the present application;

[0032] Figure 4 It is a schematic diagram of a workflow of the PSI pressure registration and acquisition module provided by this application;

[0033] Figure 5 It is a schematic diagram of a workflow of the memory information collection module provided by this application;

[0034] Figure 6 It is a schematic diagram of a workflow of the application scenario monitoring module provided by this application;

[0035] Figure 7 It is a schematic diagram of a workflow of the system pressure decision module provided by the present application;

[0036] Figure 8 is a schematic diagram of another workflow of the system pressure decision module provided by the present application;

[0037] Fig. 9 is a schematic diagram of a device for adjusting memory provided by the present application;

[0038] Fig.10 It is a schematic diagram of an electronic device for adjusting memory provided by the present application. DETAILED DESCRIPTION

[0039] The technical solutions in the embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0040] Figure 1 The figure shows a hardware structure of a device suitable for the present application.

[0041] The device 100 may be a mobile phone, a smart screen, a tablet computer, a wearable electronic device, an in-vehicle electronic device, an augmented reality (AR) device, a virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), a projector, etc. The embodiment of the present application does not impose any limitation on the specific type of the device 100.

[0042] The 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 button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0043] It should be noted that Figure 1 The structure shown does not constitute a specific limitation on the device 100. In other embodiments of the present application, the device 100 may include Figure 1 More or fewer components than those shown, or the apparatus 100 may include Figure 1 Combinations of some of the components shown, or the apparatus 100 may include Figure 1 Subassemblies of some of the components shown. Figure 1 The components shown may be implemented in hardware, software, or a combination of software and hardware.

[0044] The processor 110 may include one or more processing units. For example, the processor 110 may include at least one of the following processing units: an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and a neural-network processing unit (NPU). Different processing units may be independent devices or integrated devices.

[0045] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.

[0046] 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.

[0047] In some embodiments, the processor 110 may include one or more interfaces. For example, the processor 110 may include at least one of the following interfaces: 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 SIM interface, and a USB interface.

[0048] 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 180K, 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 180K through the I2C interface, so that the processor 110 communicates with the touch sensor 180K through the I2C bus interface to realize the touch function of the device 100.

[0049] 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.

[0050] 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 the PCM 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 through a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.

[0051] 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.

[0052] 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 device 100. The processor 110 and the display screen 194 communicate via the DSI interface to implement the display function of the device 100.

[0053] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal interface or as a data signal interface. In some embodiments, the GPIO interface can be used to connect the processor 110 with the camera 193, the display screen 194, the wireless communication module 160, the audio module 170, and the sensor module 180. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, or a MIPI interface.

[0054] The USB interface 130 is an interface that complies with the USB standard specification, for example, it can be a mini USB interface, a micro USB interface, or a USB Type C interface. The USB interface 130 can be used to connect a charger to charge the device 100, can also be used to transfer data between the device 100 and peripheral devices, and can also be used to connect headphones to play audio through the headphones. The USB interface 130 can also be used to connect other devices 100, such as AR devices.

[0055] Figure 1 The connection relationship between the modules shown is only a schematic illustration and does not constitute a limitation on the connection relationship between the modules of the device 100. Optionally, the modules of the device 100 may also adopt a combination of multiple connection modes in the above embodiments.

[0056] The charging management module 140 is used to receive power 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 current from the wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive electromagnetic waves through the wireless charging coil of the device 100 (the current path is shown as a dotted line). While the charging management module 140 is charging the battery 142, it may also power the device 100 through the power management module 141.

[0057] 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 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, and battery health status (e.g., leakage, impedance). Optionally, the power management module 141 can be set in the processor 110, or the power management module 141 and the charging management module 140 can be set in the same device.

[0058] The wireless communication function of the device 100 can be implemented by components such as the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor.

[0059] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in 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 the 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.

[0060] The mobile communication module 150 can provide a wireless communication solution applied to the device 100, such as at least one of the following solutions: second generation (2 th generation, 2G) mobile communication solutions, third generation (3 th generation, 3G) mobile communication solutions, fourth generation (4 th generation, 5G) mobile communication solutions, the fifth generation (5 thThe 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 may receive electromagnetic waves from the antenna 1, and perform processing such as filtering and amplifying the received electromagnetic waves, and then transmit them to the modem processor for demodulation. The mobile communication module 150 may also amplify the signal modulated by the modem processor, and the amplified signal is converted into an electromagnetic wave and radiated out through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be arranged in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be arranged in the same device as at least some of the modules of the processor 110.

[0061] 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 (e.g., a speaker 170A, a receiver 170B), or displays an image 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.

[0062] Similar to the mobile communication module 150, the wireless communication module 160 can also provide a wireless communication solution applied to the device 100, such as at least one of the following solutions: wireless local area networks (WLAN), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR). 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 and filters the electromagnetic wave signal, 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 and amplify it, and the signal is converted into electromagnetic waves and radiated through the antenna 2.

[0063] In some embodiments, antenna 1 of device 100 is coupled to mobile communication module 150 , and antenna 2 of device 100 is coupled to wireless communication module 160 .

[0064] The device 100 can implement display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to 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.

[0065] The display screen 194 can be used to display images or videos. 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 (AMOLED), a flexible light-emitting diode (FLED), a mini light-emitting diode (Mini LED), a micro light-emitting diode (Micro LED), a micro OLED (Micro OLED) or a quantum dot light emitting diode (QLED). In some embodiments, the device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.

[0066] The device 100 can realize the shooting function through the ISP, the camera 193, the video codec, the GPU, the display screen 194 and the application processor.

[0067] The ISP is used to process the data fed back by the camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing and converts it into an image visible to the naked eye. The ISP can perform algorithm optimization on the noise, brightness and color of the image. The ISP can also optimize the exposure and color temperature of the shooting scene. In some embodiments, the ISP can be set in the camera 193.

[0068] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard red green blue (RGB), YUV or other format. In some embodiments, the device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.

[0069] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.

[0070] Video codecs are used to compress or decompress digital videos. The device 100 may support one or more video codecs. Thus, the device 100 may play or record videos in a variety of coding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, and MPEG4.

[0071] NPU is a processor that draws on the structure of biological neural networks, such as the transmission mode between neurons in the human brain to quickly process input information, and can also continuously self-learn. The NPU can realize functions such as intelligent cognition of the device 100, such as: image recognition, face recognition, voice recognition and text understanding.

[0072] The external memory interface 120 can be used to connect an external memory card, such as a secure digital (SD) card, to expand the storage capacity of the 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.

[0073] The internal memory 121 can be used to store computer executable program codes, which include instructions. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system, at least one application required for a function (for example, a sound playback function and an image playback function). The data storage area can store data created during the use of the device 100 (for example, audio data and a phone book). 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, and a universal flash storage (UFS). The processor 110 executes various processing methods of the device 100 by running instructions stored in the internal memory 121 and / or instructions stored in a memory provided in the processor.

[0074] The 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 interface 170D, and the application processor.

[0075] The audio module 170 is used to convert digital audio information into analog audio signal output, and can also be used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 or some functional modules of the audio module 170 can be arranged in the processor 110.

[0076] The speaker 170A, also called a horn, is used to convert an audio electrical signal into a sound signal. The device 100 can listen to music or make a hands-free call through the speaker 170A.

[0077] The receiver 170B, also called an earpiece, is used to convert an audio electrical signal into a sound signal. When a user uses the device 100 to answer a call or voice message, the user can listen to the voice by placing the receiver 170B close to the ear.

[0078] Microphone 170C, also known as a microphone or a microphone, is used to convert sound signals into electrical signals. When a user makes a call or sends a voice message, the sound signal can be input into microphone 170C by speaking close to microphone 170C. Device 100 can be provided with at least one microphone 170C. In other embodiments, device 100 can be provided with two microphones 170C to achieve a noise reduction function. In other embodiments, device 100 can also be provided with three, four or more microphones 170C to achieve functions such as identifying the source of sound and directional recording. Processor 110 can process the electrical signal output by microphone 170C. For example, audio module 170 and wireless communication module 160 can be coupled through a PCM interface. After microphone 170C converts ambient sound into an electrical signal (such as a PCM signal), the electrical signal is transmitted to processor 110 through the PCM interface; volume analysis and frequency analysis are performed on the electrical signal from processor 110 to determine the volume and frequency of the ambient sound.

[0079] 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 or a cellular telecommunications industry association of the USA (CTIA) standard interface.

[0080] 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 set on the display screen 194. There are many types of pressure sensors 180A, for example, they can be resistive pressure sensors, inductive pressure sensors or capacitive pressure sensors. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When the force acts on the pressure sensor 180A, the capacitance between the electrodes changes, and the device 100 determines the intensity of the pressure according to the change in capacitance. When the touch operation acts on the display screen 194, the device 100 detects the touch operation according to the pressure sensor 180A. The device 100 can also calculate the position of the touch according to 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 the 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.

[0081] The gyro sensor 180B can be used to determine the motion posture of the device 100. In some embodiments, the angular velocity of the device 100 around three axes (i.e., the x-axis, the y-axis, and the z-axis) 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 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 device 100 through reverse movement to achieve anti-shake. The gyro sensor 180B can also be used in scenes such as navigation and somatosensory games.

[0082] The air pressure sensor 180C is used to measure air pressure. In some embodiments, the device 100 calculates the altitude through the air pressure value measured by the air pressure sensor 180C to assist in positioning and navigation.

[0083] The magnetic sensor 180D includes a Hall sensor. The device 100 can use the magnetic sensor 180D to detect the opening and closing of the flip leather case. In some embodiments, when the device 100 is a flip phone, the device 100 can detect the opening and closing of the flip cover according to the magnetic sensor 180D. The device 100 can set features such as automatic unlocking of the flip cover according to the detected opening and closing state of the leather case or the opening and closing state of the flip cover.

[0084] The acceleration sensor 180E can detect the magnitude of the acceleration of the device 100 in various directions (generally the x-axis, y-axis, and z-axis). When the device 100 is stationary, the magnitude and direction of gravity can be detected. The acceleration sensor 180E can also be used to identify the posture of the device 100 as an input parameter for applications such as horizontal and vertical screen switching and pedometers.

[0085] The distance sensor 180F is used to measure the distance. The device 100 can measure the distance by infrared or laser. In some embodiments, for example, in a shooting scene, the device 100 can use the distance sensor 180F to measure the distance to achieve fast focusing.

[0086] The proximity light sensor 180G may include, for example, a light-emitting diode (LED) and a light detector, such as a photodiode. The LED may be an infrared LED. The device 100 emits infrared light outward through the LED. The device 100 uses a photodiode to detect infrared reflected light from nearby objects. When the reflected light is detected, the device 100 can determine that there is an object nearby. When the reflected light is not detected, the device 100 can determine that there is no object nearby. The device 100 can use the proximity light sensor 180G to detect whether the user holds the device 100 close to the ear to talk, so as to automatically turn off the screen to save power. The proximity light sensor 180G can also be used for automatic unlocking and automatic screen lock in holster mode or pocket mode.

[0087] The ambient light sensor 180L is used to sense the brightness of the ambient light. The device 100 can adaptively adjust the brightness of the display screen 194 according to the perceived ambient light brightness. The ambient light sensor 180L can also be used to automatically adjust the white balance when taking pictures. The ambient light sensor 180L can also cooperate with the proximity light sensor 180G to detect whether the device 100 is in a pocket to prevent accidental touch.

[0088] The fingerprint sensor 180H is used to collect fingerprints. The device 100 can use the collected fingerprint characteristics to realize functions such as unlocking, accessing application locks, taking photos, and answering calls.

[0089] The temperature sensor 180J is used to detect temperature. In some embodiments, the device 100 uses the temperature detected by the temperature sensor 180J to execute a temperature processing strategy. For example, when the temperature reported by the temperature sensor 180J exceeds a threshold, the device 100 reduces the performance of a processor located near the temperature sensor 180J to reduce power consumption and implement thermal protection. In other embodiments, when the temperature is lower than another threshold, the device 100 heats the battery 142 to avoid abnormal shutdown of the device 100 due to low temperature. In other embodiments, when the temperature is lower than another threshold, the device 100 performs a boost on the output voltage of the battery 142 to avoid abnormal shutdown due to low temperature.

[0090] The touch sensor 180K is also called a touch control device. The touch sensor 180K can be set on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, which is also called a touch control screen. The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor 180K 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 180K can also be set on the surface of the device 100 and set at a different position from the display screen 194.

[0091] The bone conduction sensor 180M can obtain a vibration signal. In some embodiments, the bone conduction sensor 180M can obtain a vibration signal of a vibrating bone block of the vocal part of the human body. The bone conduction sensor 180M can also contact the human pulse to receive a blood pressure beat signal. In some embodiments, the bone conduction sensor 180M can also be set in an earphone and combined into a bone conduction earphone. The audio module 170 can parse out a voice signal based on the vibration signal of the vibrating bone block of the vocal part obtained by the bone conduction sensor 180M to realize a voice function. The application processor can parse the heart rate information based on the blood pressure beat signal obtained by the bone conduction sensor 180M to realize a heart rate detection function.

[0092] The button 190 includes a power button and a volume button. The button 190 can be a mechanical button or a touch button. The device 100 can receive a button input signal and implement a function related to the case input signal.

[0093] Motor 191 can generate vibration. Motor 191 can be used for incoming call reminders and can also be used for touch feedback. Motor 191 can generate different vibration feedback effects for touch operations acting on different applications. Motor 191 can also generate different vibration feedback effects for touch operations acting on different areas of the display screen 194. Different application scenarios (for example, time reminders, receiving messages, alarm clocks, and games) can correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.

[0094] The indicator 192 may be an indicator light, which may be used to indicate the charging status and the change in the amount of electricity, and may also be used to indicate messages, missed calls, and notifications.

[0095] The SIM card interface 195 is used to connect a SIM card. The SIM card can be inserted into the SIM card interface 195 to achieve contact with the device 100, and can also be pulled out from the SIM card interface 195 to achieve separation from the device 100. The device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. Multiple cards can be inserted into the same SIM card interface 195 at the same time, and the types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with external memory cards. The device 100 interacts with the network through the SIM card to achieve functions such as calls and data communications. In some embodiments, the device 100 uses an embedded SIM (embedded-SIM, eSIM) card, and the eSIM card can be embedded in the device 100 and cannot be separated from the device 100.

[0096] The hardware system of the device 100 is described in detail above, and the software system of the device 100 is introduced below. The software system can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture or a cloud architecture. The embodiment of the present application takes the layered architecture as an example to exemplarily describe the software system of the device 100.

[0097] like Figure 2 As shown, the software system using a layered architecture is divided into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the software system can be divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the Android runtime (Android Runtime) and the system library, and the kernel layer.

[0098] The application layer may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc.

[0099] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer may include some predefined functions.

[0100] For example, the application framework layer includes the window manager, content provider, view system, phone manager, resource manager, notification manager, PSI pressure registration collection module, memory information collection module, application scenario monitoring module and system pressure decision module.

[0101] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, and capture the screen.

[0102] Content providers are used to store and retrieve data and make it accessible to applications. The data may include video, images, audio, calls made and received, browsing history and bookmarks, and phone books.

[0103] The view system includes visual controls, such as controls for displaying text and controls for displaying images. 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.

[0104] The phone manager is used to provide communication functions of the device 100, such as management of call status (connected or disconnected).

[0105] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, and video files.

[0106] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used for download completion notifications and message reminders. The notification manager can also manage notifications that appear in the system's top status bar in the form of icons or scrolling text, such as notifications from applications running in the background. The notification manager can also manage notifications that appear on the screen in the form of dialog windows, such as prompting text messages in the status bar, emitting reminder sounds, vibrating electronic devices, and flashing indicator lights.

[0107] The PSI pressure registration acquisition module is used to collect various types of PSI, such as central processing unit (CPU) running time, memory recovery time and I / O waiting time; the memory information acquisition module is used to collect memory-related information such as available memory, swap free and anon pages; the application scenario monitoring module is used to collect scenario information such as APP startup and APP switching.

[0108] The system pressure decision module is used to make memory adjustment decisions based on the information collected by the PSI pressure registration collection module, the memory information collection module and the application scenario monitoring module.

[0109] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.

[0110] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.

[0111] The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

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

[0113] The surface manager is used to manage the display subsystem and provide the fusion of 2D layers and 3D layers for multiple applications.

[0114] The media library supports playback and recording of multiple audio formats, playback and recording of multiple video formats, and static image files. The media library can support multiple audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG and PNG.

[0115] The 3D graphics processing library can be used to implement 3D graphics drawing, image rendering, compositing and layer processing.

[0116] A 2D graphics engine is a drawing engine for 2D drawings.

[0117] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.

[0118] The following is an illustrative description of the workflow of the software system and the hardware system of the device 100 in combination with displaying a photo-taking scene.

[0119] When the user performs a touch operation on the touch sensor 180K, the corresponding hardware interrupt is sent to the operating system layer, and the operating system layer processes the touch operation into an original input event, which includes, for example, information such as the touch coordinates and the timestamp of the touch operation; then, the operating system layer identifies the control corresponding to the original input and output event, and notifies the application (APP) corresponding to the control. For example, if the above touch operation is a single-click operation, and the APP corresponding to the above control is a camera APP, the camera APP can call the background service through the API, transmit the control instruction to the logical port management module, and control the camera 193 to shoot through the logical port management module.

[0120] When the camera app is running, data related to the camera app can be temporarily stored in the memory, waiting for the processor to call. If the memory resources are insufficient, the processor may need to wait for a while to obtain the data of the camera app. Therefore, the usage of memory resources is associated with the operation of the camera app (such as the startup rate).

[0121] In order to improve the utilization of memory resources, it is necessary to manage the usage of memory resources. Memory resources can be managed by adjusting memory configuration parameters. The following introduces two memory configuration parameters applicable to this application.

[0122] 1. Extra free memory configuration parameter (extra_free_kbytes).

[0123] The configuration method of extra_free_kbytes can be / proc / sys / vm / extra_free_kbytes, which means to increase the values ​​of low watermark and high watermark without changing the minimum watermark.

[0124] The value of extra_free_kbytes is positively correlated with the size of the kernel's reserved memory, that is, the larger the value of extra_free_kbytes, the larger the kernel's reserved memory, and accordingly, the smaller the memory that third-party apps (such as camera apps) can use. When the value of extra_free_kbytes is large, the memory compaction function kswapd / kcompactd will be triggered more frequently, and the memory recycling function lowmemorykiller will also be triggered more frequently to reserve more memory for the kernel. When the value of extra_free_kbytes is small, third-party apps can use more memory, but the probability of direct reclaim or I / O blocking during memory allocation will increase.

[0125] 2. Memory swap parameters (swappiness).

[0126] The swappiness setting can be configured in / proc / sys / vm / swappiness. The kernel will try to swap runtime memory to zRAM or delete memory pages in the system cache to get more memory. Swappiness is used to balance the usage frequency of these two methods. The larger the swappiness value, the more actively the kernel will swap runtime memory to zRAM; the smaller the swappiness value, the more the kernel will prefer to delete memory pages in the system cache.

[0127] By setting the values ​​of memory configuration parameters, you can control how the kernel manages memory. If the values ​​of memory configuration parameters are not set appropriately, system performance will be degraded. For example, when the swappiness value is small, if there are a large number of file read tasks, the system will fall into a cache thrashing state (i.e., insufficient memory causes file pages to be frequently read and released repeatedly). Even if there is a large amount of free space in the zRAM, it cannot be used, resulting in high system I / O load.

[0128] The following is a detailed description of the memory adjustment method provided by the present application.

[0129] The method for adjusting memory provided in this application can be applied to Figure 3 The system shown in FIG. 1 includes a PSI pressure registration and acquisition module, a memory information acquisition module, an application scenario monitoring module and a system pressure decision module.

[0130] The PSI pressure registration collection module is used to collect various types of PSI from the PSI group time collector. The PSI group time collector is used to count the cumulative time of the tasks in each group, such as CPU running time, memory reclaim time and I / O waiting time. Among them, the CPU running time is CPU PSI, which reflects the computing pressure of the system; the memory reclaim time is memory reclaim PSI, which reflects the memory reclaim pressure of the system; the I / O waiting time is I / O PSI, which reflects the I / O pressure of the system.

[0131] For example, a CPU can process multiple tasks, including a memory recovery task, and the time taken by the CPU to complete the multiple tasks is the CPU running time, wherein the time taken by the CPU to complete the memory recovery task is the memory recovery time. In addition, the time taken by the multiple tasks to read and write from a disk is the I / O waiting time.

[0132] The memory information collection module is used to read / prof / meminfo through the prof fs file system. / prof / meminfo includes, for example, available memory (memory available), available swap space (swap free), and the number of anonymous pages (anon pages).

[0133] Swap free reflects the remaining capacity of zRAM, and anon pages reflects the amount of data that can be input into zRAM. When swap free is low and anon pages is low, the use of zRAM is not profitable, and the use frequency of zRAM can be reduced; when swap free is high and anon pages is high, the use of zRAM is profitable, and the use frequency of zRAM can be increased. Adjusting memory configuration parameters consumes computing resources. Therefore, when the available memory (physical memory) is large, there is no need to adjust the memory configuration parameters; when the available memory is small, the memory configuration parameters can be adjusted.

[0134] The application scenario monitoring module is used to collect scenario information such as APP startup and APP switching. For example, the scenario information can be obtained through the activity manager service (AMS) in the system service.

[0135] The system pressure decision module can obtain pressure thresholds and adjustment parameters, where the pressure threshold can be the time window size for PSI statistics, the reporting threshold for different pressures, the threshold for the remaining amount of zRAM space, the threshold for the anon page size, etc.; the adjustment parameter can be the upper limit, lower limit, preset value, etc. of swappiness adjustment. The system pressure decision module can also make memory adjustment decisions based on the pressure threshold, adjustment parameters, information collected by the PSI pressure registration collection module, memory information collection module, and application scenario monitoring module. For example, swappiness and extra_free_kbytes can be adjusted through the proc fs file system.

[0136] The following is a detailed introduction to the workflow of the PSI pressure registration and acquisition module, memory information acquisition module, application scenario monitoring module and system pressure decision module.

[0137] The PSI pressure registration collection module can collect multiple types of PSI, such as CPU PSI, memory recycling PSI and I / OPSI. Each type of PSI can be divided into multiple levels. For example, CPU PSI can correspond to high pressure events, medium pressure events and low pressure events according to different values.

[0138] Figure 4 It is a collection process of a single type of PSI.

[0139] After the PSI pressure registration and collection module starts working, it can register the memory pressure monitoring and set the initial pressure state to no pressure. Then, the PSI pressure registration and collection module waits for the kernel to report the pressure event based on the epoll_wait mechanism.

[0140] If the current pressure state is no pressure, the PSI pressure registration and acquisition module waits for pressure reporting in blocking mode. Subsequently, if a pressure event is received during the waiting period for pressure reporting, the PSI pressure registration and acquisition module sets the pressure based on the pressure event; if no pressure event is received during the waiting period for pressure reporting, the PSI pressure registration and acquisition module continues to wait for pressure event reporting.

[0141] If the current pressure state is pressure, the PSI pressure registration and acquisition module can set a timeout based on the pressure reporting cycle and determine whether there is pressure reporting before the timeout.

[0142] If there is a pressure report before the timeout, the PSI pressure registration and acquisition module can set the pressure based on the pressure event; if there is no pressure report before the timeout, the PSI pressure registration and acquisition module can set the pressure state to no pressure.

[0143] It should be noted that the "currently no pressure" in S401 refers to the judgment made by the PSI pressure registration and acquisition module based on the information collected in the previous pressure reporting cycle, while S403 and S404 refer to the judgment made by the PSI pressure registration and acquisition module based on the information collected in the current pressure reporting cycle.

[0144] After executing S403 or S404, the PSI pressure registration and acquisition module may repeatedly execute S401.

[0145] For the same type of pressure, the PSI pressure registration collection module only exposes the one with the greatest semantics. For example, when the kernel reports high pressure events and low pressure events to the PSI pressure registration collection module, the PSI pressure registration collection module only displays the high pressure event to the system pressure decision module.

[0146] If the PSI pressure registration collection module registers multiple types of pressure monitoring, the kernel reports each type of pressure event independently. For example, the PSI pressure registration collection module can register CPU pressure monitoring, memory recycling pressure monitoring, and I / O pressure monitoring; then, the kernel reports CPU pressure events, memory recycling pressure events, and I / O pressure events to the PSI pressure registration collection module respectively.

[0147] The following is a specific example of how the PSI pressure registration and acquisition module works.

[0148] Set a 1s time window, within which the kernel will continuously count the CPU processing time for each task, memory recycling time, and I / O waiting time.

[0149] Taking the processing time of a multi-core CPU as an example, after the kernel collects the processing time of the multi-core CPU, it can convert the processing time of multiple CPU cores into the processing time of a single-core CPU through a weighted average algorithm.

[0150] You can preset the CPU pressure to be low when the processing time reaches 400ms, medium when the processing time reaches 500ms, and high when the processing time reaches 600ms. When the CPU processing time counted by the kernel is less than 400ms, the kernel does not report a CPU pressure event; when the CPU processing time counted by the kernel is greater than or equal to 400ms and less than 500ms, the kernel reports a CPU low pressure event; when the CPU processing time counted by the kernel is greater than or equal to 500ms and less than 600ms, the kernel reports a CPU medium pressure event; when the CPU processing time counted by the kernel is greater than or equal to 600ms, the kernel reports a CPU high pressure event.

[0151] In the above CPU pressure event reporting process, each pressure event is reported independently, that is, the PSI pressure registration and collection module may receive multiple pressure events in a time window. The semantic size of multiple pressure events is sorted as follows: high pressure event > medium pressure event > low pressure event > no pressure event. If the PSI pressure registration and collection module receives multiple pressure events in a time window, it only needs to show the event with the largest semantics to the system pressure decision module.

[0152] It should be noted that the no-pressure event is not an event reported by the kernel, but an event generated by the PSI pressure registration and collection module. When the kernel does not report any pressure event within a time window, the PSI pressure registration and collection module generates a no-pressure event.

[0153] During the processing time statistics, since the time window is continuously sliding, all information needs to be re-counted when the next time window comes. The kernel can count the processing time of the next time window according to the following method to improve statistical efficiency.

[0154] For example, time window 1 and time window 2 are two adjacent time windows, both of which have a duration of 1 second. The CPU processing time in time window 1 is 800 ms, and when time window 2 reaches 300 ms, the CPU processing time counted by the kernel is 50 ms. Then, the kernel can predict that the CPU processing time of time window 2 is 610 ms according to formula (1).

[0155] T2=(T1 / T)*Tn+Tm(1);

[0156] In formula (1), T2 is the predicted CPU processing time in the current time window, T1 is the CPU processing time in the previous time window, T is the duration of the time window, Tn is the remaining duration of the current time window, and Tm is the actual CPU processing time in the current time window.

[0157] In the above example, T1=800ms, T=1s, Tn=700ms, Tm=50ms, and substituting these numbers into formula (1) yields T2=610ms.

[0158] Figure 5 It is a schematic diagram of the workflow of a memory information collection module provided in this application.

[0159] After the memory information collection module starts working, / prof / meminfo can be read through the prof fs file system. / prof / meminfo is the memory information. / prof / meminfo can include memory available, swap free and anon pages. Among them, swap free and anon pages are memory information indicating the frequency of zRAM usage.

[0160] Since adjusting memory configuration parameters consumes computing resources, after recording the currently read memory information, the memory information collection module can determine whether to start the system pressure decision module based on memory available. When memory available is lower than the memory threshold, it means that there is less available memory. At this time, starting the system pressure decision module can achieve greater benefits. The system pressure decision module can be started. The following will detail the method of adjusting memory configuration parameters based on information such as swap free and anonpages by the system pressure decision module; when memory available is higher than the memory threshold, it means that there is more available memory. At this time, starting the system pressure decision module cannot achieve greater benefits. The memory information collection module can sleep for a period of time (for example, 2s) and then read / prof / meminfo again.

[0161] Optionally, the memory information collection module can monitor the registration startup scene when starting to work, and can be triggered by the application scene (such as application cold start) to enter the awake state after hibernation, and then read / prof / meminfo.

[0162] Figure 6 It is a schematic diagram of the workflow of an application scenario monitoring module provided in this application.

[0163] After the Activity is started, the application scenario monitoring module can be inserted before the AMS application life cycle core callback function to monitor the application scenario. The above AMS application life cycle core callback function may include Figure 6 The creation function (onCreate), start function (onStart), resume function (onResume), pause function (onPause), stop function (onStop), close function (onDestroy) and restart function (onRestart) are shown. Each function corresponds to an application scenario. By inserting stubs before these functions, the application scenario monitoring module can obtain various scenario information.

[0164] The above describes in detail the workflows of the PSI pressure registration and acquisition module, the memory information acquisition module, and the application scenario monitoring module. Next, the workflow of the system pressure decision module will be described in detail.

[0165] like Figure 7 As shown, the system pressure decision module is initialized and loaded Figure 3 The pressure threshold and adjustment parameters shown are then registered, and the PSI pressure registration acquisition module, memory information acquisition module and application scenario monitoring module are subsequently registered, and PSI, memory information and scenario information are obtained from these three modules respectively.

[0166] When the value of memavailable is lower than the memavailable waterline ( Figure 7 When the value of memavailable is lower than the memavailable waterline, the available memory is in a loose state, and the system pressure decision module can obtain little system benefit by continuing to adjust the memory, so the memory adjustment function can be exited.

[0167] Optionally, the memory threshold can be set according to the size of the physical memory. When the physical memory of the terminal device is large, the memory threshold can be set to a value with a lower proportion; when the physical memory of the terminal device is small, the memory threshold can be set to a value with a higher proportion.

[0168] For example, if the physical memory of terminal device A is 12GB and the physical memory of terminal device B is 6GB, the memavailable watermark of terminal device A can be set to one-third of the physical memory, that is, 4GB; the memavailable watermark of terminal device B can be set to one-half of the physical memory, that is, 3GB. In this way, the terminal device with a larger physical memory (terminal device A) can reduce the consumption of computing resources by memory adjustment while ensuring sufficient available memory; the terminal device with a smaller physical memory (terminal device B) can adjust the memory in advance to reduce the probability of problems such as insufficient memory.

[0169] Figure 8 It is a schematic diagram of the workflow of the system pressure decision module.

[0170] After the system pressure decision module starts working (ie, initialized), if the available memory is lower than the memory threshold (ie, the value of memavailable is lower than the memavailable waterline), it is determined whether the memory pressure is high.

[0171] For example, the time required for a memory recovery task (i.e., the time indicated by the memory PSI) indicates the memory demand pressure. When the time required for the memory recovery task is greater than the third time threshold, it means that there are currently more memory recovery tasks and the third-party APP has a greater demand for memory. The system pressure decision module can reduce extra_free_kbytes to reserve more memory for the third-party APP; when the time required for the memory recovery task is less than the third time threshold, it means that there are currently fewer memory recovery tasks and the third-party APP has a smaller demand for memory. The system pressure decision module can increase extra_free_kbytes to reserve more memory for the kernel.

[0172] After adjusting extra_free_kbytes, the system pressure decision module can adjust swappiness.

[0173] The system pressure decision module first determines whether the current APP running scenario meets the preset scenario. If the current APP running scenario meets the preset scenario, the system pressure decision module can issue the swappiness corresponding to the preset scenario. For example, if the preset scenario is the application startup scenario and the current APP running scenario is also the application startup scenario, the system pressure decision module can determine whether the current APP running scenario meets the preset scenario; the various resource requirements of the application startup scenario are relatively fixed, and the system performance can be optimized by adjusting the memory according to the preset swappiness, without collecting PSI, swap free, anon pages and other information for calculation, thereby reducing the complexity of memory adjustment.

[0174] If the current APP running scenario does not meet the preset scenario, the system pressure decision module can adjust swappiness based on information such as PSI, swapfree and anon pages. The adjustment method is shown in Table 1.

[0175] Table 1

[0176] I / O PSI CPU PSI swap free&anon pages swappiness N / A Low high ↑ Low high N / A ↓ Low N / A Low ↓ high high N / A Balance Value high N / A Low Balance Value

[0177] In Table 1, N / A indicates that the parameter is not currently applicable. I / O PSI is positively correlated with I / O pressure. The larger the I / O PSI, the greater the I / O pressure. CPU PSI is positively correlated with computing pressure. The larger the CPU PSI, the greater the computing pressure.

[0178] For the judgment method of the first row in Table 1, when the processing time (the time indicated by the CPU PSI) is less than the second time threshold, it means that the computing pressure is small, and the frequency of zRAM usage can be increased in exchange for more available memory. When swap free is high and anon pages are high, the use benefit of zRAM is large, and the frequency of zRAM usage can be increased. Considering CPU PSI, anon pages and swap free comprehensively, the swappiness value can be increased to increase the frequency of zRAM usage, thereby achieving optimal system performance and improving the effect of memory management.

[0179] For the judgment method of the second row in Table 1, when the processing time (the time indicated by the CPU PSI) is greater than the second time threshold, it means that the computing pressure is large, and the frequency of zRAM usage can be reduced to reduce the computing resource requirements. When the I / O time (the time indicated by the I / O PSI) is less than the first time threshold, it means that the current I / O pressure is small and the demand for memory is small, so the frequency of zRAM usage can be reduced. Considering the I / O PSI and CPU PSI comprehensively, the swappiness value can be reduced to reduce the frequency of zRAM usage, thereby achieving optimal system performance and improving the effect of memory management.

[0180] For the judgment method of the third row in Table 1, when the I / O time (the time indicated by the I / O PSI) is less than the first time threshold, it means that the current I / O pressure is small and the demand for memory is small, so the frequency of zRAM usage can be reduced. When swap free is low and anon pages is low, the benefit of zRAM usage is small, so the frequency of zRAM usage can be reduced. Considering I / O PSI, anon pages, and swap free comprehensively, the swappiness value can be reduced to reduce the frequency of zRAM usage, thereby achieving optimal system performance and improving the effect of memory management.

[0181] For the judgment method of the fourth row in Table 1, when the processing time (the time indicated by the CPU PSI) is greater than the second time threshold, it means that the computing pressure is large, and the frequency of zRAM usage can be reduced to reduce the computing resource demand. When the I / O time (the time indicated by the I / O PSI) is greater than the first time threshold, it means that the current I / O pressure is large and the demand for memory is large. The frequency of zRAM usage should be increased in exchange for more available memory. Considering the I / O PSI and CPU PSI comprehensively, swappiness can be set to a suitable value (such as a preset balance value) to balance the computing resource demand and memory demand, thereby achieving optimal system performance and improving the effect of memory management.

[0182] For the judgment method of the fifth row in Table 1, when the I / O time (the time indicated by the I / O PSI) is greater than the first time threshold, it means that the current I / O pressure is large and the demand for memory is large, and the frequency of use of zRAM should be increased. When swap free is low and anon pages is low, the benefit of using zRAM is small, and the frequency of use of zRAM should be reduced. Considering I / O PSI, swap free and anon pages comprehensively, swappiness can be set to a suitable value (such as a preset balance value) to balance the memory demand and the benefit of using zRAM, so as to achieve optimal system performance and improve the effect of managing memory.

[0183] The above five ways of adjusting swappiness are some embodiments provided by this application. Based on the above adjustment ideas, more adjustment methods can be expanded, and this application will not list them one by one. In addition, the above first time threshold and the second time threshold can be preset values, such as Figure 3 The threshold value obtained by the system pressure decision module is shown in FIG.

[0184] If the PSI, swap free, and anon pages obtained by the system pressure decision module do not meet the conditions shown in Table 1, the system pressure decision module may not adjust swappiness. Regardless of whether swappiness is adjusted, the system pressure decision module may sleep for a period of time after making a judgment according to Table 1 to reduce the consumption of computing resources and memory resources.

[0185] After applying the above method on a Huawei phone with 2GB of memory and EMUI11.0 lite, the startup time of the camera app under high system load (such as launching 30 apps in a row) was reduced by 50ms compared to the startup time without applying the above method, and the available memory was increased by 80MB.

[0186] In the above embodiment, the system pressure decision module first adjusts extra_free_kbytes, and then adjusts swappiness; in the process of adjusting swappiness, the system pressure decision module first adjusts swappiness based on the application scenario, and then adjusts swappiness based on PSI, swap free and anon pages. It should be noted that the order of these adjustment steps can be interchangeable, and this application does not limit this.

[0187] For example, the system pressure decision module may adjust swappiness first and then adjust extra_free_kbytes; in the process of adjusting swappiness, the system pressure decision module may first adjust swappiness based on PSI, swap free, and anon pages, and then adjust swappiness based on the application scenario.

[0188] The above describes in detail an example of a method for adjusting memory provided by the present application. It is understandable that, in order to implement the above functions, the corresponding device includes a hardware structure and / or software module corresponding to each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present application.

[0189] The present application can divide the functional units of the device for adjusting memory according to the above method example. For example, each function can be divided into each functional unit, or two or more functions can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units. It should be noted that the division of units in the present application is schematic and is only a logical functional division. There may be other division methods in actual implementation.

[0190] Fig. 9 1 is a schematic diagram of a device for adjusting memory provided by the present application. The device 900 includes a processing unit 910 and an input unit 920, wherein the input unit 920 can perform the acquisition step under the control of the processing unit 910.

[0191] For example:

[0192] The input unit 920 is used to: obtain multiple resource pressures, where the multiple resource pressures are used to indicate multiple requirements for memory compression;

[0193] The processing unit 910 is used to adjust the memory configuration parameters according to the multiple resource pressures, and there is a preset corresponding relationship between the memory configuration parameters and the multiple resource pressures.

[0194] Optionally, the memory configuration parameters include memory swap parameters, the multiple resource pressures include input / output pressure and memory swap space pressure, and the processing unit 910 is specifically used to: when the input / output pressure decreases, and when the memory swap space pressure decreases, reduce the memory swap parameter; or when the input / output pressure increases, and when the memory swap space pressure decreases, adjust the memory swap parameter to a preset value.

[0195] Optionally, the memory configuration parameters include memory swap parameters, the multiple resource pressures include processor pressure and memory swap space pressure, and the processing unit 910 is specifically used to: increase the memory swap parameters when the processor pressure decreases and when the memory swap space pressure increases.

[0196] Optionally, the size of the memory swap space pressure is positively correlated with the number of anonymous pages.

[0197] Optionally, the size of the memory swap space pressure is positively correlated with the size of the available swap space.

[0198] Optionally, the memory configuration parameters include memory swap parameters, the multiple resource pressures include processor pressure and input / output pressure, and the processing unit 910 is specifically used to: when the input / output pressure decreases and when the processor pressure increases, reduce the memory swap parameters; or when the input / output pressure increases and when the processor pressure increases, adjust the memory swap parameters to a preset value.

[0199] Optionally, the processing unit 910 is specifically configured to: when the current application running scenario indicated by the scenario information does not conform to a preset scenario, adjust the memory configuration parameters according to the multiple resource pressures.

[0200] Optionally, the processing unit 910 is further configured to: when the memory reclaiming pressure increases, reduce the extra free memory configuration parameter; or when the memory reclaiming pressure decreases, increase the extra free memory configuration parameter.

[0201] Optionally, the processing unit 910 is specifically configured to: when the available memory is less than a memory threshold, adjust the memory configuration parameters according to the multiple resource pressures.

[0202] The specific manner in which the device 900 executes the method for adjusting memory and the beneficial effects produced can refer to the relevant description in the method embodiment.

[0203] Fig.10 A structural schematic diagram of an electronic device provided by the present application is shown. Fig.10The dotted line in the figure indicates that the unit or the module is optional. The device 1000 can be used to implement the method described in the above method embodiment. The device 1000 can be a terminal device, a server or a chip.

[0204] The device 1000 includes one or more processors 1001, which can support the device 1000 to implement the method in the method embodiment. The processor 1001 can be a general-purpose processor or a special-purpose processor. For example, the processor 1001 can be a central processing unit (CPU), a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, such as discrete gates, transistor logic devices, or discrete hardware components.

[0205] The processor 1001 may be used to control the device 1000, execute software programs, and process data of the software programs. The device 1000 may also include a communication unit 1005 to implement input (reception) and output (transmission) of signals.

[0206] For example, device 1000 may be a chip, communication unit 1005 may be an input and / or output circuit of the chip, or communication unit 1005 may be a communication interface of the chip, and the chip may be a component of a terminal device, a server, or other electronic devices.

[0207] For another example, the device 1000 may be a terminal device or a server, and the communication unit 1005 may be a transceiver of the terminal device or the server, or the communication unit 1005 may be a transceiver circuit of the terminal device or the server.

[0208] The device 1000 may include one or more memories 1002, on which a program 1004 is stored. The program 1004 can be executed by the processor 1001 to generate instructions 1003, so that the processor 1001 performs the method described in the above method embodiment according to the instructions 1003. Optionally, data can also be stored in the memory 1002. Optionally, the processor 1001 can also read the data stored in the memory 1002 (as shown in Table 1), and the data can be stored at the same storage address as the program 1004, or the data can be stored at a different storage address from the program 1004.

[0209] The processor 1001 and the memory 1002 may be provided separately or integrated together, for example, integrated on a system on chip (SOC) of a terminal device.

[0210] The device 1000 may further include an antenna 1006. The communication unit 1005 is configured to implement the transceiver function of the device 1000 through the antenna 1006.

[0211] The present application also provides a computer program product, which, when executed by the processor 1001, implements the method described in any method embodiment of the present application.

[0212] The computer program product may be stored in the memory 1002 , for example, a program 1004 , which is converted into an executable target file that can be executed by the processor 1001 after preprocessing, compiling, assembling, and linking.

[0213] The present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a computer, the method described in any method embodiment of the present application is implemented. The computer program can be a high-level language program or an executable target program.

[0214] The computer-readable storage medium is, for example, a memory 1002. The memory 1002 may be a volatile memory or a nonvolatile memory, or the memory 1002 may include both a volatile memory and a nonvolatile memory. Among them, the nonvolatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM), and direct rambus RAM (DR RAM).

[0215] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described devices and equipment and the technical effects produced can refer to the corresponding processes and technical effects in the aforementioned method embodiments, and will not be repeated here.

[0216] In several embodiments provided in the present application, the disclosed systems, devices, and methods may be implemented in other ways. For example, some features of the method embodiments described above may be ignored or not performed. The device embodiments described above are merely schematic, and the division of units is merely a logical function division. There may be other division methods in actual implementation, and multiple units or components may be combined or integrated into another system. In addition, the coupling between the units or the coupling between the components may be direct coupling or indirect coupling, and the coupling may include electrical, mechanical, or other forms of connection.

[0217] It should be understood that in the various embodiments of the present application, the size of the serial number of each process does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0218] In addition, the terms "system" and "network" are often used interchangeably in this article. The term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0219] In short, the above is only a preferred embodiment of the technical solution of this application, and is not intended to limit the protection scope of this application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this application should be included in the protection scope of this application.

Claims

1. A method for adjusting memory configuration parameters, characterized in that: include: Get at least two resource pressures; adjusting memory configuration parameters according to the at least two resource pressures; When the at least two resource pressures include input / output pressure and memory swap space pressure, adjusting the memory configuration parameters according to the at least two resource pressures includes: When the input / output pressure decreases and when the memory swap space pressure decreases, the memory swap parameter is reduced.

2. The method according to claim 1, characterized in that When the input / output pressure increases, and when the memory swap space pressure decreases, the memory swap parameter is adjusted to a preset value.

3. The method according to claim 1, characterized in that When the at least two resource pressures include processor pressure and memory swap space pressure, The adjusting the memory configuration parameters according to the at least two resource pressures includes: When the processor pressure decreases and when the memory swap space pressure increases, the memory swap parameter is increased.

4. The method according to claim 2 or 3, characterized in that: The size of the memory swap space pressure is positively correlated with the number of anonymous pages.

5. The method according to any one of claims 2 to 4, characterized in that The size of the memory swap space pressure is positively correlated with the size of the available swap space.

6. The method according to claim 1, characterized in that When the at least two resource pressures include processor pressure and input / output pressure, The adjusting the memory configuration parameters according to the at least two resource pressures includes: When the input / output pressure decreases, and when the processor pressure increases, reducing the memory swap parameter; or, When the input / output pressure increases, and when the processor pressure increases, the memory swap parameter is adjusted to a preset value.

7. The method according to any one of claims 1 to 6, characterized in that The adjusting the memory configuration parameters according to the at least two resource pressures includes: When the current application running scenario indicated by the scenario information does not conform to the preset scenario, the memory configuration parameters are adjusted according to the at least two resource pressures.

8. The method according to any one of claims 1 to 7, characterized in that The memory configuration parameters also include additional free memory configuration parameters, and the method further includes: When memory reclaim pressure increases, reduce the extra free memory configuration parameter; or, When memory reclaim pressure decreases, increase the extra free memory configuration parameter.

9. The method according to any one of claims 1 to 8, characterized in that The adjusting the memory configuration parameters according to the at least two resource pressures includes: When the available memory is less than the memory threshold, the memory configuration parameter is adjusted according to the at least two resource pressures.

10. The method according to claim 9, characterized in that The ratio of the memory threshold to the physical memory is negatively correlated with the size of the physical memory.

11. A device for adjusting memory configuration parameters, characterized in that: The device comprises a processor and a memory, wherein the processor and the memory are coupled, and the memory is used to store a computer program. When the computer program is executed by the processor, the device executes the method according to any one of claims 1 to 10.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 10.