Method for preloading memory page, electronic device, and chip system

By generating and preloading PTE snapshots accessed during application hot startup, the problem of page missing exceptions in electronic devices during hot startup is solved, and application startup speed and user experience are improved.

WO2024179104A1PCT designated stage expired Publication Date: 2024-09-06HONOR DEVICE CO LTD

Patent Information

Application Number
PCT/CN2023/136403
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-02-28
Filing Date
2023-12-05
Publication Date
2024-09-06

AI Technical Summary

Technical Problem

When an electronic device is hot-starting an application, page faults occur due to the memory recycling mechanism, resulting in long application startup times and poor user experience.

Method used

By generating and storing PTE snapshots of page objects accessed during application hot start, preloading file pages and anonymous page data into physical memory reduces page missing anomalies and improves application hot start speed.

Benefits of technology

It significantly speeds up application hot startup, improves user experience, reduces page missing exceptions, and improves application startup efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2023136403_06092024_PF_FP
    Figure CN2023136403_06092024_PF_FP
Patent Text Reader

Abstract

Embodiments of the present application provide a method for preloading a memory page, an electronic device, and a chip system, and relate to the technical field of terminal applications. The method comprises: after a hot start of an application ends, generating a page table entry snapshot from a page table entry of which page objects accessed in the hot start process of the application as a file page and an anonymous page, wherein the page table entry snapshot can be stored in a disk or a memory; when the application is hot-started next time, pre-reading the page table entry snapshot of the application from the disk or the memory, and according to the page table entry snapshot, loading file page data and anonymous page data corresponding to the page table entry snapshot in the physical memory; and filling the page table entry. Since the filled page table entry comprises a mapping relationship from the virtual memory to the physical memory of the application, the incidence of page faults during the hot start of the application can be reduced, thereby accelerating the speed of the application start.
Need to check novelty before this filing date? Find Prior Art

Description

Method for preloading memory pages, electronic device, and chip system

[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on February 28, 2023, with application number 202310174653.0 and application name “A method for preloading memory pages, electronic device and chip system”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The embodiments of the present application relate to the field of terminal application technology, and in particular to a method for preloading memory pages, an electronic device, and a chip system. Background Art

[0003] As the functions of electronic devices become more and more powerful, more and more applications are installed in the electronic devices. Users can use the functions provided by these applications based on the applications installed in the electronic devices.

[0004] When an application is hot-started, due to the memory recycling mechanism, a page fault exception usually occurs when accessing a swapped-out or released memory page again. After a page fault exception occurs, the system puts the application process in the startup process into a blocking queue until the page fault exception problem is resolved. For example, after a page fault exception occurs, physical memory is allocated to the application, the relevant file page data and anonymous page data are loaded in the allocated physical memory, and the mapping relationship between the application's virtual memory and the physical address of the allocated physical memory is filled in the Page Table Entry (PTE) used to store the mapping relationship between virtual memory and physical memory. This will result in a longer application hot-start time and a poor user experience.

[0005] Summary of the Invention

[0006] The embodiments of the present application provide a method for preloading memory pages, an electronic device, and a chip system, which can accelerate the speed of application hot start and improve user experience.

[0007] To achieve the above objectives, this application adopts the following technical solutions:

[0008] In a first aspect, an embodiment of the present application provides a method for preloading a memory page, comprising:

[0009] The kernel receives pre-read information, the pre-read information including an identifier of the first application and a hot start identifier;

[0010] In response to the pre-read information, the kernel reads a PTE snapshot corresponding to the identifier of the first application from a first storage space, the PTE snapshot being generated for PTEs of file pages and anonymous pages based on page objects accessed during a historical hot start of the first application, the first storage space being located in physical memory or disk;

[0011] The kernel loads the file page data corresponding to the PTE snapshot on disk and the anonymous page data corresponding to the swap partition into physical memory;

[0012] The kernel writes a mapping relationship between the virtual memory of the file page data and the physical memory of the file page data, and a mapping relationship between the virtual memory of the anonymous page data and the physical memory of the anonymous page data into the PTE of the first application.

[0013] In the present application, a PTE snapshot is generated for the PTEs of file pages and anonymous pages, the page objects accessed during the hot start of the application, and the PTE snapshot is stored in a first storage space; when the application is subsequently hot started, the PTE snapshot corresponding to the identifier of the same application is read from the first storage space; then the file page data corresponding to the PTE snapshot on the disk and the anonymous page data in the swap partition are loaded into the physical memory, and the mapping relationship between the virtual memory and physical memory of the file page data, as well as the mapping relationship between the virtual memory and physical memory of the anonymous page data, are written into the PTE; because the file page data and the anonymous page data have been preloaded in advance, and the mapping relationship between the virtual memory and physical memory of the file page data, as well as the mapping relationship between the virtual memory and physical memory of the anonymous page data, have been written into the PTE, the page fault anomaly during the hot start of the application is reduced, and the speed of the hot start of the application is accelerated.

[0014] As another implementation of the first aspect of the present application, before the kernel receives the pre-read information, the method further includes:

[0015] The kernel receives the capture information, where the capture information includes an identifier of the first application and a hot start identifier;

[0016] In response to the captured information, the kernel generates a PTE snapshot corresponding to the identifier of the first application based on the PTEs of the file pages and anonymous pages in the page table corresponding to the identifier of the first application;

[0017] The kernel stores the PTE snapshot corresponding to the identifier of the first application in the first storage space.

[0018] In this application, a PTE snapshot of the application can be generated by using the PTEs of file pages and anonymous pages in the page table corresponding to the application during the historical hot start process, so that the file page data and anonymous page data can be preloaded according to the PTE snapshot during subsequent hot starts (both file pages and anonymous pages are memory pages).

[0019] As another implementation of the first aspect of the present application, in response to the captured information, the kernel generates a PTE snapshot corresponding to the identifier of the first application based on the PTEs of the file pages and anonymous pages in the page table corresponding to the identifier of the first application, including:

[0020] In response to the captured information, the kernel determines that a PTE snapshot corresponding to the identifier of the first application does not exist in the first storage space;

[0021] The kernel generates a PTE snapshot corresponding to the identifier of the first application based on the PTEs of the file pages and anonymous pages in the page table corresponding to the identifier of the first application.

[0022] In this application, there is no need to generate a PTE snapshot based on the PTE written during each hot start of the application. If the first storage space does not contain a PTE snapshot corresponding to the application, it is necessary to generate a PTE snapshot corresponding to the application based on the PTEs whose page objects in the page table corresponding to the application are file pages and anonymous pages; if the first storage space already contains a PTE snapshot corresponding to the application, it is not necessary to generate a PTE snapshot corresponding to the application based on the PTEs whose page objects in the page table corresponding to the application are file pages and anonymous pages.

[0023] As another implementation of the first aspect of the present application, the kernel generates a PTE snapshot corresponding to the identifier of the first application based on a PTE in which the page objects in the page table corresponding to the identifier of the first application are file pages and anonymous pages, including:

[0024] The kernel sets the status bit in the page table corresponding to the identifier of the first application to a preset character, and the page object to a PTE of a preset type, and generates a PTE snapshot corresponding to the identifier of the first application. The preset character is used to indicate that the virtual memory corresponding to the PTE has been mapped to the physical memory (for example, it can be determined by pte_present) and has been accessed (for example, it can be determined by checking pte_young). The preset types include active, referenced, and anon.

[0025] In this application, the PTE for generating a PTE snapshot can be determined based on the status bit in the PTE data structure and the page object (i.e., page flag). The anonymous page type is anon, and you can select active and referenced file pages to generate a PTE snapshot. Selecting certain file page types to generate a PTE snapshot can balance the pre-reading time caused by loading a large number of file pages with the application startup speed.

[0026] As another implementation of the first aspect of the present application, before the kernel receives the pre-read information, the method further includes:

[0027] The monitoring module detects that the first application is started to the pre-reading node, and the pre-reading node is located before the ActivityStart phase in the application startup process;

[0028] The monitoring module sends a pre-reading instruction to the pre-reading module;

[0029] In response to the pre-read instruction, the pre-read module transmits the pre-read information to the kernel through a system call.

[0030] In this application, the process of pre-reading file pages and anonymous pages is implemented through the kernel in the kernel space; the time node of pre-reading is detected by the monitoring module in the user space; the information interaction between the user space and the kernel space is realized through system calls; in order to improve the speed of application startup, the time node for pre-reading can be determined before the ActivityStart stage where a large number of page fault exceptions occur.

[0031] As another implementation of the first aspect of the present application, before the kernel receives the capture information, the method further includes:

[0032] The monitoring module detects that the first application is started to the capture node, and the capture node is located within the first time after or at the end of the DoFrame phase in the application startup process;

[0033] The monitoring module sends a capture instruction to the pre-reading module;

[0034] In response to the capture instruction, the pre-reading module transmits the capture information to the kernel through a system call.

[0035] In the present application, the process of generating a PTE snapshot is implemented by the kernel in the kernel space; the time node of generating the PTE snapshot is detected by the monitoring module in the user space; the information exchange between the user space and the kernel space is realized by means of system calls; in order to be able to generate some types of file pages and anonymous pages filled with page fault exceptions during the hot start of the application, the time node for capturing the PTE information can be determined at the end of the DoFrame phase during the application startup process or within the first time thereafter.

[0036] As another implementation of the first aspect of the present application, before the kernel receives the capture information, the method further includes:

[0037] The monitoring module detects that the first application is started to a capture node, and the capture node is located within a first time at or after the end of the ActivityStart phase in the application startup process;

[0038] The monitoring module sends a capture instruction to the pre-reading module;

[0039] In response to the capture instruction, the pre-reading module transmits the capture information to the kernel through a system call.

[0040] In this application, according to actual conditions, PTE information can also be captured at the end of the ActivityStart phase when a large number of page fault exceptions occur during the application startup process or within the first time thereafter. At this time, the captured PTE information already contains most of the file page data and anonymous page data required during the application hot start process.

[0041] As another implementation of the first aspect of the present application, the method further includes:

[0042] The kernel receives the deletion information, where the deletion information includes an identifier of the first application;

[0043] In response to the deletion information, the kernel deletes the PTE snapshot corresponding to the identifier of the first application stored in the first storage space.

[0044] In this application, in order to save storage space, when an application is deleted from an electronic device, the PTE snapshot of the application can be deleted together with the application.

[0045] As another implementation of the first aspect of the present application, before the kernel receives the deletion information, the method further includes:

[0046] The monitoring module receives an uninstall instruction of the first application;

[0047] In response to the uninstall instruction, the monitoring module transmits deletion information to the kernel through a system call.

[0048] As another implementation method of the first aspect of the present application, PTE includes a mapping relationship between virtual memory and physical memory, and the PTE snapshot includes the file name of the file page data corresponding to the PTE and the storage address of the file page data in the disk, as well as the storage address of the anonymous page data corresponding to the PTE in the swap partition.

[0049] In a second aspect, an electronic device is provided, comprising a processor, wherein the processor is configured to execute a computer program stored in a memory to implement any one of the methods of the first aspect of the present application.

[0050] In a third aspect, a chip system is provided, comprising a processor coupled to a memory, wherein the processor executes a computer program stored in the memory to implement any method of the first aspect of the present application.

[0051] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by one or more processors, it implements any method of the first aspect of the present application.

[0052] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when running on a device, enables the device to execute any method of the first aspect of the present application.

[0053] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] FIG1 is a schematic diagram of a hardware structure of an electronic device to which the method for preloading memory pages provided in an embodiment of the present application is applied;

[0055] FIG2 is a schematic diagram of data flow from a virtual address to a physical address according to an embodiment of the present application;

[0056] FIG3 is a schematic diagram of an abnormal page fault phenomenon during a cold start of an application according to an embodiment of the present application;

[0057] FIG4 is a schematic diagram of a page fault abnormality during hot start of an application according to an embodiment of the present application;

[0058] FIG5 is a data structure diagram of a virtual space describing a process according to an embodiment of the present application;

[0059] FIG6 is a schematic diagram of a data structure of a PTE provided in an embodiment of the present application;

[0060] FIG7 is a schematic diagram of time nodes for capturing a PTE snapshot and preloading a PTE snapshot during a cold start of an application according to an embodiment of the present application;

[0061] FIG8 is a schematic diagram of time nodes for capturing a PTE snapshot and preloading a PTE snapshot during hot start of an application according to an embodiment of the present application;

[0062] FIG9 is a schematic diagram of the technical architecture of a method for preloading memory pages provided in an embodiment of the present application;

[0063] FIG10 is a timing diagram of capturing a PTE snapshot during a cold start of an application according to an embodiment of the present application;

[0064] FIG11 is a timing diagram of preloading a PTE snapshot during a cold start of an application according to an embodiment of the present application;

[0065] FIG12 is a schematic diagram of a process flow executed by the kernel during a cold start of an application according to an embodiment of the present application;

[0066] FIG13 is a schematic diagram of a process flow executed by the kernel when an application is uninstalled according to an embodiment of the present application;

[0067] FIG14 is a schematic diagram of a process flow of kernel execution during application hot start according to an embodiment of the present application;

[0068] FIG15 is a schematic diagram comparing the latency and IO wait of the application startup method and the native process provided in an embodiment of the present application. DETAILED DESCRIPTION

[0069] In the following description, specific details such as specific system structures and technologies are provided for illustration rather than limitation to facilitate a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details.

[0070] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or collections thereof.

[0071] It should also be understood that in the embodiments of this application, "one or more" refers to one, two, or more than two; "and / or" describes the relationship between associated objects, indicating that three relationships can exist; for example, A and / or B can mean: A exists alone, A and B exist simultaneously, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the associated objects are in an "or" relationship.

[0072] In addition, in the description of this application specification and the appended claims, the terms "first", "second", "third", "fourth", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0073] References to "one embodiment" or "some embodiments" in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present application. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.

[0074] The present invention provides a method for preloading memory pages, which can be applied to electronic devices. The electronic devices can be tablet computers, mobile phones, wearable devices, laptop computers, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), and other electronic devices. The present invention does not limit the specific type of electronic device.

[0075] Figure 1 shows a schematic diagram of the structure of an electronic device. Electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, antenna 1, antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, a camera 193, a display 194, and a subscriber identification module (SIM) card interface 195. Sensor module 180 may include a pressure sensor 180A, a touch sensor 180K, an ambient light sensor 180L, and the like.

[0076] It should be understood that the structures illustrated in the embodiments of the present application do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0077] The processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a coprocessor (SCP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units can be independent devices or integrated into one or more processors. For example, the processor 110 is used to execute the application startup method in the embodiment of the present application.

[0078] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0079] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly retrieve it from the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.

[0080] The USB interface 130 is an interface that complies with USB standards, and may be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 may be used to connect a charger to charge the electronic device 100, and may also be used to transfer data between the electronic device 100 and peripheral devices.

[0081] It is understood that the interface connection relationship between the modules illustrated in the embodiments of the present application is merely an illustrative illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods from the above embodiments, or a combination of multiple interface connection methods.

[0082] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 via the external memory interface 120 to implement data storage functions. For example, files such as music and videos can be stored on the external memory card.

[0083] The internal memory 121 can be used to store computer executable program code, which includes instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function (such as a sound playback function, an image playback function, etc.).

[0084] In addition, the internal memory 121 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.

[0085] The charging management module 140 is configured to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from the wired charger via the USB interface 130.

[0086] The power management module 141 is used to connect the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to provide power to the processor 110, the internal memory 121, the external memory, the display 194, the camera 193, and the wireless communication module 160.

[0087] In some other embodiments, the power management module 141 may also be provided in the processor 110. In some other embodiments, the power management module 141 and the charging management module 140 may also be provided in the same device.

[0088] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.

[0089] Antenna 1 and Antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve antenna utilization. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In other embodiments, the antennas can be used in conjunction with a tuning switch.

[0090] The mobile communication module 150 can provide wireless communication solutions, including 2G / 3G / 4G / 5G, for the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low-noise amplifier (LNA), and the like. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, filter and amplify the received electromagnetic waves, and transmit them to the modem processor for demodulation. The mobile communication module 150 can also amplify the signals modulated by the modem processor and convert them into electromagnetic waves for radiation via the antenna 1.

[0091] The wireless communication module 160 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 electronic device 100. The wireless communication module 160 can be one or more devices that integrate at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, frequency modulate it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0092] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 150 , and antenna 2 is coupled to wireless communication module 160 , so that electronic device 100 can communicate with the network and other devices through wireless communication technology.

[0093] The electronic device 100 can implement audio functions such as music playback and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.

[0094] The audio module 170 is used to convert digital audio signals into analog audio signals for output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be provided in the processor 110, or some functional modules of the audio module 170 can be provided in the processor 110.

[0095] The speaker 170A, also called a "speaker", is used to convert audio electrical signals into sound signals. The electronic device 100 can listen to music or listen to hands-free calls through the speaker 170A.

[0096] The receiver 170B, also called a "handset", is used to convert audio electrical signals into sound signals. When the electronic device 100 receives a call or a voice message, the user can place the receiver 170B close to the ear to hear the voice.

[0097] Microphone 170C, also known as "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can speak by putting their mouth close to the microphone 170C to input the sound signal into the microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In other embodiments, the electronic device 100 can be provided with two microphones 170C, which can not only monitor voice information but also realize noise reduction function. In other embodiments, the electronic device 100 can also be provided with three, four or more microphones 170C to realize the collection of sound signals, noise reduction, identification of sound sources, and directional recording functions. For example, the microphone 170C can be used to collect voice information involved in the embodiments of the present application.

[0098] The headphone jack 170D is used to connect a wired headphone and can be the USB interface 130 or a 3.5mm open mobile terminal platform (OMTP) standard interface or a cellular telecommunications industry association of the USA (CTIA) standard interface.

[0099] The pressure sensor 180A is used to sense pressure signals and convert them into electrical signals. In some embodiments, the pressure sensor 180A can be provided on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. A capacitive pressure sensor can be a device comprising at least two parallel plates having a conductive material. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure based on the change in capacitance. When a touch operation is applied to the display screen 194, the electronic device 100 detects the intensity of the touch operation based on the pressure sensor 180A. The electronic device 100 can also calculate the position of the touch based on the detection signal of the pressure sensor 180A.

[0100] The touch sensor 180K is also called a "touch panel." The touch sensor 180K can be disposed on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen." The touch sensor 180K is used to detect touch operations applied thereto or in the vicinity thereof. The touch sensor can transmit the detected touch operations to the application processor to determine the type of touch event. Visual output related to the touch operations can be provided via the display screen 194. In other embodiments, the touch sensor 180K can also be disposed on the surface of the electronic device 100, in a location different from that of the display screen 194.

[0101] Ambient light sensor 180L is used to sense ambient light brightness. Electronic device 100 can adaptively adjust the brightness of display screen 194 based on the perceived ambient light. Ambient light sensor 180L can also be used to automatically adjust white balance when taking photos. Ambient light sensor 180L can also work with proximity light sensor 180G to detect whether electronic device 100 is in a pocket to prevent accidental touches.

[0102] The buttons 190 include a power button, a volume button, and the like. The buttons 190 may be mechanical buttons or touch buttons. The electronic device 100 may receive key inputs and generate key signal inputs related to user settings and function control of the electronic device 100.

[0103] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts and can also be used for touch vibration feedback.

[0104] Electronic device 100 implements display functionality through a GPU, display screen 194, and an application processor. A GPU is a microprocessor for image processing that connects display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or modify display information.

[0105] Display screen 194 is used to display images, videos, and the like. Display screen 194 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 (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-oLed, or a quantum dot light-emitting diode (QLED). In some embodiments, electronic device 100 may include one or N display screens 194, where N is a positive integer greater than one.

[0106] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then passes the electrical signal to the ISP for conversion into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.

[0107] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to or removed from the electronic device 100 by inserting it into or removing it from the SIM card interface 195. The electronic device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, and the like. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The electronic device 100 interacts with the network through the SIM card to implement functions such as calls and data communications. In some embodiments, the electronic device 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100.

[0108] The embodiments of the present application do not particularly limit the specific structure of the execution subject of the method for preloading memory pages. As long as the code recording the method for preloading memory pages according to the embodiments of the present application can be run to communicate according to the method for preloading memory pages provided by the embodiments of the present application. For example, the execution subject of the method for preloading memory pages provided by the embodiments of the present application can be a functional module in an electronic device that can call and execute a program, or a communication device used in an electronic device, such as a chip.

[0109] In paged memory management, the operating system can allocate virtual memory to processes. For example, in a 32-bit operating system, the maximum virtual memory space allocated to each process is 4GB. Virtual memory can be divided into fixed-size pages, each of which is a page. For example, virtual memory can be divided into pages of 4KB (or 8KB, 16KB, etc.). At the same time, the kernel can also divide the physical memory of the electronic device into pages of the same size, and the pages in the physical memory can be recorded as physical pages. In this way, whether it is virtual memory or physical memory, pages are the smallest allocation unit.

[0110] The data corresponding to the user program (for example, the code segment, data segment, and stack segment, etc.) is stored in the physical memory. The user program cannot directly access or view the physical memory. However, the user program can directly access or view the virtual memory. Therefore, it is necessary to establish a mapping relationship between the virtual memory and the physical memory, that is, the mapping relationship from virtual memory to physical memory.

[0111] As mentioned earlier, the smallest allocation unit in virtual memory and physical memory is a page. Each page in virtual memory has a virtual address, and each page in physical memory has a physical address. Therefore, the mapping relationship between virtual memory and physical memory can be represented by recording the mapping relationship between the virtual address of virtual memory and the physical address of physical memory.

[0112] Referring to Figure 2, a flow diagram from virtual addresses to physical addresses is provided for an embodiment of the present application. When the central processing unit (CPU) needs to access data or obtain instructions, it sends the virtual address corresponding to the data or instruction to the memory management unit (MMU). The MMU is responsible for finding the physical address corresponding to the virtual address based on the above mapping relationship. The MMU sends the found physical address to the physical memory, and the physical memory performs the corresponding access according to the physical address and reads or writes the relevant data or instructions.

[0113] The memory management unit stores a page table for each user program. This page table stores the mapping relationship between virtual pages (corresponding to virtual addresses) and physical pages (corresponding to physical addresses). When a physical page is assigned to a virtual page, a record is added to the page table to store the mapping relationship between the virtual page and the physical page. Subsequently, the received virtual address can be converted into a physical address based on the mapping relationship between the virtual page and the physical page stored in the page table.

[0114] Of course, after the memory management unit receives a virtual address, it first needs to determine whether the virtual address is valid, whether it is in the physical memory, and whether it is protected.

[0115] If the virtual address is valid and there is a corresponding physical address in the physical memory, and it is not protected (that is, accessible), the virtual address can be used as an index to find the physical address corresponding to the virtual address in the page table.

[0116] However, there may also be the following situation that triggers a page fault exception: the virtual address is valid, but the physical address corresponding to the virtual address does not exist in the physical memory.

[0117] This situation may be due to the lazy allocation mechanism. That is, when a user program is started, virtual memory is allocated for the user program. However, physical memory is not allocated at this time, so there is naturally no mapping relationship between virtual memory and physical memory. When the user program needs to access certain data during operation, it searches the physical memory for the physical address corresponding to the virtual address. However, because physical memory has not yet been allocated, the physical address corresponding to the virtual address cannot be found in physical memory, triggering a page fault exception. This page fault exception is more common during the application cold start process.

[0118] This situation may also be caused by the access data being swapped out of the physical memory. For example, after the user program switches to the background, due to limited physical memory resources, the operating system will start memory page replacement and put the physical pages that have not been used for a long time (for example, anonymous pages) into the swap partition to make the freed physical memory resources available to other user programs. If the data accessed by the user program is located in the swap partition, the physical address corresponding to the virtual address will not be found in the physical memory, which will trigger a page fault exception. The operating system may also recycle physical pages that have not been used for a long time (for example, file pages) to make the freed physical memory resources available to other user programs. If the data accessed by the user program has been recycled from the physical memory to the disk, the physical address corresponding to the virtual address will not be found in the physical memory, which will trigger a page fault exception. This type of page fault exception often occurs during the hot start of an application.

[0119] Regardless of the type of page fault exception, it may be necessary to read data from the disk or swap partition (for example, read file page data from the disk, read anonymous page data from the swap partition) to the physical memory, establish a mapping relationship between the virtual address of the read memory page data (including file page data and anonymous page data) and the current physical address of the read data, fill in the PTE, and the user program can continue to run. This situation seriously blocks the operation of the user program.

[0120] Of course, in actual applications, there may be other abnormal situations. The embodiment of the present application does not focus on the causes of page fault abnormalities, so they will not be listed one by one.

[0121] After a page fault exception occurs, the operating system will put the user program into the blocking queue until the page fault exception problem is resolved, and then the user program will be put into the ready queue and continue to run. Therefore, after a page fault exception occurs, the operation of the user program will be blocked.

[0122] During the application startup process, the above-mentioned page fault exception may occur more frequently, resulting in a slower application startup process and a poor user experience.

[0123] Application startup methods include cold start and hot start. When an application is started, if the application process does not exist in the system, the system needs to create a process for the application, indicating that the application is started as a cold start.

[0124] As an example of an application cold start, after the electronic device is turned on, the user clicks the application icon on the system desktop to start the application. This startup process of the application is a cold start.

[0125] As another example of application cold start, after the user starts the application, the user switches the application to background operation. Due to the system recycling resources, the application process is killed. When the user starts the application again, the current startup process of the application is a cold start.

[0126] Referring to Figure 3, there is a schematic diagram of a page fault exception during the cold start process of an application provided in an embodiment of the present application. In this diagram, the horizontal axis represents the various stages in the cold start process of an application, among which several stages are highlighted: ApplicationStart, BindApplication, ActivityStart, Choreographer, and DoFrame. For details of these stages, please refer to the description of the subsequent embodiments. The black vertical lines indicate that a page fault exception has occurred. The thicker the black vertical lines, the more page fault exceptions that occur in a short period of time. It can be understood from Figure 3 that during the cold start process of an application, more page fault exceptions occurred in the BindApplication stage, and a small number of page fault exceptions also occurred in the ActivityStart stage. These page fault exceptions will cause the application cold start process to be slower.

[0127] When an application is started, if a process for the application already exists in the system, the system does not need to create a process for the application. Instead, it uses the existing process in the system to start creating the Activity and subsequent operations, indicating that the application is started hot.

[0128] As an example of an application hot start, after the user launches the application, the user switches the application to the background. The user can switch the application to the foreground in a variety of ways. For example, when the application is running in the background, the user clicks the application icon on the system desktop; when the application is running in the background, the user enters the application from the negative one screen; when the application is running in the background, the user starts the application through a mini-program, etc. Before the application switches to the foreground, the application process continues to exist in the system and is not killed by the system. This startup process of switching the application from the background to the foreground without killing the application process is called a hot start.

[0129] Referring to Figure 4, there is a schematic diagram of a page fault exception during the application hot start process provided in an embodiment of the present application. In this diagram, the horizontal axis represents the application hot start process, in which several stages are highlighted: ActivityStart, ActivityResume, Choreographer, and DoFrame. For details of these stages, please refer to the description of the subsequent embodiments. The black vertical lines indicate that a page fault exception has occurred. The thicker the black vertical lines, the more page fault exceptions that occur in a short period of time. It can be understood from Figure 4 that during the application hot start process, a large number of page fault exceptions occurred in the ActivityStart stage, the ActivityResume stage, the Choreographer stage, and the DoFrame stage. These page fault exceptions will cause the application hot start process to be slower.

[0130] It can be understood from Figures 3 and 4 that during the application startup process, page fault exceptions will frequently occur, which will result in a slower application startup speed and a poor user experience.

[0131] The number of page fault exceptions in Figures 3 and 4 is only used for comparison between different stages and does not represent the absolute number of page fault exceptions that occur in each stage.

[0132] To solve the above problem, an embodiment of the present application provides a method for preloading memory pages. After the application is started, the page missing information during the application startup process can be recorded through a page table entry (PTE) snapshot to generate a PTE snapshot. The PTE snapshot is stored on the disk (it can also be stored in the physical memory during a hot start); when the application is subsequently started, the memory page data corresponding to the recorded page missing information can be preloaded in the physical memory based on the PTE snapshot stored on the disk (or physical memory).

[0133] For cold start, the generated PTE snapshot includes the file name and storage address on disk of the file page data corresponding to the PTE written during this startup. Therefore, the preloaded data is the file page data corresponding to the PTE snapshot. The above preloading process may be before the process is created. After the file page data is preloaded in the physical memory, there is no need to load the file page data from the disk to the physical memory during the subsequent startup process, which can save the time of loading the file page data from the disk to the physical memory and improve the speed of application cold start.

[0134] In addition, during a cold start, after a process is started, the system allocates virtual memory to the process, establishes a mapping relationship between the virtual address and the physical address of the loaded file page data in physical memory, and fills the PTE (for example, filling the mapping relationship between the virtual address and the physical address). After filling the PTE, the occurrence of page fault exceptions can be reduced, and the speed of application cold start is also improved.

[0135] For hot boot, the generated PTE snapshot includes the file name and storage address on disk of the file page data corresponding to the PTE accessed during this boot, as well as the storage address in the swap partition of the anonymous page data corresponding to the PTE accessed during this boot. Therefore, the data loaded into the physical memory includes file page data (for example, data recovered to disk) and anonymous page data (for example, data swapped to the swap partition). Since the application process itself exists in the system and the virtual space of the process has been allocated, during the hot boot process, after the memory page data is loaded into the physical memory according to the PTE snapshot, the mapping relationship between the virtual address and the physical address can be directly established based on the physical address of the loaded memory page data in the physical memory, and the PTE can be filled (for example, the mapping relationship between the virtual address and the physical address). This reduces the occurrence of page fault exceptions and improves the speed of application hot boot.

[0136] For the convenience of subsequent description, memory page data is uniformly used to represent data preloaded in physical memory based on PTE snapshots, regardless of cold start or hot start.

[0137] In order to more clearly understand the method for preloading memory pages provided in the embodiment of the present application, the source of the PTE snapshot is first described.

[0138] When an application is cold started, the system creates a process for the application and allocates virtual memory for the process (for example, 4GB). When an application is hot started, the system does not kill the application's process and the virtual memory of the process also exists.

[0139] The virtual space corresponding to a process is described by two data structures, one is mm_struct and the other is vm_area_struct.

[0140] 5 , each process has only one mm_struct structure. The mm_struct structure describes the entire virtual space of a process. The mm_struct structure includes the process's page directory pointer (pgd) and multiple mmap pointers pointing to vm_area_struct structures.

[0141] When the system allocates virtual space to a process, it allocates it by segment. That is, it can allocate multiple virtual memory areas (VMAs) to a process, and each VMA corresponds to a vm_area_struct. If n VMAs are allocated to a process, there will be n vm_area_structs, and the mm_struct structure will contain n pointers (mmap) pointing to different vm_area_struct structures.

[0142] Taking the vm_area_struct corresponding to a virtual interval as an example, vm_start and vm_end respectively represent the starting address and ending address of the area pointed to by the virtual interval.

[0143] vm_flags describes the properties of this virtual interval. Flags can be VM_READ (readable), VM_WRITE (writable), VM_EXEC (executable), or VM_SHARED (shared by multiple processes).

[0144] Other parameters in vm_area_struct are not listed one by one.

[0145] Each virtual interval consists of many virtual pages, and the virtual pages in each virtual interval point to physical pages through page table entries (PTEs) in a page table (PT).

[0146] The page directory pointer pgd points to the page table of the process. The page table records the mapping relationship between virtual pages and physical pages. The page table contains multiple page table entries (PTEs). Each page table entry points to a page frame. The page frame is the physical page in the actual physical memory, in which data can be stored.

[0147] Taking 4GB of virtual memory as an example, it is divided into virtual pages of 4KB. Then there are 1024*1024 virtual pages in the virtual memory. Correspondingly, the page table of the process contains 1024*1024 page table entries PTE.

[0148] When a process needs to access a virtual address, it can find the vm_area_struct where the virtual address is located from the mm_struct structure. If the information recorded in the vm_area_struct indicates that the virtual address has not yet been assigned a physical address, a page fault exception will be triggered, a physical address will be assigned to the virtual address, the relevant information of the virtual address in the vm_area_struct will be modified (for example, changing the unallocated physical memory to allocated physical memory), and the mapping relationship between the virtual address and the physical address will be filled in the PTE corresponding to the virtual address. Therefore, the vm_area_struct and PTE can record the relevant information of all page fault exceptions during the application startup process.

[0149] The embodiment of the present application needs to traverse the PTE to find the PTE filled (or accessed) during the current startup process to generate a PTE snapshot. However, the page table of a process contains 1024*1024 page table entries PTE, and the traversal process is very time-consuming.

[0150] As previously mentioned, when accessing a virtual address, the corresponding PTE can be found from the vm_area_struct. Similarly, when traversing PTEs, the vm_area_struct can be used to quickly determine whether to traverse the PTEs corresponding to each virtual address. As an example, the virtual space corresponding to an application process contains n (e.g., 3, 4, etc.) virtual intervals, each of which corresponds to a vm_area_struct. If no virtual interval in the first virtual interval is mapped to physical memory, there is no need to traverse the vm_area_struct corresponding to that virtual interval. Instead, the vm_area_struct corresponding to the second virtual interval can be jumped to directly, which can speed up PTE traversal. After jumping to the vm_area_struct corresponding to the second virtual interval, the page table is searched for the PTE corresponding to the virtual address that is valid, has a physical address, and is accessible, based on the relevant information of each virtual address in the vm_area_struct corresponding to the second virtual interval (e.g., whether it is valid, whether it has a physical address, and whether it is accessible). This method allows for rapid PTE traversal.

[0151] By using the traversal method described above, PTEs can be quickly traversed to search for memory pages that were filled (or accessed for hot boot) during this startup process. Then, PTE snapshots can be generated based on these found PTEs. When the application is subsequently started, the memory page data can be preloaded in the physical memory based on the stored PTE snapshots, saving the process of loading memory page data in the physical memory during the application startup process. After the memory page data is loaded in the physical memory, the PTEs can be filled when the process startup completes the allocation of virtual space or when a process already has allocated virtual space. This can also reduce the occurrence of page fault exceptions, thereby improving the startup speed of the application.

[0152] In the embodiment of the present application, a five-level mapped page table is used as an example to describe the PTE in the page table.

[0153] 5 , the page table includes a page directory pointer (Page Global Directory, pgd), a page four directory pointer (page four directory, p4d), a page upper directory pointer (Page Upper Directory, pud), a page middle directory pointer (Page Middle Directory, pmd), and a page table entry (Page Table Entry, PTE).

[0154] Each process has a different page directory pointer (PGD). When a new process is created, a new page directory pointer (PGD) is created for it. PGD contains the addresses of several P4Ds, which in turn contain the addresses of several PUDs. PUDs contain the addresses of several PMDSs, which in turn contain the addresses of several page table entries (PTEs). Each PTE points to a page frame, which is the actual physical page in physical memory.

[0155] 6 , which shows an example of the structure of a page table entry PTE.

[0156] Bits 12 to 31 in the PTE are address bits, storing the 4K-aligned starting physical address of the virtual page. Typically, PTE addresses are page-aligned, and since only the upper 20 bits are valid, a page table entry pointing to a physical address only needs the upper 20 bits to represent the physical address. Therefore, the remaining 12 bits can be used for other purposes, such as status bits.

[0157] As an example, the P (also known as present) bit indicates whether the virtual page corresponding to the page table entry has been mapped to the physical memory; if the bit is 0, it means that the mapping has not yet been established for the virtual page, the data corresponding to the virtual page has been swapped out from the physical memory, or the virtual page is no longer in use. When the bit is 0, it indicates that the virtual page corresponding to the page table entry has been mapped to the physical memory.

[0158] The R / W bit indicates the read / write attributes of the physical page pointed to by the virtual page corresponding to the page table entry. For example, 0 is read-only, and 1 is both readable and writable. The R / W bit in the PTE is set by software based on the virtual interval to which the virtual page belongs. That is, the VM_READ / VM_WRITE attributes set for a virtual interval are copied to the PTEs of the virtual pages contained in this virtual interval.

[0159] U / S indicates the access permission of the physical page pointed to by the virtual page corresponding to the page table entry. For example, 0 means that it can only be accessed by the kernel.

[0160] The specific meanings of other bits will not be explained one by one.

[0161] In addition, each PTE corresponds to a pageflag (i.e., page object), which records whether the physical page represented by the PTE belongs to a file page or an anonymous page (anon), as well as the specific type of the file page, for example, active, referenced.

[0162] For an application, only a portion of its PTE pages may be used during startup. For example, 4GB of virtual memory may contain 1024*1024 PTE pages. Therefore, only a portion of these PTE pages may be used during startup. Therefore, valid PTE pages (those used during this startup) need to be screened out. In actual applications, valid PTE pages can be identified from PTEs using their status bits (for example, the P bit indicates that they have been mapped to physical memory). Snapshot information is then generated based on the valid PTE pages to obtain a PTE snapshot for the current startup of the application. This PTE snapshot can be stored on disk (or in physical memory for a hot boot). The next time the application is started, the memory page data corresponding to the information in the PTE snapshot is pre-loaded from disk (or physical memory) into physical memory, eliminating the need to load memory page data from disk or the swap partition into physical memory during startup. Furthermore, if PTEs can be filled, they are pre-filled, thereby reducing the occurrence of page fault exceptions and improving application startup speed.

[0163] It should be noted that when the application is cold-started, if the application version is consistent, the file page read is also fixed. Therefore, after the application cold-start is completed, the valid PTE corresponding to the file page in the page missing information of the application during this cold-start process (for example, it can be determined based on the page object whether it is a file page) (for example, it can be determined based on the P bit that it has been mapped to physical memory) can be used to generate a PTE snapshot corresponding to the cold start and stored in the form of a file on the disk. Therefore, for a cold start, a PTE snapshot can be generated based on the PTE with the page object as a file page, and the file page will be pre-read during a subsequent cold start. Therefore, for a cold start, the method for preloading memory pages provided in the embodiment of the present application can also be understood as a method for preloading file pages.

[0164] During a hot start, the memory reclamation mechanism may require generating a PTE snapshot for the PTEs corresponding to anonymous pages in the page fault information. Furthermore, the application hot start process itself is relatively short, and preloading all file pages may affect the hot start speed. Therefore, you can select certain file page types for generating PTE snapshots based on actual conditions. For example, you can select active and referenced types.

[0165] It should be noted that in actual applications, different status bits can be selected according to actual conditions to determine the physical page for generating the PTE snapshot, or PTEs corresponding to different types of file pages can be selected to generate the PTE snapshot.

[0166] Based on the above description, it can be understood that after the startup is completed, some types of file pages (for example, active, referenced) and anonymous pages in the page fault information during this hot startup process can be used to generate a PTE snapshot corresponding to the hot startup, and stored in the form of a file on the disk, or cached in the memory.

[0167] When the application is subsequently cold started, the PTE snapshot corresponding to the cold start is read from the disk; when the application is subsequently hot started, the PTE snapshot corresponding to the hot start is read from the disk or cache.

[0168] The following describes a specific implementation of the method for preloading memory pages provided in an embodiment of the present application based on the above principles.

[0169] For example, after turning on an electronic device, the user clicks the application icon on the system desktop for the first time. This startup method is called a cold boot. The cold boot process mainly includes:

[0170] The system starts loading and starting the application, creating a process for the application. This process can be recorded as ApplicationStart.

[0171] The system binds the created process to the application, and this process can be recorded as BindApplication.

[0172] The application process creates and starts the first Activity, which is recorded as ActivityStart.

[0173] Create a Choreographer object to monitor Vsync so that drawing tasks can be performed according to the screen refresh rate. This process is recorded as Choreographer.

[0174] Process drawing tasks according to the screen refresh rate. For example, the measurement, layout, and drawing process of the window corresponding to the first Activity. The drawing stage in this process can be recorded as DoFrame.

[0175] As shown in Figure 3, when the application is cold started, page fault exceptions mainly occur in the BindApplication phase, and a small number of page fault exceptions occur in the ActivityStart phase. After the ActivityStart phase ends, page fault exceptions rarely occur.

[0176] Referring to (a) in FIG7 , after the ActivityStart phase ends, the status bits of the PTE in the page table and the pageflag pointed to by the PTE can be traversed to obtain the file pages used during the current cold start of the application, and a PTE snapshot can be generated based on these used file pages.

[0177] As another embodiment of the present application, referring to (b) in Figure 7, after the end of the ActivityStart phase, page fault exceptions will not occur at all, but the probability of occurrence is small. Therefore, in order to reduce the probability of page fault exceptions during subsequent cold starts of the application, the status bits of the PTE in the page table and the pageflag pointed to by the PTE can be traversed at the end of the DoFrame phase (the interface of the first Activity will be displayed after the DoFrame phase ends) or within a certain period of time thereafter to obtain the file pages used during the cold start of this application, and generate PTE snapshots based on the file names of the file page data stored in these used file pages, the storage addresses on the disk, etc.

[0178] The reasons why this PTE snapshot can be used in subsequent cold starts include: during this cold start, the file page data will be read from the disk into the physical memory, and the physical address of the file page data will also be filled in the PTE; in order to be able to read the file page data from the disk into the physical memory in advance during the next cold start, a PTE snapshot can be generated based on the file name of the file page data in the physical page corresponding to the physical address in the PTE filled this time and the storage address of the file page data on the disk. In this way, during subsequent cold starts, the storage address of the file page data on the disk used in the application cold start process can be obtained based on the PTE snapshot, and this part of the file page data can be read from the disk into the physical memory. After the application process is started and the virtual space is allocated, a mapping relationship can be established between the physical address and the virtual address of this part of the file page data in the physical memory, and the PTE can be continued to be filled. In this way, the occurrence of page fault exceptions can be reduced.

[0179] As another embodiment of the present application, in actual applications, it is also possible to traverse the status bits of the PTE in the page table and the pageflag pointed to by the PTE at any time point between the end of the ActiveStart phase and the end of the DoFrame phase to obtain the file pages used during the cold start of this application, and generate a PTE snapshot based on these used file pages.

[0180] Regardless of the time point listed above, the PTE snapshot generated can be stored on the electronic device's disk for use by the application during a subsequent cold restart. Of course, the PTE snapshot can be stored on the electronic device's disk at a later time, as long as it can be successfully stored during the next cold restart. For example, it can be stored immediately after generation, or when the application switches to background operation or ends.

[0181] Referring to (c) in Figure 7, during the subsequent cold start process of the application, since page fault exceptions mainly occur in the BindApplication stage and thereafter, it is necessary to read the PTE snapshot stored during the application's historical cold start from the electronic device's disk before the BindApplication stage, and then load the file page data required by the application's process into physical memory based on the information recorded in the PTE snapshot, saving the process of loading file page data during the startup process. Subsequently, after BindApplication (after BindApplication, the process has been fully started and virtual space has been allocated), the PTE information can be filled in, reducing the probability of page fault exceptions in the subsequent startup process and increasing the speed of application startup.

[0182] As another embodiment of the present application, after the electronic device receives a click operation on the application icon on the system desktop and before the start of the BindApplication phase, it can read the PTE snapshot stored during the application's historical cold start from the electronic device's disk. Then, based on the information recorded in the PTE snapshot, the file page data required by the application process is loaded into physical memory, saving the process of loading file page data during the startup process. Subsequently, after BindApplication, the PTE information can be filled in, reducing the probability of subsequent page fault exceptions and improving the speed of application startup.

[0183] The hot start of an application means that after the application returns to the background, the application process is not destroyed. Therefore, in a hot start, starting from ActivityStart, the hot start process of the application mainly includes:

[0184] The application process creates and starts the activity before returning to the background last time. This process is recorded as ActivityStart.

[0185] The last time the Activity returned to the background, it entered the resume state. This process is recorded as ActivityResume.

[0186] Create a Choreographer object to monitor Vsync so that drawing tasks can be performed according to the screen refresh frequency. This process is recorded as Choreographer.

[0187] Process drawing tasks according to the screen refresh rate. For example, the measurement, layout, and drawing process of the window corresponding to the first Activity. The drawing stage in this process can be recorded as DoFrame.

[0188] As can be understood from Figure 4, when the application is hot started, page fault exceptions mainly occur in the ActivityStart stage, ActivityResume stage, and Choreographer stage.

[0189] Referring to (a) in Figure 8, at the end of or after the DoFrame phase, the PTE in the page table can be traversed, and based on the status bit and the pageflag pointed to by the PTE, some file pages used during the current application hot start (for example, the selection of Active type and referenced type file pages is determined based on the pageflag corresponding to the PTE) and anonymous pages (for example, the selection of anon type is determined based on the pageflag corresponding to the PTE), and a PTE snapshot is generated based on these used file pages and anonymous pages.

[0190] In actual applications, the duration of the hot start itself is relatively short. If all the page fault exception information during the hot start process is still obtained, the process of reading the PTE snapshot from the disk or memory and preloading it during the subsequent hot start will become longer, which undoubtedly prolongs the hot start duration. Therefore, a balance can be struck between the time consumed in preloading and the time consumed incurred by the page fault exception. For example, by selecting the more important page fault exception information during the hot start process to generate the PTE snapshot, the preloading time during the subsequent hot start will become shorter, thereby reducing the overall duration of the hot start.

[0191] Most of the important page fault exception information during the hot start process is in the ActivityStart stage. Referring to (b) in Figure 8, at the end of the ActivityStart stage or a short time thereafter, the PTE status bits in the page table and the pageflag pointed to by the PTE can be traversed to obtain some file pages used during the current application hot start (for example, the active type and referenced type file pages are selected based on the pageflag corresponding to the PTE) and anonymous pages (for example, the anon type is selected based on the pageflag corresponding to the PTE). A PTE snapshot is generated based on these used file pages and anonymous pages.

[0192] As another embodiment of the present application, at any time point between the ActivityStart stage and the end of the DoFrame stage, the status bits of the PTE in the page table and the pageflag pointed to by the PTE can be traversed to obtain some file pages used during the hot start of this application (for example, the selection of active type and referenced type file pages is determined according to the pageflag corresponding to the PTE) and anonymous pages (for example, the selection of anon type is determined according to the pageflag corresponding to the PTE), and a PTE snapshot is generated based on the information of these used file pages and anonymous pages (for example, the file name of the file stored in the file page, the storage address on the disk, and other information, and the storage address of the data stored in the anonymous page in the swap partition).

[0193] The PTE snapshot generated at any of the above-listed time points can be stored in the memory or disk of the electronic device for use in subsequent hot starts of the application.

[0194] Referring to (c) in Figure 8, during the subsequent hot start process of the application, since page fault exceptions have already occurred in large numbers in the ActivityStart stage, it is necessary to read the PTE snapshot stored during the historical hot start of the application from the memory or disk of the electronic device before the ActivityStart stage, and then load the file page data and anonymous page data required by the application process according to the information recorded in the PTE snapshot. Since the process itself exists in the system during hot start and the virtual space of the process has been allocated, the PTE information can be pre-filled, which reduces the probability of page fault exceptions and improves the speed of application startup.

[0195] As another embodiment of the present application, after the electronic device detects the hot start of the application, it can read the PTE snapshot stored during the historical hot start of the application from the memory or disk of the electronic device, and then load the file page data and anonymous page data required by the application process according to the information recorded in the PTE snapshot, so that the PTE information can be pre-filled, reducing the probability of page fault exceptions and improving the speed of application startup.

[0196] In order to more clearly understand the method for preloading memory pages provided in an embodiment of the present application, the process of obtaining and storing a PTE snapshot and the process of preloading a PTE snapshot will be described in detail below.

[0197] Linux divides the virtual address space into two parts: user space and kernel space. User space cannot directly access kernel space. When a user process needs to access the kernel or use kernel functions, it needs to use system calls.

[0198] The kernel space provides the function entry of the system call; in order to enable the user space to use the entry of these system calls, these system calls can be encapsulated in the user space to obtain an encapsulation interface that can be directly used by the user space process.

[0199] When a user-space process needs to use a system call to access hardware devices or operating system resources, the user-space process uses the system call through the encapsulation interface. The system call then accesses the hardware device or system resources through kernel functions in the kernel. In other words, the system call serves as an information exchange between user space and kernel space.

[0200] Referring to the system architecture diagram shown in FIG9 , there are multiple applications at the application layer, for example, application A and application B.

[0201] The application framework layer includes a monitoring module, a pre-reading module, and a capturing module. The pre-reading module and the capturing module can exist as one module or as two independent modules.

[0202] The monitoring module can be a separate module for monitoring the application startup process, or it can be some service in the system that can monitor the application startup process. After monitoring that the application has started at a certain time point (for example, a time point that requires pre-reading), the monitoring module can send a pre-reading instruction to the pre-reading module. After monitoring that the application has started at a certain time point (for example, after the DoFrame stage), the monitoring module can send a capture instruction to the capture module.

[0203] After the pre-reading module receives the pre-reading instruction (or the capturing module receives the capturing instruction), a system call may be made to transmit the unique identifier and the starting mode of the application currently being started to the called kernel function.

[0204] There are kernel functions in the kernel layer, which are used to implement different functions, such as the pre-reading function provided in the embodiment of the present application, and the function of traversing PTE to generate PTE snapshots provided in the embodiment of the present application.

[0205] The hardware layer includes disks and physical memory. Disks are used to store PTE snapshots generated during cold boots and file page data required during application startup. During subsequent boots, the kernel first reads the PTE snapshots from disk and then preloads the file page data corresponding to the information recorded in the PTE snapshots from disk into physical memory. PTE snapshots generated during hot boots can be stored on disk or in physical memory as needed.

[0206] To better understand the interaction between the various modules, refer to the timing diagram of the process of generating and storing PTE snapshots during application cold start shown in Figure 10. The monitoring module and capture module are located in user space, and the kernel is located in kernel space.

[0207] S101: The monitoring module detects that the application runs to a capture node when it starts.

[0208] In the embodiment of the present application, if the startup process of the application is a cold start, the capture node is any node pre-set between the nodes shown in (a) to (b) in FIG. 7 .

[0209] S102: After monitoring that the application runs to the capture node when it starts, the monitoring module sends a capture instruction to the capture module.

[0210] S103: The capture module makes a system call and transmits the unique identifier and the startup mode identifier of the application currently being started to the called kernel function.

[0211] In an embodiment of the present application, each application has a unique identifier, which is used to distinguish different applications, so that the unique identifier of the application is associated when storing the PTE snapshot corresponding to the application to distinguish it from the PTE snapshots of other applications; the startup method is used to determine whether the PTE snapshot generated is a hot start or a cold start.

[0212] In the embodiment of the present application, the startup mode identifier indicates that this startup is a cold start.

[0213] S104: The kernel traverses the PTE to obtain information about valid file pages in this startup process.

[0214] If the boot mode identifier indicates that this boot is a cold boot, the file names and storage addresses in the disk space of all valid file pages (for example, valid file pages are: the PTE status bit indicates that it has been mapped to the physical address, and pageflag is the file page) are obtained.

[0215] S105, the kernel generates a PTE snapshot based on the information of the valid file page traversed. Of course, the PTE snapshot can also include other information of the file page data, and this embodiment of the application does not limit this.

[0216] S106: The kernel stores the cold start PTE snapshot corresponding to the application identifier in the disk.

[0217] In this way, you can get all the valid file page information during the application cold start process, so that you can prepare it for subsequent cold starts of the application.

[0218] Refer to the timing diagram of the process of pre-reading PTE snapshots during application cold start shown in Figure 11. The monitoring module and the pre-reading module are located in the user space, and the kernel is located in the kernel space.

[0219] S111, the monitoring module detects that the application starts and reaches the pre-read node.

[0220] In the embodiment of the present application, if the current startup process of the application is a cold start, the pre-read node is any node before the start of BindApplication as shown in (c) in FIG7 .

[0221] S112 , after detecting that the application starts and proceeds to the pre-reading node, the monitoring module sends a pre-reading instruction to the pre-reading module.

[0222] S113, the pre-reading module makes a system call, and transmits the unique identifier and the startup mode of the application currently being started to the called kernel function.

[0223] In the embodiment of the present application, each application has a unique identifier, which is used to distinguish different applications to obtain the PTE snapshot corresponding to the application; the startup mode identifier is used to determine whether to obtain the PTE snapshot during the historical hot start or the historical cold start.

[0224] The startup mode identifier in the embodiment of the present application indicates that this startup is a cold start.

[0225] S114 , after being called by the system, the kernel may read the PTE snapshot corresponding to the application identifier during the cold start from the disk based on the received application identifier.

[0226] S115, after the kernel reads the PTE snapshot, it loads the file page data corresponding to the PTE snapshot read from the disk into the physical memory.

[0227] Subsequently, after the application process is started and successfully applies for virtual space, the kernel can fill in the PTE information in the page table of the process corresponding to the application identifier according to the current physical address of the file page data loaded in the physical memory (for example, fill in the mapping relationship between the virtual address and the physical address).

[0228] This preloading method can pre-load the file page information required during the application cold start process in the physical memory, saving the process of loading file page data during the startup process. In addition, the PTE information can be filled after the application process is started and the virtual memory is applied, reducing the occurrence of page fault exceptions and improving the speed of application cold start.

[0229] It should be noted that the following logic is also implemented in the specific implementation: if the disk already stores the PTE snapshot from the previous cold start of the same application, then the subsequent cold start does not need to store the same PTE snapshot again. Accordingly, the pre-read process will only be performed during the application cold start if the disk has stored the PTE snapshot from the previous cold start of the application.

[0230] 12 , which is a logic flow chart of a cold start of an application according to an embodiment of the present application.

[0231] At some point after the cold start begins, the kernel will passively receive pre-read information (this information is used to indicate pre-reading). The pre-read information carries the application identifier and the boot mode identifier. The kernel will determine whether the disk has a PTE snapshot corresponding to the application identifier and the boot mode identifier; if the disk has a PTE snapshot corresponding to the application identifier and the boot mode identifier, the kernel will read the PTE snapshot from the disk and load the file page data corresponding to the PTE snapshot into the physical memory; of course, if the disk does not have a PTE snapshot corresponding to the application identifier and the boot mode identifier, the process ends.

[0232] At some point after the cold start begins, the kernel will passively receive capture information (this information is used to instruct the capture of PTE snapshots). Usually, the capture information is received later than the pre-read information. The capture information carries the application identifier and the boot mode identifier. The kernel will determine whether the disk has a PTE snapshot corresponding to the application identifier and the boot mode identifier. If the disk does not have a PTE snapshot corresponding to the application identifier and the boot mode identifier, it will traverse the PTE, generate a PTE snapshot based on the valid file pages, and associate the PTE snapshot with the received application identifier and the boot mode identifier and store it on the disk. Of course, if the disk has a PTE snapshot corresponding to the application identifier and the boot mode identifier, the process ends.

[0233] In actual applications, when an application is uninstalled, the PTE snapshot of the application needs to be deleted from the disk.

[0234] 13 , which is a logic flow chart of when an application provided in an embodiment of the present application is uninstalled.

[0235] The kernel receives a deletion message (instructing the deletion of a PTE snapshot) that carries an application identifier. The kernel determines whether a PTE snapshot corresponding to the application identifier exists on disk. If so, the kernel deletes the corresponding PTE snapshot from disk. If not, the process ends.

[0236] The above embodiment uses the application cold start as an example to describe the interaction between the various modules. The following uses the application hot start as an example to describe the interaction between the various modules. The main differences between the application hot start and the cold start are:

[0237] (1) The timing of pre-reading is different. However, for the kernel, the information indicating pre-reading is received passively.

[0238] (2) The timing of capturing a PTE snapshot can be different. Similarly, for the kernel, it passively receives information indicating that a snapshot has been captured.

[0239] (3) The page fault information used to generate the PTE snapshot is different, and accordingly, the memory page data loaded is different. During a cold start, the kernel can generate a PTE snapshot based on all valid file pages of the application, and accordingly, the file page data is loaded; during a hot start, the kernel can generate a PTE snapshot based on some valid file pages and valid anonymous pages of the application. During a hot start, the kernel can also generate a PTE snapshot based on the most recently accessed memory pages with reference to the pte_young in the PTE status bit, and accordingly, the file page data and anonymous page data are loaded.

[0240] (4) The operations after loading the memory page data corresponding to the PTE snapshot into physical memory are different. During a cold start, after loading the file page data corresponding to the PTE snapshot into physical memory, the kernel must wait for the application process to start and complete the virtual memory allocation before continuing to fill the PTE. During a hot start, the application process already exists and has already allocated virtual memory. Therefore, the kernel can establish a mapping relationship between virtual addresses and physical addresses based on the physical address of the file page data loaded into physical memory and fill the PTE.

[0241] (5) The storage space for PTE snapshots may vary. The PTE snapshot corresponding to a cold start needs to be stored on disk. The PTE snapshot corresponding to a hot start can be stored on disk or in memory. This is because when the application process is killed, the application-related information stored in memory will be cleared. Therefore, even if the PTE snapshot corresponding to the application's cold start is stored in memory, the PTE snapshot in memory will have been cleared when the application is cold started next time, and pre-reading will not be possible.

[0242] In addition, during hot start, if the PTE snapshot is stored in physical memory, the memory space storing the PTE snapshot, the memory space storing the page table, and the memory space storing other data of the application (for example, code segments, etc.) are different storage spaces in the physical memory.

[0243] Of course, if you have set the PTE snapshot to be stored in physical memory, the PTE snapshot at the time of hot start of this application will be read from physical memory during pre-reading. If you have set the PTE snapshot to be stored on disk, the PTE snapshot at the time of hot start of this application will be read from disk during pre-reading.

[0244] The interaction diagrams between the modules during hot start of the application may refer to the interaction diagrams between the modules during cold start of the application shown in FIG. 10 and FIG. 11 .

[0245] 14 , which is a processing logic diagram of the kernel during application hot start according to the present application.

[0246] At some point after the start of the hot boot, the kernel will passively receive pre-read information (this information is used to indicate pre-reading). The pre-read information carries the application identifier and the boot mode identifier. The kernel will determine whether the physical memory (or disk) has a PTE snapshot corresponding to the application identifier and the boot mode identifier; if the physical memory (or disk) has a PTE snapshot corresponding to the application identifier and the boot mode identifier, the memory page data (including file page data and anonymous page data) corresponding to the PTE snapshot will be loaded into the physical memory, and the PTE information will be filled in the page table according to the physical address of the memory page data (for example, the mapping relationship between the virtual address and the physical address will be filled); of course, if the physical memory (or disk) does not have a PTE snapshot corresponding to the application identifier and the boot mode identifier, the process ends.

[0247] At some point after the start of the hot boot, the kernel will passively receive capture information (this information is used to indicate the capture of PTE snapshots). Usually, the capture information is received later than the pre-read information. The capture information carries the application identifier and the boot mode identifier. The kernel will determine whether the physical memory (or disk) has a PTE snapshot corresponding to the application identifier and the boot mode identifier. If the physical memory (or disk) does not have a PTE snapshot corresponding to the application identifier and the boot mode identifier, the PTE is traversed and a PTE snapshot is generated based on valid file pages of some types and valid anonymous pages. The PTE snapshot is associated with the received application identifier and the boot mode identifier and stored in the physical memory (or disk). Of course, if the physical memory (or disk) has a PTE snapshot corresponding to the application identifier and the boot mode identifier, the process ends.

[0248] In actual applications, when an application is uninstalled, the PTE snapshot of the application also needs to be deleted from the physical memory (or disk).

[0249] As another embodiment of the present application, the startup mode of the application may also include a warm startup. Warm startup and hot startup may be combined into one startup mode using the same startup process. The application startup method provided in the embodiment of the present application can be applied to a variety of startup modes of the application. The embodiment of the present application starts three times on multiple applications in three startup modes, and the overall latency is reduced by 13%. The IO wait of the UI thread (i.e., how much time in a sampling period is the CPU idle and there is at least one unfinished disk IO request) is reduced by 47%. For details, please refer to Table 1 and Figure 15.

[0250] Table 1 Comparison of latency, IO wait, and benefits between the native process and the application startup method provided by this application (unit: ms)

[0251] It can be understood from Table 1 that the method of preloading memory pages during application startup provided by the embodiment of the present application can improve the total latency by more than 10%; and can improve the IO wait even more.

[0252] To more clearly compare the latency of the two application startup methods, refer to the latency comparison diagram shown in Figure 15. The total latency and IO wait of the application startup method provided by this application are significantly lower than those of the native process.

[0253] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0254] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.

[0255] An embodiment of the present application further provides a computer program product. When the computer program product is run on a first device, the electronic device can implement the steps in the above-mentioned various method embodiments.

[0256] 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 present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and when the computer program is executed by the processor, it can implement the steps of the above-mentioned various method embodiments. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include at least: any entity or device capable of carrying the computer program code to the first device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electric carrier signal, a telecommunication signal and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.

[0257] The present application also provides a chip system, comprising a processor coupled to a memory, the processor executing a computer program stored in the memory to implement the steps of any method embodiment of the present application. The chip system can be a single chip or a chip module composed of multiple chips.

[0258] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.

[0259] Those skilled in the art will appreciate that the units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0260] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the scope of protection of the present application.

Claims

1. A method for preloading memory pages, It is characterized in that The method is applied to a kernel of an electronic device, and comprises: Receiving pre-read information, the pre-read information including an identifier of the first application and a hot start identifier; In response to the pre-read information, reading a page table entry snapshot corresponding to the identifier of the first application from a first storage space; Loading the file page data corresponding to the page table entry snapshot in the second storage space and the anonymous page data corresponding to the third storage space into the physical memory; A mapping relationship between the virtual memory of the file page data and the physical memory of the file page data and a mapping relationship between the virtual memory of the anonymous page data and the physical memory of the anonymous page data are written into the page table entry of the first application.

2. The method according to claim 1, It is characterized in that The method further includes: generating the page table entry snapshot based on the page table entry accessed during the first application history hot start process, wherein the page objects in the page table entry are file pages and anonymous pages.

3. The method according to claim 2, It is characterized in that The first storage space is a physical memory or a disk, the second storage space is a disk, and the third storage space is a swap partition.

4. The method according to claim 3, It is characterized in that Before receiving the pre-read information, the method further includes: receiving capture information, the capture information including an identifier of the first application and a hot start identifier; In response to the captured information, generating a snapshot of a page table entry corresponding to the identifier of the first application according to the page table entry corresponding to the identifier of the first application, wherein the page objects in the page table entry are file pages and anonymous pages; The page table entry snapshot corresponding to the identifier of the first application is stored in the first storage space.

5. The method according to claim 4, It is characterized in that The step of generating, in response to the captured information, a snapshot of a page table entry corresponding to the identifier of the first application according to the page table entry corresponding to the identifier of the first application, comprises: In response to the captured information, determining that a page table entry snapshot corresponding to the identifier of the first application does not exist in the first storage space; A page table entry snapshot corresponding to the identifier of the first application is generated according to the page table entry corresponding to the identifier of the first application, wherein the page objects in the page table entry are file pages and anonymous pages.

6. The method according to claim 4 or 5, It is characterized in that The generating, according to the page table entry corresponding to the identifier of the first application, a snapshot of the page table entry corresponding to the identifier of the first application includes: The status bit in the page table corresponding to the identifier of the first application is set to a preset character, and the page object is a page table item of a preset type, and a snapshot of the page table item corresponding to the identifier of the first application is generated. The preset character is used to indicate that the virtual memory corresponding to the page table item has been mapped to the physical memory and has been accessed, and the preset types include active, referenced, and anon.

7. The method according to any one of claims 1 to 5, It is characterized in that The method further comprises: receiving deletion information, wherein the deletion information includes an identifier of the first application; In response to the deletion information, the page table entry snapshot corresponding to the identifier of the first application stored in the first storage space is deleted.

8. The method according to any one of claims 1 to 3, It is characterized in that The page table entry includes a mapping relationship from virtual memory to physical memory, and the page table entry snapshot includes a file name of the file page data corresponding to the page table entry and a storage address of the file page data in the disk, as well as a storage address of the anonymous page data corresponding to the page table entry in the swap partition.

9. An electronic device, It is characterized in that The electronic device comprises a processor, and the processor is used to run a computer program stored in a memory, so that the electronic device implements the method according to any one of claims 1 to 8.

10. A chip system, It is characterized in that The method comprises a processor coupled to a memory, wherein the processor executes a computer program stored in the memory to implement the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Method and device for pre-reading file pages and storage medium

    CN108763104A

  • Method for accelerating starting of application program and electronic equipment

    CN112783564A

  • Method for adjusting pre-reading window and electronic equipment

    CN114461588A

  • Memory page processing method and device and electronic equipment

    CN115629875A

  • Method for preloading memory page, electronic equipment and chip system

    CN115858046A

Cited By

  • Method and device for loading video track

    CN119729101A