A memory management method and terminal device
By retaining commonly used memory pages and migrating unused pages when mobile applications are hot-started, the problem of unreleased memory occupied by background applications is solved, the application's survival performance and user experience are improved, and efficient memory management is achieved.
Patent Information
- Application Number
- CN202010367180.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-04-30
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2040-04-30
AI Technical Summary
Mobile applications occupy memory that is not released when switching to the background, causing the system to kill processes or compress memory for background applications, resulting in reduced application ability to keep alive, lags, and user data loss. Traditional page replacement algorithms cannot accurately screen hot and cold. page, resulting in low memory recovery efficiency.
By using memory compression and swap operations during application hot startup, we determine and retain commonly used memory pages in the memory, migrate unused memory pages to the swap partition of the memory, and use page exception interrupt programs and marking mechanisms to accurately filter out application startup and commonly used memory pages to avoid hot and cold page identification based on long-term historical information.
It improves the performance of background applications when they are started again, reduces lagging, improves the application's survival performance and user experience, and at the same time saves memory resources and expands memory space.
Smart Images

Figure CN113590500B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal technology, and in particular to a memory management method and a terminal device. Background Art
[0002] At present, the types and number of mobile applications have increased dramatically, and the demand for memory of these applications has expanded year by year, which conflicts with the limited and expensive memory resources of mobile devices. When an application is switched to the background, the memory it occupies is not actually released. In order to meet the memory requirements of the newly started application, the system will kill the process or perform memory compression operations on the background application. However, excessive process killing will lead to the problem of reduced application survival ability, causing a series of side effects, such as re-entering the advertising interface when the background application is started again, slow startup speed, and loss of user history data. Memory compression is another means of reclaiming memory resources. By compressing the memory pages in the memory, a part of the memory space can be saved. However, memory compression essentially consumes central processing unit (CPU) resources in exchange for memory resources, which has computing resource overhead, and the memory compression operation has a limit on the compression rate.
[0003] At present, there is another way to save memory resources. This method can use storage resources such as UFS (UNIX file system) to open a swap partition for memory use. When the memory is tight, some memory pages in the memory are migrated to the swap partition to save memory resources. The traditional page replacement algorithm is based on the kernel LRU (least recently used) linked list to recycle memory pages. Specifically, the system maintains an active linked list and an inactive linked list. Memory pages that have not been used for a long time are considered to be cold pages and are placed in the inactive linked list, while frequently used memory pages are considered to be hot pages and are placed in the active linked list. When performing memory recycling, that is, performing a swap operation, the cold pages in the inactive linked list are swapped out first. However, this page replacement algorithm has two defects. First, it takes a long time to determine the cold pages and hot pages, and it is impossible to actively screen out the cold pages and hot pages in a short time; second, it is not completely accurate to use the length of time as the criterion for determining the cold pages and hot pages. When the application is switched back to the foreground, there will still be a freeze problem. Summary of the invention
[0004] The present application provides a memory management method and a terminal device, which are used to accurately determine the commonly used memory pages required for application startup and use, and when the target running application is switched to background operation, the commonly used memory pages are retained in the memory, thereby improving the problem of lag when the background running application is started again and improving the application's activity retention performance.
[0005] In the first aspect, an embodiment of the present application provides a memory management method, which can be applied to a terminal device, and the method includes: when a target running application is hot-started, the terminal determines that an application running in the background is the target running application; when the target running application is hot-started, the terminal determines the commonly used memory pages of the target running application based on the memory pages in which page exceptions occur in the target running application; finally, after the target running application switches to background operation, the terminal retains the commonly used memory pages in the memory, and swaps the uncommonly used memory pages from the memory to the swap partition of the storage.
[0006] In the embodiment of the present application, on the one hand, the method can utilize the memory pages where page exceptions occur in the target running application to determine the commonly used memory pages required for application startup and use, and the terminal retains the memory pages required for application startup and use in the memory, thereby improving the problem of freezing when the application running in the background is started again and improving the activity retention performance of the application. On the other hand, the method can accurately screen out the uncommonly used memory pages other than the commonly used memory pages, that is, the uncommonly used memory pages that need to be migrated to the swap partition, and the terminal migrates the uncommonly used memory pages to the swap partition of the memory to save memory resources.
[0007] In a possible design, the system kernel of the terminal determines the application running in the background as the target application, or the system kernel of the terminal determines the target running application according to the identifier of the application set by the user.
[0008] In one possible design, the target running application is hot-started when the target running application switches from background running to foreground running. The starting time corresponding to the hot-start of the target running application can be the first moment when the process of the target running application switches from background running to foreground running. The system kernel of the terminal can use the time period corresponding to the second time length after the first moment as the time period corresponding to the hot-start process. The second time length can be a set threshold or can be determined based on the status information of the target running application.
[0009] In a possible design, assuming that the target running application in the terminal switches from foreground running to background running, the system kernel of the terminal compresses all or part of the memory pages of the application through a memory compression operation. When the target running application is hot started, when the target running application is decompressed, the decompressed memory pages in the target running application are determined as the common memory pages of the target running application.
[0010] In an embodiment of the present application, the terminal utilizes the decompression operation when the application is hot-started to determine the commonly used memory pages required for application startup and use from the compressed data. That is, by utilizing the existing kernel mechanism of memory compression and decompression, it is possible to accurately and actively screen out commonly used pages for application startup and use, and there is no need to identify hot and cold pages based on long-term historical information. The memory pages required for application startup and use are retained in the memory, thereby improving the problem of freezes when the application running in the background is started again, improving the activity retention performance of the application, and improving the user experience to a certain extent.
[0011] In one possible design, assuming that the target running application in the terminal switches from foreground running to background running, the terminal swaps out some memory pages in the target running application. When the target running application is hot started, when the memory pages in the target running application are swapped into the memory, the memory pages swapped into the memory in the target running application are determined as the commonly used memory pages of the target running application.
[0012] In an embodiment of the present application, the terminal utilizes the swap operation when the application is hot-started to determine the commonly used memory pages required for application startup and use. The memory pages required for application startup and use are retained in the memory, thereby improving the problem of lag when the application running in the background is started again, improving the application's activity retention performance, and improving the user experience to a certain extent.
[0013] In one possible design, assuming that the target running application in the terminal switches from foreground running to background running, the terminal demaps the memory pages in the target running application. When the target running application is hot started, the remapped memory pages in the target running application are determined as the commonly used memory pages of the target running application.
[0014] In an embodiment of the present application, the terminal utilizes the remapping operation when the application is hot-started to determine the commonly used memory pages required for application startup and use. The memory pages required for application startup and use are retained in the memory, thereby improving the problem of lag when the application running in the background is started again, improving the application's activity retention performance, and improving the user experience to a certain extent.
[0015] In one possible design, when the target running application is decompressed, the terminal can mark the decompressed memory pages in the target running application, and determine the marked memory pages as the common memory pages of the target running application; or, when the memory pages in the target running application are swapped, the memory pages swapped to the memory in the target running application are marked, and the marked memory pages are determined as the common memory pages of the target running application; or, when the memory pages in the target running application are remapped, the remapped memory pages in the target running application are marked, and the marked memory pages are determined as the common memory pages of the target running application.
[0016] In the embodiment of the present application, the terminal actively filters out the commonly used memory pages for application startup and use according to the above method, and there is no need to identify hot and cold pages based on long-term historical information. The memory pages required for application startup and use are retained in the memory, thereby improving the problem of freezing when the application running in the background is started again, improving the activity retention performance of the application, and improving the user experience to a certain extent.
[0017] In one possible design, another specific method for the terminal to determine the commonly used memory pages of the target running application based on the decompressed memory pages is: each time the target running application is hot-started, the terminal marks the decompressed memory pages in the compressed data corresponding to the target running application; the terminal determines the decompressed memory pages based on the marking information of the memory pages; when the target running application is hot-started for the Kth consecutive time, the terminal determines the memory pages that have been marked more than a set threshold as the commonly used memory pages of the target running application, and records the number of times the memory pages have been marked. In other words, the terminal determines the commonly used memory pages of the target running application by analyzing the memory pages decompressed by the target running application during multiple consecutive hot starts. Compared with the previous method, the commonly used memory pages determined by this method are more accurate.
[0018] In a possible design, each time the target running application is hot-started, the terminal updates the state of the memory page used by the process running of the target running application from a first state to a second state, wherein the first state is a state in which the memory page of the target running application is marked when the target running application switches to background running; the terminal determines the memory page used by the process running according to the second state, and records the number of times the memory page is marked as the second state;
[0019] Finally, when the target running application is hot-started for the Kth consecutive time, the terminal will mark the memory pages with a number of times greater than the set threshold as the commonly used memory pages of the target running application. In other words, the terminal determines the commonly used memory pages of the target running application by analyzing the memory pages used by the target running application during multiple hot starts. Compared with the previous method, the commonly used memory pages determined by this method are more accurate.
[0020] In a possible design, the terminal retains the frequently used memory pages in the memory, and swaps the infrequently used memory pages from the memory to the swap partition of the memory, including: the terminal performs a swap operation on the memory page of the target running application; when the memory page of the target running application is the frequently used memory page, the frequently used memory page is retained in the memory; when the memory page of the target running application is the infrequently used memory page, the infrequently used memory page is swapped from the memory to the swap partition of the memory. It can be seen that after the terminal of this method accurately screens out the infrequently used memory pages that need to be migrated to the swap partition, the terminal promptly migrates the infrequently used memory pages to the swap partition of the memory to save memory resources. In this way, the memory space can be greatly expanded. In addition, the frequently used memory pages required for application startup and use can be screened out, and the terminal retains the memory pages required for application startup and use in the memory, thereby improving the problem of freeze when the background running application is started again, and improving the activity retention performance of the application.
[0021] In one possible design, after the terminal determines the frequently used memory pages, after the target running application switches to the background running for a first time duration, the frequently used memory pages are swapped from the internal memory to the swap partition of the memory. In the embodiment of the present application, if the frequently used memory pages are not used for a long time, the terminal can still migrate the frequently used memory pages to the swap partition of the memory in time to save memory resources, and the memory space can be greatly expanded in this way.
[0022] In one possible design, before the terminal migrates the infrequently used memory pages to the swap partition of the memory, the terminal determines whether the input and output I / O of the memory is idle. When the I / O of the memory is idle, the infrequently used memory pages in the memory are migrated to the swap partition of the memory. In the embodiment of the present application, the method helps to improve the impact of the I / O overhead of the memory page swapping out stage on the terminal performance.
[0023] In a possible design, when the process of the target running application is killed, the system kernel of the terminal swaps the commonly used memory pages from the main memory to the swap partition of the storage. This method is conducive to timely release of memory space and saving memory.
[0024] In a second aspect, an embodiment of the present application provides a terminal, comprising a processor and a memory, wherein the memory is used to store one or more computer programs; when the one or more computer programs stored in the memory are executed by the processor, the terminal is able to implement any possible design method of the above-mentioned first aspect.
[0025] In a third aspect, the embodiment of the present application further provides a device, which includes a module / unit for executing any possible design method of any of the above aspects. These modules / units can be implemented by hardware, or by executing corresponding software implementations by hardware.
[0026] In a fourth aspect, a computer-readable storage medium is also provided in an embodiment of the present application, and the computer-readable storage medium includes a computer program. When the computer program runs on a terminal device, the terminal device executes any possible design method of any of the above aspects.
[0027] In a fifth aspect, an embodiment of the present application further provides a method comprising a computer program product, which, when executed on a terminal, enables the terminal device to execute any possible design of any of the above aspects.
[0028] In a sixth aspect, an embodiment of the present application further provides a chip, which is coupled to a memory and is used to execute a computer program stored in the memory to execute any possible design method of any of the above aspects. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 A schematic diagram of an application scenario provided in an embodiment of the present application;
[0030] Figure 2 A schematic diagram of the structure of a mobile phone provided in an embodiment of the present application;
[0031] Figure 3 A schematic diagram of the structure of an Android operating system provided in an embodiment of the present application;
[0032] Figure 4 A flowchart of a memory management method provided in an embodiment of the present application;
[0033] Figure 5A A schematic diagram of a memory page compression scenario provided in an embodiment of the present application;
[0034] Figure 5B A schematic diagram of a memory page swap scenario provided in an embodiment of the present application;
[0035] Figure 6 A flowchart of a memory management method provided in an embodiment of the present application;
[0036] Figure 7 A schematic diagram of another memory page swap scenario provided in an embodiment of the present application;
[0037] Figure 8 A flowchart of a memory management method provided in an embodiment of the present application;
[0038] Fig. 9 A schematic diagram of a memory management device provided in an embodiment of the present application;
[0039] Fig.10 A schematic diagram of a terminal structure provided in an embodiment of the present application. DETAILED DESCRIPTION
[0040] Below, some terms used in the embodiments of the present application are explained to facilitate understanding by those skilled in the art.
[0041] 1) The APP involved in the embodiments of the present application, referred to as application, is a software program that can realize one or more specific functions. Usually, multiple applications can be installed in a terminal device. For example, a camera application, a mailbox application, a smart home control application, etc. The application mentioned below can be a system application installed when the terminal device leaves the factory, or it can be a third-party application downloaded from the Internet or obtained from other terminal devices by the user during the use of the terminal device.
[0042] 2) Application cold start: When starting an application, there is no process of the application in the system, and the system will create a new process and assign it to the application; Application hot start: When starting an application, there is already a process of the application in the system (for example, when you press the back key or the home key, the application will exit, but the process of the application will remain in the background. Compared with the cold start of the application, the hot start of the application does not involve the process of creating a process or loading resources, so the speed of the hot start of the application is much faster than the cold start speed.
[0043] 3) Memory, the memory may be a random access memory (RAM), a read-only memory (ROM), and a cache (CACHE), etc. The swap partition of the memory described in the embodiment of the present invention belongs to the external memory, and the storage space may include a flash memory (flash), a hard disk, an optical disk, a USB disk, a floppy disk or a tape drive, etc. Computer programs are usually stored in the external memory, and the processor will load the computer program from the external memory to the internal memory before executing the processing. The application program in the embodiment of the present invention is usually stored in the external memory, and the processor needs to load the application program into the internal memory when running the application program.
[0044] 4) Memory pages. The embodiments of the present application relate to a paged storage management scheme. The paged storage management scheme divides the user process address space and the memory space into equal-sized areas of the same size, and allocates them in units of memory pages. Logically adjacent memory pages are not necessarily physically adjacent. The paging is completed by the operating system hardware and is transparent to the user.
[0045] The inventors have found that a considerable proportion of the memory pages allocated to an application will rarely be used again during the subsequent hot start and deep use of the application. Figure 1 The bar chart of memory page swapping in and out of various applications at different stages shows that the amount of memory page swapping in of various applications during the startup phase and use process is very small, while the total amount of memory page swapping out is very large. Taking the application as an example, actual testing found that the application actually requires about 600MB of memory from starting the application to completing the game, that is, a cold start process, and more than half of the data will not be used a second time. The data required for the application's hot start process is even smaller. The memory pages required to switch back from the background (non-game battle state) to the foreground (game battle state) are less than 100MB. It can be seen that various applications have accumulated a large number of memory pages that are rarely used or even no longer used in the memory. Based on this discovery, the embodiment of the present application provides a memory resource management method, which can determine the memory pages required for the application to switch back from the background to the foreground, that is, it can filter out the memory pages required for application startup and deep use (or "hot data"), and the memory pages that are not often used (or "ice data"), and retain these "hot data" in the memory, and swap the "ice data" to the swap partition of the memory. This method can ensure that the memory pages required for application startup and deep use are retained in the memory, so it can improve the jamming problem that occurs when the background application is switched back to the foreground. On the other hand, the memory pages (or "ice data") that are not often used in the application are swapped out of the memory, which can effectively save memory resources.
[0046] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0047] The various embodiments disclosed in the embodiments of the present application can be applied to terminal devices. In some embodiments, the terminal device can be a portable terminal including functions such as a personal digital assistant and / or a music player, such as a mobile phone, a tablet computer, a wearable device with wireless communication functions (such as a smart watch), a vehicle-mounted device, etc. Exemplary embodiments of portable terminals include but are not limited to a portable device equipped with a Or a portable terminal with other operating systems. The portable terminal may also be a laptop computer with a touch-sensitive surface (e.g., a touch panel). It should also be understood that in some other embodiments, the terminal may also be a desktop computer with a touch-sensitive surface (e.g., a touch panel).
[0048] Take the mobile phone as an example. Figure 2 A schematic structural diagram of a mobile phone 200 is shown.
[0049] The mobile phone 200 may include a processor 210, an external memory interface 220, an internal memory 221, a USB interface 230, a charging management module 240, a power management module 241, a battery 242, an antenna 1, an antenna 2, a mobile communication module 251, a wireless communication module 252, an audio module 270, a speaker 270A, a receiver 270B, a microphone 270C, an earphone interface 270D, a sensor module 280, a button 290, a motor 291, an indicator 292, a camera 293, a display screen 294, and a SIM card interface 295, etc. The sensor module 280 may include a touch sensor 280A (of course, the mobile phone 100 may also include other sensors, such as a gyroscope sensor, an acceleration sensor, a proximity light sensor, a fingerprint sensor, an ambient light sensor, a temperature sensor, a pressure sensor, a distance sensor, a magnetic sensor, an ambient light sensor, an air pressure sensor, a bone conduction sensor, etc., which are not shown in the figure).
[0050] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the mobile phone 200. In other embodiments of the present application, the mobile phone 200 may include more or fewer components than those shown in the figure, or combine some components, or separate some 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.
[0051] The processor 210 may include one or more processing units, for example: the processor 210 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and / or a neural network processor (Neural-network Processing Unit, NPU), etc. Among them, different processing units can be independent devices or integrated in one or more processors. Among them, the controller can be the nerve center and command center of the mobile phone 200. The controller can generate an operation control signal according to the instruction opcode and the timing signal to complete the control of fetching and executing instructions.
[0052] The processor 210 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 210 is a cache memory. The memory may store instructions or data that the processor 210 has just used or cyclically used. If the processor 210 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 210, and thus improves the efficiency of the system.
[0053] The processor 210 can run the memory management method provided in the embodiment of the present application to accurately determine the commonly used memory pages required for application startup and use, and the terminal retains the memory pages required for application startup and use in the memory, thereby improving the problem of freezing when the application running in the background is started again, improving the application's activity retention performance, and enhancing the user experience. The processor 210 can include different devices. For example, when the CPU and GPU are integrated, the CPU and GPU can cooperate to execute the memory management method provided in the embodiment of the present application, such as part of the algorithm in the memory management method is executed by the CPU, and another part of the algorithm is executed by the GPU to obtain faster processing efficiency.
[0054] The display screen 294 is used to display images, videos, etc. The display screen 294 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 mobile phone 200 may include 1 or N display screens 294, where N is a positive integer greater than 1.
[0055] The display screen 294 is connected to the backlight driver IC 294A, and the backlight driver IC 294A is used to control the backlight brightness of the display screen 294. When the processor 210 (or the coprocessor therein) implements a backlight adjustment of the display screen 294, the processor 210 converts the target backlight brightness value of this adjustment into data in a specific format and sends it to the backlight driver IC 294A. After the backlight driver IC 194A identifies the target backlight brightness value, it controls the backlight brightness change of the display screen 294 so that the backlight brightness of the display screen is adjusted to the target backlight brightness value. The data in the specific format can be a pulse width modulation (PWM). In the embodiment of the present application, the display screen 294 can be an integrated flexible display screen, or a spliced display screen composed of two rigid screens and a flexible screen located between the two rigid screens. After the processor 210 runs the memory management method provided in the embodiment of the present application, the processor 210 can control the backlight brightness on the display screen 294.
[0056] The camera 293 (a front camera or a rear camera, or one camera can be used as both a front camera and a rear camera) is used to capture still images or videos. Generally, the camera 293 may include a photosensitive element such as a lens group and an image sensor, wherein the lens group includes a plurality of lenses (convex lenses or concave lenses) for collecting light signals reflected by the object to be photographed and transmitting the collected light signals to the image sensor. The image sensor generates an original image of the object to be photographed based on the light signal.
[0057] The memory 221 generally includes a memory 221A and an external memory 221B. The memory 221A may be a random access memory (RAM), a read-only memory (ROM), and a cache (CACHE), etc. The preset storage space described in the embodiment of the present invention belongs to the external memory 221B, and the storage space may include a flash memory (flash), a hard disk, an optical disk, a USB disk, a floppy disk, or a tape drive, etc. The computer program is usually stored in the external memory 221B, and the processor will load the computer program from the external memory 221B to the memory 221A before executing the processing. The application program in the embodiment of the present invention is usually stored in the external memory, and the processor needs to load the application program into the memory when running the application program.
[0058] The external memory 221B contains a computer program that can implement the memory management method provided in the embodiment of the present application, so that after the processor 210 reads the operating system program and runs the operating system, the operating system can have the memory management function provided in the embodiment of the present application. Further, the operating system can open a calling interface of the memory management function to upper-level applications. After the processor 150 reads the application from the memory 221 and runs the application, it can call the memory management function provided in the operating system through the calling interface, thereby realizing memory management.
[0059] In addition, the internal memory 221A may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0060] Of course, the code of the memory management algorithm provided in the embodiment of the present application can also be stored in an external memory. In this case, the processor 210 can run the code of the memory management algorithm stored in the external memory through the external memory interface 220, and the processor 210 can identify the commonly used memory pages and the uncommonly used memory pages, and keep the commonly used memory pages in the memory, and migrate the uncommonly used memory pages to the swap partition of the external memory 221B.
[0061] The functions of the sensor module 280 are described below.
[0062] The touch sensor 280A is also called a "touch panel". The touch sensor 280A can be set on the display screen 294, and the touch sensor 280A and the display screen 294 form a touch screen, also called a "touch screen". The touch sensor 280A is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 294. In other embodiments, the touch sensor 280A can also be set on the surface of the mobile phone 200, which is different from the position of the display screen 294. As for other sensors such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc. that can be configured for the mobile phone 200, they are not repeated here.
[0063] The wireless communication function of the mobile phone 200 can be realized through the antenna 1, the antenna 2, the mobile communication module 251, the wireless communication module 252, the modem processor and the baseband processor.
[0064] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in mobile phone 200 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of 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.
[0065] The mobile communication module 251 can provide solutions for wireless communications including 2G / 3G / 4G / 5G applied to the mobile phone 200. The mobile communication module 251 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 251 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 251 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 251 can be set in the processor 210. In some embodiments, at least some of the functional modules of the mobile communication module 251 can be set in the same device as at least some of the modules of the processor 210.
[0066] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 270A, a receiver 270B, etc.), or displays an image or video through a display screen 294. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 210 and be set in the same device as the mobile communication module 251 or other functional modules.
[0067] The wireless communication module 252 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the mobile phone 200. The wireless communication module 252 can be one or more devices integrating at least one communication processing module. The wireless communication module 252 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and filters it, and sends the processed signal to the processor 210. The wireless communication module 252 can also receive the signal to be sent from the processor 210, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0068] In addition, the mobile phone 200 can implement audio functions through the audio module 270, the speaker 270A, the receiver 270B, the microphone 270C, the headphone interface 270D, and the application processor. For example, music playback, recording, etc. The mobile phone 200 can receive the key 290 input and generate key signal input related to the user settings and function control of the mobile phone 200. The mobile phone 200 can use the motor 291 to generate a vibration prompt (such as an incoming call vibration prompt). The indicator 292 in the mobile phone 200 can be an indicator light, which can be used to indicate the charging status, power changes, and can also be used to indicate messages, missed calls, notifications, etc. The SIM card interface 295 in the mobile phone 200 is used to connect the SIM card. The SIM card can be inserted into the SIM card interface 295, or pulled out from the SIM card interface 295, to achieve contact and separation with the mobile phone 200.
[0069] It should be understood that in actual applications, the mobile phone 200 may include Figure 1 The embodiments of the present application are not limited to the more or fewer components shown. The illustrated mobile phone 200 is only an example, and the mobile phone 200 may have more or fewer components than those shown in the figure, may combine two or more components, or may have different component configurations. The various components shown in the figure may be implemented in hardware, software, or a combination of hardware and software including one or more signal processing and / or application specific integrated circuits.
[0070] The software system of the terminal device can adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present invention takes the Android system of the layered architecture as an example to exemplify the software structure of the terminal device. Figure 3 It is a software structure block diagram of the terminal device according to an embodiment of the present invention.
[0071] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the Android runtime and system library, and the kernel layer.
[0072] The application layer can include a series of application packages.
[0073] like Figure 3 As shown, the application package may include applications such as phone, camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc.
[0074] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0075] like Figure 3 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.
[0076] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0077] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0078] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0079] The phone manager is used to provide communication functions for terminal devices, such as the management of call status (including answering, hanging up, etc.).
[0080] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0081] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, the terminal device vibrates, the indicator light flashes, etc.
[0082] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0083] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0084] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0085] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.
[0086] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.
[0087] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0088] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0089] A 2D graphics engine is a drawing engine for 2D drawings.
[0090] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0091] Combine the following Figure 4 , describes the process of a memory management method provided by an embodiment of the present application. Figure 4 As shown, the method specifically includes the following steps.
[0092] Step 401 , when the target application is hot-started, the terminal determines the common memory pages of the target running application according to the memory pages where the page exception occurs in the target running application.
[0093] Among them, in one possible implementation, the terminal can determine that the application running in the background is the target running application. Specifically, a daemon process can be set in the system kernel of the terminal, and the framework layer of the terminal operating system monitors the application foreground and background switching information. When the application running in the background is switched to the foreground, the framework layer sends a signal to the daemon process. After receiving the signal, the daemon process marks the target running application switched to the foreground. The specific marking method can be implemented by adding variables in the page structure (struct page), so that the terminal can determine that the target running application is hot-started and is running in the foreground. Among them, the starting time corresponding to the hot start of the target running application can be the first moment when the process of the target running application starts to switch from the background running to the foreground running. The system kernel of the terminal can use the time period corresponding to the second time length after the first moment as the time period corresponding to the hot start process. The second time length can be a set threshold, or it can be determined according to the state information of the target running application. For example, the state information can be the state information of the activity component (Activity) or the start completion information.
[0094] In another possible implementation, the terminal device may receive the user's settings in advance, and the terminal determines the application set by the user as the target running application. For example, the user can set WeChat through the terminal's interactive interface Applications need to perform memory management, so WeChat The application is used as the target to run the application. When WeChat When the application is hot-started, the terminal The memory page where the page exception occurs in the application, confirm WeChat Common memory pages of the application.
[0095] In the embodiment of the present application, the target running application is an application that can be switched between the foreground and the background. For example, the user opens the King of Glory app on his phone. When the app is in a battle state, if the phone calls, King of Glory will The application is switched to the background. Application runs the application as the target. For example, in WeChat When the user touches the back button or home button on the phone while the app is running, the currently running WeChat Although the app will be exited, the WeChat The application process remains running in the background. The terminal system kernel can determine the running state of the application through the running task (RunningTaskInfo) class or the running application process (RunningAppProcessInfo) class in the system, thereby determining the application running in the background.
[0096] In addition, it should be noted that the process of the application switched to the background is often not killed, but temporarily stored in the memory waiting to be switched to the foreground for use next time. Generally, when the running application is switched from the foreground to the background, the system kernel of the terminal will demap, compress or perform swap operations on the memory page of the running application. Specifically, you can refer to any of the following possible methods.
[0097] Method A: When the target application switches from the foreground to the background, the terminal system kernel usually compresses the memory pages of each process of the target application and retains the compressed memory pages in the memory. This method can effectively increase the effective memory capacity and reduce the page fault rate by compressing the memory pages, and at the same time improve the memory bandwidth utilization rate.
[0098] For example, still using King of Glory For example, the application requires about 600MB of data (number of memory pages) from the first launch of the application to the completion of the game. When an application switches from the foreground to the background, the system kernel of the mobile phone compresses the memory pages of each process of the application, for example, Figure 5A As shown, the system kernel of the terminal can compress the memory page of each running process in the memory by calling a compression algorithm such as lz4, wherein the compressed data is still retained in the memory (exemplarily, occupying Figure 5A Compared with the compressed data before compression, the memory space occupied by the compressed data (i.e. Figure 5A The compression space shown) is relatively small.
[0099] Mode B: When the target running application switches from foreground to background, the system kernel of the terminal usually performs a swap operation on the memory pages of each process of the application, that is, swaps part or all of the memory pages to the swap partition of the memory to save memory.
[0100] For example, still using King of Glory For example, the application requires about 600MB of data (number of memory pages) from the first launch of the application to the completion of the game. When an application switches from the foreground to the background, the system kernel of the mobile phone performs a swap operation on the memory pages of each process of the application, for example, Figure 5B As shown, the system kernel of the terminal swaps some memory pages of the running process in the memory, wherein the swapped memory pages are migrated to the swap partition of the memory (exemplarily, occupying Figure 5B The swap partition of the memory shown in (b) in the figure can be used to save memory.
[0101] Mode C: When the target running application switches from foreground running to background running, the system kernel of the terminal usually releases the mapping of the memory pages of each process of the application, that is, releases the mapping between the physical memory page and the virtual memory page.
[0102] For example, still using King of Glory For example, the application requires about 600MB of data (number of memory pages) from the first launch of the application to the completion of the game. When an application switches from foreground to background, the system kernel of the mobile phone demaps the memory pages of each process of the application.
[0103] In an embodiment of the present application, when the target application is hot-started, the system kernel of the terminal determines whether the memory page is mapped. If it is not mapped, it indicates that a page fault exception has occurred, thereby triggering a page exception interrupt program. The page exception interrupt program determines the memory page where the page exception occurs as a common memory page. Specifically, there are the following three ways to trigger the page exception interrupt program. The terminal device can determine the memory page where the page exception occurs in the target running application according to any one of the following three ways.
[0104] Method 1: Assuming that when the running application switches from the foreground to the background, the system kernel of the terminal will execute the processing described in method A on the memory page of the running application. When the target running application is hot-started, the system kernel of the terminal decompresses the memory page of the target running application. Because the memory page of the target running application is compressed when it switches from the foreground to the background, the system kernel of the terminal determines that the decompressed memory page is not mapped, and thus triggers the page exception interrupt program. The page exception interrupt program determines the memory page with the page exception as a common memory page, that is, the system kernel of the terminal determines the decompressed memory page in the target running application as the common memory page of the target running application.
[0105] Method 2: Assuming that when the running application switches from the foreground to the background, the system kernel of the terminal will execute the processing described in method B on the memory page of the running application. When the target running application is hot-started, the system kernel of the terminal will perform a swap operation on the memory page of the target running application, that is, swap the memory page in the memory to the memory. Because the target running application switches from the foreground to the background, the memory page of the target running application is swapped to the memory, the system kernel of the terminal determines that the memory page swapped to the memory is not mapped, and therefore triggers a page exception interrupt program. The page exception interrupt program determines the memory page with the page exception as a commonly used memory page, that is, the system kernel of the terminal determines the memory page swapped to the memory in the target running application as the commonly used memory page of the target running application.
[0106] Method three, assuming that when the running application switches from the foreground to the background, the system kernel of the terminal will execute the processing described in method C on the memory page of the running application. Then, when the target running application is hot-started, the system kernel of the terminal will remap the memory page of the target running application. Because the target running application switches from the foreground to the background, the memory page of the target running application is demapped, so the system kernel of the terminal determines that the memory page swapped to the memory is not mapped, and thus triggers the page exception interrupt program. The page exception interrupt program determines the memory page with the page exception as a commonly used memory page, that is, the system kernel of the terminal determines the memory page swapped to the memory in the target running application as the commonly used memory page of the target running application.
[0107] Step 402: After the target running application is switched to background running, the terminal retains the frequently used memory pages in the memory.
[0108] Specifically, the terminal can monitor whether the target running application is switched to the background through a daemon process. The terminal system kernel can be provided with a daemon process. The framework layer of the terminal operating system monitors the application foreground and background switching information. When the application running in the foreground is switched to the background, the framework layer sends a signal to the daemon process. After receiving the signal, the daemon process marks the target running application switched to the background. The specific marking method can be implemented by adding variables to the page structure (struct page), so that the terminal can determine that the target running application is running in the background. Then the terminal system kernel retains the commonly used memory pages in the memory.
[0109] It should be noted that, in one possible case, when the target running application is switched to the background, the system kernel of the terminal may immediately perform a memory page swap operation on the target running application. At this time, after the target running application is switched to the background, it can be understood as including the start time when the target running application starts to switch to the background, and the period after the start time. Or, in another possible case, when the target running application is switched to the background, the system kernel of the terminal may perform a memory page swap operation on the target running application after a set period of time. After the target running application is switched to the background, it can be understood as the period after the set period of time from the start time.
[0110] Step 403: The terminal determines the memory pages other than the common memory pages as the non-common memory pages of the target running application.
[0111] Specifically, after the system kernel of the terminal marks the decompressed memory pages in the target running application, the unmarked memory pages in the target running application are determined as non-usable memory pages of the target running application; or, after the system kernel of the terminal marks the memory pages swapped to the memory in the target running application, the unmarked memory pages in the target running application are determined as non-usable memory pages of the target running application; or, after the system kernel of the terminal marks the memory pages remapped in the target running application, the unmarked memory pages in the target running application are determined as non-usable memory pages of the target running application.
[0112] Step 404: after the target running application is switched to background running, the unused memory pages of the target running application are swapped from the main memory to the swap partition of the storage.
[0113] In other words, after the target running application is switched to the background operation, the system kernel of the terminal only performs swap operations on the infrequently used memory pages, and does not perform swap operations on the commonly used memory pages, that is, the commonly used memory pages are retained in the memory. In other words, after the target running application is switched to the background operation, the system kernel of the terminal only performs compression operations on the infrequently used memory pages, and does not perform compression operations on the commonly used memory pages. Alternatively, after the target running application is switched to the background operation, the system kernel of the terminal only performs swap and compression operations on the infrequently used memory pages, and does not perform swap and compression operations on the commonly used memory pages. In other words, the swap operation in the above steps can be replaced by a swap and compression operation, or a compression operation, which is not limited in the embodiments of the present application.
[0114] In a possible embodiment, if the target running application switches to background running for a duration that exceeds a first duration (e.g., two hours), the system kernel of the terminal may perform a swap operation on the commonly used memory pages, for example, swapping all or part of the memory pages from the internal memory to a swap partition of the storage, or compressing the commonly used memory pages.
[0115] In a possible embodiment, in step 404, before the system kernel of the terminal migrates the infrequently used memory pages of the target running application from the memory to the swap partition of the memory, the processor of the terminal first determines whether the I / O (input / output) of the memory is idle. If the I / O (input / output) is idle, the system kernel of the terminal will still store the infrequently used memory pages in the memory in a compressed form. Once it is determined that the I / O is idle, the infrequently used memory pages will be migrated to the swap partition of the memory.
[0116] In a possible embodiment, when the process of the target running application is killed, the system kernel of the terminal swaps the commonly used memory pages from the main memory to the swap partition of the storage to save memory.
[0117] Hereinafter, the system process of the above memory management method is further illustrated in combination with scenario one and scenario two.
[0118] Scene 1
[0119] Combination Figure 6 , describes the process of the memory management method provided in the embodiment of the present application. Figure 6 As shown, the method specifically includes the following steps.
[0120] Step 601: When the target running application switches from the foreground to the background, the terminal compresses the memory page of the target running application.
[0121] For example, still using King of Glory For example, the application requires about 600MB of data (number of memory pages) from the first launch of the application to the completion of the game. When an application switches from the foreground to the background, the system kernel of the mobile phone compresses the memory pages of each process of the application, for example, Figure 5A As shown, the system kernel of the terminal can compress the memory page of each running process in the memory by calling a compression algorithm such as lz4, wherein the compressed data is still retained in the memory (exemplarily, occupying Figure 5A Compared with the compressed data before compression, the memory space occupied by the compressed data (i.e. Figure 5A The compression space shown) is relatively small.
[0122] Step 602: When the target running application is hot-started, the terminal determines the decompressed memory pages in the target running application.
[0123] Specifically, in the kernel, each memory page has a corresponding data structure, and the embodiment of the present application can add a special mark bit in the data structure. One way for the terminal to determine the decompressed memory page can be: when the target running application is switched to the background for the first time, the system kernel of the terminal sets the special mark position to 0; when the application is hot-started, the system kernel of the terminal sets the special mark positions corresponding to all decompressed memory pages to 1. In other words, when the target running application switches from background operation to foreground operation, the system kernel of the terminal will mark the memory pages required for application startup and use. The terminal device can determine the decompressed memory page based on the marking information.
[0124] In another possible embodiment, the present application may further define a first flag bit with an attribute as an enumeration value in a corresponding data structure for each memory page. Each time the target running application is hot-started, the system kernel of the terminal increments the enumeration value corresponding to the memory page that is decompressed again, until the target running application is hot-started for the K+1th consecutive time, at which time the enumeration value of the memory page of the target running application is cleared. For example, the initial value of the first flag bit is 0. When the target running application is hot-started for the first time, if the first memory page is decompressed from the compressed data, the first flag bit corresponding to the memory page is set to 1; when the target running application is hot-started for the second time, if the first memory page is decompressed again from the compressed data, the first flag bit corresponding to the memory page is set to 2. The terminal device can determine the memory page corresponding to the first flag bit being non-0 as the decompressed memory page.
[0125] It should be noted that in actual applications, the startup methods of applications include cold start and hot start. Cold start means: the terminal does not run the relevant process of the application to be started in the background. Therefore, when starting the application, the Application class is first created and initialized, and then the MainActivity class is created and initialized (including a series of measurements, layouts, drawing, etc.), and then the relevant information of the application is output to the user. Hot start means: the terminal runs the relevant process of the application to be started in the background. Therefore, when starting the application, there is no need to create and initialize the Application class, but directly create and initialize MainActivity, and then output the relevant information of the application to the user. There are other possibilities for this preset rule, and examples are not given here one by one.
[0126] In addition, memory pages can include anonymous pages, file pages, etc., which are not limited here. Anonymous pages refer to pages without file backgrounds, such as heaps, stacks, data segments, etc.; file pages refer to pages with file backgrounds, which are caches generated in memory after the program reads the file. File pages are also called file caches. It should be noted that the compressed data includes anonymous memory pages and file memory pages generated when the target application process is running.
[0127] In this step, if the target running application is hot-started, some processes will be executed, so the memory pages related to the process in the compressed data will be decompressed. Therefore, this application can accurately and actively filter out the memory pages started and used by the application through the hot start of the application. Compared with the traditional solution of identifying hot and cold pages based on long-term historical usage information, the solution provided by this application is more timely and effective.
[0128] Step 603: The terminal determines the decompressed memory page as a common memory page of the target running application.
[0129] Among them, the first method for determining the common memory pages of the target running application may be: the terminal device determines the memory pages decompressed during the hot start as the common memory pages of the target running application.
[0130] In addition, a second method for determining the commonly used memory pages of the target running application may be: when the terminal is hot-started for the Kth consecutive time, the system kernel of the terminal determines that the memory page that has been marked more than the set threshold is a commonly used memory page based on the information of the first mark bit of the memory page. In other words, the system kernel of the terminal determines the commonly used memory page based on the memory page that was decompressed during the previous K consecutive hot starts. For example, when the target running application is hot-started for the first time, the first memory page is decompressed from the compressed data, and the first mark bit corresponding to the first memory page is set to 1. Then, when the target running application is hot-started for the second time, the first memory page is decompressed from the compressed data, and the first mark bit corresponding to the first memory page is set to 2. When the target running application is hot-started for the third time, the first memory page is not decompressed from the compressed data. Assuming that K is set to 3 and the set threshold is set to 1, the system kernel of the terminal determines the first memory page as a commonly used memory page.
[0131] It should be noted that, after the terminal device determines the commonly used memory page, the system kernel of the terminal clears the first mark bit. Continuing with the above example, after the terminal determines the first memory page as the commonly used memory page, the terminal device clears the mark bits of each memory page, and subsequently, the system kernel of the terminal continues to use the memory pages that were decompressed during the previous K consecutive hot starts to determine the commonly used memory page.
[0132] Step 604: When the target running application is switched to background running, the terminal retains the frequently used memory pages in the memory.
[0133] Specifically, the system kernel of the terminal retains the marked memory page in the memory, or retains the memory page whose first marking bit is greater than a set threshold in the memory.
[0134] In step 605, the terminal determines memory pages other than commonly used memory pages as non-common memory pages of the target running application, and when the target running application is switched to background operation, the terminal migrates the non-common memory pages of the target running application from the memory to the swap partition of the storage.
[0135] It should be noted that there is no strict execution order for the above steps 604 and 605. Step 604 may be executed first and then step 605, or step 605 may be executed first and then step 604.
[0136] Specifically, in this step, before the terminal system kernel migrates the infrequently used memory pages of the target running application from the memory to the swap partition of the memory, the terminal processor first determines whether the I / O (input / output) of the memory is idle. If the I / O (input / output) is idle, the terminal system kernel will still store the infrequently used memory pages in the memory in a compressed form. Once it is determined that the I / O is idle, the infrequently used memory pages will be migrated to the swap partition of the memory.
[0137] Combine the following Figure 7 The above memory management method is illustrated by examples. For example, Figure 7 As shown in the figure, when the application is hot started, the system kernel of the terminal decompresses the memory pages in the compressed data, and the decompressed memory pages are as follows Figure 7 As shown in (b) of FIG. 1 , the system kernel of the terminal determines that the decompressed memory page is a common memory page, and determines that the remaining memory pages in the compressed space are not common memory pages, such as Figure 7 Further, when I / O is idle, the system kernel of the terminal migrates the unused memory pages to Figure 7 In the swap partition of the memory shown in (d).
[0138] In an embodiment of the present application, a prerequisite for implementing the method is that the target running application that is switched to the background performs a memory compression operation during the process of switching to the background to save memory consumption of memory pages. In the above method, based on the characteristic that some memory pages started and used by the application are decompressed when the application is hot started, the commonly used memory pages required for application startup and use can be accurately determined. The system kernel of the terminal retains the memory pages required for application startup and use in the memory, thereby improving the problem of freezing when the background running application is started again and improving the activity retention performance of the application. On the other hand, the method can accurately screen out uncommonly used memory pages that need to be migrated to the swap partition. The terminal migrates uncommonly used memory pages to the swap partition of the memory to save memory resources. The swap partition also ensures that the data generated during the operation of the process of the target running application is not lost.
[0139] Scene 2
[0140] Combine the following Figure 8 , describes the process of the memory management method provided in the embodiment of the present application. Figure 8 As shown, the method specifically includes the following steps.
[0141] Step 801: When the target running application is switched from the foreground to the background, the terminal demaps or performs a swap operation on the memory page of the target running application.
[0142] For a specific example, please refer to the above step 401, which will not be repeated here.
[0143] Step 802: When the target running application is hot-started, the terminal determines the memory page in the target running application that is swapped into the memory, or the terminal determines the memory page in the target application that is remapped.
[0144] Specifically, in the kernel, each page has a corresponding data structure, and the embodiment of the present application can add a special mark bit in the data structure. One way for the terminal to determine the memory page used when the process is running can be: when the application is switched to the background for the first time, the system kernel of the terminal sets the special mark bit to 0; when the application is hot-started, the system kernel of the terminal sets the special mark bit of all used memory pages to 1. In other words, when the target running application switches from background operation to foreground operation, the system kernel of the terminal will mark the memory pages required for application startup and use. The terminal device can determine the memory pages used when the process is running based on the marking information.
[0145] In another possible embodiment, the present application may further define a first flag bit with an attribute as an enumeration value in a corresponding data structure for each memory page. Each time the target running application is hot-started, the system kernel of the terminal increments the enumeration value corresponding to the memory page that is used again, until the target running application is hot-started for the K+1th consecutive time, at which time the enumeration value of the memory page of the target running application is cleared. For example, the initial value of the first flag bit is 0. When the target running application is hot-started for the first time, if the first memory page is used, the first flag bit corresponding to the memory page is set to 1; when the target running application is hot-started for the second time, if the first memory page is used again, the first flag bit corresponding to the memory page is set to 2. The terminal device can determine the memory page corresponding to the first flag bit being non-0 as the memory page used by the process.
[0146] The specific description of the hot start of the application, the cold start of the application, and the memory page can refer to the above step 603, which will not be repeated here.
[0147] Step 803: the terminal determines the memory page that is swapped into the memory or the memory page that is remapped when the process is running as the common memory page of the target running application.
[0148] Among them, the first method for determining the common memory pages of the target running application can be: the terminal device determines the memory pages swapped into the memory or the remapped memory pages of the hot start process as the common memory pages of the target running application.
[0149] In addition, a second method for determining the commonly used memory pages of the target running application may be: when the terminal is hot-started for the Kth consecutive time, the system kernel of the terminal determines that the memory page that has been marked more than the set threshold is a commonly used memory page based on the information of the first mark bit of the memory page. In other words, the system kernel of the terminal determines the commonly used memory page based on the memory page that was swapped into the memory or the memory page that was remapped during the previous K consecutive hot starts. For example, when the target running application is hot-started for the first time, the first memory page is used, and the first mark bit corresponding to the first memory page is set to 1. Then, when the target running application is hot-started for the second time, the first memory page is used, and the first mark bit corresponding to the first memory page is set to 2. When the target running application is hot-started for the third time, the first memory page is not used. Assuming that K is set to 3 and the set threshold is set to 1, the system kernel of the terminal determines the first memory page as a commonly used memory page.
[0150] It should be noted that after the terminal device determines the commonly used memory page, the system kernel of the terminal clears the first mark bit. Continuing with the above example, after the terminal determines the first memory page as the commonly used memory page, the terminal device clears the mark bits of each memory page, and subsequently, the system kernel of the terminal continues to determine the commonly used memory page by the memory page used in the previous K consecutive hot starts.
[0151] Step 804: When the target running application is switched to background running, the terminal retains the common memory page in the memory.
[0152] Specifically, the system kernel of the terminal retains the marked memory page in the memory, or retains the memory page whose first marking bit is greater than a set threshold in the memory.
[0153] In step 805, the terminal determines memory pages other than commonly used memory pages as non-common memory pages of the target running application, and when the target running application is switched to background operation, the terminal migrates the non-common memory pages of the target running application from the memory to the swap partition of the storage.
[0154] It should be noted that there is no strict execution order for the above steps 804 and 805. Step 804 may be executed first and then step 805, or step 805 may be executed first and then step 804.
[0155] Specifically, in this step, before the terminal system kernel migrates the infrequently used memory pages of the target running application from the memory to the swap partition of the memory, the terminal processor first determines whether the I / O (input / output) of the memory is idle. If the I / O (input / output) is idle, the terminal system kernel will still store the infrequently used memory pages in the memory in a compressed form. Once it is determined that the I / O is idle, the infrequently used memory pages will be migrated to the swap partition of the memory.
[0156] In the embodiment of the present application, the method does not limit the target running application to perform compression operations when switching to the background application. The system kernel of the terminal can accurately determine the common memory pages and uncommon memory pages required for application startup and use by judging whether the memory page is used, and the implementation method is relatively flexible. The system kernel of the terminal retains the memory pages required for application startup and use in the memory, thereby improving the problem of freezing when the background running application is started again and improving the application's activity retention performance. On the other hand, the method can accurately screen out uncommon memory pages that need to be migrated to the swap partition. The terminal migrates uncommon memory pages to the swap partition of the memory to save memory resources. The swap partition also ensures that the data generated when the process of the target running application is running is not lost.
[0157] It should be noted that the method provided in the above embodiment can be combined with the existing memory reuse technology. For example, the existing memory reuse technologies include memory deduplication, ballooning technology, transcendent memory technology and SWAP technology, etc. The embodiments of the present application are not limited to this.
[0158] Based on the above embodiments, the present application provides a memory management device, which is applied to a terminal device to implement the following Figure 4 Memory management methods shown in Fig. 9 As shown, the device 900 includes: a determination unit 901 and a processing unit 902, wherein:
[0159] A determining unit 901 is configured to determine, when a target running application is hot-started, a common memory page of the target running application according to a memory page in which a page exception occurs in the target running application;
[0160] The processing unit 902 is used to retain the frequently used memory pages in the memory and swap the infrequently used memory pages from the memory to the swap partition of the storage after the target running application is switched to the background running.
[0161] In a possible design, the determination unit 901 is used to determine an application running in the background as a target application, or the determination unit 901 is used to determine the target running application according to an application identifier set by a user.
[0162] In one possible design, the target running application is hot-started when the target running application switches from background running to foreground running. The starting moment corresponding to the hot-start of the target running application may be the first moment when the process of the target running application switches from background running to foreground running. The determination unit 901 is used to use the time period corresponding to the second time length after the first moment as the time period corresponding to the hot-start process. The second time length may be a set threshold value or may be determined based on the status information of the target running application.
[0163] In a possible implementation, when the target running application is decompressed, the decompressed memory pages in the target running application are determined as common memory pages of the target running application.
[0164] In a possible implementation, when a swap operation is performed on a memory page in the target running application, the memory page in the target running application that is swapped to the memory is determined as a common memory page of the target running application.
[0165] In a possible implementation, when a memory page in the target running application is remapped, the remapped memory page in the target running application is determined as a common memory page of the target running application.
[0166] In another possible implementation, each time the target running application is hot-started, the processing unit 902 marks the decompressed memory pages in the target running application, and determines the marked memory pages as the commonly used memory pages of the target running application; or, marks the memory pages swapped to the memory in the target running application, and determines the marked memory pages as the commonly used memory pages of the target running application; or, marks the remapped memory pages in the target running application, and determines the marked memory pages as the commonly used memory pages of the target running application.
[0167] In one possible implementation, the processing unit 902 is specifically used to: perform a swap operation on the memory page of the target running application; when the memory page of the target running application is a commonly used memory page, retain the commonly used memory page in the memory; when the memory page of the target running application is an uncommonly used memory page, swap the uncommonly used memory page from the memory to the swap partition of the storage.
[0168] In a possible implementation, the processing unit 902 is further configured to: after the target running application is switched to background running for a first time duration, swap the commonly used memory pages from the internal memory to the swap partition of the storage.
[0169] In a possible implementation, the processing unit 902 migrates the unused memory pages of the target running application from the memory to the swap partition of the storage only when it determines that the memory I / O is idle; otherwise, the unused memory pages are retained in the memory.
[0170] In a possible implementation, when the process of the target running application is killed, the processing unit 902 swaps the common memory page from the memory to a swap partition of the storage.
[0171] By using the memory management device provided in the embodiment of the present invention, based on the characteristic that page missing exceptions occur in memory pages started and used by some applications when the applications are hot started, the common memory pages required for application startup and use can be accurately determined, and the system kernel of the terminal retains the memory pages required for application startup and use in the memory, thereby improving the problem of freezing when the application running in the background is started again and improving the activity retention performance of the application. On the other hand, the method can accurately screen out uncommonly used memory pages that need to be migrated to the swap partition, and the terminal migrates uncommonly used memory pages to the swap partition of the storage to save memory resources. The swap partition also ensures that the data generated by the process of the target running application is not lost.
[0172] It should be noted that the division of units in the embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. Each functional unit in the embodiments of the present application may be integrated into a processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0173] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0174] Based on the above embodiments, the present invention also provides a terminal device for implementing Figure 4 , Figure 6 or Figure 8 The memory management method shown in Fig. 9 The functions of the memory management device 900 shown in FIG. Fig.10 As shown, the terminal device 1000 includes: a transceiver 1001, a processor 1002, a bus 1003, and a memory 1004, wherein:
[0175] The transceiver 1001, the processor 1002, and the memory 1004 are interconnected via the bus 1003, and the bus 1003 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.10 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0176] The transceiver 1001 is used to communicate and interact with other devices.
[0177] The processor 1002 is used to implement Figure 4 The memory management method shown or, as Figure 6 The memory management method shown, or Figure 8 The memory management method shown.
[0178] In the embodiment of the present application, the method does not limit the target running application to perform compression operations when switching to the background application. The system kernel of the terminal can accurately determine the common memory pages and uncommon memory pages required for application startup and use by judging whether the memory page is used, and the implementation method is relatively flexible. The system kernel of the terminal retains the memory pages required for application startup and use in the memory, thereby improving the problem of freezing when the background running application is started again and improving the application's activity retention performance. On the other hand, the method can accurately screen out uncommon memory pages that need to be migrated to the swap partition. The terminal migrates uncommon memory pages to the swap partition of the memory to save memory resources. The swap partition also ensures that the data generated when the process of the target running application is running is not lost.
[0179] An embodiment of the present application also provides a computer storage medium, in which computer instructions are stored. When the computer instructions are executed on a terminal device, the terminal device executes the above-mentioned related method steps to implement the method in the above-mentioned embodiment.
[0180] The embodiments of the present application also provide a computer program product. When the computer program product is run on a computer, the computer is caused to execute the above-mentioned related steps to implement the method in the above-mentioned embodiments.
[0181] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory so that the chip executes the methods in the above-mentioned method embodiments.
[0182] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0183] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another device, or some features can be discarded or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0184] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0185] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0186] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0187] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A memory management method, applied to a terminal, characterized in that: include: When the target running application is hot-started, determining the common memory pages of the target running application according to the memory pages in which the page exception occurs in the target running application; After the target running application is switched to background running, the frequently used memory pages are retained in the memory, and the infrequently used memory pages are swapped from the memory to the swap partition of the storage device, wherein the infrequently used memory pages are memory pages other than the frequently used memory pages; Wherein, determining the common memory page of the target running application according to the memory page where the page exception occurs in the target running application includes: When the target running application is decompressed, determining the decompressed memory page of the target running application as a common memory page of the target running application; Alternatively, when a memory page in the target running application is swapped, the memory page in the target running application that is swapped to the memory is determined as a common memory page of the target running application; Alternatively, when a memory page in the target running application is remapped, the remapped memory page in the target running application is determined as a common memory page of the target running application.
2. The method according to claim 1, characterized in that The determining of the common memory pages of the target running application includes: Marking the decompressed memory pages in the target running application, and determining the marked memory pages as common memory pages of the target running application; Alternatively, the memory pages swapped to the memory in the target running application are marked, and the marked memory pages are determined as common memory pages of the target running application; Alternatively, the remapped memory pages in the target running application are marked, and the marked memory pages are determined as common memory pages of the target running application.
3. The method according to claim 1 or 2, characterized in that: Keeping the frequently used memory pages in the memory and swapping the infrequently used memory pages from the memory to a swap partition of the storage device includes: Performing a swap operation on the memory page of the target running application; When the memory page of the target running application is the common memory page, retaining the common memory page in the memory; When the memory page of the target running application is the infrequently used memory page, the infrequently used memory page is swapped from the internal memory to the swap partition of the storage.
4. The method according to claim 1 or 2, characterized in that: The method further comprises: After the target running application is switched to the background running for a first time period, the common memory page is swapped from the internal memory to the swap partition of the storage.
5. The method according to claim 1 or 2, characterized in that: Swaps unused memory pages from main memory to the storage's swap partition, including: Determine whether the input and output I / O of the memory is idle; When the I / O of the memory is idle, the unused memory page is swapped from the memory to a swap partition of the storage.
6. The method according to claim 1 or 2, characterized in that: Before the terminal determines the common memory page of the target running application according to the memory page where the page exception occurs in the target running application, the terminal further includes: When the target running application is switched to background running, the terminal compresses the memory pages in the target running application; Alternatively, when the target running application is switched to background running, the terminal performs a swap operation on a memory page in the target running application; Alternatively, when the target running application is switched to background running, the terminal remaps the memory page in the target running application.
7. The method according to claim 1 or 2, characterized in that: Also includes: Determine the application running in the background as the target running application; Alternatively, the target running application is determined according to an application identifier set by the user.
8. The method according to claim 1 or 2, characterized in that: Also includes: The target running application being hot started means that the target running application is switched from background running to foreground running.
9. The method according to claim 1 or 2, characterized in that: When the target running application is hot started, it includes: Determine a first moment when the process of the target running application switches from background running to foreground running, within a time period corresponding to a second time length after the first moment; The second time duration is a set threshold, or the second time duration is determined according to the state information of the target running application.
10. The method according to claim 1 or 2, characterized in that: Also includes: When the process of the target running application is killed, the common memory page is swapped from the memory to the swap partition of the storage.
11. A memory management device, characterized in that: include: a determining unit, configured to determine, when a target running application is hot-started, a common memory page of the target running application according to a memory page in which a page exception occurs in the target running application; a processing unit, configured to retain the frequently used memory pages in the memory and swap the infrequently used memory pages from the memory to a swap partition of the storage device after the target running application is switched to background running; The determining unit is specifically used for: When the target running application is decompressed, determining the decompressed memory page of the target running application as a common memory page of the target running application; Alternatively, when a memory page in the target running application is swapped, the memory page in the target running application that is swapped to the memory is determined as a common memory page of the target running application; Alternatively, when a memory page in the target running application is remapped, the remapped memory page in the target running application is determined as a common memory page of the target running application.
12. The device according to claim 11, characterized in that The determining unit is specifically used for: Marking the decompressed memory pages in the target running application, and determining the marked memory pages as common memory pages of the target running application; Alternatively, the memory pages swapped to the memory in the target running application are marked, and the marked memory pages are determined as common memory pages of the target running application; Alternatively, the remapped memory pages in the target running application are marked, and the marked memory pages are determined as common memory pages of the target running application.
13. The device according to claim 11 or 12, characterized in that After the target running application is switched to background running, the processing unit is specifically used to: Performing a swap operation on the memory page of the target running application; When the memory page of the target running application is the common memory page, retaining the common memory page in the memory; When the memory page of the target running application is the infrequently used memory page, the infrequently used memory page is swapped from the internal memory to the swap partition of the storage.
14. The device according to claim 11 or 12, characterized in that The processing unit is also used for: After the target running application is switched to the background running for a first time period, the common memory page is swapped from the internal memory to the swap partition of the storage.
15. The device according to claim 11 or 12, characterized in that The processing unit is specifically used for: Determine whether the input and output I / O of the memory is idle; When the I / O of the memory is idle, the unused memory page is swapped from the memory to a swap partition of the storage.
16. The device according to claim 11 or 12, characterized in that Before the determining unit determines the common memory page of the target running application according to the memory page where the page exception occurs in the target running application, the processing unit is further used to: When the target running application is switched to background running, compressing the memory pages in the target running application; Alternatively, when the target running application is switched to background running, performing a swap operation on the memory page in the target running application; Alternatively, when the target running application is switched to background running, the memory pages in the target running application are remapped.
17. The device according to claim 11 or 12, characterized in that The determining unit is further configured to: Determine the application running in the background as the target running application; Alternatively, the target running application is determined according to an application identifier set by the user.
18. The device according to claim 11 or 12, characterized in that Also includes: The target running application being hot started means that the target running application is switched from background running to foreground running.
19. The device according to claim 11 or 12, characterized in that The determining unit is specifically used for: Determine a first moment when the process of the target running application switches from background running to foreground running, and determine, within a time period corresponding to a second time period after the first moment, a commonly used memory page of the target running application based on a memory page in which a page exception occurs in the target running application; The second time duration is a set threshold, or the second time duration is determined according to the state information of the target running application.
20. The device according to claim 11 or 12, characterized in that The processing unit is also used to When the process of the target running application is killed, the common memory page is swapped from the memory to the swap partition of the storage.
21. A terminal, characterized in that: The terminal includes a display screen, a processor and a memory; The memory stores program instructions; The processor is configured to run the program instructions stored in the memory, so that the terminal executes the method according to any one of claims 1 to 10.
22. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes program instructions. When the program instructions are executed on a processor, the processor is caused to perform the method according to any one of claims 1 to 10.
23. A chip, characterized in that: The chip is coupled to a memory and is configured to execute a computer program stored in the memory to perform the method according to any one of claims 1 to 10.
