Data write protection method and storage device
By calculating the approximate compression ratio and capacity threshold of the storage device, a write protection strategy is determined, which solves the problem of storage device downtime caused by data compression uncertainty and improves the stability of the storage device.
Patent Information
- Application Number
- CN202211204735.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-29
- Publication Date
- 2026-03-03
- Estimated Expiration
- 2042-09-29
AI Technical Summary
During the operation of storage devices, due to the uncertainty of data in compression algorithms, user data may be incompressible or have a very small compression ratio. When the user capacity exceeds the physical capacity, continuous data writing by the host may cause the storage device to crash.
By obtaining the compression ratio and remaining effective capacity of each effective superblock of the storage device, a first approximate compression ratio is calculated, and based on the comparison result with the preset compression ratio and capacity threshold, a write protection strategy is determined, including controlling the storage device to enter a read-only state, a compressed state, send alarm information, or enter a normal state.
It effectively prevents the write volume of storage devices from exceeding the physical write limit, avoids downtime, and improves the stability of storage devices.
Smart Images

Figure CN115639959B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of storage device applications, and in particular to a data write protection method and storage device. Background Technology
[0002] Storage devices, such as flash memory devices, like solid-state drives (SSDs), are hard drives made using arrays of solid-state electronic storage chips. SSDs include a control unit and storage units (FLASH memory chips or DRAM memory chips).
[0003] Currently, during the operation of storage devices, the host writes data to the storage device according to the nominal user capacity. However, due to the uncertainty of the compression algorithm of the storage device in compressing data, the user data may be incompressible or have a very small compression ratio. During the continuous writing process of the host, since the user capacity of the storage device is greater than the physical capacity, when the data compression ratio is less than the nominal compression ratio of the storage device, the storage device may indicate that it can still write, but in reality, there is no physical space to write data. In this case, the host's continuous writing of data can easily lead to the storage device crashing.
[0004] Therefore, existing technologies urgently need improvement. Summary of the Invention
[0005] This application provides a data write protection method and storage device, which solves the technical problem of storage device crashing due to continuous data writing by the host and improves the stability of the storage device.
[0006] To address the aforementioned technical problems, this application provides the following technical solutions:
[0007] In a first aspect, embodiments of this application provide a data write protection method applied to a storage device, the method comprising:
[0008] When the storage device is in write mode, obtain the compression ratio and remaining effective capacity of each valid superblock of the storage device;
[0009] Calculate the first approximate compression ratio based on the compression ratio of each effective superblock;
[0010] Based on the comparison results of the first approximate compression ratio and the preset compression ratio, as well as the comparison results of the remaining effective capacity and the capacity threshold, the write protection strategy of the storage device is determined.
[0011] The write protection policies include controlling the storage device to enter a read-only state, controlling the storage device to enter a compressed state, controlling the storage device to send alarm information, or controlling the storage device to enter a normal state.
[0012] In some embodiments, calculating a first approximate compression ratio based on the compression ratio of each effective superblock includes:
[0013] The compression ratios of each effective superblock are summed to obtain the sum of the compression ratios of all effective superblocks.
[0014] Divide the sum of compression ratios by the number of effective superblocks to obtain the average compression ratio, and use the average compression ratio as the first approximate compression ratio.
[0015] In some embodiments, the method further includes:
[0016] The compression ratio of each effective superblock is calculated, specifically including:
[0017] Obtain the number of logical media addresses of all compressed data in each valid superblock and the number of physical media addresses in each valid superblock;
[0018] The compression ratio of each effective superblock is calculated based on the number of logical media addresses of all compressed data in each effective superblock and the number of physical media addresses of each effective superblock.
[0019] In some embodiments, the compression ratio of each effective superblock is calculated based on the number of logical media addresses of all compressed data in each effective superblock and the number of physical media addresses in each effective superblock, including:
[0020] Compression ratio of each effective superblock = number of logical media addresses of all compressed data in each effective superblock / number of physical media addresses in each effective superblock.
[0021] In some embodiments, the capacity threshold includes a first capacity threshold. A write protection strategy for the storage device is determined based on a comparison between a first approximate compression ratio and a preset compression ratio, and a comparison between the remaining effective capacity and the capacity threshold, including:
[0022] When the first approximate compression ratio is less than or equal to the preset compression ratio, if the remaining effective capacity of the storage device is less than the first capacity threshold, the write protection strategy of the storage device is determined to control the storage device to enter the read-only state, where the remaining effective capacity = remaining physical capacity * preset compression ratio, and the preset compression ratio = nominal capacity / total physical capacity.
[0023] In some embodiments, the capacity threshold includes a second capacity threshold. A write protection strategy for the storage device is determined based on a comparison between a first approximate compression ratio and a preset compression ratio, and a comparison between the remaining effective capacity and the capacity threshold, including:
[0024] When the first approximate compression ratio is less than or equal to the preset compression ratio, if the first capacity threshold ≤ the remaining effective capacity < the second capacity threshold, then the write protection strategy of the storage device is determined to be to control the storage device to send alarm information, wherein the second capacity threshold is greater than the first capacity threshold.
[0025] In some embodiments, the capacity threshold includes a third capacity threshold. A write protection strategy for the storage device is determined based on a comparison between a first approximate compression ratio and a preset compression ratio, and a comparison between the remaining effective capacity and the capacity threshold, including:
[0026] When the first approximate compression ratio is less than or equal to the preset compression ratio, if the second capacity threshold ≤ the remaining effective capacity < the third capacity threshold, then the write protection strategy of the storage device is determined to be to control the storage device to enter the compression state. The compression state includes triggering the storage device to read the data already stored in the storage medium of the storage device and compressing the read data in order to write the compressed data into the storage medium of the storage device.
[0027] In some embodiments, the storage device includes a cache module and at least two storage media, the at least two storage media including a first storage media and a second storage media. Triggering the storage device to read data already stored in the storage media of the storage device and compressing the read data to write the compressed data back to the storage media of the storage device includes:
[0028] Read the data from the first storage medium into the cache module;
[0029] The cache module compresses the data in the first storage medium and writes the compressed data to the second storage medium.
[0030] In some embodiments, a write protection strategy for the storage device is determined based on a comparison between a first approximate compression ratio and a preset compression ratio, and a comparison between the remaining effective capacity and a capacity threshold, including:
[0031] If the remaining effective capacity is greater than or equal to the third capacity threshold, or if the first approximate compression ratio is greater than the preset compression ratio, then the write protection strategy of the storage device is determined to control the storage device to enter a normal state. The normal state includes the host writing data to the storage device normally, and the third capacity threshold is greater than the second capacity threshold.
[0032] In some embodiments, the method further includes:
[0033] Calculate the remaining user capacity and remaining physical capacity;
[0034] Calculate the remaining compression ratio based on the remaining user capacity and remaining physical capacity;
[0035] Based on the comparison results of the first approximate compression ratio and the preset compression ratio, the comparison results of the remaining effective capacity and the capacity threshold, and / or the comparison results of the remaining compression ratio and the preset compression ratio, the write protection strategy of the storage device is determined.
[0036] Wherein, the remaining compression ratio = remaining user capacity / remaining physical capacity, the remaining user capacity = nominal capacity - effective user capacity, and the remaining physical capacity = total physical capacity - effective physical capacity.
[0037] In some embodiments, a write protection strategy for the storage device is determined based on a comparison between a first approximate compression ratio and a preset compression ratio, a comparison between the remaining effective capacity and a capacity threshold, and / or a comparison between the remaining compression ratio and the preset compression ratio, including:
[0038] If the first approximate compression ratio is less than or equal to the preset compression ratio, and the remaining effective capacity of the storage device is less than the first capacity threshold, and the remaining compression ratio is greater than the preset compression ratio, then the write protection strategy of the storage device is determined to control the storage device to enter the read-only state.
[0039] If the first approximate compression ratio is less than or equal to the preset compression ratio, and the first capacity threshold is less than or equal to the remaining effective capacity and the second capacity threshold is less than or equal to the remaining compression ratio, then the write protection strategy of the storage device is determined to be to control the storage device to send alarm information.
[0040] If the first approximate compression ratio is less than or equal to the preset compression ratio, and the second capacity threshold is less than or equal to the remaining effective capacity and the third capacity threshold is less than or equal to the remaining compression ratio, then the write protection strategy of the storage device is determined to be to control the storage device to enter the compression state.
[0041] If the first approximate compression ratio is greater than the preset compression ratio, or the remaining effective capacity is greater than or equal to the third capacity threshold, or the remaining compression ratio is less than or equal to the preset compression ratio, then the write protection strategy for the storage device is determined to control the storage device to enter the normal state.
[0042] In some embodiments, the method further includes:
[0043] Get the number of free superblocks on the storage device;
[0044] If the number of free superblocks is less than the first quantity threshold, then the write protection policy of the storage device is determined to control the storage device to enter the compression state.
[0045] If the number of free superblocks is less than the second quantity threshold, the write protection policy of the storage device is determined to be to control the storage device to send alarm information, wherein the first quantity threshold is less than the second quantity threshold.
[0046] Secondly, embodiments of this application provide a storage device, including:
[0047] At least one processor; and
[0048] A memory that is communicatively connected to at least one processor; wherein,
[0049] The memory stores instructions that can be executed by at least one processor, which enables the at least one processor to perform the data write protection method as described in the first aspect.
[0050] Thirdly, embodiments of this application also provide a non-volatile computer-readable storage medium storing computer-executable instructions that enable a storage device to perform the data write protection method as described in the first aspect.
[0051] The beneficial effects of this application embodiment are as follows: Unlike existing technologies, this application embodiment provides a data write protection method applied to a storage device. The method includes: when the storage device is in a write state, obtaining the compression ratio and remaining effective capacity of each effective superblock of the storage device; calculating a first approximate compression ratio based on the compression ratio of each effective superblock; determining a write protection strategy for the storage device based on a comparison result between the first approximate compression ratio and a preset compression ratio, and a comparison result between the remaining effective capacity and a capacity threshold; wherein the write protection strategy includes controlling the storage device to enter a read-only state, controlling the storage device to enter a compressed state, controlling the storage device to send alarm information, or controlling the storage device to enter a normal state, and the preset compression ratio = nominal capacity / total physical capacity.
[0052] By comparing the first approximate compression ratio with the preset compression ratio, and by comparing the remaining effective capacity with the capacity threshold, the write protection strategy of the storage device is determined. This application can prevent the write volume of the storage device from exceeding the physical writable capacity, solve the problem of the storage device crashing due to continuous data writing by the host, and thus improve the stability of the storage device. Attached Figure Description
[0053] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.
[0054] Figure 1 This is a schematic diagram of a host writing data according to an embodiment of this application;
[0055] Figure 2This is a schematic diagram illustrating the correspondence between user data and physical data provided in an embodiment of this application;
[0056] Figure 3 This is a schematic diagram of the structure of a flash memory device provided in an embodiment of this application;
[0057] Figure 4 This is a schematic diagram of a data write protection framework provided in an embodiment of this application;
[0058] Figure 5 This is a flowchart illustrating a data write protection method provided in an embodiment of this application;
[0059] Figure 6 yes Figure 5 A detailed flowchart of step S502 in the process;
[0060] Figure 7 This is a schematic flowchart illustrating the calculation of the compression ratio of an effective superblock, provided in an embodiment of this application.
[0061] Figure 8 This is a schematic diagram of the overall process of a data writing method provided in an embodiment of this application;
[0062] Figure 9 This is a schematic diagram of the structure of a storage device provided in an embodiment of this application;
[0063] Figure 10 This is a schematic diagram of a data compression process provided in an embodiment of this application;
[0064] Figure 11 This is a flowchart illustrating another data write protection method provided in an embodiment of this application;
[0065] Figure 12 This is a schematic diagram of the overall process of another data write protection method provided in the embodiments of this application;
[0066] Figure 13 This is a flowchart illustrating a method for determining a write protection strategy based on the number of free superblocks, as provided in an embodiment of this application.
[0067] Figure 14A This is a schematic diagram of the capacity distribution of a storage device provided in an embodiment of this application;
[0068] Figure 14B This is a schematic diagram of the capacity distribution of another storage device provided in an embodiment of this application;
[0069] Figure 15 This is a schematic diagram of the structure of a storage device provided in an embodiment of this application;
[0070] Figure 16This is a schematic diagram of the structure of a data write protection system provided in an embodiment of this application. Detailed Implementation
[0071] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.
[0072] It should be noted that, unless there is a conflict, the various features in the embodiments of this application can be combined with each other, all of which are within the protection scope of this application. Furthermore, although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than the module division in the device or the order in the flowchart. Moreover, the terms "first," "second," and "third" used in this application do not limit the data or execution order, but only distinguish identical or similar items with essentially the same function and effect.
[0073] The technical solution of this application will be described in detail below with reference to the accompanying drawings:
[0074] Please see Figure 1 , Figure 1 This is a schematic diagram of a host writing data according to an embodiment of this application;
[0075] like Figure 1 As shown, the process of writing data to the host includes:
[0076] Step S101: The host writes data to the storage device;
[0077] Step S102: The storage device compresses the data;
[0078] Step S103: The storage device writes the compressed data to the storage medium.
[0079] The storage device compresses the data, and the data compression ratio of its compression algorithm is:
[0080] Data compression ratio = Original compressed data size / Export compressed data size;
[0081] The original compressed data size is determined by the user's data format, while the output compressed data size is the result of the user data being compressed by the compression algorithm. Since the output data size is different for different types of data, the data compression ratio is different for different types of data.
[0082] The default compression ratio for storage devices is:
[0083] Preset compression ratio = nominal capacity / total physical capacity.
[0084] It is understandable that due to the uncertainty of compression algorithms in compressing data, user data may be incompressible or have a very small compression ratio. If the compression ratio of all data written by the host is smaller than the preset compression ratio of the storage device, then the storage device may not have enough physical capacity to accommodate the user data under continuous writing. This will cause the amount of data written by the host to exceed the amount of data that can actually be stored physically, and the storage device may crash.
[0085] Please refer to the following: Figure 2 , Figure 2 This is a schematic diagram illustrating the correspondence between user data and physical data provided in an embodiment of this application;
[0086] like Figure 2 As shown, when the data is not compressed, there is a one-to-one correspondence between the logical media address (LMA) and the physical media address (PMA). Both the logical media address and the physical media address are in units of 4KB, meaning that the smallest data unit represented by the logical media address and the physical media address is 4KB.
[0087] When the data is not compressed, one LMA constitutes one PMA for writing to the storage medium, i.e., 1:1;
[0088] After data compression, multiple LMAs form one PMA for writing to the storage medium, i.e., N:1. LMA is used to represent user capacity, and PMA is used to represent physical capacity. Therefore, the ratio of user capacity represented by LMA to physical capacity represented by PMA is N:1. That is, the same physical capacity can store N times the amount of user data, thereby achieving the effect of capacity expansion and increasing the data density per unit physical capacity.
[0089] In this embodiment, the storage device includes a flash memory device that uses a standard hard disk or micro hard disk as the storage medium, or a flash memory device that uses flash memory as the storage medium. The storage device has a compression function, capable of compressing data written by the host, or reading data stored in the storage medium of the storage device and then compressing it. The following description uses a flash memory device as the storage device:
[0090] Please see Figure 3 , Figure 3 This is a schematic diagram of the structure of a flash memory device provided in an embodiment of this application;
[0091] like Figure 3As shown, the flash memory device 100 includes a flash memory medium 110 and a controller 120 connected to the flash memory medium 110. The flash memory device 100 communicates with the host 200 via wired or wireless means to enable data exchange.
[0092] Flash memory medium 110, as the storage medium of flash memory device 100, is also called flash memory, Flash, Flash memory or Flash chip. It is a type of storage device and is a non-volatile memory that can retain data for a long time even without a current supply. Its storage characteristics are equivalent to hard disk, which makes flash memory medium 110 the basis for the storage medium of various portable digital devices.
[0093] The controller 120 includes a data converter 121, a processor 122, a cache 123, a flash memory controller 124, and an interface 125.
[0094] Data converter 121, connected to processor 122 and flash memory controller 124 respectively, is used to convert binary data to hexadecimal data and vice versa. Specifically, when flash memory controller 124 writes data to flash memory medium 110, data converter 121 converts the binary data to be written into hexadecimal data before writing it to flash memory medium 110. When flash memory controller 124 reads data from flash memory medium 110, data converter 121 converts the hexadecimal data stored in flash memory medium 110 into binary data, and then reads the converted data from the binary data page register. Data converter 121 may include a binary data register and a hexadecimal data register. The binary data register can be used to store data converted from hexadecimal to binary, and the hexadecimal data register can be used to store data converted from binary to hexadecimal.
[0095] The processor 122 is connected to the data converter 121, the cache 123, the flash memory controller 124, and the interface 125, respectively. The processor 122 can be connected to the data converter 121, the cache 123, the flash memory controller 124, and the interface 125 via a bus or other means. The processor is used to run non-volatile software programs, instructions, and modules stored in the cache 123, thereby implementing any method embodiment of this application.
[0096] The buffer 123 is mainly used to buffer the read / write commands sent by the host 200 and the read or write data obtained from the flash memory medium 110 according to the read / write commands sent by the host 200.
[0097] The flash controller 124 is connected to the flash media 110, the data converter 121, the processor 122, and the cache 123. It is used to access the back-end flash media 110 and manage various parameters and data I / O of the flash media 110; or, it is used to provide access interfaces and protocols, implement the corresponding SAS / SATA target protocol or NVMe protocol, obtain I / O instructions issued by the host 200, decode and generate internal private data results for execution; or, it is used to be responsible for the core processing of the flash translation layer (FTL).
[0098] Interface 125 connects host 200, data converter 121, processor 122, and buffer 123. It is used to receive data sent by host 200 or data sent by processor 122, so as to realize data transmission between host 200 and processor 122. Interface 125 can be SATA-2 interface, SATA-3 interface, SAS interface, MSATA interface, PCI-E interface, NGFF interface, CFast interface, SFF-8639 interface, and M.2 NVME / SATA protocol.
[0099] Please see Figure 4 , Figure 4 This is a schematic diagram of a data write protection framework provided in an embodiment of this application;
[0100] like Figure 4 As shown, the data is written to a protected frame, including:
[0101] Step S401: The host writes data to the storage device;
[0102] Step S402: The storage device compresses the data;
[0103] Step S403: The storage device writes the compressed data to the storage medium;
[0104] Step S404: Calculate and process the relevant parameters of the storage device;
[0105] Step S405: The storage device reads out the written data and performs compression processing;
[0106] Step S406: The storage device writes the compressed data to the storage medium;
[0107] Step S407: The storage device performs corresponding processing based on the calculation results;
[0108] Step S408: The host performs the corresponding processing.
[0109] As can be seen from the above steps, this application calculates and processes relevant parameters in the storage device during the process of the host writing data to the storage device, and then informs the host to perform corresponding processing based on the calculation results.
[0110] Example 1
[0111] For details, please refer to [link / reference]. Figure 5 , Figure 5 This is a flowchart illustrating a data write protection method provided in an embodiment of this application;
[0112] This data write protection method is applied to storage devices. Specifically, the execution subject of this data write protection method is one or at least two processors of the storage device.
[0113] like Figure 5 As shown, the process of this data write protection method includes:
[0114] Step S501: When the storage device is in write mode, obtain the compression ratio and remaining effective capacity of each effective superblock of the storage device;
[0115] Specifically, when a storage device is in a write state, it means that a sending device sends data to the storage device to write the data into the storage device. The sending device includes devices such as a host and a writing device used to send data to the storage device.
[0116] It is understandable that a storage device includes multiple superblocks (SBLKs), each of which is used to store data. The storage device records information about each superblock, including its sequence number, whether it is a valid superblock, and its compression ratio.
[0117] As you can understand, remaining effective capacity refers to the theoretically remaining capacity that a user can still write, calculated based on the preset compression ratio, i.e., the nominal compression ratio. In other words, it's the capacity that can be continuously written if all subsequent data written by the user maintains the nominal compression ratio. Specifically, remaining effective capacity = remaining physical capacity * preset compression ratio. For example, assuming the remaining physical capacity is 5GB and the preset compression ratio is 2, then the remaining effective capacity is 5GB * 2 = 10GB.
[0118] Step S502: Calculate the first approximate compression ratio based on the compression ratio of each effective superblock;
[0119] It is understood that the approximate compression ratio of a storage device equals the effective user capacity minus the effective approximate physical capacity. However, since there is invalid data in the written data, the effective user capacity cannot be obtained directly, resulting in the storage device calculated using the effective user capacity and the effective approximate physical capacity being inaccurate. Based on this, the embodiments of this application calculate the first approximate compression ratio using the compression ratio of each effective superblock, which helps to improve the accuracy of the compression ratio.
[0120] For details, please refer to [link / reference]. Figure 6 , Figure 6 yes Figure 5 A detailed flowchart of step S502 in the process;
[0121] like Figure 6 As shown, step S502 includes:
[0122] Step S5021: Sum the compression ratios of each effective superblock to obtain the sum of the compression ratios of all effective superblocks;
[0123] Specifically, an effective superblock refers to a superblock that has been used. A storage device consists of used superblocks and free superblocks. Assuming that the storage device includes 5 effective superblocks with compression ratios of 1.2, 1.8, 2.0, 1.0 and 1.0 respectively, the sum of the compression ratios of each effective superblock is: 1.2 + 1.8 + 2.0 + 1.0 + 1.0 = 7.0.
[0124] Step S5022: Divide the sum of compression ratios by the number of effective superblocks to obtain the average compression ratio, and use the average compression ratio as the first approximate compression ratio.
[0125] Specifically, the sum of compression ratios is divided by the number of effective superblocks to obtain the average compression ratio. The average compression ratio is used as the first approximate compression ratio. For example, if the sum of compression ratios is 7.0 and the number of effective superblocks is 5, then the average compression ratio is 7.0 / 5 = 1.4.
[0126] By calculating the average compression ratio of the effective superblocks and using this average as an approximate compression ratio of the storage device, the current compression ratio of the storage device can be better determined, thus enabling a better determination of the storage device's write protection strategy.
[0127] In this embodiment, both the physical media address (PMA) and the logical media address (LMA) are in 4K units. That is, 4K is the smallest data unit represented by the host and the storage medium. When the data is not compressed, one LMA constitutes one PMA write granularity, that is, the LMA and PMA have a 1:1 write relationship. After the data is compressed, several LMAs constitute one PMA write granularity, that is, the LMA and PMA have an N:1 write relationship. Since the LMA can be used to characterize the user capacity and the PMA can be used to characterize the physical capacity, the same physical capacity can store N times the user data, thereby achieving the effect of capacity expansion, that is, increasing the data density per unit physical capacity.
[0128] In this embodiment of the application, the method further includes: calculating the compression ratio of each effective superblock.
[0129] Please refer to the following: Figure 7 , Figure 7 This is a schematic flowchart illustrating the calculation of the compression ratio of an effective superblock, provided in an embodiment of this application.
[0130] like Figure 7 As shown, the process for calculating the compression ratio of the effective superblock includes:
[0131] Step S701: Obtain the number of logical media addresses of all compressed data in each valid superblock and the number of physical media addresses of each valid superblock;
[0132] Specifically, both physical media addresses (PMA) and logical media addresses (LMA) are in 4K units. The number of logical media addresses represents the user capacity, and the number of physical media addresses represents the physical capacity. For example, if the number of logical media addresses for all compressed data in a valid superblock is 120, it means that the user capacity corresponding to the compressed data is 120*4K. If the number of physical media addresses for the valid superblock is 100, it means that the physical capacity corresponding to the valid superblock is 100*4K.
[0133] Step S702: Calculate the compression ratio of each effective superblock based on the number of logical media addresses of all compressed data in each effective superblock and the number of physical media addresses of each effective superblock.
[0134] Specifically, the compression ratio of each effective superblock is calculated based on the number of logical media addresses of all compressed data in each effective superblock and the number of physical media addresses in each effective superblock, including:
[0135] Compression ratio of each effective superblock = number of logical media addresses of all compressed data in each effective superblock / number of physical media addresses in each effective superblock.
[0136] For example: If the number of logical media addresses of all compressed data in a certain effective superblock is 120 and the number of physical media addresses of the effective superblock is 100, then the compression ratio of the effective superblock = the number of LMAs of all compressed data in each effective superblock : the number of PMAs of each effective superblock = 120 / 100 = 1.2.
[0137] Step S503: Determine the write protection strategy of the storage device based on the comparison results of the first approximate compression ratio and the preset compression ratio, and the comparison results of the remaining effective capacity and the capacity threshold.
[0138] Specifically, the first approximate compression ratio is used to characterize the current compression ratio of the storage device, while the preset compression ratio is the ratio of the nominal capacity to the total physical capacity. By comparing the first approximate compression ratio and the preset compression ratio, as well as comparing the remaining effective capacity and the capacity threshold, the write protection strategy of the storage device can be comprehensively determined. The write protection strategy includes controlling the storage device to enter a read-only state, controlling the storage device to enter a compressed state, controlling the storage device to send alarm information, or controlling the storage device to enter a normal state.
[0139] Specifically, the capacity thresholds include a first capacity threshold, a second capacity threshold, and a third capacity threshold. Based on the comparison results of a first approximate compression ratio and a preset compression ratio, and the comparison results of the remaining effective capacity and the capacity thresholds, a write protection strategy for the storage device is determined, including:
[0140] When the first approximate compression ratio is less than or equal to the preset compression ratio, if the remaining effective capacity of the storage device is less than the first capacity threshold, the write protection strategy of the storage device is determined to control the storage device to enter the read-only state, where the remaining effective capacity = remaining physical capacity * preset compression ratio.
[0141] When the first approximate compression ratio is less than or equal to the preset compression ratio, if the first capacity threshold ≤ the remaining effective capacity < the second capacity threshold, then the write protection strategy of the storage device is determined to be to control the storage device to send alarm information, wherein the second capacity threshold is greater than the first capacity threshold.
[0142] When the first approximate compression ratio is less than or equal to the preset compression ratio, if the second capacity threshold ≤ the remaining effective capacity < the third capacity threshold, then the write protection strategy of the storage device is determined to be to control the storage device to enter the compression state. The compression state includes triggering the storage device to read the data already stored in the storage medium of the storage device and compressing the read data in order to write the compressed data into the storage medium of the storage device.
[0143] For details, please refer to [link / reference]. Figure 8 , Figure 8 This is a schematic diagram of the overall process of a data writing method provided in an embodiment of this application;
[0144] like Figure 8 As shown, the overall process of this data writing method includes:
[0145] Step S801: The storage device enters the write state;
[0146] Specifically, the sending device begins writing data to the storage device; for example, the host begins writing data to the storage device.
[0147] Step S802: Calculate the first approximate compression ratio;
[0148] Specifically, the first approximate compression ratio = the sum of the compression ratios of all effective superblocks / the number of effective superblocks.
[0149] Step S803: Is the first approximate compression ratio less than or equal to the preset compression ratio?
[0150] Specifically, it is determined whether the first approximate compression ratio is less than the preset compression ratio, where the preset compression ratio = nominal capacity / total physical capacity.
[0151] If the first approximate compression ratio is less than or equal to the preset compression ratio, proceed to step S804;
[0152] If the first approximate compression ratio is greater than the preset compression ratio, proceed to step S811.
[0153] Step S804: Calculate the remaining effective capacity;
[0154] Specifically, if the first approximate compression ratio is less than or equal to the preset compression ratio, the remaining effective capacity is calculated, where the remaining effective capacity = remaining physical capacity * preset compression ratio, and the remaining physical capacity = total physical capacity - effective physical capacity.
[0155] Step S805: Is the remaining effective capacity less than the first capacity threshold?
[0156] Specifically, it determines whether the remaining effective capacity is less than the first capacity threshold, where the remaining effective capacity = remaining physical capacity * preset compression ratio.
[0157] If the remaining effective capacity is less than the first capacity threshold, proceed to step S806;
[0158] If the remaining effective capacity is greater than or equal to the first capacity threshold, proceed to step S807;
[0159] Step S806: Determine the write protection policy of the storage device to control the storage device to enter a read-only state;
[0160] Specifically, if the remaining effective capacity is less than the first capacity threshold, the write protection strategy for the storage device is determined to control the storage device into a read-only state. Understandably, if the remaining effective capacity is small, the storage device needs to be put into a read-only state in advance to prevent write overload from causing a system crash.
[0161] It is understood that, in this embodiment of the application, while controlling the storage device to enter a read-only state, an alarm message is sent to prompt the sending device that the storage device can no longer be written to.
[0162] Step S807: Is the remaining effective capacity less than the second capacity threshold?
[0163] Specifically, if the remaining effective capacity is greater than or equal to the first capacity threshold, then it is further determined whether the remaining effective capacity is less than the second capacity threshold, wherein the second capacity threshold is greater than the first capacity threshold.
[0164] If the remaining effective capacity is less than the second capacity threshold, proceed to step S808;
[0165] If the remaining effective capacity is greater than or equal to the second capacity threshold, proceed to step S809;
[0166] Step S808: Determine the write protection policy of the storage device to control the storage device to send alarm information;
[0167] Specifically, when the first capacity threshold is less than or equal to the remaining effective capacity and less than the second capacity threshold, the control storage device sends an alarm message to the sending device to inform the user that the storage device has a write overload risk. The sending device includes devices such as the host and the writing device used to send data to the storage device.
[0168] In this embodiment, the storage device includes a processor and a front-end module, which controls the storage device to send alarm information to the sending device, such as sending alarm information to the host. This includes sending alarm information to the front-end module via a remote procedure call (RPC) so that the front-end module forwards the alarm information to the host. The alarm information is transmitted in the form of a queue.
[0169] Step S809: Is the remaining effective capacity less than the third capacity threshold?
[0170] Specifically, if the remaining effective capacity is greater than or equal to the second capacity threshold, then it is further determined whether the remaining effective capacity is less than the third capacity threshold, wherein the third capacity threshold is greater than the second capacity threshold.
[0171] If the remaining effective capacity is less than the third capacity threshold, proceed to step S810;
[0172] If the remaining effective capacity is greater than or equal to the third capacity threshold, proceed to step S811.
[0173] Step S810: Determine the write protection policy of the storage device to control the storage device to enter a compressed state;
[0174] Specifically, when the second capacity threshold ≤ remaining effective capacity < third capacity threshold, the write protection strategy of the storage device is determined to control the storage device to enter the compression state. The compression state includes triggering the storage device to read the data already stored in the storage medium of the storage device and compressing the read data in order to write the compressed data back to the storage medium of the storage device.
[0175] Please refer to the following: Figure 9 , Figure 9 This is a schematic diagram of the structure of a storage device provided in an embodiment of this application;
[0176] like Figure 9 As shown, the storage device 900 includes a first storage medium 901, a cache module 902, and a second storage medium 903.
[0177] It is understood that the storage medium in the embodiments of this application may include multiple media, and no limitation is imposed here.
[0178] In this embodiment of the application, the storage device includes a cache module and at least two storage media, including a first storage medium and a second storage medium. The storage device is triggered to read data already stored in the storage media of the storage device and to compress the read data so as to write the compressed data into the storage media of the storage device.
[0179] For details, please refer to [link / reference]. Figure 10 , Figure 10 This is a schematic diagram of a data compression process provided in an embodiment of this application;
[0180] like Figure 10 As shown, the data compression process includes:
[0181] Step S1001: Read the data from the first storage medium into the cache module;
[0182] By reading data from the first storage medium into the cache module, the data can be compressed in the cache module to speed up the compression process.
[0183] In this embodiment, the cache module includes dynamic random access memory, such as Double Data Rate Synchronous Dynamic Random Access Memory (DDRSDRAM).
[0184] Step S1002: Compress the data in the first storage medium in the cache module, and write the compressed data to the second storage medium.
[0185] In this embodiment of the application, the first storage medium includes NAND chips and the second storage medium includes NAND chips. For example, the first storage medium is NAND chip 1 and the second storage medium is NAND chip 2.
[0186] It is understandable that after the data in the cache module is written to the second storage medium, the data in the first storage medium becomes invalid. Since the data written to the second storage medium is compressed, the same user data occupies less space in the storage device, thus achieving the purpose of expanding capacity.
[0187] In this embodiment, the compression process is performed by the compression module of the storage device. The compression module compresses the data in the cache module to obtain compressed data, and then writes the compressed data into the second storage medium.
[0188] It is understandable that the length of compressed data is determined by the compression algorithm. Different compression algorithms or different data patterns can result in different lengths of compressed data.
[0189] Step S811: Determine the write protection policy of the storage device to control the storage device to enter the normal state.
[0190] Specifically, if the remaining effective capacity is greater than or equal to the third capacity threshold, it indicates that the remaining effective capacity is sufficient and no additional processing is required. At this time, the control storage device enters the normal state, that is, the host writes data to the storage device normally, and the storage device can receive the data written by the host normally.
[0191] In this embodiment, a data write protection method for a compressed storage device is proposed. This method protects the storage device from safe writing by compressing, alarming, and read-only modes. It can protect the storage device from crashing due to the available space being larger than the actual physical space when the data compression ratio is low, thereby improving the security of the storage device.
[0192] In this application embodiment, a data write protection method is provided and applied to a storage device. The method includes: when the storage device is in a write state, obtaining the compression ratio and remaining effective capacity of each effective superblock of the storage device; calculating a first approximate compression ratio based on the compression ratio of each effective superblock; and determining a write protection strategy for the storage device based on a comparison between the first approximate compression ratio and a preset compression ratio, and a comparison between the remaining effective capacity and a capacity threshold. The write protection strategy includes controlling the storage device to enter a read-only state, controlling the storage device to enter a compressed state, controlling the storage device to send alarm information, or controlling the storage device to enter a normal state. The preset compression ratio is defined as nominal capacity / total physical capacity. By determining the write protection strategy for the storage device through the comparison between the first approximate compression ratio and the preset compression ratio, and the comparison between the remaining effective capacity and the capacity threshold, this application can prevent the write volume of the storage device from exceeding the physical writable capacity, solving the problem of storage device crashes caused by continuous data writing by the host, thereby improving the stability of the storage device.
[0193] Example 2
[0194] It should be noted that the relevant content in the embodiments of this application can refer to the content mentioned in Embodiment 1 above, and the same parts will not be repeated here.
[0195] Please refer to the following: Figure 11 , Figure 11 This is a flowchart illustrating another data write protection method provided in an embodiment of this application;
[0196] This data write protection method is applied to storage devices. Specifically, the execution subject of this data write protection method is one or at least two processors of the storage device.
[0197] like Figure 11 As shown, the process of this data write protection method includes:
[0198] Step S1101: When the storage device is in write state, obtain the compression ratio and remaining effective capacity of each effective superblock of the storage device;
[0199] Step S1102: Calculate the first approximate compression ratio based on the compression ratio of each effective superblock;
[0200] Step S1103: Calculate the remaining user capacity and remaining physical capacity;
[0201] Specifically, remaining user capacity = nominal capacity - effective user capacity, and remaining physical capacity = total physical capacity - effective physical capacity.
[0202] It is understandable that remaining user capacity refers to writable user capacity, and remaining physical capacity refers to writable physical capacity. Assuming that a certain storage device has a physical capacity of 4T, a nominal capacity of 6T, an effective user capacity of 3.5T, and an effective physical capacity of 3.5T, then the remaining user capacity is 6T-3.5T=2.5T, and the remaining physical capacity is 4T-3.5T=0.5T.
[0203] Step S1104: Calculate the remaining compression ratio based on the remaining user capacity and remaining physical capacity;
[0204] Specifically, the remaining compression ratio = remaining user capacity / remaining physical capacity. Assuming the remaining user capacity is 2.5T and the remaining physical capacity is 0.5T, then the remaining compression ratio = 2.5T / 0.5T = 5.
[0205] It is understandable that the first approximate compression ratio may have some errors, such as invalid data being added and the logical address of the data being overwritten, which would invalidate the NAND data. Obtaining the original software architecture design would also lead to some errors. Therefore, the main purpose of calculating the remaining compression ratio is to further predict whether the storage device can continue to write a certain amount of user data under the current data compression ratio, so as to comprehensively control the write protection strategy of the storage device.
[0206] Step S1105: Determine the write protection strategy of the storage device based on the comparison results of the first approximate compression ratio and the preset compression ratio, the comparison results of the remaining effective capacity and the capacity threshold, and / or the comparison results of the remaining compression ratio and the preset compression ratio.
[0207] Specifically, based on the comparison results of the first approximate compression ratio and the preset compression ratio, and the comparison results of the remaining effective capacity and the capacity threshold, and / or the comparison results of the remaining compression ratio and the preset compression ratio, a write protection strategy for the storage device is determined, including:
[0208] If the first approximate compression ratio is less than or equal to the preset compression ratio, and the remaining effective capacity of the storage device is less than the first capacity threshold, and the remaining compression ratio is greater than the preset compression ratio, then the write protection strategy of the storage device is determined to control the storage device to enter the read-only state.
[0209] If the first approximate compression ratio is less than or equal to the preset compression ratio, and the first capacity threshold is less than or equal to the remaining effective capacity and the second capacity threshold is less than or equal to the remaining compression ratio, then the write protection strategy of the storage device is determined to be to control the storage device to send alarm information.
[0210] If the first approximate compression ratio is less than or equal to the preset compression ratio, and the second capacity threshold is less than or equal to the remaining effective capacity and the third capacity threshold is less than or equal to the remaining compression ratio, then the write protection strategy of the storage device is determined to be to control the storage device to enter the compression state.
[0211] If the first approximate compression ratio is greater than the preset compression ratio, or the remaining effective capacity is greater than or equal to the third capacity threshold, or the remaining compression ratio is less than or equal to the preset compression ratio, then the write protection strategy for the storage device is determined to control the storage device to enter the normal state.
[0212] Please refer to the following: Figure 12 , Figure 12 This is a schematic diagram of the overall process of another data write protection method provided in the embodiments of this application;
[0213] like Figure 12 As shown, the overall process of this data write protection method includes:
[0214] Step S1201: The storage device enters the write state;
[0215] Step S1202: Calculate the first approximate compression ratio;
[0216] Specifically, the first approximate compression ratio = the sum of the compression ratios of all effective superblocks / the number of effective superblocks.
[0217] Step S1203: Is the first approximate compression ratio less than or equal to the preset compression ratio?
[0218] Specifically, determine whether the first approximate compression ratio is less than or equal to the preset compression ratio. If yes, proceed to step S1204; otherwise, proceed to step S1212.
[0219] Step S1204: Calculate the remaining effective capacity and remaining compression ratio;
[0220] Specifically, the remaining effective capacity = remaining physical capacity * preset compression ratio, where the remaining physical capacity = total physical capacity - effective physical capacity.
[0221] Specifically, the remaining compression ratio = remaining user capacity / remaining physical capacity.
[0222] Step S1205: Is the remaining compression ratio less than or equal to the preset compression ratio?
[0223] Specifically, determine whether the remaining compression ratio is less than or equal to the preset compression ratio. If yes, proceed to step S1212; otherwise, proceed to step S1206.
[0224] Understandably, if the remaining compression ratio is less than or equal to the preset compression ratio, it means that under normal circumstances, the storage device can write data equivalent to the remaining physical capacity * preset compression ratio, that is, the user data that can be written is greater than or equal to the remaining physical capacity * preset compression ratio. At this time, no other processing is required, and the storage device can be controlled to enter the normal state.
[0225] Step S1206: Is the remaining effective capacity less than the first capacity threshold?
[0226] Specifically, if the remaining compression ratio is greater than the preset compression ratio, then it is further determined whether the remaining effective capacity is less than the first capacity threshold. If yes, then proceed to step S1207; if no, then proceed to step S1208.
[0227] In this embodiment of the application, the method further includes:
[0228] Calculate the first capacity threshold. Specifically, the first capacity threshold = first weight * nominal capacity. The first weight can be sent from the sending device to the storage device, or the first weight can be dynamically adjusted according to the current parameters of the storage device, including parameters such as bit error rate. For example, if the first weight is 1%, then the first capacity threshold is 1% * nominal capacity.
[0229] Step S1207: Determine the write protection policy of the storage device to control the storage device to enter a read-only state;
[0230] Step S1208: Is the remaining effective capacity less than the second capacity threshold?
[0231] Specifically, if the remaining effective capacity is greater than or equal to the first capacity threshold, then it is further determined whether the remaining effective capacity is less than the second capacity threshold, wherein the second capacity threshold is greater than the first capacity threshold.
[0232] If the remaining effective capacity is less than the second capacity threshold, proceed to step S1209;
[0233] If the remaining effective capacity is greater than or equal to the second capacity threshold, proceed to step S1210.
[0234] In this embodiment of the application, the method further includes:
[0235] The second capacity threshold is calculated as follows: Second capacity threshold = Second weight * Nominal capacity. The second weight can be sent from the sending device to the storage device, or the second weight can be dynamically adjusted based on the current parameters of the storage device, including parameters such as bit error rate. For example, if the second weight is 10%, then the second capacity threshold is 10% * nominal capacity.
[0236] Step S1209: Determine the write protection policy of the storage device to control the storage device to send alarm information;
[0237] Step S1210: Is the remaining effective capacity less than the third capacity threshold?
[0238] Specifically, if the remaining effective capacity is greater than or equal to the second capacity threshold, then it is further determined whether the remaining effective capacity is less than the third capacity threshold, wherein the third capacity threshold is greater than the second capacity threshold.
[0239] If the remaining effective capacity is less than the third capacity threshold, proceed to step S1210;
[0240] If the remaining effective capacity is greater than or equal to the third capacity threshold, proceed to step S1211.
[0241] In this embodiment of the application, the method further includes:
[0242] The third capacity threshold is calculated as follows: Third capacity threshold = Third weight * Nominal capacity. The third weight can be sent from the transmitting device to the storage device, or the third weight can be dynamically adjusted based on the current parameters of the storage device, including parameters such as bit error rate. For example, if the third weight is 50%, then the third capacity threshold is 50% * nominal capacity.
[0243] Step S1211: Determine the write protection policy of the storage device as controlling the storage device to enter a compressed state;
[0244] Specifically, the content of step S1211 can be found in the relevant content mentioned in the above embodiments, and will not be repeated here.
[0245] Step S1212: Determine the write protection policy of the storage device to control the storage device to enter the normal state.
[0246] Specifically, the content of step S1212 can be found in the relevant content mentioned in the above embodiments, and will not be repeated here.
[0247] In this embodiment of the application, the method further includes: obtaining the number of free superblocks, and determining the write protection strategy of the storage device based on the number of free superblocks.
[0248] For details, please refer to [link / reference]. Figure 13 , Figure 13 This is a flowchart illustrating a method for determining a write protection strategy based on the number of free superblocks, as provided in an embodiment of this application.
[0249] like Figure 13 As shown, the process of determining the write protection policy based on the number of free superblocks includes:
[0250] Step S1301: Obtain the number of free superblocks;
[0251] Specifically, it retrieves the number of free superblocks in the storage device, where free superblocks refer to unused superblocks.
[0252] Step S1302: Is the number of free superblocks less than the first quantity threshold?
[0253] Specifically, it determines whether the number of free superblocks is less than a first quantity threshold, where the first quantity threshold is set according to specific needs, for example, the first quantity threshold is set to 3.
[0254] If the number of free superblocks is less than the first quantity threshold, proceed to step S1303;
[0255] If the number of free superblocks is greater than or equal to the first quantity threshold, proceed to step S1304;
[0256] Step S1303: Determine the write protection policy as controlling the storage device to enter a compressed state;
[0257] Specifically, if the number of free superblocks is less than the first quantity threshold, the write protection strategy of the storage device is determined to control the storage device to enter a compression state in order to accelerate the internal compression of the storage device for capacity expansion.
[0258] Step S1304: Is the number of free superblocks less than the second quantity threshold?
[0259] Specifically, it is determined whether the number of free superblocks in the storage device is less than a second quantity threshold, wherein the second quantity threshold is greater than the first quantity threshold, and the second quantity threshold is set according to specific needs, for example, the second quantity threshold is set to 6.
[0260] If the number of free superblocks is less than the second quantity threshold, proceed to step S1305;
[0261] If the number of free superblocks is greater than or equal to the second quantity threshold, proceed to step S1306.
[0262] Step S1305: Determine the write protection policy as controlling the storage device to send alarm information;
[0263] Specifically, if the number of free superblocks is less than the second quantity threshold, the write protection policy of the storage device is determined to be to control the storage device to send alarm information. For example, the storage device is controlled to send alarm information to the sending device. For example, if the sending device is the host, the storage device is controlled to send alarm information to the host.
[0264] Step S1306: Determine the write protection policy to control the storage device to enter normal state.
[0265] Specifically, if the number of free superblocks is greater than or equal to the second quantity threshold, the write protection policy is determined to control the storage device to enter a normal state.
[0266] It is understood that the first quantity threshold and the second quantity threshold in the embodiments of this application can be set according to specific needs, and are not limited here.
[0267] By using a first quantity threshold and a second quantity threshold to measure whether the number of superblocks in the storage device meets the requirements, this application can determine the write protection strategy of the storage device in advance, thereby improving the stability of the storage device.
[0268] An example illustrating the process of determining the write protection policy:
[0269] Assuming a storage device has a total physical capacity of 4T and a nominal capacity of 6T, the first capacity threshold is 1% * nominal capacity = 1% * 6T = 0.06T, the second capacity threshold is 10% * 6T = 0.6T, and the third capacity threshold is 50% * 6T = 3T.
[0270] At this point, the preset compression ratio = nominal capacity / total physical capacity = 6T / 4T = 1.5;
[0271] (1) When the remaining physical capacity of the storage device is 1T, if the first approximate compression ratio of the storage device is 1.8 > 1.5, it means that the used physical capacity is 3T, that is, the effective physical capacity is 3T, the written user capacity is 3T * 1.8 = 5.4T, that is, the effective user capacity is 5.4T. At this time, the remaining user capacity is 0.6T, and the remaining compression ratio is remaining user capacity: remaining physical capacity = 0.6:1 < 1.5. At this time, the storage device does not need to be processed, that is, the storage device is controlled to enter the normal state.
[0272] (2) When the remaining physical capacity of the storage device is 1T, if the first approximate compression ratio of the storage device is 1 < 1.5, it means that the written user capacity is 3T, that is, the effective user capacity is 3T, the used physical capacity is 3T, that is, the effective physical capacity is 3T, then the remaining user capacity is 6T - 3T = 3T, the remaining physical capacity is 1T, and the remaining compression ratio is user capacity: physical capacity = 3:1 > 1.5. At this time, it is necessary to start immediately to speed up compression, that is, to control the storage device to enter the compression state.
[0273] (3) When the remaining physical capacity of the storage device is 0.5T, if the first approximate compression ratio of the storage device is 1 < 1.5, it means that: the written user capacity is 3.5T, that is, the effective user capacity is 3.5T, the used physical capacity is 3.5T, that is, the effective physical capacity is 3.5T, then the remaining user capacity is 6T - 3.5T = 2.5T, the remaining physical capacity is 0.5T, and the remaining compression ratio is user capacity: physical capacity = 2.5: 0.5 = 5 > 1.5. At this time, an alarm needs to be started immediately and the host needs to be notified, that is, the storage device needs to be controlled to send alarm information to the sending device, for example, to send alarm information to the host.
[0274] (4) When the remaining physical capacity of the storage device is 0.2T, if the first approximate compression ratio of the storage device is still less than the preset compression ratio of 1.5, it will enter read-only mode in advance and notify the host, that is, control the storage device to enter read-only mode and send alarm information to the sending device, for example: send alarm information to the host.
[0275] The following examples further illustrate the capacity distribution of storage devices:
[0276] Please refer to the following: Figure 14A , Figure 14A This is a schematic diagram of the capacity distribution of a storage device provided in an embodiment of this application;
[0277] like Figure 14A As shown, initially, no data has been written to the storage device, the remaining user capacity is 20GB, and the total physical capacity is 10GB, while the nominal capacity is 20GB. Assuming the first weight is 1%, the second weight is 10%, and the third weight is 50%, then:
[0278] First capacity threshold = First weight * Nominal capacity = 1% * 20GB = 0.2GB;
[0279] Second capacity threshold = Second weight * Nominal capacity = 10% * 20GB = 2GB;
[0280] Third capacity threshold = Third weight * Nominal capacity = 50% * 20GB = 10GB.
[0281] At this point, assuming the storage device is always in a low compression ratio state, and the approximate compression ratio of the storage device is always the first approximate compression ratio, for example: the first approximate compression ratio is 1.6, then the maximum amount that the user can write = the first approximate compression ratio * the total physical capacity = 1.6 * 10GB = 16GB;
[0282] Therefore, during the continuous sequential writing of data by the host, the write protection strategy of the storage device is as follows:
[0283] When the host starts writing data, the control of the storage device enters the normal state, that is, the storage device normally receives the data written by the host;
[0284] ① When the host writes 8GB,
[0285] Effective physical capacity = 8GB / 1.6 = 5GB;
[0286] Remaining physical storage capacity = 10GB - 5GB = 5GB;
[0287] The remaining effective capacity is 5GB * 2 = 10GB, reaching the third capacity threshold. The storage device is then put into compression mode, i.e., internal compression acceleration is initiated.
[0288] ② When the host writes 14.4GB,
[0289] Effective physical capacity = 14.4GB / 1.6 = 9GB
[0290] Remaining physical storage capacity = 10GB - 9GB = 1GB
[0291] The remaining effective capacity is 1GB * 2 = 2GB, which reaches the second capacity threshold. The storage device is then controlled to send an alarm message to the sending device to inform the user that the storage device is at risk of overwrite.
[0292] ③ When the host writes 15.84GB,
[0293] Effective physical capacity = 15.84GB / 1.6 = 9.9GB
[0294] Remaining physical storage capacity = 10GB - 9.9GB = 0.1GB
[0295] The remaining effective capacity is 0.1GB * 2 = 0.2GB, which reaches the first capacity threshold. The storage device is then put into read-only mode, meaning that the host cannot write data.
[0296] Please refer to the following: Figure 14B , Figure 14B This is a schematic diagram of the capacity distribution of another storage device provided in an embodiment of this application;
[0297] like Figure 14B As shown, the nominal capacity of the storage device is 20GB, the physical capacity is 10GB, the approximate effective physical capacity is 5GB, the remaining physical capacity is 5GB, the effective user capacity is 7GB, and the remaining user capacity is 13GB.
[0298] The storage device includes 10 superblocks, of which superblocks 0-4 are active superblocks and superblocks 5-9 are free superblocks. The compression ratios of superblocks 0-4 are 1.2, 1.8, 2.0, 1.0 and 1.0, respectively.
[0299] At this point, the nominal capacity of the storage device is 20GB, and the total physical capacity is 10GB. Therefore, the preset compression ratio = nominal capacity / physical capacity = 20GB / 10GB = 2.
[0300] The first approximate compression ratio = the sum of the compression ratios of all effective superblocks / the number of effective superblocks. Specifically, the compression ratios of each effective superblock are summed to obtain the sum of compression ratios as: 1.2 + 1.8 + 2.0 + 1.0 + 1.0 = 7.0. Since the sum of compression ratios is 7.0 and the number of effective superblocks is 5, the average compression ratio is 7.0 / 5 = 1.4, that is, the first approximate compression ratio is 1.4.
[0301] The remaining compression ratio is: remaining user capacity / remaining physical capacity = 13GB / 5GB = 2.6.
[0302] Assuming the first weight is 1%, the second weight is 10%, and the third weight is 50%, then:
[0303] First capacity threshold = First weight * Nominal capacity = 1% * 20GB = 0.2GB;
[0304] Second capacity threshold = Second weight * Nominal capacity = 10% * 20GB = 2GB;
[0305] Third capacity threshold = Third weight * Nominal capacity = 50% * 20GB = 10GB.
[0306] At this point, the first approximate compression ratio is 1.4, and the preset compression ratio is 2.0, meaning the first approximate compression ratio is less than the preset compression ratio. Furthermore, the remaining compression ratio is 2.6, meaning the remaining compression ratio is greater than the preset compression ratio. Also, the remaining effective capacity equals the remaining physical capacity multiplied by the preset compression ratio, which is 5GB multiplied by 2, resulting in 10GB of usable space. Therefore, the remaining effective capacity equals the third capacity threshold. Figure 11 As shown, the write protection policy for the storage device is determined to control the storage device to enter a normal state.
[0307] In this embodiment of the application, by statistically analyzing and calculating the data in the storage device, it is possible to predict in advance whether the compression ratio of the storage device is consistent with the user's expectations. Furthermore, different protection measures can be taken based on different capacity thresholds and remaining effective capacity to prevent downtime and ensure the normal functioning and stable operation of the storage device.
[0308] In this application embodiment, a data write protection method is provided and applied to a storage device. The method includes: when the storage device is in a write state, obtaining the compression ratio and remaining effective capacity of each effective superblock of the storage device; calculating a first approximate compression ratio based on the compression ratio of each effective superblock; calculating a remaining compression ratio based on the remaining user capacity and remaining physical capacity; and determining a write protection strategy for the storage device based on a comparison result between the first approximate compression ratio and a preset compression ratio, a comparison result between the remaining effective capacity and a capacity threshold, and / or a comparison result between the remaining compression ratio and the preset compression ratio. By determining the write protection strategy for the storage device through the comparison results between the first approximate compression ratio and the preset compression ratio, the comparison result between the remaining effective capacity and the capacity threshold, and / or the comparison result between the remaining compression ratio and the preset compression ratio, this application can prevent the write volume of the storage device from exceeding the physical writable capacity, solving the problem of storage device downtime caused by continuous data writing by the host, thereby improving the stability of the storage device.
[0309] Please see Figure 15 , Figure 15 This is a schematic diagram of the structure of a storage device provided in an embodiment of this application;
[0310] like Figure 15 As shown, the storage device 1500 includes one or more processors 1501 and a memory 1502. Wherein, Figure 15 Take a processor 1501 as an example.
[0311] The processor 1501 and the memory 1502 can be connected via a bus or other means. Figure 15 Taking the example of a connection between China and Israel via a bus.
[0312] The memory 1502, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The processor 1501 executes various functional applications and data processing of the data write protection method by running the non-volatile software programs, instructions, and modules stored in the memory 1502, thereby implementing the data write protection method of the above-described method embodiment. This data write protection method can be executed by various electronic devices with certain logic processing capabilities, such as control chips.
[0313] Memory 1502 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 1502 may optionally include memory remotely located relative to processor 1501, and these remote memories may be connected to processor 1501 via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0314] The module is stored in memory 1502. When executed by one or more processors 1501, it performs the data write protection method in any of the above method embodiments, for example, the method described above. Figure 5 The steps shown.
[0315] Please refer to the following: Figure 16 , Figure 16 This is a schematic diagram of the structure of a data write protection system provided in an embodiment of this application;
[0316] like Figure 16 As shown, the data write protection system 1600 includes a sending device 1601 and a storage device 1602. The sending device 1601 is used to send write data to the storage device 1602 so that the storage device 1602 stores the write data.
[0317] In this embodiment, the transmitting device 1601 includes electronic devices capable of transmitting data, such as a host, computer, or terminal. The storage device 1602 includes electronic devices capable of storing data, such as flash memory or non-volatile memory. Data transmission between the transmitting device 1601 and the storage device 1602 is based on a data transmission protocol, such as the NVMe protocol.
[0318] This application also provides a non-volatile computer storage medium storing computer-executable instructions that are executed by one or more processors. For example, the one or more processors can execute the data write protection method in any of the above method embodiments, such as executing the data write protection method in any of the above method embodiments, or executing the steps described above.
[0319] The apparatus or device embodiments described above are merely illustrative. The unit modules described as separate components may or may not be physically separate, and the components shown as module units may or may not be physical units; that is, they may be located in one place or distributed across multiple network module units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0320] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented using software plus a general-purpose hardware platform, or of course, using hardware. Based on this understanding, the above technical solutions, in essence or the parts that contribute to the related technology, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions for a computer device (which may be a personal computer, server, or network device, etc.) to execute the various embodiments or some parts of the embodiments.
[0321] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and not to limit them; under the concept of this application, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of different aspects of this application as described above. For the sake of brevity, they are not provided in detail; although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A data write protection method, characterized by, The method is applied to a storage device, and comprises the following steps: When the storage device is in a write state, obtaining a compression ratio of each valid super block of the storage device and a remaining valid capacity, the compression ratio of the valid super block being a ratio of a number of logical medium addresses of all compressed data of the valid super block to a number of physical medium addresses of the valid super block, and the remaining valid capacity = remaining physical capacity * preset compression ratio, the preset compression ratio = nominal capacity / total physical capacity; According to the compression ratio of each valid super block, calculating a first approximate compression ratio, the first approximate compression ratio being an average value of the compression ratios of all the valid super blocks; According to a comparison result of the first approximate compression ratio and a preset compression ratio, and a comparison result of the remaining valid capacity and a capacity threshold, determining a write protection strategy of the storage device; The write protection strategy comprises controlling the storage device to enter a read-only state, controlling the storage device to enter a compression state, controlling the storage device to send alarm information, or controlling the storage device to enter a normal state.
2. The method of claim 1, wherein, The step of calculating the first approximate compression ratio according to the compression ratio of each valid super block comprises the following steps: Summing the compression ratios of all the valid super blocks to obtain a sum of the compression ratios of all the valid super blocks; Dividing the sum of the compression ratios by the number of the valid super blocks to obtain an average value of the compression ratios, and taking the average value of the compression ratios as the first approximate compression ratio.
3. The method of claim 2, wherein, The method further comprises the following steps: Calculating the compression ratio of each valid super block, specifically comprising the following steps: Obtaining the number of logical medium addresses of all the compressed data of each valid super block and the number of physical medium addresses of each valid super block; According to the number of logical medium addresses of all the compressed data of each valid super block and the number of physical medium addresses of each valid super block, calculating the compression ratio of each valid super block.
4. The method of claim 3, wherein, The step of calculating the compression ratio of each valid super block according to the number of logical medium addresses of all the compressed data of each valid super block and the number of physical medium addresses of each valid super block comprises the following step: The compression ratio of each valid super block = the number of logical medium addresses of all the compressed data of each valid super block / the number of physical medium addresses of each valid super block.
5. The method of claim 1, wherein, The capacity threshold comprises a first capacity threshold, and the step of determining the write protection strategy of the storage device according to the comparison result of the first approximate compression ratio and the preset compression ratio, and the comparison result of the remaining valid capacity and the capacity threshold comprises the following step: When the first approximate compression ratio is less than or equal to the preset compression ratio, if the remaining valid capacity of the storage device is less than the first capacity threshold, it is determined that the write protection strategy of the storage device is to control the storage device to enter the read-only state.
6. The method of claim 5, wherein, The capacity threshold comprises a second capacity threshold, and the step of determining the write protection strategy of the storage device according to the comparison result of the first approximate compression ratio and the preset compression ratio, and the comparison result of the remaining valid capacity and the capacity threshold comprises the following step: When the first approximate compression ratio is less than or equal to the preset compression ratio, if the first capacity threshold is less than or equal to the remaining effective capacity and the remaining effective capacity is less than the second capacity threshold, it is determined that the write protection strategy of the storage device is to control the storage device to send alarm information.
7. The method of claim 6, wherein, The capacity threshold includes a third capacity threshold, and the write protection strategy of the storage device is determined according to the comparison result of the first approximate compression ratio and the preset compression ratio, and the comparison result of the remaining effective capacity and the capacity threshold, and the write protection strategy of the storage device is determined according to the comparison result of the first approximate compression ratio and the preset compression ratio, and the comparison result of the remaining effective capacity and the capacity threshold, and / or the comparison result of the remaining compression ratio and the preset compression ratio. When the first approximate compression ratio is less than or equal to the preset compression ratio, if the second capacity threshold is less than or equal to the remaining effective capacity and the remaining effective capacity is less than the third capacity threshold, it is determined that the write protection strategy of the storage device is to control the storage device to enter a compression state, and the compression state includes triggering the storage device to read out data stored in the storage medium of the storage device and performing compression processing on the read-out data to write the compressed data into the storage medium of the storage device.
8. The method of claim 7, wherein, The storage device includes a cache module and at least two storage media, and the at least two storage media include a first storage medium and a second storage medium, and the triggering the storage device to read out data stored in the storage medium of the storage device and performing compression processing on the read-out data to write the compressed data into the storage medium of the storage device includes: reading out the data in the first storage medium to the cache module; performing compression processing on the data in the first storage medium in the cache module and writing the compressed data into the second storage medium.
9. The method according to claim 7 or 8, characterized in that, The write protection strategy of the storage device is determined according to the comparison result of the first approximate compression ratio and the preset compression ratio, and the comparison result of the remaining effective capacity and the capacity threshold, and the write protection strategy of the storage device is determined according to the comparison result of the first approximate compression ratio and the preset compression ratio, and the comparison result of the remaining effective capacity and the capacity threshold, and / or the comparison result of the remaining compression ratio and the preset compression ratio. When the remaining effective capacity is greater than or equal to the third capacity threshold or the first approximate compression ratio is greater than the preset compression ratio, it is determined that the write protection strategy of the storage device is to control the storage device to enter a normal state, and the normal state includes that the host normally writes data to the storage device, and the third capacity threshold is greater than the second capacity threshold.
10. The method of claim 1, wherein, The method further includes: calculating a remaining user capacity and a remaining physical capacity; calculating a remaining compression ratio according to the remaining user capacity and the remaining physical capacity; determining the write protection strategy of the storage device according to the comparison result of the first approximate compression ratio and the preset compression ratio, and the comparison result of the remaining effective capacity and the capacity threshold, and / or the comparison result of the remaining compression ratio and the preset compression ratio; The remaining compression ratio = remaining user capacity / remaining physical capacity, the remaining user capacity = nominal capacity-effective user capacity, and the remaining physical capacity = total physical capacity-effective physical capacity.
11. The method of claim 10, wherein, The method further comprises: acquiring the number of free super blocks of the storage device; if the number of free super blocks is less than a first quantity threshold, determining the write protection strategy of the storage device as controlling the storage device to enter a compression state; if the number of free super blocks is less than a second quantity threshold, determining the write protection strategy of the storage device as controlling the storage device to send alarm information, wherein the first quantity threshold is less than the second quantity threshold. comprises:
12. The method of claim 1, wherein, at least one processor; and a memory connected to the at least one processor in communication; wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the data write protection method according to any one of claims 1-12.
13. A storage device, comprising:
Citation Information
Patent Citations
Memory system
CN111722794A
Data compression method for SSD
CN114003169A