Data compression method and device, electronic equipment and storage medium
Through the dual compression method combining hardware and software, the compression processing is dynamically adjusted, which solves the problem of inflexible selection of compression algorithms in the existing technology and improves the efficiency of data compression and storage space utilization.
Patent Information
- Application Number
- CN202310394068.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-12
- Publication Date
- 2024-10-18
AI Technical Summary
Existing data compression technology lacks flexibility in the selection of compression algorithms, and it is difficult to dynamically adjust the compression rate according to the specific needs of the data, resulting in low storage space utilization efficiency.
Using a method that combines hardware and software compression methods, the data is first processed through hardware compression. If the compression rate does not meet the preset value, secondary processing is performed through software compression, and the compression method is dynamically adjusted to improve flexibility.
It improves the flexibility and efficiency of data compression, can better adapt to the storage needs of different data, and improves the utilization of storage space.
Smart Images

Figure CN118796086A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of data processing technology, and specifically relates to a data compression method, device, electronic equipment and storage medium. Background Art
[0002] With the rapid development of society, the amount of data generated has increased exponentially, and the amount of data that needs to be stored has also increased. The information industry has put forward higher requirements on the capacity of storage devices. The expansion of the capacity of the storage system will increase the cost of the equipment. In order to store more data in a limited storage space, the compression technology of the storage system has emerged. The flexibility of the related data compression methods when compressing data needs to be improved. Summary of the invention
[0003] In view of the above problems, the present application proposes a data compression method, device, electronic device and storage medium to improve the above problems.
[0004] In a first aspect, an embodiment of the present application provides a data compression method, the method comprising: obtaining data to be processed; performing a first compression process on the data to be processed to obtain first compressed data, wherein the first compression process represents compression processing of the data to be processed by a hardware-based compression method; if the compression rate of the first compressed data does not meet a preset compression rate, performing a second compression process on the first compressed data to obtain target compressed data, wherein the second compression process represents compression processing of the data to be processed by a software-based compression method.
[0005] In a second aspect, an embodiment of the present application provides a data compression device, which includes: a data acquisition unit, used to acquire data to be processed; a first processing unit, used to perform a first compression process on the data to be processed to obtain first compressed data, wherein the first compression process represents compression processing of the data to be processed by a hardware-based compression method; a second processing unit, used to perform a second compression process on the first compressed data to obtain target compressed data if the compression rate of the first compressed data does not meet a preset compression rate, wherein the second compression process represents compression processing of the data to be processed by a software-based compression method.
[0006] In a third aspect, an embodiment of the present application provides an electronic device, comprising one or more processors and a memory; one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the above-mentioned method.
[0007] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a program code is stored, wherein the above method is executed when the program code is run.
[0008] The embodiments of the present application provide a data compression method, device, electronic device and storage medium. Obtain data to be processed, perform a first compression process on the data to be processed, and obtain first compressed data. The first compression process represents that the data to be processed is compressed by a hardware-based compression method. When the compression rate of the first compressed data does not meet the preset compression rate, the first compressed data is compressed by a software-based compression method to obtain target compressed data. The second compression process represents that the data to be processed is compressed by a software-based compression method. Through the above method, two compression processing methods are used to compress the data to be processed, and the compression processing method is adjusted according to the compression rate of the data to be processed, thereby improving the flexibility when performing data compression. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0010] Figure 1 A schematic diagram of an application scenario of a data compression method proposed in an embodiment of the present application is shown;
[0011] Figure 2 A schematic diagram of an application scenario of a data compression method proposed in an embodiment of the present application is shown;
[0012] Figure 3 A flow chart of a data compression method proposed in an embodiment of the present application is shown;
[0013] Figure 4 A flow chart of a data compression method proposed in another embodiment of the present application is shown;
[0014] Figure 5 A structural block diagram of a data compression device proposed in an embodiment of the present application is shown;
[0015] Figure 6 A structural block diagram of an electronic device or a server for executing a data compression method according to an embodiment of the present application is shown;
[0016] Figure 7A storage unit in an embodiment of the present application is shown for storing or carrying program code for implementing a data compression method according to an embodiment of the present application. DETAILED DESCRIPTION
[0017] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0018] With the development of science and technology and the continuous improvement of people's living standards, in order to further improve data processing capabilities and data storage capabilities, data compression technology is widely used in computer systems. In related methods, data can be compressed according to a certain compression algorithm and stored in a compressed memory through a memory compression method. The system finds the compressed data from the compressed memory and decompresses it for use by the system.
[0019] The inventors found in their research on related data compression methods that when compressing data according to a certain compression algorithm, either a hardware-based compression algorithm or a software-based compression algorithm is used to compress the data, and the flexibility needs to be improved.
[0020] Therefore, the inventors proposed the data compression method, device, electronic device and storage medium in the present application. Obtain the data to be processed, perform a first compression process on the data to be processed, and obtain first compressed data. The first compression process represents that the data to be processed is compressed by a hardware-based compression method. When the compression rate of the first compressed data does not meet the preset compression rate, the first compressed data is compressed by a software-based compression method to obtain target compressed data. The second compression process represents that the data to be processed is compressed by a software-based compression method. Through the above method, two compression processing methods are used to compress the data to be processed, and the compression processing method is adjusted according to the compression rate of the data to be processed, thereby improving the flexibility when performing data compression.
[0021] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.
[0022] In the embodiment of the present application, the data compression method provided can be executed by an electronic device. In this way, all steps in the data compression method provided by the embodiment of the present application can be executed by the electronic device. For example, Figure 1As shown, the processor of the electronic device 100 executes to obtain the data to be processed; the first compression processing is performed on the data to be processed to obtain first compressed data, and the first compression processing represents that the data to be processed is compressed by a hardware-based compression method; if the compression rate of the first compressed data does not meet the preset compression rate, the first compressed data is subjected to a second compression processing to obtain target compressed data, and the second compression processing represents that the data to be processed is compressed by a software-based compression method.
[0023] Furthermore, the data compression method provided in the embodiment of the present application can also be executed by a server (cloud). Correspondingly, in this method executed by the server, the server can execute the acquisition of data to be processed; the first compression processing is performed on the data to be processed to obtain first compressed data, and the first compression processing represents the compression processing of the data to be processed by a hardware-based compression method; if the compression rate of the first compressed data does not meet the preset compression rate, the first compressed data is subjected to a second compression processing to obtain target compressed data, and the second compression processing represents the compression processing of the data to be processed by a software-based compression method.
[0024] In addition, the electronic device and the server may also perform the steps in collaboration. In this mode, some steps of the data compression method provided by the embodiment of the present application are performed by the electronic device, while other steps are performed by the server.
[0025] For example, Figure 2 As shown, the electronic device 100 can execute a data compression method including: obtaining data to be processed, and then having the server 200 perform a first compression process on the data to be processed to obtain first compressed data, wherein the first compression process represents compression processing of the data to be processed by a hardware-based compression method; if the compression rate of the first compressed data does not meet the preset compression rate, performing a second compression process on the first compressed data to obtain target compressed data, wherein the second compression process represents compression processing of the data to be processed by a software-based compression method.
[0026] It should be noted that in this method of collaborative execution by the electronic device and the server, the steps respectively executed by the electronic device and the server are not limited to the methods introduced in the above examples. In actual applications, the steps respectively executed by the electronic device and the server can be dynamically adjusted according to actual conditions.
[0027] It should be noted that the electronic device 100 can be Figure 1 and Figure 2In addition to the smartphone shown in the figure, it can also be a car device, a wearable device, a tablet computer, a laptop computer, a smart speaker, etc. The server 120 can be an independent physical server, or a server cluster or a distributed system composed of multiple physical servers.
[0028] See also Figure 3 , a data compression method provided in an embodiment of the present application is applied to Figure 1 or Figure 2 The electronic device or server shown, the method comprising:
[0029] Step S110: Obtain data to be processed.
[0030] In the embodiment of the present application, the data to be processed may be data that is determined to be compressed. The data to be processed may be data that needs to be written into a memory. The data to be processed may be data generated by a processor when executing a program, data received by interacting with other devices or processes, or data exchanged between multiple memories.
[0031] As a way, the data to be processed can be the data written into the memory for the first time. Memory (also known as random access memory, RAM) refers to the memory used when running a program (i.e., running memory). It can only temporarily store data and is used to exchange cache data with the processor, but the memory itself cannot be used to store data for a long time. When the application is running, it needs to occupy memory space to store data during the running process. The size of the memory space occupied by different applications in different running states may not be the same.
[0032] The data written into the memory for the first time may be hot data in the time series data, which refers to time series data. Time series data is a data column recorded in chronological order according to a unified indicator, and the time series data may include time information, data type, and data information. The time information may specifically be a timestamp; the data type may be a known data type or a data type that may appear in the future, such as existing data types that may include Integer, Long, Float, Double, String, Binary Array, Image, etc.; the data information may be the data itself, that is, the original data that does not contain descriptions such as time information and data type.
[0033] Since time series data has a massive nature, it is impossible to store all the data in the memory of an electronic device. In order to solve this problem, in the embodiment of the present application, the data in the current time is placed in the memory as hot data, and then when the hot data exceeds the specified time, the electronic device will compress it and finally persist it as cold data. Among them, hot data can be frequently accessed data, which is usually stored in a cache storage device, and cold data refers to data with low access frequency and low access performance requirements, such as data that will not be accessed in the short term or even no longer needed in the future.
[0034] As another method, the data to be processed may be a determined allocated memory. When performing memory compression processing on the allocated memory, a portion of the allocated memory may be selected from all the allocated memory, and then the portion of the allocated memory may be firstly subjected to memory compression processing by a hardware-based compression algorithm. The size of the portion of the allocated memory may be determined according to a preset compression amount. The preset compression amount is a preset size of the allocated memory that needs to be subjected to memory compression.
[0035] Optionally, in an embodiment of the present application, when the kernel allocates memory to a process, it is known how much memory each process needs, and then when allocating memory to the corresponding process, it can record how much memory is allocated to each process. Therefore, when the allocated memory is compressed according to the preset compression amount, part of the allocated memory can be selected from all the allocated memory for memory compression according to the size of the memory corresponding to each process and the preset compression amount. Exemplarily, if the preset compression amount is 10MB, and the size of the memory corresponding to process 1 is 2MB, the size of the memory corresponding to process 2 is 5MB, the size of the memory corresponding to process 3 is 8MB, and the size of the memory corresponding to process 4 is 3MB, then when part of the allocated memory is selected from all the allocated memory for memory compression according to the size of the memory corresponding to each process and the preset compression amount, memory compression can be selected for the memory corresponding to process 1, process 2 and process 4; or memory compression can be selected for the memory corresponding to process 1 and process 3.
[0036] Optionally, in the embodiment of the present application, the data to be processed in the memory may be obtained at set intervals. Alternatively, the operation of obtaining the data to be processed currently stored in the memory may be performed according to a trigger instruction input by the user.
[0037] Step S120: performing a first compression process on the data to be processed to obtain first compressed data, wherein the first compression process represents compressing the data to be processed in a hardware-based compression manner.
[0038] In the embodiment of the present application, the first compression process refers to memory compression processing of the data to be processed by a hardware-based compression method. Among them, the memory compression process refers to compressing the allocated memory according to a certain algorithm and storing it in the memory compression space to release a part of the space occupied by these allocated memories. For example, the target memory page is compressed, and the compressed memory page is written to the memory compression space in the memory space to release a part of the memory space occupied by these target memory pages.
[0039] When the system needs to use compressed data, it can find the compressed data from the memory compression space and decompress it for use by the system.
[0040] As a method, if the data to be processed is a selected part of the allocated memory. When performing memory compression processing on the selected part of the allocated memory, the part of the allocated memory can be first compressed with different compression ratios using a hardware-based compression method. Among them, the compression ratio can be determined by the ratio of the current free memory to the preset compression amount. The larger the current free memory, the larger the corresponding compression ratio; the smaller the current free memory, the smaller the corresponding compression ratio. The compression ratio represents the degree of compression of the allocated memory. The larger the compression ratio, the greater the degree of compression of the allocated memory; the smaller the compression ratio, the smaller the compression ratio.
[0041] In the embodiment of the present application, the hardware-based compression method can be understood as a compression algorithm based on running in a hardware compression module, that is, a hardware module is used to compress the data to be processed. Among them, the compression algorithm running in the hardware compression module may include but is not limited to the LZ77 algorithm, the LZSS algorithm, and the deflater algorithm, etc., which are not specifically limited here. The compression speed of the data compression algorithm based on hardware implementation is very fast, but due to the limitation of hardware implementation, the compression rate is usually low.
[0042] It is known that the LZ77 algorithm is a dictionary-based algorithm that encodes long strings (also called phrases) into short tokens and replaces the phrases in the dictionary with small tokens to achieve the purpose of compression. In other words, it compresses data by replacing long strings that appear repeatedly in the data with small tokens. The symbols it processes are not necessarily text characters, but can be symbols of any size.
[0043] The LZSS algorithm is a lossless data compression algorithm. The core of the compression algorithm is to replace the repeated part with the string that has already appeared. The output of the encoder is just a pointer to the string that appeared earlier. The LZSS algorithm is improved from the LZ77 algorithm, also known as "sliding window compression". This algorithm uses a virtual window that can slide with the compression process as a dictionary. If the string to be compressed appears in the window, its position and length are output. If it does not appear, the character is output as it is.
[0044] The deflater algorithm is a lossless data compression algorithm that uses both the LZ77 algorithm and Huffman Coding. The source code for deflater compression and decompression can be found in the free, general-purpose compression library zlib.
[0045] Optionally, in an embodiment of the present application, the first compressed data is compressed data obtained by compressing the data to be processed by a hardware-based compression method. When the data to be processed is subjected to the first compression processing by a hardware-based compression method, the compression operation of a preset time length can be performed on the data to be processed. After the preset time length, it can be determined whether the first compressed data needs to be compressed again based on the data volume of the compressed first compressed data. Among them, the preset time lengths corresponding to different hardware-based compression methods may be different. Specifically, the preset time length corresponding to the hardware-based compression method may be determined based on the data volume of the data to be processed; or, the preset time length corresponding to the hardware-based compression method may also be determined based on the compression speed of the compression method itself; or, the preset time length corresponding to the hardware-based compression method may also be determined based on the compression rate of the compression method itself. Among them, the compression rate may also be called the compression ratio, which characterizes the degree of compression of the data to be processed.
[0046] Among them, when the preset duration corresponding to the hardware-based compression method can be determined based on the data amount of the data to be processed, the larger the data amount of the data to be processed, the longer the corresponding preset duration can be set; conversely, the smaller the data amount of the data to be processed, the shorter the corresponding preset duration can be set.
[0047] When the preset duration corresponding to the hardware-based compression method can also be determined based on the compression speed of the compression method itself, the faster the compression speed of the compression method itself, the shorter the corresponding preset duration can be set; conversely, the shorter the compression speed of the compression method itself, the longer the corresponding preset duration can be set.
[0048] When the preset duration corresponding to the hardware-based compression method can also be determined based on the compression rate of the compression method itself, the higher the compression rate of the compression method itself, the shorter the corresponding preset duration can be set; conversely, the lower the compression rate of the compression method itself, the longer the corresponding preset duration can be set.
[0049] Optionally, the preset duration corresponding to the hardware-based compression method can also be determined based on at least two of the compression speed, compression ratio of the compression method itself, and the data volume of the data to be processed. Specifically, the preset duration can also be determined based on at least two of the compression speed, compression ratio of the compression method itself, and the data volume of the data to be processed, which can include that the preset duration can be determined based on the compression speed and compression ratio of the compression method itself; or, the preset duration can be determined based on the compression speed of the compression method itself and the data volume of the data to be processed; or, the preset duration can be determined based on the compression ratio of the compression method itself and the data volume of the data to be processed; or, the preset duration can be determined based on the compression speed, compression ratio of the compression method itself, and the data volume of the data to be processed.
[0050] When the preset duration can be determined based on the compression speed and compression rate of the compression method itself, the length of the preset duration is positively correlated with the compression speed and compression rate of the compression method itself.
[0051] When the preset time length can be determined based on the compression speed of the compression method itself and the data volume of the data to be processed, the length of the preset time length is negatively correlated with the compression speed of the compression method itself, and positively correlated with the data volume of the data to be processed.
[0052] Similarly, when the preset time length can be determined based on the compression rate of the compression method itself and the data volume of the data to be processed, the length of the preset time length is negatively correlated with the compression rate of the compression method itself and positively correlated with the data volume of the data to be processed.
[0053] When the data to be processed is compressed by the hardware-based compression method, timing starts. When the timing reaches a preset time, the compression of the data to be processed by the hardware-based compression method is stopped to obtain first compressed data.
[0054] Optionally, in an embodiment of the present application, the first compression processing of the data to be processed is triggered based on a hardware compression instruction.
[0055] Step S130: If the compression rate of the first compressed data does not meet the preset compression rate, a second compression process is performed on the first compressed data to obtain target compressed data, wherein the second compression process represents compressing the data to be processed by a software-based compression method.
[0056] In the embodiment of the present application, the preset compression rate is the preset ideal compression degree corresponding to the data to be processed. The second compression process refers to performing secondary compression process on the data to be processed by a software-based compression method, that is, compressing the first compressed data by a software-based compression method.
[0057] Among them, the software-based compression method refers to a compression algorithm based on running in the CPU, which is equivalent to being based on a certain algorithm software. The software-based data compression algorithm may include but is not limited to the LZ4 algorithm, the Zstandard (ZSTD) algorithm, the Snappy algorithm, etc., which are not specifically limited here. The data compression algorithm implemented based on software usually has a higher compression rate, but the corresponding compression speed is slower.
[0058] It can be known that the LZ4 algorithm is a lossless data compression algorithm that focuses on compression and decompression speed.
[0059] The Zstandard (ZSTD) algorithm is a fast lossless compression algorithm open sourced by Facebook, targeting real-time compression scenarios and better compression ratios at the zlib level. It provides a very wide range of compression / speed tradeoffs while supporting very fast decoders. It also provides a special mode for small data, called dictionary compression, and can create a dictionary from any sample set.
[0060] Snappy (formerly Zippy) is a fast data compression and decompression library written in C++ by Google based on the LZ77 algorithm and open sourced in 2011. Its goal is not maximum compression rate or compatibility with other compression libraries, but very high speed and reasonable compression rate.
[0061] In an embodiment of the present application, the compression ratio corresponding to the first compression processing method is less than or equal to the compression ratio corresponding to the second compression processing method; the compression speed corresponding to the first compression processing method is greater than the compression speed corresponding to the second compression processing method.
[0062] As a method, a compression ratio corresponding to the first compressed data is obtained; if the compression ratio of the first compressed data does not meet the preset compression ratio, a second compression process is performed on the first compressed data.
[0063] The compression ratio of the first compressed data may be determined based on the data volume of the first compressed data and the data volume of the data to be processed, that is, the compression ratio of the first compressed data=the data volume of the first compressed data / the data volume of the data to be processed.
[0064] When the data to be processed is first compressed and the first compressed data is obtained, the data volume of the first compressed data can be obtained in real time. The data volume of the data to be processed can be obtained when the data to be processed is obtained, or can be obtained before the data to be processed is compressed, which is not specifically limited here.
[0065] When the data volume of the data to be processed and the data volume of the first compressed data are obtained, the compression rate of the first compressed data can be calculated in real time. After the compression rate of the first compressed data is calculated, the compression rate of the first compressed data is compared with the preset compression rate to determine whether the compression rate of the first compressed data meets the preset compression rate.
[0066] If the compression ratio of the first compressed data meets the preset compression ratio, the data to be processed will no longer be compressed; if the compression ratio of the first compressed data does not meet the preset compression ratio, the data to be processed will be compressed twice using a software-based compression method.
[0067] Similarly, when the software-based compression method is used to perform secondary compression on the data to be processed, the compression time can also be limited. When the preset time is reached, the compression of the data to be processed is stopped. The setting method of the preset time is the same as the above method and will not be repeated here.
[0068] When determining whether the compression rate of the first compressed data meets the preset compression rate, if the compression rate of the first compressed data is greater than or equal to the preset compression rate, it can be determined that the compression rate of the first compressed data meets the preset compression rate; conversely, if the compression rate of the first compressed data is less than the preset compression rate, it can be determined that the compression rate of the first compressed data does not meet the preset compression rate.
[0069] Optionally, in the process of performing a first compression processing on the processed data through a hardware-based compression method, the compression rate of the first compressed data can be obtained in real time. If at a certain moment before the preset time length is reached, the compression processing of the processed data can be stopped at that moment; conversely, if before the preset time length is reached, the compression rate of the first compressed data does not meet the preset compression rate, the compression processing of the processed data continues until the preset time length ends.
[0070] After the preset time period ends, if the compression rate of the first compressed data has not yet met the preset compression rate, the first compressed data is compressed by a software-based compression method within another preset time period. Similarly, within another preset time period, the compression rate corresponding to the data during the compression process can also be obtained in an embodiment. If the compression rate corresponding to the data meets the preset compression rate at a certain moment before the preset time period is reached, the data is stopped from being compressed at that moment to obtain the target compressed data; otherwise, the data is continued to be compressed until the preset time period is reached, and the compressed data obtained at the preset time period is used as the target compressed data.
[0071] Optionally, in the embodiment of the present application, a total preset duration may be set for the first compression process and the second compression process, and within the preset duration, the processing durations of the first compression process and the second compression process may be dynamically adjusted. Specifically, when adjusting the processing durations of the first compression process and the second compression process, the compression rate of the compressed data may be obtained in real time during the compression process of the data to be processed, so that the processing durations of the first compression process and the second compression process may be adjusted in real time according to the compression rate.
[0072] Specifically, the process described in step S110-step S130 can be: in response to the hardware compression instruction, the system can first transmit the data to be processed to the hardware compression module for compression processing to obtain first compressed data. If the compression rate of the first compressed data does not meet the preset compression rate, the first compressed data is transmitted to the software-based compression module for re-compression.
[0073] In an embodiment of the present application, the data to be processed is first compressed using a hardware-based compression method, which can quickly compress the data to be processed, thereby improving the compression performance of the computer system, and at the same time reducing the time and computing resources required for compression, thereby improving the efficiency of the computer system and reducing the energy consumption of the computer system.
[0074] Furthermore, in the process of quickly compressing the data to be processed through a hardware-based compression method, the compression rate of the compressed data during the compression process can be used in real time to dynamically adjust the compression method to a software-based compression method to continue compressing the compressed data, thereby further improving the compression efficiency.
[0075] The present application provides a data compression method, which obtains data to be processed, performs a first compression process on the data to be processed, and obtains first compressed data. The first compression process represents that the data to be processed is compressed by a hardware-based compression method. When the compression rate of the first compressed data does not meet the preset compression rate, the first compressed data is compressed by a second compression process to obtain target compressed data. The second compression process represents that the data to be processed is compressed by a software-based compression method. Through the above method, two compression processing methods are used to compress the data to be processed, and the compression processing method is adjusted according to the compression rate of the data to be processed, thereby improving the flexibility of data compression.
[0076] See also Figure 4 , a data compression method provided in an embodiment of the present application is applied to Figure 1 or Figure 2 The electronic device or server shown, the method comprising:
[0077] Step S210: Acquire multiple memory pages corresponding to the currently running application program.
[0078] In an embodiment of the present application, the obtaining of multiple memory pages corresponding to the currently running application includes: in response to a memory compression instruction, obtaining multiple memory pages corresponding to the currently running application. The memory compression instruction is used to instruct to compress the memory pages stored in the memory through a software-based compression method or a hardware-based compression method to release more memory.
[0079] In the embodiment of the present application, the memory compression instruction can be triggered in a variety of ways.
[0080] As one of the ways, the memory compression instruction can be triggered when it is detected that the current free memory is lower than the preset memory. Among them, the preset memory is a pre-set memory size that indicates insufficient free memory, and the preset memory is a memory threshold that is greater than the memory waterline. In an embodiment of the present application, whenever an application is started, or a new page is generated and needs to be stored in the memory, it triggers the acquisition of the current free memory once. If the current free memory is lower than the preset memory, it indicates that the current memory is insufficient, and the pages already stored in the memory need to be compressed to make room for the new page. Among them, the new page can be generated for the application that has just been started, or it can be generated for other already running applications, which is not specifically limited here.
[0081] It is understandable that the operation of the electronic device's system and application processes requires the system kernel to allocate memory space for them. And as the system runs, the kernel continuously recycles and allocates memory. For example, the kernel can monitor the usage of memory space in real time and detect whether the remaining free memory space is less than the preset memory.
[0082] Generally, the system kernel sets a memory watermark when performing memory management. When the system allocates memory pages, it detects whether the remaining free memory space of the system is less than the memory watermark. If it is less than the memory watermark, memory recovery is required. However, generally, when it is detected that the remaining free memory space of the system is less than the memory watermark, the system is already in a low memory state. Furthermore, memory compression operations are generally time-consuming. If the system is already in a low memory state before memory compression is performed, the system will be in a low memory state for a long time, and memory recovery cannot be completed in time, resulting in low memory recovery efficiency, affecting the normal operation of the system and applications.
[0083] In order to avoid the situation where the system is in a low memory state for a long time, the solution of the embodiment of the present application will compress the memory in advance, so the preset memory is a value greater than the memory waterline. When it is detected that the free memory space is less than the preset memory, the memory compression process is started, instead of waiting until the free memory space is lower than the memory waterline before performing memory compression.
[0084] Optionally, it is also possible to detect in real time whether the current free memory is lower than the preset memory, and trigger the memory compression instruction when it is detected that the current free memory is lower than the preset memory. Alternatively, it is also possible to periodically detect the free memory, and trigger the memory compression instruction when it is detected that the current free memory is lower than the preset memory.
[0085] As another method, the memory compression instruction can also be triggered periodically. Specifically, the memory compression instruction is pre-set, and the triggering time period of the memory compression instruction is set. Whenever the triggering time of the memory compression instruction is reached, the memory compression instruction is triggered.
[0086] As another way, the memory compression instruction can also be triggered when the startup of a designated application is detected. The designated application can be a pre-set application for triggering the memory compression instruction. In the embodiment of the present application, the designated application can be an application that uses a large amount of memory during operation, such as a game application. Since the designated application needs to use a large amount of memory during operation, in order to reserve enough memory for the designated application in advance, the memory compression instruction can be triggered when the startup of the designated application is detected, so as to perform memory compression on the pages stored in the memory in advance based on the memory compression instruction.
[0087] In an embodiment of the present application, the system kernel can monitor the remaining free memory of the system in real time. When it is detected that the current free memory is lower than the preset memory, it triggers the start of obtaining multiple memory pages corresponding to the currently running application.
[0088] Step S220: Obtain access parameters corresponding to each of the plurality of memory pages.
[0089] In the embodiment of the present application, the access parameters may include the access frequency, access duration, access timestamp, etc. corresponding to each memory page. The access frequency represents the number of times the memory page is accessed within a preset time; the access duration represents the length of time each time the memory page is accessed; and the access timestamp may represent the start time or end time of the most recent access to the memory page.
[0090] As one approach, obtaining access parameters corresponding to each of the plurality of memory pages includes: obtaining access frequencies corresponding to each of the plurality of memory pages.
[0091] When the access parameter is the access frequency, the multiple memory pages may be screened based on the access frequencies corresponding to the multiple memory pages, and the memory pages whose corresponding access frequencies meet the specified conditions are selected from the multiple memory pages as the data to be processed.
[0092] As another manner, obtaining access parameters corresponding to each of the plurality of memory pages includes: obtaining access timestamps corresponding to each of the plurality of memory pages.
[0093] When the access parameter is an access timestamp, the multiple memory pages may be screened based on the access timestamps corresponding to the multiple memory pages, and memory pages whose corresponding timestamps meet specified conditions may be selected from the multiple memory pages as data to be processed.
[0094] Optionally, obtaining access parameters corresponding to each of the multiple memory pages includes: obtaining access durations corresponding to each of the multiple memory pages.
[0095] When the access parameter is the access duration, the multiple memory pages may be screened based on the access durations corresponding to the multiple memory pages, and memory pages whose corresponding durations meet the specified conditions may be selected from the multiple memory pages as data to be processed.
[0096] Step S230: Based on the access parameter, determine the data to be processed from the multiple memory pages.
[0097] As one approach, determining the data to be processed from the multiple memory pages based on the access parameter includes: taking the memory pages whose corresponding access frequency is lower than the preset access frequency among the multiple memory pages as the data to be processed.
[0098] In the case where the access parameter is the access frequency, when screening multiple memory pages, the memory pages whose corresponding access frequency is lower than the preset access frequency among the multiple memory pages can be used as the data to be processed. The preset access frequency is a preset frequency that indicates that the memory page is rarely accessed within a preset time period. The preset time period can be any set time period, which is not specifically limited here.
[0099] When the access frequency corresponding to a memory page is lower than the preset access frequency, it can be seen that the memory page will not be accessed frequently. It can be seen from the side that the memory page is an unimportant memory page. Therefore, you can choose to compress the memory page first, and then decompress it when you need to access the memory page later.
[0100] As another way, determining the data to be processed from the multiple memory pages based on the access parameter includes: taking the memory page whose corresponding access timestamp is farthest from the current time among the multiple memory pages as the data to be processed.
[0101] When the access parameter is an access timestamp, when filtering multiple memory pages, the memory page whose corresponding access timestamp is farthest from the current time among the multiple memory pages can be used as the data to be processed. In this case, the access timestamp can refer to the end time of the last access to the memory page.
[0102] Similarly, when the access timestamp corresponding to a memory page is the timestamp farthest from the current time, it can be seen that the memory page is unlikely to be accessed again in a short period of time. Therefore, you can choose to compress the memory page first, and then decompress it when you need to access the memory page later.
[0103] Optionally, determining the data to be processed from the multiple memory pages based on the access parameters includes: taking, among the multiple memory pages, memory pages whose corresponding access duration is less than a preset duration as the data to be processed.
[0104] When the access parameter is the access duration, when screening multiple memory pages, the memory pages whose corresponding access duration is less than the preset duration can be used as the data to be processed. The preset duration can be any pre-set duration.
[0105] Step S240: performing a first compression process on the data to be processed to obtain first compressed data, wherein the first compression process represents compressing the data to be processed in a hardware-based compression manner.
[0106] Step S250: Determine whether the compression rate of the first compressed data meets the preset compression rate, if so, execute step S260, if not, execute step S270.
[0107] In an embodiment of the present application, when the data to be processed is a memory page, the compression rate of the first compressed data can be determined based on the data volume of the target memory page before compression and the data volume of the target memory page after compression. Among them, the target memory page is a memory page that needs to be compressed and processed determined from multiple memory pages. The preset compression rate is any pre-set compression rate, and the preset compression rate can be determined based on the number of newly generated memory pages or the current free memory. Specifically, the more the number of newly generated memory pages, the larger the corresponding preset compression rate can be set; the smaller the current free memory, the larger the corresponding preset compression rate can be set.
[0108] Step S260: taking the first compressed data as the target compressed data.
[0109] In the embodiment of the present application, after the first compression processing is performed on the data to be processed to obtain the first compressed data, if the compression rate of the first compressed data meets the preset compression rate, the first compressed data is output as the target compressed data.
[0110] Step S270: performing a second compression process on the first compressed data to obtain target compressed data, wherein the second compression process represents compressing the data to be processed by a software-based compression method.
[0111] The present application provides a data compression method, which uses two compression processing methods to compress the data to be processed, and adjusts the compression processing method according to the compression rate of the data to be processed, thereby improving the flexibility of data compression.
[0112] See also Figure 5 , an embodiment of the present application provides a data compression device 300, the device 300 comprising:
[0113] The data acquisition unit 310 is used to acquire data to be processed.
[0114] As a method, the data acquisition unit 310 is specifically used to acquire multiple memory pages corresponding to the currently running application; acquire access parameters corresponding to each of the multiple memory pages; and determine the data to be processed from the multiple memory pages based on the access parameters.
[0115] Furthermore, the data acquisition unit 310 is also specifically used to acquire the access frequencies corresponding to each of the multiple memory pages; and use the memory pages whose corresponding access frequencies are lower than the preset access frequencies among the multiple memory pages as the data to be processed.
[0116] Furthermore, the data acquisition unit 310 is also specifically used to obtain the access timestamps corresponding to each of the multiple memory pages; and use the memory page whose corresponding access timestamp is farthest from the current time among the multiple memory pages as the data to be processed.
[0117] The first processing unit 320 is configured to perform a first compression process on the data to be processed to obtain first compressed data, wherein the first compression process represents compressing the data to be processed in a hardware-based compression manner.
[0118] The second processing unit 330 is used to perform a second compression process on the first compressed data to obtain target compressed data if the compression rate of the first compressed data does not meet the preset compression rate. The second compression process represents compressing the data to be processed by a software-based compression method.
[0119] As a method, the second processing unit 330 is specifically used to obtain the compression ratio corresponding to the first compressed data; if the compression ratio of the first compressed data does not meet the preset compression ratio, the first compressed data is subjected to a second compression process. The compression ratio corresponding to the first compression process is less than or equal to the compression ratio corresponding to the second compression process; and the compression speed corresponding to the first compression process is greater than the compression speed corresponding to the second compression process.
[0120] As another embodiment, the second processing unit 330 is further configured to use the first compressed data as the target compressed data if the compression rate of the first compressed data meets the preset compression rate.
[0121] It should be noted that the device embodiment in the present application corresponds to the aforementioned method embodiment. The specific principles in the device embodiment can be found in the contents of the aforementioned method embodiment and will not be repeated here.
[0122] The following will be combined Figure 6 An electronic device or server provided in the present application is described.
[0123] See also Figure 6 Based on the above data compression method and device, the embodiment of the present application also provides another electronic device or server 800 that can execute the above data compression method. The electronic device or server 800 includes one or more (only one is shown in the figure) processors 802, a memory 804 and a network module 806 that are coupled to each other. Among them, the memory 804 stores a program that can execute the content of the above embodiment, and the processor 802 can execute the program stored in the memory 804.
[0124] Among them, the processor 802 may include one or more processing cores. The processor 802 uses various interfaces and lines to connect the various parts of the entire electronic device or server 800, and executes various functions and processes data of the electronic device or server 800 by running or executing instructions, programs, code sets or instruction sets stored in the memory 804, and calling data stored in the memory 804. Optionally, the processor 802 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 802 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 802, but implemented separately through a communication chip.
[0125] The memory 804 may include a random access memory (RAM) or a read-only memory (ROM). The memory 804 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 804 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc. The data storage area may also store data (such as a phone book, audio and video data, chat record data) created by the electronic device or server 800 during use.
[0126] The network module 806 is used to receive and send electromagnetic waves, realize the mutual conversion between electromagnetic waves and electrical signals, so as to communicate with a communication network or other devices, such as communicating with electronic devices. The network module 806 may include various existing circuit elements for performing these functions, such as antennas, radio frequency transceivers, digital signal processors, encryption / decryption chips, user identity modules (SIM) cards, memories, etc. The network module 806 may communicate with various networks such as the Internet, corporate intranets, wireless networks, or communicate with other devices via wireless networks. The above-mentioned wireless networks may include cellular telephone networks, wireless local area networks, or metropolitan area networks. For example, the network module 806 may exchange information with a base station.
[0127] Please refer to Figure 7 , which shows a structural block diagram of a computer-readable storage medium provided in an embodiment of the present application. The computer-readable storage medium 900 stores program codes, which can be called by a processor to execute the method described in the above method embodiment.
[0128] The computer-readable storage medium 900 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer-readable storage medium 900 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 900 has storage space for program code 910 that performs any method step in the above method. These program codes can be read from or written to one or more computer program products. The program code 910 can be compressed, for example, in an appropriate form.
[0129] The present application provides a data compression method, device, electronic device and storage medium, which obtains data to be processed, performs a first compression process on the data to be processed, and obtains first compressed data. The first compression process represents that the data to be processed is compressed by a hardware-based compression method. When the compression rate of the first compressed data does not meet the preset compression rate, the first compressed data is compressed by a second compression method to obtain target compressed data. The second compression process represents that the data to be processed is compressed by a software-based compression method. Through the above method, two compression processing methods are used to compress the data to be processed, and the compression processing method is adjusted according to the compression rate of the data to be processed, thereby improving the flexibility of data compression.
[0130] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.
Claims
1. A data compression method, characterized in that: The method comprises: Get the data to be processed; Performing a first compression process on the data to be processed to obtain first compressed data, wherein the first compression process represents compressing the data to be processed in a hardware-based compression manner; If the compression rate of the first compressed data does not meet the preset compression rate, a second compression process is performed on the first compressed data to obtain target compressed data, and the second compression process represents compressing the data to be processed by a software-based compression method.
2. The method according to claim 1, characterized in that If the compression rate of the first compressed data does not meet the preset compression rate, performing a second compression process on the first compressed data to obtain target compressed data includes: Obtaining a compression ratio corresponding to the first compressed data; If the compression rate of the first compressed data does not meet the preset compression rate, a second compression process is performed on the first compressed data.
3. The method according to claim 1 or 2, characterized in that: The method further comprises: If the compression rate of the first compressed data meets the preset compression rate, the first compressed data is used as the target compressed data.
4. The method according to claim 1, characterized in that: The compression ratio corresponding to the first compression processing method is less than or equal to the compression ratio corresponding to the second compression processing method; the compression speed corresponding to the first compression processing method is greater than the compression speed corresponding to the second compression processing method.
5. The method according to claim 1, characterized in that The obtaining of the data to be processed comprises: Get multiple memory pages corresponding to the currently running application; Obtaining access parameters corresponding to each of the plurality of memory pages; Based on the access parameter, data to be processed is determined from the plurality of memory pages.
6. The method according to claim 5, characterized in that The obtaining of access parameters corresponding to each of the plurality of memory pages includes: Obtaining access frequencies corresponding to each of the plurality of memory pages; The step of determining the data to be processed from the plurality of memory pages based on the access parameter comprises: Among the multiple memory pages, the memory pages corresponding to which the access frequency is lower than the preset access frequency are used as data to be processed.
7. The method according to claim 5, characterized in that The obtaining of access parameters corresponding to each of the plurality of memory pages includes: Obtaining access timestamps corresponding to each of the plurality of memory pages; The step of determining the data to be processed from the plurality of memory pages based on the access parameter comprises: Among the multiple memory pages, the memory page whose corresponding access timestamp is farthest from the current time is used as the data to be processed.
8. A data compression device, characterized in that: The device comprises: A data acquisition unit, used for acquiring data to be processed; A first processing unit, configured to perform a first compression process on the data to be processed to obtain first compressed data, wherein the first compression process represents compressing the data to be processed in a hardware-based compression manner; The second processing unit is used to perform a second compression process on the first compressed data to obtain target compressed data if the compression rate of the first compressed data does not meet the preset compression rate. The second compression process represents compressing the data to be processed by a software-based compression method.
9. An electronic device, characterized in that: The method comprises one or more processors; one or more programs are stored in the memory and configured to execute the method according to any one of claims 1 to 7 by the one or more processors.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program code, wherein when the program code is executed by a processor, the method according to any one of claims 1 to 7 is executed.
