Method and electronic device for reading compressed files

By cached decompressed compressed file data pages in electronic devices, the problem of inefficiency when reading compressed files is solved, and more efficient data reading and system resource utilization are achieved.

CN117724650BActive Publication Date: 2025-02-18HONOR DEVICE CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202310891709.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-19
Publication Date
2025-02-18
Estimated Expiration
2043-07-19

AI Technical Summary

Technical Problem

Electronic devices are inefficient when reading compressed files, and need to repeatedly read and decompress the same compressed blocks, resulting in wasted system resources and inefficient data reading.

Method used

When receiving a read request, the required compressed block is first read from the external memory, decompressed and cached into memory, ensuring that the required data page can be read directly from the memory during the next read request, avoiding repeated reading and settlement compression.

Benefits of technology

It improves the efficiency of electronic devices to read compressed files, reduces the number of reads to external memory, saves system resources, and improves the speed and efficiency of data reading.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117724650B_ABST
    Figure CN117724650B_ABST
Patent Text Reader

Abstract

The embodiments of the present application relate to the field of computer technology, and in particular to a method for reading compressed files and an electronic device, which can improve the efficiency of electronic devices in reading compressed files. The electronic device includes a memory, in which a plurality of compressed blocks are stored, the plurality of compressed blocks are obtained by compressing at least one file, and each compressed block includes M data pages in a file, where M is an integer greater than 1. The method includes: receiving a first read request, the first read request is used to request to read Q first data pages in a first file; if the q first data pages are not cached in the memory of the electronic device, then the K first compressed blocks where the q first data pages are located are read from the memory, the K first compressed blocks are decompressed to obtain a plurality of second data pages, and the plurality of second data pages are cached in the memory; at least one of the K first compressed blocks compresses M‑m first data pages, 1≤m<M; and the Q first data pages are read from the memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a method and electronic device for reading a compressed file. Background Art

[0002] The electronic device reads data from an external memory, which may be a disk, hard disk, optical disk, USB flash drive, etc. The data may be application data, photos, audio data, etc. in the electronic device, or operating system data, etc. In order to save storage space of the electronic device, the above data may be stored in the form of a compressed file.

[0003] A compressed file may include multiple compressed blocks, each compressed block is compressed from a fixed amount of original data. The mobile phone uses compressed blocks as units when reading compressed files. For example, the data that the mobile phone needs to read is compressed in the first compressed block. The mobile phone can read the first compressed block from the external memory and decompress it, thereby obtaining the data to be read. The next time the mobile phone needs to read the data in the first compressed block, it needs to read the first compressed block from the external memory again and decompress it again to obtain the data to be read. Repeatedly reading the first compressed block and decompressing it repeatedly results in low efficiency when the mobile phone reads compressed files. Summary of the invention

[0004] The embodiments of the present application provide a method for reading a compressed file and an electronic device, which are used to improve the efficiency of the electronic device in reading the compressed file.

[0005] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:

[0006] In a first aspect, a method for reading a compressed file is provided, which is applied to an electronic device. The electronic device includes an external memory, in which a plurality of compressed blocks are stored, the plurality of compressed blocks are obtained by compressing at least one file, and each compressed block includes M data pages in a file, where M is an integer greater than 1. The method includes: receiving a first read request, the first read request is used to request to read Q first data pages in a first file, the first read request indicates the identifier of the first file and the position of the Q first data pages in the first file, and Q is an integer greater than or equal to 1; if q first data pages among the Q first data pages are not cached in the memory of the electronic device, then K first compressed blocks where the q first data pages are located are read from the external memory, the K first compressed blocks are decompressed to obtain a plurality of second data pages, and the plurality of second data pages are cached in the memory; wherein the plurality of second data pages include q first data pages; at least one first compressed block among the K first compressed blocks compresses Mm first data pages, 1≤q≤Q, K≥1, 1≤m<M, and q, K and m are all integers; and Q first data pages are read from the memory.

[0007] In the present application, an electronic device receives a first read request, the first read request requests to read Q first data pages in a first file, and the memory of the electronic device has Qq first data pages cached. For the q data pages that are not cached, the electronic device reads out the K first compressed blocks to which the q first data pages belong from the external memory in units of compressed blocks, and the number of first data pages compressed in at least one of the K first compressed blocks is less than the number of data pages included in the first compressed block. The K first compressed blocks are decompressed to obtain a plurality of second data pages including the q first data pages. The plurality of second data pages are cached in the memory, and the Q first data pages are read from the memory. When processing a read request, the present application can decompress all the second data pages in the first compressed block to which the requested first data page belongs, and cache them in the memory. In this way, after receiving the second read request, if the second read request requests to read part or all of the second data pages in the first compressed block, the electronic device can read from the memory, thereby improving the efficiency of reading compressed files.

[0008] In another possible implementation of the first aspect, after caching the plurality of second data pages in the memory, after receiving the second read request, the electronic device can quickly read the data pages from the memory. Specifically, the method further includes: receiving the second read request, the second read request is used to request to read P third data pages in the second file, the second read request indicates the identifier of the second file and the position of the P third data pages in the second file, P is an integer greater than or equal to 1; the P third data pages are included in the plurality of second data pages; the P third data pages are cached in the memory of the electronic device, and the P third data pages are read from the memory.

[0009] In another possible implementation of the first aspect, the electronic device reads Q first data pages from the memory, including: for Qq first data pages cached in the memory, directly reading Qq first data pages from the memory; for q first data pages not cached in the memory, reading q first data pages from multiple second data pages cached in the memory.

[0010] In another possible implementation of the first aspect, after the electronic device reads the K first compressed blocks to which the q first data pages belong from the external memory, it can also pre-read multiple second compressed blocks to further improve the efficiency of reading the compressed file. Specifically, the method also includes: after reading the K first compressed blocks to which the q first data pages belong from the external memory, reading N second compressed blocks after the K first compressed blocks from the external memory based on the pre-reading window, where N is the size of the pre-reading window; decompressing the N second compressed blocks to obtain multiple fourth data pages, and caching the multiple fourth data pages in the memory.

[0011] In another possible implementation of the first aspect, the electronic device determines whether the first read request is a sequential read before pre-reading. If the first read request is a sequential read, the electronic device will read N second compressed blocks after at least one first compressed block after reading K first compressed blocks belonging to q first data pages from the external memory. Since the first read request is a sequential read, the electronic device determines that the next read request is likely to be a sequential read. At this time, the electronic device will pre-read multiple second compressed blocks after reading the first compressed block belonging to the first data page requested by the first read request, which can improve the hit rate of the pre-reading.

[0012] In another possible implementation of the first aspect, if a fifth data page in at least one third compressed block before a first first compressed block among the K first compressed blocks is cached in the memory, the first request indicates sequential reading of data pages in the first file. This implementation provides a specific implementation of identifying whether the first read request is a sequential read.

[0013] In another possible implementation of the first aspect, if the current memory usage of the electronic device is less than the first threshold or the current remaining memory of the electronic device is greater than the second threshold, the N second compressed blocks after the K first compressed blocks are read from the external memory based on the pre-reading window. The electronic device performs pre-reading only when the current memory of the electronic device is sufficient.

[0014] In another possible implementation of the first aspect, if the first file is stored as a compressed file in the external memory, the K first compressed blocks where the q first data pages are located are read from the external memory. If the first file is not stored as a compressed file in the external memory, the q first data pages are read from the external memory.

[0015] In another possible implementation of the first aspect, if the current memory usage of the electronic device is less than the third threshold or the current remaining memory of the electronic device is greater than the fourth threshold, the K first compressed blocks where the q first data pages are located are read from the external memory. The electronic device will only execute a method for reading a compressed file provided in the present application when the current memory of the electronic device is sufficient.

[0016] In a second aspect, the present application provides an electronic device, which includes: a first memory, an external memory and one or more processors; the first memory is coupled to the processor; wherein the external memory stores a plurality of compressed blocks, the plurality of compressed blocks are obtained by compressing at least one file, each compressed block includes M data pages in a file, M is an integer greater than 1; the first memory is used to store computer program code, the computer program code includes computer instructions; when the computer instructions are executed by the processor, the electronic device performs the following steps: receiving a first read request, the first read request is used to request to read Q first data pages in a first file, the first read request Find an identifier indicating a first file and positions of Q first data pages in the first file, where Q is an integer greater than or equal to 1; if q of the Q first data pages are not cached in a memory of the electronic device, read K first compressed blocks where the q first data pages are located from an external memory, decompress the K first compressed blocks to obtain a plurality of second data pages, and cache the plurality of second data pages in the memory; wherein the plurality of second data pages include q first data pages; at least one of the K first compressed blocks compresses Mm first data pages, 1≤q≤Q, K≥1, 1≤m<M, and q, K, and m are all integers; read Q first data pages from the memory.

[0017] In another possible implementation of the second aspect, when the above-mentioned computer instructions are executed by the processor, the electronic device performs the following steps: receiving a second read request, the second read request is used to request to read P third data pages in the second file, the second read request indicates the identifier of the second file and the positions of the P third data pages in the second file, P is an integer greater than or equal to 1; the P third data pages are included in multiple second data pages; the P third data pages are cached in the memory of the electronic device, and the P third data pages are read from the memory.

[0018] In another possible implementation of the second aspect, when the above-mentioned computer instructions are executed by the processor, the electronic device performs the following steps: for the Qq first data pages cached in the memory, Qq first data pages are directly read from the memory; for the q first data pages not cached in the memory, q first data pages are read from multiple second data pages cached in the memory.

[0019] In another possible implementation of the second aspect, when the above-mentioned computer instructions are executed by the processor, the electronic device performs the following steps: after reading K first compressed blocks containing q first data pages from an external memory, read N second compressed blocks after the K first compressed blocks from the external memory based on a pre-read window, where N is the size of the pre-read window; decompress the N second compressed blocks to obtain multiple fourth data pages, and cache the multiple fourth data pages in the memory.

[0020] In another possible implementation of the second aspect, when the above-mentioned computer instructions are executed by the processor, the electronic device performs the following steps: after reading K first compressed blocks belonging to q first data pages from the external memory, read N second compressed blocks after the K first compressed blocks.

[0021] In another possible implementation of the first aspect, if a fifth data page in at least one third compressed block before a first first compressed block among the K first compressed blocks is cached in the memory, the first request indicates sequential reading of data pages in the first file.

[0022] In another possible implementation of the second aspect, if the current memory usage of the electronic device is less than the first threshold or the current remaining memory of the electronic device is greater than the second threshold, N second compressed blocks after K first compressed blocks are read from the external memory based on the pre-read window.

[0023] In another possible implementation of the second aspect, if the first file is stored as a compressed file in the external memory, the K first compressed blocks where the q first data pages are located are read from the external memory. If the first file is not stored as a compressed file in the external memory, the q first data pages are read from the external memory.

[0024] In another possible implementation of the second aspect, if the current memory usage of the electronic device is less than the third threshold or the current remaining memory of the electronic device is greater than the fourth threshold, the K first compressed blocks where the q first data pages are located are read from the external memory. The electronic device will only execute a method for reading a compressed file provided in the present application when the current memory of the electronic device is sufficient.

[0025] In a third aspect, the present application provides a chip system, which can be applied to an electronic device including a first memory. The chip system includes one or more interface circuits and one or more processors. The interface circuit and the processor are interconnected by a line. The interface circuit is used to receive a signal from the above-mentioned memory and send the signal to the processor, and the signal includes a computer instruction stored in the memory. When the processor executes the computer instruction, the electronic device executes the method as in the first aspect and any possible design thereof.

[0026] In a fourth aspect, the present application provides a computer-readable storage medium, the computer-readable storage medium comprising computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the method of the first aspect and any possible design thereof.

[0027] In a fifth aspect, the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the method of the first aspect and any possible design thereof.

[0028] It can be understood that the beneficial effects that can be achieved by the electronic device of any possible design of the second aspect, the chip system of the third aspect, the computer-readable storage medium of the fourth aspect, and the computer program product of the fifth aspect can be referred to as the beneficial effects in the first aspect and any possible design of the electronic device, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 A schematic diagram of a data reading process provided in an embodiment of the present application;

[0030] Figure 2a A schematic diagram of a data compression process provided in an embodiment of the present application;

[0031] Figure 2b A schematic diagram of another data compression process provided in an embodiment of the present application;

[0032] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0033] Figure 4 A schematic diagram of a software architecture of an electronic device provided in an embodiment of the present application;

[0034] Figure 5 A flowchart of a method for reading a compressed file provided in an embodiment of the present application;

[0035] Figure 6a A schematic diagram of the structure of a compressed file provided in an embodiment of the present application;

[0036] Figure 6b Another structural diagram of reading a compressed file provided in an embodiment of the present application;

[0037] Figure 7 A flowchart of another method for reading a compressed file provided in an embodiment of the present application;

[0038] Figure 8 A flowchart of another method for reading a compressed file provided in an embodiment of the present application. DETAILED DESCRIPTION

[0039] The electronic device reads data from an external memory, which may be, for example, a disk, a hard disk, an optical disk, a USB flash drive, etc. The data may be, for example, application data, pictures, audio and video data in the electronic device, or operating system data, etc. The above data may be stored in the external memory in the form of a file. It should be understood that a file may be a set of data sequences stored in the external memory.

[0040] Exemplarily, a process running in an electronic device may issue a read request to read data, and in response to the received read request, the electronic device may identify whether the data to be read is already in the memory buffer. If the data to be read is already in the memory buffer, the electronic device may copy the data to be read from the memory buffer to the memory space of the process. The data cached in the memory buffer is read from an external memory (such as a hard disk or disk) in response to a previous read request.

[0041] If the data to be read is not in the memory buffer, the electronic device can send an input / output (I / O) request to the external memory. The I / O request is used to request to read the data stored in the file in the external memory. For example, the block driver device in the electronic device can send the I / O request to the control unit in the external memory, and in response to the I / O request, the control unit reads the data from the file and returns the data. The electronic device can place the acquired data in the memory buffer, and then the electronic device copies the data from the memory buffer to the memory space of the process, so that a read request can be completed.

[0042] A page can be a basic unit for electronic devices to read and write data. The size of a page can usually be 4kb, that is, one page can store 4kb of data. When an electronic device reads data, it uses pages as units. For example, a target file has 16kb and can include page1-page4, where each page includes 4kb of data. When an electronic device needs to read data in the range of 0-3kb in the target file, the electronic device will read out 0-4kb of data, that is, read out all the data in page1.

[0043] The memory buffer may be located in the kernel space, for example, and the memory buffer may be a page cache, in which multiple pages may be cached. It should be understood that an I / O request may be a read request or a write request, and a read request may read data from an external memory, and a write request may write data to an external memory. In the embodiment of the present application, an I / O request mainly refers to a read request.

[0044] In order to increase the speed at which electronic devices read data, a pre-reading mechanism can be used to pre-read data that may be used by the process. The pre-reading mechanism means that the electronic device reads more data than expected for an I / O request of an application and caches the data in a memory buffer. In this way, when the next I / O request comes, the data can be read directly from the memory buffer, avoiding reading data from the external memory again, avoiding an I / O request between the external memory and the memory, and improving the data reading efficiency.

[0045] The pre-reading mechanism may include synchronous pre-reading and asynchronous pre-reading. Synchronous pre-reading can be understood as the electronic device reading multiple pages from the external memory, some of which include the data required for this read request, and some of which may be data that the electronic device predicts may be required for subsequent read requests. Asynchronous pre-reading can be understood as the electronic device reading multiple pages from the external memory, which are data not required for this read request.

[0046] The electronic device sets the size of the pre-reading window, that is, the number of pages read in one pre-reading. The size of the pre-reading window is variable, for example, it can be increased by multiples.

[0047] Combine the following Figure 1 Introduce the pre-reading mechanism. Figure 1 As shown in the figure, a process can issue three read requests. These three read requests can be issued by the same process or by different processes. These three read requests all request data in the same target file. Figure 1 The external storage in may be, for example, a disk.

[0048] The first read request is a request to read the data in the target file for the first time. Since it is the first read, the memory buffer does not cache the data. The mobile phone sends the first I / O request, which can be a synchronous pre-read request. The initial value of the pre-read window size can be 4 pages (16kb). The electronic device can read 4 pages (16kb) of data backward from the current pointer position of the target file on the disk according to the size of the pre-read window. These 4 pages of data can be continuous in the target file. The mobile phone can cache these 4 pages of files in the memory cache area. Figure 1 As shown, after the first read request, the memory buffer can cache page1-page4. Wherein, page1 may include the target data requested by the first read request, and page2-page4 include the pre-read data. It should be understood that the data requested to be read by the first read request may be part of the data in page1 or all of the data.

[0049] The process sends a second read request, such as Figure 1As shown, the second read request requests to read the data in page2. The electronic device recognizes that page2 is already in the memory buffer, and the file system can return page2 to the process. And trigger an asynchronous pre-read. During this asynchronous pre-read, the size of the pre-read window can be 8 pages (32kb). The mobile phone can pre-read the data in page5-page12 and cache it in the memory buffer.

[0050] The process sends a third read request, such as Figure 1 As shown in the figure, the third read request requests to read the data in page5. The mobile phone recognizes that page5 is already in the memory buffer, and the mobile phone can directly obtain the data from page5 in the memory buffer and return it to the process. And trigger an asynchronous pre-read. During this asynchronous pre-read, the size of the pre-read window can be 16 pages (32kb). The file system can read the data in page13-page28 and cache it in the memory buffer.

[0051] It can be seen that the pre-reading mechanism can reduce the number of I / Os between the memory and the external storage, reduce the I / O overhead, and improve the data reading efficiency. However, the pre-reading mechanism introduced above is not suitable for the scenario of compressed files.

[0052] First, compressed files and a method for reading compressed files in related technologies are introduced.

[0053] The data in the electronic device can be stored on the external memory in the format of a compressed file.

[0054] Taking the external memory as a disk as an example, when storing files, the electronic device will use a compression algorithm to compress the files into compressed files, and then the electronic device will store the compressed files in the disk. Figure 2a As shown, a 16kb original file may include page1-page4, a total of 4 pages of data, wherein each page is 4kb in size. The mobile phone can compress the original data into a compressed file of 8kb in size. That is to say, the electronic device can use 4 pages of original data as a compression unit, and compress these 4 pages of data into a compressed block C0. Among them, the compression unit can be understood as a unit when the electronic device compresses a file, and the compression unit may include M pages of original data. When compressing a file, the electronic device compresses M pages of original data as a unit, and compresses M pages of original data into a compressed block. Among them, M can be an integer greater than 1.

[0055] like Figure 2b As shown, Figure 2bThe size of the original data in the file may be 48kb. When compressing the file, the electronic device may compress 2 pages (8kb) of data into a compressed block. That is, the compression unit may be 2 pages. For the original data of 48kb in size, the electronic device compresses page1-page2 into compressed block C0, page3-page4 into compressed block C1, ..., and page11-page12 into compressed block C7. In some embodiments, a compressed block may also be referred to as a compressed package.

[0056] When the electronic device reads data in any page of the compressed file, it needs to read the compressed block including the page and decompress the compressed block before reading the data of the target page.

[0057] A process in an electronic device issues a read request for target data in a target compressed file. In response to receiving the read request, the electronic device checks whether the target data has been cached in a memory buffer. If not in the buffer, the electronic device determines the compressed block where the target data is located. That is, the electronic device determines in which compressed blocks the target data is compressed. In some implementations, the target data may be compressed in one compressed block. In other embodiments, the target data may be compressed in multiple compressed blocks, and these multiple compressed blocks may be continuous in the compressed file of the target file. Afterwards, the electronic device reads out the compressed block where the target data is located, and decompresses the compressed block to obtain multiple data pages in the compressed block, and then returns the target data in the multiple data pages to the process.

[0058] For example, assume that a process issues a read request for target data in a compressed file, such as the read request indicating that Figure 2a The electronic device reads the compressed block C0 from the disk. After that, the compressed block C0 is decompressed to obtain the original data pages page1-page4. After that, the electronic device caches page2 in the memory buffer. The electronic device returns the process from the target data in page2 to complete a read request. The target data can be part of the data in page2 or all of the data.

[0059] The process is sent again Figure 2a After receiving the read request for the target data in page3 of the process, the electronic device reads the compressed block C0 from the disk again. After that, the compressed block C0 is decompressed to obtain the original data pages page1-page4. After that, the electronic device caches the data in page3 in the memory buffer. The electronic device returns the target data in page3 to the process, completing the second read request.

[0060] That is to say, at least two processes may issue read requests for different data pages in the same compressed block in the compressed file. Because in the related art, for a read request, the electronic device will read the compressed block from the disk, and after decompression, the electronic device will only cache the data page where the data to be read is located in the memory buffer. This results in that for the next read request to read a different data page in the compressed block, the electronic device needs to read the compressed block again from the disk, decompress it again, and cache the data page to obtain the data to be read in the data page. In this way, there is a waste of system resources and low data reading efficiency.

[0061] Based on this, an embodiment of the present application provides a method and an electronic device for reading a compressed file. When the electronic device processes the first read request sent by the process, it can read the first compressed block to which the first data page requested to be read by the first read request belongs. The electronic device decompresses the first compressed block and caches all the second data pages obtained by decompression in the memory. In this way, when processing the next read request, if the read request requests to read the second data page in the first compressed block, since all the second data pages in the first compressed block have been cached in the memory, the electronic device can read the second data page directly from the memory. In this way, repeated reading and repeated decompression can be avoided, thereby improving the efficiency of the electronic device in reading data in compressed files. In addition, I / O requests can be saved to save IO overhead.

[0062] by Figure 2a For example, the process sends a read request for the target data in the compressed file. Specifically, the read request indicates to read the data of page2. The electronic device reads the compressed block C0 from the disk. After that, the compressed block C0 is decompressed to obtain the original data pages page1-page4. After that, the electronic device caches all pages 1-page4 in the memory buffer. The electronic device obtains the target data from page2 and returns it to the process, completing a read request. After the process sends a read request for the target data in page3 again. The electronic device will directly read the target data of page3 in the memory buffer.

[0063] The method provided in the embodiments of the present application can be applied to electronic devices with data processing capabilities. The above-mentioned electronic devices may include servers, mobile phones, tablet computers, laptops, personal computers (PCs), ultra-mobile personal computers (UMPCs), handheld computers, netbooks, smart home devices (e.g., smart TVs, smart screens, large screens, smart speakers, smart air conditioners, etc.), personal digital assistants (PDAs), wearable devices (e.g., smart watches, smart bracelets, etc.), vehicle-mounted devices, virtual reality devices, etc., and the embodiments of the present application do not impose any restrictions on this. In the embodiments of the present application, the above-mentioned electronic devices are electronic devices that can run operating systems and install applications. Optionally, the operating system running on the electronic device may be system, system, System, etc.

[0064] For example, please refer to Figure 3 , which shows a schematic diagram of the structure of an electronic device 300. The electronic device 300 may include a processor 310, an external memory interface 320, an internal memory 321, an audio module 330, a speaker 330A, a microphone 330B, a display screen 340, a communication module 350, a power module 360, an input device 370, a sensor module 380, etc. Among them, the sensor module 380 may include a pressure sensor, a touch sensor, etc.

[0065] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 300. In other embodiments of the present application, the electronic device 300 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0066] The processor 310 may include one or more processing units. For example, the processor 310 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), and / or a neural-network processing unit (NPU). Different processing units may be independent components or integrated into one or more processors. In some embodiments, the electronic device 300 may also include one or more processors 310.

[0067] The controller is the nerve center and command center of the electronic device 300. It can generate operation control signals according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.

[0068] The application processor can run the operating system of the electronic device 300, which is used to manage the hardware and software resources of the electronic device 300. For example, it can manage and configure memory, determine the priority of system resource supply and demand, control input and output devices, operate the network, manage the file system, manage drivers, etc. The operating system can also be used to provide an operation page for users to interact with the system. Among them, various types of software can be installed in the operating system, such as drivers, applications (applications, Apps), etc.

[0069] NPU is a neural network (NN) computing processor, which can quickly process input information and continuously self-learn by drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain. NPU can realize applications such as intelligent cognition of electronic device 300.

[0070] The processor 310 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 310 is a cache memory. The memory may store instructions or data that the processor 310 has just used or cyclically used. If the processor 310 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 310, and thus improves the efficiency of the system.

[0071] In some embodiments, the processor 310 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a SIM card interface, and / or a USB interface, etc.

[0072] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 300. In other embodiments of the present application, the electronic device 300 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0073] The external memory interface 320 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 300. The external memory card communicates with the processor 310 through the external memory interface 320 to implement a data storage function, such as storing music, video and other files in the external memory card.

[0074] The internal memory 321 can be used to store one or more computer programs, which include instructions. The processor 310 can enable the electronic device 300 to execute the application operation method provided in some embodiments of the present application, as well as various applications and data management, etc. by running the above instructions stored in the internal memory 321. The internal memory 321 may include a code storage area and a data storage area. Among them, the data storage area can store data created during the use of the electronic device 300, etc. In addition, the internal memory 321 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more disk storage components, a flash memory component, a universal flash storage (universal flash storage, UFS), etc. In some embodiments, the processor 310 can enable the electronic device 300 to execute the application operation method provided in the embodiment of the present application, as well as other applications and data management by running instructions stored in the internal memory 321, and / or instructions stored in a memory provided in the processor 310. For example, in an embodiment of the present application, the electronic device 300 can cache the compressed data pages in the compressed block in the memory. The external memory 320 may store a plurality of compressed blocks, where the plurality of compressed blocks are obtained by compressing at least one file, and each compressed block includes M data pages in a file, where M is an integer greater than 1.

[0075] The electronic device 300 can implement audio functions through an audio module 330, a speaker 330A, a microphone 330B, and an application processor, etc. For example, music playing, recording, etc. The audio module 330 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 330 can also be used to encode and decode audio signals. In some embodiments, the audio module 330 can be arranged in the processor 310, or some functional modules of the audio module 330 can be arranged in the processor 310.

[0076] The speaker 330A, also called a "horn", is used to convert audio electrical signals into sound signals.

[0077] The microphone 330B, also called a "microphone" or "microphone", is used to convert a sound signal into an electrical signal. A user can make a sound by approaching the microphone 330B with his or her mouth, and input the sound signal into the microphone 330B.

[0078] The communication function of the electronic device 300 can be realized through the antenna 1, the antenna 2 and the communication module 350.

[0079] The communication module 350 can provide solutions for wireless communications including cellular, Wi-Fi, Bluetooth (BT), wireless data transmission modules (e.g., 433MHz, 868MHz, 915MHz) applied to the electronic device 300. The communication module 350 can be one or more devices integrating at least one communication processing module. The communication module 350 receives electromagnetic waves via antenna 1 or antenna 2, filters and frequency modulates the electromagnetic wave signals, and sends the processed signals to the processor 310. The communication module 350 can also receive the signal to be sent from the processor 310, frequency modulate it, amplify it, and convert it into electromagnetic waves for radiation through antenna 1 or antenna 2.

[0080] The electronic device 300 implements the display function through a GPU, a display screen 340, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 340 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 310 may include one or more GPUs, which execute program instructions to generate or change display information.

[0081] The display screen 340 is used to display images, videos, etc. The display screen 340 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicrOLED, Micro-OLED, quantum dot light-emitting diodes (QLED), etc. In some embodiments, the electronic device 300 may include 1 or N display screens 340, where N is a positive integer greater than 1. In the embodiment of the present application, the display screen 340 can be used to display a UI and receive user operations on the UI.

[0082] In some embodiments, the display screen 340 is provided with a pressure sensor, a touch sensor, and the like. The pressure sensor is used to sense pressure signals and can convert pressure signals into electrical signals. When a touch operation is applied to the display screen 340, the electronic device 300 detects the strength of the touch operation according to the pressure sensor. The electronic device 300 can also calculate the position of the touch according to the detection signal of the pressure sensor. The touch sensor, also known as a "touch panel", can form a touch screen, also known as a "touch screen", with the display screen 340. The touch sensor is used to detect touch operations applied thereto or thereabout. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can also be provided through the display screen 340. The power module 360 ​​can be used to supply power to the various components included in the electronic device 300. In some embodiments, the power module 360 ​​can be a battery, such as a rechargeable battery.

[0083] The input device 370 may include a keyboard, a mouse, etc. The keyboard is used to input English letters, numbers, punctuation marks, etc. into the electronic device 300, thereby issuing commands to the electronic device 300, inputting data, etc. The mouse is an indicator for the vertical and horizontal coordinates of the display system of the electronic device 300, and is used to input instructions, etc. to the electronic device 300. Among them, the input device 370 can be connected to the electronic device 300 through a wired connection, for example, the input device 370 is connected to the electronic device 300 through a GPIO interface, a USB interface, etc. The input device 370 can also be connected to the electronic device 300 wirelessly, for example, the input device 370 is connected to the electronic device 300 through Bluetooth, infrared, etc.

[0084] Take the above electronic device 300 as a mobile phone as an example. The software system of the electronic device 300 can adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present invention takes the Android system of the layered architecture as an example to illustrate the software structure of the electronic device 300.

[0085] Figure 4 It is a software structure block diagram of the electronic device 300 according to an embodiment of the present invention.

[0086] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the Android runtime (Android runtime), the system library, and the kernel layer.

[0087] The application layer can include a series of application packages.

[0088] like Figure 4As shown, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc., and may also include other applications not shown, such as third-party applications installed by users themselves.

[0089] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.

[0090] like Figure 4 As shown, the application framework layer may include a content provider, a view system, a resource manager, a notification manager, and the like.

[0091] Android Runtime includes core libraries and virtual machines. Android Runtime is responsible for scheduling and management of the Android system.

[0092] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.

[0093] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0094] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0095] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.

[0096] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[0097] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.

[0098] A 2D graphics engine is a drawing engine for 2D drawings.

[0099] The kernel layer is the layer between hardware and software. The kernel layer can include display drivers, audio drivers, sensor drivers, decompression modules, reading modules, etc.

[0100] The reading module responds to the triggering of the first read request of the first process of the application program, and searches in the memory whether the Q first data pages requested by the first read request have been cached. The reading module identifies that the q first data pages are not cached in the memory, and the reading module can read the K first compressed blocks to which the q first data pages belong from the memory. The decompression module is used to decompress the K first compressed blocks to obtain a plurality of second data pages. The reading module is also used to cache the plurality of second data pages in the memory, and read the q first data pages therefrom.

[0101] The reading module recognizes that Qq first data pages other than the q first data pages among the Q first data pages have been cached in the memory, and the reading module can directly read the Qq first data pages.

[0102] In conjunction with the accompanying drawings, a method for reading a compressed file provided by an embodiment of the present application is introduced below by taking the electronic device being a mobile phone and the external memory being a disk as an example. Figure 5 A flowchart of a method for reading a compressed file provided in an embodiment of the present application.

[0103] In S501 , the mobile phone receives a first read request of a first process.

[0104] The first process may be any process in the mobile phone. Exemplarily, the first process may be a process corresponding to an application, and the application may be, for example, a game application, a video application, a gallery application, and the like.

[0105] The first process may initiate a read request. Exemplarily, during the running and / or startup of the application, the first process corresponding to the application may initiate a read request. The first process may call a read function in a function library to initiate a read request. The read function may be, for example, read(). The read request may be, for example, read(3kb, identifier of the first file). The first read request is used to request to read data in the first file, and the first file may be a code file that needs to be executed during the startup / running of the application.

[0106] The first read request is used to request to read Q first data pages in the first file, where Q is an integer greater than or equal to 1. For example, Q=3, and the first request is used to request to read data in three first data pages in the first file. For each first data page, the first read request may request to read part or all of the data therein, which is not specifically limited in the embodiments of the present application.

[0107] The first read request may indicate an identifier of the first file and positions of the Q first data pages in the first file.

[0108] The first file may be a set of data sequences stored in a disk. The Q first data pages may be part of the data or all of the data in the first file. That is, the Q first data pages may be part of the data sequences or all of the data sequences in a set of data sequences. For example, the first file may be a 128kb binary sequence, the Q first data pages may be 32kb of the binary sequences, each first data page may include 4kb of data, and Q may be 8.

[0109] The identifier of the first file is used to mark the first file, and the identifier of the first file may be the name of the first file.

[0110] The data in the Q first data pages may be referred to as target data, and the target data is data to be obtained from the first file. The position of the target data in the first file may be represented by an offset and / or a number of bytes. The unit of the number of bytes may be KB. 1KB of bytes may include 1049 bytes.

[0111] Exemplarily, the offset and the number of bytes can indicate the position of the target data in the first file. For example, the offset can indicate the position of the first byte of the target data in the first file relative to the current pointer of the first file. The starting position of the target data can be determined according to the offset, and the number of bytes can indicate the end position of the target data N bytes backward from the starting position of the target data. In other words, the offset plus the number of bytes can determine the starting position and the end position of the target data in the first file, and then delineate the position of the target data in the first file.

[0112] Exemplarily, the byte number may indicate the position of the target data in the first file. For example, the byte number may indicate that the target data is N bytes backward from the position of the current pointer of the first file. That is, the target data is located N bytes backward from the current pointer.

[0113] For example, the first read request may include an index file (inode) of the first file, which includes information such as the size, creation time, modification time, location of the first file on the disk, and an identifier of the first file, such as the name of the first file.

[0114] by Figure 6a Taking the target data A shown in the figure as an example, the first read request requests to read 6kb bytes from the header of the first file. Since a page can include 4kb of data, the target data A is located in page1-page2 in the first file, that is, the first read request requests to read the target data A in the first data page page1 and page2 in the first file. Figure 6aTaking the target data B shown in the figure as an example, the first read request requests to read 3kb of bytes from the header of the first file backwards. Since a page can include 4kb of data, the target data B is located in page1 (the first data page) in the first file. That is, the first request requests to read the target data B in the first data page page1 of the first file.

[0115] by Figure 6b As shown, the first read request requests to read 12kb of byte data backward from the current pointer position of the first file. Assume that the current pointer position is at the 3kb position in page2. Since a page can include 4kb of data, the starting position of the target data is in page2, the ending position of the target data is in page5, and the target data is located in page2-page5 (the first data page) in the first file. That is, the first request requests to read the target data in the first data page page2-page5 in the first file.

[0116] In S502, the mobile phone recognizes that q first data pages among the Q first data pages are not cached in the memory buffer, and Qq first data pages among the Q first data pages except the q first data pages are stored in the memory buffer.

[0117] The mobile phone will identify whether each of the Q first data pages has been cached in the memory buffer. When the mobile phone caches data in the internal buffer, it is also in units of pages.

[0118] If the mobile phone recognizes that Q first data pages have been cached in the memory buffer, the mobile phone can directly read the target data in the Q first data pages from the memory buffer. If the mobile phone recognizes that the Q first data pages are not cached in the memory buffer, the mobile phone needs to read the Q first data pages from the disk. In some cases, some of the Q first data pages may be stored in the memory buffer, while other parts of the first data pages are not stored in the memory buffer. That is, the mobile phone may recognize that q of the Q first data pages are not cached in the memory buffer, while Qq of the Q first data pages except the q first data pages are stored in the memory buffer. Wherein, 1≤q≤Q, q is an integer.

[0119] Specifically, when q first data pages among the Q first data pages are not cached in the memory buffer, and Qq first data pages other than the q first data pages among the Q first data pages are stored in the memory buffer, for the q first data pages not cached in the memory buffer, the mobile phone can read the compressed blocks where the q first data pages are located from the disk, that is, execute S503, or execute S504. For the Qq first data pages cached in the memory buffer, the mobile phone does not need to read the compressed blocks where the first data pages are located from the disk.

[0120] In S503, the mobile phone recognizes that the first file is stored in the disk as a compressed file.

[0121] The first file has a first identifier, and the first identifier is used to mark the first file as a compressed file. The first identifier can be stored in an index file of the first file, and the mobile phone can obtain the first identifier in the index file of the first file, and then identify whether the first file is stored as a compressed file in the disk based on the first identifier. The mobile phone can add the first identifier to the first file when compressing and storing the first file.

[0122] The mobile phone recognizes that the first file is not stored as a compressed file in the disk, and can directly read the q first data pages in the first file from the disk. The mobile phone caches the obtained q first data pages in the memory buffer and returns the target data therein to the first process (not shown in the figure).

[0123] If the mobile phone recognizes that the first file is stored as a compressed file, since the mobile phone can only read the compressed data in the compressed and stored first file in units of compressed blocks, the mobile phone will first calculate the first compressed blocks to which the q first data pages belong. Specifically, the mobile phone can execute S504. It should be understood that the mobile phone can directly execute S504 after executing S502, or can execute S503 after executing S502, and then execute S504. In other words, S503 is an optional step.

[0124] In S504, the mobile phone determines the K first compressed blocks to which the q first data pages belong.

[0125] As mentioned above, when storing a file, the mobile phone compresses the file into one or more fixed-size compressed blocks based on a fixed-size compression unit. When reading a compressed file, the mobile phone can only use the compressed block as a unit, and can read one or more compressed blocks at a time. Among them, one compressed block is compressed from M data pages in the first file. M is an integer greater than 1. In the embodiment of the present application, M can be 4, that is, one compressed block is compressed from 4 data pages in the first file.

[0126] The mobile phone may determine the first compression block to which the first data page belongs based on the page offset of each of the q first data pages in the first file and the size of the compression unit.

[0127] For example, a data page includes 4kb of data, and the size of the compression unit is 4 data pages, that is, 16kb. Then the offset of page1 is 0, the offset of page2 is 4kb, the offset of page3 is 8kb, the offset of page4 is 12kb, ..., and the offset of pageN is 4(N-1)kb. Assuming that the first data page requested to be read is page6-page30, the mobile phone divides the offset of page6 by the size of the compression unit and takes the modulus. That is, 20 / 16 is calculated and the modulus is 1, that is, page6 is in the second compressed block C1. Divide the offset of page20 by the size of the compression unit and take the modulus. That is, 116 / 16 is calculated and the modulus is 7, that is, page6 is in the 7th compressed block C6. In this way, the mobile phone can calculate that the q first data pages are in the second compressed block C1 to the 7th compressed block C6.

[0128] For example Figure 6a In the example, the data page includes 4kb of data, and the size of the compression unit is 4 data pages, that is, 16kb. Then the offset of Page1 is 0, and the offset of page2 is 4. The mobile phone divides the offset of page0 by the size of the compression unit and takes the modulus. That is, 0 / 16 is calculated and the modulus is 0, that is, page1 is in the first compressed block C0. Divide the offset of page2 by the size of the compression unit and take the modulus. That is, 4 / 16 is calculated and the modulus is 0, that is, page2 is in the first compressed block C0. In this way, the mobile phone can calculate that the first data page is compressed in the first compressed block C0.

[0129] For example Figure 6b In the example, the data page includes 4kb of data, and the size of the compression unit is 4 data pages, that is, 8kb. Then the offset of Page2 is 4, and the offset of page5 is 16. The mobile phone divides the offset of page2 by the size of the compression unit and takes the modulus. That is, 4 / 8 is calculated and the modulus is 0, which means that page2 is in the first compressed block C0. Divide the offset of page5 by the size of the compression unit and take the modulus. That is, 16 / 8 is calculated and the modulus is 2, which means that page5 is in the third compressed block C2. In this way, the mobile phone can calculate that the first data page is compressed in compression block C0-compression block C2.

[0130] In some embodiments, the mobile phone can search for a mapping relationship between a data page and a compressed block in the first file to determine the first compressed block to which the first data page belongs. For example, the mobile phone stores a mapping relationship between each page in the first file and each compressed block after the first file is compressed. Figure 6b For example, the mapping relationship may be as shown in Table 1.

[0131] Table 1

[0132] First file data page First compressed file compressed block First file data page First compressed file compressed block page1-page2 Compressed block C0 page9-page10 Compressed block C4 Page3page4 Compressed block C1 Page11-page12 Compressed block C5 Page5-page6 Compressed block C2 Page7-page8 Compressed block C3

[0133] When the mobile phone compresses the first data page, it compresses it in units of pages, for example, 4 data pages are compressed into one compressed block. Since the number of q first data pages may not be a multiple of the compression unit or the first first data page among the q first data pages may not be the first data page in the first compressed block, the K first compressed blocks include two types of first compressed blocks. One is a compressed block compressed from 4 consecutive first data pages, and the other is a compressed block compressed from the first data page and other data pages. This type of compressed block is compressed from m first data pages, where m is an integer less than M.

[0134] That is to say, q data pages may belong to K first compressed blocks. At least one of the K first compressed blocks is compressed from m first data pages and other data pages. Wherein, 1≤q≤Q, K≥1, 1≤m<M, q, K and m are all integers. This type of compressed block may be compressed from at least one first data page requested by the first read request and other data pages that are not requested to be read. Wherein, the other data pages may be data pages not requested by the first request in the first file, or data pages in the second file. Figure 6b In the first data page page2-page5, page2 is a partial data page in the compressed block C0, page3-page4 are all data pages in the compressed block C1, and page5 is a partial data page in the compressed block C2.

[0135] In S505 , the mobile phone reads K first compressed blocks from the disk.

[0136] After the mobile phone determines the K first compressed blocks to which the q first data pages belong, the mobile phone can read the K first compressed blocks from the disk in units of compressed blocks. Figure 6a In , the phone can read the compressed block C0 from the disk. Figure 6b In the example, the mobile phone can read compressed blocks C0, C1, and C2 from the disk.

[0137] In S506, the mobile phone decompresses the K first compressed blocks to obtain a plurality of second data pages.

[0138] The second data page is a data page decompressed from the first compressed block. The second data page is a data page in the first compressed block, that is, the compressed block is compressed from the second data page. The first data page is part or all of the data pages in the second data page, that is, the plurality of second data pages include q first data pages. The plurality of second data pages are decompressed from each first compressed block in the K first compressed blocks.

[0139] The mobile phone has a built-in compression algorithm, and the mobile phone can call the compression algorithm to decompress at least one compressed block process to obtain the second data page in each first compressed block. Figure 6a The compressed block C0 in the compressed block C0 is decompressed to obtain page1-page4 in the compressed block C0. The first data page is page1-page2 or page1, and the first data page is a partial data page in the second data page.

[0140] Mobile phone pair Figure 6b The compressed blocks C0, C1 and C2 in the data are decompressed respectively to obtain page1-page2, page3-page4 and page5-page6 respectively. The first data page is page2-page5, the first data page is a partial data page in the second data page, and the second data page includes the first data page.

[0141] At S507 , the mobile phone caches the plurality of second data pages in the memory.

[0142] The mobile phone caches all the second data pages decompressed from each first compression block in a memory buffer in the memory. Figure 6a The mobile phone caches all the pages 1-page 2, page 3-page 4, page 5-page 6 decompressed from the compressed blocks C0, C1, and C2 in the memory buffer.

[0143] At S508 , the mobile phone reads Q first data pages from the memory buffer.

[0144] After the mobile phone caches the multiple second data pages in the memory buffer, the mobile phone can read the Q first data pages from the memory buffer.

[0145] In S509, the mobile phone returns the target data to the first process.

[0146] The mobile phone returns part or all of the data in the Q first data pages to the first process. For example, the first read request may also include a memory address for storing the target data, and after reading the target data, the mobile phone may place the target data at the memory address.

[0147] by Figure 6a For example, the first read request indicates to read the target data A in the first data page page1 and page2. After reading page1 and page2 from the memory buffer, the mobile phone can return the target data therein to the first process.

[0148] It can be seen that in this solution, when the mobile phone processes the first read request initiated by the first process, it can calculate the K first compressed blocks belonging to the q first data pages. The mobile phone reads the K first compressed blocks from the disk, decompresses the K first compressed blocks, and caches all the second data pages obtained by decompression in the memory. In this way, when the mobile phone processes the next read request, if the read request requests to read the second data page in the first compressed block, since all the second data pages in the first compressed block have been cached in the memory, the mobile phone can directly read the second data page from the memory. In this way, the mobile phone can avoid repeated disk reading and repeated decompression, thereby improving the efficiency of the mobile phone in reading data in compressed files. In addition, it can save I / O requests between memory and disk, and can save IO overhead.

[0149] As described above, at least one of the K first compressed blocks is compressed from m first data pages and other data pages. Among them, the other data pages may be data pages in the second file. After the mobile phone caches multiple second data pages in the K first compressed blocks in the memory, if the mobile phone receives a second read request again, and the second read request requests to read the third data page in the second file that is compressed in the first compressed block, the mobile phone can directly read the third data page from the memory, thereby improving data reading efficiency.

[0150] The second read request can be initiated by the second process. The second process can be any process in the mobile phone. Exemplarily, the first process can be a process corresponding to an application, and the application can be, for example, a game application, a video application, a gallery application, etc. Exemplarily, during the operation and / or startup of the application, the second process corresponding to the application can initiate a read request. The first process can call a read function in a function library to initiate a read request. The read function can be, for example, read(). The read request can be, for example, read(3kb, identifier of the second file). The second read request is used to request to read data in the second file, and the second file can be a code file that needs to be executed during the startup / operation of the application.

[0151] For example, Figure 7 After S509, the mobile phone can also execute S701-S703.

[0152] At S701 , the mobile phone receives a second read request sent by a second process.

[0153] The second read request is used to request to read P third data pages in the second file, wherein the second file and the first file may be different files.

[0154] The second read request indicates the identifier of the second file and the positions of the P third data pages in the second file, where P is an integer greater than or equal to 1. The identifier of the second file may be the name of the second file. The positions of the P third data pages in the second file may be represented by an offset and / or a number of bytes, and the details may be referred to in the foregoing description, which will not be repeated here.

[0155] The P third data pages are included in the plurality of second data pages, that is, the plurality of second data pages obtained by decompressing the K first compressed blocks to which the Q first data pages belong include the P third data pages.

[0156] As an example, a 136kb first file may be compressed into 33 first compressed blocks, wherein the 33rd first compressed block is compressed from 2 first data pages and 2 third data pages, and the third data page is a data page in the second file.

[0157] At S702 , the mobile phone reads P third data pages from the memory.

[0158] Because the mobile phone has cached multiple second data pages in the memory when processing the first read request, at this time, the mobile phone can directly read the P third data pages from the memory.

[0159] In S703, the mobile phone returns the target data in the P third data pages to the second process.

[0160] The target data is all or part of the data in the P third data pages.

[0161] For example, the second process requests to read Figure 6b Because page1-page2 is already cached in the memory buffer, the mobile phone can directly read data from page1-page2 in the memory buffer and return the data to the second process. In this way, the mobile phone can quickly return the data requested by the second process.

[0162] After the mobile phone reads the first compressed block, the mobile phone will pre-read one or more second compressed blocks, and the mobile phone decompresses the second compressed block to obtain multiple fourth data pages. The mobile phone caches the multiple fourth data pages in the memory, which can further improve the efficiency of the mobile phone in reading data in the compressed file. It should be understood that the first compressed block is a compressed block to which the first data belongs, and the second compressed block is a compressed block that does not include the first data. The second compressed block is a compressed block that the mobile phone reads in advance from the disk in order to process the next read request. The first compressed block and the second compressed block can be compressed from the same file.

[0163] Exemplarily, after the mobile phone executes S505 and reads the K first compressed blocks belonging to the first data page, it may also pre-read N second compressed blocks according to the size of the pre-read window, where N is the size of the pre-read window.

[0164] N is an integer greater than or equal to 1. For example, when N is 1, the pre-read window is the size of 1 compressed block, and the mobile phone can read the first compressed block required this time and read a second compressed block backward. For example, when N is 4, the pre-read window is the size of 4 compressed blocks, and the mobile phone can read the first compressed block required this time and read 4 second compressed blocks backward. For example, when N is 8, the pre-read window is the size of 8 compressed blocks, and the mobile phone can read the first compressed block required this time and read 8 second compressed blocks backward, and 128kb of data can be pre-read. In some embodiments, the size of the pre-read window is not fixed. For example, the size of the pre-read window can increase exponentially with the number of read requests.

[0165] After reading the first compressed block and the second compressed block, the mobile phone can decompress the first compressed block and the second compressed block, and cache all the decompressed data pages in the buffer. In this way, the buffer can include all the second data pages in the first compressed block and all the fourth data pages in the second compressed block.

[0166] For example, Figure 6b As shown, the first process requests to read the target data in the first data page, and the first data page is compressed in the compressed blocks C0-C2. The mobile phone reads the compressed blocks C0, C1 and C2 from the disk, and pre-reads the compressed blocks C3 and C4. The mobile phone uses the compression algorithm to decompress the compressed blocks C0-C4 to obtain the data pages of page1-page8. The mobile phone caches it in the buffer. In this way, when the second process requests to read part or all of the data in any compressed block of compressed blocks C0-C4, the mobile phone can directly read the data page from the cache. For example, when the second process requests to read the target data in page7 (the fourth data page) in C4, the mobile phone can directly read the target data from page7 in the memory buffer.

[0167] That is, the mobile phone reads data from the first compressed file in units of compressed blocks. When the mobile phone reads the first data page required by the current process, it reads the first compressed block to which the first data page belongs from the first compressed file, and after decompressing the first compressed block, caches all the second data pages in the first compressed block in the buffer. In this way, when the second process requests to read the target data in all or part of the second data pages in the compressed block, the mobile phone can read directly from the cache.

[0168] Furthermore, the mobile phone will read one or more second compressed blocks in advance, decompress the second compressed blocks, and cache the fourth data page in the second compressed blocks in the memory buffer. In this way, when the second process requests to read the fourth data page in the second compressed block, the mobile phone can directly read the target data from the buffer, avoiding reading and decompressing data from the disk, avoiding an I / O request between the disk and the memory, and improving data reading efficiency.

[0169] In some cases, the second process may not request to read the fourth data page in the second compressed block. In this case, the fourth data page pre-read by the mobile phone is not used by the second process, which will cause a waste of memory. In order to improve the hit rate of pre-read data, that is, to pre-read the data required by the second process, the mobile phone will identify whether the type of the process's read request for the first file is a sequential read when pre-reading. If the read request of the first process is a sequential read, the mobile phone will pre-read one or more second compressed blocks.

[0170] Sequential reading can also be called continuous reading. Sequential reading can be understood as reading the data in the file continuously. When the mobile phone reads sequentially, the pointer in the file can only move from the beginning to the end, that is, the data in the file can only be read sequentially from the beginning to the end. For example, the data read by the current process and the data read by the previous process are continuous or not far apart in the file. The mobile phone recognizes that the read request of the current process is a sequential read. The mobile phone predicts that the next read request for the same file is also a sequential read. At this time, the mobile phone will pre-read one or more compressed block data.

[0171] like Figure 8 As shown, after the mobile phone executes S505 and reads K first compressed blocks from the disk, the mobile phone can execute S801-S509.

[0172] At S801 , the mobile phone recognizes that a first read request indicates sequential reading of data pages in a first file.

[0173] Exemplarily, the mobile phone can identify whether a certain number of data pages before the first data page in the first file have been cached in the memory. If the data page has been cached in the memory, the mobile phone identifies that the first process is a sequential read. For example, the mobile phone identifies whether the fifth data page in one or more consecutive third compressed blocks before the first first compressed block in the K first compressed blocks has been stored in the buffer. Among them, the third compressed block is a compressed block located before the first first compressed block in the K first compressed blocks. If the fifth data page in one or more third compressed blocks has been cached in the memory buffer, it means that the first process and the previous process read the data page compressed by the compressed block in the first file in sequence, that is, the read request of the first process is a sequential read request. The mobile phone predicts that the second process behind the first process may also read the data page compressed by the compressed block in the first file in sequence. The mobile phone will only read one or more second compressed blocks backward after reading the K first compressed blocks where the first process is located. Exemplarily, the mobile phone can execute S802.

[0174] The fifth data page in one or more third compressed blocks is not cached in the memory buffer, indicating that the first process and the previous process may randomly read the data page compressed by the compressed block in the first file. The mobile phone predicts that the second process after the first process may also randomly read the data page compressed by the compressed block in the first file. At this time, the mobile phone will not pre-read the one or more third compressed blocks backward.

[0175] At S802 , N second compressed blocks following the K first compressed blocks are read from a disk based on a read-ahead window.

[0176] After the mobile phone reads K first compressed blocks from the disk, it can pre-read N third compressed blocks, where N is an integer greater than 1.

[0177] like Figure 8 As shown, S506 may specifically be S803, and S507 may specifically be S804.

[0178] In S803, the mobile phone decompresses the K first compressed blocks to obtain a plurality of second data pages, and decompresses the N second compressed blocks to obtain a plurality of fourth data pages.

[0179] At S804, the mobile phone caches a plurality of second data pages and a plurality of fourth data pages in the memory, wherein the second data pages include q first data pages.

[0180] Afterwards, the mobile phone may execute S508 - S509 , read the Q first data pages from the memory buffer, and return the target data in the Q first data pages to the first process.

[0181] by Figure 6bAs shown, the target data requested to be read by the first process is compressed in compressed blocks C0-C2. After the mobile phone reads compressed blocks C0-C2, the mobile phone will identify whether the fifth data page in compressed block C-1 (the third compressed block) has been cached in the memory. Specifically, the mobile phone will identify whether page0 and / or page-1 (the fifth data page) in C-1 have been cached in the memory. Exemplarily, the mobile phone can check whether the data page with the above offset has been cached in the memory buffer based on the offset of page-1 or page0. If page0 and / or page-1 exist in the memory buffer, the mobile phone recognizes that the fifth data page has been cached in the memory, and then, the mobile phone recognizes that the read request of the first process is a sequential read, and the mobile phone will perform a pre-read operation, such as pre-reading compressed blocks C3, C4 and C5.

[0182] Furthermore, in order to avoid reading too many data pages at a time and occupying memory, when the mobile phone recognizes that the first file is a compressed file, the mobile phone will also recognize whether the current memory of the mobile phone is sufficient. Only when it is recognized that the current memory of the mobile phone is sufficient, the mobile phone will cache all the second data pages in the compressed block after decompression in the memory. In other words, only when the current memory of the mobile phone is sufficient, the mobile phone will execute a method for reading a compressed file provided in an embodiment of the present application. When the current memory of the mobile phone is insufficient, the mobile phone can execute a reading method such as in the related art, and only cache the data page where the target data is located in the memory to save memory space.

[0183] Exemplarily, the mobile phone may include a third threshold value, and the mobile phone may identify the current memory usage. When the current memory usage is less than the third threshold value, the mobile phone identifies that the current memory is sufficient, and when the current memory usage is greater than the third threshold value, the mobile phone identifies that the current memory is insufficient. The memory usage can be understood as the size of the memory space occupied in the memory.

[0184] The mobile phone may include a fourth threshold value, and the mobile phone may identify the remaining amount of the current memory. When the remaining amount of the current memory is greater than the fourth threshold value, the mobile phone identifies that the current memory is sufficient, and when the remaining amount of the current memory is less than the fourth threshold value, the mobile phone identifies that the current memory is insufficient. The remaining amount of the memory may be understood as the size of the memory space in the memory excluding the occupied memory space.

[0185] That is, if the current memory usage of the electronic device is less than the third threshold or the current remaining memory of the electronic device is greater than the fourth threshold, the K first compressed blocks where the q first data pages are located are read from the external memory. The blocks are decompressed and the multiple second data pages are cached in the memory. After the electronic device reads the K first compressed blocks where the q first data pages are located in the external memory, the electronic device can again identify whether the current memory is sufficient, and then identify whether to perform pre-reading.

[0186] For example, after the mobile phone reads K first compressed blocks from the disk, the mobile phone recognizes that the current memory is sufficient, and then performs a pre-read operation to pre-read the second compressed block that may be used by the next process, decompress it, and cache the decompressed multiple fourth data pages. If the current memory of the mobile phone is insufficient, the mobile phone does not perform the pre-read operation.

[0187] The mobile phone may include a first threshold value, and the mobile phone may identify the current memory usage. When the current memory usage is less than the first threshold value, the mobile phone identifies that the current memory is sufficient, and when the current memory usage is greater than the first threshold value, the mobile phone identifies that the current memory is insufficient. The memory usage can be understood as the size of the memory space occupied in the memory.

[0188] The mobile phone may include a second threshold value, and the mobile phone may identify the remaining amount of the current memory. When the remaining amount of the current memory is greater than the second threshold value, the mobile phone identifies that the current memory is sufficient, and when the remaining amount of the current memory is less than the second threshold value, the mobile phone identifies that the current memory is insufficient. The remaining amount of the memory may be understood as the size of the memory space in the memory excluding the occupied memory space.

[0189] An embodiment of the present application provides an electronic device, which includes: a first memory, an external memory, and one or more processors. The first memory is coupled to the processor. The external memory stores a plurality of compressed blocks, which are obtained by compressing at least one file, and each compressed block includes M data pages in a file, where M is an integer greater than 1; the first memory is used to store computer program code, and the computer program code includes computer instructions; when the computer instructions are executed by the processor, the electronic device can execute the various functions or steps executed by the mobile phone in the above method embodiment. The structure of the electronic device can refer to Figure 3 The structure of the electronic device 300 is shown.

[0190] The present application also provides a computer storage medium, which includes computer instructions. When the computer instructions are in the above electronic device (such as Figure 3 When the method is executed on the electronic device 300 shown in the figure, the electronic device executes each function or step in the above method embodiment.

[0191] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute each function or step in the above method embodiment.

[0192] The embodiment of the present application also provides a chip system, which includes at least one processor and at least one interface circuit. The processor and the interface circuit can be interconnected by lines. For example, the interface circuit can be used to receive signals from other devices (such as a memory of an electronic device). For another example, the interface circuit can be used to send signals to other devices (such as a processor). Exemplarily, the interface circuit can read instructions stored in the memory and send the instructions to the processor. When the instruction is executed by the processor, the electronic device can perform the various steps in the above embodiments. Of course, the chip system can also include other discrete devices, which is not specifically limited in the embodiment of the present application.

[0193] Through the description of the above implementation methods, technical personnel in the relevant field can clearly 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.

[0194] 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.

[0195] 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.

[0196] 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.

[0197] 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 codes.

[0198] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims

1. A method for reading a compressed file, characterized in that: Applied to an electronic device, the electronic device includes an external memory, the external memory stores a plurality of compressed blocks, the plurality of compressed blocks are obtained by compressing at least one file, each compressed block includes M data pages in a file, M is an integer greater than 1, the method includes: Receive a first read request, where the first read request is used to request to read Q first data pages in a first file, the first read request indicates an identifier of the first file and positions of the Q first data pages in the first file, where Q is an integer greater than or equal to 1; If q of the Q first data pages are not cached in the memory of the electronic device, K first compressed blocks where the q first data pages are located are read from the external memory, the K first compressed blocks are decompressed to obtain a plurality of second data pages, and the plurality of second data pages are cached in the memory; wherein the plurality of second data pages include the q first data pages; at least one of the K first compressed blocks compresses Mm first data pages and m data pages, 1≤q≤Q, K≥1, 1≤m<M, q, K and m are all integers; and the first read request does not request to read the m data pages; The Q first data pages are read from the memory.

2. The method according to claim 1, characterized in that After caching the plurality of second data pages in the memory, the method further includes: receiving a second read request, the second read request being used to request reading P third data pages in a second file, the second read request indicating an identifier of the second file and positions of the P third data pages in the second file, where P is an integer greater than or equal to 1; the P third data pages are included in the plurality of second data pages; The P third data pages are cached in the memory of the electronic device, and the P third data pages are read from the memory.

3. The method according to claim 1, characterized in that The step of reading the Q first data pages from the memory includes: If Qq first data pages other than the q first data pages among the Q first data pages are cached in the memory, the Qq first data pages are directly read from the memory; The q first data pages are not cached in the memory, and the q first data pages are read from the plurality of second data pages cached in the memory.

4. The method according to any one of claims 1 to 3, characterized in that After reading the K first compressed blocks where the q first data pages are located from the external memory, the method further includes: Reading N second compressed blocks after the K first compressed blocks from the external memory based on a pre-reading window, where N is the size of the pre-reading window; Decompressing the N second compressed blocks to obtain a plurality of fourth data pages, and caching the plurality of fourth data pages in the memory.

5. The method according to claim 4, characterized in that The step of reading the N second compressed blocks after the K first compressed blocks from the external memory based on the pre-read window includes: If the first read request indicates to sequentially read data pages in the first file, the N second compressed blocks are read from the external memory based on the pre-read window.

6. The method according to claim 5, characterized in that If the fifth data page in at least one third compressed block before the first first compressed block in the K first compressed blocks is cached in the memory, the first read request indicates to sequentially read the data pages in the first file.

7. The method according to claim 4, characterized in that The step of reading the N second compressed blocks after the K first compressed blocks from the external memory based on the pre-read window includes: If the current memory usage of the electronic device is less than the first threshold or the current remaining memory of the electronic device is greater than the second threshold, the N second compressed blocks following the K first compressed blocks are read from the external memory based on the pre-read window.

8. The method according to any one of claims 1-3, 5-7, characterized in that: The step of reading the K first compressed blocks where the q first data pages are located from the external memory includes: If the first file is stored as a compressed file in the external memory, the K first compressed blocks where the q first data pages are located are read from the external memory.

9. The method according to claim 1, characterized in that: The step of reading the K first compressed blocks where the q first data pages are located from the external memory includes: If the current memory usage of the electronic device is less than the third threshold or the current remaining memory of the electronic device is greater than the fourth threshold, the K first compressed blocks where the q first data pages are located are read from the external memory.

10. An electronic device, characterized in that: The electronic device comprises: a first memory, an external memory and one or more processors; the first memory is coupled to the processor; wherein the external memory stores a plurality of compressed blocks, the plurality of compressed blocks are obtained by compressing at least one file, each compressed block includes M data pages in a file, M is an integer greater than 1; the first memory stores computer program code, the computer program code includes computer instructions; when the computer instructions are executed by the processor, the electronic device executes the method as described in any one of claims 1-9.

11. A computer-readable storage medium, characterized in that: The method comprises computer instructions, which, when executed on an electronic device, cause the electronic device to execute the method as claimed in any one of claims 1 to 9.

12. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.

Citation Information

Patent Citations

  • Transparent hardware-assisted memory decompression

    CN107250991A

  • Method for reading compressed file, file system and electronic equipment

    CN114461589A

  • Processor instructions for data compression and decompression

    CN114661677A