Memory compression method, apparatus, and electronic device
Patent Information
- Application Number
- CN202211026868.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-25
- Publication Date
- 2026-09-04
- Estimated Expiration
- 2042-08-25
AI Technical Summary
但相关方式中,内存压缩方法的压缩效果还有待提高
[0007] Fourthly, this application provides a computer-readable storage medium storing program code, wherein the above-described method is executed when the program code is run.
Smart Images

Figure CN115549688B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically, to a memory compression method, apparatus, and electronic device. Background Technology
[0002] With the development of computer technology, data compression technology has been widely used in computer systems to save storage space or transmission bandwidth. One approach involves using memory compression to compress data according to a specific algorithm and store it in compressed memory. The system then retrieves the compressed data from this memory, decompresses it, and makes it available for system use. However, the compression effectiveness of memory compression methods still needs improvement. Summary of the Invention
[0003] In view of the above problems, this application proposes a memory compression method, apparatus, and electronic device to improve the above problems.
[0004] In a first aspect, this application provides a memory compression method, the method comprising: obtaining the memory access frequency of a target memory; obtaining a first reference compression algorithm corresponding to the memory access frequency; obtaining the current remaining memory and CPU load; obtaining a target compression algorithm based on the remaining memory, the CPU load and the first reference compression algorithm; and compressing the data in the target memory based on the target compression algorithm.
[0005] Secondly, this application provides a memory compression apparatus, the apparatus comprising: a memory access frequency acquisition unit for acquiring the memory access frequency of a target memory; a first reference compression algorithm acquisition unit for acquiring a first reference compression algorithm corresponding to the memory access frequency; a parameter acquisition unit for acquiring the current remaining memory and CPU load; a target compression algorithm acquisition unit for obtaining a target compression algorithm based on the remaining memory, the CPU load, and the first reference compression algorithm; and a compression execution unit for compressing data in the target memory based on the target compression algorithm.
[0006] Thirdly, this application provides an electronic device including one or more processors and a memory; one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs being configured to perform the methods described above.
[0007] Fourthly, this application provides a computer-readable storage medium storing program code, wherein the above-described method is executed when the program code is run.
[0008] This application provides a memory compression method, apparatus, electronic device, and storage medium. After obtaining the memory access frequency of the target memory, a first reference compression algorithm corresponding to the memory access frequency is obtained. The current remaining memory and CPU load are also obtained. Based on the remaining memory, the CPU load, and the first reference compression algorithm, a target compression algorithm is obtained. Data in the target memory is then compressed using the target compression algorithm. This method allows for the first obtaining of the first reference compression algorithm based on the target memory's memory access frequency, and then, based on the current remaining memory, CPU load, and the first reference compression algorithm, obtaining a target compression algorithm that conforms to the memory access patterns of the target process under current resource conditions, thereby achieving a good compression effect. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 A flowchart of a memory compression method proposed in an embodiment of this application is shown;
[0011] Figure 2 A flowchart of a memory compression method according to another embodiment of this application is shown;
[0012] Figure 3 A flowchart of a memory compression method according to another embodiment of this application is shown;
[0013] Figure 4 A schematic diagram of the business process of a memory compression method proposed in this application is shown;
[0014] Figure 5 A structural block diagram of a memory compression device according to an embodiment of this application is shown;
[0015] Figure 6 A structural block diagram of an electronic device proposed in this application is shown;
[0016] Figure 7 It is a storage unit in this application embodiment for storing or carrying program code that implements the memory compression method according to this application embodiment. Detailed Implementation
[0017] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort 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, data compression technology is widely used in computer systems to further improve data processing and data storage capabilities. Among related methods, data can be compressed according to a certain algorithm and stored in compressed memory. The system then retrieves the compressed data from the compressed memory, decompresses it, and makes it available for system use.
[0019] The inventors discovered in their research that the compression performance of existing memory compression methods still needs improvement. For example, using the same compression algorithm for all memory is insufficient because different processes or different memory locations within the same process have different characteristics. Using the same algorithm for all processes or different memory locations within the same process will not achieve optimal compression results. Furthermore, some processes are not frequently used; using a low compression ratio algorithm will result in them occupying more memory after compression compared to a high compression ratio, leading to decreased memory utilization.
[0020] Therefore, the inventors have proposed a memory compression method, apparatus, and electronic device as described in this application. After obtaining the memory access frequency of the target memory, a first reference compression algorithm corresponding to the memory access frequency is obtained. The current remaining memory and CPU load are also obtained. Based on the remaining memory, the CPU load, and the first reference compression algorithm, a target compression algorithm is obtained. Data in the target memory is then compressed based on the target compression algorithm. This method allows for the first obtaining of the first reference compression algorithm from the memory access frequency of the target memory, and then, based on the current remaining memory, CPU load, and the first reference compression algorithm, obtaining a target compression algorithm that conforms to the memory access patterns of the target process under current resource conditions, thereby achieving a good compression effect.
[0021] Please see Figure 1 This application provides a memory compression method, the method comprising:
[0022] S110: Obtain the memory access frequency of the target memory.
[0023] The target memory can refer to the memory that needs to be compressed, which can be the memory accessed by the corresponding object. The memory access frequency can refer to the number of times an object (such as a process) accesses the target memory within a specified time period.
[0024] One way is to view the access history of the target memory, which contains the number of times the target memory was accessed within a specified time period, thereby obtaining the memory access frequency of the target memory.
[0025] S120: Obtain the first reference compression algorithm corresponding to the memory access frequency.
[0026] As one approach, if the memory access frequency is greater than a preset frequency, the first reference compression algorithm corresponding to the target memory is determined to be a first type of compression algorithm, which is an algorithm with a compression ratio less than a preset compression ratio; if the memory access frequency is less than or equal to the preset frequency, the first reference compression algorithm corresponding to the target memory is determined to be a second type of compression algorithm, which is an algorithm with a compression ratio greater than or equal to the preset compression ratio.
[0027] Compared to the second type of compression algorithm, the first type of compression algorithm consumes more memory space but consumes less CPU (Central Processing Unit). For example, the preset compression ratio can be 2.14. As shown in Table 1, the first type of compression algorithm can be: zstd 1.5.1-1, zlib 1.2.11-1, brotli 1.0.9-0, zstd 1.5.1--fast=1, zstd 1.5.1--fast=3, quicklz 1.5.0-1, zstd1.5.1--fast=4. The second type of compression algorithm can be: lzo1x 2.10-1, lz4 1.9.3, lzf 3.6-1, and snappy 1.1.9.
[0028] Table 1
[0029] zstd 1.5.1-1 2.887 530MB / s 1700MB / s zlib 1.2.11-1 2.743 95MB / s 400MB / s brotli 1.0.9-0 2.702 395MB / s 450MB / s zstd 1.5.1 --fast=1 2.437 600MB / s 2150MB / s zstd 1.5.1--fast=3 2.239 670MB / s 2250MB / s quicklz 1.5.0-1 2.238 540MB / s 760MB / s zstd1.5.1--fast=4 2.148 710MB / s 2300MB / s lzo1x 2.10-1 2.106 660MB / s 845MB / s lz4 1.9.3 2.101 740MB / s 4500MB / s lzf 3.6-1 2.077 410MB / s 830MB / s snappy 1.1.9 2.073 550MB / s 1750MB / s
[0030] For example, the memory access frequency of the target memory obtained in step S110 can be A, and the preset frequency can be B. If the memory access frequency A is greater than the preset frequency B, the first reference compression algorithm corresponding to the target memory can be determined to be a first type of compression algorithm, such as zstd 1.5.1-1, zlib 1.2.11-1, brotli 1.0.9-0, zstd 1.5.1--fast=1, zstd 1.5.1--fast=3, quicklz 1.5.0-1, zstd1.5.1--fast=4, etc. If the memory access frequency A is less than or equal to the preset frequency B, the first reference compression algorithm corresponding to the target memory can be determined to be a second type of compression algorithm, such as lzo1x 2.10-1, lz4 1.9.3, lzf 3.6-1, snappy 1.1.9, etc.
[0031] Optionally, the preset frequency can be preset based on the system's hardware performance. The better the system's hardware performance, the higher the preset frequency can be set. The quality of the system's hardware performance can be determined by the system's memory size, the number of CPUs, and the CPU's processing speed. The larger the system's memory, the more CPUs, and the faster the CPU's processing speed, the better the system's hardware performance.
[0032] Optionally, the preset frequency can also be preset based on the access frequency of all memory on the system. For example, the average access frequency of all memory on the system can be used as the preset frequency; or the median access frequency of all memory on the system can be used as the preset frequency.
[0033] Optionally, the preset compression ratio can be preset based on the compression ratio of all compression algorithms included in the system. For example, the average compression ratio of all compression algorithms in the system can be used as the preset compression ratio; or the median compression ratio of all compression algorithms in the system can be used as the preset compression ratio.
[0034] Optionally, when the first type of compression algorithm and the second type of compression algorithm included in the system include multiple compression algorithms, one of the compression algorithms can be arbitrarily selected as the first reference compression algorithm.
[0035] S130: Get the current remaining memory and CPU load.
[0036] CPU load refers to the current utilization rate of the CPU. The higher the utilization rate, the more processes the CPU is currently processing, and the greater the CPU load.
[0037] One way to check the current remaining memory and CPU load is through relevant commands in the operating system.
[0038] S140: Based on the remaining memory, the CPU load, and the first reference compression algorithm, obtain the target compression algorithm.
[0039] One approach is to adjust the first reference compression algorithm based on remaining memory and CPU load, and then use the adjusted first reference compression algorithm as the target compression algorithm.
[0040] Optionally, adjusting the first reference compression algorithm can involve adjusting its compression parameters. If the current remaining memory is sufficient and the current CPU load is greater than or equal to the load threshold, the compression parameters of the first reference compression algorithm can be adjusted to decrease the compression ratio and increase the compression speed, and the adjusted first reference compression algorithm can be used as the target compression algorithm. If the current remaining memory is insufficient and the current CPU load is less than the load threshold, the compression parameters of the first reference compression algorithm can be adjusted to increase the compression ratio and decrease the compression speed, and the adjusted first reference compression algorithm can be used as the target compression algorithm. If the current remaining memory is sufficient and the current CPU load is less than the load threshold, the first reference compression algorithm can be used directly as the target compression algorithm without adjustment.
[0041] Optionally, when the system includes multiple compression algorithms of the first and second types, the adjustment of the first reference compression algorithm can be achieved by selecting another algorithm from the same type of compression algorithms as the first reference compression algorithm for switching. If the current remaining memory is sufficient and the current CPU load is greater than or equal to the load threshold, the first reference compression algorithm can be replaced by a compression algorithm of the same type as the first reference compression algorithm that has a slower compression speed, and the replaced algorithm can be used as the target compression algorithm. If the current remaining memory is insufficient and the current CPU load is less than the load threshold, the first reference compression algorithm can be replaced by a compression algorithm of the same type as the first reference compression algorithm that has a higher compression ratio, and the replaced algorithm can be used as the target compression algorithm. If the current remaining memory is sufficient and the current CPU load is less than the load threshold, the first reference compression algorithm can be used directly as the target compression algorithm without replacement.
[0042] For example, the first reference compression algorithm obtained in step S120 is quicklz 1.5.0-1 in the first type of compression algorithm. The first type of compression algorithm in the system can also include zstd 1.5.1-1, zlib 1.2.11-1, brotli 1.0.9-0, zstd 1.5.1--fast=1, zstd 1.5.1--fast=3, zstd1.5.1--fast=4, etc. As shown in Table 1, if the current remaining memory is sufficient and the current CPU load is greater than or equal to the load threshold, quicklz 1.5.0-1 can be replaced with zstd1.5.1--fast=4, and zstd1.5.1--fast=4 can be used as the target compression algorithm. If the current remaining memory is insufficient and the current CPU load is less than the load threshold, quicklz 1.5.0-1 can be replaced with zlib 1.2.11-1, and zlib 1.5.1--fast=4 can be used as the target compression algorithm. 1.2.11-1 can be used as the target compression algorithm. If the current remaining memory is sufficient and the current CPU load is less than the load threshold, quicklz 1.5.0-1 can be directly used as the target compression algorithm.
[0043] Alternatively, a second reference compression algorithm can be derived based on the remaining memory and CPU load; and a target compression algorithm can be derived based on the first and second reference compression algorithms.
[0044] Optionally, the current remaining memory can be compared with the preset memory. If the remaining memory is greater than or equal to the preset memory, it indicates that the current remaining memory is sufficient; if the remaining memory is less than the preset memory, it indicates that the current remaining memory is insufficient.
[0045] Optionally, preset memory and load thresholds can be obtained based on multiple trials.
[0046] As another approach, if there is sufficient remaining memory and the current CPU load is less than the load threshold, the first reference compression algorithm can be used as the target compression algorithm.
[0047] S150: Compress the data in the target memory based on the target compression algorithm.
[0048] As one approach, the data in the target memory can be compressed based on the target compression algorithm obtained in step S140.
[0049] This embodiment provides a memory compression method. After obtaining the memory access frequency of a target memory, a first reference compression algorithm corresponding to the memory access frequency is obtained, current remaining memory and CPU load are acquired, a target compression algorithm is obtained based on the remaining memory, the CPU load and the first reference compression algorithm, and data in the target memory is compressed based on the target compression algorithm. Through the above method, the first reference compression algorithm can be obtained first through the memory access frequency of the target memory, and then the target compression algorithm that conforms to the memory access law of the target process under current resource conditions can be obtained based on the current remaining memory, CPU load and the first reference compression algorithm, thereby achieving a good compression effect.
[0050] Please refer to Figure 2 , a memory compression method provided by the present application, the method comprising:
[0051] S210: Obtain a memory access frequency of a target memory.
[0052] S220: Obtain a first reference compression algorithm corresponding to the memory access frequency.
[0053] S230: Obtain current remaining memory and CPU load.
[0054] S240: Obtain a second reference compression algorithm based on the remaining memory and the CPU load.
[0055] As an approach, if the current remaining memory is sufficient and the current CPU load is less than a load threshold, the second reference compression algorithm is determined to be a first-type compression algorithm, and the first-type compression algorithm is an algorithm with a compression rate less than a preset compression rate; if the current remaining memory is insufficient and the current CPU load is greater than or equal to the load threshold, the second reference compression algorithm is determined to be a second-type compression algorithm, and the second-type compression algorithm is an algorithm with a compression rate greater than or equal to the preset compression rate.
[0056] Optionally, the current remaining memory may be compared with a preset memory, if the remaining memory is greater than or equal to the preset memory, it indicates that the current remaining memory is sufficient; if the remaining memory is less than the preset memory, it indicates that the current remaining memory is insufficient.
[0057] For example, the preset memory may be A, the load threshold may be B, the current remaining memory may be A1, and the current CPU load may be B1. When A1>A and B1<B, the second reference compression algorithm can be determined to be the first-type compression algorithm; when A1≤A and B1≥B, the second reference compression algorithm can be determined to be the second-type compression algorithm.
[0058] S250: Obtain the target compression algorithm based on the first reference compression algorithm and the second reference compression algorithm.
[0059] In one approach, if the first reference compression algorithm and the second reference compression algorithm are of the same type, the first reference compression algorithm can be used as the target compression algorithm; if the first reference compression algorithm and the second reference compression algorithm are of different types, the second reference compression algorithm can be used as the target compression algorithm.
[0060] This embodiment provides a memory compression method that, through the aforementioned approach, first obtains a first reference compression algorithm based on the memory access frequency of the target memory, and then, based on the current remaining memory, CPU load, and the first reference compression algorithm, obtains a target compression algorithm that conforms to the memory access patterns of the target process under the current resource conditions, thereby achieving a good compression effect. Furthermore, in this embodiment, the target compression algorithm can be obtained based on the first and second reference compression algorithms, allowing the target memory to be compressed based on the target compression algorithm that conforms to the memory access patterns of the target process under the current resource conditions, thus achieving a good compression effect. Moreover, the memory compression method proposed in this application can integrate multiple compression algorithms onto a single electronic device, enabling the electronic device to select a suitable algorithm from multiple compression algorithms to compress data in the target memory based on the memory compression method proposed in this application, thereby achieving a good compression effect.
[0061] Please see Figure 3 This application provides a memory compression method, the method comprising:
[0062] S310: Determine whether the data in the target memory meets the target conditions.
[0063] The target condition can include the same character appearing repeatedly in the data.
[0064] One approach is to compare the data in the target memory with the target conditions to determine whether the data in the target memory meets the target conditions.
[0065] For example, if the data in the target memory can be AAAAAABBBBBBCCCCCC, then the data in the target memory satisfies the target condition.
[0066] Optionally, the target condition can be determined based on the characteristics of the data in the target memory. The characteristics of the data can refer to the occurrence of characters according to a specific pattern. For example, the target condition can also be that the data is purely numeric, and the numbers appearing later are multiples of the numbers appearing earlier.
[0067] S320: If the target condition is not met, execute the step of obtaining the access frequency of the target memory.
[0068] As one approach, if it is determined based on step S310 that the data in the target memory does not meet the target conditions, step S110 can be executed: obtain the access frequency of the target memory.
[0069] S330: If the target condition is met, the compression algorithm corresponding to the target condition shall be used as the target compression algorithm.
[0070] Among them, when the target condition is that the same character appears repeatedly in the data, the compression algorithm corresponding to the target condition can be to compress the data in the form of "number of times the character is repeated + character".
[0071] As one approach, if it is determined from step S310 that the data in the target memory meets the target conditions, the compression algorithm corresponding to the target conditions is used as the target compression algorithm. For example, when the data in the target memory can be AAAAAABBBBBBCCCCCC, the result of compression using the target compression algorithm is 6A6B6C.
[0072] Optionally, when the target condition is that the data is purely numeric, and the numbers appearing later are multiples of the numbers appearing earlier, the compression algorithm corresponding to the target condition can compress the data in the form of "starting number + number of numbers + multiple value".
[0073] S340: Compress the data in the target memory based on the target compression algorithm.
[0074] This embodiment provides a memory compression method that, through the aforementioned approach, first obtains a first reference compression algorithm based on the memory access frequency of the target memory. Then, based on the current remaining memory, CPU load, and the first reference compression algorithm, a target compression algorithm that conforms to the memory access patterns of the target process under the current resource conditions is obtained, thereby achieving a good compression effect. Furthermore, in this embodiment, it can first determine whether the data in the target memory meets the target conditions. When the target conditions are met, the compression algorithm corresponding to the target conditions can be directly used as the target compression algorithm to compress the data in the target memory. This allows for the compression of data that meets the target conditions while saving computing resources, achieving a good compression effect.
[0075] To better understand the solutions of all embodiments of this application, a business process of the memory compression method of this application is described below.
[0076] Please see Figure 4First, based on step S1, confirm whether the data in the target memory meets the target conditions. If the target conditions are met, then steps S2 and S3 can be executed sequentially. If the target conditions are not met, then step S4 can be executed: obtain the memory access frequency of the target memory, and then based on step S5, determine whether the memory access frequency is greater than the preset frequency. If the judgment result obtained based on step S5 is yes, then steps S6, S7, S8, and S3 can be executed sequentially. If the judgment result obtained based on step S5 is yes, then steps S9, S7, S8, and S3 can be executed sequentially.
[0077] Please see Figure 5 This application provides a memory compression device 600, the device 600 comprising:
[0078] The memory access frequency acquisition unit 610 is used to acquire the memory access frequency of the target memory.
[0079] The first reference compression algorithm acquisition unit 620 is used to acquire a first reference compression algorithm corresponding to the memory access frequency;
[0080] The parameter acquisition unit 630 is used to acquire the current remaining memory and CPU load.
[0081] The target compression algorithm acquisition unit 640 is used to obtain the target compression algorithm based on the remaining memory, the CPU load, and the first reference compression algorithm;
[0082] The compression execution unit 650 is used to compress data in the target memory based on the target compression algorithm.
[0083] In one approach, the first reference compression algorithm acquisition unit 620 is specifically used to determine, if the memory access frequency is greater than a preset frequency, that the first reference compression algorithm corresponding to the target memory is a first type of compression algorithm, wherein the first type of compression algorithm is an algorithm with a compression ratio less than a preset compression ratio; and if the access frequency is less than or equal to the preset frequency, determine that the first reference compression algorithm corresponding to the target memory is a second type of compression algorithm, wherein the second type of compression algorithm is an algorithm with a compression ratio greater than or equal to the preset compression ratio.
[0084] In one approach, the target compression algorithm acquisition unit 640 is specifically used to acquire a preset number of target signal strengths generated within a specified time period, and based on the remaining memory and the CPU load, obtain a second reference compression algorithm; and based on the first reference compression algorithm and the second reference compression algorithm, obtain the target compression algorithm.
[0085] Optionally, the target compression algorithm acquisition unit 640 is specifically used to determine the second reference compression algorithm as a first type of compression algorithm if the current remaining memory is sufficient and the current CPU load is less than the load threshold, wherein the first type of compression algorithm is an algorithm with a compression ratio less than a preset compression ratio; and to determine the second reference compression algorithm as a second type of compression algorithm if the current remaining memory is insufficient and the current CPU load is greater than or equal to the load threshold, wherein the second type of compression algorithm is an algorithm with a compression ratio greater than or equal to the preset compression ratio.
[0086] Optionally, the target compression algorithm acquisition unit 640 is specifically used to: if the first reference compression algorithm and the second reference compression algorithm are of the same type, use the first reference compression algorithm as the target compression algorithm; if the first reference compression algorithm and the second reference compression algorithm are of different types, use the second reference compression algorithm as the target compression algorithm.
[0087] Optionally, the target compression algorithm acquisition unit 640 is specifically used to select the first reference compression algorithm as the target compression algorithm if the current remaining memory is sufficient and the current CPU load is less than the load threshold.
[0088] The device 600 further includes:
[0089] The target condition confirmation unit 660 is used to confirm whether the data in the target memory meets the target conditions; if the target conditions are not met, the access frequency of the target memory is obtained; if the target conditions are met, the compression algorithm corresponding to the target conditions is used as the target compression algorithm; and the data in the target memory is compressed based on the target compression algorithm.
[0090] Optionally, the target condition includes: the same character appears repeatedly in the data.
[0091] The following will combine Figure 6 This application describes an electronic device.
[0092] Please see Figure 6 Based on the aforementioned memory compression method and apparatus, this application embodiment also provides another electronic device 100 capable of executing the aforementioned memory compression method. The electronic device 100 includes a processor 102, a memory 104, and a network module 106. The memory 104 stores a program capable of executing the contents of the aforementioned embodiments, and the processor 102 can execute the program stored in the memory 104.
[0093] The processor 102 may include one or more processing cores. The processor 102 connects to various parts within the electronic device 100 using various interfaces and lines, and performs various functions and processes data of the electronic device 100 by running or executing instructions, programs, code sets, or instruction sets stored in the memory 104, and by calling data stored in the memory 104. Optionally, the processor 102 may be implemented using at least one of the following hardware forms: a Neural Network Processing Unit (NPU), a Digital Signal Processing Unit (DSP), a Field-Programmable Gate Array (FPGA), or a Programmable Logic Array (PLA). The processor 102 may integrate one or more of the following: a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a Neural Network Processing Unit (NPU), and a modem. Specifically, the CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; the NPU handles multimedia data such as video and images; and the modem handles wireless communication. It is understandable that the aforementioned modem may not be integrated into the processor 102, but may be implemented using a separate communication chip.
[0094] The memory 104 may include random access memory (RAM), read-only memory (ROM), and double data rate synchronous dynamic random access memory (DDR). The memory 104 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 104 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described below. The data storage area may also store data created by the terminal 100 during use (such as phonebook data, audio and video data, chat log data, etc.).
[0095] The network module 106 can be used to enable information interaction between the electronic device 100 and other devices, such as transmitting device control commands, manipulation request commands, and status information acquisition commands. However, the network module 106 may differ depending on the specific device being used.
[0096] Please refer to Figure 7 This diagram illustrates a structural block diagram of a computer-readable storage medium provided in an embodiment of this application. The computer-readable storage medium 800 stores program code that can be called by a processor to execute the methods described in the above method embodiments.
[0097] The computer-readable storage medium 800 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 800 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 800 has storage space for program code 810 that performs any of the method steps described above. This program code can be read from or written to one or more computer program products. The program code 810 may, for example, be compressed in a suitable form.
[0098] In summary, the memory compression method, apparatus, and electronic device provided in this application, after obtaining the memory access frequency of the target memory, obtains a first reference compression algorithm corresponding to the memory access frequency, obtains the current remaining memory and CPU load, and based on the remaining memory, the CPU load, and the first reference compression algorithm, obtains a target compression algorithm, and compresses the data in the target memory based on the target compression algorithm. This approach allows for the first obtaining of the first reference compression algorithm from the memory access frequency of the target memory, and then, based on the current remaining memory, CPU load, and the first reference compression algorithm, obtaining a target compression algorithm that conforms to the memory access patterns of the target process under current resource conditions, thereby achieving a good compression effect.
[0099] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A memory compression method, characterized in that, The method includes: Obtain the memory access frequency of the target memory; Obtain a first reference compression algorithm corresponding to the memory access frequency; Get the current remaining memory and CPU load; If the current remaining memory is sufficient and the current CPU load is less than the load threshold, the second reference compression algorithm is determined to be the first type of compression algorithm, which is an algorithm with a compression ratio less than a preset compression ratio. If the current remaining memory is insufficient and the current CPU load is greater than or equal to the load threshold, the second reference compression algorithm is determined to be the second type of compression algorithm, which is an algorithm with a compression ratio greater than or equal to the preset compression ratio. Based on the first reference compression algorithm and the second reference compression algorithm, the target compression algorithm is obtained; The data in the target memory is compressed based on the target compression algorithm.
2. The method according to claim 1, characterized in that, The method further includes: If the memory access frequency is greater than the preset frequency, the first reference compression algorithm corresponding to the memory access frequency of the target memory is determined to be the first type of compression algorithm; If the memory access frequency is less than or equal to the preset frequency, the first reference compression algorithm corresponding to the memory access frequency of the target memory is determined to be the second type of compression algorithm.
3. The method according to claim 1, characterized in that, The process of obtaining the target compression algorithm based on the first reference compression algorithm and the second reference compression algorithm includes: If the first reference compression algorithm and the second reference compression algorithm are of the same type, the first reference compression algorithm shall be used as the target compression algorithm. If the first reference compression algorithm and the second reference compression algorithm are of different types, the second reference compression algorithm shall be used as the target compression algorithm.
4. The method according to claim 1, characterized in that, Before obtaining the memory access frequency of the target memory, the method further includes: Confirm whether the data in the target memory meets the target conditions; If the target condition is not met, the access frequency of the target memory is obtained. If the target condition is met, the compression algorithm corresponding to the target condition will be used as the target compression algorithm. The data in the target memory is compressed based on the target compression algorithm.
5. The method according to claim 4, characterized in that, The target condition includes: the same character appears repeatedly in the data.
6. A memory compression device, characterized in that, The device includes: The memory access frequency acquisition unit is used to acquire the memory access frequency of the target memory. The first reference compression algorithm acquisition unit is used to acquire the first reference compression algorithm corresponding to the memory access frequency. The parameter acquisition unit is used to obtain the current remaining memory and CPU load; The target compression algorithm acquisition unit is configured to: if the current remaining memory is sufficient and the current CPU load is less than a load threshold, determine the second reference compression algorithm as a first type of compression algorithm, wherein the first type of compression algorithm is an algorithm with a compression ratio less than a preset compression ratio; if the current remaining memory is insufficient and the current CPU load is greater than or equal to the load threshold, determine the second reference compression algorithm as a second type of compression algorithm, wherein the second type of compression algorithm is an algorithm with a compression ratio greater than or equal to the preset compression ratio; and obtain a target compression algorithm based on the first reference compression algorithm and the second reference compression algorithm. A compression execution unit is used to compress data in the target memory based on the target compression algorithm.
7. An electronic device, characterized in that, Includes one or more processors and memory; One or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs being configured to perform the method of any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores program code, wherein the method described in any one of claims 1-5 is executed when the program code is run.
Citation Information
Patent Citations
Data compression and storage method and device, data compression method and device, equipment and medium
CN109756230A
Data compression in storage clients
US20170194987A1