Memory recovery method, terminal, storage medium and program product
By selecting memory pages with lower recycling costs from the inactive memory page list and releasing their mapping relationship with the virtual memory area, the problem of low memory recycling efficiency in terminal devices is solved and faster memory supply is achieved.
Patent Information
- Application Number
- CN202410483400.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-22
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2044-04-22
AI Technical Summary
In terminal devices, when memory is recycled, a memory page is mapped to multiple virtual memory areas, resulting in low recycling efficiency and a long time.
Starting from the starting memory page of the inactive memory page linked list, memory pages whose recycling cost representation values are less than or equal to the first recycling cost limit value are determined one by one, their mapping relationships with the virtual memory area are released, and memory pages are preferentially selected for recycling based on the recycling costs of the memory pages.
It improves the efficiency of memory recycling, reduces computing resources and time costs, and ensures the speed of memory supply.
Smart Images

Figure CN119248664B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a memory recovery method, terminal, storage medium, and program product. Background Art
[0002] When an application installed on a terminal such as a mobile phone or tablet runs, the operating system deployed in the terminal will create a process for the application and allocate a virtual memory area (VMA) to the process. There is a mapping relationship between the above VMA and the memory pages of physical memory. In this way, each process can indirectly access the memory page through its corresponding VMA, that is, the process can run in the memory page of physical memory.
[0003] The capacity of physical memory is limited. When memory is scarce and new memory needs arise, the operating system needs to reclaim memory, that is, unmap memory pages from the VMAs. The unmapped memory pages are then reclaimed and can be used to meet the new memory needs.
[0004] However, in some cases, a memory page may be mapped to multiple VMAs. When reclaiming such a memory page, the mapping relationship between the memory page and multiple VMAs needs to be released, which takes a long time and results in low memory reclamation efficiency. Summary of the Invention
[0005] In view of this, the present application provides a memory recovery method, terminal, storage medium and program product to improve memory recovery efficiency.
[0006] In a first aspect, an embodiment of the present application provides a memory recovery method, the method comprising:
[0007] Starting from a starting memory page of the inactive first memory page linked list, based on the target recycling quantity, first memory pages whose recycling cost representation values are less than or equal to the first recycling cost limit value are determined one by one, wherein the memory pages included in the first memory page linked list are: memory pages that are eliminated from the memory pages recorded in the active second memory page linked list and whose recycling cost representation values are less than or equal to the second recycling cost limit value; the maximum number of the first memory pages is the target recycling quantity; and the recycling cost representation values are determined based on the number of virtual memory areas (VMAs) that have a mapping relationship with the memory pages;
[0008] Determine a first VMA that has a mapping relationship with each first memory page;
[0009] Determine a first mapping page table corresponding to the first process to which each first VMA is allocated;
[0010] The mapping relationship between the first memory page and the first VMA stored in each first mapping page table is released, and each first memory page is deleted from the first memory page linked list.
[0011] As can be seen from the above, when applying the solution provided by the embodiment of the present application for memory recycling, starting from the starting memory page of the inactive first memory page linked list, the first memory pages whose recycling cost representation value is less than or equal to the first recycling cost limit value are determined one by one, and the maximum number of first memory pages is the target recycling number. Thus, the first VMA with which each first memory page has a mapping relationship can be determined, and the first mapping page table corresponding to the first process to which each first VMA is allocated can be determined. Then, the mapping relationship between the first memory page stored in each first mapping page table and the first VMA can be released, and each first memory page can be deleted from the first memory page linked list. In this way, the first memory page is successfully recycled and can be used to meet new memory needs.
[0012] Among them, the recycling cost characterization value is used to describe the cost of recycling memory pages. The memory pages with a recycling cost characterization value less than the first recycling cost limit value are memory pages with a smaller recycling cost. It can be seen that the solution provided by the embodiment of the present application takes into account the recycling cost of the memory page when determining the first memory page to be recycled this time. When performing memory recycling, memory pages with a smaller recycling cost can be preferentially selected for recycling. Overall, it is beneficial to ensure that the memory pages finally recycled are all memory pages with a smaller recycling cost, reducing the computing resource cost and time cost spent on memory recycling, improving the efficiency of memory recycling, and accelerating the supply speed of memory.
[0013] In one embodiment of the present application, the method further includes:
[0014] If the determined number of first memory pages is less than the target recycling number, increasing the first recycling cost limit value;
[0015] Return to the step of starting from the starting memory page of the inactive first memory page linked list and determining, based on the target recycling quantity, first memory pages whose recycling cost representation values are less than or equal to the first recycling cost limit value one by one.
[0016] The first memory page is determined based on the recycling cost representation value of the memory page and the first recycling cost limit value. When the number of determined first memory pages is less than the target recycling number, that is, the number of recycled memory pages has not reached the expected recycling number, it indicates that the recycling cost of some memory pages in the first memory page linked list is relatively high. At this time, increasing the first recycling cost limit value can relax the judgment conditions when determining the first memory page. In this way, when returning to execute the memory recycling process, it is conducive to determining more first memory pages based on the increased first recycling cost limit value, thereby facilitating determining the first memory pages whose number meets the target recycling number, and ensuring that this memory recycling can meet the memory recycling needs.
[0017] In one embodiment of the present application, increasing the first recycling cost limit value includes:
[0018] A first step length is added to the first recovery cost limit value to obtain an increased first recovery cost limit value.
[0019] In this way, when the number of determined first memory pages does not reach the target recycling number, the first recycling cost limit value can be gradually increased according to the first step, which is conducive to determining more first memory pages according to the increased first recycling cost limit value.
[0020] In one embodiment of the present application, the first step length is: a preset step length value.
[0021] In this way, the first step length is pre-set, and there is no need to perform the step of determining the step length. The first recovery cost limit value can be conveniently increased according to the preset step length value, thereby improving the execution efficiency of the solution.
[0022] In one embodiment of the present application, the first step length is: a step value determined according to the determined number of first memory pages and the target recycling number.
[0023] It can be seen that the determined number of first memory pages and the target recycling number can reflect the gap between the recycling cost representation value of the memory page and the first recycling cost limit value, and thus can reflect the recycling difficulty of memory recycling according to the current first recycling cost limit value. According to the above recycling difficulty, the first step length for increasing the first recycling cost limit value can be accurately and reasonably determined.
[0024] In one embodiment of the present application, the recycling cost representation value is: the number of VMAs that have a mapping relationship with the memory page.
[0025] The number of VMAs that are mapped to memory pages can more conveniently and accurately reflect the recycling cost of the memory pages, thereby improving the accuracy of the obtained recycling cost representation value.
[0026] In one embodiment of the present application, the recycling cost representation value is: a recycling duration prediction value determined based on the number of VMAs that have a mapping relationship with the memory page.
[0027] In this way, the memory page recycling cost can be reflected intuitively and accurately from the perspective of the memory page recycling time.
[0028] In one embodiment of the present application, the method further includes:
[0029] Determine whether the memory reclamation demand is an urgent memory reclamation demand;
[0030] If not, the step of starting from the starting memory page of the inactive first memory page linked list and determining, based on the target recycling quantity, first memory pages whose recycling cost representation values are less than or equal to the first recycling cost limit value one by one is executed.
[0031] If the memory recycling demand is not an emergency memory recycling demand, it means that the remaining memory capacity is still relatively sufficient, the current memory demand is not urgent, and the recycling pressure is relatively small. At this time, the solution provided in the embodiment of the present application can be adopted to improve the recycling efficiency of the memory page, thereby improving the rationality of the solution.
[0032] In one embodiment of the present application, determining whether the memory reclamation demand is an urgent memory reclamation demand includes:
[0033] Determine whether the memory reclamation request is an urgent memory reclamation request based on at least one of the following conditions:
[0034] The urgency of memory reclamation demand is greater than the preset urgency;
[0035] The remaining memory capacity is less than the preset capacity threshold;
[0036] A length ratio between the second memory page linked list and the first memory page linked list is greater than a preset ratio threshold.
[0037] In this way, multiple conditions can be used to determine whether the memory reclamation demand is an urgent memory reclamation demand from multiple dimensions, thereby improving the accuracy and rationality of the judgment.
[0038] In one embodiment of the present application, the method further includes:
[0039] Determining whether a difference between the number of memory pages included in the inactive first memory page linked list and a target recycling number is greater than a preset number;
[0040] If yes, execute the step of starting from the starting memory page of the inactive first memory page linked list and determining, based on the target recycling quantity, the first memory pages whose recycling cost representation values are less than or equal to the first recycling cost limit value one by one.
[0041] When the difference between the number of memory pages and the target recycling number is large, a small number of memory pages in the first memory page linked list need to be recycled. In this case, the solution provided in the embodiment of the present application can be adopted to select memory pages with lower recycling costs for recycling, so as to improve the recycling efficiency of memory pages and improve the rationality of the solution.
[0042] In a second aspect, an embodiment of the present application provides a terminal, including:
[0043] one or more processors and memory;
[0044] The memory is coupled to the one or more processors, and is used to store computer program code, where the computer program code includes computer instructions. The one or more processors call the computer instructions to enable the terminal to execute the method described in the first aspect.
[0045] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, comprising a computer program, which, when executed on a terminal, enables the terminal to execute the method described in the first aspect.
[0046] In a fourth aspect, an embodiment of the present application provides a computer program product, which includes executable instructions. When the executable instructions are executed on a terminal, the terminal executes the method described in the first aspect.
[0047] In the fifth aspect, an embodiment of the present application provides a chip system, which is applied to a terminal. The chip system includes one or more processors, which are used to call computer instructions to enable the terminal to input data into the chip system and execute the method described in the first aspect to reclaim memory.
[0048] The beneficial effects of the solutions provided by the embodiments in the second to fifth aspects can be referred to the beneficial effects of the solutions provided by the embodiments in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0050] Figure 1 A schematic diagram of the structure of a terminal provided in an embodiment of the present application;
[0051] Figure 2 A software structure diagram of a terminal provided in an embodiment of the present application;
[0052] Figure 3 A schematic diagram of a mapping relationship provided in an embodiment of the present application;
[0053] Figure 4 A flowchart of the first memory recycling method provided in an embodiment of the present application;
[0054] Figure 5 A schematic diagram of the first memory recycling process provided in an embodiment of the present application;
[0055] Figure 6 A flowchart of the second memory recycling method provided in an embodiment of the present application;
[0056] Figure 7 A flowchart of a third memory recycling method provided in an embodiment of the present application;
[0057] Figure 8 A schematic diagram of the second memory recycling process provided in an embodiment of the present application;
[0058] Figure 9 A schematic diagram of a memory recycling process in related art;
[0059] Figure 10a A schematic diagram of the first memory page linked list provided in an embodiment of the present application;
[0060] Figure 10b A schematic diagram of the second memory page linked list provided in an embodiment of the present application;
[0061] Figure 10c A schematic diagram of the third memory page linked list provided in an embodiment of the present application;
[0062] Figure 10d A schematic diagram of the fourth memory page linked list provided in an embodiment of the present application;
[0063] Figure 11 A schematic structural diagram of a chip system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0064] In order to better understand the technical solution of the present application, the embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0065] In order to facilitate the clear description of the technical solutions of the embodiments of the present application, in the embodiments of the present application, words such as "first" and "second" are used to distinguish between identical or similar items with substantially the same functions and effects. For example, the first instruction and the second instruction are intended to distinguish different user instructions and do not limit their order. Those skilled in the art will understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit them to be different.
[0066] It should be noted that, in this application, words such as "exemplarily" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design described in this application as "exemplary" or "for example" should not be construed as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplarily" or "for example" is intended to present the relevant concepts in a concrete manner.
[0067] The solution provided in the embodiments of the present application can be applied to terminals such as mobile phones, tablet computers, desktop computers, smart watches, wearable electronic devices, augmented reality (AR) devices, virtual reality (VR) devices, vehicle-mounted devices, smart cars, robots, etc.
[0068] For example, Figure 1 The figure shows a schematic diagram of the structure of the terminal 100. The terminal 100 may include a processor 110, a display screen 120, a camera 130, an internal memory 140, a Subscriber Identification Module (SIM) card interface 150, a Universal Serial Bus (USB) interface 160, a charging management module 170, a battery management module 171, a battery 172, a sensor module 180, a mobile communication module 190, a wireless communication module 200, an antenna 1, and an antenna 2. The sensor module 180 may include a pressure sensor 180A, a fingerprint sensor 180B, a touch sensor 180C, an ambient light sensor 180D, and the like.
[0069] It should be understood that the structures illustrated in the embodiments of the present application do not constitute a specific limitation on the terminal 100. In other embodiments of the present application, the terminal 100 may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0070] The processor 110 may include one or more processing units. For example, the processor 110 may include a central processing unit (CPU), an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). The different processing units may be independent components or integrated into one or more processors. In some embodiments, the terminal 100 may also include one or more processors 110. The controller may generate operation control signals based on instruction opcodes and timing signals to control instruction fetching and execution. In other embodiments, the processor 110 may also include a memory for storing instructions and data. For example, the memory in the processor 110 may be a cache memory. This memory may store instructions or data that have just been used or are being recycled by the processor 110. If the processor 110 needs to use the instruction or data again, it can directly call it from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the terminal 100 in processing data or executing instructions.
[0071] In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an Inter-Integrated Circuit (I2C) interface, an Inter-Integrated Circuit Sound (I2S) interface, a Pulse Code Modulation (PCM) interface, a Universal Asynchronous Receiver / Transmitter (UART) interface, a Mobile Industry Processor Interface (MIPI), a General-Purpose Input / Output (GPIO) interface, a SIM card interface, and / or a USB interface. The USB interface 160 is an interface that complies with USB standards and may be a Mini USB interface, a Micro USB interface, a USB Type-C interface, or the like. The USB interface 160 may be used to connect a charger to charge the terminal 100, or to transfer data between the terminal 100 and peripheral devices. The USB interface 160 may also be used to connect headphones to play audio through the headphones.
[0072] It is understood that the interface connection relationship between the modules illustrated in the embodiments of the present application is for illustrative purposes only and does not constitute a structural limitation on the terminal 100. In other embodiments of the present application, the terminal 100 may also adopt different interface connection methods from the above embodiments, or a combination of multiple interface connection methods.
[0073] The wireless communication function of the terminal 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 190, the wireless communication module 200, the modem processor, and the baseband processor.
[0074] Antenna 1 and Antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in terminal 100 can be used to cover a single or multiple 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 other embodiments, the antennas can be used in conjunction with a tuning switch.
[0075] Terminal 100 implements display functions through a GPU, display screen 120, and an application processor. The GPU is a microprocessor for image processing that connects display screen 120 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or modify display information.
[0076] The display screen 120 is used to display images, videos, etc. The display screen 120 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a mini-LED, a micro-LED, a micro-o-LED, or a quantum dot light-emitting diode (QLED). In some embodiments, the terminal 100 may include one or more display screens 120.
[0077] In some embodiments of the present application, when the display panel adopts materials such as OLED, AMOLED, FLED, etc., the above Figure 1 The display screen 120 can be bent. Here, the display screen 120 can be bent to any angle at any position and can be maintained at that angle. For example, the display screen 120 can be folded in half from the middle to the left or right. It can also be folded in half from the middle to the top or bottom.
[0078] The display screen 120 of the terminal 100 may be a flexible screen. Currently, flexible screens have attracted much attention due to their unique characteristics and huge potential. Compared with traditional screens, flexible screens are more flexible and bendable, which can provide users with a new way of interaction based on the bendable characteristics, and can meet more user demands for the terminal. For terminals equipped with a foldable display, the foldable display on the terminal can be switched between a small screen in a folded form and a large screen in an unfolded form at any time. Therefore, users are using the split-screen function on terminals equipped with a foldable display more and more frequently.
[0079] The terminal 100 can implement a shooting function through an ISP, a camera 130, a video codec, a GPU, a display screen 120, and an application processor, wherein the camera 130 includes a front camera and a rear camera.
[0080] The ISP processes data fed back by the camera 130. For example, when shooting, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, which is then passed to the ISP for processing and converted into a visible image. The ISP can perform algorithmic optimization on image noise, brightness, and color. The ISP can also optimize parameters such as exposure and color temperature of the captured scene. In some embodiments, the ISP can be located within the camera 130.
[0081] The camera 130 is used to take photos or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal oxide semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP for conversion into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard red, green, blue (RGB), YUV, or other format. In some embodiments, the terminal 100 may include 1 or N cameras 130, where N is a positive integer greater than 1.
[0082] The digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals. For example, when the terminal 100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0083] Video codecs are used to compress or decompress digital video. Terminal 100 may support one or more video codecs. This allows terminal 100 to play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, and MPEG4.
[0084] The NPU is a neural network (NN) computing processor. Drawing on the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it rapidly processes input information and can continuously self-learn. The NPU enables intelligent cognitive applications in the terminal 100, such as image recognition, face recognition, speech recognition, and text comprehension.
[0085] The internal memory 140 can be used to store one or more computer programs, which include instructions. The processor 110 can execute the above instructions stored in the internal memory 140, so that the terminal 100 performs the memory recovery method provided in some embodiments of the present application, as well as various applications and data processing. The internal memory 140 may include a program storage area and a data storage area. The program storage area may store an operating system; the program storage area may also store one or more applications (such as a gallery, contacts, etc.). The data storage area may store data created during the use of the terminal 100 (such as photos, contacts, etc.). In addition, the internal memory 140 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more disk storage components, a flash memory component, a universal flash memory (UFS), etc. In some embodiments, the processor 110 can execute the memory recovery method provided in the embodiments of the present application, as well as other applications and data processing by executing the instructions stored in the internal memory 140 and / or the instructions stored in the memory provided in the processor 110.
[0086] The internal memory 140 can be used to store the relevant programs of the memory recovery method provided in the embodiment of the present application, and the processor 110 can be used to call the relevant programs of the memory recovery method stored in the internal memory 140 when displaying information to execute the memory recovery method of the embodiment of the present application.
[0087] The sensor module 180 may include a pressure sensor 180A, a fingerprint sensor 180B, a touch sensor 180C, an ambient light sensor 180D, and the like.
[0088] Pressure sensor 180A is used to sense pressure signals and convert them into electrical signals. In some embodiments, pressure sensor 180A can be located on display screen 120. There are many types of pressure sensors 180A, including resistive, inductive, and capacitive pressure sensors. A capacitive pressure sensor may comprise at least two parallel plates made of conductive material. When force is applied to pressure sensor 180A, the capacitance between the electrodes changes, and terminal 100 determines the intensity of the pressure based on the change in capacitance. When a touch operation is applied to display screen 120, terminal 100 detects the touch operation based on pressure sensor 180A. Terminal 100 can also calculate the touch location based on the detection signal from pressure sensor 180A. In some embodiments, touch operations applied to the same touch location but with different touch operation intensities can correspond to different operation instructions. For example, when a touch operation with an intensity less than a first pressure threshold is applied to a short message application icon, a command to view short messages is executed; when a touch operation with an intensity greater than or equal to the first pressure threshold is applied to a short message application icon, a command to create a new short message is executed.
[0089] The fingerprint sensor 180B is used to collect fingerprints. The terminal 100 can use the collected fingerprint characteristics to implement functions such as unlocking, accessing application locks, taking photos, and answering calls.
[0090] Touch sensor 180C, also known as a touch-sensitive device, can be provided on display screen 120. Touch sensor 180C and display screen 120 form a touch screen, also known as a touchscreen. Touch sensor 180C is used to detect touch operations applied thereto or in the vicinity thereof. Touch sensor 180C can transmit the detected touch operations to an application processor to determine the type of touch event. Visual output related to the touch operations can be provided via display screen 120. In other embodiments, touch sensor 180C can also be provided on the surface of terminal 100, in a different location from display screen 120.
[0091] Ambient light sensor 180D is used to sense ambient light brightness. Terminal 100 can adaptively adjust the brightness of display screen 120 based on the perceived ambient light brightness. Ambient light sensor 180D can also be used to automatically adjust white balance during photography. Ambient light sensor 180D can also transmit information about the device's environment to the GPU.
[0092] The ambient light sensor 180D is also used to obtain the brightness, light ratio, color temperature, etc. of the acquisition environment in which the camera 130 captures images.
[0093] Figure 2The software system of the terminal can adopt a layered architecture, event-driven architecture, micro-kernel architecture, micro-service architecture, or cloud architecture.
[0094] A layered architecture divides the terminal's software system into several layers, each with distinct roles and responsibilities. Layers communicate with each other via software interfaces. In some embodiments, the software system can be divided into five layers: applications, application framework, system libraries, hardware abstraction layer (HAL), and kernel.
[0095] The application layer can include a series of application packages, and the application layer runs applications by calling the application programming interface (API) provided by the application framework layer. Figure 2 As shown, the application package may include applications such as camera, browser, gallery, music, etc. It can be understood that the port of each of the above applications can be used to receive data.
[0096] The application framework layer provides API and programming framework for the applications in the application layer. The application framework layer includes some predefined functions. Figure 2 As shown, the application framework layer may include a window manager, a content provider, a view system, a resource manager, a notification manager, and a Dynamic Host Configuration Protocol (DHCP) module.
[0097] The system library can include multiple functional modules, such as surface manager, 3D graphics processing library, 2D graphics engine and file library.
[0098] The hardware abstraction layer can contain multiple library modules, such as display and motor libraries. The terminal system can load the corresponding library modules for the device hardware, thereby enabling the application framework layer to access the device hardware. For example, the terminal system can load the corresponding library module for the camera, thereby enabling the camera application to access the camera.
[0099] The kernel layer is the layer between hardware and software. The kernel layer is deployed with an operating system, which is used to drive the hardware and make it work. The kernel layer includes at least a display driver, a camera driver, a sensor driver, and a motor driver, etc., which are not limited in the embodiments of the present application. It is understandable that the display driver, camera driver, sensor driver, and motor driver, etc. can all be considered as a driver node. Each of the above-mentioned driver nodes includes an interface that can be used to receive data.
[0100] Among them, the operating system deployed in the kernel layer of the terminal can respond to the memory reclamation indication and execute the memory reclamation solution provided in the embodiment of the present application.
[0101] To facilitate understanding of the solutions provided by the embodiments of the present application, some concepts involved in the embodiments of the present application are first introduced below.
[0102] 1. Memory Page
[0103] A memory page refers to a memory access unit in physical memory that is divided into fixed sizes. It can also be called a physical memory page, physical page frame, page frame, etc.
[0104] 2. First memory page list
[0105] The first memory page linked list refers to an inactive memory page linked list maintained by the operating system, that is, an inactive linked list, which records the frame numbers of inactive memory pages.
[0106] The activity level of a memory page is associated with the number of times the memory page has been accessed recently. An inactive memory page is a memory page that has been accessed less frequently recently, that is, a memory page that has been less active recently.
[0107] 3. Second memory page list
[0108] The second memory page linked list refers to an active memory page linked list maintained by the operating system, that is, an active linked list, which records the frame numbers of inactive memory pages.
[0109] In contrast to the first memory page linked list, the second memory page linked list is the memory pages that have been accessed more frequently recently, that is, the memory pages that have been more active recently.
[0110] 4. VMA, Mapping Page Table
[0111] When the application installed in the terminal is running, the operating system deployed in the terminal will create a process for the application, and when the process requests memory, it will allocate VMA to the process in response to the process's memory request. VMA can be understood as an abstraction of a continuous linear address space. There is a mapping relationship between VMA and the memory pages of physical memory. The above mapping relationship is stored in the mapping page table (PageTable) corresponding to the process.
[0112] A memory page may be mapped to one VMA or may be mapped to multiple VMAs.
[0113] Below through Figure 3 Provide a more intuitive introduction to VMA and mapping page tables.
[0114] See also Figure 3 , which is a schematic diagram of a mapping relationship provided in an embodiment of the present application.
[0115] As can be seen, the operating system allocates a VMAs to processes 1-3: VMA1 and VMA4 to process 1, VMA2 to process 2, and VMA3 to process 3. VMA4 is mapped to memory page 1, VMA5-VMA6 to memory page 2, and VMA1-VMA3 to memory page 3.
[0116] Then, for process 1, it is allocated VMA1 and VMA4. The mapping relationship between VMA1 and memory page 3 and the mapping relationship between VMA4 and memory page 1 will be recorded in the mapping page table 1 corresponding to process 1; similarly, the mapping relationship between VMA2 and memory page 3 will be recorded in the mapping page table 2 corresponding to process 2; the mapping relationship between VMA3 and memory page 3 will be recorded in the mapping page table 3 corresponding to process 3.
[0117] The following is a detailed introduction to the memory recovery solution provided in the embodiments of the present application.
[0118] See also Figure 4 , which is a flow chart of the first memory recovery method provided in an embodiment of the present application, the above method includes the following steps S401-S404.
[0119] Step S401: starting from the starting memory page of the inactive first memory page linked list, first memory pages having a recycling cost representation value less than or equal to a first recycling cost limit value are determined one by one based on a target recycling quantity.
[0120] This step can be performed when there is a memory reclaim indication. The embodiment of the present application does not limit the memory reclaim indication and is introduced below by way of example.
[0121] In one case, when a process requests memory, if the operating system determines that the current remaining memory capacity is insufficient to allocate memory to the process, a memory reclaim indication may be generated.
[0122] In another case, the operating system may periodically scan memory usage. When it determines that the ratio of the current remaining memory capacity to the total memory capacity is lower than a certain ratio, it may be considered that the memory capacity is relatively tight and a memory reclamation indication may be generated.
[0123] The target recycling quantity is the number of memory pages that need to be recycled this time, determined based on the current memory recycling instruction.
[0124] The following is an example of how to determine the target recycling quantity.
[0125] In one implementation, the memory reclamation indication may directly carry the target number of memory pages to be reclaimed this time.
[0126] In another embodiment, the memory reclamation instruction may include a target memory capacity to be reclaimed. Thus, the target number of memory pages to be reclaimed may be determined based on the target memory capacity and the unit memory capacity of the memory page. For example, the ratio of the target memory capacity to the unit memory capacity may be calculated, and the result may be rounded up and added to 1 to obtain the target number of memory pages to be reclaimed.
[0127] The memory page recycling cost representation value is used to describe the cost required to recycle the memory page. The above cost may include computing resource cost, time cost, etc., which is not limited in this embodiment of the present application.
[0128] In one case, the recycling cost representation value may be the number of VMAs that have a mapping relationship with the memory page.
[0129] The inventors have discovered through practice that the greater the number of VMAs that are mapped to a memory page, the longer it takes to reclaim that memory page. Therefore, the number of VMAs that are mapped to a memory page can more conveniently and accurately reflect the memory page's recycling cost, improving the accuracy of the resulting recycling cost representation.
[0130] In another case, the recycling cost representation value may be a recycling duration prediction value determined based on the number of VMAs that have a mapping relationship with the memory page.
[0131] Specifically, the number of VMAs that are mapped to the memory page may be obtained first, and then the predicted value of the memory page reclaiming duration may be determined based on the relationship between the number and the time required to reclaim the memory page.
[0132] In this way, the memory page recycling cost can be reflected intuitively and accurately from the perspective of the memory page recycling time.
[0133] The first recycling cost limit value mentioned above is introduced below.
[0134] In one implementation, the first recovery cost limit value may be pre-set by a staff member based on experience, and this embodiment of the present application does not limit this.
[0135] In another embodiment, the first recycling cost limit value can be set according to the urgency of the memory recycling demand. The meaning and determination method of the urgency of the memory recycling demand will be described in detail in the subsequent embodiments and will not be described in detail here.
[0136] For example, when the urgency of the memory reclamation demand is low, a smaller first reclamation cost limit value is set; when the urgency of the memory reclamation demand is high, a larger first reclamation cost limit value is set.
[0137] The memory pages included in the first memory page linked list are introduced below.
[0138] The memory pages included in the first memory page linked list are: memory pages that are eliminated from the memory pages recorded in the second memory page linked list and whose recycling cost representation values are less than or equal to the second recycling cost limit value.
[0139] That is, the memory pages whose recycling cost representation values are less than or equal to the second recycling cost limit value can be first determined from the second memory page linked list, these memory pages can be deleted from the second memory page linked list, and these memory pages can be recorded in the first memory page linked list. For details, see the subsequent embodiments. In this way, the first memory page to be recycled can be selected from the first memory page linked list.
[0140] Among them, the second recovery cost limit value can be set in a similar manner to the above-mentioned first recovery cost limit value. The second recovery cost limit value can be the same as the first recovery cost limit value or different from the first recovery cost limit value. This embodiment of the present application does not limit this.
[0141] The following describes a specific method for determining the first memory page from the first memory page linked list.
[0142] The starting memory page of the first memory page linked list is the first memory page recorded in the first memory page linked list. In this step, starting from the starting memory page, the first memory pages whose recovery cost representation value is less than or equal to the first recovery cost limit value are determined one by one, and the maximum number of the first memory pages is the target recovery number.
[0143] That is, first, the starting memory page is determined to be the first memory page based on the recycling cost representation value of the starting memory page. Then, the starting memory page is determined to be the first memory page based on the recycling cost representation value of the second memory page. And so on, until the number of determined first memory pages reaches the target recycling number. The following figure provides a visual explanation.
[0144] See also Figure 5, which is a schematic diagram of the first memory recycling process provided in an embodiment of the present application, Figure 5 The judgment that the requirement is met is to judge that the recycling cost representation value of the memory page is less than or equal to the first recycling cost limit value.
[0145] Figure 5 In the process, if the memory pages recorded in the first memory page linked list are recorded as [F1, F2, F3, F4, F5, F6] and the target recycling quantity is 4, you can start from memory page F1, first determine that F1 meets the requirements, and determine memory page F1 as the first memory page. Since the number of the first memory page does not reach the target recycling quantity, continue to execute the process, determine that F2 does not meet the requirements, continue to determine that F3 meets the requirements, and determine memory page F3 as the first memory page. Then determine that F4 meets the requirements, and determine memory page F4 as the first memory page. At this time, the number of the first memory page reaches the target recycling quantity, and the process ends.
[0146] Step S402: Determine a first VMA that has a mapping relationship with each first memory page.
[0147] After determining the first memory page to be reclaimed this time, in order to perform memory page reclamation, it is necessary to first determine the first VMA that has a mapping relationship with each first memory page.
[0148] As mentioned above Figure 3 As shown, if memory page 3 is the first memory page, it can be determined that the first VMA that has a mapping relationship with memory page 3 is VMA-VM3.
[0149] Step S403: determining a first mapping page table corresponding to the first process to which each first VMA is allocated.
[0150] The process maintains a mapping page table, which records the mapping relationship between the VMA allocated by the process and the memory page.
[0151] After the aforementioned steps S401 and S402, the first memory pages to be reclaimed and the first VMAs that have a mapping relationship with each first memory page are determined, the first mapping page table corresponding to the first process to which each first VMA is allocated can be determined, so as to subsequently release the mapping relationship between the first memory page and the first VMA from the first mapping page table.
[0152] Step S404: canceling the mapping relationship between the first memory pages and the first VMA stored in each first mapping page table, and deleting each first memory page from the first memory page linked list.
[0153] After the mapping relationship between the first memory page and the first VMA stored in each first mapping page table is released, all VMAs that have a mapping relationship with the first memory page are released, and the first memory page no longer has a mapping relationship with any VMA.
[0154] For example, if the first VMA corresponding to the first memory page F1 is VMA1-VMA3, the first processes P1-P3 are allocated VMA1-VMA3 respectively, and the first mapping page tables of P1-P3 respectively record the mapping relationship between F1 and VMA1, the mapping relationship between F1 and VMA2, and the mapping relationship between F1 and VMA3. In this way, after the mapping relationship stored in the mapping page table of P1-P3 is released, VMA1-VMA3 that have a mapping relationship with F1 are all released, and F1 no longer has a mapping relationship with any VMA.
[0155] It can be seen that after the mapping relationship between the first memory page stored in each first mapping page table and the first VMA is released, the first memory page is reclaimed, or in other words, the first memory page is released. At this time, the physical memory page is successfully reclaimed and can be used to meet new memory requirements.
[0156] Among them, each first memory page can be deleted from the first memory page linked list every time it is determined, or each first memory page can be deleted from the first memory page linked list after the target number of first memory pages to be recycled is determined. This embodiment of the present application does not limit this.
[0157] As can be seen from the above, when applying the solution provided by the embodiment of the present application for memory recycling, starting from the starting memory page of the inactive first memory page linked list, the first memory pages whose recycling cost representation value is less than or equal to the first recycling cost limit value are determined one by one, and the maximum number of first memory pages is the target recycling number. Thus, the first VMA with which each first memory page has a mapping relationship can be determined, and the first mapping page table corresponding to the first process to which each first VMA is allocated can be determined. Then, the mapping relationship between the first memory page stored in each first mapping page table and the first VMA can be released, and each first memory page can be deleted from the first memory page linked list. In this way, the first memory page is successfully recycled and can be used to meet new memory needs.
[0158] Among them, the recycling cost characterization value is used to describe the cost of recycling memory pages. The memory pages with a recycling cost characterization value less than the first recycling cost limit value are memory pages with a smaller recycling cost. It can be seen that the solution provided by the embodiment of the present application takes into account the recycling cost of the memory page when determining the first memory page to be recycled this time. When performing memory recycling, memory pages with a smaller recycling cost can be preferentially selected for recycling. Overall, it is beneficial to ensure that the memory pages finally recycled are all memory pages with a smaller recycling cost, reducing the computing resource cost and time cost spent on memory recycling, improving the efficiency of memory recycling, and accelerating the supply speed of memory.
[0159] according to Figure 4 In addition to the description of the illustrated embodiment, the present application also provides another memory recycling method.
[0160] See also Figure 6 , which is a flow chart of the second memory recovery method provided in an embodiment of the present application, the above method includes the following steps S601-S606.
[0161] Step S601: starting from the starting memory page of the second memory page linked list, target memory pages having recycling cost representation values less than or equal to the second recycling cost limit value are determined one by one.
[0162] This step can be performed when there is a memory recycling indication, or it can be performed according to a certain period, and the embodiments of the present application do not limit this.
[0163] In this step, the method of determining the target memory page one by one from the second memory page is the same as the above Figure 3 The method of determining the first memory page one by one from the first memory page described in the illustrated embodiment is similar, the only difference being that the memory page linked list and the memory pages recorded in the linked list are different, which will not be described in detail here.
[0164] In one case, the target reclaim amount may also be considered when determining the target memory page from the second memory page.
[0165] For example, the target memory pages may be determined one by one starting from the starting memory page of the second memory page linked list, and the maximum number of the target memory pages is the target recycling number.
[0166] In this way, when there is a need for memory recovery, the target memory page recorded in the second memory page linked list can be eliminated to the first memory page linked list first. When determining the target memory page to be eliminated, the recovery cost representation value of the memory page and the second recovery cost limit value are taken into consideration, so that the target memory page with lower recovery cost can be eliminated to the first memory page linked list first.
[0167] Step S602: Delete the target memory page from the second memory page linked list, and add the target memory page to the first memory page linked list.
[0168] In this step, the target memory page originally recorded in the second memory page linked list is "transferred" to the first memory page linked list, which can also be referred to as the target memory page originally recorded in the second memory page linked list being eliminated from the first memory page linked list.
[0169] Step S603: starting from the starting memory page of the first memory page linked list, based on the target recycling quantity, first memory pages having recycling cost representation values less than or equal to the first recycling cost limit value are determined one by one.
[0170] Step S604: Determine a first VMA that has a mapping relationship with each first memory page.
[0171] Step S605: Determine the first mapping page table corresponding to the first process to which each first VMA is allocated.
[0172] Step S606: cancel the mapping relationship between the first memory pages and the first VMA stored in each first mapping page table, and delete each first memory page from the first memory page linked list.
[0173] The above steps S603 to S606 are the same as the above Figure 4 In the illustrated embodiment, steps S401 to S404 are the same and will not be described in detail here.
[0174] In this embodiment, when there is a need for memory recycling, the target memory page with lower recycling cost in the second memory page linked list is first eliminated to the first memory page linked list, and then the first memory page with lower recycling cost is selected from the first memory page linked list for recycling.
[0175] Since the recycling cost representation value can be the number of VMAs that are mapped to the memory page, the memory page with a smaller recycling cost representation value in the second memory page linked list is eliminated to the first memory page, that is, the memory page with a smaller number of corresponding VMAs in the second memory page linked list is eliminated to the first memory page first.
[0176] The inventors have found through practice that the number of VMAs that are mapped to memory pages is associated with the access frequency of the memory pages, and the above number and access frequency are generally positively correlated: the larger the number, the higher the access frequency of the memory pages, and the smaller the number, the lower the access frequency of the memory pages.
[0177] Therefore, the memory pages with smaller corresponding VMA numbers in the second memory page list are eliminated to the first memory page first, that is, the memory pages with lower access frequency (which can be called "cold pages") in the second memory page list are eliminated to the first memory page first, so that when the memory pages are subsequently recycled from the first memory page list, it is beneficial to give priority to recycling the "cold pages" with lower access frequency, reduce the probability of recycling the "hot pages" with higher access frequency, and further improve the rationality of the memory recycling scheme.
[0178] exist Figure 4 Based on the embodiment shown, if all memory pages recorded in the first memory page linked list have been traversed and the number of determined first memory pages has not yet reached the target recycling number, the first recycling cost limit value can be adjusted and the memory recycling process can be repeated based on the memory pages included in the first memory page linked list until the number of determined first memory pages reaches the target recycling number. In view of the above situation, the embodiment of the present application provides a second memory recycling method.
[0179] See also Figure 7 , which is a flow chart of the third memory recovery method provided in an embodiment of the present application, the above method includes the following steps S701-S706.
[0180] Step S701: starting from the starting memory page of the inactive first memory page linked list, first memory pages having a recycling cost representation value less than or equal to a first recycling cost limit value are determined one by one based on the target recycling quantity.
[0181] Step S702: Determine a first VMA that has a mapping relationship with each first memory page.
[0182] Step S703: Determine the first mapping page table corresponding to the first process to which each first VMA is allocated.
[0183] Step S704: cancel the mapping relationship between the first memory pages and the first VMA stored in each first mapping page table, and delete each first memory page from the first memory page linked list.
[0184] The above steps S701 to S704 are the same as the above Figure 4 In the illustrated embodiment, steps S401 to S404 are the same and will not be described in detail here.
[0185] Step S705: Determine whether the number of the determined first memory pages is less than the target recycling number. If so, execute step S706.
[0186] Whether the number of the determined first memory pages is less than the target recycling number, that is, the number of recycled memory pages is less than the target recycling number, in this case, step S706 may be executed.
[0187] Step S706: Increase the first recovery cost limit value, and return to step S701.
[0188] Depend on Figure 4 As can be seen from the illustrated embodiment, memory pages in the first memory page linked list whose recycling cost representation value is less than or equal to the first recycling cost limit value will be determined as first memory pages for recycling, that is, memory pages with lower recycling costs will be recycled.
[0189] Then, if after one round of traversal, the number of reclaimed memory pages is less than the target reclaim number, that is, the number of reclaimed memory pages does not reach the expected reclaim number, it indicates that the reclaim cost of some memory pages in the first memory page linked list is high. In order to be able to reclaim the target reclaim number of memory pages, the first reclaim cost limit value can be increased, that is, the judgment criteria for the first memory page can be relaxed, and return to step S701, and repeat the memory reclaim process to determine more first memory pages.
[0190] See also Figure 8 , is a schematic diagram of the second memory recycling process provided in an embodiment of the present application, Figure 8 The judgment that the requirement is met is to judge that the recycling cost representation value of the memory page is less than or equal to the first recycling cost limit value.
[0191] Figure 8 In the example, if the memory pages recorded in the first memory page linked list are recorded as [F1, F2, F3, F4, F5, F6] and the target recycling quantity is 3, we can start from the starting memory page F1, first determine whether F1 meets the requirements, and determine memory page F1 as the first memory page. Since the number of the first memory page does not reach the target recycling quantity, the execution process continues, and then determine in turn that F2-F6 do not meet the requirements.
[0192] At this time, all memory pages have been traversed, and the number of the first memory pages has not yet reached the target recovery number. In this case, the first recovery cost limit value can be increased. Since the first memory page F1 is deleted from the first memory page linked list, memory page F2 becomes the starting memory page. Continue to judge whether F2 meets the requirements and determine memory page F2 as the first memory page. Then judge whether F3 meets the requirements and determine memory page F3 as the first memory page. At this time, the number of the first memory pages reaches the target recovery number and the process ends.
[0193] The following describes a method for increasing the first recovery cost limit value.
[0194] Specifically, a first step length may be added to the first recovery cost limit value to obtain an increased first recovery cost limit value.
[0195] In this way, when the number of determined first memory pages does not reach the target recycling number, the first recycling cost limit value can be gradually increased according to the first step, which is conducive to determining more first memory pages according to the increased first recycling cost limit value.
[0196] Among them, the embodiment of the present application does not limit the specific method of determining the first step length, and an example is given below to illustrate.
[0197] In one embodiment, the first step length can be a preset step length value. This can be set by staff based on experience, for example, 1, 2, etc. In this way, the first step length is pre-set, eliminating the need to perform a step length determination step. The first recovery cost limit value can be conveniently increased according to the preset step length value, thereby improving the execution efficiency of the solution.
[0198] In another implementation, the first step length may be a step value determined according to the determined number of first memory pages and the target recycling number.
[0199] Specifically, the difference between the target recycling quantity and the determined quantity of the first memory pages may be calculated, and the first step length may be determined according to a preset correspondence between the difference and the step length value.
[0200] The above correspondence relationship may be that the difference value is positively correlated with the step value.
[0201] For example, a larger difference value corresponds to a larger step size, and a smaller difference value corresponds to a smaller step size.
[0202] When the above difference is large, it means that there is a large gap between the number of first memory pages and the expected target recovery number. The reason may be that there is a large gap between the recovery cost representation value of the memory page in the first memory page linked list and the first recovery cost limit value, resulting in a high difficulty in memory recovery according to the current first recovery cost limit value. Therefore, in order to quickly determine more first memory pages, the restriction conditions for determining the first memory page can be relaxed to a large extent, that is, a larger first step length can be determined.
[0203] Conversely, when the above difference is small, it means that the gap between the number of first memory pages and the expected target recovery number is small. The reason may be that the gap between the recovery cost representation value of the memory page in the first memory page linked list and the first recovery cost limit value is small, resulting in a lower recovery difficulty for memory recovery according to the current first recovery cost limit value. Therefore, the restriction conditions for determining the first memory page can be relaxed to a smaller extent, that is, a smaller first step length can be determined.
[0204] It can be seen that the determined number of first memory pages and the target recycling number can reflect the gap between the recycling cost representation value of the memory page and the first recycling cost limit value, and thus can reflect the recycling difficulty of memory recycling according to the current first recycling cost limit value. According to the above recycling difficulty, the first step length for increasing the first recycling cost limit value can be accurately and reasonably determined.
[0205] The first memory page is determined based on the recycling cost representation value of the memory page and the first recycling cost limit value. When the number of determined first memory pages is less than the target recycling number, that is, the number of recycled memory pages has not reached the expected recycling number, it indicates that the recycling cost of some memory pages in the first memory page linked list is relatively high. At this time, increasing the first recycling cost limit value can relax the judgment conditions when determining the first memory page. In this way, when returning to execute the memory recycling process, it is conducive to determining more first memory pages based on the increased first recycling cost limit value, thereby facilitating determining the first memory pages whose number meets the target recycling number, and ensuring that this memory recycling can meet the memory recycling needs.
[0206] The beneficial effects of the solutions provided in the embodiments of the present application are analyzed in detail below.
[0207] The inventor has found through practice that the more VMAs that are mapped to a memory page, the longer it takes to reclaim the memory page. Specifically, as the number of VMAs that are mapped to a memory page increases, the time required to reclaim the memory page also increases significantly.
[0208] Set a fixed test model: start 25 applications installed on the terminal in sequence, wait for 5 seconds after starting, return to the desktop and wait for 5 seconds, then start the next application, repeat this three times, and collect the generated test data. The following table can be obtained based on the test data:
[0209] Table 1
[0210]
[0211] Table 1 above is a table obtained based on test data, wherein Mapcount (mapping number) refers to the number of VMAs that have a mapping relationship with the memory page, the first column of data indicates the interval to which the Mapcount corresponding to the memory page belongs, the second column of data indicates the number of memory pages located in the above intervals, the third column of data indicates the percentage of the number of memory pages located in the above intervals to the total number of memory pages, the fourth column of data indicates the recycling time of the memory pages located in the above intervals, in microseconds (μs), and the fifth column of data indicates the percentage of the recycling time of the memory pages located in the above intervals to the total recycling time.
[0212] The table above shows that memory pages with Mapcount in the range [1,10] (i.e., memory pages with less than 10 corresponding VMAs) account for about 98% of the total memory pages, but the time required to reclaim these memory pages only accounts for about 54% of the total time. Memory pages with Mapcount in the range >50 (i.e., memory pages with more than 50 corresponding VMAs) account for only about 1% of the total memory, but the time required to reclaim these memory pages accounts for about 27% of the total time.
[0213] It can be seen that as the Mapcount corresponding to a memory page increases, the time required to reclaim the memory page will also increase significantly.
[0214] The following is a detailed comparison between the memory recycling solution provided in the embodiment of the present application and the memory recycling solution in the related art.
[0215] First, the memory recycling solution in related technologies is introduced.
[0216] When performing memory recycling in the related art, memory pages are recycled sequentially starting from the starting memory page of the inactive first memory page linked list.
[0217] See also Figure 9 , which is a schematic diagram of a memory recycling process in related technology.
[0218] It can be seen that the memory pages recorded in the first memory page linked list are [F1, F2, ..., F11, F12], and the target recycling number is 11. The existing technology will first recycle F1, and then recycle the memory pages after F1, that is, recycle F2, and so on, until F11 is recycled. It is determined that the number of recycled memory pages reaches the target recycling number, and the process ends.
[0219] Depend on Figure 9 It can be seen intuitively that when performing memory reclamation, the related technology only reclaims memory pages in the order of the memory pages recorded in the first memory page list. As a result, if the number of VMAs mapped to the front part of the first memory page list increases, the reclamation time will increase significantly.
[0220] In the solution provided in the embodiment of the present application, the recovery cost of memory pages is taken into consideration when performing memory recovery, and memory pages with lower recovery costs can be preferentially selected for recovery. Compared with the memory recovery solution in the related art, it is generally beneficial to ensure that the memory pages finally recovered are memory pages with lower recovery costs, thereby reducing the computing resource cost and time cost spent on memory recovery and improving the efficiency of memory recovery.
[0221] The following combination Figure 10a-Figure 10d , analyzed through specific examples. Among them, Figure 10a-Figure 10d Schematic diagrams of the first to fourth memory page linked lists provided in the embodiments of the present application, respectively, Figure 10a-Figure 10d The numbers recorded in the first memory page linked list indicate the number of VMAs that have a mapping relationship with the memory page. Figure 10b-Figure 10d The memory pages shown with a gray background in the first memory page linked list are memory pages that have been reclaimed.
[0222] If the first memory page linked list includes 10 memory pages, the target number of memory recycling requirements is 7, and the first memory page linked list is as follows Figure 10a shown.
[0223] When using related technologies for memory recycling:
[0224] The first memory page linked list after recycling is as follows Figure 10b As shown, Figure 10b The memory pages shown with a gray background in the first memory page linked list are memory pages that have been reclaimed.
[0225] Assuming that the time cost of releasing one memory page and VMA is 1, the total time cost of memory recycling in related technologies is: 1+2+6+3+8+4+2=26.
[0226] When using the solution provided in the embodiments of this application to reclaim memory:
[0227] If the first recycling cost limit is set to 2, then after the first round of memory recycling, the memory pages with the number of mapped VMAs less than or equal to 2 will be recycled, such as Figure 10c shown.
[0228] It can be seen that the number of memory pages recovered in the first round of memory recycling is 6, which is less than the target recycling number of 7. Therefore, the first recycling cost limit value can be increased. Assuming that the increased first recycling cost limit value is 3, the second round of memory recycling is carried out. Among them, the memory pages recovered in the first round of memory recycling will be deleted from the first memory page list. Then, the first memory page list after the second round of memory recycling is as follows: Figure 10d shown.
[0229] It can be seen that in the second round of memory reclamation, the memory pages with 3 mapped VMAs were also reclaimed, and the total number of reclaimed memory pages reached the target reclamation number of 7.
[0230] Similarly, assuming that the time cost required to release one memory page and VMA is 1, the total time cost spent on memory recycling in the solution provided in the embodiment of the present application is: 1+2+2+1+2+1+3=12.
[0231] By comparison, it can be seen that in the above example, the total time cost spent on memory recovery by the related technology is 26, while the total time cost spent on memory recovery by the solution provided in the embodiment of the present application is only 12. Compared with the related technology, the time cost of memory recovery is greatly lowered, and the memory recovery efficiency is improved.
[0232] The beneficial effects of the solution provided in the embodiments of the present application are verified below through specific data.
[0233] See Table 2 below, which is a table obtained based on the data obtained from the aforementioned fixed test model.
[0234] Table 2
[0235] Statistics This application plan Related technologies Percent change time consuming 1,639,977,435 2,116,527,289 -22.52 Number of reverse mappings 84,724,910 96,461,638 -12.17 Recycling volume 43,215,503 46,408,993 -6.88 Scan volume 83,938,021 93,505,519 -10.23 Recycling volume / time 0.03 0.02 20.18 Scanning volume / recovery volume 1.94 2.01 -3.60
[0236] Among them, the unit of time consumption in Table 2 is microseconds, the number of reverse mappings represents the number of times the mapped VMA is determined based on the memory page, the first column of data represents various statistical items, the second column of data represents the data obtained by statistics of the present application scheme, the third column of data represents the data obtained by statistics of related technologies, and the fourth column of data represents the percentage change of data of the present application scheme relative to the related technology.
[0237] It can be seen intuitively from the above table that compared with the related art, the present application scheme reduces the recovery time by about 23% while reducing the recovery volume by about 6.88%. Among them, the reduction in recovery volume is the test difference, but the reduction in time is much greater than the reduction in recovery volume. In addition, the scanning volume is reduced by about 10%, and the recovery efficiency (recovery volume / recovery time) is improved by about 20%. The scanning volume is reduced by about 10%, and an average of about 1.94 pages can be recovered for every scan, while the related art needs to scan 2.01 pages.
[0238] See Table 3 below, which is a table obtained based on the data obtained from the aforementioned fixed test model.
[0239] Table 3
[0240]
[0241] Among them, the unit of time consumption in Table 3 is microseconds. Direct memory recovery time consumption, asynchronous memory recovery time consumption 1, asynchronous memory recovery time consumption 2, and asynchronous memory recovery time consumption 3 are all related parameters that characterize the time consumption in the memory recovery process, which will not be introduced in detail here; the first column of data represents various statistical items, the second column of data represents the data obtained by statistics of this application scheme, the third column of data represents the data obtained by statistics of related technologies, and the fourth column of data represents the percentage change of data of this application scheme relative to the related technology.
[0242] It can be seen intuitively from the above table that compared with the related technology, the direct memory recovery time of this application solution is reduced by about 35%. This part of the time is reflected in the time consumed by synchronous waiting when the process applies for memory; the asynchronous memory recovery time 1 (kswapd) is reduced by about 24%, which can reduce the power consumption of kswapd; the total time is reduced by about 23%.
[0243] In one embodiment of the present application, when performing the above Figure 1 In the illustrated embodiment, before step S101 , it may be determined whether the memory reclamation demand is an urgent memory reclamation demand. If not, step S101 is executed.
[0244] When the memory reclamation demand is an urgent memory reclamation demand, it means that the remaining memory capacity is seriously insufficient. The current memory demand is urgent and the reclamation pressure is high. Memory pages need to be reclaimed as soon as possible for use.
[0245] If the memory recycling demand is not an emergency memory recycling demand, it means that the remaining memory capacity is still relatively sufficient, the current memory demand is not urgent, and the recycling pressure is relatively small. At this time, the solution provided in the embodiment of the present application can be adopted to improve the recycling efficiency of the memory page, thereby improving the rationality of the solution.
[0246] If the memory reclamation demand is an urgent memory reclamation demand, in order to reclaim the memory pages as quickly as possible for use, a solution of related technology may be adopted, that is, reclaiming the memory pages in sequence.
[0247] Specifically, whether the memory reclamation requirement is an urgent memory reclamation requirement can be determined based on the following conditions:
[0248] Condition 1: The urgency of the memory reclamation requirement is greater than the preset urgency.
[0249] The urgency of memory reclamation requirements can be called the priority of the operating system kernel when performing this reclamation. The value range of priority is [0,12]. The smaller the value, the higher the urgency and the greater the reclamation pressure.
[0250] When this condition is met, it indicates that the current memory demand is relatively urgent. Therefore, the memory reclamation demand can be determined as an urgent memory reclamation demand.
[0251] Condition 2: The remaining memory capacity is less than the preset capacity threshold.
[0252] The preset capacity threshold may be a low watermark. When the remaining memory capacity is less than the preset capacity threshold, it indicates that the current remaining memory capacity is already relatively tight. Therefore, the memory reclamation demand may be determined to be an urgent memory reclamation demand.
[0253] Condition 3: The remaining memory capacity is less than the preset capacity threshold.
[0254] A length ratio between the second memory page linked list and the first memory page linked list is greater than a preset ratio threshold.
[0255] When the above length ratio is greater than the preset ratio threshold, it indicates that there are more active memory pages and fewer inactive memory pages, and it is difficult to add new memory pages to the first memory page linked list, that is, the linked list has become unbalanced. At this time, it can be determined that the memory reclamation demand is an urgent memory reclamation demand.
[0256] It should be noted that the memory recovery demand can be determined to be an urgent memory recovery demand when any one of the above conditions 1-3 is met. This relaxes the judgment conditions for the urgent memory recovery demand, which is conducive to timely jumping out of the plan when the memory recovery demand is more urgent, thereby improving the rationality of the memory recovery plan; the memory recovery demand can also be determined to be an urgent memory recovery demand when any two of the above conditions 1-3 are met; the memory recovery demand can also be determined to be an urgent memory recovery demand when all conditions 1-3 are met. In this way, the judgment conditions for the urgent memory recovery demand are stricter, that is, the plan is jumped out only when the urgency of the memory recovery demand is high, taking into account both memory recovery efficiency and actual needs.
[0257] In this way, multiple conditions can be used to determine whether the memory reclamation demand is an urgent memory reclamation demand from multiple dimensions, thereby improving the accuracy and rationality of the judgment.
[0258] In one embodiment of the present application, when performing the above Figure 1 In the illustrated embodiment, before step S101 , it may be determined whether the difference between the number of memory pages included in the inactive first memory page linked list and the target recycling number is greater than a preset number. If so, step S101 is executed.
[0259] When the difference between the number of memory pages and the target recycling number is large, a small number of memory pages in the first memory page linked list need to be recycled. In this case, the solution provided in the embodiment of the present application can be adopted to select memory pages with lower recycling costs for recycling, so as to improve the recycling efficiency of memory pages and improve the rationality of the solution.
[0260] When the difference between the number of memory pages and the target recycling number is small, most of the memory pages in the first memory page linked list need to be recycled. In this case, it is not meaningful to select memory pages from the linked list for recycling.
[0261] For example, if the number of memory pages is the same as the target recycling number, then all memory pages in the first memory page linked list must be recycled. In this case, it is meaningless to select memory pages from the linked list for recycling.
[0262] Therefore, when the difference between the number of memory pages and the target recycling number is small, the solution of the related technology can be used to perform memory recycling, that is, recycling memory pages in sequence.
[0263] The user information involved in the embodiments of this application is all information authorized by the user. The acquisition, storage, use, processing, transmission, provision and disclosure of user information comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0264] In a specific implementation, the present application further provides a computer storage medium, wherein the computer storage medium may store a program, wherein when the program is executed, the device containing the computer-readable storage medium is controlled to perform some or all of the steps in the above embodiment. The above storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0265] In a specific implementation, an embodiment of the present application further provides a computer program product, which includes executable instructions. When the executable instructions are executed on a terminal, the terminal executes some or all of the steps in the above method embodiment.
[0266] In a specific implementation, the embodiment of the present application further provides a terminal, including:
[0267] like Figure 11 As shown, the present application also provides a chip system, which is applied to the terminal 100, and the chip system includes one or more processors 1101. The processor 1101 is used to call computer instructions so that the terminal 100 inputs the data to be processed into the chip system, and the chip system performs memory recovery based on the memory recovery method provided in the embodiment of the present application.
[0268] In one possible implementation, the chip system further includes input and output interfaces for inputting and outputting data.
[0269] The various embodiments of the mechanisms disclosed in this application can be implemented in hardware, software, firmware, or a combination of these implementation methods. The embodiments of the present application can be implemented as a computer program or program code executed on a programmable system, which includes at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device.
[0270] Program code can be applied to input instructions to perform the functions described herein and generate output information. The output information can be applied to one or more output devices in a known manner. For the purposes of this application, a processing system includes any system having a processor such as, for example, a digital signal processor (DSP), a microcontroller, an application specific integrated circuit (ASIC), or a microprocessor.
[0271] Program code can be implemented with a high-level programming language or an object-oriented programming language to communicate with the processing system. Where necessary, program code can also be implemented in assembly language or machine language. In fact, the mechanism described in this application is not limited to the scope of any particular programming language. In either case, the language can be a compiled language or an interpreted language.
[0272] In some cases, the disclosed embodiments can be implemented in hardware, firmware, software or any combination thereof. The disclosed embodiments can also be implemented as instructions carried or stored on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which can be read and executed by one or more processors. For example, instructions can be distributed over a network or by other computer-readable media. Therefore, machine-readable media can include any mechanism for storing or transmitting information in a machine (e.g., computer) readable form, including but not limited to, floppy disks, optical disks, optical disks, compact disc read-only memories (Compact Disc Read Only Memory, CD-ROMs), magneto-optical disks, read-only memories, random access memories, erasable programmable read-only memories (Erasable Programmable Read Only Memory, EPROM), electrically erasable programmable read-only memories (Electrically Erasable Programmable Read Only Memory, EEPROM), magnetic cards or optical cards, flash memory, or tangible machine-readable memories for transmitting information (e.g., carrier waves, infrared signal digital signals, etc.) using the Internet in electrical, optical, acoustic or other forms of propagation signals. Accordingly, machine-readable media includes any type of machine-readable media suitable for storing or transmitting electronic instructions or information in a form readable by a machine (eg, a computer).
[0273] In the accompanying drawings, some structural or method features may be shown in a particular arrangement and / or order. However, it should be understood that such a particular arrangement and / or order may not be required. Rather, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the accompanying drawings. In addition, the inclusion of a structural or method feature in a particular figure does not imply that such a feature is required in all embodiments, and in some embodiments, such features may not be included or may be combined with other features.
[0274] It should be noted that the units / modules mentioned in the various device embodiments of the present application are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, or a part of a physical unit / module, or can be implemented as a combination of multiple physical units / modules. The physical implementation of these logical units / modules themselves is not the most important. The combination of functions implemented by these logical units / modules is the key to solving the technical problems raised by this application. In addition, in order to highlight the innovative part of this application, the above-mentioned device embodiments of this application do not introduce units / modules that are not closely related to solving the technical problems raised by this application. This does not mean that other units / modules do not exist in the above-mentioned device embodiments.
[0275] It should be noted that in the examples and description of this patent, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "including a" does not exclude the presence of other identical elements in the process, method, article or device that includes the element.
[0276] Although the present application has been shown and described with reference to certain preferred embodiments thereof, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the application.
Claims
1. A memory recovery method, characterized in that: The method comprises: Starting from a starting memory page of the inactive first memory page linked list, based on the target recycling quantity, first memory pages whose recycling cost representation values are less than or equal to the first recycling cost limit value are determined one by one, wherein the memory pages included in the first memory page linked list are: memory pages that are eliminated from the memory pages recorded in the active second memory page linked list and whose recycling cost representation values are less than or equal to the second recycling cost limit value; the maximum number of the first memory pages is the target recycling quantity; and the recycling cost representation values are determined based on the number of virtual memory areas (VMAs) that have a mapping relationship with the memory pages; Determine a first VMA that has a mapping relationship with each first memory page; Determine a first mapping page table corresponding to the first process to which each first VMA is allocated; Release the mapping relationship between the first memory page and the first VMA stored in each first mapping page table, and delete each first memory page from the first memory page linked list; The method further comprises: If the determined number of first memory pages is less than the target recycling number, increasing the first recycling cost limit value; Return to the step of starting from the starting memory page of the inactive first memory page linked list and determining, based on the target recycling quantity, first memory pages whose recycling cost representation values are less than or equal to the first recycling cost limit value one by one.
2. The method according to claim 1, characterized in that The increasing the first recovery cost limit value includes: A first step length is added to the first recovery cost limit value to obtain an increased first recovery cost limit value.
3. The method according to claim 2, characterized in that The first step length is: A preset step value; or A step value is determined based on the determined number of first memory pages and the target recycling number.
4. The method according to any one of claims 1 to 3, characterized in that The recycling cost representation value is: The number of VMAs that are mapped to memory pages; or The predicted value of the reclaim duration is determined based on the number of VMAs that are mapped to the memory page.
5. The method according to any one of claims 1 to 3, characterized in that The method further comprises: Determine whether the memory reclamation demand is an urgent memory reclamation demand; If not, the step of starting from the starting memory page of the inactive first memory page linked list and determining, based on the target recycling quantity, first memory pages whose recycling cost representation values are less than or equal to the first recycling cost limit value one by one is executed.
6. The method according to claim 5, characterized in that The determining whether the memory reclamation demand is an urgent memory reclamation demand includes: Determine whether the memory reclamation request is an urgent memory reclamation request based on at least one of the following conditions: The urgency of memory reclamation demand is greater than the preset urgency; The remaining memory capacity is less than the preset capacity threshold; A length ratio between the second memory page linked list and the first memory page linked list is greater than a preset ratio threshold.
7. The method according to any one of claims 1 to 3, characterized in that The method further comprises: Determining whether a difference between the number of memory pages included in the inactive first memory page linked list and a target recycling number is greater than a preset number; If yes, execute the step of starting from the starting memory page of the inactive first memory page linked list and determining, based on the target recycling quantity, the first memory pages whose recycling cost representation values are less than or equal to the first recycling cost limit value one by one.
8. A terminal, characterized in that: include: one or more processors and memory; The memory is coupled to the one or more processors, and is configured to store computer program codes, where the computer program codes include computer instructions. The one or more processors invoke the computer instructions to enable the terminal to execute the method according to any one of claims 1 to 7.
9. A computer-readable storage medium, characterized in that The method comprises a computer program, which, when executed on a terminal, causes the terminal to execute the method according to any one of claims 1 to 7.
10. A computer program product, characterized in that The computer program product comprises executable instructions, and when the executable instructions are executed on a terminal, the terminal is caused to perform the method according to any one of claims 1 to 7.
11. A chip system, characterized in that: The chip system is applied to a terminal, and the chip system includes one or more processors, which are used to call computer instructions to enable the terminal to input data into the chip system and execute the method described in any one of claims 1 to 7 to perform memory recovery.
Citation Information
Patent Citations
Memory recycle method and device for mobile terminal
CN108563506A
Memory optimization method, electronic equipment and storage medium
CN117171062A