Method, device and terminal device for pre-reading file pages
By obtaining parameter information of memory usage status and I/O processing status, dynamically adjusting the file pre-read window size, solving the problem of too many invalid file pages in the prior art, and improving the application startup response speed and overall usage performance of terminal devices.
Patent Information
- Application Number
- CN201910798611.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-08-27
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2039-08-27
AI Technical Summary
The prior art is prone to pre-reading too many invalid file pages during file pre-reading, resulting in excessive memory usage and affecting the application startup response speed and usage performance of terminal devices.
By obtaining parameter information of memory usage status and I/O processing status, the size of the file pre-read window is dynamically adjusted, thereby adaptively adjusting the usage of memory resources by the pre-read operation. The specific method includes reducing the size of the pre-read window when the memory usage pressure or I/O processing pressure is large to reduce the pre-read file page; increasing the size of the pre-read window when the memory usage pressure or I/O processing pressure is small to increase the pre-read file page.
By dynamically adjusting the size of the pre-read window, invalid pre-reading is effectively reduced, memory usage is reduced, and application startup response speed and overall usage performance of terminal devices are improved.
Smart Images

Figure CN112445725B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to computer technology, and in particular to a method, device and terminal device for pre-reading file pages. Background Art
[0002] The operating system is located between the underlying hardware and the user, and is the bridge between the two. Users can input instructions through the operating system's user interface. The operating system parses the instructions, drives the hardware devices, and implements user requirements. The operating system can provide the following functions: process management, memory management, file system, network communication, security mechanism, user interface, and driver program, etc. Among them, the file system is the method and data structure used in the operating system to clearly define the files on the storage device (disk, solid-state drive, etc.) or partition, that is, the method of organizing files on the storage device.
[0003] During the startup and operation of the terminal device application, some file pages can be read from the external storage (for example, disk) into the memory through the file pre-reading method provided by the operating system for use by the application. The file pre-reading method can adjust the pre-reading window size according to certain rules based on the file access mode (sequential reading or random reading). For example, the pre-reading window is increased for sequential reading and decreased for random reading. All file pages in the pre-reading window are read into the memory so that the application can quickly access the file pages from the memory.
[0004] However, the above-mentioned file pre-reading method may have the problem of pre-reading too many invalid file pages, that is, too many file pages that will not be accessed in the near future are pre-read into the memory, occupying too much memory space, squeezing the memory space available for the terminal device's application, resulting in slow application startup response and jamming on the terminal device, affecting the performance of the terminal device. Summary of the invention
[0005] The present application provides a method, apparatus and terminal device for pre-reading file pages to improve the performance of the terminal device.
[0006] In a first aspect, the present application provides a method for pre-reading a file page, the method may include: obtaining status parameter information, the status parameter information is used to indicate at least one of a memory usage status or an input / output (IO) processing status; determining the size of a file pre-reading window according to the status parameter information; and reading a corresponding file page from an external storage device into a memory according to the file pre-reading window. After the file page is read into the memory, it can be accessed by an application.
[0007] This implementation method can adaptively adjust the size of the file pre-reading window based on the state parameter information, and then perform pre-reading operations according to the size of the file pre-reading window. The number of file pages for pre-reading operations based on different file pre-reading window sizes is different, and the file pages of the pre-reading operation occupy different memory resources, thereby realizing adaptive adjustment of the memory resource occupation of the pre-reading operation. For example, it can be determined based on the state parameter information that the memory usage pressure is high and / or the I / O processing pressure is high. When the memory usage pressure is high and / or the I / O processing pressure is high, the size of the pre-reading window is reduced, thereby reducing the file pages read in the pre-reading operation, thereby alleviating the slow application startup response, jamming and other phenomena, thereby improving the performance of the terminal device.
[0008] In one possible design, an achievable method for determining the size of a file pre-read window based on the status parameter information includes: when the status parameter information indicates that at least one of the memory usage pressure or the IO processing pressure is at a first level, reducing the size of the file pre-read window; when the status parameter information indicates that at least one of the memory usage pressure or the IO processing pressure is at a second level, increasing the size of the file pre-read window; wherein the first level of memory usage pressure or IO processing pressure is greater than the second level of memory usage pressure or IO processing pressure.
[0009] In this implementation, when the status parameter information indicates that at least one of the memory usage pressure or the IO processing pressure is at the first level, it means that the memory usage pressure is large and / or the IO processing pressure is large. By reducing the size of the file pre-reading window to reduce the pre-read file pages, the memory resources occupied by the pre-read file pages are reduced to alleviate the slow application startup response, jamming and other phenomena. When the status parameter information indicates that at least one of the memory usage pressure or the IO processing pressure is at the first level, it means that the memory usage pressure is small and / or the IO processing pressure is small. By increasing the size of the file pre-reading window to increase the pre-read file pages, the page fault phenomenon can be reduced to improve the file access speed of the terminal device, thereby improving the performance of the terminal device.
[0010] In one possible design, the status parameter information may include at least one of a memory parameter or an IO parameter, the memory parameter includes at least one of a memory occupancy, a memory utilization rate, or a cumulative number of page faults, and the IO parameter includes an IO queue length.
[0011] This implementation method can determine the usage status of memory resources according to memory parameters and / or IO parameters, and based on this, adaptively adjust the occupancy of memory resources by pre-read operations to improve the performance of terminal equipment.
[0012] In a possible design, the implementation method of determining the size of the file pre-reading window according to the state parameter information includes: determining a first indicator according to at least one of the memory parameter and the IO parameter. Determining the size of the file pre-reading window according to the first indicator.
[0013] In a possible design, a feasible way to determine the size of the file pre-reading window according to the first indicator includes: determining the numerical interval to which the first indicator belongs according to the first indicator, and using the window size corresponding to the numerical interval to which the first indicator belongs as the size of the file pre-reading window.
[0014] In a possible design, a method of reading the corresponding file page from the external storage device to the memory according to the file pre-reading window includes: selecting at least one file page in the file pre-reading window according to the pre-reading model, and reading the at least one file page from the external storage device to the memory. The pre-reading model is a data structure in the memory determined according to at least one of the file access real-time data and the file access history data, the pre-reading model corresponds to the file, the file access real-time data is not synchronized with the file access history data, and the file access history data is the data in the external storage device.
[0015] In this implementation, since the pre-reading model is determined based on at least one of the real-time file access data and the historical file access data, the pre-reading model records the access records of the file pages. The pre-reading model can be used to increase the pre-reading hit rate and improve the probability of the file pages read from the external storage device to the memory being accessed by the application layer, thereby reducing invalid pre-reading and reducing the waste of memory resources.
[0016] In a possible design, the read-ahead model includes N bits, each bit corresponds to a file page of the file, each bit is used to indicate whether the file page corresponding to the bit is accessed, and N is an integer greater than or equal to 1.
[0017] In a possible design, the method may further include: determining whether the number of fragments formed by the at least one file page is greater than a first threshold. If the number of fragments formed by the at least one file page is greater than the first threshold, all file pages in the file pre-read window are read from the external storage device to the memory. If the number of fragments formed by the at least one file page is less than or equal to the first threshold, the step of reading the at least one file page from the external storage device to the memory is performed.
[0018] This implementation compares the number of fragments formed by at least one pre-read file page with the size of a first threshold value. When the number of formed fragments is greater than the first threshold value, all file pages in the file pre-read window are read from the external storage device to the memory, thereby avoiding I / O fragmentation caused by a large number of fragments and improving I / O processing efficiency. When the number of formed fragments is less than or equal to the first threshold value, at least one pre-read file page is read from the external storage device to the memory, and the remaining file pages in the file pre-read window except for the at least one pre-read file page are not pre-read, thereby reducing the memory occupation of the pre-read operation and reducing invalid pre-reading.
[0019] In a possible design, reading all file pages in a file pre-reading window from an external storage device to a memory may include: determining whether a bit corresponding to the last file page in the file pre-reading window indicates that the last file page has been accessed. When the bit corresponding to the last file page indicates that the last file page has been accessed, reading all file pages in the file pre-reading window and at least one file page after the file pre-reading window from an external storage device to the memory. When the bit corresponding to the last file page indicates that the last file page has not been accessed, reading all file pages in the file pre-reading window from an external storage device to the memory; wherein the at least one file page after the file pre-reading window and the last file page in the file pre-reading window belong to the same fragment.
[0020] This implementation method determines whether the last file page of the file pre-read window has been accessed. When the last file page is accessed, the file page belonging to the same fragment as the last file page is read into the memory, thereby avoiding I / O fragmentation caused by the division of the pre-read window boundary (that is, some pages in the same fragment are divided outside the window and have to be read again when they are accessed next time, increasing the number of I / O times), thereby improving I / O processing efficiency.
[0021] In a possible design, reading the at least one file page from the external storage device into the memory may include: determining whether the bit corresponding to the last file page of the file pre-reading window indicates that the last file page is accessed. When the bit corresponding to the last file page indicates that the last file page is accessed, reading the at least one file page and the at least one file page after the file pre-reading window from the external storage device into the memory. When the bit corresponding to the last file page indicates that the last file page is not accessed, reading the at least one file page from the external storage device into the memory. The at least one file page after the file pre-reading window and the last file page of the file pre-reading window belong to the same fragment.
[0022] This implementation method determines whether the last file page of the file pre-read window has been accessed. When the last file page is accessed, the file page belonging to the same fragment as the last file page is read into the memory, thereby avoiding I / O fragmentation caused by the division of the pre-read window boundary (that is, some pages in the same fragment are divided outside the window and have to be read again when they are accessed next time, increasing the number of I / O times), thereby improving I / O processing efficiency.
[0023] In one possible design, the file access history data includes at least one of the position, length, or time of the read access request before the file is opened this time, and the file access real-time data includes at least one of the position, length, or time of the read access request after the file is opened this time.
[0024] In one possible design, the method may further include: updating the file access history data corresponding to the file in the external storage device according to the pre-read model.
[0025] In a possible design, the obtaining of the status parameter information may include: obtaining the status parameter information when triggering the pre-reading of the file page; or obtaining the status parameter information at a preset period.
[0026] In a second aspect, an embodiment of the present application provides a device for pre-reading file pages, which may include: a state acquisition module, used to acquire state parameter information, the state parameter information is used to represent at least one of a memory usage state or an input / output (IO) processing state; a pre-read window determination module, used to determine the size of a file pre-read window according to the state parameter information; and a pre-read module, used to read the corresponding file page from an external storage device into a memory according to the file pre-read window, so that the application layer can access the file page.
[0027] In one possible design, the pre-reading window determination module is used to: when the status parameter information indicates that at least one of the memory usage pressure or the IO processing pressure is at a first level, reduce the size of the file pre-reading window; when the status parameter information indicates that at least one of the memory usage pressure or the IO processing pressure is at a second level, increase the size of the file pre-reading window; wherein the first level of memory usage pressure or IO processing pressure is greater than the second level of memory usage pressure or IO processing pressure.
[0028] In a possible design, the pre-reading window determination module is used to: determine a first indicator according to at least one of the memory parameter and the IO parameter, and determine a size of the pre-reading window of the file according to the first indicator.
[0029] In a possible design, the pre-reading window determination module is used to: determine the numerical interval to which the first indicator belongs according to the first indicator, and use the window size corresponding to the numerical interval to which the first indicator belongs as the size of the pre-reading window of the file.
[0030] In a possible design, the pre-reading module is used to: select at least one file page in the pre-reading window of the file according to the pre-reading model, and read the at least one file page from the external storage device to the memory. The pre-reading model is a data structure determined according to at least one of the file access real-time data and the file access history data, the pre-reading model corresponds to the file, the file access real-time data is not synchronized with the file access history data, and the file access history data is the data in the external storage device.
[0031] In a possible design, the pre-reading module is further used to: determine whether the number of fragments formed by the at least one file page is greater than a first threshold. If the number of fragments formed by the at least one file page is greater than the first threshold, all file pages in the file pre-reading window are read from the external storage device to the memory; if the number of fragments formed by the at least one file page is less than or equal to the first threshold, the step of reading the at least one file page from the external storage device to the memory is executed.
[0032] In one possible design, the pre-reading module is used to: determine whether the bit corresponding to the last file page of the file pre-reading window indicates that the last file page is accessed; when the bit corresponding to the last file page indicates that the last file page is accessed, read all file pages in the file pre-reading window and at least one file page after the file pre-reading window from the external storage device to the memory; when the bit corresponding to the last file page indicates that the last file page is not accessed, read all file pages in the file pre-reading window from the external storage device to the memory; wherein, at least one file page after the file pre-reading window and the last file page of the file pre-reading window belong to the same fragment.
[0033] In one possible design, the pre-reading module is used to: determine whether the bit corresponding to the last file page of the file pre-reading window indicates that the last file page is accessed; when the bit corresponding to the last file page indicates that the last file page is accessed, read the at least one file page and the at least one file page after the file pre-reading window from the external storage device to the memory; when the bit corresponding to the last file page indicates that the last file page is not accessed, read the at least one file page from the external storage device to the memory; wherein, the at least one file page after the file pre-reading window and the last file page of the file pre-reading window belong to the same fragment.
[0034] In a possible design, the pre-reading module is further used to update the file access history data corresponding to the file in the external storage device according to the pre-reading model.
[0035] In a possible design, the state acquisition module is used to: acquire the state parameter information when triggering the pre-reading of the file page; or, acquire the state parameter information at a preset period.
[0036] In a possible design, the device for pre-reading file pages may be a terminal device or an internal chip of the terminal device.
[0037] In a third aspect, the present application provides a terminal device, comprising: one or more processors; a memory for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement a method as described in any one of the above-mentioned first aspects.
[0038] In a fourth aspect, the present application provides a computer-readable storage medium, comprising a computer program, wherein when the computer program is executed on a computer, the computer executes any one of the methods described in the first aspect.
[0039] In a fifth aspect, the present application provides a computer program or a computer program product comprising the computer program, which, when executed by a computer, is used to execute any of the methods described in the first aspect.
[0040] In a sixth aspect, the present application provides a chip comprising a processor and a memory, wherein the memory is used to store a computer program, and the processor is used to call and run the computer program stored in the memory to execute a method as described in any one of the above-mentioned first aspects.
[0041] The method, device and terminal device for pre-reading file pages of the present application obtain state parameter information, and the state parameter information can be used to represent at least one of the memory usage state or the I / O processing state, determine the size of the file pre-reading window according to the state parameter information, read the corresponding file page from the external storage device to the memory according to the file pre-reading window, so that the application layer can access the file page, and can adaptively adjust the size of the file pre-reading window based on the state parameter information, and then perform a pre-reading operation according to the size of the file pre-reading window. The number of file pages pre-reading operations based on different file pre-reading window sizes is different, and the file pages of the pre-reading operation occupy different memory resources, thereby realizing adaptive adjustment of the occupation of memory resources by the pre-reading operation. For example, it can be determined based on the state parameter information that the memory usage pressure is large and / or the I / O processing pressure is large. When the memory usage pressure is large and / or the I / O processing pressure is large, the size of the pre-reading window is reduced, thereby reducing the file pages read by the pre-reading operation, thereby alleviating the slow application startup response, jamming and other phenomena, thereby improving the performance of the terminal device. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 A schematic diagram of the hardware structure of an electronic device according to an embodiment of the present application;
[0043] Figure 2 A schematic diagram of the software structure of an electronic device according to an embodiment of the present application;
[0044] Figure 3 A schematic diagram of the software structure of an electronic device according to an embodiment of the present application
[0045] Figure 4A A flow chart of a method for pre-reading a file page according to an embodiment of the present application;
[0046] Figure 4B A schematic diagram of a file pre-reading window according to an embodiment of the present application;
[0047] Figure 5 A flowchart of another method for pre-reading a file page according to an embodiment of the present application;
[0048] Fig. 6A A flowchart of another method for pre-reading a file page according to an embodiment of the present application;
[0049] Figure 6B A schematic diagram of a pre-read file page according to an embodiment of the present application;
[0050] Figure 7 A flowchart of another method for pre-reading a file page according to an embodiment of the present application;
[0051] Figure 8 A schematic diagram of the structure of another terminal device according to an embodiment of the present application. DETAILED DESCRIPTION
[0052] The terms "first", "second", etc. in the specification embodiments, claims, and drawings of the present application are only used for the purpose of distinguishing descriptions, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, including a series of steps or units. The method, system, product, or device is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.
[0053] It should be understood that in this application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0054] The method for pre-reading file pages provided in the embodiment of the present application can be applied to terminal devices such as mobile phones, tablet computers, laptops, ultra-mobile personal computers (UMPCs), handheld computers, netbooks, personal digital assistants (PDAs), wearable electronic devices, virtual reality devices, etc., and the embodiment of the present application does not impose any restrictions on this.
[0055] For example, Figure 1 A schematic structural diagram of the terminal device 100 is shown.
[0056] The terminal device 100 may include: an application processor 101, a microcontroller unit (MCU) 103, a memory 105, a modem 107, a radio frequency (RF) module 109, a wireless fidelity (Wi-Fi) module 111, a Bluetooth module 113, a sensor 114, a positioning module 150, an input / output (I / O) device 115 and other components. These components can communicate via one or more communication buses or signal lines. Those skilled in the art will understand that Figure 1 The hardware structure shown in the figure does not constitute a limitation on the terminal device. The terminal device 100 may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0057] Combine the following Figure 1 The various components of the terminal device 100 are described in detail:
[0058] The application processor 101 is the control center of the terminal device 100, and uses various interfaces and buses to connect various components of the terminal device 100. In some embodiments, the application processor 101 may include one or more processing units.
[0059] The memory 105 stores computer programs such as Figure 1 The operating system 161 and application 163 shown. The application processor 101 is configured to execute the computer program in the memory 105, so as to implement the functions defined by the computer program, for example, the application processor 101 executes the operating system 161 to implement various functions of the operating system on the terminal device 100. The memory 105 also stores other data besides the computer program, such as data generated during the operation of the operating system 161 and the application 163. The memory 105 may include internal memory and external memory. The internal memory includes but is not limited to random access memory (Random Access Memory, RAM), read-only memory (Read-Only Memory, ROM), or cache, etc. The external memory includes but is not limited to flash memory, hard disk, optical disk, universal serial bus (universalserial bus, USB) disk, etc. The computer program is usually stored in the external memory, and the processor loads the program from the external memory to the internal memory before executing the computer program.
[0060] The memory 105 may be independent and connected to the application processor 101 via a bus; the memory 105 may also be integrated with the application processor 101 into a chip subsystem.
[0061] MCU 103 is a coprocessor for acquiring and processing data from sensor 114. The processing capability and power consumption of MCU 103 are less than those of application processor 101, but it has the feature of "always on". It can continuously collect and process sensor data when application processor 101 is in sleep mode, and ensure the normal operation of the sensor with extremely low power consumption. Sensor 114 may include light sensor, motion sensor, gyroscope, barometer, hygrometer, thermometer, infrared sensor, etc., which will not be described in detail here. MCU 103 and sensor 114 may be integrated into the same chip, or they may be separate components connected via a bus.
[0062] Modem 107 and RF module 109 constitute the communication subsystem of terminal device 100, which is used to implement the main functions of wireless communication standard protocols such as 3GPP and ETSI. Among them, Modem 107 is used for encoding and decoding, signal modulation and demodulation, equalization, etc. RF module 109 is used for receiving and sending wireless signals, and RF module 109 includes but is not limited to antenna, at least one amplifier, coupler, duplexer, etc. RF module 109 cooperates with Modem 107 to realize wireless communication function.
[0063] The terminal device 100 can also use a Wi-Fi module 111, a Bluetooth module 113, etc. for wireless communication. The Wi-Fi module 111 is used to provide the terminal device 100 with network access that complies with Wi-Fi-related standard protocols. The terminal device 100 can access a Wi-Fi access point through the Wi-Fi module 111 to access the Internet. In some other embodiments, the Wi-Fi module 111 can also be used as a Wi-Fi wireless access point to provide Wi-Fi network access for other terminal devices. The Bluetooth module 113 is used to implement short-range communication between the terminal device 100 and other terminal devices (such as mobile phones, smart watches, etc.). The Wi-Fi module 111 in the embodiment of the present application can be an integrated circuit or a Wi-Fi chip, etc., and the Bluetooth module 113 can be an integrated circuit or a Bluetooth chip, etc.
[0064] The positioning module 150 is used to determine the geographical location of the terminal device 100. It is understandable that the positioning module 150 can specifically be a receiver of a positioning system such as a global positioning system (GPS), a global navigation satellite system (GLONASS), or a Beidou satellite navigation system (BDS).
[0065] The Wi-Fi module 111, the Bluetooth module 113 and the positioning module 150 can be separate chips or integrated circuits, or they can be integrated together. For example, in one embodiment, the Wi-Fi module 111, the Bluetooth module 113 and the positioning module 150 can be integrated into the same chip. In another embodiment, the Wi-Fi module 111, the Bluetooth module 113, the positioning module 150 and the MCU 103 can also be integrated into the same chip.
[0066] The input / output device 115 includes, but is not limited to, a display 151 , a touch screen 153 , and an audio circuit 155 , etc.
[0067] Among them, the touch screen 153 can collect touch events on or near the terminal device 100 by the user (for example, the user uses a finger, a stylus, or any other suitable object to operate on or near the touch screen 153), and send the collected touch events to other devices (for example, the application processor 101).
[0068] The display (also called display screen) 151 is used to display information input by the user or information presented to the user. The display can be configured in the form of a liquid crystal display screen, an organic light emitting diode, etc.
[0069] The audio circuit 155, the speaker 116, and the microphone 117 can provide an audio interface between the user and the terminal device 100. The audio circuit 155 can transmit the electrical signal converted from the received audio data to the speaker 116, which is converted into a sound signal for output; on the other hand, the microphone 117 converts the collected sound signal into an electrical signal, which is received by the audio circuit 155 and converted into audio data, and then the audio data is sent to, for example, another terminal device through the modem 107 and the radio frequency module 109, or the audio data is output to the memory 105 for further processing.
[0070] In addition, the terminal device 100 may also have a fingerprint recognition function. For example, a fingerprint collection device may be configured on the back of the terminal device 100 (e.g., below the rear camera), or on the front of the terminal device 100 (e.g., below the touch screen 153).
[0071] Furthermore, the operating system 161 carried by the terminal device 100 may be iOS®, Android®, Microsoft® or other operating systems, and the embodiments of the present application do not impose any restrictions on this.
[0072] Take the terminal device 100 equipped with the Android® operating system as an example. Figure 2As shown, the terminal device 100 can be logically divided into a hardware layer 21, an operating system 161, and an application layer 31. The hardware layer 21 includes the application processor 101, the microcontroller unit 103, the memory 105, the modem 107, the Wi-Fi module 111, the sensor 114, the positioning module 150 and other hardware resources as described above. The application layer 31 includes one or more application programs, such as the application 163, which can be any type of application program such as a social application, an e-commerce application, a browser, etc. The operating system 161, as the software middleware between the hardware layer 21 and the application layer 31, is a computer program that manages and controls hardware and software resources.
[0073] In one embodiment, the operating system 161 includes a kernel 23, a hardware abstraction layer (HAL) 25, libraries and runtime 27, and a framework 29. The kernel 23 is used to provide underlying system components and services, such as power management, memory management, file system management, thread management, hardware drivers, etc.; hardware drivers include Wi-Fi drivers, sensor drivers, positioning module drivers, etc. The hardware abstraction layer 25 is an encapsulation of the kernel driver, providing an interface to the framework 29 and shielding the low-level implementation details. The hardware abstraction layer 25 runs in the user space, while the kernel driver runs in the kernel space.
[0074] The library and runtime 27 is also called the runtime library, which provides the required library files and execution environment for the executable program at runtime.
[0075] The framework 29 is used to provide various basic common components and services for the application programs in the application layer 31, such as window management, position management, etc.
[0076] The functions of the various components of the operating system 161 described above may be implemented by the application processor 101 executing a program stored in the memory 105 .
[0077] Taking the memory 105 including internal memory and external memory as an example, the memory management and file system management of the kernel 23 in the above operating system 161 are explained as follows: Figure 3As shown, the hardware layer 21 may include a memory 1051 and an external memory 1052, the kernel 23 may include a memory management 231 and a file system management 232, and the application processor 101 of the embodiment of the present application may be configured to execute a computer program in the memory 105, thereby implementing the method of pre-reading file pages of the embodiment of the present application, so that the memory management 231 can dynamically adjust the size of the file pre-read window according to the status parameter information, and the memory management 231 sends a pre-read request to the file system management 232 based on the size of the file pre-read window, and the file system management 232 reads the corresponding file page from the external memory 1052 to the memory 1051, thereby improving the performance of the terminal device 100.
[0078] It should be noted that the above-mentioned external memory can also be called external memory.
[0079] Those skilled in the art will appreciate that the terminal 100 may include Figure 1 Fewer or more components than shown, Figure 1 The terminal device shown only includes components that are more relevant to the multiple implementation methods disclosed in the embodiments of the present application.
[0080] The "file" mentioned in this application refers to a collection of information stored on a terminal device using a memory as a carrier. A file can be a text document, picture, audio or video, executable program, etc.
[0081] The "file page" involved in this application refers to the constituent unit of a file. The operating system can perform I / O on the file in units of file pages to facilitate memory management. The file as described above may include one or more file pages, each of which is of equal size, for example, 4 kilobytes (KB). Each file page corresponds to a different sequence number.
[0082] For ease of understanding, the following embodiments of the present application will be described in detail with Figures 1 to 3 Taking the terminal device with the structure shown as an example, the method for pre-reading file pages provided in the embodiment of the present application is explained in conjunction with the accompanying drawings.
[0083] Figure 4A This is a flow chart of a method for pre-reading a file page according to an embodiment of the present application. Figure 4A As shown, the method of this embodiment may be executed by a terminal device or a processor of the terminal device, and the processor may be an application processor. The method may include:
[0084] Step 101: Obtain status parameter information.
[0085] The status parameter information can be used to indicate at least one of the memory usage status or the I / O processing status. The memory usage status can be understood as the memory usage of computer programs, data generated during the operation of computer programs, cache data (e.g., cache file pages), etc., or the availability of memory. The I / O processing status can be understood as the processing of I / O requests, for example, the number of I / O requests that need to be processed.
[0086] Exemplarily, the status parameter information may include at least one of a memory parameter or an I / O parameter. The memory parameter may include at least one of a memory occupancy, a memory usage rate, or a cumulative number of page faults. The I / O parameter may include at least one of an I / O queue length or an I / O request data volume.
[0087] In some embodiments, the above-mentioned state parameter information can be obtained when triggering the pre-reading of file pages; or, the above-mentioned state parameter information can be obtained at a preset period. Exemplarily, the way to trigger the pre-reading of file pages can be to determine whether there is a page missing when processing a file page read request issued by the user state. The page missing means that the file page to be read is not in the memory. If a page missing occurs, the pre-reading of file pages is triggered. The way of pre-reading file pages can also be called synchronous pre-reading, that is, the file pre-reading window includes the currently accessed file page. Another way to trigger the pre-reading of file pages can be to pre-read a part of the file pages after the currently accessed file page in a sequential reading scenario. The way of pre-reading file pages can also be called asynchronous pre-reading, that is, when no page missing occurs, a part of the pages after the currently accessed file page can also be pre-read in advance.
[0088] As an example, the application layer 31 can read the file page through system calls such as read() and mmap(), and the operating system 161 can determine whether to trigger the pre-reading of the file page in the above manner. When the pre-reading of the file is triggered, the above Figure 3 The memory management 231 shown can obtain the state parameter information.
[0089] Step 102: Determine the size of the file pre-reading window according to the status parameter information.
[0090] The file pre-reading window is used to represent a set of one or more file pages in a file. For example, a specific form of the file pre-reading window may be a set of continuous file page numbers. Another specific form of the file pre-reading window may be a starting file page number and an ending file page number. Another specific form of the file pre-reading window may be a starting file page number and a window length. The unit of the window length is a file page. It should be noted that the file pre-reading window may also be in other specific forms, such as a window length and an ending file page number, etc. The embodiments of the present application do not give examples one by one. Figure 4BThe file pre-reading window is schematically described as follows: Figure 4B As shown, the file pre-reading window 1 starts from the 1st file page and ends at the 4th file page, and the file pre-reading window 2 starts from the 1st file page and ends at the 6th file page.
[0091] The embodiment of the present application can determine the size of the file pre-reading window, that is, the window length, according to the state parameter information. The window length can be the number of file pages included in the file pre-reading window. For example, Figure 4B The window length of the file pre-reading window 1 shown is 4. For example, when it is determined according to the state parameter information that the memory usage is greater than a preset threshold, the size of the file pre-reading window can be determined to be a smaller value, such as Figure 4B The file pre-reading window 1 shown in the figure can reduce the pre-read file pages when the memory usage pressure is large. When it is determined according to the status parameter information that the memory usage is less than the preset threshold, the size of the file pre-reading window can be determined to be a larger value, such as Figure 4B The file pre-reading window 2 shown in the figure increases the pre-reading file pages when the memory space is free.
[0092] In some embodiments, when the status parameter information indicates that at least one of the memory usage pressure or the IO processing pressure is at a first level, the size of the file pre-read window is reduced; when the status parameter information indicates that at least one of the memory usage pressure or the IO processing pressure is at a second level, the size of the file pre-read window is increased; wherein the first level of memory usage pressure or the IO processing pressure is greater than the second level of memory usage pressure or the IO processing pressure. For example, the first level may refer to a level at which the memory usage pressure and / or the IO processing pressure is greater, and the second level may refer to a level at which the memory usage pressure and / or the IO processing pressure is greater. For example, if the above-mentioned memory usage is greater than a preset threshold, the memory usage pressure is at the first level, and if the memory usage is less than the preset threshold, the memory usage pressure is at the second level.
[0093] One possible way to reduce the size of the file pre-reading window is to reset the size of the file pre-reading window to a value that is smaller than the original size. Another possible way is to reduce the size of the file pre-reading window by a value based on the original size.
[0094] The position of the file pre-reading window may be determined according to the position of the file page that triggers the pre-reading, for example, may be determined according to the position of the missing page, but the embodiments of the present application are not limited thereto.
[0095] An example is given above. Figure 3 After the memory management 231 obtains the state parameter information, the size of the file pre-reading window can be determined according to the state parameter information.
[0096] Step 103: Read the corresponding file page from the external storage device into the memory according to the file pre-reading window, so that the application layer can access the file page.
[0097] For example, the above Figure 3 After determining the size of the file pre-reading window, the memory management 231 shown may send a pre-reading request to the file system management 232 based on the size of the file pre-reading window, and the file system management 232 reads the corresponding file page from the external memory 1052 to the memory 1051 .
[0098] The embodiment of the present application pre-reads the corresponding file pages based on the file pre-read window, and can reduce the pre-read file pages when the memory usage pressure is high and / or the I / O processing pressure is high. When the memory usage pressure and / or the I / O processing pressure is low, the pre-read file pages are increased. That is, the occupation of memory resources by the pre-read operation can be adaptively adjusted based on the file pre-read window to improve the performance of the terminal device.
[0099] In this embodiment, by obtaining state parameter information, the state parameter information can be used to indicate at least one of the memory usage state or the I / O processing state, the size of the file pre-read window is determined according to the state parameter information, and the corresponding file page is read from the external storage device to the memory according to the file pre-read window, so that the application layer can access the file page. The size of the file pre-read window can be adaptively adjusted based on the state parameter information, and then the pre-read operation can be performed according to the size of the file pre-read window. The number of file pages pre-reading the operation based on different file pre-read window sizes is different, and the file pages of the pre-read operation occupy different memory resources, thereby realizing adaptive adjustment of the occupation of memory resources by the pre-read operation. For example, it can be determined based on the state parameter information that the memory usage pressure is large and / or the I / O processing pressure is large. When the memory usage pressure is large and / or the I / O processing pressure is large, the size of the pre-read window is reduced, thereby reducing the file pages read by the pre-read operation, thereby alleviating the slow application startup response, jamming, etc., thereby improving the performance of the terminal device.
[0100] Several specific embodiments are used below. Figure 4A The technical solution of the method embodiment shown is described in detail.
[0101] Figure 5 This is another flow chart of a method for pre-reading a file page according to an embodiment of the present application. Figure 5 As shown, the method of this embodiment can be executed by a terminal device or a processor of the terminal device. This embodiment is illustrated by taking the state parameter information including memory parameters and I / O parameters as an example. The method may include:
[0102] Step 201: Obtain memory parameters and I / O parameters.
[0103] For the specific explanations of the memory parameters and I / O parameters, reference can be made to Figure 4A the explanation in step 101 of the embodiment shown, which will not be elaborated here.
[0104] Step 202: Determine a first metric according to the memory parameters and I / O parameters.
[0105] In the embodiments of the present application, the memory parameters and I / O parameters can be used to determine the first metric by means of summation, weighted summation, etc. This first metric can also be referred to as a comprehensive pressure metric. In the embodiments of the present application, X is used to represent the value of the first metric. The larger the value of X, the greater the memory usage pressure and / or I / O processing pressure, that is, the higher the memory utilization rate and / or the longer the I / O queue length. Of course, it can be understood that it can also be set that the smaller the value of X, the greater the memory usage pressure and / or I / O processing pressure, that is, the higher the memory utilization rate and / or the longer the I / O queue length. In the embodiments of the present application, an example is given with the larger the value of X, the greater the memory usage pressure and / or I / O processing pressure.
[0106] Step 203: Determine the size of the file prefetch window according to the first metric.
[0107] For example, the above Figure 3 shown memory management 231 can determine the size of the file prefetch window according to this first metric.
[0108] One implementable way is to set n thresholds, X1 < X2 <... < Xn. These n thresholds can divide the value range of X into (n + 1) numerical intervals. These (n + 1) numerical intervals can be: [0, X1], (X1, X2], ……, (Xn, ∞). Set each numerical interval to correspond to a window size, and the window sizes corresponding to the above (n + 1) numerical intervals decrease in sequence. One implementable way of the above step 203 is: determine the numerical interval to which the first metric belongs according to the first metric, and use the window size corresponding to the numerical interval to which the first metric belongs as the size of the file prefetch window.
[0109] Step 204: Read corresponding file pages from the external storage device into the memory according to the file prefetch window for the application layer to access the file pages.
[0110] Among them, for the explanation of step 204, reference can be made to Figure 4A step 103 of the embodiment shown, which will not be elaborated here.
[0111] In this embodiment, by obtaining memory parameters and I / O parameters, determining a first indicator according to the memory parameters and the I / O parameters, determining the size of a file pre-read window according to the first indicator, and reading corresponding file pages from an external storage device to a memory according to the file pre-read window, so that an application layer can access the file pages, thereby adaptively adjusting the occupation of memory resources by pre-read operations based on memory parameters and I / O parameters. When the memory usage pressure is high and / or the I / O processing pressure is high, the size of the pre-read window is reduced, thereby reducing the file pages read by the pre-read operation, thereby alleviating the slow application startup response, jamming, and other phenomena, thereby improving the performance of the terminal device.
[0112] Based on any of the above embodiments, the embodiments of the present application can also use a pre-reading model to increase the pre-reading hit rate, that is, to increase the probability of the file page read from the external storage device to the memory being accessed by the application layer, thereby reducing invalid pre-reading. The specific implementation method can refer to the explanation of the following embodiment.
[0113] One possible implementation method of step 103 or step 204 is: selecting at least one file page in the file pre-read window as a pre-read page according to a pre-read model, and reading the pre-read page from an external storage device into a memory, wherein the pre-read model is a data structure in the memory determined according to real-time file access data and historical file access data, the pre-read model corresponds to the file, the real-time file access data is not synchronized with the historical file access data, and the historical file access data is the data in the external storage device.
[0114] The file access history data may include at least one of the position, length, or time of the read access request before the current file opening. The file access history data may come from an external storage device, for example, the file access history data may include the file page number of the file accessed by the application layer before the current file opening, for example, the file access history data may include 2, 3, and 10, which means that the application layer accessed the file pages with the sequence numbers 2, 3, and 10 before the current file opening. The file access real-time data may include at least one of the position, length, or time of the read access request after the current file opening, for example, the file access real-time data may include at least one of the position, length, or time of the read access request after the current file opening and before the current file closing, that is, the file access real-time data is the data generated by the application layer in the process of accessing the file, for example, the file access real-time data may include the file page number of the file accessed by the application layer, for example, the file access real-time data may include 1, 2, and 10, which means that the application layer accessed the file pages with the sequence numbers 1, 2, and 10. Of course, it can be understood that the above-mentioned file access history data and the above-mentioned file access real-time data can also be bit maps. For example, the file access history data can include 2, 3 and 10. Assuming that the file corresponding to the file access history data has 11 file pages, the file access history data can be 01100000010.
[0115] The pre-reading model is a data structure in memory determined according to at least one of the real-time data of file access and the historical data of file access. In one implementation, the pre-reading model may be a bitmap. For example, the pre-reading model may include N bits, each bit corresponding to a file page of the file, and each bit used to indicate whether the file page corresponding to the bit has been accessed, and N is an integer greater than or equal to 1. When the bit is 0, it indicates that the corresponding file page has not been accessed, and when the bit is 1, it indicates that the corresponding file page has been accessed. Of course, it can be understood that the bit can also be used to indicate that the corresponding file page has not been accessed when the bit is 1, and the corresponding file page can be accessed when the bit is 0. The embodiment of the present application is illustrated by taking the example that the bit is 0 to indicate that the corresponding file page has not been accessed, and the bit is 1 to indicate that the corresponding file page has been accessed. Being accessed or not accessed refers to being accessed or not accessed during the startup process or running process of the application. For example, file A includes 15 file pages, and the 1st, 2nd, 3rd and 10th file pages have been accessed (including historical and real-time), the pre-reading model of file A may be 111000000100000.
[0116] After determining the file pre-reading window based on the state parameter information, the embodiment of the present application can select one or more file pages as pre-reading pages in the file pre-reading window based on the pre-reading model, and read the pre-reading pages from the external storage device to the memory. Taking the pre-reading model of file A as 111000000100000 as an example for further explanation, the file pre-reading window determined by the above embodiment starts from the first file page, and the window length is 11. According to the pre-reading model of file A, the first, second, third and tenth file pages in the file pre-reading window can be selected as pre-reading pages, and the first, second, third and tenth file pages are read from the external storage device to the memory, while the remaining file pages in the file pre-reading window of file A are not pre-read, thereby reducing the memory occupation of the pre-reading operation and reducing invalid pre-reading.
[0117] Fig. 6A This is another flow chart of a method for pre-reading a file page according to an embodiment of the present application. Fig. 6A As shown, the method of this embodiment may be executed by a terminal device or a processor of the terminal device, and the method of this embodiment may include:
[0118] Step 301: Obtain status parameter information.
[0119] Step 302: Determine the size of the file pre-reading window according to the status parameter information.
[0120] The explanation of step 301 and step 302 can be found in Figure 4A Step 101 and step 102 of the illustrated embodiment will not be described in detail here.
[0121] Step 303: Select at least one file page in the file pre-reading window as a pre-reading page according to the pre-reading model.
[0122] The explanation of the pre-reading model and the selection of the pre-reading page according to the pre-reading model can be found in the above embodiment, which will not be described in detail here.
[0123] Step 304 , determining whether the number of fragments formed by the pre-read pages is greater than a first threshold, if so, executing step 305 , if not, executing step 306 .
[0124] The "fragment" mentioned in this application refers to a number of file pages with consecutive serial numbers in a file.
[0125] As described above, several file pages with consecutive serial numbers in a file can constitute a fragment. The embodiment of the present application can determine the final pre-read file page based on the number of fragments constituted by the pre-read pages. The above selection of the 1st, 2nd, 3rd and 10th file pages of file A as pre-read pages is further illustrated as an example, wherein the 1st, 2nd and 3rd file pages can constitute a fragment, and the 10th page is a fragment, so the number of fragments constituted by the pre-read page is 2. The number of fragments constituted by the pre-read page (2) is compared with the first threshold. If it is greater than, all pages in the file pre-read window are read through the following step 305, for example, the 1st to 11th file pages of file A are read. If it is less than or equal to, the pre-read file pages are read through the following step 306, for example, the 1st, 2nd, 3rd and 10th file pages of file A are read. The value of the first threshold can be 3, 4, 5, etc., which can be flexibly set according to needs. The first threshold can also be dynamically adjusted according to the current memory usage status and / or I / O processing status.
[0126] Step 305: read all file pages in the file pre-reading window from the external storage device into the memory.
[0127] When the number of fragments formed by the pre-read pages is greater than the first threshold, that is, the number of fragments is large, since a large number of fragments will cause I / O fragmentation and affect the I / O processing efficiency, the embodiment of the present application reads all file pages in the file pre-read window from the external storage device to the memory when the number of fragments is large, so as to avoid I / O fragmentation.
[0128] Step 306: Read the pre-read page from the external storage device into the memory.
[0129] When the number of fragments composed of pre-read pages is less than or equal to a first threshold, the pre-read pages can be read from the external storage device into the memory, and the remaining file pages in the file pre-read window except the pre-read pages are not pre-read, thereby reducing the memory occupancy of the pre-read operation and reducing invalid pre-reading.
[0130] In some embodiments, when executing step 305 or step 306, the method of the embodiment of the present application can also determine whether to read the file page outside the file pre-read window into the memory according to the bit corresponding to the last file page in the file pre-read window. For example, according to the pre-read model, the bit value corresponding to the last file page in the file pre-read window is 1, then the range of the file pre-read window can be crossed, and the bit value corresponding to each file page can be checked backward in sequence until a complete fragment is determined (that is, the first bit with a value of 0 after the pre-read window is found, or the last page of the file is checked), and all the file pages therein are read into the memory. A second threshold value can also be set, and when the total number of file pages selected for this pre-reading (the number of file pages that need to be read into the memory in step 305 or step 306 and the number of file pages that need to be read into the memory outside the file pre-read window) is greater than or equal to the second threshold value, the backward check is stopped.
[0131] Take the pre-reading model of file A as [1110 0001] 1111 1100 as an example for further explanation, where the area within [ ] is the file pre-reading window. If the second threshold is not set, the 1st to 3rd and 8th to 14th pages of file A are selected as pre-reading pages; if the second threshold is set to 8, that is, at most 8 file pages are selected for this pre-reading, the 1st to 3rd and 8th to 12th pages are selected as pre-reading pages.
[0132] Exemplarily, one possible implementation of step 305 is to determine whether the bit corresponding to the last file page in the file pre-reading window indicates that the last file page is accessed. When the bit corresponding to the last file page indicates that the last file page is accessed, all file pages in the file pre-reading window and at least one file page after the file pre-reading window are read from the external storage device to the memory. When the bit corresponding to the last file page indicates that the last file page is not accessed, all file pages in the file pre-reading window are read from the external storage device to the memory. Among them, at least one file page after the file pre-reading window and the last file page in the file pre-reading window belong to the same fragment.
[0133] Optionally, one achievable manner of reading all file pages in the file pre-reading window and at least one file page after the file pre-reading window from the external storage device into the memory is to read M file pages among all file pages in the file pre-reading window and at least one file page after the file pre-reading window from the external storage device into the memory. The M may represent the second threshold value.
[0134] Exemplarily, one possible implementation of step 306 is to determine whether the bit corresponding to the last file page of the file pre-reading window indicates that the last file page is accessed. When the bit corresponding to the last file page indicates that the last file page is accessed, the pre-reading page and at least one file page after the file pre-reading window are read from the external storage device into the memory. When the bit corresponding to the last file page indicates that the last file page is not accessed, the pre-reading page is read from the external storage device into the memory. The at least one file page after the file pre-reading window and the last file page of the file pre-reading window belong to the same fragment.
[0135] Optionally, one possible way to read the pre-read page and at least one file page after the file pre-read window from the external storage device into the memory is to read M file pages among the pre-read page and at least one file page after the file pre-read window from the external storage device into the memory.
[0136] by Figure 6B Give an example, such as Figure 6B As shown, the pre-reading model of file B is 10101100, and the file pre-reading window is the 1st to 5th file pages, wherein the black square indicates that the corresponding bit of the pre-reading model is 1, and the white square indicates that the corresponding bit of the pre-reading model is 0. Through the above-mentioned step 305 and the above-mentioned implementation method, it can be determined that the bit corresponding to the last file page (the 5th file page) of the file pre-reading window indicates that it is accessed, and then all the file pages (the 1st to 5th file pages) in the file pre-reading window and at least one file page after the file pre-reading window (for example, the 6th file page) can be read from the external storage device to the memory. Alternatively, through the above-mentioned step 306 and the above-mentioned implementation method, it can be determined that the bit corresponding to the last file page (the 5th file page) of the file pre-reading window indicates that it is accessed, and then the pre-reading pages (the 1st, 3rd and 5th file pages) in the file pre-reading window and at least one file page (for example, the 6th file page) after the file pre-reading window can be read from the external storage device to the memory.
[0137] In this embodiment, by obtaining status parameter information, the size of the file pre-reading window is determined according to the status parameter information, at least one file page in the file pre-reading window is selected as the pre-reading page according to the pre-reading model, and it is determined whether the number of fragments constituted by the pre-reading page is greater than a first threshold value. If so, all file pages in the file pre-reading window are read from the external storage device into the memory. If not, the pre-reading page is read from the external storage device into the memory, thereby realizing adaptive adjustment of the memory resource occupation by the pre-reading operation based on the status parameter information, which can alleviate the slow response and jamming of the application startup, thereby improving the performance of the terminal device.
[0138] And by comparing the number of fragments formed by the pre-read pages with the size of the first threshold, when the number of formed fragments is greater than the first threshold, all file pages in the file pre-read window are read from the external storage device to the memory, which can avoid I / O fragmentation caused by a large number of fragments and improve I / O processing efficiency. When the number of formed fragments is less than or equal to the first threshold, the pre-read pages are read from the external storage device to the memory, and the remaining file pages in the file pre-read window except the pre-read pages are not pre-read, thereby reducing the memory occupation of the pre-read operation and reducing invalid pre-reading.
[0139] By determining whether the last file page in the file pre-read window has been accessed, when the last file page is accessed, the file page belonging to the same fragment as the last file page is read into the memory, thereby avoiding I / O fragmentation caused by the division of the pre-read window boundary (that is, some pages in the same fragment are divided outside the window and have to be read again when they are accessed next time, increasing the number of I / O times), thereby improving I / O processing efficiency.
[0140] Based on any of the above embodiments, the method for pre-reading file pages of the present application can also update the file access history data corresponding to the file in the external storage device according to the above pre-reading model. It should be noted that before using the pre-reading model to update, the file access history data corresponding to the file can be empty.
[0141] In one implementable manner, the file access history data corresponding to the file in the external storage device is periodically updated according to the pre-reading model by a kernel thread.
[0142] The external storage device can allocate different read / write paths to different files, and the storage space corresponding to the read / write path stores the file access history data corresponding to a file. For example, when it is necessary to select a pre-read page, the file system management 232 can read the file access history data from the storage space corresponding to the file's read / write path into the memory to determine the pre-read model based on the file access history data and the file access real-time data. After the pre-read operation, the file system management 232 can write the pre-read model into the storage space corresponding to the file's read / write path in the same format as the file access history data, that is, update the file access history data stored in the storage space.
[0143] Figure 7 This is another flow chart of a method for pre-reading a file page according to an embodiment of the present application. Figure 7 As shown, this embodiment takes the application layer 31 and the operating system 161 as an example to explain the method of the embodiment of the present application. The method of this embodiment may include:
[0144] Step 401: The application layer triggers opening a file.
[0145] For example, when an application in the application layer is started, it triggers the opening of a file.
[0146] Step 402: Create an initialized pre-reading model.
[0147] For example, creating an initialized pre-reading model may be generating a bitmap including N bits, where the initial values of the N bits are all 0.
[0148] Step 403, determine whether there is file access history data in the storage space corresponding to the read-write path corresponding to the file, if yes, execute step 404, if not, end.
[0149] Step 404: read the file access history data into the memory, and fill the file access history data into the initialized pre-reading model after parsing.
[0150] For example, if the file access history data indicates that the 1st, 2nd, 3rd, and 10th file pages have been accessed, the values of the 1st, 2nd, 3rd, and 10th bits among the above N bits may be updated to 1.
[0151] Step 405: The application layer triggers access to a file page of the file.
[0152] For example, the application layer can read a file page through system calls such as read() and mmap().
[0153] Step 406: Record the information of accessing the file page into the pre-reading model.
[0154] For example, when an application triggers access to the 4th file page of a file, the value of the 4th bit in the above N bits is updated to 1, and the updated pre-reading model is 11110000010000….
[0155] Step 407, determine whether a page fault occurs, if so, execute step 408, if not, end.
[0156] Determine whether the 4th file page of the file is in the memory. If not, it can be determined that a page fault has occurred.
[0157] Step 408: Obtain status parameter information.
[0158] Step 409: Determine the size of the file pre-reading window according to the status parameter information.
[0159] The explanation of step 408 and step 409 can be found in Figure 4A Step 101 and step 102 of the illustrated embodiment will not be described in detail here.
[0160] Step 410: Select at least one file page in the file pre-reading window as a pre-reading page according to the pre-reading model, and issue an I / O request.
[0161] The pre-read page is read from the external storage device to the memory through the I / O request so as to be accessed by the application layer.
[0162] This embodiment can realize adaptive adjustment of the occupation of memory resources by pre-reading operation based on state parameter information, which can alleviate the slow response and freeze of application startup, thereby improving the performance of terminal equipment. In addition, the pre-reading model can be used to increase the pre-reading hit rate, increase the probability of file pages read from the external storage device to the memory being accessed by the application layer, thereby reducing invalid pre-reading.
[0163] It is understandable that, in order to implement the above functions, the terminal device includes hardware and / or software modules corresponding to the execution of each function. 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.
[0164] In this embodiment, the terminal device can be divided into functional modules according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware. It should be noted that the division of modules in this embodiment is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0165] In the case of dividing each functional module into corresponding functional modules, Figure 8 A possible schematic diagram of the composition of the terminal device 800 involved in the above embodiment is shown. Figure 8 As shown, the terminal device 800 may include: a state acquisition module 801 , a pre-reading window determination module 802 and a pre-reading module 803 .
[0166] The status acquisition module 801 may be used to support the terminal device 800 in executing the above-mentioned steps 101, 201, etc., and / or other processes of the technology described herein.
[0167] The pre-reading window determination module 802 may be used to support the terminal device 800 in executing the above steps 102 , 202 , 203 , etc., and / or other processes for the technology described herein.
[0168] The pre-reading module 803 may be used to support the terminal device 800 in executing the above-mentioned steps 103, 204, 303, 304, etc., and / or other processes for the technology described herein.
[0169] It should be noted that 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.
[0170] The terminal device provided in this embodiment is used to execute the above method of pre-reading file pages, and thus can achieve the same effect as the above implementation method.
[0171] In the case of using an integrated unit, the terminal device may include a processing module, a storage module and a communication module. The processing module may be used to control and manage the actions of the terminal device, for example, it may be used to support the terminal device in executing the steps performed by the above-mentioned state acquisition module 801, pre-reading window determination module 802 and pre-reading module 803. The storage module may be used to support the terminal device in executing stored program codes and data, etc. The communication module may be used to support the communication between the terminal device and other devices.
[0172] Among them, the processing module can be a processor or a controller. It can implement or execute various exemplary logic boxes, modules and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module can be a memory. The communication module can specifically be a device that interacts with other devices, such as a radio frequency circuit, a Bluetooth chip, a Wi-Fi chip, etc.
[0173] In one embodiment, when the processing module is a processor and the storage module is a memory, the terminal device involved in this embodiment may be a Figure 1 Device of the structure shown.
[0174] This embodiment also provides a computer storage medium, in which computer instructions are stored. When the computer instructions are executed on an electronic device, the terminal device executes the above-mentioned related method steps to implement the method of pre-reading file pages in the above embodiment.
[0175] This embodiment further provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute the above-mentioned related steps to implement the method for pre-reading file pages in the above-mentioned embodiment.
[0176] 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 execution instructions, and when the device is running, the processor can execute the computer execution instructions stored in the memory to enable the chip to execute the method of pre-reading file pages in the above-mentioned method embodiments.
[0177] Among them, the terminal 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.
[0178] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0179] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0180] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0181] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0182] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
Claims
1. A method for pre-reading a file page, characterized in that: include: Acquire state parameter information, where the state parameter information is used to represent at least one of a memory usage state or an input / output (IO) processing state; Determine the size of the file pre-reading window according to the state parameter information; Reading corresponding file pages from an external storage device into a memory according to the file pre-reading window; Wherein, reading the corresponding file page from the external storage device to the memory according to the file pre-reading window includes: Selecting at least one file page in the file pre-reading window according to the pre-reading model, and reading the at least one file page from the external storage device into the memory; The pre-reading model is a data structure in the memory determined according to at least one of the file access real-time data and the file access history data, the pre-reading model corresponds to the file, the file access real-time data is not synchronized with the file access history data, and the file access history data is data in the external storage device; The pre-reading model includes N bits, each bit corresponds to a file page of the file, each bit is used to indicate whether the file page corresponding to the bit is accessed, and N is an integer greater than or equal to 1; Determining whether the number of fragments formed by the at least one file page is greater than a first threshold; If the number of fragments formed by the at least one file page is greater than a first threshold, all file pages in the file pre-reading window are read from the external storage device to the memory; If the number of fragments formed by the at least one file page is less than or equal to a first threshold, executing a step of reading the at least one file page from an external storage device into a memory; The step of reading the at least one file page from the external storage device to the memory includes: Determining whether a bit corresponding to the last file page of the file pre-reading window indicates that the last file page is accessed; When the bit corresponding to the last file page indicates that the last file page is accessed, reading the at least one file page and at least one file page after the file pre-reading window from the external storage device into the memory; When the bit corresponding to the last file page indicates that the last file page has not been accessed, reading the at least one file page from the external storage device into the memory; The at least one file page after the file pre-reading window and the last file page of the file pre-reading window belong to the same segment.
2. The method according to claim 1, characterized in that The determining the size of the file pre-reading window according to the state parameter information includes: when the state parameter information indicates that at least one of the memory usage pressure or the IO processing pressure is at a first level, reducing the size of the file pre-reading window; when the state parameter information indicates that at least one of the memory usage pressure or the IO processing pressure is at a second level, increasing the size of the file pre-reading window; The first level of memory usage pressure or IO processing pressure is greater than the second level of memory usage pressure or IO processing pressure.
3. The method according to claim 1 or 2, characterized in that: The status parameter information includes at least one of a memory parameter or an IO parameter, the memory parameter includes at least one of a memory occupancy, a memory usage rate, or a cumulative number of page faults, and the IO parameter includes an IO queue length.
4. The method according to claim 3, characterized in that Determining the size of the file pre-reading window according to the state parameter information includes: Determine a first indicator according to at least one of the memory parameter and the IO parameter; The size of the file pre-reading window is determined according to the first indicator.
5. The method according to claim 4, characterized in that The determining the size of the file pre-reading window according to the first indicator includes: Determine, according to the first indicator, a numerical range to which the first indicator belongs; The window size corresponding to the numerical interval to which the first indicator belongs is used as the size of the file pre-reading window.
6. The method according to claim 1, characterized in that The step of reading all file pages in the file pre-reading window from the external storage device to the memory includes: Determining whether a bit corresponding to the last file page of the file pre-reading window indicates that the last file page is accessed; When the bit corresponding to the last file page indicates that the last file page is accessed, all file pages in the file pre-reading window and at least one file page after the file pre-reading window are read from the external storage device into the memory; When the bit corresponding to the last file page indicates that the last file page has not been accessed, all file pages in the file pre-reading window are read from the external storage device to the memory; The at least one file page after the file pre-reading window and the last file page of the file pre-reading window belong to the same segment.
7. The method according to any one of claims 1 to 2, 4 to 6, characterized in that: The file access history data includes at least one of the position, length, or time of the read access request before the file is opened this time, and the file access real-time data includes at least one of the position, length, or time of the read access request after the file is opened this time.
8. The method according to any one of claims 1 to 2, 4 to 6, characterized in that: The method further comprises: The file access history data corresponding to the file in the external storage device is updated according to the pre-reading model.
9. The method according to any one of claims 1 to 2, 4 to 6, characterized in that: The obtaining of status parameter information includes: Acquire the state parameter information when triggering the pre-reading of the file page; or, The state parameter information is obtained at a preset period.
10. A device for pre-reading a file page, characterized in that: include: A state acquisition module, used to acquire state parameter information, where the state parameter information is used to represent at least one of a memory usage state or an input / output (IO) processing state; A pre-reading window determination module, used to determine the size of the file pre-reading window according to the state parameter information; A pre-reading module, used for reading corresponding file pages from an external storage device into a memory according to the file pre-reading window; The pre-reading module is further used for: selecting at least one file page in the file pre-reading window according to the pre-reading model, and reading the at least one file page from the external storage device to the memory; wherein the pre-reading model is a data structure in the memory determined according to at least one of the file access real-time data and the file access history data, the pre-reading model corresponds to the file, the file access real-time data is not synchronized with the file access history data, and the file access history data is the data in the external storage device; The pre-reading model includes N bits, each bit corresponds to a file page of the file, each bit is used to indicate whether the file page corresponding to the bit is accessed, and N is an integer greater than or equal to 1; The pre-reading module is also used to: determine whether the number of fragments formed by the at least one file page is greater than a first threshold; if the number of fragments formed by the at least one file page is greater than the first threshold, read all file pages in the file pre-reading window from the external storage device to the memory; if the number of fragments formed by the at least one file page is less than or equal to the first threshold, execute the step of reading the at least one file page from the external storage device to the memory; The pre-reading module is also used for: Determining whether a bit corresponding to the last file page of the file pre-reading window indicates that the last file page is accessed; When the bit corresponding to the last file page indicates that the last file page is accessed, reading the at least one file page and at least one file page after the file pre-reading window from the external storage device into the memory; When the bit corresponding to the last file page indicates that the last file page has not been accessed, reading the at least one file page from the external storage device into the memory; The at least one file page after the file pre-reading window and the last file page of the file pre-reading window belong to the same segment.
11. The device according to claim 10, characterized in that The pre-reading window determination module is used to: when the state parameter information indicates that at least one of the memory usage pressure or the IO processing pressure is at a first level, reduce the size of the file pre-reading window; when the state parameter information indicates that at least one of the memory usage pressure or the IO processing pressure is at a second level, increase the size of the file pre-reading window; The first level of memory usage pressure or IO processing pressure is greater than the second level of memory usage pressure or IO processing pressure.
12. The device according to claim 10 or 11, characterized in that The status parameter information includes at least one of a memory parameter or an IO parameter, the memory parameter includes at least one of a memory occupancy, a memory usage rate, or a cumulative number of page faults, and the IO parameter includes an IO queue length.
13. The device according to claim 12, characterized in that The pre-reading window determination module is used to: determine a first indicator according to at least one of the memory parameter and the IO parameter; and determine a size of the file pre-reading window according to the first indicator.
14. The device according to claim 13, characterized in that The pre-reading window determination module is used to: determine the numerical interval to which the first indicator belongs according to the first indicator; and use the window size corresponding to the numerical interval to which the first indicator belongs as the size of the file pre-reading window.
15. The device according to claim 10, characterized in that The pre-reading module is used for: Determining whether a bit corresponding to the last file page of the file pre-reading window indicates that the last file page is accessed; When the bit corresponding to the last file page indicates that the last file page is accessed, all file pages in the file pre-reading window and at least one file page after the file pre-reading window are read from the external storage device into the memory; When the bit corresponding to the last file page indicates that the last file page has not been accessed, all file pages in the file pre-reading window are read from the external storage device to the memory; The at least one file page after the file pre-reading window and the last file page of the file pre-reading window belong to the same segment.
16. The device according to any one of claims 10 to 11, 13 to 15, characterized in that The file access history data includes at least one of the position, length, or time of the read access request before the file is opened this time, and the file access real-time data includes at least one of the position, length, or time of the read access request after the file is opened this time.
17. The device according to any one of claims 10 to 11, 13 to 15, characterized in that The pre-reading module is further used to update the file access history data corresponding to the file in the external storage device according to the pre-reading model.
18. The device according to any one of claims 10 to 11, 13 to 15, characterized in that The state acquisition module is used to: acquire the state parameter information when triggering the pre-reading of the file page; or acquire the state parameter information at a preset period.
19. A terminal device, characterized in that: include: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 9.
20. A computer-readable storage medium, characterized in that: The invention comprises a computer program, which, when executed on a computer, causes the computer to execute the method according to any one of claims 1 to 9.
21. A computer program product, characterized in that When the computer program product is executed by a computer, it is used to perform the method according to any one of claims 1 to 9.
22. A chip, characterized in that: The invention comprises a processor and a memory, wherein the memory is used to store a computer program, and the processor is used to call and run the computer program stored in the memory to execute the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Data pre-fetching method and device for non-uniform memory access
CN102508638A
Solid state drives control device and solid state drives data access method based on learning
CN106250064A