Method for reading compressed file and related device
By identifying the cluster where the compressed file page resides and decompressing it into the cache module, the problem of slow compressed file reading speed is solved, improving reading efficiency and speed.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2026-04-03
AI Technical Summary
Existing technologies require additional decompression operations when reading compressed files, resulting in slower reading speeds and significantly worse reading performance compared to regular files.
By determining the cluster where the compressed file pages reside, multiple file pages can be decompressed from storage and copied to the cache module without affecting the original caching strategy. This reduces the number of storage reads and decompression operations, thereby improving read efficiency.
Reducing the number of decompression operations improves the efficiency of applications reading compressed files and increases reading speed.
Smart Images

Figure CN121785513A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method and related apparatus for reading compressed files. Background Technology
[0002] In various computer devices or intelligent electronic devices, such as Figure 1 As shown, when reading a regular file, the application requests to read the target file pages (e.g., page1-page2). The caching module, upon receiving a request to read two pages, increases the number of pages to six, reading four more pages ahead of the user and caching them in the caching module. It then requests cached file pages (e.g., page1-page6) from the file system, which in turn requests these cached file pages from the disk. However, due to limited memory, files or infrequently used applications are usually compressed, such as... Figure 2 As shown, in the prior art, when reading a compressed file, for example, when an application reads the target file pages (page1-page2), the caching module also needs to read 4 more pages and request 6 pages of files from the file system as cache files. The file system will request them from the disk according to the compression unit (cluster). For example, a cluster contains 8 pages. Therefore, the file system needs to request the compressed file pages (cpage) corresponding to these 8 pages from the disk and decompress them to obtain decompressed file pages including cache file pages. Then, the extra file pages (page7-page8) are discarded, and cache file pages (page1-page6) are returned to the cache area. The cache area then returns the target file pages (page1-page2) to the application.
[0003] Compared to regular files, compressed files require additional decompression operations during data reading, resulting in slower read speeds and a significant performance degradation. For example, taking a 295MB VDEX file from a video application as an example, the read speed of a regular file is 586.47 MB / s. Using LZ4 compression saves 105.9MB of space with a compression rate of 35.9%, but the read speed is only 481.23 MB / s, a 18% decrease. Using ZSTD compression (default compression level 1) saves 148.3MB of space with a compression rate of 50.3%, but the read speed is only 276.73 MB / s, a 42% decrease. (All specific values mentioned here are measured under specific conditions on specific electronic devices based on specific hardware and software.)
[0004] The above method of reading compressed files involves multiple decompression steps, resulting in a low reading speed. Summary of the Invention
[0005] This application provides a method and related apparatus for reading compressed files, which can improve the efficiency of reading compressed files.
[0006] In a first aspect, embodiments of this application provide a method for reading compressed files, the method comprising:
[0007] The system receives a first request from an application, which requests to read a first file page. Specifically, for example, when a user operates the application on the electronic device and needs to read the first file page, it's equivalent to the application sending a first request to read the first file page. The first file page is stored in units of 4KB, and there can be one or more pages. When there are multiple first file pages, these pages can be consecutive or non-consecutive. Correspondingly, the electronic device receives the first request; this can be a module within the electronic device, such as a cache module.
[0008] Obtain the first cluster where the first file page was compressed; specifically, when the application requests a compressed file, since the compressed file is compressed in units of clusters, it is necessary to first determine which cluster or cluster the first file page was in when it was compressed before decompressing the corresponding cluster. These clusters are collectively referred to as the first cluster.
[0009] The first storage space is used to decompress multiple file pages contained in the first cluster. Specifically, after determining the first cluster, the compressed file page (cpage) corresponding to the first cluster is stored in the first storage space. Decompressing the compressed file page (cpage) yields multiple file pages, wherein the multiple file pages are the multiple file pages contained in the first cluster. The first storage space can be local storage (e.g., disk) or external storage.
[0010] The decompressed file pages are copied to the cache module. Specifically, the file pages are the file pages that the cache module requests to read and that the cache module needs to cache. Therefore, the file system returns all the decompressed file pages to the cache module. For example, it can copy them to the cache module or return them to the cache module in other ways. This is not limited here.
[0011] The first file page from the caching module is returned to the application. After receiving the returned plurality of file pages, including the first file page, the caching module then returns the first file page to the application.
[0012] In this method, without affecting the original caching strategy, the number of file pages that the caching module needs to cache each time is cached according to cluster alignment. The file system returns all the decompressed file pages to the caching module. Therefore, when the application requests to read other file pages in the future, those other file pages are likely already cached in the caching module, and the caching module does not need to request the file page from the file system again. This reduces the number of times the first storage space is read and the number of decompressions, and improves the efficiency of reading compressed files.
[0013] In another alternative approach, obtaining the first cluster where the first file page was compressed includes:
[0014] Obtain the cluster specification when compressing the first file page, wherein the cluster specification is the number of pages contained in each cluster, such as 8 pages, 16 pages, 32 pages, etc.
[0015] The first cluster is determined based on the metadata information of the first file page and the specifications of the cluster. The metadata information of the first file page includes one or more of the following: location information, file identifier, file index, etc., or it may be obtained based on other information or methods.
[0016] In this method, the first cluster containing the first file page can be accurately located based on the information of the first file page and the specifications of the cluster.
[0017] In another alternative approach, the step of decompressing the multiple file pages contained in the first cluster from the first storage space includes:
[0018] Obtain the first address of the compressed file page (cpage) corresponding to the multiple file pages (pages) contained in the first cluster; specifically, the multiple file pages (pages) contained in the first cluster are compressed to reduce their data size, but are still stored in 4K units. In order to distinguish the storage unit of page before compression, the storage unit of the compressed file is cpage. The data storage location changes after compression, so it is necessary to obtain the first address information of the compressed file page (cpage) corresponding to the multiple file pages (pages);
[0019] The compressed file page (cpage) is obtained from the first storage space according to the first address; specifically, the first address information is submitted to the first storage space to request the compressed file page (cpage), and the first storage space finds the compressed file page (cpage) according to the first address and returns it;
[0020] The compressed file is decompressed to obtain the plurality of file pages. Specifically, the decompression of the obtained compressed file to obtain the plurality of file pages can be performed in the first storage space or in other modules of the electronic device.
[0021] In this method, the location information of the compressed file page (cpage) is obtained first, and then the compressed file page (cpage) is obtained from the first storage space according to the location information, which can ensure the accuracy of the obtained compressed file page (cpage).
[0022] In another alternative approach, after receiving the first request from the application and before obtaining the first cluster where the target first file page is compressed, the method further includes:
[0023] The first file page is determined to be a file page of a compressed file. The electronic device will not execute the operation of obtaining the first cluster where the first file page was compressed if it recognizes that the first file page requested by the application is a file page of a compressed file; otherwise, the operation of obtaining the first cluster where the first file page was compressed will be executed according to the normal file reading process.
[0024] Adding an operation to confirm that the first file page is a compressed file page in this method can ensure that the method of this application is executed in the appropriate use case and avoid unnecessary operations.
[0025] In another alternative approach, after obtaining the first cluster where the first file page was compressed, and before decompressing the multiple file pages contained in the first cluster from the first storage space, the method further includes:
[0026] The cache module determines that the multiple file pages contained in the first cluster are the file pages that the cache module needs to cache. Specifically, after obtaining the first cluster, the cache module performs a pre-read operation aligned with the first cluster, treating all the multiple file pages in the first cluster as the file pages that the cache module needs to cache, and which are also the file pages that the cache module needs to request.
[0027] In this method, the cache module performs a pre-read operation aligned with the first cluster, requesting all file pages in the first cluster. This facilitates the subsequent return of all file pages obtained by decompressing the cluster to the cache module, thereby increasing the pre-read window size of the cache module.
[0028] In another alternative approach, files other than the first file page located in the plurality of file pages of the cache module are prefetched file pages.
[0029] In another alternative approach, after returning the plurality of file pages to the cache module, the method further includes:
[0030] The system receives a second request from the application, requesting the reading of a second file page; determines that the second file page is in the cache module; and returns the second file page from the cache module to the application. Specifically, after receiving multiple file pages contained in the first cluster, when the cache module receives a second request from the application to read the second file page, if it recognizes that the cached multiple file pages include the second file page, it can directly return the second file page to the application without repeating the reading and decompression process.
[0031] This method reduces the number of decompression operations and improves the efficiency of the application in reading files.
[0032] In one alternative implementation, the method is applied to a Linux system.
[0033] Secondly, embodiments of this application provide an apparatus for reading compressed files, the apparatus comprising:
[0034] A receiving unit is configured to receive a first request sent by an application, wherein the first request is for requesting to read a first file page.
[0035] The acquisition unit is used to acquire the first cluster in which the first file page was compressed;
[0036] A decompression unit is used to decompress multiple file pages contained in the first cluster from the first storage space;
[0037] The copy unit is used to copy multiple decompressed file pages to the cache module;
[0038] The sending unit is used to return the first file page from the cache module to the application.
[0039] Thirdly, embodiments of this application provide an electronic device comprising: one or more processors; and a memory; wherein the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code including computer instructions, and the one or more processors invoke the computer instructions to cause the electronic device to perform the method described in any of the possible implementations of the first aspect.
[0040] Fourthly, embodiments of this application provide a chip system applied to an electronic device. The chip system includes one or more processors, which are configured to invoke computer instructions to cause the electronic device to perform the method described in any of the possible implementations of the first aspect.
[0041] Fifthly, embodiments of this application provide a computer program product containing instructions that, when the computer program product is run on a processor, implement the method described in any of the possible implementations of the first aspect.
[0042] In a sixth aspect, embodiments of this application provide a computer-readable storage medium including instructions that, when executed on a processor, implement the method described in any of the possible implementations of the first aspect.
[0043] It should be understood that the descriptions of technical features, technical solutions, beneficial effects, or similar language in this application do not imply that all features and advantages can be achieved in any single embodiment. Rather, it is understood that the description of a feature or beneficial effect means that a specific technical feature, technical solution, or beneficial effect is included in at least one embodiment. Therefore, the descriptions of technical features, technical solutions, or beneficial effects in this specification do not necessarily refer to the same embodiment. Furthermore, the technical features, technical solutions, and beneficial effects described in this embodiment can be combined in any suitable manner. Those skilled in the art will understand that embodiments can be implemented without one or more specific technical features, technical solutions, or beneficial effects of a particular embodiment. In other embodiments, additional technical features and beneficial effects may be identified in specific embodiments that do not embody all embodiments. Attached Figure Description
[0044] The accompanying drawings used in the embodiments of this application are described below.
[0045] Figure 1 This is a flowchart illustrating a method for reading ordinary files provided in an embodiment of this application;
[0046] Figure 2 This is a flowchart illustrating a prior art method for reading compressed files provided in an embodiment of this application;
[0047] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;
[0048] Figure 4 This is a schematic diagram of the software architecture of a Linux system provided in an embodiment of this application;
[0049] Figure 5 This is a schematic diagram of a file storage method provided in an embodiment of this application;
[0050] Figure 6 This is a schematic diagram of file compression using the F2FS flash-friendly file system provided in an embodiment of this application;
[0051] Figure 7 This is a flowchart illustrating a method for reading compressed files provided in an embodiment of this application;
[0052] Figure 8 This is a flowchart illustrating a specific implementation of a method for reading compressed files provided in this application embodiment;
[0053] Figure 9 This is a schematic diagram illustrating an example of sequentially reading 128 pages from a 4K file, as provided in an embodiment of this application.
[0054] Figure 10 This is a schematic diagram of a device for reading compressed files provided in an embodiment of this application. Detailed Implementation
[0055] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this application refers to and includes any or all possible combinations of one or more of the listed items.
[0056] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.
[0057] The method proposed in this application embodiment can be used in various electronic devices or systems (such as Linux systems), as long as the electronic device or system performs a pre-read operation when reading compressed files.
[0058] For example, the electronic device in this application embodiment may be a smart screen device, a smart TV (TV), a mobile phone, a tablet computer, an ultra-mobile personal computer (UMPC), a netbook, as well as a cellular phone, a personal digital assistant (PDA), a wearable device (such as a smartwatch, a smart bracelet), and other devices with the function of reading compressed files. This application embodiment does not impose any special restrictions on the specific form of the electronic device.
[0059] For example, taking a mobile phone as an electronic device, Figure 3 This is a schematic diagram of the structure of an electronic device 10 provided in an embodiment of this application. That is, exemplary, Figure 3 The electronic device shown could be a mobile phone.
[0060] like Figure 3As shown, the electronic device 10 may include a processor 110, an external memory interface 120, an internal memory 129, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0061] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 10. In other embodiments of this application, the electronic device 10 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0062] Processor 110 may include one or more processing units, such as application processors (APs), modem processors, graphics processing units (GPUs), image signal processors (ISPs), controllers, video codecs, digital signal processors (DSPs), baseband processors, and / or neural network processing units (NPUs). These different processing units may be independent devices or integrated into one or more processors.
[0063] Processor 110 can generate operation control signals based on instruction opcodes and timing signals to control instruction fetching and execution. This electronic device can execute commands through processor 110. Figure 7 or Figure 8All or part of the operations in the method embodiments shown include, for example, receiving a first request sent by an application; obtaining the first cluster where the first file page is compressed; decompressing multiple file pages contained in the first cluster from the first storage space; copying the decompressed multiple file pages to the cache module; and returning the first file page in the cache module to the application.
[0064] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0065] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0066] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple I2C buses. The processor 110 can couple to the touch sensor 180K, charger, flash, camera 193, etc., through different I2C bus interfaces. For example, the processor 110 can couple to the touch sensor 180K through the I2C interface, enabling the processor 110 and the touch sensor 180K to communicate through the I2C bus interface, thereby realizing the touch function of the electronic device 10.
[0067] The I2S interface can be used for audio communication. In some embodiments, the processor 110 may include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to enable communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 can transmit audio signals to the wireless communication module 160 via the I2S interface to enable the function of answering phone calls through a Bluetooth headset.
[0068] The PCM interface can also be used for audio communication, sampling, quantizing, and encoding analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 can be coupled via the PCM bus interface. In some embodiments, the audio module 170 can also transmit audio signals to the wireless communication module 160 via the PCM interface, enabling the function of answering phone calls through a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
[0069] The UART interface is a universal serial data bus used for asynchronous communication. This bus can be a bidirectional communication bus. It converts the data to be transmitted between serial and parallel communication. In some embodiments, the UART interface is typically used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 via the UART interface to implement Bluetooth functionality. In some embodiments, the audio module 170 can transmit audio signals to the wireless communication module 160 via the UART interface to enable music playback through Bluetooth headphones.
[0070] The MIPI interface can be used to connect the processor 110 to peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI) and a display serial interface (DSI). In some embodiments, the processor 110 and the camera 193 communicate via the CSI interface to enable the electronic device 10 to capture images. The processor 110 and the display screen 194 communicate via the DSI interface to enable the electronic device 10 to display images.
[0071] The GPIO interface can be configured via software. It can be configured as a control signal or a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 to a camera 193, a display screen 194, a wireless communication module 160, an audio module 170, a sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.
[0072] USB port 130 is a USB standard compliant interface, specifically a Mini USB port, Micro USB port, USB Type-C port, etc. USB port 130 can be used to connect a charger to charge electronic device 10, and can also be used for data transfer between electronic device 10 and peripheral devices. It can also be used to connect headphones for audio playback. This interface can also be used to connect other electronic devices, such as AR devices.
[0073] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the electronic device 10. In other embodiments of this application, the electronic device 10 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.
[0074] The charging management module 140 receives charging input from a charger. The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 receives charging input from the wired charger via the USB interface 130. In some wireless charging embodiments, the charging management module 140 receives wireless charging input via the wireless charging coil of the electronic device 10. While charging the battery 142, the charging management module 140 can also supply power to the electronic device via the power management module 141.
[0075] The power management module 141 connects the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, providing power to the processor 110, internal memory 129, display screen 194, camera 193, and wireless communication module 160, etc. The power management module 141 can also monitor parameters such as battery capacity, battery cycle count, and battery health status (leakage current, impedance). In some other embodiments, the power management module 141 may also be located within the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may be located in the same device.
[0076] The wireless communication function of electronic device 10 can be implemented through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor, and baseband processor.
[0077] Antennas 1 and 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 10 can be used to cover one or more communication frequency bands. Different antennas can also be multiplexed to improve antenna utilization. For example, antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with a tuning switch.
[0078] The mobile communication module 150 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the electronic device 10. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves via the antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to the modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via the antenna 1. In some embodiments, at least some functional modules of the mobile communication module 150 may be housed in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 150 and at least some modules of the processor 110 may be housed in the same device.
[0079] The modem processor may include a modulator and a demodulator. The modulator modulates the low-frequency baseband signal to be transmitted into a mid-to-high frequency signal. The demodulator demodulates the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After processing by the baseband processor, the low-frequency baseband signal is transmitted to the application processor. The application processor outputs sound signals through an audio device (not limited to speaker 170A, receiver 170B, etc.) or displays images or videos through the display screen 194. In some embodiments, the modem processor may be a separate device. In other embodiments, the modem processor may be independent of the processor 110 and may be housed in the same device as the mobile communication module 150 or other functional modules.
[0080] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 10, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 2, demodulates and filters the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, frequency modulate and amplify them, and then convert them into electromagnetic waves for radiation via antenna 2.
[0081] In some embodiments, antenna 1 of electronic device 10 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, enabling electronic device 10 to communicate with networks and other devices via wireless communication technology. The wireless communication technology may include Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Time-Division Code Division Multiple Access (TD-SCDMA), Long Term Evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technologies, etc. The GNSS may include the Global Positioning System (GPS), the Global Navigation Satellite System (GLONASS), the BeiDou Navigation Satellite System (BDS), the Quasi-Zenith Satellite System (QZSS), and / or satellite-based augmentation systems (SBAS).
[0082] Electronic device 10 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connecting the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0083] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a miniature LED, a microLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 10 may include one or N displays 194, where N is a positive integer greater than 1.
[0084] Electronic device 10 can perform shooting functions through ISP, camera 193, video codec, GPU, display 194 and application processor.
[0085] The ISP (Image Signal Processor) is used to process data fed back from the camera 193. For example, when taking a picture, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, and the camera's photosensitive element transmits the electrical signal to the ISP for processing, converting it into an image visible to the naked eye. The ISP can also perform algorithmic optimization on image noise and brightness. The ISP can also optimize parameters such as exposure and color temperature of the shooting scene. In some embodiments, the ISP can be set in the camera 193.
[0086] Camera 193 is used to capture still images or videos. An object is projected onto a photosensitive element by generating an optical image through the lens. The photosensitive element can be a charge-coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor.
[0087] A digital signal processor (DSP) is used to process digital signals. Besides digital image signals, it can also process other digital signals. For example, when the electronic device 10 selects a frequency, the DSP can perform Fourier transforms on the frequency energy.
[0088] Video codecs are used to compress or decompress digital video. Electronic device 10 may support one or more video codecs. Thus, electronic device 10 can play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG 2, MPEG 3, MPEG 4, etc.
[0089] An NPU (Neural Processing Unit) is a neural network (NN) computing processor that, by borrowing from the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, rapidly processes input information and can continuously learn on its own. NPUs enable intelligent cognitive applications in electronic devices, such as image recognition, facial recognition, speech recognition, and text understanding.
[0090] Internal memory 129 may include one or more random access memory (RAM) and one or more non-volatile memory (NVM).
[0091] Random access memory can include static random-access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), and double data rate synchronous dynamic random access memory (DDR SDRAM, such as fifth-generation DDR SDRAM, which is generally called DDR5 SDRAM). Non-volatile memory can include disk storage devices and flash memory.
[0092] Flash memory can be classified according to its operating principle, including NOR FLASH, NAND FLASH, 3D NAND FLASH, etc.; according to the level of the storage cell, including single-level cell (SLC), multi-level cell (MLC), triple-level cell (TLC), quad-level cell (QLC), etc.; and according to the storage specification, including universal flash storage (UFS) and embedded multimedia card (eMMC), etc.
[0093] The random access memory can be directly read and written by the processor 110. It can be used to store executable programs (such as machine instructions) of the operating system or other running programs, as well as user and application data.
[0094] Non-volatile memory can also store executable programs and user and application data, and can be pre-loaded into random access memory for direct reading and writing by the processor 110.
[0095] The external memory interface 120 can be used to connect to external non-volatile memory, thereby expanding the storage capacity of the electronic device 10. The external non-volatile memory communicates with the processor 110 through the external memory interface 120 to perform data storage functions. For example, music, video, and other files can be stored in the external non-volatile memory.
[0096] Electronic device 10 can implement audio functions such as music playback and recording through audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, and application processor.
[0097] The audio module 170 is used to convert digital audio information into analog audio signals for output, and also to convert analog audio input into digital audio signals. The audio module 170 can also be used for encoding and decoding audio signals. In some embodiments, the audio module 170 may be located in the processor 110, or some functional modules of the audio module 170 may be located in the processor 110.
[0098] The speaker 170A, also known as a "loudspeaker," is used to convert audio electrical signals into sound signals. The electronic device 10 can listen to music or make hands-free calls through the speaker 170A.
[0099] The receiver 170B, also known as the "earpiece," is used to convert audio electrical signals into sound signals. When the electronic device 10 receives a telephone call or voice message, the receiver 170B can be brought close to the ear to hear the voice.
[0100] Microphone 170C, also known as a "microphone" or "voice transducer," is used to convert sound signals into electrical signals. When making a phone call or sending a voice message, the user can speak by bringing their mouth close to microphone 170C, inputting the sound signal into microphone 170C.
[0101] The 170D headphone jack is used to connect wired headphones. The 170D headphone jack can be a USB 130 interface or a 3.5mm Open Mobile Terminal Platform (OMTP) standard interface, a CTIA (Cellular Telecommunications Industry Association of the USA) standard interface.
[0102] The pressure sensor 180A is used to sense pressure signals and can convert the pressure signals into electrical signals. In some embodiments, the pressure sensor 180A may be disposed on the display screen 194.
[0103] The gyroscope sensor 180B can be used to determine the motion attitude of the electronic device 10. In some embodiments, the angular velocity of the electronic device 10 about three axes (i.e., the x, y, and z axes) can be determined by the gyroscope sensor 180B.
[0104] The barometric pressure sensor 180C is used to measure air pressure. In some embodiments, the electronic device 10 calculates altitude using the air pressure value measured by the barometric pressure sensor 180C to assist in positioning and navigation.
[0105] The magnetic sensor 180D includes a Hall sensor.
[0106] The accelerometer 180E can detect the magnitude of acceleration of electronic device 10 in various directions (generally three axes).
[0107] A distance sensor 180F is used to measure distance. Electronic device 10 can measure distance via infrared or laser. In some embodiments, during a shooting scene, electronic device 10 can utilize the distance sensor 180F to measure distance for rapid focusing.
[0108] The proximity light sensor 180G may include, for example, a light-emitting diode (LED) and a light detector, such as a photodiode.
[0109] An ambient light sensor 180L is used to sense the ambient light intensity. The electronic device 10 can adaptively adjust the brightness of the display screen 194 according to the sensed ambient light intensity.
[0110] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 10 can utilize the characteristics of the collected fingerprints to achieve fingerprint unlocking, accessing application locks, taking photos with fingerprints, answering calls with fingerprints, etc.
[0111] Temperature sensor 180J is used to detect temperature. In some embodiments, electronic device 10 uses the temperature detected by temperature sensor 180J to execute a temperature processing strategy.
[0112] Touch sensor 180K, also known as a "touch device," can be located on display screen 194. The touch sensor 180K and display screen 194 together form a touchscreen, also known as a "touchscreen." Touch sensor 180K detects touch operations applied to or near it. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through display screen 194. In other embodiments, touch sensor 180K may also be located on the surface of electronic device 10, in a different position than display screen 194.
[0113] The bone conduction sensor 180M can acquire vibration signals. In some embodiments, the bone conduction sensor 180M can acquire vibration signals from the vibrating bone segments of the human vocal cords.
[0114] Button 190 includes the power button, volume buttons, etc. Button 190 can be a mechanical button or a touch button.
[0115] Motor 191 can generate vibration alerts. Motor 191 can be used for incoming call vibration alerts or for touch vibration feedback.
[0116] Indicator 192 can be an indicator light, used to indicate charging status, power changes, or to indicate messages, missed calls, notifications, etc.
[0117] The SIM card interface 195 is used to connect a SIM card. The SIM card can be inserted into or removed from the SIM card interface 195 to make contact with or separate from the electronic device 10.
[0118] The software system of electronic devices can adopt a layered architecture, transaction-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This application uses a layered Linux system as an example for illustrative purposes. Please refer to... Figure 4 , Figure 4 This is a schematic diagram of the software architecture of a Linux system provided in an embodiment of this application.
[0119] A layered architecture divides software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the Linux system software can be broadly divided into an application layer (also called user space) and a kernel layer (also called kernel space).
[0120] The application layer can include a package of applications.
[0121] like Figure 4 As shown, applications can include file management, office software, social networking software, camera, gallery, map, navigation, music, video, SMS and other applications.
[0122] For example, when a user operates social media software on an electronic device and uses certain functions, they may need to access compressed files compressed by the operating system. In this case, the compressed file needs to be decompressed before it can be accessed or used. These compressed files compressed by the operating system are different from those compressed by the user or application. The method proposed in this application embodiment is also for compressed files compressed by the operating system.
[0123] When music and video applications are launched, users can play audio on their electronic devices. The device can determine the audio playback scenario based on the running application. For example, in response to a user's request to play a music file on a music application, the music application can identify the audio file through the audio playback management service at the application framework layer. This audio playback management service can then invoke the audio hardware in the abstraction layer to activate the hardware involved in music playback, such as speakers and earpieces, causing the electronic device to launch the music application and begin playing the music file.
[0124] The kernel layer is the core of the Linux system, responsible for managing system resources and hardware, including process management, memory management, file system (e.g., VFS) management, network functions, and handling system calls. The kernel provides a range of services, resources, and functionalities, which applications access by calling system call API functions.
[0125] The System Call Interface (SCI) is essentially the application programming interface (API) provided by the Linux kernel to the application layer. It serves as the entry point for Linux applications to access the kernel. It provides standard APIs for programs to use (such as read, write, open, etc.) and handles the switch between user space and kernel space. Not only Linux, but all operating systems provide system calls to the application layer, allowing applications to access various services provided by the operating system. Through system calls, Linux applications can request the kernel to perform certain actions on their behalf, such as opening files on the disk, reading and writing files, closing files, and controlling other hardware peripherals. Through the system call API, the application layer can interact with the kernel.
[0126] Another important resource managed by the kernel is memory. For efficiency, virtual memory is managed by hardware, and memory is managed in so-called memory pages (4KB for most architectures). Linux includes methods for managing available memory, as well as the hardware mechanisms used for physical and virtual mapping. However, memory management involves more than just the 4KB buffer. Linux provides abstractions for the 4KB buffer, such as the slab allocator. This memory management model uses the 4KB buffer as a base, allocates structures from it, and tracks memory page usage—which pages are full, which are not fully used, and which are empty. This allows the model to dynamically adjust memory usage according to system needs. To support multiple users sharing memory, sometimes available memory can be exhausted. For this reason, pages can be moved out of memory and onto the disk. This process is called swapping, as pages are swapped from memory to the hard drive.
[0127] The Virtual Filesystem Switch (VFS) is a kernel software layer in Linux, an abstraction layer above specific file systems. It handles all calls related to the POSIX file system, providing a common interface to various file systems, allowing upper-level applications to access different file systems and facilitating communication between them. The VFS acts as an exchange layer between the System Call Interface (SCI) and the file systems supported by the kernel. Above the VFS is a general API abstraction for functions such as `open`, `close`, `read`, and `write`. Below the VFS are file system abstractions that define the implementation of upper-level functions. These are plugins for a given file system (over 50). Below the file system layer is a buffer cache, which provides a general set of functions (file system-independent). This cache layer optimizes access to physical devices by retaining data for a period of time (or pre-fetching data so it's available when needed). Below the buffer cache are device drivers, which implement the interface for specific physical devices.
[0128] At the bottom of the kernel layer lies the device driver layer, responsible for the management and control of specific hardware devices, such as disk drivers and network adapter drivers. Device drivers are part of the operating system kernel and are programs responsible for interacting with hardware devices. They provide an abstraction layer, allowing the operating system and applications to access different types of hardware in a unified way. Device drivers interact with the kernel layer through APIs provided by the kernel, while also directly accessing the hardware. Drivers encapsulate hardware operations, enabling upper-layer applications to interact with the device through system calls. Device drivers provide the operating system with an interface to the hardware layer, allowing user-space applications to access various hardware resources in a simplified manner. This design improves system portability and flexibility, enabling Linux to support a wide range of hardware devices.
[0129] The hardware layer can include local device storage (such as disks and flash memory) and external storage devices. The hardware layer is responsible for interacting directly with these storage devices, ensuring smooth data read and write operations. Internal storage provides high-speed data read and write performance, ensuring that the system and applications can quickly access the data they need. Some devices support external storage, such as SD cards, which provides users with additional storage space for storing media files (such as photos, music, and videos) and other user-manageable data. Disks and flash memory are typically partitioned to optimize performance and manage data. For example, internal storage may be divided into system partitions, user data partitions, and cache partitions. Storage devices use specific file systems to organize and manage files. Android typically uses a Flash-Friendly FileSystem (F2FS) or a Fourth Extended Filesystem (EXT4) to suit the characteristics of electronic devices and provide stable performance.
[0130] In the embodiments of this application, combined with Figure 4 This example illustrates the workflow of an electronic device 10 reading a compressed file.
[0131] The application on electronic device 10 sends a request to read the target file page to the VFS in the kernel layer through the system interface call layer. The cache module in the VFS receives the request to read the target file page and performs a pre-read operation. It then requests a cached file page from the file system. The file system uses a compression algorithm to find the corresponding compressed file page (cpage) and requests the compressed file page (cpage) from the local device storage through the device driver layer. The file system decompresses the compressed file page (cpage) from the local device storage using a compression algorithm, discards redundant file pages, and returns the cached file page (page) to the cache module. The cache module then returns the target file page (page) to the application.
[0132] Among them, such as Figure 5 As shown, files are typically stored in the operating system in units of file pages. One file page usually corresponds to one page in memory, and a page is 4KB in size. A file consists of X pages, which can be stored contiguously or non-contiguously on the disk. File compression is usually performed in units of clusters, which consist of K pages, such as 8 pages, 16 pages, or 32 pages. Figure 6A file compression diagram of a Flash-Friendly File System (F2FS) is presented. Source data A from a cluster is compressed to obtain compressed data B. Compressed data B is smaller than the source data A. Data B is then stored in a file in units of cpages (the compressed file size is reduced, but it is still stored in 4KB units; to distinguish between the uncompressed and compressed files, the unit after compression is represented by cpage, which has the same size as a page). Ultimately, this reduces the number of pages in the file, thereby reducing the disk space occupied by the file (where X and K are integers greater than or equal to 1).
[0133] Correspondingly, when reading compressed files, decompression is also performed on a cluster-by-cluster basis. When an application requests to read n pages, the caching module performs pre-reading based on certain rules, actually requesting to read n+m pages from the file system. The file system aligns these n+m pages to the cluster, that is, it obtains the cluster where these n+m pages were compressed, and decompresses them according to the cluster. The file system actually requests to read t pages from the disk (where t is the total number of file pages in the cluster, t>=n+m). Since these t pages have been compressed... For each t1 cpage (t > t1 due to compression), the file system submits the address of the t1 cpages to the disk, requests the t1 cpages from the disk, decompresses the obtained t1 cpages to obtain t pages, and returns the n+m pages to the cache module, discarding the decompressed redundant pages. However, the next time the discarded redundant pages are requested, the cache module does not have the page cached, and it needs to request the file system again. The file system continues to request from the disk and then decompress, resulting in a large number of decompressions and low read efficiency (where n, m, t, and t1 are integers greater than or equal to 1).
[0134] Based on the above problems, this application proposes a method for reading compressed files, which can reduce the number of decompression operations and improve reading efficiency. The specific method is as follows.
[0135] Please see Figure 7 , Figure 7 This is a flowchart illustrating a method for reading compressed files provided in an embodiment of this application. This method can be based on... Figure 3 The hardware architecture and / or of the electronic device shown Figure 4The software architecture shown can be used, but it can also be implemented based on other architectures. This method can be applied to Linux systems, as well as other systems or devices, as long as the system or device requires a pre-read operation when reading the compressed file. The compressed file can be read in 4KB units or other units, and can be read sequentially or in other ways. This method includes, but is not limited to, the following steps:
[0136] Step S701: Receive the first request sent by the application.
[0137] Specifically, the first request is used to request the reading of the first file page. For example, the first request may include information about one or more file fragments, which correspond to the first file page. Therefore, the first request can be considered as a request to read the first file page. The first file page can be one page or multiple pages. When the first file page is multiple pages, the multiple pages can be consecutive or non-consecutive.
[0138] For example, if an application wants to read pages 26-40, it can send a first request to the caching module, requesting to read pages 26-40. The caching module receives the first request, which may contain metadata information about the requested pages (such as the page number, identifier, address, etc.) and may also contain other information related to the requested pages. This caching module has a prefetch operation and can also be called a prefetch module.
[0139] The application can be any application capable of reading compressed files, such as office software, email clients, social software (e.g., SMS), multimedia players (e.g., music, photo albums), games, etc. This application can be an application on a Linux system or an application on other systems. When a user operates these applications on an electronic device, they may need to read relevant files, which may be compressed files. At this time, the application will trigger the action of sending the first request to read the compressed file.
[0140] Step S702: Obtain the first cluster where the first file page was compressed.
[0141] Specifically, since the first file page is compressed on a cluster-by-cluster basis, during reading, it's necessary to first identify which cluster(s) the first file page was categorized into during compression. All clusters containing the first file page are then identified; these clusters are collectively referred to as the first cluster. The first cluster can be a single cluster or multiple clusters. For example, assuming there are multiple first file pages, when the first cluster is a single cluster, it contains all the first file pages. When the first cluster consists of multiple clusters, each cluster contains a portion of the first file pages, and the pages within each cluster do not overlap. The sum of the pages in these multiple clusters contains all the aforementioned first file pages. After obtaining the first cluster, the multiple file pages contained within it are identified as the file pages that need to be cached.
[0142] Optionally, obtaining the first cluster where the first file page was compressed may include the following steps:
[0143] The specifications of the cluster when the first file page is compressed are obtained. The specifications of the cluster are the number of pages contained in each cluster, such as 8 pages, 16 pages, 32 pages, etc. The specifications of the cluster can be obtained by the caching module or by other means. Then, the first cluster is determined according to the metadata information of the first file page (such as one or more of the information such as location information, file identifier, file index, etc.) and the specifications of the cluster. For example, the cluster can be segmented and numbered according to the cluster specifications first, and then the sequence number of the first file page in the first cluster can be determined according to the index and segmentation of the first file page. Alternatively, the first cluster can be obtained by other means. The multiple file pages in the first cluster are the file pages that the caching module needs to cache and the file pages that the caching module needs to request to read.
[0144] For example, after the caching module receives the first request from the application to read pages 26-40, it recognizes that the cluster size of pages 26-40 during compression is 32. This means that during compression, every 32 pages are grouped into one cluster. That is, pages 0-31 are the first cluster, pages 32-63 are the second cluster, and so on. Then, combined with the index information of pages 26-40, it finds the corresponding first clusters, which are cluster0 and cluster1. Cluster0 contains pages 0-31, and cluster1 contains pages 32-63. The pages 0-63 contained in clusters 0 and 1 are the pages that the caching module needs to request.
[0145] Optionally, before obtaining the first cluster where the first file page was compressed, the process may further include: a caching module determining that the first file page is a file page of a compressed file. The operation of obtaining the first cluster where the first file page was compressed is only performed if the first file page is a file page of a compressed file; otherwise, the operation of obtaining the first cluster where the first file page was compressed is not performed.
[0146] Step S703: Decompress the multiple file pages contained in the first cluster from the first storage space.
[0147] Specifically, after determining the first cluster, it is necessary to request multiple file pages contained within the first cluster. Since the compressed file pages (cpages) corresponding to the first cluster are stored in the first storage space, it is necessary to request the compressed file pages (cpages) from the first storage space and decompress them to obtain the multiple file pages. These multiple file pages are the file pages that the caching module needs to cache. The decompression operation can be performed by the first storage space itself, or it can be sent by the first storage space to other modules for decompression. The subject and method of decompression are not limited here. The first storage space can be the local storage of the electronic device (e.g., a hard disk) or external storage (e.g., a Secure Digital (SD) card).
[0148] Optionally, decompressing multiple file pages contained in the first cluster from the first storage space may include:
[0149] Obtain the first address of the compressed file page (cpage) corresponding to the multiple file pages (page) contained in the first cluster. It can be understood that the first address can be mapped to a specific storage area of the first storage space; then obtain the compressed file page (cpage) from the first storage space according to the first address; decompress the compressed file page (cpage) to obtain the multiple file pages (page).
[0150] Specifically, the multiple file pages contained in the first cluster are stored in units of pages (e.g., 4K per page) before compression. After compression, the file size is reduced, but it is still stored in units of 4K. To distinguish the storage unit of pages before compression, the storage unit of the compressed file is called a cpage. The data storage location changes after compression, so it is necessary to obtain the address information (e.g., the first address) of the compressed file page (cpage) corresponding to the multiple file pages. Then, the compressed file page (cpage) is obtained from the first storage space according to the location information, and then decompressed to obtain the multiple file pages.
[0151] For example, after the caching module obtains the first cluster, it can send a third request to the file system to request multiple file pages contained in the first cluster. Upon receiving the third request, the file system obtains the address information of the compressed file page (cpage) corresponding to the file in the first cluster, and then sends a fourth request to the first storage space (e.g., a disk) to request the compressed file page (cpage). The fourth request includes the address information of the compressed file page (cpage). After receiving the fourth request, the first storage space returns the compressed file page (cpage) to the file system. The file system decompresses the obtained compressed file page (cpage) to obtain the multiple file pages. The file system can decompress the files using a compression / decompression algorithm, or through other methods. Alternatively, the files may be decompressed by another module (e.g., the first storage space) and then returned to the file system as decompressed files. Information transmission between modules can be actively obtained by sending request messages, passively received, or obtained through other methods; no specific limitations are made here.
[0152] For example, after the caching module determines that the first cluster corresponding to the first file page is cluster0 and cluster1, it sends a third request to the file system, requesting multiple file pages (also all pages, i.e., page0-page63) contained in cluster0 and cluster1. After receiving the third request, the file system identifies the compressed file pages (cpages) corresponding to the compressed files in cluster0 and cluster1 as cpage0-cpage8, obtains the address information of cpage0-cpage8, and sends a fourth request to the first storage space, requesting the corresponding compressed file pages (cpages). The fourth request contains the address information. After receiving the fourth request, the first storage space returns the cpages (cpage0-cpage8) corresponding to the address information to the file system. After receiving cpage0-cpage8, the file system decompresses it to obtain page0-page63.
[0153] Step S704: Copy the multiple decompressed file pages to the cache module.
[0154] Specifically, the multiple file pages mentioned are the file pages that the caching module needs to cache. Therefore, the file system copies all of these decompressed file pages to the caching module, rather than partially copying them, and there is no discarding of redundant file pages. Simply put, regardless of how many pages the file system receives, it returns all of them to the caching module. The pages that the caching module needs to cache are synchronized with the pages requested by the file system, and the pages actually cached by the caching module are also synchronized with the pages received by the file system. For example, if the file system obtains decompressed files pages0-63, it copies all of pages0-63 to the caching module.
[0155] Accordingly, the caching module receives the multiple file pages.
[0156] Step S705: Return the first file page from the cache module to the application.
[0157] Specifically, after the caching module receives multiple file pages, it includes the first file page. At this point, it can respond to the application's first request by returning the first file page to the application, thus ending the response to the application's first request.
[0158] For example, if the cache module contains pages 0-63 and the application requests pages 26-40, the cache module can directly return pages 26-40 to the application.
[0159] Optionally, after copying multiple file pages to the caching module, the following may also be included:
[0160] The application sends a second request to the caching module, which requests a second file page. When the second file page is in the caching module, the caching module directly returns the second file page to the application.
[0161] For example, the file system copies pages 0-63 to the cache module. Then, the application sends a second request to the cache module to read page 48. At this time, page 48 already exists in the cache module, so the cache module can directly respond to the second request and return page 48 to the application, thus ending the application's second request response.
[0162] Please see Figure 8 , Figure 8 A flowchart illustrating a specific implementation of a method for reading compressed files according to an embodiment of this application is provided. Combined with the above detailed description, the interactive operations between the various modules that may be involved in this method are shown.
[0163] exist Figure 7 or Figure 8 In the described method, without affecting the original caching strategy, the number of file pages that the caching module needs to cache each time is cached according to cluster alignment. The file system returns all the decompressed file pages to the caching module. Therefore, when the application requests to read other file pages later, those other file pages are likely already cached in the caching module, and the caching module does not need to request the file page from the file system again. This reduces the number of times the first storage space is read and the number of decompressions, and improves the efficiency of reading compressed files.
[0164] To more clearly and intuitively demonstrate the improvements and beneficial effects of the method for reading compressed files proposed in the embodiments of this application, please refer to [link to relevant documentation]. Figure 9 , Figure 9 An example of sequentially reading 128 pages of a 4K file is given, and the reading performance is compared using existing technologies and the method in the embodiments of this application.
[0165] The process of reading compressed files using existing technology is as follows:
[0166] 1. The application reads page0, and the prefetch module reads pages0-3. Assuming the cluster size is 32 pages during compression, pages0-31 are read from the file. After pages0-31 are read, pages4-31 are discarded. The contents of pages0-3 are copied to the cache, and then page0 is returned to the application.
[0167] 2. When the application reads pages1-page3, it directly retrieves pages1-page3 from the cache and returns them to the application.
[0168] 3. The application reads page 4, the prefetch module reads pages 4-19, and reads pages 0-31 from the file; after pages 0-31 are read, pages 0-3 and pages 20-31 are discarded, the contents of pages 4-19 are copied to the cache, and page 4 is returned to the application.
[0169] 4. When the application reads pages 5-19, it directly retrieves pages 1-3 from the cache and returns them to the application.
[0170] 5. When the application reads page 20, the prefetch module reads pages 20-51 and pages 0-63 in the file. After pages 0-63 are read, pages 0-19 and pages 52-63 are discarded. The contents of pages 20-51 are copied to the cache, and then page 20 is returned to the application.
[0171] 6. When the application reads page 52, the prefetch module reads pages 52-116 and pages 32-127 from the file. After pages 32-127 are read, pages 32-52 and pages 117-127 are discarded. The contents of pages 52-116 are copied to the cache, and then page 52 is returned to the application.
[0172] 7. Similarly, when the application reads page64, it directly retrieves page64 from the cache and returns it to the application.
[0173] The process of reading compressed files using the method proposed in this application embodiment is as follows:
[0174] 1. The application reads page0. The prefetch module recognizes page0 as a page in a compressed file and obtains the cluster size of this compressed file (assuming it's 32 pages). The prefetch module reads pages0-31 from the file, copies the contents of pages0-31 to the cache, and returns page0 to the application.
[0175] 2. Whenever the application reads a file from page 1 to page 31 (e.g., page 4 or page 20), it directly retrieves the file from the cache and returns it to the application.
[0176] 3. The application reads page 52. The prefetch module recognizes page 52 as a compressed file and obtains the cluster size of this compressed file. The prefetch module then reads pages 32-63, copies the contents of pages 32-63 to the cache, and returns page 52 to the application.
[0177] 4. The application reads page 64, the prefetch module reads pages 64-127, the contents of pages 64-127 are copied to the cache, and page 64 is returned to the application.
[0178] 5. Similarly, whenever the application reads a file from page 65 to page 127, it can directly find the file in the cache module and return it to the application.
[0179] Comparing the two solutions above, it can be concluded that by using the method in this embodiment to read compressed files, the number of reads and decompressions in cluster0 is reduced by 2, and the number of reads and decompressions in cluster1 is reduced by 1, effectively reducing the number of decompressions and improving the efficiency of reading compressed files.
[0180] Actual test results show that, compared with the prior art, the method proposed in this application reduces the number of decompression operations by 723 when reading a 378M compressed file sequentially at a file size of 4K, and improves the sequential read speed by 25%; when reading a 4K file size randomly, the number of decompression operations is reduced by 51,890, and the random read speed is improved by 963% (part of the benefit comes from cache hits).
[0181] It is worth noting that the specific values mentioned in the embodiments of this application are obtained by testing specific electronic devices under specific conditions based on specific hardware and software. They are only examples and not limitations. The result values may be different when testing other files using other electronic devices.
[0182] The methods of the embodiments of this application have been described in detail above, and the apparatus of the embodiments of this application is provided below.
[0183] Please see Figure 10 , Figure 10 This is a schematic diagram of the structure of a device 100 for reading compressed files according to an embodiment of this application. The device may include a receiving unit 1001, an acquiring unit 1002, a decompression unit 1003, a copying unit 1004, and a sending unit 1005. The detailed description of each unit is as follows.
[0184] The receiving unit 1001 is configured to receive a first request sent by the application, wherein the first request is for requesting to read a first file page.
[0185] The acquisition unit 1002 is used to acquire the first cluster where the first file page is compressed;
[0186] The decompression unit 1003 is used to decompress multiple file pages contained in the first cluster from the first storage space;
[0187] The copying unit 1004 is used to copy multiple decompressed file pages to the cache module;
[0188] The sending unit 1005 is used to return the first file page in the cache module to the application.
[0189] Optionally, one possible implementation of the acquisition unit 1002 when acquiring the first cluster where the first file page is compressed is as follows:
[0190] The acquisition unit 1002 can acquire the cluster specifications when the first file page is compressed; then, based on the metadata information of the first file page (such as one or more of the information such as location information, file identifier, file index, etc.) and the cluster specifications, it can acquire the first cluster.
[0191] Optionally, one possible implementation of the decompression unit 1003 decompressing multiple file pages contained in the first cluster from the first storage space is as follows:
[0192] First, the first address of the compressed file page (cpage) corresponding to the multiple file pages (page) contained in the first cluster is obtained. Then, the compressed file page (cpage) is obtained from the first storage space according to the first address. Then, the decompression unit 1003 decompresses the compressed file page (cpage) to obtain the multiple file pages (page).
[0193] Optionally, the device may also include:
[0194] The first determining unit is configured to determine that the first file page is a file page of a compressed file. This first determining unit can be configured to perform the operation of obtaining the first cluster where the first file page was compressed only after determining that the first file page is a file page of a compressed file, following a first request sent by the application and before obtaining the first cluster where the first file page was compressed.
[0195] Optionally, the device further includes a second determining unit:
[0196] The receiving unit 1001 is also configured to receive a second request sent by the application, the second request being for requesting to read a second file page, and the timing of receiving the second request occurs after receiving the first request;
[0197] The second determining unit is used to determine the second file page in the caching module. This second determining unit can be used after receiving a second request sent by the application.
[0198] The sending unit 1005 is also used to return a second file page from the cache module to the application.
[0199] Optionally, the device may also include:
[0200] The third determining unit is used to determine that the multiple file pages contained in the first cluster are the file pages that the caching module needs to cache. The third determining unit can be used after obtaining the first cluster where the first file page was compressed and before decompressing the multiple file pages contained in the first cluster from the first storage space.
[0201] It should be noted that the implementation of each unit can be referred to accordingly. Figure 7 or Figure 8 The corresponding descriptions of the method embodiments shown will not be repeated here.
[0202] It should be understood that the steps in the above-described method embodiments provided in this application can be implemented by integrated logic circuits in the processor hardware or by instructions in software form. The method steps disclosed in the embodiments of this application can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.
[0203] This application also provides an electronic device that may include a memory and a processor. The memory may be used to store a computer program; the processor may be used to invoke the computer program in the memory to cause the electronic device to perform all or part of the steps in any of the above method embodiments (e.g., when multiple devices or modules interact, executing the steps corresponding to one of the devices or the predicted module). Optionally, one possible implementation of the memory and processor is as described above in the electronic device.
[0204] This application also provides a chip system including at least one processor for implementing the functions involved in the methods performed by the electronic device in any of the above embodiments.
[0205] In one possible design, the chip system also includes a memory for storing program instructions and data, which may be located within or outside the processor.
[0206] The chip system can consist of chips or include chips and other discrete components.
[0207] Optionally, the chip system may contain one or more processors. These processors can be implemented in hardware or software. When implemented in hardware, the processor can be a logic circuit, an integrated circuit, etc. When implemented in software, the processor can be a general-purpose processor, implemented by reading software code stored in memory.
[0208] Optionally, the chip system may contain one or more memories. The memory may be integrated with the processor or disposed separately from it; this application embodiment does not limit this. For example, the memory may be a non-transient processor, such as a read-only memory (ROM), which may be integrated with the processor on the same chip or disposed separately on different chips. This application embodiment does not specifically limit the type of memory or the arrangement of the memory and processor.
[0209] For example, the chip system may be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processor (DSP), a micro controller unit (MCU), a programmable logic device (PLD), or other integrated chips.
[0210] This application also provides a computer program product comprising: a computer program (also referred to as code or instructions) that, when run, causes a computer to perform the method executed by the electronic device in any of the above embodiments.
[0211] This application also provides a computer-readable storage medium storing a computer program (also referred to as code or instructions). When the computer program is run, it causes the computer to perform the method executed by the electronic device in any of the above embodiments.
[0212] The various embodiments of this application can be combined arbitrarily to achieve different technical effects.
[0213] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive).
[0214] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
[0215] In summary, the above description is merely an embodiment of the technical solution of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made based on the disclosure of this application should be included within the scope of protection of this application.
Claims
1. A method for reading compressed files, characterized in that, include: Receive a first request sent by the application, wherein the first request is for requesting to read a first file page. Obtain the first cluster where the first file page was compressed; Decompress the multiple file pages contained in the first cluster from the first storage space; Copy the multiple file pages obtained from decompression to the cache module; Return the first file page from the cache module to the application.
2. The method according to claim 1, characterized in that, The step of obtaining the first cluster where the first file page is compressed includes: Obtain the cluster specifications when the first file page is compressed; The first cluster is determined based on the metadata information of the first file page and the specifications of the cluster, wherein the metadata information of the first file page includes one or more of the following: location information, file identifier, and file index information.
3. The method according to claim 1 or 2, characterized in that, The step of decompressing the multiple file pages contained in the first cluster from the first storage space includes: Obtain the first address of the compressed file page cpage corresponding to the multiple file pages contained in the first cluster; The compressed file page cpage is retrieved from the first storage space based on the first address; Decompress the compressed file page cpage to obtain the multiple file pages page.
4. The method according to any one of claims 1-3, characterized in that, After receiving the first request from the application and before obtaining the first cluster where the first file page is compressed, the method further includes: The first file page is determined to be a file page of the compressed file.
5. The method according to any one of claims 1-4, characterized in that, After obtaining the first cluster where the first file page was compressed, and before decompressing the multiple file pages contained in the first cluster from the first storage space, the method further includes: The multiple file pages contained in the first cluster are identified as the file pages that the caching module needs to cache.
6. The method according to any one of claims 1-5, characterized in that, The files other than the first file page located in the cache module are pre-read file pages.
7. The method according to any one of claims 1-6, characterized in that, After copying the multiple decompressed file pages to the cache module, the process also includes: Receive a second request sent by the application, the second request being used to request the reading of a second file page; Determine that the second file page is in the cache module; Return the second file page from the cache module to the application.
8. The method according to any one of claims 1-7, characterized in that, The method is applied to the Linux system.
9. A device for reading compressed files, characterized in that, include: A receiving unit is configured to receive a first request sent by an application, wherein the first request is for requesting to read a first file page. The acquisition unit is used to acquire the first cluster where the first file page is compressed; A decompression unit is used to decompress multiple file pages contained in the first cluster from the first storage space; The copy unit is used to copy multiple decompressed file pages to the cache module; A sending unit is used to return the first file page from the cache module to the application.
10. An electronic device, characterized in that, The electronic device includes: one or more processors; a memory; wherein the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code including computer instructions, and the one or more processors call the computer instructions to cause the electronic device to perform the method as described in any one of claims 1-8.
11. A chip system, characterized in that, The chip system is applied to an electronic device, the chip system including one or more processors, the processors being configured to invoke computer instructions to cause the electronic device to perform the method as described in any one of claims 1-8.
12. A computer program product containing instructions, characterized in that, When the computer program product is run on a processor, it implements the method as described in any one of claims 1-8.
13. A computer-readable storage medium comprising instructions, characterized in that, When the instructions are executed on the processor, they implement the method as described in any one of claims 1-8.