Data caching device and method
Through the data cache device with integrated compression, decompression and verification functions, the problem of low efficiency of read and write data from memory by the processor is solved, and more efficient data writing and security is achieved.
Patent Information
- Application Number
- CN202510695264.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-27
- Publication Date
- 2025-08-26
AI Technical Summary
In the prior art, when the processor reads and writes data from the memory, it is necessary to perform compression and decompression processing and access request verification, resulting in a decrease in data reading and writing efficiency.
Data cache equipment that integrates compression, decompression and verification functions, including cache modules, compression processing modules and verification sub-units, improves data writing efficiency through comparative verification and compression processing.
Through the integrated compression, decompression and verification functions, data interaction is reduced, the processing efficiency and security of data cache devices are improved, and data writing efficiency is improved.
Smart Images

Figure CN120541009A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data caching, and in particular to a data caching device and method. Background Art
[0002] In the related art, when the processor of an electronic device reads and writes data from a memory, it is necessary to compress and decompress the read and written data, including decompressing the data in the memory and reading it out, and compressing the data provided by the processor and writing it into the memory.
[0003] At the same time, in order to improve the security of the system, when the processor accesses the memory, the processor's access request needs to be verified. Only after the verification is passed is access to the memory allowed to read and write data.
[0004] Compression and decompression processing, as well as request verification, will consume a certain amount of time, resulting in reduced data reading and writing efficiency. Summary of the Invention
[0005] To this end, this application discloses the following technical solutions:
[0006] A first aspect of the present application provides a data cache device, comprising:
[0007] Cache module, used to cache compressed data;
[0008] The compression processing module includes a compression unit and a decompression unit. The compression unit is used to compress the original data to obtain compressed data, and when the original data passes the comparison verification, output the compressed data to the cache module for caching; the decompression unit is used to decompress the compressed data obtained from the cache module;
[0009] The decompression unit also includes a check subunit, which is used to compare and check the original data to be written to the first position of the cache module with the first decompressed data. The first decompressed data is obtained by the decompression unit by decompressing the existing data obtained from the first position in the cache module.
[0010] Optionally, the original data includes content data and identification data, and the identification data represents a storage address of the content data in a memory;
[0011] Comparing and verifying the original data to be written to the first position of the cache module with the first decompressed data includes:
[0012] The identification data contained in the original data to be written to the first position of the cache module is compared and verified with the identification data contained in the first decompressed data.
[0013] Optionally, the data cache device further includes:
[0014] a control unit, configured to output the existing data at the first position to a memory for storage if the existing data at the first position satisfies a first condition;
[0015] The first condition includes that the existing data does not match the data stored at the storage address corresponding to the existing data in the memory;
[0016] Outputting the compressed data to the cache module for caching includes:
[0017] The compressed data is output to a first location of the cache module to replace the existing data cached in the first location.
[0018] Optionally, compressing the original data to obtain compressed data includes:
[0019] In a case where the data amount of the original data does not match the target data amount, merging the original data with the first decompressed data according to the offset information of the write request, and compressing the merged data to obtain compressed data, where the target data amount is the amount of data that can be stored at one storage address of the memory;
[0020] When the data amount of the original data matches the target data amount, compressing the original data to obtain compressed data;
[0021] The write request carries the original data.
[0022] Optionally, the original data includes content data and identification data, and the identification data represents a storage address of the content data in a memory;
[0023] The cache module includes a data cache unit and an identification cache unit;
[0024] The data cache unit is used to cache the compressed data;
[0025] The identification buffer unit is used to buffer identification data contained in original data corresponding to the compressed data.
[0026] Optionally, the first position is a cache position corresponding to the first identification data in the data cache unit;
[0027] The first identification data is identification data in the identification cache unit that matches the identification data contained in the original data.
[0028] Optionally, the check subunit is further configured to:
[0029] If the identification data contained in the original data does not match the identification data cached by the identification cache unit, comparing and verifying the original data to be written to the first location of the cache module with second decompressed data obtained by the decompression unit from the data obtained from the first storage address of the memory;
[0030] The first storage address is a storage address represented by identification data contained in the original data, and the first position is any idle cache position in the data cache unit.
[0031] Optionally, the decompression unit is further configured to decompress the existing data obtained from the second position of the data cache unit, and feed back the decompressed data to the target device;
[0032] The second position is a cache position corresponding to second identification data in the data cache unit, and the second identification data is identification data in the identification cache unit that matches the identification data carried by the read request, and the read request is sent by the target device to the data cache device.
[0033] Optionally, the cache module further includes a cache queue;
[0034] When the identification data carried in the read request does not match the identification data in the identification cache unit, the decompression unit is further configured to:
[0035] If the identification data carried in the read request matches the existing data in the cache queue, decompressing the existing data obtained from the cache queue and feeding the decompressed data back to the target device;
[0036] The existing data obtained from the cache queue is used to cache in the data cache unit.
[0037] Optionally, the decompression unit is further configured to:
[0038] If the identification data carried in the read request does not match the existing data in the cache queue, decompressing the existing data obtained from the second storage address of the memory, and feeding back the decompressed data to the target device;
[0039] The existing data obtained from the second storage address is used to cache in the cache queue, and the second storage address is the storage address corresponding to the identification data carried in the read request.
[0040] A second aspect of the present application provides a data caching method, comprising:
[0041] Obtaining original data to be written to the first position of the cache module;
[0042] performing a comparison and verification on the original data and first decompressed data of the cache module based on a check subunit, where the first decompressed data is obtained by decompressing existing data at the first position in the cache module by the decompression unit;
[0043] When the original data passes the comparison and verification, the compressed data corresponding to the original data is output to the cache module for caching, and the compressed data is obtained by compressing the original data by the compression unit;
[0044] The decompression unit includes the syndrome unit, the decompression unit and the compression unit are both included in a compression processing module, and the cache module and the compression processing module belong to the same data cache device. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without any creative work.
[0046] Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application;
[0047] Figure 2 This is a structural diagram of a data cache device provided in an embodiment of the present application;
[0048] Figure 3 This is a structural diagram of another data cache device provided in an embodiment of the present application;
[0049] Figure 4 This is a flow chart of a data caching method provided by an embodiment of the present application;
[0050] Figure 5 This is a flow chart of a data reading method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0052] This embodiment provides a data cache device, which can be applied to any electronic device.
[0053] As an example, see Figure 1 , is a structural diagram of an electronic device including the data cache device, and the electronic device may include a processor 101, a data cache device 102 and a memory 103.
[0054] The processor 101 may be any type of processor, for example, a central processing unit (CPU), a graphics processing unit (GPU), an embedded neural network processor (NPU), or a system on chip (SOC), without limitation.
[0055] The memory 103 may be a memory device that can be read and written by the processor 101, for example, a double data rate synchronous dynamic random access memory, or other types of memory devices.
[0056] When the electronic device is running, the processor 101 may send an access request to the data cache device 102 . The access request may be a read request for reading data from the memory 103 or a write request for writing data to the memory 103 .
[0057] After receiving the access request, the data cache device 102 can process the access request and feedback the processing result to the processor 101. If the access request is a read request, the feedback processing result may include the to-be-read data corresponding to the read request; if the access request is a write request, the feedback processing result may include a notification of successful data writing.
[0058] The data cache device 102 processes the access request, which may include any one or more of the following:
[0059] Compress or decompress any one or more of the data carried in the write request, the data from the data cache device, and the data from the memory 103;
[0060] Verify access requests, such as verifying the data carried in write requests;
[0061] Performing data read and write operations includes but is not limited to caching data from a write request into its own cache module, writing data from its own cache module into the memory 103, and caching data from the memory 103 into its own cache module, any one or more operations.
[0062] The working principle of the data cache device of this embodiment is described below in conjunction with the structure of the data cache device.
[0063] See Figure 2, is a structural diagram of a data cache device of this embodiment, and the data cache device may include the following modules.
[0064] Cache module 201, used for caching compressed data;
[0065] The compression processing module 202 includes a compression unit 2021 and a decompression unit 2022. The compression unit 2021 is used to compress the original data to obtain compressed data, and when the original data passes the comparison verification, output the compressed data to the cache module for caching; the decompression unit 2022 is used to decompress the compressed data obtained from the cache module;
[0066] The decompression unit 2022 also includes a check subunit 2023, which is used to compare and verify the original data at the first position to be written to the cache module with the first decompressed data. The first decompressed data is obtained by the decompression unit 2022 by decompressing the existing data obtained from the first position in the cache module 201.
[0067] The compressed data cached by the cache module 201 may include compressed data output by the compression unit 201 after compression processing, and may also include compressed data obtained by the data cache device from the memory.
[0068] The original data compressed by the compression unit 2021 can come from any processor connected to the data cache device. For example, Figure 1 The processor 101 sends a write request to the data cache device 102 . The data cache device may use the data carried in the write request as original data, and perform comparison verification and compression processing through the verification subunit 2023 and the compression unit 2021 , respectively.
[0069] The order of compression and comparison verification of the original data is not limited. In some embodiments, after obtaining the original data, the verification sub-unit 2023 can first perform comparison verification, and after the comparison verification, the compression unit 2021 performs compression processing to obtain the corresponding compressed data, which is finally stored in the cache module 201, that is, the comparison verification is performed first and then the compression processing is performed.
[0070] In some embodiments, after obtaining the original data, the compression unit 2021 can first compress the original data, and then the decompression unit 2022 decompresses the existing data, and the verification sub-unit 2023 compares and verifies the original data. After the comparison and verification, the compressed data is written into the cache module 201, that is, compression processing is performed first and then comparison and verification is performed.
[0071] In some embodiments, after obtaining the original data, the compression unit 2021 can first compress the original data. During the compression process, the decompression unit 2022 decompresses the existing data, and the verification sub-unit 2023 compares and verifies the original data. After the comparison and verification, the compressed data is written into the cache module 201, that is, the compression process and comparison and verification are performed simultaneously.
[0072] Among them, performing compression processing and comparison verification at the same time can shorten the time from obtaining the original data to completing the caching of the corresponding compressed data, thereby improving data writing efficiency.
[0073] After the verification subunit 2023 performs a comparison verification on each piece of original data, the verification result can be fed back to the processor that provides the original data, for example, to Figure 1 The processor 101 shown. The verification result can be regarded as at least a part of the aforementioned processing result. The verification result can be a pass or a fail. Among them, passing the verification can be regarded as the original data provided by the processor being successfully saved, and thus the result of passing the verification can be regarded as a successful data write; if the verification fails, the compression unit 2021 may not compress the original data and may not cache the corresponding compressed data in the cache module 201, so the result of failing the verification can be regarded as a data write failure.
[0074] Optionally, in the case of comparison verification, the verification result may be fed back to the processor only after the compressed data is written into the cache module 201 .
[0075] A piece of original data can be defined as the original data carried in a write request sent by a processor to a data cache device.
[0076] The first location refers to a cache location in the cache module 201 that is reserved for caching compressed data corresponding to the original data. When the original data is obtained, the first location may or may not already have compressed data cached. When the original data is obtained, the compressed data cached at the first location can be considered as existing data at the first location.
[0077] When obtaining the original data, if the above-mentioned existing data exists at the first position, the decompression unit 2022 can obtain the existing data from the cache module 201, decompress the existing data to obtain the first decompressed data, and then call the verification subunit 2023, and the verification subunit 2023 will compare and verify the original data with the first decompressed data.
[0078] The beneficial effects of this embodiment are:
[0079] The data cache device of this embodiment, on the one hand, integrates the compression unit 2021 and the decompression unit 2022 that realize the compression and decompression functions, and the verification subunit 2023 that realizes the comparison and verification function into the same module, namely the compression processing module 202. This can reduce unnecessary data interaction between the above units during the compression, decompression and comparison and verification process, thereby improving processing efficiency. On the other hand, the data cache device integrates the cache module 201 that caches compressed data and the compression processing module 202 that processes data, so that each unit inside the compression processing module 202 can directly read and write data from the cache module 201, thereby improving the efficiency of data interaction between the cache module 201 and the compression processing module 202. Through the above two effects, the data cache device can improve the efficiency of writing original data under the premise of realizing the processing process of compression, decompression and comparison and verification of data when processing write requests.
[0080] In some embodiments, a piece of original data may include two parts: content data and identification data; wherein, the content data can be recorded as data, which is the data that the processor actually wants to write into the memory; the identification data can be recorded as tag, which is used to represent the storage address of the content data in the memory, that is, to represent the location in the memory where the content data should be written.
[0081] Correspondingly, for each compressed data cached in the cache module 201, after the compressed data is decompressed by the decompression unit 2022 to obtain the corresponding decompressed data, the decompressed data also includes two parts: content data and identification data. The content data is the part of the decompressed data that needs to be written to the memory, and the identification data represents the storage address of the content data in the memory.
[0082] The verification subunit 2023 compares and verifies the original data at the first position to be written into the cache module with the first decompressed data in the following manner:
[0083] The identification data contained in the original data at the first position to be written into the cache module is compared and verified with the identification data contained in the first decompressed data.
[0084] If the identification data contained in the original data is the same as the identification data contained in the first decompressed data, it can be determined that the original data passes the comparison verification; if the identification data contained in the original data is different from the identification data contained in the first decompressed data, it can be determined that the original data fails the comparison verification.
[0085] The compressed data cached in the cache module 201, each corresponding identification data can find a corresponding storage address in the memory (such as the internal memory). If the identification data contained in the original data is different from the identification data contained in the first decompressed data, it means that the storage address required by the original data may not exist in the memory. In this case, blocking the access request corresponding to the original data may be an unsafe access request. At this time, blocking the caching of the compressed data corresponding to the original data is conducive to improving the security of the data cache device and the subsequent memory.
[0086] Optional, see Figure 3 , the data cache device may further include:
[0087] A control unit 2013 is configured to output the existing data at the first position to a memory for storage if the existing data at the first position meets a first condition;
[0088] The first condition includes that the existing data does not match the data stored at the storage address corresponding to the existing data in the memory.
[0089] Correspondingly, outputting the compressed data to the cache module for caching may include:
[0090] The compressed data is output to a first location of the cache module to replace existing data cached at the first location.
[0091] As described above, after decompression, each existing data in the cache module 201 can obtain decompressed data consisting of identification data and content data. The identification data obtained after the existing data is decompressed is equivalent to the identification data corresponding to the existing data; the storage address represented by the identification data corresponding to the existing data is the storage address corresponding to the existing data in the memory.
[0092] The control unit 2013 may be a unit within the cache module 201 .
[0093] When the cache module 201 includes the control unit 2013 , the existing data at the first position can be read out by the control unit 2013 and then transferred to the decompression unit 2022 for decompression processing.
[0094] In some embodiments, since the compressed data cached in the cache module 201 can be decompressed to obtain two parts, namely, identification data and content data, when storing the existing data at the first position in the memory, the control unit 2013 can store the complete existing data at the first position in the memory, or, it can only store the part of the compressed data corresponding to the content data at the first position in the memory, and the part of the compressed data corresponding to the identification data is not stored in the memory.
[0095] In some embodiments, whether each piece of compressed data in the cache module 201 satisfies the first condition may be determined in the following manner.
[0096] When a compressed data is stored in the cache module 201, it can be determined whether the part of the compressed data corresponding to the content data is read directly from the memory or obtained after compression processing by the compression unit 2021. If it is the former, a mark that does not meet the first condition is configured for the compressed data to indicate that the compressed data matches the data stored at the corresponding storage address in the memory. If it is the latter, a mark that meets the first condition is configured for the compressed data to indicate that the compressed data does not match the data stored at the corresponding storage address in the memory.
[0097] Therefore, before outputting the compressed data to the cache module for caching, it can be determined whether the existing data at the first position meets the first condition according to the mark corresponding to the existing data at the first position.
[0098] Optionally, the data cache device includes Figure 3 In the case of the cache control unit 2010 shown, determining whether the existing data at the first position meets the first condition and configuring the above-mentioned mark for the cached compressed data can both be performed by the cache control unit 2010.
[0099] If the existing data at the first position meets the first condition, the control unit 2013 first outputs the existing data at the first position to the memory for storage, and then outputs the compressed data to the first position of the cache module 201. If the existing data at the first position does not meet the first condition, the control unit 2013 can directly output the obtained compressed data to the first position of the cache module 201, directly overwriting the existing data at the first position.
[0100] When the existing data at the first position is output to the memory for storage, the storage address of the existing data in the memory can be determined based on the identification data obtained after decompression of the existing data, and then the existing data, or the compressed content data contained in the existing data, can be written to the storage address.
[0101] Through the above-mentioned caching method, it can be ensured that the existing data in the cache module 201 that meets the first condition can be updated to the memory in time before being overwritten by the newly input compressed data, thereby preventing data loss.
[0102] In some optional embodiments, such as Figure 3 As shown, the cache module 201 may include a data cache unit 2011 and an identification cache unit 2012;
[0103] The data cache unit 2011 is used to cache compressed data;
[0104] The identification cache unit 2012 is used to cache identification data contained in the original data corresponding to the compressed data.
[0105] The first location for caching compressed data refers to a cache location in the data cache unit 2011 .
[0106] Furthermore, the cache module 201 may include Figure 3 The cache control unit 2010 shown is used to directly read and write the data cache unit 2011 and the identification cache unit 2012. For example, the compressed data can be read from the data cache unit 2011 and passed to the control unit 2013 to provide the compressed data to the compression processing module 202 and / or any of the memory through the control unit 2013; at the same time, the compressed data from the compression processing module 202 and / or the memory can be obtained from the control unit 2013 and written into the data cache unit 2011.
[0107] In a compressed data, the part corresponding to the identification data can be recorded as compressed identification data, and the part corresponding to the content data can be recorded as compressed content data. The former can obtain the identification data after decompression processing, and the latter can obtain the content data after decompression processing.
[0108] When performing compression processing to obtain a compressed data, the content data and the identification data may be compressed separately so as to facilitate distinguishing the compressed identification data from the compressed content data.
[0109] The identifier cache unit 2012 may cache uncompressed identifier data or compressed identifier data.
[0110] Each time the cache control unit 2010 writes a piece of compressed data into the data cache unit 2011 , it may write the identification data corresponding to the compressed data or the compressed identification data into the identification cache unit 2012 .
[0111] In some optional embodiments, compressing the original data to obtain compressed data may include:
[0112] In a case where the data volume of the original data does not match the target data volume, the original data and the first decompressed data are merged according to the offset information of the write request, and the merged data is compressed to obtain compressed data, where the target data volume is the amount of data that can be stored at one storage address of the memory;
[0113] When the data volume of the original data matches the target data volume, compressing the original data to obtain compressed data;
[0114] The write request carries the original data.
[0115] Each cache position of the data cache unit 2011 can correspond to a row of cache space. A row of cache space corresponding to a cache position can be called a cache line. A cache line can cache a compressed data. The amount of compressed content data cached in a cache line can be consistent with the target data amount of the memory.
[0116] The data volume of the original data matches the target data volume, which can be defined as the data volume of the compressed content data obtained by compressing the content data contained in the original data is equal to the target data volume. Correspondingly, if the data volume of the compressed content data is smaller than the target data volume, it can be determined that the data volume of the original data does not match the target data volume.
[0117] As an example, if the original data obtained is compressed and the corresponding compressed data is not enough to fill a cache line, it means that the data volume of the original data does not match the target data volume. If the original data obtained is compressed and the corresponding compressed data can just fill a cache line, it means that the data volume of the original data and the target data volume match.
[0118] The offset information carried in the write request is used to indicate the storage location of the content data contained in the original data at the corresponding storage address.
[0119] As an example, assuming that the compressed content data stored at a storage address in the memory is decompressed to obtain 64 bytes of content data, and the original data contains 10 bytes of content data, the offset information carried in the write request can indicate that the 10-byte content data contained in the original data should be stored at the 20th to 29th bytes of the corresponding storage address.
[0120] The original data and the first decompressed data may be merged in the following manner:
[0121] After obtaining the first decompressed data, the original data at the position indicated by the offset information in the first decompressed data is replaced with the original data to obtain the fused data.
[0122] In combination with the above example, the 10-byte content data contained in the original data can be used to replace the 20th to 29th bytes of the 64-byte content data contained in the first decompressed data. In the fused data obtained in this way, the data from bytes 0 to 19 and bytes 30 to 63 are consistent with the original data at the corresponding positions in the first decompressed data, and the data from bytes 20 to 29 are the 10-byte content data contained in the original data; the identification data remains unchanged relative to the first decompressed data.
[0123] When the fused data is obtained, any compression algorithm can be used to compress the fused data to obtain compressed data. The compression algorithm used is selected from a variety of related algorithms according to needs. For example, any one of the Arm Frame Buffer Compression (AFBC) algorithm, the deep learning-based compression algorithm, and the Huffman coding algorithm can be used. The implementation principles of these algorithms can be found in the relevant technologies and will not be described in detail.
[0124] In the case that the data volume of the original data matches the target data volume, the above compression algorithm can be directly applied to compress the original data to obtain compressed data.
[0125] Compressing the original data according to the above method can meet the processor's needs of writing original data of different data volumes in different scenarios.
[0126] In some optional embodiments, the first position is a cache position corresponding to the first identification data in the data cache unit;
[0127] The first identification data is identification data in the identification cache unit that matches the identification data contained in the original data.
[0128] In the above embodiment, after the data cache device obtains the original data, it can compare the address information corresponding to the original data with the multiple address information cached in the identification cache unit. If any address information in the identification cache unit successfully matches the address information corresponding to the original data, the cache position corresponding to the address information in the data cache unit can be determined as the first position.
[0129] The address information corresponding to the original data may be included in a write request received by the data cache device. The address information corresponding to the original data may be identification data contained in the original data. The address information of the identification cache unit may be uncompressed identification data cached in the identification cache unit, or compressed identification data cached in the identification cache unit.
[0130] When comparing the address information corresponding to the original data with the address information of the identification cache unit, if the address information is compressed identification data, the compressed identification data can be decompressed first to obtain uncompressed identification data, and then the identification data of the original data carried in the write request and the uncompressed identification data from the identification cache unit can be compared. If the two are consistent, it is determined that the two match each other, or the match is successful. If the two are inconsistent, it is determined that the two do not match, or the match fails.
[0131] Among them, if there is a first identification data that matches successfully in the identification cache unit, it means that the cache module has cached the existing data of the first storage address in the memory. At this time, the existing data in the cache module can be replaced with compressed data after comparison and verification. If there is no first identification data that matches successfully in the identification cache unit, that is, each identification data of the identification cache unit fails to match the identification data of the original data, it means that the cache module has not cached the existing data of the first storage address in the memory. At this time, the compressed data can be stored in the cache module after comparison and verification.
[0132] The first storage address refers to an address in the memory indicated by the write request and used to store original data.
[0133] Optionally, the data cache device includes Figure 3 In the case of the cache control unit 2010 shown, the above method for determining the first position can be executed by the cache control unit 2010.
[0134] Optionally, the check subunit is further configured to:
[0135] If the identification data contained in the original data does not match the identification data cached by the identification cache unit, comparing and verifying the original data at the first location to be written into the cache module with the second decompressed data obtained by the decompression unit by decompressing the data obtained from the first storage address of the memory;
[0136] The first storage address is a storage address represented by the identification data contained in the original data, and the first position is any idle cache position in the data cache unit.
[0137] When there is at least one free cache location in the data cache unit 2011, any free cache location can be determined as the first location, and then the compressed data can be directly written to the first location. At this time, there is no existing data at the first location, and it is not necessary to determine whether the existing data meets the first condition.
[0138] In the case that there is no free cache position in the data cache unit 2011, the control unit 2013 or the cache control unit 2010 may determine a cache position as the first position in the data cache unit 2011 according to any of the following rules:
[0139] Find the compressed data written earliest into the data cache unit 2011, and determine the cache location of the compressed data as the first location;
[0140] In the data cache unit 2011 , a cache position with the least cumulative number of read and write times in a recent period of time is determined, and the cache position is determined as the first position.
[0141] After determining the first position according to the above method, you can first determine whether the existing data at the first position meets the first condition. If the first condition is met, first write the existing data to the corresponding storage address in the memory, and then write the compressed data corresponding to the original data to the first position. If the first condition is not met, the compressed data corresponding to the original data can be directly written to the first position.
[0142] When the identification data contained in the original data does not match the identification data cached by the identification cache unit, the control unit 2013 can read the existing data stored at the first storage address of the memory at the current moment, and then send the existing data at the first storage address to the decompression unit 2022 for decompression processing to obtain second decompressed data.
[0143] When obtaining the second decompressed data, if the existing data at the first storage address contains compressed content data and compressed identification data, then the method of comparing and verifying the original data based on the second decompressed data, and the method of compressing the original data, can all refer to the method of comparing and verifying and compressing the original data based on the first decompressed data in the aforementioned embodiment. It is only necessary to replace the first decompressed data involved with the second decompressed data, and no further details will be given.
[0144] When the second decompressed data is obtained, if the existing data at the first storage address only contains compressed content data but does not contain compressed identification data, then when performing a comparison check on the original data based on the second decompressed data, the first storage address of the memory and the identification data contained in the original data may be compared. If the two are consistent, the comparison check passes; if the two are inconsistent, the comparison check fails.
[0145] When the original data is compressed based on the second decompressed data, depending on whether the data volume of the original data matches the target data volume, the content data contained in the original data can be directly compressed, or the content data contained in the original data and the second decompressed data can be merged according to the offset information, and the merged data can be compressed to obtain compressed content data, and the identification data contained in the original data can be compressed to obtain compressed identification data, and finally, compressed data corresponding to the original data consisting of compressed content data and compressed identification data can be obtained.
[0146] Optionally, the control unit 2013 may include Figure 3 As shown in the cache queue, each time the control unit 2013 reads data from the memory, it can first store the data in the memory into the cache queue, and then read the stored data from the cache queue.
[0147] Based on the above data cache device and its working principle, this embodiment also provides a data cache method. The data cache method can be executed by the above data cache device. Figure 4 , which is a flowchart of the data caching method.
[0148] S401: Obtain a write request.
[0149] S402: Determine whether the write request is successful.
[0150] Among them, if the identification data corresponding to the original data carried by the write request successfully matches the first identification data cached by the cache module 201, the write request hits; if the identification data corresponding to the original data carried by the write request fails to match each identification data cached by the cache module 201, the write request misses.
[0151] If the write request succeeds, step S403 is executed; if the write request fails, step S408 is executed.
[0152] S403: perform comparison and verification on the original data.
[0153] If the original data passes the comparison and verification, step S404 is executed; if the original data fails the comparison and verification, step S407 is executed.
[0154] S404: Determine whether the existing data at the first position meets a first condition.
[0155] If the first condition is met, step S405 is executed; if the first condition is not met, step S406 is executed.
[0156] S405: Output the existing data at the first position to the memory for storage.
[0157] S406: Cache the compressed data obtained after the original data is compressed into a first location.
[0158] S407, feedback verification results.
[0159] S408: decompress existing data at the first storage address of the memory to obtain second decompressed data.
[0160] After obtaining the second decompressed data, steps S403 to S407 may be continued based on the second decompressed data.
[0161] The implementation of each step in the above method can refer to the working principle of the corresponding module or unit in the above embodiment, which will not be repeated here.
[0162] Figure 4 The data writing method shown is equivalent to:
[0163] Obtaining original data to be written to the first position of the cache module;
[0164] performing a comparison and verification on the original data and the first decompressed data of the cache module based on the check subunit, where the first decompressed data is obtained by the decompression unit decompressing the existing data at the first position in the cache module;
[0165] When the original data passes the comparison and verification, the compressed data corresponding to the original data is output to the cache module for caching. The compressed data is obtained by the compression unit compressing the original data;
[0166] The decompression unit includes a check subunit, the decompression unit and the compression unit are both included in the compression processing module, and the cache module and the compression processing module belong to the same data cache device.
[0167] Wherein, step S401 is equivalent to obtaining the original data to be written into the first position of the cache module;
[0168] S403 is equivalent to comparing and verifying the original data and the first decompressed data of the cache module based on the check subunit; step S406 is equivalent to outputting the compressed data corresponding to the original data to the cache module for caching when the original data passes the comparison and verification.
[0169] The process of compressing the original data to obtain compressed data includes:
[0170] In a case where the data volume of the original data does not match the target data volume, the original data and the first decompressed data are merged according to the offset information of the write request, and the merged data is compressed to obtain compressed data, where the target data volume is the amount of data that can be stored at one storage address of the memory;
[0171] When the data volume of the original data matches the target data volume, the original data is compressed to obtain compressed data; the write request carries the original data.
[0172] Optionally, the decompression unit 2022 is further configured to decompress the existing data obtained from the second location of the data cache unit 2011 and feed back the decompressed data to the target device;
[0173] The second position is the cache position corresponding to the second identification data in the data cache unit 2011. The second identification data is the identification data in the identification cache unit 2012 that matches the identification data carried in the read request. The read request is sent by the target device to the data cache device.
[0174] In the above embodiment, the data cache device may obtain a read request from the processor, the read request is used to read existing data stored in the memory, and the identification data carried in the read request may indicate at which storage address of the memory the existing data needs to be read.
[0175] After receiving the read request, the data cache device may compare the identification data carried in the read request with the identification data cached in the identification cache unit 2012 to determine whether there is matching second identification data in the identification cache unit 2012 .
[0176] If there is second identification data in the identification cache unit 2012, then it can be determined that the data required for the read request is cached in the data cache unit 2011, and the second position where the data is cached corresponds to the second identification data. Therefore, the existing data at the second position can be read from the second position corresponding to the second identification data, and the existing data at the second position is sent to the decompression unit 2022. After the decompression unit 2022 decompresses the existing data at the second position, it feeds back the decompressed data to the target device.
[0177] The comparison of the identification data and the reading of the existing data at the second location may be performed by the cache control unit 2010 , and the read existing data at the second location may be transferred to the decompression unit 2022 via the control unit 2013 .
[0178] The method of comparing the identification data carried by the read request with the identification data cached by the identification cache unit 2012 can be consistent with the method of comparing the identification data carried by the write request with the identification data cached by the identification cache unit 2012 in the aforementioned embodiment, and will not be repeated here.
[0179] The target device in the above embodiment may refer to Figure 1 Processor 101 is shown.
[0180] Optionally, the cache module further includes a cache queue;
[0181] If there is no matching second identification data in the identification cache unit 2012, that is, if the identification data carried in the read request does not match the identification data in the identification cache unit, the decompression unit 2022 is further configured to:
[0182] If the identification data carried in the read request matches the existing data in the cache queue, decompress the existing data obtained from the cache queue and feed the decompressed data back to the target device;
[0183] The existing data obtained from the cache queue is used to be cached in the data cache unit 2011 .
[0184] Each time the control unit 2013 reads existing data from the memory, the read existing data can be cached in the cache queue of the control unit 2013. When the cache control unit 2010 determines that there is no matching second identification data in the identification cache unit 2012, the control unit 2013 can compare the storage address of the existing data cached in the cache queue with the storage address indicated by the read request. If the storage address of a piece of existing data in the cache queue is consistent with the storage address indicated by the read request, it can be determined that the existing data belongs to the data required by the read request. At this time, the control unit can read the existing data from the cache queue and send it to the decompression unit 2022 for decompression processing, and then the decompression unit 2022 feeds back the decompressed data to the target device.
[0185] At the same time, after the control unit 2013 obtains the existing data corresponding to the read request from the cache queue, it can also store the obtained existing data into the data cache unit 2011 through the cache control unit 2010, and store the identification data corresponding to the existing data in the identification cache unit 2012, so that the next time the same data is requested, it can be read directly from the data cache unit 2011.
[0186] Among them, the existing data in the cache queue is decompressed and fed back to the target device, and the data in the cache queue is written into the data cache unit 2011. The order of the two actions is not limited. It can be decompressed and fed back to the target device first, or written into the data cache unit 2011 first, or both can be performed simultaneously.
[0187] The storage address of the existing data may be represented by identification data corresponding to the existing data, and the storage address indicated by the read request may be represented by identification data carried in the read request.
[0188] In some embodiments, the read request may also carry offset information, which indicates that the data to be read is the data at a specific location on the corresponding storage address. For example, the offset information may indicate reading the data from the 10th to 20th bytes on the corresponding storage address, or indicate reading the data from the 30th to 40th bytes on the corresponding storage address.
[0189] When the read request carries offset information, the control unit 2013 can read only the required part of the data from the cache queue according to the offset information and send it to the decompression unit 2022, and only store the part of the data corresponding to the offset information into the data cache unit 2011.
[0190] For example, the storage address of an existing data in the cache queue matches the storage address of the read request, and the offset information carried by the read request indicates that the data of the 10th to 20th bytes at the storage address is required. Therefore, the control unit 2013 reads the part of the existing data corresponding to the 10th to 20th bytes from the cache queue and sends it to the decompression unit 2022 for decompression, and at the same time stores this part of the data in the data cache unit 2011.
[0191] Optionally, when obtaining existing data from the data cache unit 2011, only the portion of data corresponding to the offset information may be obtained based on the offset information.
[0192] Reading a corresponding portion of data according to the offset information is beneficial for reducing the amount of data to be read and shortening the time taken to read the data, thereby feeding back the required data to the target device more quickly.
[0193] Optionally, the decompression unit 2022 is further configured to:
[0194] If the identification data carried in the read request does not match the existing data in the cache queue, decompress the existing data obtained from the second storage address of the memory, and feed the decompressed data back to the target device;
[0195] The existing data obtained from the second storage address is used to cache in the cache queue, and the second storage address is the storage address corresponding to the identification data carried in the read request.
[0196] In the above embodiment, the control unit 2013 can read the existing data at the second storage address from the memory based on the storage address indicated by the identification data carried by the read request, fill the read existing data into the cache queue, so that it can be obtained from the cache queue when the same data is read subsequently, and send the existing data from the cache queue to the decompression unit 2022 for decompression, so that the decompressed data can be fed back to the target device.
[0197] Each time the control unit 2013 reads data from the memory, it can generate a bus read access operation for the memory address according to the memory address to be read, and then execute the bus read access operation to obtain the existing data in the memory at the corresponding memory address.
[0198] In some optional embodiments, the data compression module 202 may also include Figure 3The compression control unit 2020 shown is used to realize data interaction between the compression processing module 202 and the cache module 201. That is to say, the data and various notifications sent from the compression processing module 202 to the compression unit 2021 and the decompression unit 2022, as well as the data and various notifications (such as verification results) sent from the compression unit 2021 and the decompression unit 2022 to the compression processing module 202, can all be transmitted through the compression control unit 2020.
[0199] Based on the above data cache device and its working principle, this embodiment also provides a data reading method, which can be executed by the above data cache device. Figure 5 , which is a flowchart of the data reading method.
[0200] S501: Obtain a read request.
[0201] S502: Determine whether the read request is successful.
[0202] If the read request is successful, execute step S503 ; if the read request is unsuccessful, execute step S504 .
[0203] If the identification cache unit 2012 contains second identification data that matches the identification data carried in the read request, it can be determined that the read request is a hit; if the identification cache unit 2012 does not contain the second identification data, it can be determined that the read request is a miss.
[0204] S503: Decompress the existing data at the second position in the data cache unit and feed the decompressed data back to the target device.
[0205] S504: Determine whether the cache queue has existing data corresponding to the read request.
[0206] If the cache queue does not have existing data corresponding to the read request, step S505 is executed; if the cache queue has existing data corresponding to the read request, step S506 is executed.
[0207] S505 , reading existing data at the second storage address of the memory and writing the data into the cache queue.
[0208] After executing S505 , S506 may be executed to feed back the existing data written into the second storage address in the cache queue to the target device.
[0209] S506: Decompress the existing data corresponding to the read request in the cache queue and feed it back to the target device.
[0210] S507: De-write the existing data corresponding to the read request in the cache queue into the data cache unit.
[0211] The implementation of each step in the above method can refer to the working principle of the corresponding module or unit in the above embodiment, which will not be repeated here.
[0212] Figure 5 In the method shown, steps S501 to S503 are equivalent to:
[0213] decompressing existing data obtained from a second location of the cache module and feeding the decompressed data back to the target device, where the second location is determined based on a read request issued by the target device;
[0214] Steps S505 to S507 are equivalent to:
[0215] When the cache module does not cache the data corresponding to the read request, the existing data at the second storage address obtained from the memory is decompressed, the decompressed data is fed back to the target device, and the existing data at the second storage address is cached in the cache module.
[0216] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referenced to each other.
[0217] For the convenience of description, the above systems or devices are described as being divided into various modules or units according to their functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0218] Through the description of the above embodiments, it can be seen that those skilled in the art can clearly understand that the present application can be implemented by means of software plus the necessary general hardware platform. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in various embodiments of the present application or certain parts of the embodiments.
[0219] Finally, it should be noted that, in this document, relational terms such as first, second, third, and fourth are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus comprising the element.
[0220] The above is only a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A data cache device, comprising: Cache module, used to cache compressed data; A compression processing module, comprising a compression unit and a decompression unit, wherein the compression unit is configured to compress the original data to obtain compressed data, and output the compressed data to the cache module for caching when the original data passes comparison verification; The decompression unit is used to decompress the compressed data obtained from the cache module; The decompression unit also includes a check subunit, which is used to compare and check the original data to be written to the first position of the cache module with the first decompressed data. The first decompressed data is obtained by the decompression unit by decompressing the existing data obtained from the first position in the cache module.
2. The device according to claim 1, wherein the original data comprises content data and identification data, and the identification data represents a storage address of the content data in a memory; Comparing and verifying the original data to be written to the first position of the cache module with the first decompressed data includes: The identification data contained in the original data to be written to the first position of the cache module is compared and verified with the identification data contained in the first decompressed data.
3. The device according to claim 1, wherein the data cache device further comprises: a control unit, configured to output the existing data at the first position to a memory for storage if the existing data at the first position satisfies a first condition; The first condition includes that the existing data does not match the data stored at the storage address corresponding to the existing data in the memory; Outputting the compressed data to the cache module for caching includes: The compressed data is output to a first location of the cache module to replace the existing data cached in the first location.
4. The device according to claim 1, wherein compressing the original data to obtain the compressed data comprises: In a case where the data amount of the original data does not match the target data amount, merging the original data with the first decompressed data according to the offset information of the write request, and compressing the merged data to obtain compressed data, where the target data amount is the amount of data that can be stored at one storage address of the memory; When the data amount of the original data matches the target data amount, compressing the original data to obtain compressed data; The write request carries the original data.
5. The device according to claim 1, wherein the original data comprises content data and identification data, and the identification data represents a storage address of the content data in a memory; The cache module includes a data cache unit and an identification cache unit; The data cache unit is used to cache the compressed data; The identification buffer unit is used to buffer identification data contained in original data corresponding to the compressed data.
6. The device according to claim 5, wherein the first position is a cache position in the data cache unit corresponding to the first identification data; The first identification data is identification data in the identification cache unit that matches the identification data contained in the original data.
7. The device according to claim 5, wherein the syndrome unit is further configured to: If the identification data contained in the original data does not match the identification data cached by the identification cache unit, comparing and verifying the original data to be written to the first location of the cache module with second decompressed data obtained by the decompression unit from the data obtained from the first storage address of the memory; in, The first storage address is a storage address represented by identification data contained in the original data, and the first position is any idle cache position in the data cache unit.
8. The device according to claim 5, wherein the decompression unit is further configured to decompress the existing data obtained from the second location of the data cache unit and feed the decompressed data back to the target device; The second position is a cache position corresponding to second identification data in the data cache unit, and the second identification data is identification data in the identification cache unit that matches the identification data carried by the read request, and the read request is sent by the target device to the data cache device.
9. The device according to claim 8, wherein the cache module further comprises a cache queue; When the identification data carried in the read request does not match the identification data in the identification cache unit, the decompression unit is further configured to: If the identification data carried in the read request matches the existing data in the cache queue, decompressing the existing data obtained from the cache queue and feeding the decompressed data back to the target device; in, The existing data obtained from the cache queue is used to cache in the data cache unit.
10. The device according to claim 9, wherein the decompression unit is further configured to: If the identification data carried in the read request does not match the existing data in the cache queue, decompressing the existing data obtained from the second storage address of the memory, and feeding back the decompressed data to the target device; in, The existing data obtained from the second storage address is used to be cached in the cache queue, and the second storage address is the storage address corresponding to the identification data carried in the read request.
11. A data caching method, comprising: Obtaining original data to be written to the first position of the cache module; performing a comparison and verification on the original data and first decompressed data of the cache module based on a check subunit, where the first decompressed data is obtained by decompressing existing data at the first position in the cache module by the decompression unit; When the original data passes the comparison and verification, the compressed data corresponding to the original data is output to the cache module for caching, and the compressed data is obtained by compressing the original data by the compression unit; The decompression unit includes the syndrome unit, the decompression unit and the compression unit are both included in a compression processing module, and the cache module and the compression processing module belong to the same data cache device.
12. The method according to claim 11, wherein compressing the original data to obtain the compressed data comprises: When the data volume of the original data does not match the target data volume, the original data and the first decompressed data are merged according to the offset information of the write request, and the merged data is compressed to obtain compressed data, where the target data volume is the amount of data that can be stored at one storage address of the memory; When the data amount of the original data matches the target data amount, compressing the original data to obtain compressed data; The write request carries the original data.
13. The method according to claim 11, further comprising at least one of the following: decompressing existing data obtained from a second location of the cache module, and feeding back the decompressed data to a target device, wherein the second location is determined based on a read request issued by the target device; When the cache module does not cache the data corresponding to the read request, the existing data obtained from the second storage address of the memory is decompressed, the decompressed data is fed back to the target device, and the existing data of the second storage address is cached in the cache module.