Memory management method and device, electronic equipment and computer readable storage medium
Patent Information
- Application Number
- CN202111603331.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2020-12-23
- Filing Date
- 2020-12-30
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2040-12-30
AI Technical Summary
然而终端设备在使用过程中,随着应用打开数量的增加,其中运行的进程越来越多,占用的内存也会越来越多,这样将会使得系统的可用内存变少,出现内存不足的问题,进而导致终端设备出现卡顿现象
[0032]Fourthly, embodiments of this application also provide a computer-readable storage medium comprising computer instructions that, when executed on an electronic device, cause the electronic device to perform the memory management method as described above.
Smart Images

Figure CN114443277B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a memory management method, apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] With the development of terminal technology, terminal devices have become indispensable items in people's daily lives. However, during the use of terminal devices, as the number of applications opened increases, the number of running processes also increases, consuming more and more memory. This reduces the available memory of the system, leading to insufficient memory and causing the terminal device to lag. Summary of the Invention
[0003] This application provides a memory management method, apparatus, electronic device, and computer-readable storage medium for managing the memory of electronic devices. This can improve memory reclamation efficiency, reduce system lag, and enhance user experience.
[0004] In a first aspect, embodiments of this application provide a memory management method, the memory management method comprising:
[0005] When the first application starts, an application-level memory control group for the first application is created; anonymous pages of the first application are added to the least recently used list of the application-level memory control group, and anonymous pages are reclaimed according to the least recently used list; file pages of the first application are added to the global least recently used list of memory nodes, and file pages are reclaimed according to the global least recently used list. By using the memory management method provided in this application embodiment, by creating a corresponding application-level memory control group for the first application, adding the anonymous pages of the first application to the corresponding application-level memory control group, and adding the file pages of the first application to the global least recently used list, not only can anonymous pages be managed in a fine-grained manner, but memory reclamation efficiency is also maintained, thereby reducing system lag and improving the user experience.
[0006] In conjunction with the first aspect, in one possible design, the memory management method further includes: managing anonymous pages of the first application according to the application-level memory control group; and / or controlling the reclamation order of the anonymous pages according to the state of the first application; and / or controlling the reclamation ratio of the anonymous pages according to the application-level memory control group, wherein the reclamation ratio of the anonymous pages is the number of anonymous pages to be reclaimed in the first application and the total number of anonymous pages in the first application; and / or controlling the memory usage of the first application managed by the application-level memory control group. Based on the above design, the embodiments of this application can manage the anonymous pages of the application according to the application-level memory control group, for example, managing memory reclamation and release, thereby improving the user experience.
[0007] In conjunction with the first aspect, in one possible design, the memory management method further includes: determining the recycling order of anonymous pages of the first application based on the frozen state and / or active state and / or foreground state of the first application. Therefore, embodiments of this application can manage the anonymous pages of an application according to the application-level memory control group, for example, managing memory reclamation and release, thereby improving the user experience.
[0008] In conjunction with the first aspect, in one possible design, creating the application-level memory control group (AMR) of the first application upon startup further includes: when the first process of the first application starts, creating the AMR corresponding to the first application according to the application identifier of the first process. Based on this design, each application has an application identifier, which can be used to uniquely identify the application. Therefore, the first application can create the corresponding AMR according to the application identifier upon startup, thereby creating the corresponding AMR at the application level and improving memory reclamation efficiency.
[0009] In conjunction with the first aspect, in one possible design, when the first process of the first application starts, creating the application-level memory control group corresponding to the first application according to the application identifier corresponding to the first process further includes: if the memory control group corresponding to the application identifier of the first process does not exist, then creating the application-level memory control group corresponding to the first application. Based on this design, system lag can be reduced and the user experience improved.
[0010] In conjunction with the first aspect, in one possible design, if the application identifier exists in a memory control group, the first process is added to the application-level memory control group, and the first process is managed according to the application-level memory control group. Based on this design, when the first process of the application starts, the anonymous pages allocated by the first process can be added to the application-level memory control group, and the file pages allocated by the first process can be added to the global least recently used list. Therefore, the above design can perform targeted memory reclamation, improving the efficiency of memory reclamation.
[0011] In conjunction with the first aspect, in one possible design, the memory management method further includes: when the electronic device starts up, creating a corresponding memory control group according to a whitelist; when a system process starts up, determining whether it is a whitelisted process based on its process name; if it is a whitelisted process, adding it to the memory control group. This design can prevent the system from mistakenly reclaiming these system processes, thus avoiding impacting the user experience.
[0012] In conjunction with the first aspect, in one possible design, the memory management method further includes: adding the anonymous pages of the whitelisted processes to the least recently used list of the memory control group; and reclaiming the anonymous pages of the whitelisted processes according to the least recently used list. This design can prevent the system from mistakenly reclaiming these system processes, thus avoiding negative impacts on the user experience.
[0013] In conjunction with the first aspect, in one possible design, the memory management method further includes: adding the file pages of the whitelisted processes to a global least recently used linked list of memory nodes; and reclaiming the file pages of the whitelisted processes according to the global least recently used linked list. This design can prevent the system from mistakenly reclaiming these system processes, thus avoiding negative impacts on the user experience.
[0014] In one possible design, the memory management method further includes: when the second process of the first application starts, adding the anonymous pages of the second process to the least recently used list of the application-level memory control group, and adding the file pages of the second process to the global least recently used list. Therefore, the above design can perform targeted memory reclamation, improving the efficiency of memory reclamation.
[0015] In one possible design, the memory management method further includes: removing the first process and / or the second process from the application-level memory control group when the first process and / or the second process is destroyed. Based on this design, when a process is destroyed, it is removed from the memory control group, thereby releasing the process's anonymous pages and file pages, improving the smoothness of the operating system and preventing lag in electronic devices.
[0016] In one possible design, the memory management method further includes deleting the application-level memory control group when the first application is destroyed. Based on this design, the process's anonymous pages can be deleted and released from the least recently used list of the application-level memory control group, and the process's file pages can be deleted and released from the global least recently used list, thereby improving the smoothness of the operating system and preventing lag in electronic devices.
[0017] In one possible design, the memory management method further includes: when the first application requests the anonymous page, adding the anonymous page to the active least recently used list of the application-level memory control group; and when the first application requests the file page, adding the file page to the global active least recently used list. Therefore, the above design can perform targeted memory reclamation, improving the efficiency of memory reclamation.
[0018] Secondly, embodiments of this application also provide a memory management device, the memory management device comprising:
[0019] A module is created to create the application-level memory control group for the first application when the first application starts.
[0020] The control module is used to add the anonymous pages of the first application to the least recently used list of the memory control group, and reclaim the anonymous pages according to the least recently used list. The control module is also used to add the file pages of the first application to the global least recently used list, and reclaim the file pages according to the global least recently used list. Using the memory management device provided in this application embodiment, the creation module creates a corresponding application-level memory control group for the first application, and the control module adds the anonymous pages of the first application to the corresponding application-level memory control group and the file pages of the first application to the global least recently used list. This not only allows for fine-grained management of anonymous pages but also does not affect memory reclamation efficiency, thereby reducing system lag and improving the user experience.
[0021] In conjunction with the second aspect, in one possible design, the memory management device further includes a management module, which is further configured to: manage anonymous pages of the first application according to the application-level memory control group; and / or control the reclamation order of the anonymous pages according to the state of the first application; and / or control the reclamation ratio of the anonymous pages according to the application-level memory control group, wherein the reclamation ratio of the anonymous pages is the number of anonymous pages to be reclaimed in the first application and the total number of anonymous pages in the first application; and / or control the memory usage of the application-level memory control group. Based on this design, memory reclamation efficiency can be improved, thereby reducing system lag and enhancing the user experience.
[0022] In conjunction with the second aspect, in one possible design, the creation module can also be used to create an application-level memory control group corresponding to the first application according to the application identifier corresponding to the first process when the first process of the first application starts. Based on this design, each application has an application identifier, which can be used to uniquely identify the application. Therefore, the creation module can create the corresponding application-level memory control group according to the application identifier when the first application starts, thereby creating the corresponding application-level memory control group at the application level and improving memory reclamation efficiency.
[0023] In conjunction with the second aspect, in one possible design, the creation module is further configured to create an application-level memory control group corresponding to the first application when the memory control group corresponding to the application identifier of the first process does not exist. Therefore, the above design can perform targeted memory reclamation, improving the efficiency of memory reclamation.
[0024] In conjunction with the second aspect, in one possible design, the control module is used to add the first process to the application-level memory control group when the application identifier indicates that a memory control group exists; the management module is also used to manage the first process according to the application-level memory control group. Based on this design, memory reclamation efficiency can be improved, thereby reducing system lag and enhancing the user experience.
[0025] In one possible design, the management module is used to remove the first process from the application-level memory control group when the first process is destroyed. Based on this design, when a process is destroyed, it is removed from the memory control group, thereby releasing the process's anonymous pages and file pages, improving the smoothness of the operating system and preventing lag in electronic devices.
[0026] In one possible design, the management module is further configured to delete the application-level memory control group when the first application is destroyed. Based on this design, the process's anonymous pages are removed and released from the least recently used list of the first memory control group, and the process's file pages are removed and released from the global least recently used list, thereby improving the smoothness of the operating system and preventing lag in electronic devices.
[0027] In some possible designs, when the first application requests the anonymous page, the control module adds the anonymous page to the active least recently used list of the application-level memory control group; when the first application requests the file page, the control module adds the file page to the global active least recently used list. Therefore, the above design can perform targeted memory reclamation, improving the efficiency of memory reclamation.
[0028] Thirdly, embodiments of this application also provide an electronic device, the electronic device comprising:
[0029] Memory, used to store computer programs;
[0030] A processor is configured to execute the computer program stored in the memory, and when the computer program is executed, the processor is configured to perform the memory management method as described above.
[0031] Based on the above design, by creating a corresponding memory control group for the first application, adding the anonymous pages of the first application to the corresponding memory control group, and adding the file pages of the first application to the global least recently used list, not only can the anonymous pages be managed in a fine-grained manner, but the memory reclamation efficiency will not be affected, thereby reducing system lag and improving the user experience.
[0032] Fourthly, embodiments of this application also provide a computer-readable storage medium comprising computer instructions that, when executed on an electronic device, cause the electronic device to perform the memory management method as described above.
[0033] In this embodiment, by creating a corresponding application-level memory control group for the first application, adding the anonymous pages of the first application to the corresponding application-level memory control group, and adding the file pages of the first application to the global least recently used list, not only can the anonymous pages be managed in a fine-grained manner, but the memory reclamation efficiency will not be affected, thereby reducing system lag and improving the user experience. Attached Figure Description
[0034] Figure 1 This is a schematic diagram of the structure of an electronic device to which the memory management method provided in the embodiments of this application is applicable.
[0035] Figure 2 This is a schematic diagram of the structure of an operating system provided in an embodiment of this application.
[0036] Figure 3 This is a flowchart illustrating a memory management method provided in an embodiment of this application.
[0037] Figure 4 This is a flowchart illustrating another memory management method provided in an embodiment of this application.
[0038] Figure 5 This is a flowchart illustrating another memory management method provided in an embodiment of this application.
[0039] Figure 6 This is a schematic diagram of a memory management method provided in an embodiment of this application.
[0040] Figure 7 This is a schematic diagram of another memory management method provided in an embodiment of this application.
[0041] Figure 8 This is a schematic diagram of another memory management method provided in an embodiment of this application.
[0042] Figure 9 This is a schematic diagram of a memory management device provided in an embodiment of this application.
[0043] Explanation of main component symbols
[0044] Electronic devices 100
[0045] Processor 110
[0046] External memory interface 120
[0047] Internal memory 121
[0048] USB interface 130
[0049] Charging management module 140
[0050] Power Management Module 141
[0051] Battery 142
[0052] Antennas 1 and 2
[0053] Mobile communication module 150
[0054] Wireless communication module 160
[0055] Audio Module 170
[0056] Speaker 170A
[0057] Receiver 170B
[0058] Microphone 170C
[0059] 170D headphone jack
[0060] Sensor Module 180
[0061] Pressure sensor 180A
[0062] 180B Gyroscope Sensor
[0063] 180C barometric pressure sensor
[0064] Magnetic Sensor 180D
[0065] 180E Accelerometer
[0066] Distance sensor 180F
[0067] 180G Proximity Light Sensor
[0068] 180H fingerprint sensor
[0069] Temperature sensor 180J
[0070] 180K touch sensor
[0071] 180L Ambient Light Sensor
[0072] 180M bone conduction sensor
[0073] Button 190
[0074] Motor 191
[0075] Indicator 192
[0076] Camera 193
[0077] Display screen 194
[0078] SIM card interface 195
[0079] Memory management device 200
[0080] Create module 201
[0081] Control Module 202
[0082] Management Module 203
[0083] The following detailed description, in conjunction with the accompanying drawings, will further illustrate this application. Detailed Implementation
[0084] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0085] The term "and / or" in this application describes a relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent three cases: A exists alone, A and B exist simultaneously, and B exists alone. The symbol " / " in this document indicates that the related objects are in an "or" relationship; for example, A / B means A or B.
[0086] In the embodiments of this application, terms such as "first" and "second" are used only to distinguish different objects and should not be construed as indicating or implying relative importance or order. For example, "first application" and "second application" are used to distinguish different applications, not to describe a specific order of applications. Features specified as "first" or "second" may explicitly or implicitly include one or more of those features.
[0087] In the description of the embodiments of this application, the words "exemplary" or "for example" are used to indicate that they are examples, illustrations, or descriptions. Any embodiment or design that is described as "exemplary" or "for example" in the embodiments of this application should not be construed as having a greater advantage than other embodiments or design. Rather, the use of the words "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0088] This application discloses a memory management method, an electronic device, and a computer-readable storage medium, which can improve the stability of the operating system, avoid lag in electronic devices, and enhance the user experience.
[0089] The memory management method provided in this application can be applied to electronic devices, which may also be referred to as user equipment (UE), mobile station (MS), mobile terminal, etc. Optionally, the electronic device may have the ability to communicate with one or more core networks via a radio access network (RAN). For example, the electronic device may be a mobile phone (or "cellular" phone) or a mobile computer, etc.
[0090] Figure 1 A schematic diagram of the structure of the electronic device 100 is shown.
[0091] Electronic device 100 may be a mobile phone, tablet computer, desktop computer, laptop computer, handheld computer, notebook computer, ultra-mobile personal computer (UMPC), netbook, as well as cellular phone, personal digital assistant (PDA), augmented reality (AR) device, virtual reality (VR) device, artificial intelligence (AI) device, wearable device, in-vehicle device, smart home device and / or smart city device. The embodiments of this application do not impose any special restrictions on the specific type of electronic device.
[0092] Electronic device 100 may include processor 110, external memory interface 120, internal memory 121, universal serial bus (USB) interface 130, charging management module 140, power management module 141, battery 142, antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, sensor module 180, button 190, motor 191, indicator 192, camera 193, display screen 194, and subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity 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.
[0093] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0094] Processor 110 may include one or more processing units, such as application processors (APs), modem processors, graphics processing units (GPUs), image signal processors (ISPs), controllers, video codecs, digital signal processors (DSPs), baseband processors, and / or neural network processing units (NPUs). These different processing units may be independent devices or integrated into one or more processors.
[0095] The controller can generate operation control signals based on the instruction opcode and timing signals to complete the control of instruction fetching and execution.
[0096] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can directly retrieve it from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0097] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0098] 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 I2C buses. The processor 110 can couple to the touch sensor 180K, charger, flash, camera 193, etc., through different I2C bus interfaces. For example, the processor 110 can couple to the touch sensor 180K through the I2C interface, enabling the processor 110 and the touch sensor 180K to communicate through the I2C bus interface, thereby realizing the touch function of the electronic device 100.
[0099] The I2S interface can be used for audio communication. In some embodiments, the processor 110 may include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to enable communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 can transmit audio signals to the wireless communication module 160 via the I2S interface to enable the function of answering phone calls through a Bluetooth headset.
[0100] 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 bus interface. In some embodiments, the audio module 170 can also transmit audio signals to the wireless communication module 160 via the PCM interface, enabling the function of answering phone calls through a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
[0101] The UART interface is a universal serial data bus used for asynchronous communication. This bus can be a bidirectional communication bus. It converts the data to be transmitted between serial and parallel communication. In some embodiments, the UART interface is typically 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 via the UART interface to implement Bluetooth functionality. In some embodiments, the audio module 170 can transmit audio signals to the wireless communication module 160 via the UART interface to enable music playback through Bluetooth headphones.
[0102] The MIPI interface can be used to connect the processor 110 to peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI) and a display serial interface (DSI). In some embodiments, the processor 110 and the camera 193 communicate via the CSI interface to enable the electronic device 100 to capture images. The processor 110 and the display screen 194 communicate via the DSI interface to enable the electronic device 100 to display images.
[0103] The GPIO interface can be configured via software. It can be configured as a control signal or a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 to a camera 193, a display screen 194, a wireless communication module 160, an audio module 170, a sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.
[0104] USB port 130 is a USB standard compliant interface, specifically a Mini USB port, Micro USB port, USB Type-C port, etc. USB port 130 can be used to connect a charger to charge electronic device 100, and can also be used for data transfer between electronic device 100 and peripheral devices. It can also be used to connect headphones for audio playback. This interface can also be used to connect other electronic devices, such as AR devices.
[0105] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.
[0106] The charging management module 140 receives charging input from a charger. The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 receives charging input from the wired charger via the USB interface 130. In some wireless charging embodiments, the charging management module 140 receives wireless charging input via the wireless charging coil of the electronic device 100. While charging the battery 142, the charging management module 140 can also supply power to the electronic device via the power management module 141.
[0107] The power management module 141 connects 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, providing power to the processor 110, internal memory 121, display screen 194, camera 193, and wireless communication module 160, etc. The power management module 141 can also monitor parameters such as battery capacity, battery cycle count, and battery health status (leakage current, impedance). In some other embodiments, the power management module 141 may also be located within the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may be located in the same device.
[0108] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.
[0109] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover one or more communication frequency bands. Different antennas can also be reused to improve antenna utilization. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with a tuning switch.
[0110] The mobile communication module 150 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the electronic device 100. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves via antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to a modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via antenna 1. In some embodiments, at least some functional modules of the mobile communication module 150 may be housed in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 150 and at least some modules of the processor 110 may be housed in the same device.
[0111] The modem processor may include a modulator and a demodulator. The modulator modulates the low-frequency baseband signal to be transmitted into a mid-to-high frequency signal. The demodulator demodulates 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 processing by the baseband processor, the low-frequency baseband signal is transmitted to the application processor. The application processor outputs sound signals through an audio device (not limited to speaker 170A, receiver 170B, etc.) or displays images or videos through the display screen 194. In some embodiments, the modem processor may be a separate device. In other embodiments, the modem processor may be independent of the processor 110 and may be housed in the same device as the mobile communication module 150 or other functional modules.
[0112] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 100, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. 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 antenna 2, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.
[0113] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, enabling electronic device 100 to communicate with networks and other devices via wireless communication technology. The wireless communication technology may include Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Time Division Code Division Multiple Access (TD-SCDMA), Long Term Evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technologies, etc. The GNSS may include the Global Positioning System (GPS), the Global Navigation Satellite System (GLONASS), the BeiDou Navigation Satellite System (BDS), the Quasi-Zenith Satellite System (QZSS), and / or satellite-based augmentation systems (SBAS).
[0114] Electronic device 100 implements 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 and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0115] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel may 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 miniature LED, a microLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 100 may include one or N displays 194, where N is a positive integer greater than 1.
[0116] Electronic device 100 can perform shooting functions through ISP, camera 193, video codec, GPU, display 194 and application processor.
[0117] The ISP (Image Signal Processor) is used to process data fed back from the camera 193. For example, when taking a picture, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, and the camera's photosensitive element transmits the electrical signal to the ISP for processing, transforming it into an image visible to the naked eye. The ISP can also perform algorithmic optimization of image noise, brightness, and skin tone. The ISP can also optimize parameters such as exposure and color temperature of the shooting scene. In some embodiments, the ISP can be set in the camera 193.
[0118] Camera 193 is used to capture still images or videos. An object is projected onto a photosensitive element by generating an optical image through the lens. The photosensitive element can be a charge-coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, which is then passed to an ISP for conversion into a digital image signal. The ISP outputs the digital image signal to a DSP for processing. The DSP converts the digital image signal into image signals in standard RGB, YUV, or other formats. In some embodiments, the electronic device 100 may include one or N cameras 193, where N is a positive integer greater than 1.
[0119] Digital signal processors (DSPs) are used to process digital signals. Besides digital image signals, they can also process other digital signals. For example, when electronic device 100 selects a frequency, the DSP can perform Fourier transforms on the frequency energy.
[0120] Video codecs are used to compress or decompress digital video. Electronic device 100 may support one or more video codecs. Thus, electronic device 100 can play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0121] An NPU (Neural Processing Unit) is a computational processor for neural networks (NNs). By borrowing the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it can rapidly process input information and continuously learn on its own. NPUs enable intelligent cognitive applications in electronic devices, such as image recognition, facial recognition, speech recognition, and text understanding.
[0122] Internal memory 121 may include one or more random access memory (RAM) and one or more non-volatile memory (NVM).
[0123] Random access memory can include static random-access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM, for example, fifth generation DDR SDRAM is generally called DDR5 SDRAM), etc.
[0124] Non-volatile memory can include disk storage devices and flash memory.
[0125] Flash memory can be classified according to its operating principle, including NOR FLASH, NAND FLASH, 3D NAND FLASH, etc.; according to the level of the storage cell, including single-level cell (SLC), multi-level cell (MLC), triple-level cell (TLC), quad-level cell (QLC), etc.; and according to the storage specification, including universal flash storage (UFS) and embedded multimedia card (eMMC), etc.
[0126] The random access memory can be directly read and written by the processor 110. It can be used to store executable programs (such as machine instructions) of the operating system or other running programs, as well as user and application data.
[0127] Non-volatile memory can also store executable programs and user and application data, and can be pre-loaded into random access memory for direct reading and writing by the processor 110.
[0128] The external memory interface 120 can be used to connect to external non-volatile memory, thereby expanding the storage capacity of the electronic device 100. The external non-volatile memory communicates with the processor 110 through the external memory interface 120 to perform data storage functions. For example, music, video, and other files can be stored in the external non-volatile memory.
[0129] Electronic device 100 can implement audio functions, such as music playback and recording, through audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, and application processor.
[0130] The audio module 170 is used to convert digital audio information into analog audio signals for output, and also to convert analog audio input into digital audio signals. The audio module 170 can also be used for encoding and decoding audio signals. In some embodiments, the audio module 170 may be located in the processor 110, or some functional modules of the audio module 170 may be located in the processor 110.
[0131] The speaker 170A, also known as a "loudspeaker," is used to convert audio electrical signals into sound signals. The electronic device 100 can listen to music or make hands-free calls through the speaker 170A.
[0132] The receiver 170B, also known as the "earpiece," is used to convert audio electrical signals into sound signals. When the electronic device 100 answers a telephone call or voice message, the receiver 170B can be brought close to the ear to listen to the voice.
[0133] Microphone 170C, also known as a "microphone" or "voice transducer," is used to convert sound signals into electrical signals. When making a phone call or sending a voice message, the user can speak by bringing their mouth close to microphone 170C, inputting the sound signal into microphone 170C. Electronic device 100 may have at least one microphone 170C. In some embodiments, electronic device 100 may have two microphones 170C, which, in addition to collecting sound signals, can also perform noise reduction. In other embodiments, electronic device 100 may also have three, four, or more microphones 170C, which can collect sound signals, reduce noise, identify the sound source, and perform directional recording, etc.
[0134] The 170D headphone jack is used to connect wired headphones. The 170D headphone jack can be a USB 130 interface or a 3.5mm Open Mobile Terminal Platform (OMTP) standard interface, a CTIA (Cellular Telecommunications Industry Association of the USA) standard interface.
[0135] Pressure sensor 180A is used to sense pressure signals and convert them into electrical signals. In some embodiments, pressure sensor 180A can be disposed on display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, and capacitive pressure sensors. A capacitive pressure sensor may include at least two parallel plates with conductive material. When force is applied to pressure sensor 180A, the capacitance between the electrodes changes. Electronic device 100 determines the pressure intensity based on the change in capacitance. When a touch operation is applied to display screen 194, electronic device 100 detects the intensity of the touch operation based on pressure sensor 180A. Electronic device 100 can also calculate the touch position based on the detection signal from pressure sensor 180A. In some embodiments, touch operations applied to the same touch position but with different touch operation intensities can correspond to different operation commands. For example, when a touch operation with an intensity less than a first pressure threshold is applied to the SMS application icon, a command to view an SMS is executed. When a touch operation with an intensity greater than or equal to the first pressure threshold is applied to the SMS application icon, a command to create a new SMS is executed.
[0136] The gyroscope sensor 180B can be used to determine the motion attitude of the electronic device 100. In some embodiments, the gyroscope sensor 180B can determine the angular velocity of the electronic device 100 about three axes (i.e., the x, y, and z axes). The gyroscope sensor 180B can be used for image stabilization. For example, when the shutter is pressed, the gyroscope sensor 180B detects the angle of the shake of the electronic device 100, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to counteract the shake of the electronic device 100 by moving in the opposite direction, thus achieving image stabilization. The gyroscope sensor 180B can also be used in navigation and motion-sensing game scenarios.
[0137] The barometric pressure sensor 180C is used to measure air pressure. In some embodiments, the electronic device 100 calculates altitude using the air pressure value measured by the barometric pressure sensor 180C to assist in positioning and navigation.
[0138] The magnetic sensor 180D includes a Hall sensor. The electronic device 100 can use the magnetic sensor 180D to detect the opening and closing of the flip cover. In some embodiments, when the electronic device 100 is a flip phone, the electronic device 100 can detect the opening and closing of the flip cover using the magnetic sensor 180D. Then, based on the detected opening and closing state of the cover or the flip cover, features such as flip unlocking can be set.
[0139] The 180E accelerometer can detect the magnitude of acceleration of electronic device 100 in various directions (typically three axes). When electronic device 100 is stationary, it can detect the magnitude and direction of gravity. It can also be used to identify the posture of electronic devices and applied to applications such as screen orientation switching and pedometers.
[0140] A distance sensor 180F is used to measure distance. Electronic device 100 can measure distance via infrared or laser. In some embodiments, during a shooting scene, electronic device 100 can utilize the distance sensor 180F to measure distance for rapid focusing.
[0141] The proximity 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 electronic device 100 emits infrared light outward through the LED. The electronic device 100 uses the photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that an object is near the electronic device 100. When insufficient reflected light is detected, the electronic device 100 can determine that no object is near the electronic device 100. The electronic device 100 may use the proximity sensor 180G to detect when a user holds the electronic device 100 close to their ear for a phone call, so as to turn off the screen to save power. The proximity sensor 180G can also be used for unlocking and locking the screen in holster mode and pocket mode.
[0142] The ambient light sensor 180L is used to sense the brightness of ambient light. The electronic device 100 can adaptively adjust the brightness of the display screen 194 based on the sensed ambient light brightness. The ambient light sensor 180L can also be used to adjust the white balance when taking pictures. The ambient light sensor 180L can also work with the proximity sensor 180G to detect whether the electronic device 100 is in a pocket to prevent accidental touches.
[0143] The fingerprint sensor 180H is used to acquire fingerprints. The electronic device 100 can utilize the acquired fingerprint characteristics to achieve fingerprint unlocking, accessing application locks, taking photos with fingerprints, answering calls with fingerprints, etc.
[0144] Temperature sensor 180J is used to detect temperature. In some embodiments, electronic device 100 uses the temperature detected by temperature sensor 180J to execute a temperature handling strategy. For example, when the temperature reported by temperature sensor 180J exceeds a threshold, electronic device 100 performs thermal protection by reducing the performance of a processor located near temperature sensor 180J to reduce power consumption. In other embodiments, when the temperature is below another threshold, electronic device 100 heats battery 142 to prevent abnormal shutdown of electronic device 100 due to low temperature. In still other embodiments, when the temperature is below yet another threshold, electronic device 100 boosts the output voltage of battery 142 to prevent abnormal shutdown due to low temperature.
[0145] Touch sensor 180K, also known as a "touch device," can be located on display screen 194. The touch sensor 180K and display screen 194 together form a touchscreen, also known as a "touchscreen." Touch sensor 180K detects touch operations applied to or near it. The touch sensor can transmit 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 display screen 194. In other embodiments, touch sensor 180K may also be located on the surface of electronic device 100, in a different position than display screen 194.
[0146] The bone conduction sensor 180M can acquire vibration signals. In some embodiments, the bone conduction sensor 180M can acquire vibration signals from the vibrating bone segments of the human vocal cords. The bone conduction sensor 180M can also contact the human pulse to receive blood pressure signals. In some embodiments, the bone conduction sensor 180M can also be incorporated into headphones to form bone conduction headphones. The audio module 170 can parse the voice signals from the vibrating bone segments of the vocal cords acquired by the bone conduction sensor 180M to realize voice functionality. The application processor can parse heart rate information from the blood pressure signals acquired by the bone conduction sensor 180M to realize heart rate detection functionality.
[0147] Buttons 190 include a power button, volume buttons, etc. Buttons 190 can be mechanical buttons or touch-sensitive buttons. Electronic device 100 can receive button input and generate key signal inputs related to user settings and function control of electronic device 100.
[0148] Motor 191 can generate vibration alerts. Motor 191 can be used for incoming call vibration alerts or for touch vibration feedback. For example, different vibration feedback effects can correspond to touch operations performed on different applications (such as taking photos, playing audio, etc.). Motor 191 can also correspond to different vibration feedback effects for touch operations performed on different areas of the display screen 194. Different application scenarios (such as time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also be customized.
[0149] Indicator 192 can be an indicator light, used to indicate charging status, power changes, or to indicate messages, missed calls, notifications, etc.
[0150] The SIM card interface 195 is used to connect a SIM card. The SIM card can be inserted into or removed from the SIM card interface 195 to make contact with and separate from the electronic device 100. The electronic device 100 can support one or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, etc. Multiple cards can be inserted into the same SIM card interface 195 simultaneously. The multiple cards can be of the same or different types. The SIM card interface 195 is also compatible with different types of SIM cards. The SIM card interface 195 is also compatible with external storage cards. The electronic device 100 interacts with the network through the SIM card to realize functions such as calls and data communication. In some embodiments, the electronic device 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from it. The software system of the electronic device 100 can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This application uses the layered architecture of the Android system as an example to illustrate the software structure of the electronic device 100.
[0151] Figure 2 This is a software structure block diagram of the electronic device 100 according to an embodiment of this application.
[0152] A layered architecture divides software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the Android runtime and system libraries, and the kernel layer.
[0153] The application layer can include a series of application packages.
[0154] like Figure 2 As shown, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, and SMS.
[0155] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions.
[0156] like Figure 2 As shown, the application framework layer may include a window manager, content provider, view system, phone manager, resource manager, notification manager, etc.
[0157] The window manager is used to manage windowed applications. It can retrieve screen size, determine the presence of a status bar, lock the screen, and capture screenshots, among other things.
[0158] Content providers store and retrieve data, making that data accessible to applications. This data may include videos, images, audio, made and received phone calls, browsing history and bookmarks, phone books, etc.
[0159] A view system includes visual controls, such as controls for displaying text and controls for displaying images. View systems can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text notification icon could include views for displaying text and views for displaying images.
[0160] The phone manager is used to provide communication functions for electronic device 100. For example, it manages call status (including connection and disconnection).
[0161] The file explorer provides applications with various resources, such as localized strings, icons, images, layout files, video files, and more.
[0162] The notification manager allows applications to display notifications in the status bar. These notifications can be used to deliver informational messages, appear briefly, and then disappear without user interaction. For example, the notification manager can be used to notify users of download completion or message alerts. The notification manager can also display notifications as icons or scrolling text in the top status bar, such as notifications from background applications, or as dialog boxes on the screen. Examples include displaying text messages in the status bar, emitting sounds, vibrating electronic devices, and flashing indicator lights.
[0163] The Android Runtime consists of core libraries and a virtual machine. The Android runtime is responsible for the scheduling and management of the Android system.
[0164] The core library consists of two parts: one part is the functionalities that need to be called by the Java language, and the other part is the Android core library.
[0165] The application layer and application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.
[0166] System libraries can include multiple functional modules. For example: surface manager, media libraries, 3D graphics processing libraries (e.g., OpenGL ES), 2D graphics engines (e.g., SGL), etc.
[0167] The Surface Manager is used to manage the display subsystem and provides the blending of 2D and 3D layers for multiple applications.
[0168] The media library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG.
[0169] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0170] A 2D graphics engine is a graphics engine for 2D drawing.
[0171] The kernel layer is the layer between hardware and software. The kernel layer contains at least the display driver, camera driver, audio driver, and sensor driver.
[0172] The following example, using a scene of capturing a photograph, illustrates the workflow of the software and hardware of the electronic device 100.
[0173] When touch sensor 180K receives a touch operation, a corresponding hardware interrupt is sent to the kernel layer. The kernel layer processes the touch operation into a raw input event (including touch coordinates, timestamp of the touch operation, etc.). The raw input event is stored in the kernel layer. The application framework layer retrieves the raw input event from the kernel layer and identifies the control corresponding to the input event. Taking a touch click as an example, where the corresponding control is the camera application icon, the camera application calls the application framework layer's interface to launch the camera application, and then calls the kernel layer to launch the camera driver, capturing still images or videos through camera 193.
[0174] Based on the hardware structure of the aforementioned electronic device, various embodiments of the memory management method of this application are proposed.
[0175] This application provides a memory management method.
[0176] Please see Figure 3 , Figure 3 This is a flowchart of a memory management method provided in an embodiment of this application. The subject executing the memory management method is an electronic device 100, and the memory management method may include, but is not limited to, the following steps:
[0177] Step S31: When the application starts, the electronic device creates the application-level memory control group for that application.
[0178] The memory control group can be used to manage memory units corresponding to applications. It can be created in memory as an object and includes methods for managing memory units (such as controlling memory unit reclamation parameters) and relevant information describing memory resources. For example, the relevant information may include the current physical memory usage of the memory control group and the current memory activity status of the memory control group. Memory units can be in units of pages, and the size of a page can be 4KB. This application proposes an application-level memory control group that can be created when the application starts. It can include the memory information of the application's process and manage the application's process based on the memory information. This makes memory management more targeted, reduces the overhead of the memory management structure, improves the user experience, and improves memory reclamation efficiency.
[0179] An application is the smallest unit of interaction between the electronic device 100 and the user. Specifically, the electronic device 100 can provide services to the user through applications. For example, a user can play games through a game application, watch videos through a video application, or play music through a music application.
[0180] Electronic device 100 may include one or more applications, where "one or more" means two or more. For example, the electronic device 100 may install applications such as browsers, shopping apps, game apps, and music apps, and each application requires memory to start and run. In one embodiment, the electronic device 100 may create an application-level memory control group corresponding to the application when the application starts.
[0181] In this application embodiment, the first application can be one of the system applications in the electronic device or one of the third-party applications in the electronic device. Specifically, it can be determined according to actual usage needs, and this application embodiment does not limit it.
[0182] For example, if the application is a browser, the electronic device 100 can create an application-level memory control group (memcg1) corresponding to the browser when the browser starts. Therefore, the kernel will manage the browser's memory according to this application-level memory control group (memcg1). Similarly, if the application is a game application, the electronic device 100 can create an application-level memory control group (memcg2) corresponding to the game application when the game application starts. Then, the kernel can manage the game application's memory according to this application-level memory control group (memcg2).
[0183] In one implementation, the user space can create a folder (i.e., a memory control group) under the control group (cgroup) directory. This folder is created on an application-by-application basis; that is, the processes of any application can be added to this folder. Thus, multiple applications of the electronic device 100 can create their own application-level memory control groups upon startup. Therefore, in this embodiment, multiple applications in the electronic device 100 can create their own corresponding application-level memory control groups upon startup, i.e., application-level memory control groups are created at the application level.
[0184] It is understood that the above examples are exemplary and can be determined according to actual usage. This application does not limit the scope of the examples.
[0185] Step S32: Add the anonymous page requested by the application to the least recently used list of the application-level memory control group.
[0186] File-backed pages can be memory caches of data from disk; the data stored in a file-backed page can be found on disk. Anonymous pages, on the other hand, are memory pages dynamically allocated by the application and do not have corresponding disk files.
[0187] When the application starts, it requests memory resources from the system. The kernel can add the anonymous pages allocated by the application to the Least Recently Used (LRU) list of the application-level memory control group. For example, an application can add anonymous pages to its corresponding application-level memory control group immediately upon acquiring them. Least Recently Used can be a memory management algorithm used for memory management and reclamation control, specifically for selecting the least recently used page for reclamation.
[0188] Taking a shopping application as an example, if a user opens the shopping application on the electronic device 100, a corresponding application-level memory control group memcg3 will be created for the shopping application. The shopping application will also request memory resources from the system. At this time, when the shopping application immediately obtains an anonymous page, the electronic device 100 can add the obtained anonymous page to the LRU list in the application-level memory control group memcg3 for management.
[0189] Therefore, by creating a corresponding application-level memory control group for the application (which could be the shopping application), the anonymous pages requested by the application are added to the application-level memory control group corresponding to the application. Thus, this embodiment of the application can manage the anonymous pages of the application according to the application-level memory control group, and / or control the recycling order of the anonymous pages according to the state of the application, and / or control the recycling ratio of the anonymous pages according to the application-level memory control group, and / or control the memory usage of the application managed by the application-level memory control group.
[0190] In one embodiment, the order in which anonymous pages are recycled can be controlled based on the application's state; that is, the order in which applications are recycled can be determined based on the application's state. Specifically, embodiments of this application can determine the recycling order of anonymous pages based on the application's frozen state and / or active state and / or foreground state. For example, if application 1 is in a frozen state and application 2 is in an active state, then the anonymous pages of application 1 can be recycled first based on the frozen state of application 1, and then the anonymous pages of application 2 can be recycled. That is, the more active the application, the later its anonymous pages will be recycled.
[0191] In one embodiment, the reclamation ratio of anonymous pages can be controlled according to the application-level memory control group. For example, application 1 creates a corresponding application-level memory control group memcg1 at startup, and application 2 creates a corresponding application-level memory control group memcg2 at startup. If the reclamation ratio of anonymous pages controlled in application-level memory control group memcg1 is 60%, and LRU list 1 in application 1 includes 100 anonymous pages, only 60 anonymous pages can be reclaimed sequentially from the tail of LRU list 1 during memory reclamation. If the reclamation ratio of anonymous pages controlled in application-level memory control group memcg2 is 70%, and LRU list 2 in application 2 includes 100 anonymous pages, only 70 anonymous pages can be reclaimed sequentially from the tail of LRU list 2 during memory reclamation. It can be understood that in one embodiment, the more active the application, the lower its anonymous page reclamation ratio.
[0192] Step S33: Add the file page requested by the application to the global least recently used list.
[0193] As described above, when the application starts, it requests memory resources from the system, and the electronic device 100 adds the requested anonymous page to the application-level memory control group corresponding to the application. In the embodiments of this application, the electronic device 100 also adds the file page requested by the application to the global LRU list. For example, the application can add the file page to the global LRU list as soon as it is requested.
[0194] For example, at the first moment, the user can open a shopping application on electronic device 100. Electronic device 100 creates a corresponding application-level memory control group (memcg3) for this shopping application. At this time, the shopping application can load library files such as .so and .lib files from the disk, and the allocated file pages can be added to the global LRU list. At the second moment, the user can open a gallery application on electronic device 100. Electronic device 100 creates a corresponding application-level memory control group (memcg4) for this gallery application. When the user browses photos, the gallery application can load photos and other files from the disk, and the allocated file pages can be added to the global LRU list. After using the application for a period of time, the system can reclaim the library files and photo files according to their positions in the global LRU list.
[0195] Understandably, the LRU list can be divided into an active list and an inactive list, with pages reclaimed from the inactive list. In other words, the memory control group corresponding to the first application uses two LRU lists to manage anonymous pages, while file pages are managed using two global LRU lists.
[0196] Specifically, in the embodiments of this application, when the application requests anonymous pages and file pages, the requested anonymous pages are added to the active list of the application-level memory control group corresponding to the application, and the requested file pages are added to the global active list. When memory in the memory control group is reclaimed, it is first reclaimed from the cold data at the tail of the inactive list. When an anonymous page in the inactive list is referenced a preset number of times, it can be removed from the inactive list and placed into the active list. When there are insufficient anonymous pages in the inactive list, the system can continue to scan the active list and migrate some anonymous pages to the inactive list.
[0197] In one possible implementation, memory control groups can be created based on process identifiers (PIDs), with each process ID managing its own LRU list; that is, memory control groups are created at the process level. However, creating memory control groups based on process IDs leads to wasted power consumption in the electronic device 100, thus affecting user experience. It can be understood that an application is the smallest unit of interaction with the user in the electronic device 100. From the user's perspective, an application is an object to be manipulated; from the demand perspective, an application is a carrier of resource requirements. Therefore, in the technical solution of this application, application-level memory control groups are created at the application level. That is, one application-level memory control group is created for each application. Using the technical solution of this application, anonymous pages can be managed according to applications, memory, power consumption, and performance consumption can be controlled, and recycling efficiency is improved.
[0198] In one possible implementation, each process could correspond to a memory control group; however, this would consume significant system resources. Furthermore, file pages are caches or buffer areas of disk files, and sharing is their primary characteristic. Therefore, managing file pages according to memory control groups would lead to uneven distribution of hot and cold file pages. In addition, when memory is insufficient, memory is reclaimed; uneven distribution of hot and cold file pages would cause frequent reclamation of hotter file pages, easily leading to system lag and severely impacting user experience. Therefore, the technical solution provided in this application creates corresponding application-level memory control groups for applications, adds anonymous pages requested by the application to the LRU list of the application-level memory control group, and adds file pages requested by the application to a global LRU list. Thus, this application embodiment can manage anonymous pages at the application level, with controllable memory, power consumption, and performance, while also improving memory reclamation efficiency, reducing system lag, and enhancing user experience.
[0199] The storage management method of this application will be further described in detail below, based on the methods described in the above embodiments. Please refer to... Figure 4 , Figure 4Another flowchart illustrating the memory management method provided in this application embodiment may include, but is not limited to, the following steps:
[0200] Step S41: When the application process starts, an application-level memory control group corresponding to the application is created according to the application identifier corresponding to the process.
[0201] As we can understand it, a process is an application running in memory, and it is the basic unit for system resource allocation and scheduling. Each process has its own independent memory space.
[0202] It is understandable that each application has an application identifier (such as a package name) that can be used to uniquely identify the application. There are many ways to obtain the application identifier. For example, it can be determined by querying the application's configuration information, or it can be determined by the application's process identifier.
[0203] In one embodiment, an application may include multiple processes. That is, the application may include multiple processes, and when the application's processes start, an application-level memory control group corresponding to the first application is created according to the application identifier corresponding to the process. For example, in one embodiment, the electronic device 100 may create the application-level memory control group corresponding to the application according to the package name corresponding to the process.
[0204] For example, taking a browser as an example, assuming that process 1 of the browser starts, if the application-level memory control group (memcg1) corresponding to the application identifier APP1 of process 1 does not exist, then the application-level memory control group (memcg1) corresponding to the browser is created. If the application identifier APP1 of process 1 already has an application-level memory control group (memcg1), then the browser does not need to recreate the application-level memory control group (memcg1). In this case, process 1 is added to the application-level memory control group (memcg1) of the browser, and process 1 is managed according to the application-level memory control group (memcg1). The memory resources of process 1 can be added to the LRU list of the application-level memory control group (memcg1). Next, if the browser's process 2 starts, since the browser includes process 1 and process 2, process 2 and process 1 belong to the same application identifier APP1. At this time, the application identifier APP1 corresponding to process 2 has already created an application-level memory control group memcg1. Therefore, when process 2 starts, process 2 is directly added to the application-level memory control group memcg1 corresponding to the browser, and the memory resources of process 2 are added to the LRU list of the application-level memory control group memcg2.
[0205] Step S42: Add the anonymous pages of the process to the least recently used list of the memory control group, reclaim the anonymous pages according to the least recently used list, and add the file pages of the process to the global least recently used list of the memory node, and reclaim the file pages according to the global least recently used list.
[0206] In one embodiment, if the application identifier corresponding to the process has already created the application-level memory control group corresponding to the application, the anonymous pages requested by the first process can be added to the LRU list of the memory control group, and the file pages requested by the first process can be added to the global LRU list of the memory node.
[0207] For example, taking a browser as the first application, assuming that browser process 1 starts, since the application identifier APP1 corresponding to webpage 1 has already created an application-level memory control group memcg1, the anonymous page requested by process 1 is added to the browser's application-level memory control group memcg1, and the file page requested by process 1 is added to the global LRU list. Next, if browser process 2 starts, since process 2 and process 1 belong to the same application identifier APP1, and the application identifier APP1 corresponding to process 2 has already created an application-level memory control group memcg1, when process 2 starts, the anonymous page requested by process 2 is directly added to the browser's application-level memory control group memcg1. Therefore, the anonymous pages of process 1 and process 2 can be reclaimed according to the least recently used list, and the file pages requested by process 2 are added to the global LRU list, allowing for the reclamation of file pages of process 1 and process 2 based on the global least recently used list.
[0208] Step S43: If the process is destroyed, remove the process from the application-level memory control group.
[0209] In embodiments of this application, if the application's process is destroyed, the process can be removed from the application's application-level memory control group.
[0210] Assuming the application includes process 1, process 2, and process 3, when the system's memory resources are insufficient and memory needs to be reclaimed, the system can choose to kill process 1 and process 2, and simultaneously remove process 1 and process 2 from the memory control group corresponding to the application, thereby releasing some anonymous pages and file pages of the application to meet the system's memory requirements.
[0211] Step S44: If the application is destroyed, delete the application-level memory control group.
[0212] In embodiments of this application, if an application is destroyed, the memory control group corresponding to that application is deleted. For example, if all processes in the memory control group of the application are destroyed, the anonymous pages of those processes can be deleted and released from the least recently used list of the application-level memory control group, and the file pages of those processes can be deleted and released from the global least recently used list.
[0213] For example, when a user launches a browser, three processes are created: process 1, process 2, and process 3. These processes are all added to the browser's application-level memory control group (memcg1). When the user exits the browser, processes 1, 2, and 3 are destroyed from the application's memory control group, and the kernel removes the browser's application-level memory control group (memcg1). At this point, the memory occupied by the browser is released.
[0214] Please see Figure 5 , Figure 5 This is another schematic flowchart illustrating a memory management method provided in an embodiment of this application. The memory management method may include, but is not limited to, the following steps:
[0215] Step S51: Create a memory control group according to the whitelist.
[0216] In the embodiments of this application, when the electronic device 100 starts up, it can create a memory control group according to a whitelist. Therefore, critical system processes in the whitelist can be added to the memory control group.
[0217] Step S52: When the system process starts, determine whether it is a whitelisted process based on the process name of the system process.
[0218] System processes can include those necessary for the system to manage the computer and perform various operations, such as additional program processes started and executed by the user. Among these processes, some system processes are those that the system needs to call for operation. The absence of these processes will affect the operation of the entire system, such as critical system services and frequently used system services.
[0219] In the embodiments of this application, when a system process or system service starts, it can be determined whether it is a whitelisted process based on its process name. For example, the whitelist may include process name 1 of system process 1, process name 2 of system process 2, and process name 3 of system process 3. If system process 1 starts and its process name 1 is found in the whitelist, then system process 1 is determined to be a whitelisted process. If system process 2 starts and its process name 2 is found in the whitelist, then system process 2 is determined to be a whitelisted process. If system process 4 starts and its process name 4 is not found in the whitelist, then system process 4 is determined to be a non-whitelisted process.
[0220] Step S53: Add the system process to the memory control group.
[0221] In the embodiments of this application, if the process name of the system process determines that it is a whitelist process, then the whitelist process is added to the memory control group. That is, some critical system services and frequently used system services are added to the whitelist to avoid the system mistakenly reclaiming these system processes and affecting the user experience.
[0222] In one embodiment, if a system process is determined to be a whitelisted process, the anonymous pages of the whitelisted process can be added to the least recently used list of the memory control group, and the anonymous pages of the whitelisted process can be reclaimed according to the least recently used list. In addition, the file pages of the whitelisted process can be added to the global least recently used list of the memory node, thereby allowing the file pages of the whitelisted process to be reclaimed according to the global least recently used list.
[0223] Please see Figure 6 , Figure 6 This is a scene diagram of memory management disclosed in an embodiment of this application.
[0224] In embodiments of this application, when an application of the electronic device 100 is launched, an application-level memory control group can be created according to the application's package name. Therefore, in some embodiments of this application, each application creates an application-level memory control group. For example, each application manages memory according to its corresponding application-level memory control group.
[0225] In the embodiments of this application, when an application of the electronic device 100 is deleted, the application-level memory control group corresponding to the package name of the application can be deleted, and the memory corresponding to the application-level memory control group of the application can be released.
[0226] Please refer to the following: Figure 7 , Figure 7 This is a more specific scenario diagram of memory management disclosed in the embodiments of this application.
[0227] The following will take a news application as an example, and combine it with... Figure 7 The memory management scheme disclosed in this application will be described.
[0228] When process 1 of the news application is created, the electronic device 100 creates an application-level memory control group (memcg1) according to the package name of the news application. Then, the kernel adds the anonymous pages allocated by the news application to the application-level memory control group memcg1 and the file pages allocated by the news application to the global LRU list. It is understood that, in one embodiment, other applications in the electronic device, such as a music application, may also create a corresponding application-level memory control group (memcg2) at startup, add the anonymous pages allocated by the music application to the application-level memory control group memcg2, and add the file pages allocated by the music application to the global LRU list.
[0229] If process 2 of the news application is created, add process 2 to the application-level memory control group memcg1 of the news application, add the anonymous page requested by process 2 to the application-level memory control group memcg1, and add the file page requested by process 2 to the global LRU list.
[0230] If process 2 of the news application is destroyed, process 2 is removed from the application-level memory control group memcg1 of the news application, wherein the anonymous page of process 2 is removed from the application-level memory control group memcg2 of the news application, and the file page of process 2 is also removed from the global LRU list.
[0231] When the news application exits, the processes in the news application's application-level memory control group (memcg1) are destroyed, and the kernel will delete the news application's application-level memory control group (memcg1). At this time, the file pages and anonymous pages corresponding to the news application will also be released.
[0232] Therefore, by adopting the embodiments of this application, anonymous pages can be managed according to the application dimension, and memory, power consumption and performance consumption can be controlled, so as to achieve fine-grained memory management.
[0233] Please see Figure 8 , Figure 8 This is a scene diagram of memory management disclosed in an embodiment of this application.
[0234] The embodiments of this application customize multiple parameter setting interfaces for the application-level memory control group of each application. Therefore, user space can set the application's reclamation priority, the application's maximum memory usage, and the application's reclamation parameters through parameter settings.
[0235] Specifically, user space can control the reclamation order of an application's application-level memory control group (AMS) in kernel space by setting parameters for that AMS. For example, user space can set a reclamation priority based on the application's importance; therefore, when memory reclamation is needed, the reclamation order of the AMS in kernel space is controlled according to the application's reclamation priority. Furthermore, user space can also control the reclamation ratio of the AMS in kernel space based on its parameters.
[0236] As the kernel of a computing device, the operating system is independent of ordinary applications. It has access to protected memory space and also has permission to access underlying hardware devices. To ensure kernel security and prevent user processes from directly manipulating the kernel, the operating system divides the address space (which can be a portion of the computing device's memory or virtual memory) into two parts: kernel space, a protected memory space used to store kernel code and data; and user space, used to store application code and data. When a process executes user program code, the process is in user mode. Conversely, when a process executes a system call and enters kernel code, the process is in kernel mode. User-mode processes run in user space, and kernel-mode processes run in kernel space.
[0237] In one embodiment, user space can control the behavior of the application-level memory control group (AMS) in kernel space by setting parameters of the application's AMS. For example, user space can control the application's memory usage, such as the application's maximum memory usage, based on the parameters of the application's AMS.
[0238] For example, taking a browser as an application, the user space can set the maximum memory usage of the browser through an interface, thus limiting the memory size of each application. Suppose the browser's maximum memory usage is 800MB, but the browser actually uses 900MB. In this case, since the browser's file pages have been backed up to disk, the system kernel will clean up the browser's file pages and compress the browser's anonymous pages to meet the memory requirements.
[0239] As one possible implementation, in one embodiment, the parameters of the application-level memory control group can be set by providing the following interface:
[0240] Waterline setting interface: User space can set the standard waterline of system memory through the waterline setting interface, and the kernel will try its best to meet this waterline through reclamation to ensure that the system memory is in a healthy state.
[0241] Ratio setting interface: User space can set the recycling and replacement ratio of each application according to user habits and application characteristics through the ratio setting interface, so as to control the amount of recycling and replacement, reduce the invalid recycling of applications, and enhance the user experience.
[0242] Important rating value setting interface: Users can set the priority and importance of each application based on user habits and application characteristics through the important rating value setting interface, and determine their recycling order in the recycling process, thereby enhancing the user experience.
[0243] Application memory usage limit setting interface: User space can set the memory usage limit for each application through the application memory usage limit setting interface to ensure that each application uses memory in a healthy way.
[0244] Active compression interface: When the application is in a frozen state, the user space can actively compress and reclaim the application's anonymous pages through the active compression interface to increase system memory and ensure memory health.
[0245] Application memory usage interface: User space uses the application memory usage interface to query the anonymous page usage of various applications in the system, which is used as a reference when performing cleanup and recycling.
[0246] System Status Interface: User space uses the system status interface to query the real-time status of the system, such as the system's memory status, CPU status, I / O status, and the running status of some key processes.
[0247] By employing the technical solution in this application embodiment, when memory reclamation is required, the system can reclaim file pages according to the hot / cold status of the global LRU list, and anonymous pages according to user-defined parameters, based on the application's importance, maximum memory usage, and reclamation parameters. Therefore, the technical solution in this application embodiment makes memory reclamation more targeted and can further improve reclamation efficiency.
[0248] Please see Figure 9 , Figure 9 This is a schematic diagram of a memory management device disclosed in an embodiment of this application. The memory management device can be used to execute... Figures 3 to 8 For details on the steps of the memory management method described in [the document], please refer to [the document / reference]. Figures 3 to 8 The relevant descriptions in [the document] will not be repeated here. For example... Figure 9 As shown, the memory management device 200 may include: a creation module 201, a control module 202, and a management module 203.
[0249] In the embodiments of this application, the creation module 201 is used to create an application-level memory control group for the first application when the first application starts.
[0250] The control module 202 is used to add the anonymous pages requested by the application to the least recently used list of the memory control group. The control module 202 is also used to add the file pages requested by the application to the global least recently used list.
[0251] The creation module 201 can also be used to create an application-level memory control group corresponding to the application according to the application identifier corresponding to the process when the application's process starts.
[0252] Specifically, if the memory control group corresponding to the application identifier of the process does not exist, the creation module 201 creates the application-level memory control group corresponding to the application.
[0253] If the creation module 201 has already created the application-level memory control group corresponding to the application identifier, the control module 202 adds the process to the application-level memory control group, adds the anonymous page of the process to the least recently used list of the application-level memory control group, and adds the file page of the process to the global least recently used list.
[0254] The management module 203 is used to remove the process from the application-level memory control group when the process is destroyed. The management module 203 is also used to delete the application-level memory control group when all processes in the application's application-level memory control group are destroyed.
[0255] In one possible implementation, the management module 203 can also be used for:
[0256] Anonymous pages for applications are managed according to the application-level memory control group;
[0257] And / or control the recycling order of the anonymous pages based on the state of the application;
[0258] And / or control the reclamation ratio of the anonymous pages according to the memory control group;
[0259] And / or control the memory usage of the memory control group.
[0260] In some possible implementations, the control module 202 is further configured to:
[0261] When the application requests the anonymous page, the control module 202 is used to add the anonymous page to the active least recently used linked list of the first memory control group;
[0262] When the application requests the file page, the management module 203 adds the file page to the globally active least recently used list.
[0263] When memory reclamation is required, the management module 203 controls the reclamation order of the memory control group in the kernel space according to the first parameter of the memory control group.
[0264] When memory reclamation is required, the management module 203 controls the reclamation ratio of the memory control group in the kernel space according to the second parameter of the memory control group.
[0265] The management module 203 is also used to control the memory usage of the memory control group in the kernel space according to the third parameter of the memory control group. It is understood that the division of the modules in the above memory management device is only for illustrative purposes. In other embodiments, the memory management device can be divided into different modules as needed to complete the functions of the above memory management device.
[0266] The implementation of each module in the memory management device provided in this application embodiment can be in the form of a computer program. This computer program can run on an electronic device or a server. The specific implementation of each module in this application embodiment can also be referred to... Figures 3 to 8 The corresponding description of the method embodiments shown. Figure 9 The described memory management device enables fine-grained management of anonymous pages and improves the targeting and efficiency of page reclamation, thereby preventing application lag and enhancing user experience. For details, please refer to the specific embodiments of the memory management method described above, which will not be elaborated upon here.
[0267] This application also provides a computer-readable storage medium. The storage medium stores computer instructions that, when executed on a computing device, cause the computing device to perform the memory management method provided in the foregoing embodiments.
[0268] It will be apparent to those skilled in the art that this application is not limited to the details of the exemplary embodiments described above, and that this application can be implemented in other specific forms without departing from the spirit or essential characteristics of this application. Therefore, any appropriate changes and variations made to the above embodiments within the essential spirit and scope of this application should fall within the scope of protection claimed by this application.
Claims
1. A memory management method applied to electronic devices, characterized in that, The memory management method includes: When the first process of the first application starts, if the memory control group corresponding to the application identifier of the first process does not exist, then the application-level memory control group of the first application is created according to the application identifier of the first process. Add the anonymous pages of the first process of the first application to the least recently used list of the application-level memory control group, and reclaim the anonymous pages according to the least recently used list; Add the file pages of the first process of the first application to the global least recently used list of the memory node, and reclaim the file pages according to the global least recently used list; When the second process of the first application starts, the anonymous page of the second process is added to the least recently used list of the application-level memory control group, and the file page of the second process is added to the global least recently used list; When the first process is destroyed, the anonymous page of the first process is removed from the application-level memory control group; When the second process is destroyed, the anonymous page of the second process is removed from the application-level memory control group; When the first application is destroyed, the application-level memory control group is deleted.
2. The memory management method as described in claim 1, characterized in that, The memory management method further includes: The anonymous pages of the first application are managed according to the application-level memory control group; And / or control the recycling order of the anonymous pages based on the state of the first application; And / or control the reclamation ratio of the anonymous pages according to the application-level memory control group, wherein the reclamation ratio of the anonymous pages is the number of anonymous pages to be reclaimed in the first application and the total number of anonymous pages in the first application; And / or control the memory usage of the first application managed by the application-level memory control group.
3. The memory management method as described in claim 2, characterized in that, The step of controlling the recycling order of the anonymous page according to the state of the first application also includes: The order in which anonymous pages of the first application are recycled is determined based on the frozen state and / or active state and / or foreground state of the first application.
4. The memory management method as described in claim 2 or 3, characterized in that, When the first process of the first application starts, creating the application-level memory control group of the first application according to the application identifier corresponding to the first process further includes: If the application identifier exists in a memory control group, the first process is added to the application-level memory control group, and the first process is managed according to the application-level memory control group.
5. The memory management method according to any one of claims 1 to 3, characterized in that, The memory management method further includes: When an electronic device starts up, it creates a corresponding memory control group according to the whitelist. When a system process starts, it is determined whether the process name is a whitelisted process; if it is a whitelisted process, it is added to the memory control group.
6. The memory management method as described in claim 5, characterized in that, The memory management method further includes: Add the anonymous pages of the whitelisted processes to the least recently used list of the memory control group; The anonymous pages of the whitelisted processes are reclaimed based on the least recently used linked list.
7. The memory management method as described in claim 5, characterized in that, The memory management method further includes: Add the file pages of the whitelisted processes to the global least recently used linked list of the memory node; File pages of the whitelisted processes are reclaimed based on the globally least recently used linked list.
8. The memory management method according to any one of claims 1 to 3 and 6 to 7, characterized in that, The memory management method further includes: When the first application obtains the anonymous page, the anonymous page is added to the active least recently used list of the application-level memory control group; When the first application requests the file page, it adds the file page to the globally active least recently used list.
9. A memory management device, characterized in that, include: A creation module is used to create an application-level memory control group for the first application according to the application identifier of the first process when the first process of the first application starts, if the memory control group corresponding to the application identifier of the first process does not exist. The control module is used to add the anonymous pages of the first process of the first application to the least recently used list of the application-level memory control group, and reclaim the anonymous pages according to the least recently used list; The control module is also used to add the file pages of the first process of the first application to the global least recently used list of the memory node, and reclaim the file pages according to the global least recently used list; The control module is also configured to add the anonymous pages of the second process to the least recently used list of the application-level memory control group and add the file pages of the second process to the global least recently used list when the second process of the first application starts. When the first process is destroyed, the anonymous page of the first process is removed from the application-level memory control group; When the second process is destroyed, the anonymous page of the second process is removed from the application-level memory control group; when the first application is destroyed, the application-level memory control group is removed.
10. The memory management device as claimed in claim 9, characterized in that, Also includes The management module is used for: The anonymous pages of the first application are managed according to the application-level memory control group; And / or control the recycling order of the anonymous pages based on the state of the first application; And / or control the reclamation ratio of the anonymous pages according to the application-level memory control group; And / or control the memory usage of the first application managed by the application-level memory control group.
11. The memory management device as claimed in claim 9, characterized in that, The control module is used to add the first process to the application-level memory control group when the application identifier exists; The memory management device also includes a management module. The management module is used to manage the first process according to the application-level memory control group.
12. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program stored in the memory, wherein when the computer program is executed, the processor is configured to perform the memory management method as described in any one of claims 1 to 8.
13. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes computer instructions that, when executed on an electronic device, cause the electronic device to perform the memory management method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Method and device for recovering memories, terminal equipment and computer readable storage medium
CN108287761A
Memory recovery method and device, storage medium and electronic equipment
CN111831441A
Memory management method and device, electronic equipment and computer readable storage medium
CN114443268A