Pre-reading method and electronic device
By aggregating file access addresses through the pre-reading method, the problem of page missing exceptions during application startup is solved, and memory access efficiency and user experience are improved.
Patent Information
- Application Number
- CN202410524726.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-28
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2044-04-28
AI Technical Summary
Due to memory size limitations, page fault exceptions may occur during application startup and transition, resulting in a longer application startup time and affecting user experience.
The pre-read method is used to obtain file access information when the application is started. The pre-read calculation parameters are calculated based on the remaining memory space status, and the file access addresses are aggregated to reduce the number of IO accesses and improve the data reading speed.
Effectively speed up the pre-reading rate of application startup scenarios, shorten application startup time, and improve user experience.
Smart Images

Figure CN119271575B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal devices, and in particular to a pre-reading method and electronic equipment. Background Art
[0002] As electronic devices become increasingly powerful, more and more applications are installed. Users can use the functions provided by these applications based on the installed applications. Currently, due to memory size limitations, memory recycling mechanisms are often used in user scenarios such as application startup and transitions. Due to this mechanism, page faults may occur when an application accesses memory again, resulting in longer application startup times and a poor user experience. Summary of the Invention
[0003] In order to solve the above technical problems, the present application provides a pre-reading method and an electronic device to effectively improve the efficiency of application access to memory.
[0004] In the first aspect, the present application provides a pre-reading method, which is applied to an electronic device, and the method includes: during the application startup process, obtaining the file access information of the application, the file access information includes multiple files that need to be accessed when the application is started and multiple access addresses corresponding to each file. Based on the current memory remaining space status, obtain the pre-reading calculation parameters. Based on the pre-reading calculation parameters and the file access information, obtain the pre-reading acquisition information corresponding to the application; the pre-reading acquisition information includes the access address information of at least one file among the multiple files, the access address information includes N access addresses, N is an integer greater than 0, and the N value is less than the number of access addresses corresponding to the file in the file access information, and the N access addresses corresponding to each file cover the multiple access addresses of the corresponding file. During the next startup of the application, based on the pre-reading acquisition information, read the data corresponding to the N access addresses corresponding to each file in at least one file. In this way, the present application can effectively reduce the number of IO accesses by processing the access addresses of the files required for application startup and converting multiple access addresses into N access addresses. Furthermore, in this application, the remaining memory space is associated with pre-read calculation parameters, which can be adjusted based on the remaining memory space. This improves the coverage accuracy of the N access addresses of each file in the pre-read collection information and increases the data reading speed during data pre-reading. This effectively speeds up the pre-read rate of the next application startup scenario, improves the efficiency of application startup, shortens the application startup time, and enhances the user experience.
[0005] Exemplarily, N is a smaller value, such as a value between 3 and 5. Usually, the number of multiple access addresses corresponding to a file is large, for example, it may be dozens to thousands. By setting a smaller N value, the excessive access addresses are converted into a smaller number of access addresses, which can effectively reduce the number of IO accesses during the data reading process, reduce storage pressure, and increase the data reading rate.
[0006] In one possible implementation, the pre-read calculation parameters include an N value and a step threshold. Thus, in this application, based on the N value and step threshold obtained based on the remaining memory space, two values associated with the size of the remaining memory space can be obtained, and these two values can be adjusted according to changes in the remaining memory space to achieve dynamic adjustment of the address aggregation conditions to adapt to different usage scenarios.
[0007] In one possible implementation, pre-read calculation parameters are obtained based on the current remaining memory space status, including: calculating an N value based on the remaining memory space status; and calculating a step threshold based on the remaining memory space status. Thus, in this application, the N value and step threshold obtained based on the remaining memory space can be used to obtain two values associated with the remaining memory space size. These two values can then be adjusted based on changes in the remaining memory space to achieve dynamic adjustment of address aggregation conditions to accommodate different usage scenarios.
[0008] In one possible implementation, based on pre-read calculation parameters and file access information, pre-read collection information corresponding to the application is obtained, including: based on a step threshold, address aggregation of multiple access addresses for each file to obtain N access addresses corresponding to each file. In this way, after calculating the step threshold using the remaining memory space, the application can further aggregate the addresses based on the step threshold, thereby reducing the number of file access addresses and achieving the effect of reducing the number of IO accesses, thereby effectively accelerating the pre-read rate of the next application startup scenario, improving the efficiency of application startup, shortening the application startup time, and improving the user experience.
[0009] In one possible implementation, based on a step threshold, multiple access addresses of each file are aggregated to obtain N access addresses corresponding to each file, including: aggregating the access addresses in the address range that satisfies the step threshold indication among the multiple access addresses in each file. In an embodiment of the present application, "the address range that satisfies the step threshold indication" means that the step between the access address of this traversal and the access address of the previous traversal is less than the step threshold. The step between the access addresses refers to the difference between the starting address of the current access address and the ending address of the previous access address. In this way, by setting the step threshold as a condition for address aggregation, the access addresses that meet the conditions can be merged, thereby reducing the number of access addresses to reduce the number of IO accesses when reading data.
[0010] In one possible implementation, obtaining pre-read collection information corresponding to an application based on pre-read calculation parameters and file access information includes: obtaining access address information for m files from a plurality of files based on the pre-read calculation parameters and file access information; sorting the m files based on their corresponding access counts; and retaining the access address information of at least one file in the sorted m files. Thus, by sorting the files based on access counts, pre-read collection information corresponding to files with a high access count can be retained, thereby reducing memory usage.
[0011] In one possible implementation, reading data corresponding to N access addresses corresponding to each file in at least one file based on pre-read collection information includes reading data corresponding to the N access addresses corresponding to each file in the at least one file based on merged pre-read collection information, wherein the merged pre-read collection information is obtained based on the pre-read collection information and the most recently acquired pre-read collection information corresponding to the application. In this way, by merging the current and previous pre-read collection information, the accuracy of the pre-read collection information can be improved, thereby accelerating the data reading rate during the next pre-read.
[0012] In a second aspect, the present application provides an electronic device comprising: one or more processors, a memory; and one or more computer programs, wherein the one or more computer programs are stored in the memory, and when the computer programs are executed by the one or more processors, the electronic device performs the following steps: during application startup, obtaining file access information of the application, the file access information including multiple files that need to be accessed when the application is started and multiple access addresses corresponding to each file; based on the current remaining memory space status, obtaining pre-read calculation parameters; based on the pre-read calculation parameters and the file access information, obtaining pre-read collection information corresponding to the application; the pre-read collection information includes access address information of at least one file among the multiple files, the access address information includes N access addresses, N is an integer greater than 0, and the N value is less than the number of access addresses corresponding to the file in the file access information, and the N access addresses corresponding to each file cover multiple access addresses of the corresponding file; during the next startup of the application, based on the pre-read collection information, read the data corresponding to the N access addresses corresponding to each file in at least one file.
[0013] In a possible implementation, the pre-reading calculation parameters include an N value and a step threshold.
[0014] In one possible implementation, when the computer program is executed by one or more processors, the electronic device performs the following steps: calculating the N value based on the remaining memory space status; and calculating the step threshold based on the remaining memory space status.
[0015] In one possible implementation, when the computer program is executed by one or more processors, the electronic device performs the following steps: based on a step threshold, aggregating multiple access addresses of each file to obtain N access addresses corresponding to each file.
[0016] In a possible implementation, when the computer program is executed by one or more processors, the electronic device performs the following steps: performing address aggregation on access addresses in each file that meet an address range indicated by a step threshold among multiple access addresses in the file.
[0017] In one possible implementation, when the computer program is executed by one or more processors, the electronic device performs the following steps: based on pre-read calculation parameters and file access information, obtain access address information of m files among n files; sort the m files based on the number of accesses corresponding to the m files; and retain the access address information of at least one file in the sorted m files.
[0018] In one possible implementation, when the computer program is executed by one or more processors, the electronic device performs the following steps: based on the merged pre-read acquisition information, reads the data corresponding to N access addresses corresponding to each file in at least one file, wherein the merged pre-read acquisition information is obtained based on the pre-read acquisition information and the pre-read acquisition information corresponding to the application most recently acquired.
[0019] The second aspect and any implementation of the second aspect correspond to the first aspect and any implementation of the first aspect, respectively. The technical effects corresponding to the second aspect and any implementation of the second aspect can be referred to the technical effects corresponding to the first aspect and any implementation of the first aspect, and will not be repeated here.
[0020] In a third aspect, the present application provides a computer-readable medium for storing a computer program, wherein the computer program includes instructions for executing the method in the first aspect or any possible implementation of the first aspect.
[0021] In a fourth aspect, the present application provides a computer program comprising instructions for executing the method in the first aspect or any possible implementation of the first aspect.
[0022] In a fifth aspect, the present application provides a chip comprising a processing circuit and a transceiver pin. The transceiver pin and the processing circuit communicate with each other via an internal connection path, and the processing circuit executes the method of the first aspect or any possible implementation of the first aspect to control the receive pin to receive a signal and to control the transmit pin to send a signal. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 is a schematic diagram of the hardware structure of an electronic device shown as an example;
[0024] Figure 2 is a schematic diagram of the software structure of an electronic device shown as an example;
[0025] Figure 3 is a schematic diagram of memory access shown as an example;
[0026] Figure 4 FIG1 is a schematic diagram of an exemplary page fault exception handling process;
[0027] Figure 5 1 is a flowchart of an exemplary pre-reading method;
[0028] Figure 6 is a schematic diagram of an exemplary data structure;
[0029] Figure 7 A flowchart of steps performed by a kernel node is shown as an example;
[0030] Figure 8 The figure is a schematic diagram of an exemplary process for obtaining pre-read calculation parameters;
[0031] Figure 9 This is a schematic diagram of an exemplary process for obtaining pre-reading collected information;
[0032] Figure 10 1 is a flowchart of an exemplary pre-reading method;
[0033] Figure 11 Schematic diagram of the structure of the device shown as an example. DETAILED DESCRIPTION
[0034] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0035] The term "and / or" in this article is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0036] In the description and claims of the embodiments of this application, the terms "first" and "second" are used to distinguish different objects, rather than to describe a specific order of objects. For example, the terms "first target object" and "second target object" are used to distinguish different objects, rather than to describe a specific order of objects.
[0037] In the embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be interpreted as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0038] In the description of the embodiments of this application, unless otherwise specified, "multiple" means two or more. For example, "multiple processing units" means two or more processing units; "multiple systems" means two or more systems.
[0039] Optionally, in an embodiment of the present application, the terminal device may be a mobile terminal such as a mobile phone with a shooting function, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc. The embodiment of the present application does not limit the specific type of the terminal device.
[0040] Figure 1 1 shows a schematic diagram of the structure of the electronic device 100. It should be understood that, Figure 1 The illustrated electronic device 100 is merely one example of an electronic device, and the electronic device 100 may have more or fewer components than shown in the figures, may combine two or more components, or may have a different configuration of components. Figure 1 The various components shown in the drawings may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.
[0041] The 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, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.
[0042] 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 baseband processor, and / or a neural-network processing unit (NPU). The different processing units may be independent devices or integrated into one or more processors.
[0043] 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.
[0044] 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 access the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.
[0045] In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface.
[0046] The charging management module 140 is configured to receive charging input from a charger. The charger can be either a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 can receive charging input from the wired charger via the USB interface 130. In some wireless charging embodiments, the charging management module 140 can receive wireless charging input via the wireless charging coil of the electronic device 100. While charging the battery 142, the charging management module 140 can also provide power to the electronic device via the power management module 141.
[0047] 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, and provides power to the processor 110, the internal memory 121, the external memory, the display 194, the camera 193, and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle count, and battery health status (leakage, impedance). In some other embodiments, the power management module 141 can also be set in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 can also be set in the same device.
[0048] 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.
[0049] 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.
[0050] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G applied to 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), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.
[0051] The modem processor may include a modulator and a demodulator. The modulator is used to modulate the low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After being processed by the baseband processor, the low-frequency baseband signal is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to the speaker 170A, the receiver 170B, etc.) or displays an image or video through the display screen 194. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.
[0052] 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 integrating 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.
[0053] In some embodiments, the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology. The GNSS may include a global positioning system (GPS), a global navigation satellite system (GLONASS), a BeiDou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS) and / or a satellite-based augmentation system (SBAS).
[0054] 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.
[0055] 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.
[0056] The electronic device 100 can implement a shooting function through an ISP, a camera 193, a video codec, a GPU, a display screen 194, and an application processor.
[0057] The ISP processes data fed back by camera 193. For example, when taking a photo, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, which is then passed to the ISP for processing and converted into a visible image. The ISP can also perform algorithmic optimization on image noise, brightness, and skin tone. It can also optimize parameters such as exposure and color temperature of the captured scene. In some embodiments, the ISP can be located within camera 193.
[0058] 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.
[0059] The digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals. For example, when the electronic device 100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0060] Video codecs are used to compress or decompress digital video. Electronic device 100 may support one or more video codecs. This allows electronic device 100 to play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, and MPEG4.
[0061] The NPU is a neural network (NN) computing processor. Drawing on the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it rapidly processes input information and can continuously self-learn. The NPU can enable intelligent cognitive applications in electronic device 100, such as image recognition, face recognition, speech recognition, and text comprehension.
[0062] 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.
[0063] The internal memory 121 can be used to store computer executable program codes, which include 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. Among them, the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area can store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. 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.
[0064] 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.
[0065] The audio module 170 is used to convert digital audio information into analog audio signal 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.
[0066] The software system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. In the embodiment of the present application, the Android system with a layered architecture is used as an example to illustrate the software structure of the electronic device 100.
[0067] Figure 2 It is a software structure block diagram of the electronic device 100 according to an embodiment of the present application.
[0068] The layered architecture of electronic device 100 divides the software into several layers, each with a clear role and division of labor. Layers communicate with each other via software interfaces. In some embodiments, the Android system is divided into four layers: from top to bottom, the application layer, the application framework layer, the Android runtime and system libraries, and the kernel layer.
[0069] The application layer can include a series of application packages.
[0070] like Figure 2 As shown, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc.
[0071] The application framework layer provides an application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0072] like Figure 2 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.
[0073] The window manager is used to manage window programs. The window manager can obtain the display size, determine whether there is a status bar, lock the screen, take screenshots, etc.
[0074] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0075] The view system includes visual controls, such as those for displaying text and images. The view system is used to build applications. A display interface can consist of one or more views. For example, a display interface containing a text notification icon might include a view for displaying text and a view for displaying images.
[0076] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including answering, hanging up, etc.).
[0077] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0078] The Notification Manager allows applications to display notifications in the status bar. These messages can be displayed briefly and then disappear automatically without user interaction. For example, the Notification Manager is used to notify users of completed downloads and message reminders. The Notification Manager can also display notifications in the top status bar of the system as icons or scrolling text, such as notifications from background applications, or as dialog windows on the screen. Examples include text messages in the status bar, beeps, vibrations on electronic devices, and flashing indicator lights.
[0079] Android Runtime includes core libraries and a virtual machine. Android runtime is responsible for scheduling and management of the Android system.
[0080] The core library consists of two parts: one is the function that needs to be called by the Java language, and the other is the Android core library.
[0081] The application layer and application framework layer run in a virtual machine. The virtual machine executes Java files in the application layer and application framework layer as binary files. The virtual machine manages object lifecycles, stack management, thread management, security and exception management, and garbage collection.
[0082] The system library can include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.
[0083] The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications.
[0084] The media library supports playback and recording of a variety of common audio and video formats, as well as static image files. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0085] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0086] A 2D graphics engine is a drawing engine for 2D drawings.
[0087] The kernel layer is the layer between hardware and software. The kernel layer includes at least display driver, camera driver, audio driver, sensor driver, kernel node and pre-reading module.
[0088] It is understandable that Figure 2 The layers in the illustrated software structure and the components contained in each layer 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 layers than shown, and each layer may include more or fewer components, which is not limited in the present application.
[0089] The embodiments of the present application do not particularly limit the specific structure of the execution subject of the method for pre-reading data. As long as the code recording the method for pre-reading data according to the embodiments of the present application can be executed to communicate according to the method for pre-reading data provided by the embodiments of the present application, the execution subject of the method for pre-reading data 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.
[0090] Before introducing the technical solutions in the embodiments of the present application, a brief introduction to the background technologies that may be involved in the present application is first given:
[0091] 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 called 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. Pages in physical memory can be recorded as physical pages.
[0092] In this way, whether it is virtual memory or physical memory, the page is the smallest allocation unit.
[0093] 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.
[0094] 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.
[0095] Reference Figure 3 , which is a flow diagram from virtual address to physical address provided by 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.
[0096] Among them, the memory management unit saves a page table for each user program, which stores the mapping relationship between virtual pages (the virtual page corresponds to a virtual address) and physical pages (the physical page corresponds to a physical address). When a physical page is assigned to a virtual page, a record is added to the page table to save 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 saved in the page table.
[0097] Of course, after receiving a virtual address, the memory management unit first needs to determine whether the virtual address is valid, whether it is in physical memory, and whether it is protected. If the virtual address is valid, and there is a corresponding physical address in 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.
[0098] 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.
[0099] 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. Only when the user program needs to access certain data during execution will it search for the physical address corresponding to the virtual address in physical memory based on the data's corresponding 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 (PF). This page fault exception is more common during the application cold start process.
[0100] 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.
[0101] 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.
[0102] 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.
[0103] 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.
[0104] 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.
[0105] 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.
[0106] 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.
[0107] 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.
[0108] Reference Figure 4 , is a schematic diagram of a page fault exception during an application cold start process provided by an embodiment of the present application. In this diagram, the horizontal axis represents the various stages of the application cold start process, among which several stages are highlighted:
[0109] ApplicationStart, BindApplication, ActivityStart, Choreographer and DoFrame. These stages are described in detail in the subsequent embodiments. Black vertical lines indicate that a page fault has occurred. The thicker the black vertical lines are, the more page faults have occurred in a short period of time. Figure 4 It is understandable that during the application cold start process, more page fault exceptions occurred in the BindApplication phase, and a small number of page fault exceptions also occurred in the ActivityStart phase. These page fault exceptions will cause the application cold start process to be slower.
[0110] In order to solve the problem of application startup or transition delay under page fault anomaly, a pre-reading method is currently generally adopted to improve the data loading speed under page fault anomaly. Pre-reading can also be called preloading, which can be understood as starting a pre-reading thread in scenarios such as application startup or transition, and reading the file data used by the main thread through the pre-reading thread. The existing technology provides a pre-reading method, in which, after the application startup is completed, the information of the page fault during the application startup process can be recorded through a page table entry (Page Table Entry, PTE) snapshot to generate a PTE snapshot, and the PTE snapshot is stored on the disk (it can also be stored in the physical memory during hot start). When the application is subsequently started, the memory page data corresponding to the recorded page fault information can be pre-loaded in the physical memory based on the PTE snapshot stored on the disk (or physical memory). However, in the above-mentioned pre-reading method through the PTE snapshot, the pre-reading thread still needs to perform a large amount of IO (input and output, input / output) operations during the pre-reading process, and the speed improvement of data preloading under page fault anomaly is limited.
[0111] The present application provides a pre-reading method that clusters and merges files and their access addresses based on the access status of files (or data), which can effectively reduce the number of IO accesses, thereby improving the data reading efficiency in the case of page fault exceptions, shortening the processing time of page fault exceptions, and improving the user experience.
[0112] Figure 5 For an exemplary flowchart of the pre-reading method, please refer to Figure 5 , specifically including but not limited to the following steps:
[0113] S501: The monitoring module sends an application startup notification to the kernel node.
[0114] For example, take the startup of a video application as an example. After the video application is started in response to the received user operation, the monitoring module detects that the video application is started, and the monitoring module sends an application startup notification to the kernel node (which may also be referred to as a kernel module, etc., which is not limited in this application). The application startup notification includes but is not limited to: application identification information of the video application (such as application name, etc.) and application startup event information, and the application startup event information is used to indicate that the video reference is started. In an embodiment of the present application, the application operation process includes multiple events, and in an embodiment of the present application, an application startup start event and an application startup end event are involved, wherein the application startup start event is used to indicate that the application starts to start, and the application startup end event is used to indicate that the application startup process ends. It can also be understood that the application startup is a whole event, including the start of the event and the end of the event. The monitoring module can obtain the application startup start event and the application startup end event through the upper module. For example, the mobile phone starts the video application in response to the received user operation, and starting from this node, the application startup starts. The video application calls a series of data during the startup process and performs operations such as rendering. The video application startup is completed (i.e., the time node corresponding to the application startup end event), that is, the application interface of the video application is displayed.
[0115] S502: Obtain pre-read calculation parameters.
[0116] In the embodiment of the present application, the kernel node can start multiple threads such as the main thread and the render thread (rendering thread). The main thread can also be called the main interface thread, which is used to display the main interface of the application. The render thread is used to perform operations such as rendering to draw the main interface.
[0117] For example, if a page fault occurs, the main thread is interrupted and the kernel handles the page fault. The same applies to the render thread. If the data required by the main or render thread isn't found in physical memory, the thread is interrupted and the corresponding data is retrieved from disk or other storage. The description of the page fault exception is provided above and will not be repeated here.
[0118] In the embodiment of the present application, the main thread and the render thread correspond to multiple files respectively. Taking the main thread as an example, Figure 6 For an exemplary data structure diagram, please refer to Figure 6, the main thread corresponds to multiple access files (i.e., the files that the main thread needs to access when starting (also called file data)), for example, including but not limited to file 1, file 2... file n. The kernel node records the file access information of each file corresponding to the main thread, and the file access information is not limited to: file identification information (such as file name, file ID, etc.), file size, access address, etc. Optionally, the access address corresponding to each file may include multiple consecutive addresses, and the addresses involved in the embodiments of the present application can be understood as virtual addresses (refer to the above for the concept) or logical addresses, which will not be repeated below. Figure 6 As shown, the file access information for file 1 includes, but is not limited to, address 1, address 2, ..., address n. It should be noted that the addresses involved in the embodiments of this application are merely illustrative examples and are not intended to be limiting. It can be understood that during the execution of the main thread, based on the access address corresponding to each file information, the data corresponding to the file stored in the logical space indicated by the access address is obtained.
[0119] For example: still taking the main thread as an example, the files accessed by the main thread include file 1 to file 200, wherein the file access information of file 1 includes but is not limited to: the identification information of file 1 is: / apex / com.android.runtime / bin / linkder64, the file size is 200M, and the access addresses include but are not limited to: 0-13, 21, 23, 70-75, 208-210, 217, 510, 512-528, 1020, 1526-1590, 2006-2014, 2069-2090 (all in KB). It should be noted that the above address identification method is only an illustrative example. In other examples, it can also be represented by the starting address + offset method, which is not limited in this application.
[0120] The Render thread is the same as the main thread, and also corresponds to multiple files and file access information, which will not be repeated here.
[0121] For example, Figure 7 For an exemplary flowchart of the steps executed by the kernel node, please refer to Figure 7 , including but not limited to:
[0122] S701: Check whether application information has been recorded in the List.
[0123] For example, a kernel node stores a list containing application information. The application information includes, but is not limited to, application identifiers. An application recorded in the list indicates that memory has been allocated to it.
[0124] The kernel node queries whether the List includes the application identifier based on the application identifier information in the received application startup notification.
[0125] Exemplarily, if the application identifier is not included in the list, step s702 is executed. If the application identifier is included in the list, step s703 is executed.
[0126] S702, apply for memory and add List members.
[0127] Exemplarily, the kernel node applies for memory for the application and adds the application identifier to the List.
[0128] S703: Record file access information of the main thread and the Render thread.
[0129] For example, the kernel node records the file access information of each file corresponding to the main thread and / or render file. This can also be understood as the file access information of the main thread and / or the file access information of the render file.
[0130] Exemplarily, the kernel node obtains a memory state, and based on the memory state, obtains pre-read calculation parameters. Figure 8 For an example of a flow chart showing the acquisition of pre-read calculation parameters, please refer to Figure 8 , specifically including but not limited to the following steps:
[0131] S801, obtaining memory information.
[0132] Exemplarily, the kernel node obtains memory information, including but not limited to the size of the remaining available memory space.
[0133] S802: Calculate the address step threshold.
[0134] Exemplarily, the kernel node calculates the address step threshold based on memory information. Exemplarily, the address step, also known as the continuous address step, indicates the length (i.e., the difference) between the address location of the next access and the end address of the previous access. The address step threshold indicates the maximum address step. The address step threshold will serve as the address aggregation condition in the following examples, and its specific implementation will be described below.
[0135] For example, the address step threshold Step (in KB) is calculated as follows:
[0136] In one example, if Mem_available (ie, available memory space) > 4 GB, then Step = 2048 KB.
[0137] In another example, if Mem_available≤4GB and Mem_available>2GB, set A (ie, the step calculation coefficient) = log2(((4096-available) / 4096)*100), then Step = 128*(2*A+2).
[0138] In another example, if Mem_available<2GB, then Step=128.
[0139] It should be noted that the above values are only illustrative examples and can be set according to actual needs. This application does not limit them.
[0140] It can be understood that in the embodiment of the present application, the address step threshold and the number of access addresses to be retained, N, are both associated with the remaining memory space. When the remaining memory space is sufficient, the N value and the step threshold are increased accordingly, allowing more access addresses to be stored. This results in a higher coverage rate and a more accurate hit rate for the N access addresses corresponding to each file in the acquired pre-read data. This further increases the hit rate of the data acquired based on the pre-read data at the next startup, thereby improving pre-read efficiency.
[0141] S803, calculating the value of the reserved number N of access addresses.
[0142] Exemplarily, the kernel node calculates the reserved number N of access addresses based on the memory information. Exemplarily, Figure 6 As described in , each file corresponds to multiple consecutive addresses. In the embodiment of the present application, by setting the value N, N consecutive addresses are reserved for each file. For example, if file 1 corresponds to 20 access addresses, if N is 3, then in the embodiment of the present application, N (for example, 3) consecutive addresses will be reserved for each file through the access address aggregation method described below.
[0143] In the embodiment of the present application, the value of the reserved number N of access addresses is calculated as follows:
[0144] In one example, if Mem_available>4GB, then N=5. In another example, if Mem_available≤4GB and Mem_available>2GB, then N=4. In yet another example, if Mem_available<2GB, then N=3.
[0145] It should be noted that the above values are only illustrative examples and can be set according to actual needs. This application does not limit them.
[0146] S503: Send a pre-reading collection instruction.
[0147] Exemplarily, the kernel node sends a pre-read collection indication to the pre-read module. The indication information includes but is not limited to: file access information of the main thread (i.e., file access information of each file corresponding to the main thread, which will not be repeated below), file access information of the Render thread, pre-read calculation parameters (including the address step threshold Step and the access address retention number N value), etc. The pre-read collection indication is used to instruct the pre-read module to obtain the pre-read collection information.
[0148] S504: Obtain pre-read acquisition information based on pre-read calculation parameters
[0149] Exemplarily, the pre-reading module starts a pre-reading collection thread to obtain pre-reading collection information.
[0150] Figure 9 For an exemplary diagram of the pre-reading information acquisition process, please refer to Figure 9 , specifically including but not limited to the following steps:
[0151] S901, traverse the files and determine whether the number of files is greater than the file quantity threshold.
[0152] Exemplarily, after receiving the pre-read acquisition instruction, the pre-read acquisition thread is started, and the TOPN consecutive addresses corresponding to each file of the main thread and the TOPN consecutive addresses corresponding to each file of the render thread are obtained through the pre-read acquisition thread. Among them, TOPN is the number of access addresses reserved as described above. That is to say, in the embodiment of the present application, the pre-read acquisition information obtained by the pre-read module reserves a specified number (i.e., N value, for example, 3) of access addresses for each file of the main thread and the render thread to reduce the number of accesses. The following is an example of the processing of the main thread by the pre-read module. The processing flow of the render thread is the same, and this application will not repeat the example.
[0153] Exemplarily, after the pre-reading module obtains the access file information and N value and step threshold corresponding to each file of the main thread, it initializes the above parameters, that is, substitutes each parameter into the existing computer program for execution.
[0154] For example, the pre-reading module traverses each file of the main thread, that is, the pre-reading module will execute each file sequentially. Figure 9 The steps in , until the traversal ends.
[0155] Exemplarily, the pre-read module is provided with a file number threshold, which is used to indicate the maximum number of files that the pre-read acquisition thread processes for each thread. In the embodiment of the present application, the file number threshold is set to 100, and in other embodiments, it can also be set to other values. It can be set according to actual needs and is not limited to this.
[0156] In one example, if the pre-read module determines that the number of files currently traversed (which can also be understood as the number of files processed) is greater than the file number threshold, the current file is not processed. This can also be understood as the pre-read collection information does not include information corresponding to the file.
[0157] In another example, if the number of files currently traversed by the pre-reading module is less than or equal to the file quantity threshold, S902 is executed.
[0158] For example, let's assume the main thread has 200 files. As the pre-read acquisition thread traverses each of the first 100 files, it determines whether the number of files currently processed is less than or equal to the file quantity threshold (i.e., 100). In other words, each file is processed after S902. When the pre-read module traverses the 101st file, but the number of files currently processed is greater than the file quantity threshold, no processing is performed, and the process ends.
[0159] S902 , check whether the currently accessed address is within the address step threshold range corresponding to the TOPN consecutive addresses.
[0160] Exemplarily, the pre-reading module (specifically, the pre-reading acquisition thread, which will not be repeated below) traverses each access address corresponding to the currently traversed file until the access address traversal is completed, and then re-executes S901 to traverse the next file.
[0161] Exemplarily, the pre-reading module determines whether the access address currently traversed is within the address step threshold range corresponding to the TOPN continuous addresses. Exemplarily, as described above, after the pre-reading module obtains the N value and performs initialization, it determines to reserve N continuous addresses (i.e., access addresses) for each file, which are referred to as TOPN continuous addresses in the embodiment of the present application. And, as described above, the pre-reading module obtains the step threshold Step. The pre-reading module compares the currently traversed access address with the step range of the reserved TOPN addresses. In one example, if the current access address is within the step range of any one of the TOPN continuous addresses, S903 is executed. In another example, if it is not within the step range of any one of the continuous addresses, S903 is executed.
[0162] Exemplarily, the step range of the continuous address is the continuous address starting address to the continuous address ending address plus the step threshold. For example, assuming the continuous address is 0 to 31 and the step threshold is 128, the step range of the continuous address is: 0 to (31 + 128), that is, 0 to 159.
[0163] Optionally, the pre-reading module may first determine whether the currently traversed access address is within the Top n consecutive address range. If so, S905 is executed. If not, the pre-reading module may further determine whether the step length between the current access address and the Top n consecutive addresses (i.e., the difference between the starting address of the current access address and the ending address of each address in the Top n consecutive addresses) is less than a step length threshold. If so, S905 is executed; if so, S903 is executed.
[0164] The following uses file 1 of the main thread as an example to illustrate. The pre-read module traverses to file 1. As described above, the pre-read module has obtained the file access information corresponding to file 1. The file name is: / apex / com.android.runtime / bin / linkder64, the file size is 200M, and the access addresses include but are not limited to: 0-13, 21, 23, 70-75, 208-210, 217, 510, 512-528, 1020, 1526-1590, 2006-2014, 2016-2059, 2069-2090 (all in KB). The above content is only an illustrative example and is not limited to this application.
[0165] Since the pre-reading module can now create the TOPN address chain list and the temporary address chain list, of course, this is only an illustrative example, and the pre-reading module can also create a new address chain list when it needs to be created, and this application does not limit it. Table 1 shows an exemplary address chain list:
[0166] Table 1
[0167]
[0168] Exemplarily, the pre-read module traverses to access addresses 0 to 13 (in KB, not repeated below). The pre-read module detects the currently reserved TOPN. Since TOPN are all empty, it determines that the current access address is not within the step range of the TOPN continuous address, and executes S904. It should be noted that Table 1 is only an illustrative example. In the embodiment of the present application, the pre-read module may not create an address linked list before using the address linked list. In other words, Table 1 may be an empty list.
[0169] S903: Check whether the number of existing TOPN consecutive address linked lists is greater than or equal to the N value.
[0170] Exemplarily, the pre-reading module further determines whether the number of currently occupied TOP continuous address linked lists is greater than or equal to the N value.
[0171] In one example, if it is greater than or equal to the value N, then S906 is executed. In another example, if it is less than the value N, then S904 is executed.
[0172] For example, still taking the above example as an example, as mentioned above, Table 1 is an empty list, and the pre-reading module detects that the number of currently used TOP continuous address lists is 0, then S904 is executed, that is, the address list is increased.
[0173] S904, add an access address linked list.
[0174] Exemplarily, the pre-reading module creates an access address list, and fills the current access address into a new address linked list, and the number of accesses corresponding to the address linked list is increased by 1.
[0175] Still using the above example, the pre-reading module adds a TOP1 address list. The pre-reading module fills 0 to 13 into the TOP1 address list and increases the access count by 1. The updated list is shown in Table 2:
[0176] Table 2
[0177]
[0178] S905: Expand the continuous address range based on the current access address.
[0179] Exemplarily, the pre-reading module uses the end address of the current access address to amplify the access address last filled in TOPN (ie, the access address last traversed), and increases the corresponding access count by 1.
[0180] For example, the pre-reading module continues to traverse the next access address, which is 21KB. The pre-reading module executes S902, determines that the current access address (i.e., 21) is within the step range of 0 to (13+128) of the previous access address, and executes S905. It should be noted that, under normal circumstances, the access address is incremental. Optionally, when executing S902, the pre-reading module can compare the currently traversed access address with the step range of the previous access address without comparing other consecutive addresses in the address list. Of course, in some examples, if the access address is non-increasing, it can be compared with each address in the address list.
[0181] Exemplarily, the pre-reading module will amplify the last access address filled in the address chain based on the current access address (i.e., 21), that is, update the end address of the last access address to the end address of the current access address (e.g., 21), and increase the access count by 1. After the update, the following is shown:
[0182] Table 3
[0183]
[0184] The pre-read module continues to traverse the next access address, which is 23, and executes S902. The pre-read module determines that the current traversal access address (23) is within the access address step range (0 to (21+128)) filled in last time, and the step proceeds to S905.
[0185] Exemplarily, the pre-reading module will amplify the last access address in the address chain based on the current access address (i.e., 23), that is, update the end address of the last access address to the end address of the current access address (e.g., 23), and increase the access count by 1. The updated value is as follows:
[0186] Table 4
[0187]
[0188] For example, the pre-reading module continues to traverse the access address of file 1 and updates the address linked list in the above manner. When the access address is 510 to 528, the address linked list is updated as follows:
[0189] Table 5
[0190]
[0191] For example, the pre-read module traverses to access address 1020, executes S902, determines that access address 1020 is not within the step range 510 to (528+128) of the previously entered access address, and executes S903. Based on Table 5, the pre-read module determines that the current number of TOPN consecutive address chains (i.e., 3) is greater than or equal to the value N (i.e., 3), and executes S906.
[0192] S906: Whether the current access address is within the address step threshold range corresponding to the continuous addresses in the temporary address access linked list.
[0193] Exemplarily, the pre-reading module determines whether the current access address is within an address step threshold range corresponding to consecutive addresses in the temporary address access linked list.
[0194] In an example, if the pre-reading module determines that the current access address is within the address step threshold range corresponding to the continuous addresses in the temporary address access linked list, S907 is executed.
[0195] In another example, if the address accessed by the pre-reading module this time is not within the address step threshold range corresponding to the continuous addresses in the temporary address access linked list, S908 is executed.
[0196] Continuing with the above scenario, in this example, since the temporary address linked list is not currently reserved, the pre-reading module can determine that the current access address is not within the continuous address step range of the temporary address linked list. The pre-reading module creates a temporary address linked list and executes S907. The pre-reading module creates a temporary address linked list, as shown in Table 6:
[0197] Table 6
[0198]
[0199] S907: Update the temporary address access linked list based on the current access address.
[0200] Exemplarily, the pre-reading module determines that the currently traversed access address is not within the continuous address step range of the temporary address linked list, and then overwrites the continuous address in the original temporary address linked list with the current access address.
[0201] For example, when the pre-read module traverses to 1020, the current access address overwrites the data in the temporary address list (the current data is empty or 0), and the access count is set to 1 (that is, the access count remains 1 after each replacement). The updated address list is as follows:
[0202] Table 7
[0203]
[0204] The pre-read module traverses to the access address 1526-1590, and the steps go through S902-S903-S906. The pre-read module determines that the current traversed access address (1526-1590) is not within the continuous address step range (1020+128) of the temporary address list, and the step proceeds to S907. Based on the current traversed access address (1526-1590), the pre-read module overwrites the data in the temporary address list (the current data is 1020) with the current access address, and the access count is still set to 1 (that is, the access count remains 1 after each replacement). The updated address list is as follows:
[0205] Table 8
[0206]
[0207] The pre-read module continues to traverse the access address. When it traverses to the access address 2016-2059, the current list is as follows:
[0208] Table 9
[0209]
[0210] The pre-reading module detects that the current access address 2016-2059 is within the continuous address step range (2006-(2014+128)) of the temporary address linked list, and the step proceeds to S908.
[0211] S908: Expand the continuous address range based on the current access address.
[0212] For example, the pre-reading module may expand the continuous address range in the temporary address linked list based on the current access address, and the access count is increased by 1. The expansion method may refer to S905 and will not be described in detail here.
[0213] For example, still using the above scenario, the pre-reading module expands the continuous address range of the temporary address list based on the current access address 2016-2059. The expanded address range is 2006-2059, and the access count is increased by 1. The updated list is as follows:
[0214] Table 10
[0215]
[0216] S909, traverse TOPN, replace the continuous address data whose access times are less than the temporary address list
[0217] Exemplarily, after the pre-reading module updates the temporary address list and its corresponding access counts, it traverses the access counts corresponding to the consecutive addresses in the TOPN address list. In one example, if the consecutive addresses in the temporary address list exist, the consecutive addresses in the TOPN address list are replaced with the consecutive addresses in the temporary address list. In another example, if the consecutive addresses do not exist, it continues to traverse the next access address.
[0218] For example, still following the above scenario, after the pre-reading module updates Table 10, based on the current access count of the temporary address linked list (i.e., the number is 2), it detects whether there is a linked list in TOPN with an access count less than the access count of the temporary address linked list. The current access counts of TOPN are: 4, 2, 2, which are all greater than or equal to the access count corresponding to the temporary address linked list. In this case, no processing is performed and the next access address is traversed. The pre-reading module traverses to access addresses 2069-2090, and the steps go through S902-S903-S906-S908. The pre-reading module expands the continuous address range, and the temporary address linked list access count is increased by 1. The updated list is as follows:
[0219] Table 11
[0220]
[0221] The pre-read module traverses the access counts in the TOPN address list based on the access count of the temporary address list (i.e., 3), and detects that the access counts of TOP2 and TOP3 are both less than the access count of the temporary address list. The pre-read module can choose any one to replace. For example, the pre-read module replaces the consecutive addresses in the TOP2 address list with the consecutive addresses in the temporary address list. The updated list is as follows:
[0222] Table 12
[0223]
[0224] The pre-reading module continues to traverse the access address until the access address traversal is completed, and then repeats S901 to continue traversing the next file of the main thread.
[0225] The pre-read module executes the 100 files of the main thread Figure 9 After that, the top three consecutive addresses corresponding to each of the 100 files in the main thread are obtained. For example, the top three consecutive addresses corresponding to / apex / com.android.runtime / bin / linkder64 include: 0-75, 2006-2090, 510-528.
[0226] Exemplarily, the monitoring module may obtain an application startup completion event from an upper-layer module to determine that the application startup event has ended. The monitoring module may send an application startup completion notification to the pre-reading module to indicate that the application startup has ended. The pre-reading module may determine that the application startup event has ended in response to the application startup completion notification. Figure 10 For an exemplary diagram of the pre-reading information acquisition process, please refer to Figure 10 , specifically including but not limited to the following steps:
[0227] S1001: The pre-reading module obtains M files based on the number of times the files are accessed.
[0228] Exemplarily, the pre-read module can determine the number of accesses to each file by the main thread (the same as the render thread) based on this access, which can also be called the number of IO reads and writes, which can be understood as the number of consecutive addresses corresponding to the file. The pre-read module sorts the 100 files based on the number of accesses and obtains the top M files. In one example, M can be equal to N. In another example, M can be any value set according to actual needs, such as 5. In another example, the value of M can also be set according to the status of the remaining available space in the memory, which is not limited in this application.
[0229] S1002: The pre-reading module merges the current pre-reading collection information with the last pre-reading collection information.
[0230] Exemplarily, the pre-read module stores the pre-read collection information obtained this time, including but not limited to the pre-read collection information of the main thread and the pre-read collection information of the render thread. The pre-read collection information of the main thread includes but is not limited to: the identification information of the main thread's file and the top N consecutive addresses corresponding to each of the main thread's M files.
[0231] Exemplarily, the pre-read module merges the pre-read collection information of the application startup event corresponding to the video application obtained this time with the pre-read collection information of the application startup event corresponding to the video application obtained last time. The merging method can be to merge the continuous addresses of each file. The merging method can be set according to actual needs and is not limited by this application. For example, in an embodiment of the present application, assuming that the TOP3 continuous addresses corresponding to / apex / com.android.runtime / bin / linkder64 obtained last time include: 3~88, 2006~2090, 510~528, the pre-read module can expand the addresses where the continuous addresses partially overlap, for example, merging 3~88 and 0~75, and the merging result is 0~88.
[0232] That is, in the embodiment of the present application, the pre-reading module stores two pre-reading collection information, one of which is the pre-reading collection information obtained this time, and the other is the merged pre-reading collection information. To distinguish the merged pre-reading collection information from the above information, the merged pre-reading collection information is called the merged pre-reading collection information.
[0233] Optionally, the pre-reading module may clear the pre-reading collection information saved last time and the merged pre-reading collection information saved last time to reduce memory usage.
[0234] S505: The monitoring module sends an application startup notification to the kernel node.
[0235] Exemplarily, in a scenario where the application is started again, the monitoring module sends an application start notification to the kernel node.
[0236] S506: The kernel node sends a pre-reading instruction to the pre-reading module.
[0237] Exemplarily, the kernel node sends a pre-read instruction to the pre-read module, where the pre-read instruction includes identification information of the main thread and the render thread and their corresponding file access information, and is used to instruct the pre-read module to pre-read the access data of the main thread and / or the render thread.
[0238] S507: The pre-reading module obtains data based on the pre-reading collection information.
[0239] Exemplarily, the pre-reading module starts a pre-reading thread, which can obtain the merged pre-reading collection information corresponding to the main thread and / or the render thread. For example, after obtaining the merged pre-reading collection information corresponding to the main thread and / or the render thread, the pre-reading collection thread can save the merged pre-reading collection information corresponding to the main thread and / or the render thread to a designated storage space. The pre-reading thread can then obtain the merged pre-reading collection information corresponding to the main thread and / or the render thread from the designated storage space based on the identification information of the main thread and / or the render thread.
[0240] The pre-read thread can pre-read the data required for the main thread to run based on the TOPN consecutive addresses stored in the merged pre-read acquisition information corresponding to the main thread (the same as the Render thread). Thereby reducing the number of IO accesses and reducing the storage burden while improving the rate of data pre-reading. It can be understood that compared with the existing technology, taking the same file as an example, when the pre-read thread of the existing technology is reading the file, the program executed by the main thread may need the data, and the reading rate of the pre-read thread will affect the execution efficiency of the main thread. If the pre-read thread has not yet prepared the data required by the main thread, the main thread will be interrupted. This application aggregates the access addresses, which can effectively shorten the pre-reading time while reducing the number of accesses, so that the data required by the main thread can be read in advance as much as possible to avoid the main thread from being stuck.
[0241] That is, in the embodiment of the present application, the pre-reading process for a single access is actually divided into a pre-reading acquisition information acquisition process and a pre-reading process. That is, the pre-reading module obtains the pre-reading acquisition information corresponding to the current access through the pre-reading acquisition thread. When the application is started next time, pre-reading is performed based on the obtained pre-reading acquisition information. It should be understood that the above embodiment only illustrates the order of pre-reading acquisition information and the pre-reading process. In fact, for a single access, the pre-reading module starts the pre-reading acquisition thread and the pre-reading thread in parallel. That is, the pre-reading thread can pre-read the current access based on the pre-reading acquisition information obtained last time, and the pre-reading acquisition thread obtains the corresponding pre-reading acquisition information based on the current access for use at the next startup.
[0242] It should be noted that the embodiments of the present application are described using application startup as an example. In other embodiments, the technical solutions in the embodiments of the present application can also be applied to scenarios such as application transitions, and this application will no longer give examples one by one.
[0243] It is understandable that, in order to implement the above functions, the electronic device includes hardware and / or software modules that perform the corresponding functions. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to be beyond the scope of this application.
[0244] In one example, Figure 11 A schematic block diagram of an apparatus 1100 according to an embodiment of the present application is shown. The apparatus 1100 may include: a processor 1101 and a transceiver / transceiver pin 1102 , and optionally, a memory 1103 .
[0245] The various components of the device 1100 are coupled together via a bus 1104, wherein the bus 1104 includes, in addition to a data bus, a power bus, a control bus, and a status signal bus. However, for the sake of clarity, all buses are referred to as bus 1104 in the figure.
[0246] Optionally, the memory 1103 may be used for instructions in the aforementioned method embodiment. The processor 1101 may be used to execute instructions in the memory 1103 and control the receiving pin to receive a signal and control the transmitting pin to send a signal.
[0247] The apparatus 1100 may be the electronic device or a chip of the electronic device in the above method embodiment.
[0248] Among them, all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module and will not be repeated here.
[0249] This embodiment further provides a computer storage medium, in which computer instructions are stored. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the method in the above-mentioned embodiment.
[0250] This embodiment further provides a computer program product. When the computer program product is run on a computer, it enables the computer to execute the above-mentioned related steps to implement the method in the above-mentioned embodiment.
[0251] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory to enable the chip to execute the methods in the above-mentioned method embodiments.
[0252] Among them, the electronic device, computer storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be repeated here.
[0253] As described above, 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 above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for pre-reading data, characterized in that: Applied to electronic equipment, the method includes: During the application startup process, obtaining file access information of the application, the file access information including multiple files that need to be accessed when the application is started and multiple access addresses corresponding to each file; Based on the current remaining memory space status, obtaining pre-reading calculation parameters; wherein the pre-reading calculation parameters include N value; Based on the pre-read calculation parameter and the file access information, obtaining pre-read collection information corresponding to the application; the pre-read collection information includes access address information of at least one file among the multiple files, the access address information includes N access addresses, N is an integer greater than 0, and the value of N is less than the number of access addresses corresponding to the files in the file access information, and the N access addresses corresponding to each file cover multiple access addresses of the corresponding file; During the next startup of the application, data corresponding to the N access addresses corresponding to each file in the at least one file is read based on the pre-read collection information.
2. The method according to claim 1, characterized in that The pre-read calculation parameters also include a step length threshold; wherein the step length threshold is a maximum value of an indicated step length, and the step length is used to indicate the length between the address location of the next access and the end address of the previous access.
3. The method according to claim 2, characterized in that The step of obtaining pre-read calculation parameters based on the current remaining memory space status includes: Calculating the N value based on the remaining memory space status; The step threshold is calculated based on the remaining memory space status.
4. The method according to claim 2, characterized in that The acquiring, based on the pre-read calculation parameter and the file access information, the pre-read collection information corresponding to the application includes: Based on the step threshold, multiple access addresses of each of the files are aggregated to obtain N access addresses corresponding to each of the files.
5. The method according to claim 4, characterized in that The step of aggregating the multiple access addresses of each file based on the step threshold to obtain N access addresses corresponding to each file includes: Address aggregation is performed on access addresses that meet the address range indicated by the step threshold among the multiple access addresses in each of the files.
6. The method according to claim 1, characterized in that The acquiring, based on the pre-read calculation parameter and the file access information, the pre-read collection information corresponding to the application includes: Based on the pre-read calculation parameter and the file access information, obtaining access address information of M files among the multiple files; M is an integer greater than 0; Sorting the M files based on the number of accesses corresponding to the M files; The access address information of the at least one file in the M file sortings is retained.
7. The method according to claim 1, characterized in that The step of reading data corresponding to N access addresses corresponding to each file in the at least one file based on the pre-read collection information includes: Based on the merged pre-reading acquisition information, data corresponding to N access addresses corresponding to each file in the at least one file is read, wherein the merged pre-reading acquisition information is obtained based on the pre-reading acquisition information and the most recently acquired pre-reading acquisition information corresponding to the application.
8. An electronic device, characterized in that: include: One or more processors, memory; and one or more computer programs, wherein the one or more computer programs are stored on the memory and, when the computer programs are executed by the one or more processors, cause the electronic device to perform the following steps: During the application startup process, obtaining file access information of the application, the file access information including multiple files that need to be accessed when the application is started and multiple access addresses corresponding to each file; Based on the current remaining memory space status, obtaining pre-reading calculation parameters; wherein the pre-reading calculation parameters include N value; Based on the pre-read calculation parameter and the file access information, obtaining pre-read collection information corresponding to the application; the pre-read collection information includes access address information of at least one file among the multiple files, the access address information includes N access addresses, where N is an integer greater than 0, and the value of N is less than the number of access addresses corresponding to the files in the file access information, and the N access addresses corresponding to each file cover multiple access addresses of the corresponding file; During the next startup of the application, data corresponding to the N access addresses corresponding to each file in the at least one file is read based on the pre-read collection information.
9. The electronic device according to claim 8, wherein: The pre-read calculation parameters also include a step length threshold; wherein the step length threshold is a maximum value of an indicated step length, and the step length is used to indicate the length between the address location of the next access and the end address of the previous access.
10. The electronic device according to claim 9, characterized in that When the computer program is executed by the one or more processors, the electronic device is caused to perform the following steps: Calculating the N value based on the remaining memory space status; The step threshold is calculated based on the remaining memory space status.
11. The electronic device according to claim 9, wherein: When the computer program is executed by the one or more processors, the electronic device is caused to perform the following steps: Based on the step threshold, multiple access addresses of each of the files are aggregated to obtain N access addresses corresponding to each of the files.
12. The electronic device according to claim 11, wherein: When the computer program is executed by the one or more processors, the electronic device is caused to perform the following steps: Address aggregation is performed on access addresses that meet the address range indicated by the step threshold among the multiple access addresses in each of the files.
13. The electronic device according to claim 8, wherein: When the computer program is executed by the one or more processors, the electronic device is caused to perform the following steps: Based on the pre-read calculation parameter and the file access information, obtaining access address information of M files among the multiple files; Sorting the M files based on the number of accesses corresponding to the M files; The access address information of the at least one file in the M file sortings is retained.
14. The electronic device according to claim 8, wherein When the computer program is executed by the one or more processors, the electronic device is caused to perform the following steps: Based on the merged pre-reading acquisition information, data corresponding to N access addresses corresponding to each file in the at least one file is read, wherein the merged pre-reading acquisition information is obtained based on the pre-reading acquisition information and the most recently acquired pre-reading acquisition information corresponding to the application.
15. A computer storage medium, characterized in that The method comprises computer instructions, which, when executed on an electronic device, enable the electronic device to execute the method according to any one of claims 1 to 7.
16. A computer program product, characterized in that When the computer program product is run on a computer, the computer is enabled to perform the method according to any one of claims 1 to 7.
17. A chip, characterized in that: The electronic device comprises one or more interface circuits and one or more processors; the interface circuit is used to receive a signal from a memory of the electronic device and send the signal to the processor, wherein the signal includes a computer instruction stored in the memory; when the processor executes the computer instruction, the electronic device executes the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Memory missing page exception processing method and device, equipment and storage medium
CN114253458A
Application program memory use optimization method and device, equipment and medium
CN115237821A