Memory recovery method, terminal, storage medium and program product
By starting from the memory page starting from the inactive memory page linked list in the terminal device, the mapping relationship between the memory page and the virtual memory area is determined and decomposed one by one, and priority is given to the recycling of memory pages with lower costs, which solves the problem of low memory recycling efficiency and realizes the More efficient memory supply.
Patent Information
- Application Number
- CN202410483400.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-22
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2044-04-22
AI Technical Summary
In terminal devices, the problem of low memory recycling efficiency, especially when there is a mapping relationship between one memory page and multiple virtual memory areas, the time to unmap relationship is longer, resulting in low memory recycling efficiency.
Starting from the memory pages in the inactive memory page linked list, the memory pages whose recovery cost representation value is less than or equal to the recovery cost limit value are determined one by one, and the mapping relationship with the virtual memory area is unblocked, so that the recovery cost is preferred is smaller. memory pages to improve memory recycling efficiency.
It reduces the computing resources and time costs during memory recycling, improves the memory supply speed, and ensures the efficiency and rationality of memory recycling.
Smart Images

Figure CN119248664A_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, a terminal, a storage medium and a program product. Background Art
[0002] When an application installed in a terminal such as a mobile phone or tablet computer is running, 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 page of the 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 the physical memory.
[0003] Among them, the capacity of physical memory is limited. In the case of memory shortage, if there is a new memory demand, the operating system needs to reclaim memory, that is, to release the mapping relationship between memory pages and VMA. In this way, the memory pages with the demapped relationship are recycled and can be used to meet the above memory demand.
[0004] However, in some cases, a memory page may be mapped to more VMAs. When reclaiming such a memory page, the mapping relationship between the memory page and more VMAs needs to be released, which takes a long time and results in low efficiency of memory reclaim. 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 the 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 whose recycling cost representation values are less than or equal to the second recycling cost limit value and which are eliminated from the memory pages recorded in the active second memory page linked list, the maximum number of the first memory pages is the target recycling quantity, and the recycling cost representation value is 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 pages 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 the scheme provided by the embodiment of the present application is applied for memory recycling, starting from the starting memory page of the inactive first memory page linked list, the first memory pages whose recycling cost characterization 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, so that 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, and 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 spent on recycling memory pages, and the memory pages with recycling cost characterization values less than the first recycling cost limit value are memory pages with smaller recycling costs. It can be seen that the scheme provided in 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 recycling memory, memory pages with smaller recycling costs can be preferentially selected for recycling, which is beneficial overall to ensure that the memory pages finally recycled are all memory pages with smaller recycling costs, reducing the computing resource cost and time cost spent on memory recycling, improving the efficiency of memory recycling, and speeding up 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 characterization 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, indicating 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 condition when determining the first memory page. In this way, when returning to execute the memory recycling process, it is beneficial to determine more first memory pages based on the increased first recycling cost limit value, thereby facilitating the determination of the first memory pages whose number meets the target recycling number, thereby ensuring that this memory recycling can meet the memory recycling demand.
[0017] In one embodiment of the present application, increasing the first recovery 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 preset, and there is no need to execute 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 scheme.
[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 recovery number can reflect the gap between the recovery cost representation value of the memory page and the first recovery cost limit value, and then can reflect the recovery difficulty of memory recovery according to the current first recovery cost limit value. According to the above recovery difficulty, the first step length for increasing the first recovery 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 intuitively and accurately reflected 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, the 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, the determining whether the memory reclamation requirement is an urgent memory reclamation requirement includes:
[0033] Based on at least one of the following conditions, determine whether the memory reclamation demand is an urgent memory reclamation demand:
[0034] The urgency of memory recycling 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 judge 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] Determine 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;
[0040] If yes, 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 is executed.
[0041] When the difference between the number of memory pages and the target recycling number is large, a small portion of the 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 the 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 the memory is used to store computer program codes, where the computer program codes include 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, including 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, and the chip system includes one or more processors, and the processor is used to call computer instructions so that the terminal inputs data into the chip system and executes the method described in the first aspect to recycle memory.
[0048] The beneficial effects of the solutions provided by the embodiments in the second to fifth aspects can refer 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 drawings required for use in the embodiments will be briefly introduced below. 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 paying creative labor.
[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 block 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 schematic diagram of a process flow of a first memory recovery method provided in an embodiment of the present application;
[0054] Figure 5 A schematic diagram of a first memory recycling process provided in an embodiment of the present application;
[0055] Figure 6 A schematic diagram of a second memory recycling method provided in an embodiment of the present application;
[0056] Figure 7 A schematic diagram of a process flow of a third memory recycling method provided in an embodiment of the present application;
[0057] Figure 8 A schematic diagram of a second memory recycling process provided in an embodiment of the present application;
[0058] Fig. 9 A schematic diagram of a memory recycling process in the related art;
[0059] Fig.10a A schematic diagram of a first memory page linked list provided in an embodiment of the present application;
[0060] Fig.10b A schematic diagram of a second memory page linked list provided in an embodiment of the present application;
[0061] Fig.10c A schematic diagram of a third memory page linked list provided in an embodiment of the present application;
[0062] Fig.10d A schematic diagram of a fourth memory page linked list provided in an embodiment of the present application;
[0063] Fig.11 A schematic diagram of the structure 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, the words "first" and "second" are used to distinguish the same items or similar items with substantially the same functions and effects. For example, the first instruction and the second instruction are to distinguish different user instructions, and their order is not limited. Those skilled in the art can understand that the words "first" and "second" do not limit the quantity and execution order, and the words "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 as "exemplarily" or "for example" in this application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplarily" or "for example" is intended to present related concepts in a specific way.
[0067] The solution provided in the embodiments of the present application can be applied to mobile phones, tablet computers, desktop computers, smart watches, wearable electronic devices, augmented reality (AR) equipment, virtual reality (VR) equipment, vehicle-mounted equipment, smart cars, robots and other terminals.
[0068] For example, Figure 1 The schematic diagram of the structure of the terminal 100 is shown. The terminal 100 may include a processor 110, a display screen 120, a camera 130, an internal memory 140, a subscriber identification module (Subscriber Identification Module, SIM) card interface 150, a universal serial bus (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, etc. The sensor module 180 may include a pressure sensor 180A, a fingerprint sensor 180B, a touch sensor 180C, an ambient light sensor 180D, etc.
[0069] It is to be understood that the structure illustrated in the embodiment of the present application does 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 in the figure, or combine certain components, or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[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 processor (NPU), etc. Among them, 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. Among them, the controller may generate an operation control signal according to the instruction opcode and the timing signal to complete the control of fetching and executing instructions. In some other embodiments, a memory may also be set in the processor 110 for storing instructions and data. Exemplarily, the memory in the processor 110 may be a high-speed cache memory. The memory may store instructions or data that the processor 110 has just used or circulated. If the processor 110 needs to use the instruction or data again, it can be directly called from the memory. This avoids repeated access and reduces the waiting time of the processor 110, thereby improving 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 interface may include an Inter-Integrated Circuit (I2C) interface, an Inter-Integrated Circuit Sound (I2S) interface, a Pulse Code Modulation (PCM) interface, a Universal Asynchronous Receiver / Transmitter (UART) interface, a Mobile Industry Processor Interface (MIPI), a General-Purpose Input / Output (GPIO) interface, a SIM card interface and / or a USB interface, etc. Among them, the USB interface 160 is an interface that complies with the USB standard specification, and may specifically be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 160 may be used to connect a charger to charge the terminal 100, and may also be used to transmit data between the terminal 100 and a peripheral device. The USB interface 160 may also be used to connect headphones to play audio through the headphones.
[0072] It is understandable that the interface connection relationship between the modules illustrated in the embodiment 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 in 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 the utilization of the antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0075] The terminal 100 implements the display function through a GPU, a display screen 120, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 120 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs, which execute program instructions to generate or change 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), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. 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 is made of materials such as OLED, AMOLED, FLED, etc., the above Figure 1 The display screen 120 in the embodiment can be bent. Here, the display screen 120 can be bent means that the display screen can be bent to any angle at any position and can be kept at the 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 for their unique characteristics and great potential. Compared with traditional screens, flexible screens are flexible and bendable, which can provide users with a new interaction method based on the bendable characteristics, and can meet more user demands for the terminal. For a terminal equipped with a foldable display screen, the foldable display screen 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 foldable displays more and more frequently.
[0079] The terminal 100 can realize the shooting function through the ISP, the camera 130, the video codec, the GPU, the display screen 120 and the application processor, etc., wherein the camera 130 includes a front camera and a rear camera.
[0080] The ISP is used to process the data fed back by the camera 130. For example, when shooting, the shutter is opened, and light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing and converts it into an image visible to the naked eye. The ISP can perform algorithm optimization on the noise, brightness and color of the image. The ISP can also optimize the exposure and color temperature of the shooting scene and other parameters. In some embodiments, the ISP can be set in 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 transmits the electrical signal to the ISP to convert it 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, and can process not only digital image signals but also other digital signals. For example, when the terminal 100 is selecting 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 videos. Terminal 100 may support one or more video codecs. Thus, terminal 100 may play or record videos in multiple coding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, and MPEG4.
[0084] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of the terminal 100 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.
[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 executes 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. Among them, the program storage area can store an operating system; the program storage area can also store one or more applications (such as a gallery, contacts, etc.). The data storage area can store data (such as photos, contacts, etc.) created during the use of the terminal 100. 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, flash memory components, universal flash memory (Universal Flash Storage, UFS), etc. In some embodiments, the processor 110 can execute the memory recovery method provided in the embodiment of the present application, as well as other applications and data processing by running instructions stored in the internal memory 140 and / or instructions stored in a 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] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 120. There are many types of pressure sensors 180A, for example, they can be resistive pressure sensors, inductive pressure sensors or capacitive pressure sensors. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When the force acts on the pressure sensor 180A, the capacitance between the electrodes changes, and the terminal 100 determines the intensity of the pressure according to the change in capacitance. When the touch operation acts on the display screen 120, the terminal 100 detects the touch operation according to the pressure sensor 180A. The terminal 100 can also calculate the position of the touch according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on a short message application icon, an instruction to view the short message is executed; when a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on a short message application icon, an instruction to create a new short message is executed.
[0089] The fingerprint sensor 180B is used to collect fingerprints. The terminal 100 can use the collected fingerprint characteristics to realize functions such as unlocking, accessing application locks, taking pictures, and answering calls.
[0090] The touch sensor 180C is also called a touch control device. The touch sensor 180C can be arranged on the display screen 120, and the touch sensor 180C and the display screen 120 form a touch screen, which is also called a touch control screen. The touch sensor 180C is used to detect a touch operation acting on or near it. The touch sensor 180C can pass the detected touch operation to the application processor to determine the type of touch event. A visual output related to the touch operation can be provided through the display screen 120. In other embodiments, the touch sensor 180C can also be arranged on the surface of the terminal 100, and is arranged at a different position from the display screen 120.
[0091] The ambient light sensor 180D is used to sense the ambient light brightness. The terminal 100 can adaptively adjust the brightness of the display screen 120 according to the perceived ambient light brightness. The ambient light sensor 180D can also be used to automatically adjust the white balance when shooting. The ambient light sensor 180D can also transmit the environment information of the device to the GPU.
[0092] The ambient light sensor 180D is also used to obtain the brightness, light ratio, color temperature, etc. of the environment in which the camera 130 captures images.
[0093] Figure 2The software structure diagram of the terminal applicable to the embodiment of the present application is shown in FIG. The software system of the terminal can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture.
[0094] The layered architecture divides the terminal's software system into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the software system can be divided into five layers, namely, application layer (applications), application framework layer (application framework), system library, hardware abstraction layer (HAL) and kernel layer (kernel).
[0095] The application layer can include a series of application packages. 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, etc.
[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 may include multiple library modules, such as display library modules and motor library modules. The terminal system may 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 may load the corresponding library modules for the camera, thereby enabling the camera application to access the camera.
[0099] The kernel layer is a layer between hardware and software. The kernel layer is deployed with an operating system for driving the hardware to make the hardware work. The kernel layer at least includes 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 can be understood that the display driver, the camera driver, the sensor driver, and the motor driver, etc. can all be regarded 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 recovery indication and execute the memory recovery 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 the 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 are 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 respond to the process's memory application request and allocate VMA for the process. VMA can be understood as an abstraction of a continuous linear address space. There is a mapping relationship between VMA and the memory page of physical memory. The above mapping relationship is saved 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 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] It can be seen that for processes 1-3, the operating system allocates VMAs to each of the three processes: VMA1 and VMA4 are allocated to process 1, VMA2 is allocated to process 2, and VMA3 is allocated to process 3. Among them, the VMA that has a mapping relationship with memory page 1 is VMA4, the VMAs that have a mapping relationship with memory page 2 are VMA5-VMA6, and the VMAs that have a mapping relationship with memory page 3 are VMA1-VMA3.
[0116] Then, for process 1, VMA1 and VMA4 are allocated, and 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 , is a flow chart of the first memory recovery method provided in an embodiment of the present application, the method includes the following steps S401-S404.
[0119] Step S401: starting from the 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.
[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, and when it is determined 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 recycling indication may be generated.
[0123] The above target recycling quantity is the quantity of memory pages that need to be recycled this time, which is 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 recycling indication may directly carry the target recycling number of memory pages that need to be recycled this time.
[0126] In another implementation, the memory recycling indication may carry the target memory capacity to be recycled this time, so that the target recycling quantity of the memory page can 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 can be calculated, and the calculated result can be rounded up and added to 1 as the target recycling quantity of the memory page.
[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 the 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 inventor has found through practice that the more VMAs that are mapped to a memory page, the longer it takes to recycle the memory page. Therefore, the number of VMAs that are mapped to a memory page can more conveniently and accurately reflect the recycling cost of the memory page, thereby improving the accuracy of the recycling cost representation value obtained.
[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 intuitively and accurately reflected from the perspective of the memory page recycling time.
[0133] The first recovery cost limit value is introduced below.
[0134] In one implementation, the first recovery cost limit value may be preset by a staff member based on experience, and this embodiment of the present application does not limit this.
[0135] In another implementation, 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 are detailed 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: the 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 characterization 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, see the subsequent embodiments for details. In this way, the first memory page to be recycled can be selected from the first memory page linked list later.
[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. The embodiment of the present application does not limit this.
[0141] The specific method of determining the first memory page from the first memory page linked list is introduced below.
[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 values are 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 determine whether to determine the starting memory page as the first memory page according to the recycling cost representation value of the starting memory page, then determine whether to determine the starting memory page as the first memory page according to 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 is an intuitive description through the accompanying drawings.
[0144] See also Figure 5, is a schematic diagram of a 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 reclaim the memory page, 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-S402, the first memory page to be reclaimed and the first VMA having 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 facilitate the subsequent release of the mapping relationship between the first memory page and the first VMA from the first mapping page table.
[0152] Step S404: 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.
[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 respectively allocated VMA1-VMA3, 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 releasing the mapping relationship stored in the mapping page table of P1-P3, 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 recycled, or in other words, the first memory page is released. At this time, the physical memory page is successfully recycled and can be used to meet new memory requirements.
[0156] Among them, each time a first memory page is determined, the first memory page can be deleted from the first memory page linked list, or after the target number of first memory pages to be recycled is determined, each first memory page can be deleted from the first memory page linked list. The embodiment of the present application is not limited to this.
[0157] As can be seen from the above, when the scheme provided by the embodiment of the present application is applied for memory recycling, starting from the starting memory page of the inactive first memory page linked list, the first memory pages whose recycling cost characterization 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, so that 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, and 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 spent on recycling memory pages, and the memory pages with recycling cost characterization values less than the first recycling cost limit value are memory pages with smaller recycling costs. It can be seen that the scheme provided in 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 recycling memory, memory pages with smaller recycling costs can be preferentially selected for recycling, which is beneficial overall to ensure that the memory pages finally recycled are all memory pages with smaller recycling costs, reducing the computing resource cost and time cost spent on memory recycling, improving the efficiency of memory recycling, and speeding up the supply speed of memory.
[0159] according to Figure 4 As described in the illustrated embodiment, the present application also provides another memory recycling method.
[0160] See also Figure 6 , is a flow chart of a second memory recovery method provided in an embodiment of the present application, the 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 whose recycling cost representation values are less than or equal to the second recycling cost limit value are determined one by one.
[0162] This step can be executed when there is a memory recycling indication, or it can be executed according to a certain period, which is not limited in the embodiment of the present application.
[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 start 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 pages recorded in the second memory page linked list can be eliminated to the first memory page linked list first. When determining the target memory pages 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 pages with lower recovery costs 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 recorded in the second memory page linked list being eliminated to 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 whose recycling cost representation values are 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 pages with lower recycling costs in the second memory page linked list are 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 recovery cost representation value can be the number of VMAs that are mapped to the memory page, the memory page with a smaller recovery 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 preferentially eliminated to the first memory page.
[0176] The inventors have found through practice that the number of VMAs mapped to memory pages is associated with the access frequency of the memory pages, and the above number is generally positively correlated with the access frequency: 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 linked list are preferentially eliminated to the first memory page, that is, the memory pages with lower access frequency (which can be called "cold pages") in the second memory page linked list are preferentially eliminated to the first memory page, so that when the memory pages are subsequently recycled from the first memory page linked 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 On the basis of 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 is 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 a third memory recovery method provided in an embodiment of the present application, the method includes the following steps S701-S706.
[0180] Step S701: starting from the 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.
[0181] Step S702: Determine a first VMA that has a mapping relationship with each first memory page.
[0182] Step S703: Determine a 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 yes, 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 the 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 execute step S701.
[0188] Depend on Figure 4 It can be seen from the illustrated embodiment that the memory page 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 the first memory page for recycling, that is, the memory page with a smaller recycling cost will be recycled.
[0189] Then, if after one round of traversal, the number of memory pages that have been recycled is less than the target recycling number, that is, the number of memory pages that have been recycled 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. In order to be able to recycle the target recycling number of memory pages, the first recycling 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 recycling process to determine more first memory pages.
[0190] See also Figure 8 , is a schematic diagram of a 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 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 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, we continue to execute the process, 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, then 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, and F2 is continued to be judged to meet the requirements, and memory page F2 is determined as the first memory page. F3 is judged to meet the requirements, and memory page F3 is determined 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 is an introduction to the method of 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 implementation, the first step length may be a preset step length value. Specifically, it may be set by the staff based on experience, such as 1, 2, etc. In this way, the first step length is preset, and there is no need to perform the step of determining the step length. The first recovery cost limit value may be conveniently increased according to the preset step length value, thereby improving the execution efficiency of the scheme.
[0198] In another implementation manner, 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 page may be calculated, and the first step length may be determined according to a corresponding relationship between the preset difference and the step length value.
[0200] Among them, the above corresponding relationship can be that the difference value is positively correlated with the step value.
[0201] For example, larger difference values correspond to larger step values, and smaller difference values correspond to smaller step values.
[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 recovery number can reflect the gap between the recovery cost representation value of the memory page and the first recovery cost limit value, and then can reflect the recovery difficulty of memory recovery according to the current first recovery cost limit value. According to the above recovery difficulty, the first step length for increasing the first recovery cost limit value can be accurately and reasonably determined.
[0205] The first memory page is determined based on the recycling cost characterization 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, indicating 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 condition when determining the first memory page. In this way, when returning to execute the memory recycling process, it is beneficial to determine more first memory pages based on the increased first recycling cost limit value, thereby facilitating the determination of the first memory pages whose number meets the target recycling number, thereby ensuring that this memory recycling can meet the memory recycling demand.
[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 recycle the memory page. Specifically, as the number of VMAs that are mapped to a memory page increases, the time required to recycle the memory page will also increase significantly.
[0208] Set a fixed test model: start 25 applications installed in the terminal in sequence, that is, wait for 5 seconds after starting, return to the desktop and wait for 5 seconds, then start the next one, repeat 3 rounds, collect the generated test data, and get the following table based on the obtained test data:
[0209] Table 1
[0210]
[0211] The above Table 1 is a table obtained based on test data, wherein Mapcount (mapping number) refers to the number of VMAs that have a mapping relationship with a 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] According to the above table, we can see intuitively that the number of memory pages with Mapcount in the range of [1,10] (that is, the memory pages with the corresponding VMA number less than 10) accounts for about 98% of the total number of memory pages, but the recycling time of these memory pages only accounts for about 54% of the total recycling time; and the number of memory pages with Mapcount in the range of >50 (that is, the memory pages with the corresponding VMA number greater than 50) accounts for only about 1% of the total number of memory, but the recycling time of these memory pages accounts for about 27% of the total recycling time.
[0213] It can be seen that as the Mapcount corresponding to a memory page increases, the time required to recycle 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 the related technology is introduced.
[0216] When the related art performs memory recycling, it starts from the starting memory page of the inactive first memory page linked list and recycles the memory pages in sequence. The following is an intuitive description with the accompanying drawings.
[0217] See also Fig. 9 , which is a schematic diagram of a memory recycling process in the related art.
[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 prior art will first recycle F1, and then recycle the memory pages after F1, that is, recycle F2, and so on, until F11 is recycled, and it is determined that the number of recycled memory pages reaches the target recycling number, and the process ends.
[0219] Depend on Fig. 9 It can be seen intuitively that when the related technology performs memory recycling, it only recycles the memory pages in the order of the memory pages recorded in the first memory page list. In this way, if the number of VMAs mapped to the front part of the memory pages in the first memory page list increases, the recycling time will increase significantly.
[0220] In the solution provided in the embodiment of the present application, the recovery cost of the 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 solutions in the related art, this is generally beneficial in ensuring that the memory pages that are ultimately recovered are memory pages with lower recovery costs, thereby reducing the computing resource costs and time costs spent on memory recovery and improving the efficiency of memory recovery.
[0221] Combine the following 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. The first memory page linked list is as follows Fig.10a shown.
[0223] When using relevant technologies for memory recycling:
[0224] The first memory page linked list after recycling is as follows Fig.10b As shown, Fig.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 for releasing one memory page and VMA is 1, the total time cost for memory recycling by the related technology is: 1+2+6+3+8+4+2=26.
[0226] When memory is reclaimed using the solution provided in the embodiment of the present application:
[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 are recycled, such as Fig.10c shown.
[0228] It can be seen that the number of memory pages 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 performed. Among them, the memory pages in the first round of memory recycling will be deleted from the first memory page linked list. Then, the first memory page linked list after the second round of memory recycling is as follows: Fig.10d shown.
[0229] It can be seen that in the second round of memory recycling, the memory pages with 3 mapped VMAs were also recycled, and the total number of recycled memory pages reached the target recycling 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 reduced, and the memory recovery efficiency is improved.
[0232] The beneficial effects of the solution provided in the embodiments of the present application are verified by specific data below.
[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 Reverse mapping times 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 mapping times represents the number of times the mapped VMA is determined according to 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 recycling time by about 23% while reducing the recycling amount by about 6.88%. Among them, the reduction in recycling amount is the test difference, but the reduction in time consumption is much greater than the reduction in recycling amount; in addition, the scanning amount is reduced by about 10%, and the recycling efficiency (recovery amount / recycling time) is improved by about 20%; the scanning amount is reduced by about 10%, and an average of about 1.94 pages can be scanned to recover one page, 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, and 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 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 the data of the present 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 the present application scheme is reduced by about 35%. This part of the time consumption is reflected in the time consumption caused 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 consumption 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 reclaiming requirement is an urgent memory reclaiming requirement. If not, step S101 is executed.
[0244] When the memory recycling demand is an emergency memory recycling demand, it indicates that the remaining memory capacity is seriously insufficient, the memory demand is urgent, the recycling pressure is high, and the memory pages need to be recycled 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 the related technology may be adopted, that is, reclaiming the memory pages in sequence.
[0247] Specifically, whether the memory reclamation demand is an urgent memory reclamation demand 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 recycling requirements can be called the priority of the operating system kernel when performing this recycling. The value range of priority is [0,12]. The smaller the value, the higher the urgency and the greater the recycling 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] The 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 recovery demand is an urgent memory recovery 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 judge 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 portion of the 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 the 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 the present application is information that has been authorized by the user. The acquisition, storage, use, processing, transmission, provision and disclosure of the 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 where the computer readable storage medium is located is controlled to perform some or all of the steps in the above embodiment. The above storage medium may be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[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 Fig.11 As shown, the present application also provides a chip system, which is applied to a terminal 100, and the chip system includes one or more processors 1101, and 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 an embodiment of the present application.
[0268] In a possible implementation, the chip system also includes input and output interfaces for inputting and outputting data.
[0269] The various embodiments of the mechanism disclosed in the present 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 in this application 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 high-level programming language or object-oriented programming language to communicate with the processing system. When necessary, program code can also be implemented with assembly language or machine language. In fact, the mechanism described in this application is not limited to the scope of any specific 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 through 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 include 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 specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be required. Instead, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the accompanying drawings of the specification. In addition, the inclusion of structural or method features in a particular figure does not mean that such features are required in all embodiments, and in some embodiments, these 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 method 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 proposed by the present application. In addition, in order to highlight the innovative part of the present application, the above-mentioned device embodiments of the present application do not introduce units / modules that are not closely related to solving the technical problems proposed by the present application, which does not mean that there are no other units / modules 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 only used 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 including 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, the elements defined by the sentence "including one" do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0276] Although the present application has been illustrated and described with reference to certain preferred embodiments thereof, it will be apparent to 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 present application.
Claims
1. A memory recovery method, characterized in that: The method comprises: Starting from the 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 whose recycling cost representation values are less than or equal to the second recycling cost limit value and which are eliminated from the memory pages recorded in the active second memory page linked list, the maximum number of the first memory pages is the target recycling quantity, and the recycling cost representation value is 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; The mapping relationship between the first memory pages 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.
2. The method according to claim 1, characterized in that 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.
3. The method according to claim 2, 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.
4. The method according to claim 3, characterized in that The first step length is: a preset step value; or The step value is determined according to the determined number of first memory pages and the target recycling number.
5. The method according to any one of claims 1 to 4, 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.
6. The method according to any one of claims 1 to 4, 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, the 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.
7. The method according to claim 6, characterized in that The determining whether the memory reclamation demand is an urgent memory reclamation demand includes: Based on at least one of the following conditions, determine whether the memory reclamation demand is an urgent memory reclamation demand: The urgency of memory recycling 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.
8. The method according to any one of claims 1 to 4, characterized in that The method further comprises: Determine 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 yes, 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 is executed.
9. A terminal, characterized in that: include: one or more processors and memory; The memory is coupled to the one or more processors, and the memory is used to store computer program codes, where the computer program codes include computer instructions. The one or more processors call the computer instructions to enable the terminal to execute the method according to any one of claims 1 to 8.
10. 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 8.
11. 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 execute the method according to any one of claims 1 to 8.
12. A chip system, characterized in that: The chip system is applied to a terminal, and the chip system includes one or more processors, and the processor is used to call computer instructions so that the terminal inputs data into the chip system and executes the method described in any one of claims 1 to 8 to perform memory recovery.
Citation Information
Patent Citations
Memory recycle method and device for mobile terminal
CN108563506A
Memory recovery method and device, storage medium and electronic equipment
CN111274039A
Method for determining memory recovery threshold and related equipment
CN114168490A
File page processing method and related device
CN114968543A
Stream computing system, memory recovery method for stream computing system and computing device
CN116610444A
