Memory recovery method and apparatus
By performing memory reclamation operations during appropriate frame-drawing periods, the stuttering and frame-dropping issues caused by the memory reclamation mechanism were resolved, thus improving the display performance of electronic devices.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2025-01-02
- Publication Date
- 2026-07-03
AI Technical Summary
Existing memory reclamation mechanisms cause electronic devices to stutter and drop frames when pausing during frame drawing tasks, especially when frames cannot be drawn within a limited drawing time.
By determining the first parameter based on frame statistics and user operation information, and selecting an appropriate frame period to perform memory reclamation operations, the occurrence of display problems can be reduced.
It improves the display performance of electronic devices, reduces stuttering and frame drops caused by memory reclamation operations, and enhances the user experience.
Smart Images

Figure CN122332298A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a memory reclamation method and apparatus. Background Technology
[0002] Operating systems of electronic devices can dynamically allocate and reclaim memory resources through memory reclamation and allocation mechanisms to ensure rapid allocation and efficient utilization of memory resources, thereby improving overall system performance. In related technologies, a memory reclamation mechanism might involve the operating system performing memory reclamation when the remaining system memory falls below a pre-set threshold.
[0003] Currently, operating systems pause other tasks (such as frame rendering) during memory reclamation. However, the rendering time for each frame is limited (e.g., approximately 16.7 milliseconds when the refresh rate of an electronic device is 60 Hz). Therefore, if memory reclamation is performed during the rendering of a frame, the remaining rendering time may be insufficient to complete the rendering of that frame, leading to display issues such as stuttering and dropped frames. Thus, improving the existing memory reclamation mechanism has become a pressing technical problem. Summary of the Invention
[0004] This application provides a memory reclamation method and apparatus, which can reduce the number of display problems that occur in electronic devices due to memory reclamation operations, thereby improving the display performance of electronic devices.
[0005] In a first aspect, this application provides a memory reclamation method, which may include: in response to a frame drawing request for an acquired frame to be processed, determining a first parameter based on collected frame drawing statistics; and performing a memory reclamation operation during the frame drawing period of the frame to be processed based on the first parameter.
[0006] A frame to be processed is a frame of image that the electronic device is currently waiting to draw. A frame drawing request is used to indicate the start of the frame drawing period for the frame to be processed. For example, if the electronic device starts drawing a frame of image based on a vertical synchronization (VSync) signal, then the frame drawing request can be a VSync signal-based processing request.
[0007] Frame statistics can be obtained by statistically analyzing the frame information of historical frames of the frame to be processed. The frame information of historical frames can represent the remaining frame duration of those historical frames (the remaining frame duration of a frame can be the remaining time after the frame is drawn within the frame-drawing period). Since the rendering process of a frame is dynamic and continuous, the drawing process of the frame to be processed is closely related to the drawing process of its historical frames. Therefore, based on the statistical information obtained from the historical frame information of the frame to be processed (i.e., frame statistics), the remaining frame duration of the frame to be processed can be predicted.
[0008] The first parameter indicates the degree to which the display performance of the frame-drawing period of the frame to be processed is affected by memory reclamation operations. When the remaining frame-drawing time of the frame to be processed is short, if a memory reclamation operation is performed during the frame-drawing period of the frame to be processed, the electronic device is very likely to experience display problems such as stuttering and frame drops. When the remaining frame-drawing time of the frame to be processed is sufficient, if a memory reclamation operation is performed during the frame-drawing period of the frame to be processed, the electronic device is very unlikely to experience display problems such as stuttering and frame drops. In other words, the shorter the remaining frame-drawing time of the frame to be processed, the higher the probability of display problems caused by the electronic device performing memory reclamation operations; the longer the remaining frame-drawing time of the frame to be processed, the lower the probability of display problems caused by the electronic device performing memory reclamation operations. It can be seen that the degree to which the display performance of the electronic device is affected by memory reclamation operations during the frame-drawing period of the frame to be processed is related to the predicted remaining frame-drawing time of the frame to be processed. Since the remaining frame duration of the frame to be processed can be predicted based on frame statistics, a first parameter can be determined based on the frame statistics to indicate the degree to which the display performance of the frame period of the frame to be processed is affected by memory reclamation operations.
[0009] In the technical solution provided in this application, after the frame drawing period of the frame to be processed begins, a first parameter can be determined based on the collected frame drawing statistics to indicate the degree of impact of memory reclamation operation on the display performance of the frame drawing period of the frame to be processed. Then, based on the determined first parameter, the memory reclamation operation is performed during the frame drawing period of the frame to be processed. Therefore, when the display performance of the frame drawing period of the frame to be processed is significantly affected by the memory reclamation operation, meaning the electronic device is highly likely to experience display problems due to the memory reclamation operation, the memory reclamation operation can be omitted during the frame drawing period of the frame to be processed. Conversely, when the display performance of the frame drawing period of the frame to be processed is minimally affected by the memory reclamation operation, meaning the electronic device is unlikely to experience display problems due to the memory reclamation operation, the memory reclamation operation can be performed during the frame drawing period of the frame to be processed. It can be seen that by performing the memory reclamation operation based on the first parameter, this application can achieve memory reclamation during a suitable frame drawing period (i.e., a frame drawing period where the display performance of the electronic device is less affected by the memory reclamation operation). This reduces the number of times the electronic device experiences display problems due to the memory reclamation operation, thereby improving the display performance of the electronic device.
[0010] In one possible implementation, the frame drawing statistics may include: the amount of memory reclaimed from historical frames of the frame to be processed, the memory reclamation duration of historical frames, and the historical frame drawing duration of historical frames; based on the collected frame drawing statistics, a first parameter is determined, including: determining the predicted reclamation duration of the frame to be processed based on the amount of memory reclaimed from historical frames, the memory reclamation duration of historical frames, and the amount of memory to be reclaimed; determining the predicted frame drawing duration of the frame to be processed based on the historical frame drawing duration of historical frames; and determining the first parameter based on the predicted reclamation duration and the predicted frame drawing duration.
[0011] Specifically, the longer the predicted drawing frame duration of the frame to be processed, the higher the likelihood of display problems caused by the electronic device performing memory reclamation operations; conversely, the shorter the predicted drawing frame duration of the frame to be processed, the lower the likelihood of display problems caused by the electronic device performing memory reclamation operations.
[0012] During the frame-drawing period of the frame to be processed, the degree to which the display performance of the electronic device is affected by memory reclamation operations is related not only to the predicted frame-drawing duration of the frame to be processed, but also to the predicted reclamation duration. Therefore, compared to the remaining frame-drawing duration of the frame to be processed (which is determined based on the predicted frame-drawing duration, for example, the remaining frame-drawing duration can be the difference between the maximum drawing duration and the predicted frame-drawing duration), the task requirement duration of the frame to be processed (which is determined based on the predicted reclamation duration and the predicted frame-drawing duration, for example, the task requirement duration can be the sum of the predicted reclamation duration and the predicted frame-drawing duration) can more accurately characterize the first parameter. Therefore, by combining the predicted reclamation duration and the predicted frame-drawing duration to determine the first parameter, this application can improve the accuracy of the determined first parameter, thereby further reducing the number of display problems caused by the electronic device performing memory reclamation operations, and thus improving the display performance of the electronic device.
[0013] In another possible implementation, the first parameter is determined based on the collected frame statistics, including: determining the first parameter based on the frame statistics and the collected user operation information.
[0014] During frame rendering tasks, electronic devices may experience frame drops due to memory reclamation operations. The resulting stuttering can be perceptible to the user at times, but not at others. Whether a user perceives the stuttering depends on their user actions. Therefore, based on user action information, we can determine the user's perceived stuttering level for the frames being processed. This perceived stuttering level characterizes the probability that the user will perceive stuttering when frame drops occur during the frame rendering period. Specifically, a higher perceived stuttering level means a greater probability of perceptible stuttering, and a greater impact of memory reclamation on the display performance during the frame rendering period. Conversely, a lower perceived stuttering level means a lower probability of perceptible stuttering, and a lesser impact of memory reclamation on the display performance during the frame rendering period.
[0015] It can be seen that the display performance of the frame drawing period of the frame to be processed is affected by memory reclamation operations to a degree that is also related to user operation information. Therefore, this application can also refer to user operation information to determine the first parameter (the first parameter can be used to indicate the degree of impact of memory reclamation operations on the display performance of the frame drawing period). Since user operation information specifically affects the user's perception of stuttering in the frame to be processed, this application can determine the first parameter by referring to user operation information. This allows memory reclamation to be performed during some drawing periods where the user does not perceive stuttering, and during frame drawing periods where the user does not perceive stuttering. Even if the electronic device does experience frame dropping problems, since the user does not perceive it, it will not affect the display performance of the electronic device. Therefore, this application combines frame drawing statistics and user operation information to determine the first parameter, and performs memory reclamation operations based on the first parameter. This can not only reduce the number of display problems caused by the electronic device performing memory reclamation operations, but also reduce the number of stuttering issues that the user can perceive when the electronic device experiences frame dropping problems due to memory reclamation operations. In this way, the impact of memory reclamation operations on the display performance of the electronic device can be further reduced, thereby improving the display performance of the electronic device.
[0016] In another possible implementation, the first parameter is determined based on the collected frame statistics, including: determining the first parameter based on the frame statistics and the collected application display information.
[0017] In practical applications, the user's perception of stuttering in the frame being processed is also related to the application's display information. Specifically, the more display signals the electronic device collects from the application's display information, the greater the probability that the user will perceive stuttering when frame drops occur during the frame drawing period of the frame being processed. The display performance during the frame drawing period is also more significantly affected by memory reclamation operations, resulting in a higher perceived stuttering level. Conversely, the fewer display signals the electronic device collects from the application's display information, the lower the probability that the user will perceive stuttering when frame drops occur during the frame drawing period of the frame being processed. The display performance during the frame drawing period is also less significantly affected by memory reclamation operations, resulting in a lower perceived stuttering level.
[0018] It can be seen that the degree to which the display performance of the frame drawing period of the frame to be processed is affected by memory reclamation operations is also related to application display information. Therefore, this application can also refer to application display information to determine the first parameter (the first parameter can be used to indicate the degree to which the display performance of the frame drawing period is affected by memory reclamation operations). Since application display information specifically affects the user's perception of stuttering in the frame to be processed, this application can refer to application display information to determine the first parameter, which can realize memory reclamation during some drawing periods where the user does not perceive stuttering, and memory reclamation during frame drawing periods where the user does not perceive stuttering. Even if the electronic device does experience frame dropping problems, since the user does not perceive it, it will not affect the display performance of the electronic device. Therefore, this application combines frame drawing statistics and application display information to determine the first parameter, and performs memory reclamation operations based on the first parameter. This can not only reduce the number of display problems caused by the electronic device performing memory reclamation operations, but also reduce the number of stuttering issues that the user can perceive when the electronic device experiences frame dropping problems due to memory reclamation operations. In this way, the impact of memory reclamation operations on the display performance of the electronic device can be further reduced, thereby improving the display performance of the electronic device.
[0019] In another possible implementation, a memory reclamation operation is performed during the drawing frame period of the frame to be processed based on a first parameter, including: determining memory reclamation conditions based on at least one of the remaining memory amount, the amount of memory to be scanned, and the clock frequency of the central processing unit (CPU); and performing a memory reclamation operation during the drawing frame period of the frame to be processed if the first parameter satisfies the memory reclamation conditions.
[0020] In practical applications, during the frame drawing period of the frame to be processed, the degree to which the display performance of an electronic device is affected by memory reclamation operations is also related to the amount of remaining memory, the amount of memory to be scanned, and the CPU clock frequency. Based on this, this application can dynamically adjust the memory reclamation conditions (i.e., dynamically adjust the threshold of the first parameter) based on the amount of remaining memory, the amount of memory to be scanned, and the CPU clock frequency. This allows for the determination of a more accurate and suitable frame drawing period (i.e., a frame drawing period where the display performance of the electronic device is less affected by memory reclamation operations), thereby further reducing the number of display problems caused by memory reclamation operations and ultimately improving the display performance of the electronic device.
[0021] In another possible implementation, based on the first parameter, a memory reclamation operation is performed during the drawing frame period of the frame to be processed, including: determining the target parameter interval to which the first parameter belongs from the candidate parameter intervals; different reclamation mechanisms correspond to different candidate parameter intervals, and different reclamation rates of different reclamation mechanisms; and performing a memory reclamation operation during the drawing frame period of the frame to be processed based on the reclamation mechanism corresponding to the target parameter interval.
[0022] In this application, multiple parameter ranges (i.e., candidate parameter ranges) are pre-determined for the first parameter, and different reclamation mechanisms are set for different parameter ranges. Specifically, the larger the parameter value in the candidate parameter range, the higher the reclamation rate of the corresponding reclamation mechanism; the smaller the parameter value in the candidate parameter range, the lower the reclamation rate of the corresponding reclamation mechanism. When memory reclamation is required during the rendering time of the frame to be processed, a reclamation mechanism more suitable for the frame to be processed (i.e., a reclamation mechanism that better meets the current requirements) can be determined based on the first parameter. Taking the remaining rendering time of the frame to be processed as an example, when the remaining rendering time of the frame to be processed is short, a reclamation mechanism based on an incremental reclamation algorithm can be used for memory reclamation. Since the reclamation rate of the incremental reclamation algorithm is faster, the number of display problems will be very small when memory reclamation is performed within a short remaining rendering time. When the remaining frame duration of the frame to be processed is long, a memory reclamation mechanism based on a full-capacity reclamation algorithm can be used. Although the reclamation rate of the full-capacity reclamation algorithm is relatively slow, the number of display problems occurring during memory reclamation is also very small due to the long remaining frame duration. It can be seen that this application can implement a reclamation mechanism with different reclamation rates for frames to be processed in different frame states. This can improve the memory reclamation efficiency of electronic devices.
[0023] In another possible implementation, the memory reclamation method provided in this application can be applied to application threads in the operating system of an electronic device.
[0024] In another possible implementation, the memory reclamation method provided in this application can be applied to system threads in the operating system of an electronic device.
[0025] In another possible implementation, the memory reclamation method provided in this application can be applied to a memory reclamation management thread added to the operating system of an electronic device.
[0026] Secondly, this application provides a memory reclamation device, which includes a determining module and a processing module. The determining module is configured to determine a first parameter based on collected frame-drawing statistics in response to a frame-drawing request for a frame to be processed; wherein the frame-drawing request is used to indicate the start of a frame-drawing period for the frame to be processed, and the first parameter is used to indicate the degree to which the display performance of the frame-drawing period is affected by the memory reclamation operation; the processing module is configured to perform a memory reclamation operation during the frame-drawing period of the frame to be processed based on the first parameter.
[0027] In one possible implementation, the frame drawing statistics may include: the amount of memory reclaimed from historical frames of the frame to be processed, the memory reclamation duration of historical frames, and the historical frame drawing duration of historical frames; the determining module is specifically used to: determine the predicted reclamation duration of the frame to be processed based on the amount of memory reclaimed from historical frames, the memory reclamation duration of historical frames, and the amount of memory to be reclaimed; determine the predicted frame drawing duration of the frame to be processed based on the historical frame drawing duration of historical frames; and determine the first parameter based on the predicted reclamation duration and the predicted frame drawing duration.
[0028] In another possible implementation, the determining module is further used to: determine the first parameter based on the frame statistics and the collected user operation information.
[0029] In another possible implementation, the determining module is specifically used to: determine the first parameter based on the frame statistics and the collected application display information.
[0030] In another possible implementation, the processing module is specifically used to: determine memory reclamation conditions based on at least one of the remaining memory amount, the amount of memory to be scanned, and the CPU clock frequency; and perform memory reclamation operations during the drawing frame period of the frame to be processed if the first parameter satisfies the memory reclamation conditions.
[0031] In another possible implementation, the processing module is further specifically used to: determine the target parameter range to which the first parameter belongs from the candidate parameter range; the candidate parameter ranges correspond to different recycling mechanisms, and the recycling rates of different recycling mechanisms are different; and perform memory reclamation operations during the drawing frame period of the frame to be processed based on the recycling mechanism corresponding to the target parameter range.
[0032] In another possible implementation, the memory reclamation device provided in this application implements the corresponding functions through application threads in the operating system of the electronic device.
[0033] In another possible implementation, the memory reclamation device provided in this application implements the corresponding functions through a system thread in the operating system of the electronic device.
[0034] In another possible implementation, the memory reclamation device provided in this application implements the corresponding functions through a memory reclamation management thread added to the operating system of the electronic device.
[0035] Thirdly, this application provides an electronic device including a memory and at least one processor; the memory is coupled to the processor; wherein the memory stores computer program code, the computer program code including computer instructions, and when the computer instructions are executed by the processor, the electronic device performs the method provided in the first aspect or any implementation thereof.
[0036] Fourthly, this application provides a computer-readable storage medium including computer instructions that, when executed on an electronic device, cause the electronic device to perform the method provided in the first aspect or any implementation thereof.
[0037] Fifthly, this application provides a computer program product that, when run on a computer, causes the computer to execute the method provided in the first aspect or any implementation thereof.
[0038] It is understood that the technical effects of the technical solutions provided in the second to fifth aspects of this application can be referred to the technical effects corresponding to the first aspect or any implementation of the first aspect, and will not be repeated here.
[0039] Based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods. Attached Figure Description
[0040] Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;
[0041] Figure 2 This application provides a schematic diagram of the structure of a thread pool in an operating system.
[0042] Figure 3 This is a schematic diagram of the structure of a thread pool in another operating system provided in an embodiment of this application;
[0043] Figure 4 A schematic diagram of the structure of a thread pool in another operating system provided in an embodiment of this application;
[0044] Figure 5 A flowchart illustrating a memory reclamation method provided in an embodiment of this application;
[0045] Figure 6 A schematic diagram of the structure of a thread pool in another operating system provided in this application embodiment;
[0046] Figure 7 A simplified flowchart illustrating a memory reclamation method provided in an embodiment of this application;
[0047] Figure 8 A simplified flowchart illustrating another memory reclamation method provided in this application embodiment;
[0048] Figure 9 This is a schematic diagram of a memory recycling device provided in an embodiment of this application. Detailed Implementation
[0049] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the embodiments described herein are some, but not all, of the embodiments of this application. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the protection scope of this application.
[0050] The terms "first," "second," etc., used in the specification, embodiments, and drawings of this application are for descriptive purposes only and should not be construed as indicating or implying relative importance or order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, such as including a series of steps or units. A method, apparatus, or product is not limited to the listed steps or units but may optionally include other unlisted steps or units, or optionally include other steps or units inherent to these methods, apparatus, or products.
[0051] It is understood that in this application, "at least one" means one or more, and "more than one" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can mean: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. Furthermore, terms such as "exemplary" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or implementation described as "exemplary" or "for example" in this application should not be construed as being more preferred or advantageous than other embodiments or implementations. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0052] Before describing the technical solution provided in this application in detail, the technical background of this application will be briefly introduced below.
[0053] Currently, operating systems in electronic devices can dynamically allocate new memory space using functions such as `malloc` and dynamically reclaim allocated memory space using functions such as `free`. To ensure rapid allocation and efficient utilization of memory resources and improve the overall performance of the operating system, related technologies utilize memory reclamation and allocation mechanisms to achieve dynamic allocation and reclamation of memory resources. For example, a memory reclamation mechanism in related technologies could involve the operating system performing memory reclamation when the remaining system memory falls below a pre-set threshold.
[0054] During memory reclamation, the operating system pauses other tasks (including frame rendering tasks) until the reclamation is complete. Frame rendering tasks are image processing tasks that continuously draw frame after frame at a fixed refresh rate. However, the operating system has a limited time to render each frame during frame rendering. If memory reclamation is performed while a frame rendering task is being executed, the remaining rendering time may be insufficient to complete the rendering of that frame. This can lead to display problems such as stuttering and dropped frames on electronic devices. For example, when an electronic device has a refresh rate of 60 Hz, to ensure that the device can accurately display 60 frames per second, the rendering time for each frame must be limited to 16.7 milliseconds (ms). If memory reclamation is performed while a frame rendering task is being executed, the frame may not be rendered within 16.7 ms, potentially resulting in dropped frames. When there are many dropped frames, users will experience stuttering, and the more frames dropped, the more severe the stuttering will be.
[0055] To address the problems existing in current memory reclamation mechanisms (i.e., display issues arising from memory reclamation operations on electronic devices), this application provides a memory reclamation method. This method, by performing memory reclamation operations based on a first parameter, enables memory reclamation to be carried out during appropriate frame-drawing periods (i.e., frame-drawing periods where the display performance of the electronic device is less affected by memory reclamation operations), thereby reducing the frequency of display problems caused by memory reclamation operations and improving the display performance of the electronic device.
[0056] The memory reclamation method provided in this application can be executed by an electronic device, such as a mobile phone, wearable device (e.g., smart bracelet), tablet computer, in-vehicle device, laptop computer, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc., which can dynamically reclaim memory resources based on the memory reclamation mechanism.
[0057] For example, refer to Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 1As shown, the electronic device 101 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, 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, and a bone conduction sensor 180M, etc.
[0058] Processor 110 may include one or more processing units. In one possible implementation, processor 110 may include a CPU, graphics processing unit (GPU), modem processor, image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and neural network processing unit (NPU), etc. The different processing units may be independent devices or integrated into one or more processors. For example, multiple processing units such as CPU, GPU, ISP, and DSP may be integrated into an application processor (AP) of electronic device 101 to run the operating system and various applications of the electronic device.
[0059] The processor 110 can be used to execute the memory reclamation method provided in this application. For example, in response to the frame drawing request of the acquired frame to be processed, the processor 110 can determine a first parameter based on the collected frame drawing statistics; and after determining the first parameter, the processor 110 can perform a memory reclamation operation based on the first parameter during the frame drawing period of the frame to be processed.
[0060] Antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor, and baseband processor, etc., can work together to realize the wireless communication function of electronic device 101.
[0061] Antennas 1 and 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 101 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 one possible implementation, the antennas can also be used in conjunction with a tuning switch.
[0062] The mobile communication module 150 can provide solutions for wireless communication, including 2G, 3G, 4G, and 5G technologies, applied to the electronic device 101. 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 one possible implementation, at least some functional modules of the mobile communication module 150 may be housed in the processor 110. In another possible implementation, 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.
[0063] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 101, including wireless local area networks (WLAN), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR). The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via 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.
[0064] In one possible implementation, antenna 1 of electronic device 101 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, enabling electronic device 101 to communicate with other devices via wireless communication technology. The wireless communication technology may include at least one of the following: 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 IR technology.
[0065] The CPU, GPU, and display screen 194 work together to realize the display function of the electronic device 101. The GPU is a microprocessor for image processing and can be connected to the display screen 194 and the CPU. The GPU can handle a large number of mathematical and geometric operations and can be used for rendering and drawing images. The processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0066] The display screen 194 may include a display panel for displaying images, videos, etc. 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 quantum dot light-emitting diode (QLED), etc. For example, the electronic device 101 may include one or N display screens 194, where N is a positive integer greater than 1.
[0067] ISP, camera 193, video codec, CPU, GPU, display 194, and CPU, etc., can work together to realize the shooting function of electronic devices.
[0068] The Information Service Provider (ISP) processes data fed back from the camera 193. For example, when a user takes a photo, the shutter is opened, and light is transmitted through the lens to the camera's image sensor. The light signal is converted into an electrical signal, which is then transmitted to the ISP for processing, transforming it into a visible image. The ISP can also perform algorithmic optimizations on image noise, brightness, and skin tone. Additionally, the ISP can optimize parameters such as exposure and color temperature for the shooting scene. In one possible implementation, the ISP could be integrated into the camera 193 itself.
[0069] 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. For example, the photosensitive element can convert light signals into electrical signals and transmit them to an ISP; the ISP can convert the electrical signals into digital image signals and output them to a DSP for processing; the DSP converts the digital image signals into image signals in a standard format. In one possible implementation, electronic device 101 may include one or N cameras 193, where N is a positive integer greater than 1.
[0070] The external memory interface 120 can connect to an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 101. The external memory card communicates with the processor 110 through the external memory interface 120 to perform data storage.
[0071] Internal memory 121 can be used to store computer program code, which includes computer instructions. Processor 110 can execute these computer instructions to implement the memory reclamation method provided in this application. Internal memory 121 may include a stored program area and a stored data area. For example, the stored program area may store the operating system of the electronic device, applications required for at least one function, etc. The stored data area may store data generated during the use of electronic device 101 (e.g., audio data), etc. In addition, internal memory 121 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.
[0072] The audio functions of sub-device 101, such as music playback and recording.
[0073] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 101 can use the fingerprint sensor to collect fingerprint data. If the collected fingerprint data matches the stored template image, fingerprint unlocking can be achieved, thereby enabling access to the application lock, fingerprint photography, fingerprint answering of calls, etc.
[0074] Touch sensor 180K, also known as a "touch panel," can be located on display screen 194. The touch sensor 180K and display screen 194 together form a touchscreen, also known as a "touch screen." Touch sensor 180K detects touch operations applied to or near it. It transmits the detected touch operation to the CPU to determine the type of touch event. Additionally, display screen 194 can provide visual output related to the touch operation. Alternatively, touch sensor 180K can also be located on the surface of electronic device 101, in a different position than display screen 194.
[0075] Buttons 190 include a power button, volume buttons, etc. Buttons 190 can be mechanical buttons or touch buttons. Electronic device 101 can receive button input and generate key signal inputs related to user settings and function control of electronic device 101.
[0076] Motor 191 can generate vibration alerts. Motor 191 can be used for incoming call vibration alerts or for touch vibration feedback. For example, different touch operations applied to different applications can correspond to different vibration feedback effects. Touch operations applied to different areas of the display screen 194 can also correspond to different vibration feedback effects from motor 191. In different application scenarios (e.g., time reminders, receiving messages, alarm clocks, games, etc.), motor 191 can also achieve different vibration feedback effects.
[0077] The indicator 192 can be an indicator light used to indicate the charging status and power changes of the electronic device 101, or it can be used to indicate messages, missed calls, notifications, etc.
[0078] 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 101. The electronic device 101 can support one or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Micro SIM cards, SIM cards, etc. Multiple cards can be inserted into the same SIM card interface 195 simultaneously; the types of cards can be the same or different. The SIM card interface 195 is also compatible with different types of SIM cards and external memory cards. The electronic device 101 interacts with the network through the SIM card to achieve functions such as making calls and data communication. In one possible implementation, the electronic device 101 can use an embedded SIM card (eSIM), which can be embedded in the electronic device 101 and cannot be separated from it.
[0079] It should be noted that, Figure 1 The structures shown do not constitute a limitation on electronic devices, except... Figure 1 In addition to the components shown, the electronic device may include a ratio Figure 1 The diagram shows more or fewer components, combinations of certain components, or different component arrangements. The illustrated components can be implemented in hardware, software, or a combination of both. Additionally, Figure 1 The interface connections between the modules shown are for illustrative purposes only and do not constitute a structural limitation on electronic device 101. In practical applications, electronic device 101 may also adopt... Figure 1 Different interface connection methods, or combinations of multiple interface connection methods.
[0080] The memory reclamation method provided in this application can be applied to the operating system of electronic devices, such as Android and HarmonyOS. The operating system can be stored in the internal memory of the electronic device. The processor in the electronic device can communicate with the internal memory to retrieve instructions or data from the operating system to implement the memory reclamation method of this application. When the processor is running the operating system, the operating system can implement the memory reclamation method of this application by scheduling threads in a thread pool.
[0081] For example, refer to Figure 2 This is a schematic diagram of the structure of a thread pool in an operating system provided in an embodiment of this application. Figure 2 As shown, the operating system's thread pool includes user interface (UI) threads, rendering threads, application threads, memory reclamation threads, and memory reclamation management threads.
[0082] The UI thread is used to handle operations related to the user interface, such as processing user input and drawing the screen.
[0083] The rendering thread is used to render and draw the screen. By separating some rendering tasks (such as those corresponding to complex rendering operations) into independent threads, the load on the UI thread can be reduced and rendering efficiency can be improved.
[0084] Application threads are threads created for an application when it starts up. They are used to handle tasks such as updating the user interface and making network requests. Application threads are created when the application starts and destroyed when the application terminates.
[0085] The memory reclamation thread manages memory allocation and reclamation to ensure efficient use of system resources and prevent applications from crashing due to insufficient memory during runtime.
[0086] The memory reclamation management thread can be a thread added to the operating system's thread pool in this embodiment of the application to achieve memory reclamation during appropriate frame drawing periods.
[0087] In one possible implementation, the memory reclamation management thread can be used to execute the memory reclamation method in this application. Specifically, when the memory reclamation management thread receives a frame drawing request for a frame to be processed, it can obtain frame drawing statistics collected by the rendering thread and the memory reclamation thread, and determine a first parameter based on the frame drawing statistics. Then, the memory reclamation management thread can perform memory reclamation operations during the frame drawing period of the frame to be processed based on the first parameter. Alternatively, the memory reclamation management thread can also collect user operation information from the application thread and the UI thread, and determine the first parameter by combining the user operation information and the frame drawing statistics. Alternatively, the memory reclamation management thread can also collect application display information generated by the application thread, and determine the first parameter by combining the application display information and the frame drawing statistics. Alternatively, the memory reclamation management thread can also determine the first parameter by combining the obtained application display information, user operation information, and frame drawing statistics.
[0088] For example, refer to Figure 3 This is a schematic diagram of the structure of a thread pool in another operating system provided in an embodiment of this application. Figure 3 As shown, the operating system's thread pool includes application threads, memory reclamation threads, and system threads. System threads can be system-level threads shared by various applications. For example, system threads can be UI threads, rendering threads, etc.
[0089] In one possible implementation, a system thread can be used to execute the memory reclamation method in this application. Taking an example where the system thread includes a UI thread and a rendering thread, and the UI thread executes the memory reclamation method, when the UI thread receives a frame-drawing request for a frame to be processed, it can obtain frame-drawing statistics collected by the rendering thread and the memory reclamation thread, and determine a first parameter based on these statistics. Then, the UI thread can perform memory reclamation operations during the frame-drawing period of the frame to be processed based on the first parameter. Alternatively, the UI thread can also collect user operation information generated by the application thread, and determine the first parameter by combining the user operation information and the frame-drawing statistics. Or, the UI thread can also collect application display information generated by the application thread, and determine the first parameter by combining the application display information and the frame-drawing statistics. Alternatively, the UI thread can also determine the first parameter by combining application display information, user operation information, and frame-drawing statistics.
[0090] For example, refer to Figure 4 This is a schematic diagram of the structure of a thread pool in another operating system provided in an embodiment of this application. Figure 4 As shown, the operating system's thread pool includes UI threads, rendering threads, application threads, and memory reclamation threads.
[0091] In one possible implementation, the application thread can be used to execute the memory reclamation method in this application. Specifically, when the application thread receives a frame drawing request for a frame to be processed, it can obtain frame drawing statistics collected by the rendering thread and the memory reclamation thread, and determine a first parameter based on the frame drawing statistics. Then, the application thread can perform memory reclamation operations during the frame drawing period of the frame to be processed based on the first parameter. Alternatively, the application thread can also determine the first parameter by combining the frame drawing statistics, its own generated user operation information, and user operation information obtained from the UI thread. Or, the application thread can also determine the first parameter by combining the frame drawing statistics and its own generated application display information. Or, the application thread can also determine the first parameter by combining application display information, user operation information, and frame drawing statistics.
[0092] It should be noted that in practical applications, some operating systems do not include a memory reclamation thread in their thread pools; the functionality of the memory reclamation thread is implemented by the application thread. In this case, the thread executing the memory reclamation method in this application (memory reclamation management thread, system thread, or application thread) can obtain the corresponding frame statistics information from the application thread.
[0093] It should be understood that Figure 2 , Figure 3 ,as well as Figure 4As an example, only the threads involved in the memory reclamation method provided in this application are shown in the thread pool, and this does not constitute a limitation on the structure of the thread pool. In practical applications, the thread pool of the operating system may also include other threads.
[0094] Among the various implementation methods described above, the memory reclamation method provided in this application can be applied to application threads, system threads, or additional memory reclamation management threads of the operating system. It is understood that in practical applications, the memory reclamation method provided in this application can also be applied to other threads (e.g., memory reclamation threads), and this application does not limit this application.
[0095] Reference Figure 5 This is a flowchart illustrating a memory reclamation method provided in an embodiment of this application. This method can be applied to... Figure 2 The memory reclamation management thread in Figure 3 System threads in, or Figure 4 The application thread in the application. In the following description of this application, memory reclamation methods will be applied to Figure 2 Let's take the memory reclamation management thread in the example to illustrate this. Figure 5 As shown, the method includes the following steps:
[0096] S501. In response to the frame drawing request of the acquired frame to be processed, determine the first parameter based on the collected frame drawing statistics.
[0097] A frame to be processed is a frame of image that the electronic device is currently waiting to render.
[0098] A frame drawing request is used to indicate the start of the frame drawing period for a frame to be processed. For example, if an electronic device starts drawing a frame based on the VSync signal, then this frame drawing request can be a processing request based on the VSync signal. The VSync signal can be used not only for traditional vertical synchronization (i.e., the operating system and GPU can synchronize image rendering and actual physical refresh based on the VSync signal), but also as a key reference point in the image pipeline processing to trigger the drawing process.
[0099] Frame statistics can be obtained by statistically analyzing the frame information of historical frames of the frame to be processed. Historical frames can be the previous frame or the previous M frames of the frame to be processed, where M can be a positive integer greater than 1. The frame information of historical frames can represent the remaining frame duration of those historical frames. The remaining frame duration of a single frame can be the time remaining after the frame is drawn within the specified frame-drawing time period.
[0100] In one possible implementation, the frame-drawing information of historical frames may include the historical frame-drawing duration of the historical frames, and the frame-drawing statistics may include information obtained by statistically analyzing the historical frame-drawing durations of historical frames. For example, the frame-drawing statistics may include the average frame-drawing duration of historical frames (i.e., the average duration of multiple historical frame-drawing durations). The historical frame-drawing duration of a certain historical frame may be the actual time taken to complete the drawing of that frame during the frame-drawing period of that frame. If the maximum drawing duration allowed by the operating system for each frame (for example, when the refresh rate is 60Hz, the maximum drawing duration is approximately 16.7ms) is known, then based on the maximum drawing duration and the average frame-drawing duration, the remaining frame-drawing duration of the historical frame (i.e., the difference between the maximum drawing duration and the average frame-drawing duration) can be determined.
[0101] In practical applications, the application thread can also collect the frame intervals of historical frames (for example, the frame interval between two frames can be the acquisition interval of the frame request for those two frames), and then dynamically adjust the maximum drawing time based on the frame intervals of historical frames. For example, the frame interval of historical frames can be the average of M-1 frame intervals (i.e., the frame intervals of the M frames preceding the frame to be processed), and this average value can be determined as the maximum drawing time.
[0102] Since the rendering process of the image is dynamic and continuous, the rendering process of the frame to be processed is closely related to the rendering process of its historical frames. Therefore, based on the statistical information obtained from the rendering information of the historical frames of the frame to be processed (i.e., rendering statistics), the remaining rendering duration of the frame to be processed can be predicted. For example, the remaining rendering duration of the historical frames obtained based on the rendering statistics can be determined as the remaining rendering duration of the frame to be processed.
[0103] The first parameter indicates the degree to which the display performance of the frame-drawing period of the frame to be processed is affected by the memory reclamation operation. When the remaining frame-drawing time of the frame to be processed is short, if a memory reclamation operation is performed during the frame-drawing period of the frame to be processed, the electronic device is very likely to experience display problems such as stuttering and frame drops. When the remaining frame-drawing time of the frame to be processed is ample, if a memory reclamation operation is performed during the frame-drawing period of the frame to be processed, the electronic device is very unlikely to experience display problems such as stuttering and frame drops. In other words, the shorter the remaining frame-drawing time of the frame to be processed, the higher the probability of display problems caused by the electronic device performing memory reclamation operations; the longer the remaining frame-drawing time of the frame to be processed, the lower the probability of display problems caused by the electronic device performing memory reclamation operations.
[0104] It can be seen that during the frame-drawing period of the frame to be processed, the degree to which the display performance of the electronic device is affected by memory reclamation operations is related to the predicted remaining frame-drawing duration of the frame to be processed. Since the remaining frame-drawing duration of the frame to be processed can be predicted based on frame-drawing statistics, a first parameter can be determined based on these statistics to indicate the degree to which the display performance is affected by memory reclamation operations during the frame-drawing period of the frame to be processed. For example, the electronic device can use the remaining frame-drawing duration of the frame to be processed, obtained from frame-drawing statistics, as the first parameter.
[0105] S502. Based on the first parameter, perform memory reclamation operation during the drawing frame period of the frame to be processed.
[0106] When the display performance of the frame-drawing period of the frame to be processed is significantly affected by memory reclamation operations—meaning the electronic device is highly likely to experience display problems due to memory reclamation—then memory reclamation can be avoided during the frame-drawing period of the frame to be processed. Conversely, when the display performance of the frame-drawing period of the frame to be processed is less affected by memory reclamation operations—meaning the electronic device is unlikely to experience display problems due to memory reclamation—then memory reclamation can be performed during the frame-drawing period of the frame to be processed. Since the first parameter characterizes the degree to which the display performance of the frame-drawing period of the frame to be processed is affected by memory reclamation operations, this embodiment of the application performs memory reclamation operations based on the first parameter, enabling memory reclamation to be performed during appropriate frame-drawing periods (i.e., frame-drawing periods where the display performance of the electronic device is less affected by memory reclamation operations). This reduces the number of times the electronic device experiences display problems due to memory reclamation operations, thereby improving the display performance of the electronic device.
[0107] by Figure 2 Taking the thread pool shown as an example, in one possible implementation, the memory reclamation management thread can first obtain the historical frame duration of the historical frames collected by the rendering thread, and determine the average frame duration of the historical frames based on the historical frame duration. Then, based on the average frame duration of the historical frames and the maximum drawing duration allowed by the operating system for each frame, the memory reclamation management thread can determine the remaining frame duration of the historical frames, and set this remaining frame duration as the remaining frame duration of the frame to be processed. Then, the memory reclamation management thread can set the remaining frame duration of the frame to be processed as the first parameter. When the first parameter is greater than or equal to a preset duration, the memory reclamation management thread can perform memory reclamation operations during the frame drawing period of the frame to be processed; when the first parameter is less than the preset duration, the memory reclamation management thread can temporarily refrain from performing memory reclamation operations, waiting for a suitable time to execute them (i.e., waiting until the first parameter corresponding to a subsequent frame is less than the preset duration before execution).
[0108] In another possible implementation, the frame drawing statistics include: the amount of memory reclaimed from historical frames of the frame to be processed, the memory reclamation duration of historical frames, and the historical frame drawing duration of historical frames; based on the collected frame drawing statistics, a first parameter is determined, including: based on the amount of memory reclaimed from historical frames, the memory reclamation duration of historical frames, and the amount of memory to be reclaimed, the predicted reclamation duration of the frame to be processed is determined; based on the historical frame drawing duration of historical frames, the predicted frame drawing duration of the frame to be processed is determined; based on the predicted reclamation duration and the predicted frame drawing duration, the first parameter is determined.
[0109] The amount of memory reclaimed for a given historical frame can be the actual amount of memory reclaimed during the frame-drawing period of that frame. The duration of memory reclamation for a given historical frame can be the actual time taken to perform the memory reclamation operation during the frame-drawing period of that frame. The amount of memory to be reclaimed can be the total amount of memory resources that are no longer in use.
[0110] The predicted reclamation time of the frame to be processed can be the predicted time for performing memory reclamation operations during the frame drawing period of the frame to be processed. The predicted reclamation time of the frame to be processed is related to the amount of memory to be reclaimed. Since the drawing process of the frame to be processed is closely related to the drawing process of the historical frames of the frame to be processed, in this embodiment, the relationship between the predicted reclamation time of the frame to be processed and the amount of memory to be reclaimed can be determined based on the relationship between the amount of memory reclaimed in the historical frames and the memory reclamation time of the historical frames. For example, in this embodiment, the predicted reclamation time of the frame to be processed can be determined as follows: using the amount of memory reclaimed in M historical frames (M can be a positive integer, such as 5) as independent variables and the memory reclamation time of these M historical frames as dependent variables, the expression t = bx + c is obtained by least squares fitting. Where b and c are coefficients obtained by least squares fitting, x represents the unknown amount of memory reclaimed, and t represents the unknown memory reclamation time. Then, substituting the amount of memory to be reclaimed as the value of x into the expression t = bx + c, the obtained t value is the predicted reclamation time of the frame to be processed.
[0111] To improve the accuracy of the predicted recovery time of the frames to be processed, thereby improving the accuracy of the determined first parameter, in this embodiment, the predicted recovery time obtained based on the least squares method can be used as the initial predicted recovery time. After obtaining the initial predicted recovery time, the initial predicted recovery time can be corrected a second time to obtain the final predicted recovery time. For example, in this embodiment, the memory recovery amount of Y sample frames (Y is a large positive integer, such as Y being 1000) can be used as sample input, and the memory recovery time of these Y sample frames can be used as sample output. A recovery time prediction model is obtained through offline training based on a pre-determined neural network model (e.g., convolutional network model, feedforward network model, etc.). Then, by inputting the amount of memory to be recovered into the recovery time prediction model, the predicted recovery time output by the model can be obtained. Based on the predicted recovery time output by the model, the initial predicted recovery time can be corrected a second time to obtain the final predicted recovery time. For example, a weighted average can be taken between the initial predicted recovery time and the predicted recovery time output by the recovery time prediction model to obtain the final predicted recovery time.
[0112] The sample frames can be screens already displayed on the electronic device. The relationship between memory reclamation amount and memory reclamation duration may differ for different types of applications (e.g., text reading applications, games, instant messaging applications, etc.). Therefore, in this embodiment, different reclamation duration prediction models can be pre-trained for different types of applications. Taking a game application as an example, Y frames of screens already displayed during the game application's operation can be collected in advance, and these Y frames can be used as Y sample frames to train a reclamation duration prediction model for the game application. When determining the predicted reclamation duration of a frame to be processed, the electronic device can first determine the currently running application (i.e., the current application), and then determine the target model corresponding to the current application from the multiple pre-trained reclamation duration prediction models. The predicted reclamation duration of the frame to be processed can then be determined based on this target model.
[0113] The predicted frame drawing duration of the frame to be processed can be the time taken to complete the prediction of the frame to be processed during the frame drawing period. For example, the average frame drawing duration of historical frames (i.e., the average duration of multiple historical frame drawing durations) can be determined as the predicted frame drawing duration of the frame to be processed.
[0114] Predicted garbage collection duration and predicted frame rendering duration can characterize the task requirement duration of the frame to be processed (including the required duration for completing memory garbage collection and frame rendering tasks). For example, the task requirement duration can be the sum of the predicted garbage collection duration and the predicted frame rendering duration. When the task requirement duration of the frame to be processed is greater than or equal to the maximum rendering duration allowed by the operating system for each frame, if a memory garbage collection operation is performed during the frame rendering period of the frame to be processed, the electronic device is very likely to experience display problems such as stuttering and frame dropping. When the task requirement duration of the frame to be processed is less than the maximum rendering duration allowed by the operating system for each frame, the possibility of the electronic device experiencing display problems such as stuttering and frame dropping is very small. It can be seen that during the frame rendering period of the frame to be processed, the degree to which the display performance of the electronic device is affected by the memory garbage collection operation is related to the task requirement duration of the frame to be processed. Since the task requirement duration of the frame to be processed can be obtained based on the predicted garbage collection duration and the predicted frame rendering duration, a first parameter can also be determined based on the predicted garbage collection duration and the predicted frame rendering duration to indicate the degree to which the display performance during the frame rendering period of the frame to be processed is affected by the memory garbage collection operation. For example, the electronic device may determine the task requirement duration as the first parameter, or it may determine the difference between the maximum drawing duration and the task requirement duration (i.e., the idle drawing frame duration) as the first parameter.
[0115] During the frame rendering phase of the pending frame, the impact of memory reclamation operations on the display performance of an electronic device is related not only to the predicted frame rendering duration of the pending frame but also to the predicted reclamation duration. Specifically, the longer the predicted frame rendering duration of the pending frame, the higher the likelihood of display problems caused by memory reclamation operations; conversely, the shorter the predicted frame rendering duration, the lower the likelihood of display problems caused by memory reclamation operations. Therefore, compared to the remaining drawing frame duration of the frame to be processed (which is determined based on the predicted drawing frame duration, for example, the remaining drawing frame duration can be the difference between the maximum drawing duration and the predicted drawing frame duration), the task requirement duration of the frame to be processed (which is determined based on the predicted recycling duration and the predicted drawing frame duration, for example, the task requirement duration can be the sum of the predicted recycling duration and the predicted drawing frame duration) can more accurately represent the first parameter. Therefore, by combining the predicted recycling duration and the predicted drawing frame duration to determine the first parameter in this embodiment, the accuracy of the determined first parameter can be improved, thereby further reducing the number of display problems caused by memory reclamation operations in electronic devices, and thus improving the display performance of electronic devices.
[0116] by Figure 2Taking the thread pool shown as an example, the memory reclamation management thread can first obtain the historical frame duration of the historical frames collected by the rendering thread, and determine the predicted frame duration of the frame to be processed based on the historical frame duration. Then, the memory reclamation management thread can obtain the amount of memory reclaimed, the memory reclamation duration of the historical frames, and the amount of memory to be reclaimed from the memory reclamation thread, and determine the predicted reclamation duration of the frame to be processed based on this information. Then, the memory reclamation management thread can determine the sum of the predicted frame duration and the predicted reclamation duration as the task requirement duration of the frame to be processed, and set this task requirement duration as the first parameter. When the first parameter is less than the maximum drawing duration allowed by the operating system for each frame, the memory reclamation management thread can perform memory reclamation operations during the frame drawing period of the frame to be processed; when the first parameter is greater than or equal to the maximum drawing duration, the memory reclamation management thread can temporarily refrain from performing memory reclamation operations, waiting for a suitable opportunity to execute them (i.e., waiting until the task requirement duration corresponding to a subsequent frame is less than the maximum drawing duration before execution).
[0117] In another possible implementation, the first parameter is determined based on the collected frame statistics, including: determining the first parameter based on the frame statistics and the collected user operation information.
[0118] User operation information can include user operation signals issued by the current application before the rendering period of the frame to be processed (e.g., user operation signals issued during the rendering period of the frame preceding the frame to be processed). For example, user operation signals can be click signals, swipe signals, long-press signals, etc., triggered by user actions such as clicking, swiping, and long-pressing on the application interface during the use of the current application. Figure 2 Taking the thread pool shown as an example, user operation information can be collected by the application thread, the UI thread, or a combination of both. The memory reclamation management thread can obtain user operation information from the application thread and / or the UI thread.
[0119] During frame rendering tasks, electronic devices may experience frame drops due to memory reclamation operations. The resulting stuttering can be perceptible to the user at times, but not at others. Whether a user perceives the stuttering depends on their user actions. Therefore, based on user action information, we can determine the user's perceived stuttering level for the frames being processed. This perceived stuttering level characterizes the probability that the user will perceive stuttering when frame drops occur during the frame rendering period. Specifically, a higher perceived stuttering level means a greater probability of perceptible stuttering, and a greater impact of memory reclamation on the display performance during the frame rendering period. Conversely, a lower perceived stuttering level means a lower probability of perceptible stuttering, and a lesser impact of memory reclamation on the display performance during the frame rendering period.
[0120] It can be seen that the display performance of the frame drawing period of the frame to be processed is affected by memory reclamation operations to a degree that is also related to user operation information. Therefore, this embodiment can also refer to user operation information to determine the first parameter (the first parameter can be used to indicate the degree of impact of memory reclamation operations on the display performance of the frame drawing period). Since user operation information specifically affects the user's perception of stuttering in the frame to be processed, this embodiment can refer to user operation information to determine the first parameter, which can realize memory reclamation during some drawing periods where the user does not perceive stuttering, and memory reclamation during frame drawing periods where the user does not perceive stuttering. Even if the electronic device really has frame dropping problems, since the user does not perceive it, it will not affect the display performance of the electronic device. Therefore, this embodiment combines frame drawing statistics and user operation information to determine the first parameter, and performs memory reclamation operations based on the first parameter. This can not only reduce the number of display problems caused by the electronic device performing memory reclamation operations, but also reduce the number of stuttering issues that the user can perceive when the electronic device has frame dropping problems due to memory reclamation operations. In this way, the impact of memory reclamation operations on the display performance of the electronic device can be further reduced, and the display performance of the electronic device can be improved.
[0121] Taking the frame rendering statistics, including the memory reclamation amount of historical frames, the memory reclamation duration of historical frames, and the historical frame rendering duration of historical frames, as an example, in this embodiment, the electronic device can first determine the task requirement duration of the frame to be processed based on the frame rendering statistics, and then determine the idle frame rendering duration of the frame to be processed based on the task requirement duration of the frame to be processed and the maximum rendering duration allowed by the operating system for each frame. The idle frame rendering duration of the frame to be processed is used to characterize the remaining idle time after the frame to be processed is rendered and the memory reclamation operation is completed during the frame rendering period of the frame to be processed. For example, the idle frame rendering duration of the frame to be processed = maximum rendering duration - task requirement duration of the frame to be processed. When the idle frame duration of the frame to be processed is less than or equal to 0, it indicates that the task requirement duration is greater than or equal to the maximum drawing duration. If memory reclamation is performed during the drawing period of the frame to be processed, the electronic device is very likely to experience display problems such as stuttering and frame drops. When the idle frame duration of the frame to be processed is greater than 0, it indicates that the task requirement duration is less than the maximum drawing duration. If memory reclamation is performed during the drawing period of the frame to be processed, the possibility of display problems such as stuttering and frame drops is very small. Afterwards, the electronic device can determine the user's perception of stuttering in the frame to be processed based on user operation information, and determine the first parameter by combining the idle frame duration of the frame to be processed and the perception of stuttering. For example, the first parameter could be the difference between the idle frame duration and the perception of stuttering.
[0122] For example, an electronic device can determine the user's perceived lag level in a frame to be processed based on user operation information and a second set of parameters. Each second parameter in the second set corresponds to a different user operation signal, and each second parameter is used to indicate the correlation between the corresponding user operation signal and the display performance of the electronic device.
[0123] If the second parameter corresponding to the click signal is w1, the second parameter corresponding to the swipe signal is w2, and the second parameter corresponding to the long press signal is w3, and p1 is used to indicate whether the electronic device received a click signal during the frame-drawing period of the frame preceding the frame to be processed, p2 is used to indicate whether the electronic device received a swipe signal during the frame-drawing period of the frame preceding the frame to be processed, and p3 is used to indicate whether the electronic device received a long press signal during the frame-drawing period of the frame preceding the frame to be processed, then the user's perceived stuttering level for the frame to be processed, w, is calculated as w = w1*p1 + w2*p2 + w3*p3. Here, p1, p2, and p3 can each take two values. Taking p1 as an example, when the electronic device receives a click signal during the frame-drawing period of the frame preceding the frame to be processed, p1 can take a value of 1; when the electronic device does not receive a click signal during the frame-drawing period of the frame preceding the frame to be processed, p1 can take a value of 0. w1, w2, and w3 can be values predetermined based on the correlation between the click signal, swipe signal, and long press signal and the display performance of the electronic device.
[0124] Since users perceive lag differently when using different types of applications, the correlation between user operation signals and the display performance of electronic devices also varies for different types of applications. Based on this, embodiments of this application can pre-determine different sets of second parameters for different types of applications. Then, in the process of determining the user's perception of lag for a frame to be processed based on user operation information and the second parameter set, the electronic device can first determine the second parameter set corresponding to the current application from a plurality of pre-obtained second parameter sets, and then determine the user's perception of lag for the frame to be processed based on the determined second parameter set and the user operation information.
[0125] Furthermore, the correlation (positive or negative) between user operation signals and the display performance of electronic devices may differ for different types of applications. Therefore, for applications where user operation signals are negatively correlated with display performance (i.e., more user operation signals result in higher perceived stuttering, greater impact on display performance from memory reclamation, and ultimately worse display performance), the second parameter set should take a positive value. Conversely, for applications where user operation signals are positively correlated with display performance (i.e., more user operation signals result in lower perceived stuttering, less impact on display performance from memory reclamation, and ultimately better display performance), the second parameter set should take a negative value.
[0126] Taking a game application as an example, if a user performs a click, swipe, or long-press operation on the application interface during the rendering period of the frame preceding the frame to be processed, then the rendering period of the frame to be processed needs to respond promptly to the triggered operation. In this case, if the electronic device experiences frame drops during the rendering period of the frame to be processed, the user will perceive the lag. Conversely, if the user does not perform any triggered operation during the rendering period of the frame preceding the frame to be processed, then the rendering period of the frame to be processed is more tolerant of frame drops; in this case, even if the electronic device does experience frame drops during the rendering period of the frame to be processed, the user may not perceive it. It can be seen that for game applications, user operation signals and the display performance of the electronic device are negatively correlated. Therefore, each second parameter in the second parameter group corresponding to game applications can take a positive value.
[0127] Taking a text-reading application as an example, if a user performs a swipe (up or down) on the application interface during the rendering period of the frame preceding the current frame while reading an article, the application needs to respond to this swipe during the rendering period of the current frame. During this response, the user effectively pauses reading and waits for the application's response. In this case, if frame drops occur during the response, the user will not perceive any lag. Conversely, if the user does not perform a swipe during the rendering period of the frame preceding the current frame, there is no need to respond to the swipe during the rendering period of the current frame, allowing the user to focus on reading. In this case, if frame drops occur during the rendering period, the user will perceive lag. It can be seen that for text-reading applications, user operation signals and the display performance of the electronic device are positively correlated. Therefore, each second parameter in the second parameter group corresponding to text-reading applications can take negative values.
[0128] In another possible implementation, the first parameter is determined based on the collected frame statistics, including: determining the first parameter based on the frame statistics and the collected application display information.
[0129] Application display information may include display signals emitted by the current application before the drawing frame period of the frame to be processed (e.g., display signals emitted during the drawing frame period of the frame preceding the frame to be processed). For example, display signals may be screen refresh signals emitted by the application thread, on-screen signals emitted by the application thread, and drawing frame signals emitted by the application thread, etc.
[0130] The frame drawing signal issued by the application thread can be a signal issued by the application thread to indicate that the drawing process of the frame to be processed has officially started. This frame drawing signal is different from the VSync signal for frame drawing requests (the VSync signal for frame drawing requests is issued by the event control thread of the operating system).
[0131] The "display on screen" signal issued by the application thread can be a signal used by the application thread to display the completed frame to be processed on the electronic device's screen. In practical applications, the completed frame to be processed does not necessarily need to be displayed on the screen. Taking instant messaging applications as an example, the application interface of an instant messaging application includes multiple parts (such as friend avatars, the user's avatar, message boxes, input boxes, etc.). When drawing frames for an instant messaging application, these multiple parts may be drawn in multiple consecutive frames, with each frame drawing one or several of these parts. Therefore, if we want to display a frame only after it has been drawn completely, the application thread must issue the display on screen signal only after all multiple parts of that frame have been drawn. That is, in practical applications, it may happen that multiple frames are drawn before a single display on screen signal is issued.
[0132] The screen refresh signal emitted by the application thread can be a signal used to completely overwrite or delete the currently displayed content of the application interface. In practice, when presenting a drawn frame to the screen, it's not always necessary to completely overwrite the currently displayed content. That is, the application thread may not necessarily emit a screen refresh signal for the frame. For example, the drawn frame might be a rectangle at a specified location. When presenting this rectangle on the screen, it can be directly superimposed on the currently displayed content without deleting it. In this case, the application thread will not emit a screen refresh signal for the frame.
[0133] In practical applications, the user's perception of stuttering in the frame being processed is also related to the application's display information. Specifically, the more display signals the electronic device collects from the application's display information, the greater the probability that the user will perceive stuttering when frame drops occur during the frame drawing period of the frame being processed. The display performance during the frame drawing period is also more significantly affected by memory reclamation operations, resulting in a higher perceived stuttering level. Conversely, the fewer display signals the electronic device collects from the application's display information, the lower the probability that the user will perceive stuttering when frame drops occur during the frame drawing period of the frame being processed. The display performance during the frame drawing period is also less significantly affected by memory reclamation operations, resulting in a lower perceived stuttering level.
[0134] It can be seen that the degree to which the display performance of the frame drawing period of the frame to be processed is affected by memory reclamation operations is also related to application display information. Therefore, this embodiment can also refer to application display information to determine the first parameter (the first parameter can be used to indicate the degree to which the display performance of the frame drawing period is affected by memory reclamation operations). Since application display information specifically affects the user's perception of stuttering in the frame to be processed, this embodiment can refer to application display information to determine the first parameter, which can realize memory reclamation during some drawing periods where the user does not perceive stuttering, and memory reclamation during frame drawing periods where the user does not perceive stuttering. Even if the electronic device really has frame dropping problems, since the user does not perceive it, it will not affect the display performance of the electronic device. Therefore, this embodiment combines frame drawing statistics and application display information to determine the first parameter, and performs memory reclamation operations based on the first parameter. This can not only reduce the number of times the electronic device has display problems due to memory reclamation operations, but also reduce the number of times the user can perceive stuttering when the electronic device has frame dropping problems due to memory reclamation operations. In this way, the impact of memory reclamation operations on the display performance of the electronic device can be further reduced, and the display performance of the electronic device can be improved.
[0135] For example, in this embodiment of the application, the electronic device can determine the user's perceived lag level of the frame to be processed based on application display information, and determine the first parameter by combining the idle frame duration of the frame to be processed and the perceived lag level. For instance, the electronic device can determine the user's perceived lag level of the frame to be processed based on application display information and a third parameter group. Each third parameter in the third parameter group corresponds to a different display signal, and each third parameter is used to indicate the correlation between the corresponding display signal and the display performance of the electronic device.
[0136] If the third parameter corresponding to the frame drawing signal is w4, the third parameter corresponding to the screen loading signal is w5, and the third parameter corresponding to the screen refresh signal is w6, then p4 indicates whether the application thread sends a frame drawing signal during the frame drawing period of the frame preceding the frame to be processed; p5 indicates whether the application thread sends a screen loading signal during the frame drawing period of the frame preceding the frame to be processed; and p6 indicates whether the application thread sends a screen refresh signal during the frame drawing period of the frame preceding the frame to be processed. Therefore, the user's perceived stuttering level for the frame to be processed, w, is calculated as w = w4*p4 + w5*p5 + w6*p6. Here, p4, p5, and p6 can each take two values. For example, p4 can take the value 1 when the application thread sends a frame drawing signal during the frame drawing period of the frame preceding the frame to be processed; and it can take the value 0 when the application thread does not send a frame drawing signal during the frame drawing period of the frame preceding the frame to be processed. w1, w2, and w3 can be values that are predetermined based on the correlation between the frame signal, the on-screen signal, and the screen refresh signal and the display performance of the electronic device.
[0137] It should be understood that the correlation between display signals and the display performance of electronic devices is negative (the more display signals there are, the higher the perceived stuttering, the greater the impact of memory reclamation on display performance, and the worse the display performance). Therefore, each third parameter in the third parameter group can take a positive value.
[0138] Furthermore, the correlation between display signals and the display performance of electronic devices varies depending on the type of application. Based on this, embodiments of this application can pre-determine different third parameter sets for different types of applications. Then, in the process of determining the perceived stuttering of a frame to be processed based on application display information and the third parameter sets, the electronic device can first determine the third parameter set corresponding to the current application from multiple pre-obtained third parameter sets, and then determine the user's perceived stuttering of the frame to be processed based on the determined third parameter set and the application display information.
[0139] In another possible implementation, the first parameter is determined based on the collected frame statistics, including: determining the first parameter based on frame statistics, user operation information, and application display information.
[0140] For example, the user's perceived stuttering level for the frame to be processed is w = w1*p1 + w2*p2 + w3*p3 + w4*p4 + w5*p5 + w6*p6.
[0141] Since the display performance of the frame-drawing period of the frame to be processed is affected by memory reclamation operations, this is related not only to user operation information but also to application display information. Therefore, combining frame-drawing statistics, user operation information, and application display information to determine the first parameter can further improve the accuracy of the determined first parameter. This can further reduce the number of times the user perceives stuttering when the electronic device experiences frame drops due to memory reclamation operations, thereby further reducing the impact of memory reclamation operations on the display performance of the electronic device and improving its overall display performance.
[0142] Reference Figure 6 This is a schematic diagram of the structure of a thread pool in another operating system provided in an embodiment of this application. Figure 6 As shown, the operating system's thread pool includes UI threads, rendering threads, application threads, memory reclamation threads, and memory reclamation management threads. The memory reclamation management threads include a prediction module, a computation module, and a decision-making module.
[0143] The prediction module can first obtain the amount of memory reclaimed and the duration of memory reclaimed in historical frames collected by the memory reclamation thread, and determine the predicted reclamation duration of the frame to be processed based on the amount of memory to be reclaimed and the obtained information. Furthermore, the prediction module can obtain the historical rendering duration of historical frames collected by the rendering thread, and determine the predicted rendering duration of the frame to be processed based on the obtained information. Then, the calculation module can determine the idle rendering duration of the frame to be processed based on the maximum rendering duration allowed by the operating system for each frame, and the predicted reclamation duration and predicted rendering duration determined by the prediction module. Additionally, the calculation module can determine the lag perception based on user operation signals and display signals collected by the application thread and UI thread, and determine a first parameter based on the lag perception and the idle rendering duration. Then, the decision module can perform memory reclamation operations during the rendering period of the frame to be processed based on the first parameter. For example, when the first parameter is greater than 0, the memory reclamation operation is performed.
[0144] In one possible implementation, a memory reclamation operation is performed during the drawing frame period of the frame to be processed, based on a first parameter, including: determining memory reclamation conditions based on at least one of the remaining memory amount, the amount of memory to be scanned, and the CPU clock frequency; and performing the memory reclamation operation during the drawing frame period of the frame to be processed if the first parameter satisfies the memory reclamation conditions.
[0145] Remaining memory is the total amount of free memory resources currently available to the operating system. Memory to be scanned is the amount of memory the operating system will scan during the next memory reclamation operation. CPU clock frequency refers to the operating frequency of the CPU core.
[0146] The memory reclamation conditions can include dynamically adjusted parameter thresholds. When the first parameter is less than or equal to the current parameter threshold, the first parameter does not meet the memory reclamation conditions; when the first parameter is greater than the current parameter threshold, the first parameter meets the memory reclamation conditions.
[0147] In practical applications, during the frame drawing period of the frame to be processed, the degree to which the display performance of an electronic device is affected by memory reclamation operations is also related to the amount of remaining memory, the amount of memory to be scanned, and the CPU clock frequency. Based on this, embodiments of this application can dynamically adjust the memory reclamation conditions (i.e., dynamically adjust the threshold of the first parameter) based on the amount of remaining memory, the amount of memory to be scanned, and the CPU clock frequency. This allows for the determination of a more accurate and suitable frame drawing period (i.e., a frame drawing period where the display performance of the electronic device is less affected by memory reclamation operations), thereby further reducing the number of display problems caused by memory reclamation operations and ultimately improving the display performance of the electronic device.
[0148] In a possible implementation, based on a first parameter, a memory recycling operation is performed during the frame drawing period of a frame to be processed, and it further includes: determining a target parameter range to which the first parameter belongs from candidate parameter ranges; and performing a memory recycling operation during the frame drawing period of the frame to be processed based on the recycling mechanism corresponding to the target parameter range.
[0149] Among them, different candidate parameter ranges correspond to different recycling mechanisms, and the recycling rates of different recycling mechanisms are different.
[0150] Exemplarily, the candidate parameter ranges may include a first range, a second range, a third range, and a fourth range. If the first parameter is represented by v, the first range may be v ≤ 0; the second range may be [0 < v ≤ firstline]; the third range may be [firstline < v ≤ secondline]; the third range may be v > Secondline. firstline and secondline may be pre-determined values.
[0151] The recycling mechanism corresponding to the first range may be not performing a memory recycling operation; the recycling mechanism corresponding to the second range may be performing a lightweight memory recycling operation (for example, a recycling mechanism based on an incremental recycling algorithm); the recycling mechanism corresponding to the third range may be performing an intermediate-weight memory recycling operation (for example, a recycling mechanism based on a generational recycling algorithm); the recycling mechanism corresponding to the fourth range may be performing a heavyweight memory recycling operation (for example, a recycling mechanism based on a full-volume recycling algorithm). For example, if the target parameter range to which the first parameter belongs is the third range, the electronic device may perform generational recycling during the frame drawing period of the frame to be processed. The process of specifically performing a memory recycling operation using an incremental recycling algorithm, a generational recycling algorithm, and a full-volume recycling algorithm may refer to the descriptions in related technologies, and will not be elaborated in this embodiment of the present application.
[0152] In this embodiment, multiple parameter ranges (i.e., candidate parameter ranges) are pre-determined for the first parameter, and different recycling mechanisms are set for different parameter ranges. Specifically, the larger the parameter value in the candidate parameter range, the higher the recycling rate of the corresponding recycling mechanism; the smaller the parameter value in the candidate parameter range, the lower the recycling rate of the corresponding recycling mechanism. When memory recycling is required to be performed during the drawing frame time of the frame to be processed, a recycling mechanism more suitable for the frame to be processed (i.e., a recycling mechanism that better meets the current requirements) can be determined based on the first parameter. Taking the remaining drawing frame time of the frame to be processed as an example, when the remaining drawing frame time of the frame to be processed is short, a recycling mechanism based on an incremental recycling algorithm can be used for memory recycling. Since the recycling rate of the incremental recycling algorithm is faster, the number of display problems will be very small when memory recycling is performed within a short remaining drawing frame time. When the remaining frame duration of the frame to be processed is long, a memory reclamation mechanism based on a full-capacity reclamation algorithm can be used for memory reclamation. Although the reclamation rate of the full-capacity reclamation algorithm is relatively slow, the number of display problems occurring during memory reclamation is also very small due to the long remaining frame duration. It can be seen that the embodiments of this application can implement different reclamation rates for the frames to be processed under different frame states. This can improve the memory reclamation efficiency of electronic devices.
[0153] For example, to determine a more accurate appropriate frame period for performing memory reclamation operations, different candidate parameter ranges can be defined for different types of applications (the range of the candidate parameter ranges can be different, and the number of candidate parameter ranges can also be different). Alternatively, the candidate parameter ranges can also be dynamic parameter ranges determined based on the amount of remaining memory, the amount of memory to be scanned, and the CPU clock frequency.
[0154] In one possible implementation, in response to the frame drawing request of the acquired frame to be processed, a first parameter is determined based on the collected frame drawing statistics, including: periodically responding to the frame drawing request with a preset duration as the execution interval, and determining the first parameter based on the frame drawing statistics; wherein the preset duration is equal to the total duration of multiple frame drawing time periods.
[0155] In practical applications, the amount of memory resources to be reclaimed generated in each drawing frame period is limited, and some drawing frame periods generate only a small amount of memory resources to be reclaimed. Based on this, embodiments of this application can perform a memory reclamation decision every few drawing frame periods. This reduces the number of memory reclamation operations while ensuring memory reclamation efficiency, thus saving computer resources.
[0156] By Figure 2 Taking the memory reclamation management thread in the memory management system executing the memory reclamation method as an example, refer to... Figure 7This application provides a simplified flowchart illustrating a memory reclamation method. For example... Figure 7 As shown, if the frame to be processed is the i-th frame, the memory reclamation management thread can execute the following memory reclamation method after obtaining the drawing request for the i-th frame:
[0157] S701. Based on the frame statistics (memory reclamation amount and memory reclamation duration) of the first M frames obtained from the memory reclamation thread, determine the predicted reclamation duration of the frame to be processed. Figure 7 (represented by Ti1 in Chinese).
[0158] S702. Based on the frame statistics (historical frame duration) of the previous M frames obtained from the rendering thread, determine the predicted frame duration of the frame to be processed. Figure 7 (represented by Ti2 in Chinese).
[0159] S703, based on the maximum rendering time per frame allowed by the operating system ( Figure 7 (Represented by Ti3), Ti1, and Ti2, determine the idle drawing frame duration of the frame to be processed. Figure 7 (represented by Ti4 in Chinese).
[0160] S704. Determine the perceived lag level based on user operation information and application display information from the previous frame obtained from the UI thread and application thread.
[0161] S705, based on Ti4 and stuttering perception, determines the first parameter.
[0162] S706, Perform memory reclamation operation based on the first parameter.
[0163] If the electronic device performs a memory reclamation decision every two drawing frame periods, then after the electronic device obtains the drawing frame request for the (i+2)th frame, it needs to repeat the memory reclamation methods from S701 to S706.
[0164] Taking the operating system's thread pool, which includes the UI thread, rendering thread, application thread, and memory reclamation management thread (excluding the memory reclamation thread), as an example, refer to... Figure 8 This application provides a simplified flowchart illustrating another memory reclamation method. For example... Figure 8 As shown, if the frame to be processed is the i-th frame, the memory reclamation management thread can execute the following memory reclamation method after obtaining the drawing request for the i-th frame:
[0165] S801. Based on the frame statistics (memory reclamation amount and memory reclamation duration) of the first M frames obtained from the application thread, determine the predicted reclamation duration of the frame to be processed. Figure 8 (represented by Ti1 in Chinese).
[0166] S802. Based on the frame statistics (historical frame duration) of the previous M frames obtained from the rendering thread, determine the predicted frame duration of the frame to be processed. Figure 8 (represented by Ti2 in Chinese).
[0167] S803, based on the maximum rendering time per frame allowed by the operating system ( Figure 8 (Represented by Ti3), Ti1, and Ti2, determine the idle drawing frame duration of the frame to be processed. Figure 8 (represented by Ti4 in Chinese).
[0168] S804. Determine the perceived lag level based on the user operation information and application display information of the previous frame obtained from the UI thread and application thread.
[0169] S805, based on Ti4 and stuttering perception, determines the first parameter.
[0170] S806, Perform memory reclamation operation based on the first parameter.
[0171] If the electronic device performs a memory reclamation decision every two drawing frame periods, then after the electronic device obtains the drawing frame request for the (i+2)th frame, it needs to repeat the memory reclamation methods from S801 to S806.
[0172] It should be understood that the memory reclamation mechanism provided in this application embodiment can also be used in conjunction with memory reclamation mechanisms in related technologies. For example, the memory reclamation method provided in this application embodiment further includes: during the periodic response to a drawing frame request and the determination of a first parameter based on drawing frame statistics, if the remaining memory is detected to be less than a preset minimum memory threshold, then a memory reclamation operation is performed.
[0173] In the memory reclamation method provided in this application embodiment, after the start of the frame drawing period of the frame to be processed, a first parameter can be determined based on the collected frame drawing statistics, and then a memory reclamation operation is performed during the frame drawing period of the frame to be processed based on the determined first parameter. The frame drawing statistics can be information obtained by statistically analyzing the frame drawing information of the historical frames of the frame to be processed. Since the frame drawing information of historical frames can characterize the remaining frame drawing duration of historical frames (the remaining frame drawing duration of a frame can be the duration remaining after the frame drawing period of that frame is completed), and the drawing process of the frame to be processed is closely related to the drawing process of its historical frames, the remaining frame drawing duration of the frame to be processed can be predicted based on the information obtained by statistically analyzing the frame drawing information of the historical frames of the frame to be processed (i.e., the frame drawing statistics). The shorter the remaining frame drawing duration of the frame to be processed, the higher the possibility of display problems due to the electronic device performing memory reclamation operations; the longer the remaining frame drawing duration of the frame to be processed, the lower the possibility of display problems due to the electronic device performing memory reclamation operations. In other words, during the frame-drawing period of the frame to be processed, the degree to which the display performance of the electronic device is affected by the memory reclamation operation is related to the predicted remaining frame-drawing duration of the frame to be processed. Since the remaining frame-drawing duration of the frame to be processed can be predicted based on frame-drawing statistics, a first parameter can be determined based on these statistics to indicate the degree to which the display performance is affected by the memory reclamation operation during the frame-drawing period of the frame to be processed. Therefore, when the display performance is significantly affected by the memory reclamation operation during the frame-drawing period of the frame to be processed—meaning the electronic device is highly likely to experience display problems due to the memory reclamation operation—then the memory reclamation operation can be avoided during the frame-drawing period of the frame to be processed. Conversely, when the display performance is only slightly affected by the memory reclamation operation—meaning the electronic device is unlikely to experience display problems due to the memory reclamation operation—then the memory reclamation operation can be performed during the frame-drawing period of the frame to be processed.
[0174] As can be seen, the embodiments of this application perform memory reclamation operations based on the first parameter, which can achieve memory reclamation during appropriate frame-drawing periods (i.e., frame-drawing periods where the display performance of the electronic device is less affected by memory reclamation operations). This reduces the number of display problems that occur in the electronic device due to memory reclamation operations, thereby improving the display performance of the electronic device.
[0175] It should be noted that the order of the methods provided in the embodiments of this application can be appropriately adjusted, and the process can also be added or removed as appropriate. Any variations that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the protection scope of this application, and the embodiments of this application do not limit this.
[0176] It is understandable that, in order to achieve the above functions, electronic devices include hardware and / or software modules that perform the respective functions. (Refer to...) Figure 9 This is a schematic diagram of a memory reclamation device provided in an embodiment of this application. Figure 9 As shown, when each functional module is divided according to its corresponding function, the memory reclamation device 900 may include a determination module 901 and a processing module 902.
[0177] The determining module 901 is used to determine a first parameter based on the collected drawing frame statistics information in response to the drawing frame request of the acquired frame to be processed; wherein, the drawing frame request is used to indicate the start of the drawing frame period of the frame to be processed, and the first parameter is used to indicate the degree of impact of the memory reclamation operation on the display performance of the drawing frame period; the processing module 902 is used to perform a memory reclamation operation during the drawing frame period of the frame to be processed based on the first parameter.
[0178] In one possible implementation, the frame drawing statistics may include: the amount of memory reclaimed from historical frames of the frame to be processed, the memory reclamation duration of historical frames, and the historical frame drawing duration of historical frames; the determining module 901 is specifically used to: determine the predicted reclamation duration of the frame to be processed based on the amount of memory reclaimed from historical frames, the memory reclamation duration of historical frames, and the amount of memory to be reclaimed; determine the predicted frame drawing duration of the frame to be processed based on the historical frame drawing duration of historical frames; and determine the first parameter based on the predicted reclamation duration and the predicted frame drawing duration.
[0179] In another possible implementation, the determining module 901 is further used to: determine the first parameter based on the frame statistics and the collected user operation information.
[0180] In another possible implementation, the determining module 901 is further used to: determine the first parameter based on the frame statistics and the collected application display information.
[0181] In another possible implementation, the processing module 902 is specifically used to: determine memory reclamation conditions based on at least one of the remaining memory amount, the amount of memory to be scanned, and the CPU clock frequency; and perform memory reclamation operation during the drawing frame period of the frame to be processed if the first parameter satisfies the memory reclamation conditions.
[0182] In another possible implementation, the processing module 902 is further specifically used to: determine the target parameter range to which the first parameter belongs from the candidate parameter range; the candidate parameter ranges correspond to different recycling mechanisms, and the recycling rates of different recycling mechanisms are different; and perform memory recycling operations during the drawing frame period of the frame to be processed based on the recycling mechanism corresponding to the target parameter range.
[0183] In another possible implementation, the memory reclamation device 900 provided in this application embodiment implements the corresponding functions through application threads in the operating system of the electronic device.
[0184] In another possible implementation, the memory reclamation device 900 provided in this application embodiment implements the corresponding functions through a system thread in the operating system of the electronic device.
[0185] In another possible implementation, the memory reclamation device 900 provided in this application embodiment implements the corresponding functions through a memory reclamation management thread added to the operating system of the running electronic device.
[0186] The memory reclamation device provided in this application embodiment is used to execute the aforementioned memory reclamation method. Figure 5 Taking the memory reclamation method shown as an example, module 901 is determined to be usable for execution. Figure 5 In S501, the processing module 902 can be used to execute... Figure 5 S502 in the above. The specific implementation process of the memory reclamation device and its corresponding beneficial effects can be referred to the relevant descriptions in the foregoing method embodiments, and will not be repeated here.
[0187] For example, the functions implemented by the determining module 901 and the processing module 902 can both be achieved through... Figure 1 Processor 110 in the middle executes Figure 1 The program instructions in the internal memory 121 are implemented.
[0188] It should be noted that, Figure 9 The module division described herein is exemplary, representing only one logical functional division; in actual implementation, other division methods are possible. For example, two or more functions can be integrated into a single module. The integrated module described above can be implemented either in hardware or as a software functional module. For example, Figure 9 The function implemented by the determination module 901 in the middle is the same as that of the module 901 in the middle. Figure 6 The prediction module and the calculation module in the code perform the same function; Figure 9 The functions implemented by the processing module 902 in the middle are the same as those implemented by the processing module 902 in the middle Figure 6 The decision-making module in the same module performs the same function.
[0189] This application also provides a computer-readable storage medium including computer instructions that, when executed on an electronic device, cause the electronic device to perform any of the aforementioned memory reclamation methods. For example, when the computer instructions are executed by one or more processors in the electronic device, the methods performed by the memory reclamation apparatus in the above embodiments can be implemented.
[0190] This application also provides a computer program product that, when run on a computer, causes the computer to execute any of the aforementioned memory reclamation methods. For example, when the computer program product runs on a computer, it can implement the methods executed by the memory reclamation device in the above embodiments.
[0191] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A memory reclamation method, characterized by, The method includes: In response to the frame drawing request of the acquired frame to be processed, a first parameter is determined based on the collected frame drawing statistics; wherein, the frame drawing request is used to indicate the start of the frame drawing period of the frame to be processed, and the first parameter is used to indicate the degree to which the display performance of the frame drawing period is affected by the memory reclamation operation. Based on the first parameter, the memory reclamation operation is performed during the drawing frame period.
2. The method of claim 1, wherein, The frame drawing statistics include: the memory reclamation amount of the historical frames of the frame to be processed, the memory reclamation duration of the historical frames, and the historical frame drawing duration of the historical frames; determining the first parameter based on the collected frame drawing statistics includes: Based on the amount of memory reclaimed in the historical frames, the memory reclamation duration of the historical frames, and the amount of memory to be reclaimed, the predicted reclamation duration of the frame to be processed is determined. Based on the historical frame duration of the historical frames, the predicted frame duration of the frame to be processed is determined. The first parameter is determined based on the predicted recovery time and the predicted frame drawing time.
3. The method according to claim 1 or 2, characterized in that, The determination of the first parameter based on the collected frame statistics includes: The first parameter is determined based on the frame statistics and the collected user operation information.
4. The method according to any one of claims 1 to 3, characterized in that, The determination of the first parameter based on the collected frame statistics includes: The first parameter is determined based on the frame statistics and the collected application display information.
5. The method according to any one of claims 1-4, characterized in that, The step of performing the memory reclamation operation based on the first parameter during the drawing frame period includes: Determine the memory reclamation conditions based on at least one of the remaining memory amount, the amount of memory to be scanned, and the clock frequency of the central processing unit (CPU). If the first parameter satisfies the memory reclamation condition, the memory reclamation operation is performed during the drawing frame period.
6. The method according to any one of claims 1-5, characterized in that, The step of performing the memory reclamation operation based on the first parameter during the drawing frame period includes: The target parameter range to which the first parameter belongs is determined from the candidate parameter ranges; the candidate parameter ranges correspond to different recovery mechanisms, and the recovery rates of different recovery mechanisms are different; Based on the recycling mechanism corresponding to the target parameter range, the memory recycling operation is performed during the drawing frame period.
7. The method according to any one of claims 1-6, characterized in that, The method is applied to application threads within the operating system of an electronic device.
8. The method according to any one of claims 1-6, characterized in that, The method is applied to system threads in the operating system of electronic devices.
9. The method according to any one of claims 1-6, characterized in that, The method is applied to a memory reclamation management thread added to the operating system of an electronic device.
10. A memory reclamation device, characterized in that, The device includes: The determination module is used to determine a first parameter in response to the frame drawing request of the acquired frame to be processed, based on the collected frame drawing statistics; wherein, the frame drawing request is used to indicate the start of the frame drawing period of the frame to be processed, and the first parameter is used to indicate the degree to which the display performance of the frame drawing period is affected by the memory reclamation operation. The processing module is configured to perform the memory reclamation operation during the drawing frame period based on the first parameter.
11. The apparatus according to claim 10, characterized in that, The frame drawing statistics include: the memory reclamation amount of the historical frames of the frame to be processed, the memory reclamation duration of the historical frames, and the historical frame drawing duration of the historical frames; the determining module is specifically used for: Based on the amount of memory reclaimed in the historical frames, the memory reclamation duration of the historical frames, and the amount of memory to be reclaimed, the predicted reclamation duration of the frame to be processed is determined. Based on the historical frame duration of the historical frames, the predicted frame duration of the frame to be processed is determined. The first parameter is determined based on the predicted recovery time and the predicted frame drawing time.
12. The apparatus according to claim 10 or 11, characterized in that, The determining module is further specifically used for: The first parameter is determined based on the frame statistics and the collected user operation information.
13. The apparatus according to any one of claims 10-12, characterized in that, The determining module is further specifically used for: The first parameter is determined based on the frame statistics and the collected application display information.
14. The apparatus according to any one of claims 10-13, characterized in that, The processing module is specifically used for: Determine memory reclamation conditions based on at least one of the following: remaining memory amount, memory amount to be scanned, and CPU clock frequency; If the first parameter satisfies the memory reclamation condition, the memory reclamation operation is performed during the drawing frame period.
15. The apparatus according to any one of claims 10-14, characterized in that, The processing module is also specifically used for: The target parameter range to which the first parameter belongs is determined from the candidate parameter ranges; the candidate parameter ranges correspond to different recovery mechanisms, and the recovery rates of different recovery mechanisms are different; Based on the recycling mechanism corresponding to the target parameter range, the memory recycling operation is performed during the drawing frame period.
16. The apparatus according to any one of claims 10-15, characterized in that, The device performs its functions by running application threads within the operating system of the electronic device.
17. The apparatus according to any one of claims 10-15, characterized in that, The device performs its functions by running system threads within the operating system of the electronic device.
18. The apparatus according to any one of claims 10-15, characterized in that, The device implements the corresponding functions through a memory reclamation management thread added to the operating system of the electronic device.
19. An electronic device, characterized in that, include: Memory and at least one processor; The memory is coupled to the processor; wherein the memory stores computer program code, the computer program code including computer instructions, and when the computer instructions are executed by the processor, the electronic device performs the method as described in any one of claims 1-9.
20. A computer-readable storage medium comprising computer instructions, characterized in that, When the computer instructions are executed on the electronic device, the electronic device causes the electronic device to perform the method as described in any one of claims 1-9.
21. A computer program product, characterized in that, When the computer program product is run on a computer, it causes the computer to perform the method as described in any one of claims 1-9.