[ detailed description ] embodiments
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
At present, a flash memory device mainly includes a flash memory medium and a flash memory controller, as shown in fig. 1, fig. 1 is a schematic diagram of an internal structure of a flash memory device according to an embodiment of the present invention.
The flash memory operation takes a page (page) as a read-write unit and a physical block (block) as an erasing unit, and medium access inside the device provides multiple levels of parallelism such as channels, particle encapsulation, particle flash memory chips and the like. The flash memory particle packages are organized in a multi-channel mode inside the device, each channel can be connected with a plurality of particle packages, and the transmission channels are shared among the particle packages but can independently execute instructions. Each particle package contains two or more particles therein, each particle being independently selectable to execute an instruction. The interior of the particle can be divided into a plurality of slices, and each slice comprises a register buffer with the size of one page and is used for temporarily storing read-write data.
The flash memory controller is mainly responsible for address mapping, garbage recovery and wear leveling. The flash memory relieves the erasing delay of the flash memory unit before writing in a remote updating mode, because the erasing times of the flash memory unit are limited, the flash memory controller balances the erasing times among the physical blocks in the device through a wear-leveling algorithm, and simultaneously, the garbage recovery algorithm selects the physical blocks with high erasing efficiency as much as possible to recover so as to control the writing amplification.
It is understood that the flash memory controller of the flash memory device can store data evenly into the different physical blocks, thereby improving the health status of the flash memory device as a whole. However, the importance of data is not considered during the data storage process, resulting in some important data (such as file system data) being allocated to the physical blocks with poor health status, resulting in the important data being lost. Since some data itself is far more valuable than the flash memory device itself, it is more cost effective to improve the protection of the data itself.
Based on this, please refer to fig. 2, fig. 2 is a schematic flow chart of a data storage method based on a flash memory according to an embodiment of the present invention. The flash memory may specifically be a device such as a USB disk (USB flash disk) or an SSD, and may specifically be composed of a flash memory controller and a flash memory medium, where the function of the flash memory controller may specifically be implemented by a control chip, the function of the flash memory medium may specifically be implemented by a memory chip, and the memory chip may be a flash chip, and the flash type chip may specifically be a NAND flash chip. As shown in fig. 2, the method includes:
s101, acquiring the health state of each idle physical block.
The physical block is a physical area on the flash memory medium, where data is stored, and the physical block is a unit of storage of data on a disk and is a minimum unit of operation used when a file is operated in upper software. The physical block is composed of sectors, and one physical block is read from the hardware device, and one or more sectors are actually read from the hardware device. The physical blocks correspond to logical blocks, and the logical blocks correspond to files. In this embodiment, the health status of each physical block is predetermined, and when there is a data storage request, the health status of the free physical block is obtained.
The health status of the physical block can reflect the service life of the flash memory device executing the method and the working performance of the flash memory device in reading/writing data to a certain extent.
As shown in fig. 3, the specific process of determining the health status of the physical block includes:
s11, acquiring historical access times of the physical block;
s12, when the historical access times are larger than or equal to preset times, acquiring the R/B signal waiting time when the physical block is accessed for the last time;
and S13, determining the health state of the physical block according to the R/B signal waiting time.
In this embodiment, each physical block has a corresponding area record history access number. When the historical access times are larger than or equal to the preset times, checking the R/B signal waiting time length, judging the health state of the physical block according to the length of the time length, when the waiting time length is longer, indicating that the health state of the physical block is worse, and when the waiting time length is shorter, indicating that the health state of the physical block is better. When the historical access times of the physical block are less, the physical block is relatively new, the difference between the R/B signal waiting time lengths of the physical block is relatively small, and the R/B signal waiting time length when the physical block is accessed for the first time can be directly used to reduce the calculation steps.
The R/B signal represents ready/busy, the output of the R/B can display the state of the flash memory chip, when the R/B is at low level, the R/B signal represents that programming, erasing or random reading operation is in progress, and after the operation is finished, the R/B signal automatically returns to high level. Whether the program, erase or random read operation is completed can be determined by the R/B signal, and if it is "busy", it indicates that the program, erase or random read operation is in progress, and if it is "ready", it indicates that the operation is completed.
Wherein the R/B signal waiting duration is checked, i.e. the R/B signal waiting duration when the physical block was last accessed is checked.
Wherein, the latest R/B signal waiting time comprises: the R/B signal waiting time of the last time when the data is written into the physical block; or the R/B signal waiting time of the last time when the physical block is read. That is, when the last operation of the physical block is to read data, the R/B signal waiting time in the process of reading data is checked, and when the last operation of the physical block is to write data, the R/B signal waiting time in the process of writing data is checked.
The health state of the physical block is determined according to the R/B signal waiting time, the longer the R/B signal waiting time is, the longer the operation time is, the longer the R/B signal waiting time is, along with the increase of the number of write operations of the flash memory chip, the longer the R/B signal waiting time is, and therefore the health state of the physical block is deteriorated. Conversely, the shorter the R/B signal latency, the better the health of the physical block.
In this embodiment, some data (such as the total capacity, the storage space occupied by the file system, the storage space occupied by the system overhead, the user habit, and the like) may be combined, the specific health state of the physical block may be determined according to the obtained R/B signal waiting duration, and the corresponding relationship between the R/B signal waiting duration and the specific health state of the physical block may be recorded. For example, the R/B signal latency is 10 CPU clock cycles, the corresponding physical block health status is at a first level, the R/B signal latency is 7 CPU clock cycles, the corresponding physical block health status is at a second level, the R/B signal latency is 4 CPU clock cycles, the corresponding physical block health status is at a third level, and so on. The first level indicates that the R/B signal waiting time of the physical block is greater than the initial R/B signal waiting time of the physical block and the redundant time is within a first preset range, the second level indicates that the R/B signal waiting time of the physical block is greater than the initial R/B signal waiting time of the physical block and the redundant time is within a second preset range, and the third level indicates that the R/B signal waiting time of the physical block is greater than the initial R/B signal waiting time of the physical block and the redundant time is within a third preset range. The duration of the first preset range is greater than that of the second preset range, and the duration of the second preset range is greater than that of the third preset range.
It should be noted that, since the R/B signal waiting duration when the physical block is accessed last time is obtained, and the health status of the physical block is determined by using the last R/B signal waiting duration, the determination result of the health status of the physical block is a dynamic updating process, and the health status of the physical block is dynamically updated according to the number of times of use of the physical block and the last R/B signal waiting duration.
S102, determining the importance level of the data to be stored.
In this embodiment, the flash memory device executing the method may actively identify the data type of the data to be stored, so as to determine the importance level of the data to be stored according to the data type. For example, when the data to be stored belongs to metadata of a file system, the data to be stored is important data by default. Among them, the file system is a method and a data structure used by an operating system to specify files on a storage device (usually a disk, and also a NAND Flash based solid state disk) or a partition, that is, a method of organizing files on a storage device. For example, the storage file system of the NAND flash memory is mainly classified by its structure into a conventional file system based on a block device and a log-structured file system, which are the most commonly used file systems for a disk memory, such as the FAT file system and the EXT2 file system; log-structured file systems include JFFS2, YAFFS, CFFS, and the like.
In this embodiment, the flash memory device executing the method may further determine the importance level of the data to be stored according to the user identifier of the data to be stored. Only after the user performs the user-defined labeling on the importance level of the data to be stored, the flash memory device can judge the importance level of the data according to the label labeled by the user during the data storage, and the process is a passive process for determining the importance level of the data to be stored.
It should be noted that, in addition to the two methods for determining the level of the data to be stored, the importance level of the data to be stored may be determined by other methods.
S103, storing the data to be stored into the corresponding physical block according to the importance level of the data to be stored and the health state of the physical block.
In this embodiment, after determining the importance level of the data to be stored and the health status of the free physical blocks, the most important data to be stored is written into the free physical block with the best health status, and the second most important data to be stored is written into the free physical block with the better health status. The correspondence between the importance levels of the data to be stored and the health states of the physical blocks may be preset, for example, the first-level important data to be stored corresponds to the physical block with the best health state, the second-level important data to be stored corresponds to the physical block with the better health state, the third-level important data to be stored corresponds to the physical block with the general health state, and the fourth-level important data to be stored corresponds to the physical block with the worse health state, where the first-level important data, the second-level important data, the third-level important data, and the fourth-level important data are sorted from high to low according to the importance levels of the data. After the importance level of the data to be stored is determined, the corresponding physical block is automatically searched according to the importance level.
In the following, a common file system FAT is taken as an example, as shown in fig. 4, where data such as a super block, a block description, a bit table, a node table, and the like are used as metadata, and a data block is used for storing real data. Since the access efficiency of metadata has an important influence on the performance of the entire file system, and its corruption can cause data access failure, metadata is important data, and accordingly, the metadata is stored into a physical block in a good health state. Further, after a predetermined time, when it is detected that the health status of the physical block stored in the metadata is degraded, the physical block stored in the metadata may be adjusted to match the metadata with other physical blocks with good health status.
The embodiment of the invention provides a data storage method based on a flash memory, which comprises the steps of acquiring the health state of an idle physical block and the important level of data to be stored, and storing the data to be stored according to the important level of the data to be stored and the health state of the physical block. According to the embodiment, important data can be stored in the physical block with a good health state, and the safety of the important data during storage is improved.
Referring to fig. 5, fig. 5 is a schematic flowchart illustrating a data storage method based on a flash memory according to another embodiment of the present invention. As shown in fig. 5, the method includes:
s201, receiving a data storage request corresponding to data to be stored, wherein the data storage request comprises at least one logic number;
s202, searching for a free physical block according to the data storage request;
s203, acquiring the health state of each idle physical block;
s204, determining the importance level of the data to be stored;
s205, storing the data to be stored into a corresponding physical block according to the importance level of the data to be stored and the health state of the physical block;
s206, establishing mapping between the physical block stored by the data to be stored and the logic number contained in the data storage request corresponding to the data to be stored.
The main difference between this embodiment and the above-mentioned embodiment is that after data storage is completed according to the importance level of the data to be stored and the health status of the physical block, a mapping between the physical block and the logical number of the data to be stored is also established according to the storage result. The mapping may be used, when there is a data reading request, to find a physical block corresponding to the logical number according to the logical number carried in the data reading request and by combining a mapping relationship between the physical block and the logical number, and then read data in the physical block.
It should be noted that, in the above data reading process, the health status of the physical block may also be updated according to the waiting time of the R/B signal in the data reading process, and when the health status of the physical block is updated and the location of the data storage is changed, the mapping table is updated accordingly.
Wherein, the logic number is a number corresponding to the logic block. The specific file system manages a logical space, which is similar to a large array, each element in the array is the basic unit of file system operation, i.e. a logical block, generally the logical block is numbered from 0, and the logical block is continuous and corresponds to the logical block, i.e. a physical block.
The embodiment of the invention provides a data storage method based on a flash memory, which comprises the steps of acquiring the health state of an idle physical block and the important level of data to be stored, storing the data to be stored according to the important level of the data to be stored and the health state of the physical block, and establishing corresponding mapping according to the storage result. On one hand, the embodiment can store important data into a physical block with a good health state, so that the safety of the important data during storage is improved, and on the other hand, corresponding data is obtained according to the mapping relation during reading data.
Referring to fig. 6, fig. 6 is a schematic structural diagram of a data storage device based on a flash memory according to an embodiment of the present invention. As shown in fig. 6, the apparatus 30 includes: an acquisition module 33, a determination module 34 and a storage module 35.
The obtaining module 33 is configured to obtain a health state of each idle physical block; a determining module 34 for determining the importance level of the data to be stored; and the storage module 35 is configured to store the data to be stored into the corresponding physical block according to the importance level of the data to be stored and the health state of the physical block.
In this embodiment, the obtaining module 33 and the determining module 34 are respectively connected to the storage modules, the obtaining module 33 sends the obtained health status of each idle physical block to the storage module 35, the determining module 34 sends the determined importance level of the data to be stored to the storage module 35, and the storage module 35 stores the data to be stored according to the health status of the physical block and the importance level of the data to be stored.
The health state of the physical block is specifically determined according to the R/B signal waiting time when the physical block is accessed last time.
Wherein the physical block was accessed the last time comprises: a read operation or a write operation.
In some embodiments, referring to fig. 7, the main difference between fig. 7 and fig. 6 is that the apparatus 30 further includes: a receiving module 31, a searching module 32 and a establishing module 36.
The receiving module 31 is configured to receive a data storage request corresponding to data to be stored, where the data storage request includes at least one logic number; a searching module 32, configured to search for a free physical block according to the data storage request; the establishing module 36 is configured to establish a mapping between the physical block in which the data to be stored is stored and the logic number included in the data storage request corresponding to the data to be stored.
It should be noted that, as the contents of information interaction, execution process, and the like between the modules in the flash memory-based data storage device in the embodiment of the present invention are based on the same concept as the method embodiment of the present invention, the specific contents are also applicable to the flash memory-based data storage device. The respective modules in the embodiments of the present invention can be implemented as separate hardware or software, and the combination of the functions of the respective units can be implemented using separate hardware or software as necessary.
The embodiment of the invention provides a data storage device based on a flash memory, which stores data to be stored according to the important level of the data to be stored and the health state of a physical block by acquiring the health state of an idle physical block and the important level of the data to be stored, and establishes a corresponding mapping table according to the storage result. On one hand, the embodiment can store important data into a physical block with a good health state, so that the safety of the important data during storage is improved, and on the other hand, corresponding data is obtained according to the mapping table during reading data, so that the data reading speed is higher to a certain extent due to the fact that the data storage is combined with the health state of the physical block.
Referring to fig. 8, fig. 8 is a schematic structural diagram of a flash memory chip according to an embodiment of the present invention. As shown in fig. 8, the flash memory chip 40 includes: the controller 41 and the memory 42 are electrically connected, and the controller 41 and the memory 42 are electrically connected.
The memory 42, which is a non-volatile computer-readable storage medium, may be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as program instructions/modules corresponding to the flash-based data storage method in the embodiment of the present invention (for example, the obtaining module 33, the determining module 34, and the storing module 35 shown in fig. 6). The controller 41 executes various functional applications of the server and data processing, i.e., implements the flash-based data storage method of the above-described method embodiment, by running the non-volatile software programs, instructions, and modules stored in the memory 42.
The memory 42 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the flash memory-based data storage device, and the like.
The one or more modules are stored in the memory 42 and, when executed by the one or more controllers 41, perform the flash-based data storage method of any of the method embodiments described above, e.g., performing the functions of method steps S101-S103 of fig. 2, method steps S11-S13 of fig. 3, method steps S201-S206 of fig. 5, modules 33-35 of fig. 6, and modules 31-36 of fig. 7, described above.
The product can execute the method provided by the embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
Embodiments of the present invention provide a non-volatile computer-readable storage medium storing computer-executable instructions for an electronic device to perform any of the above-described method embodiments of the flash-based data storage method, for example, performing the above-described functions of method steps S101 to S103 in fig. 2, method steps S11 to S13 in fig. 3, method steps S201 to S206 in fig. 5, modules 33 to 35 in fig. 6, and modules 31 to 36 in fig. 7.
Embodiments of the present invention provide a computer program product comprising a computer program stored on a non-volatile computer-readable storage medium, the computer program comprising program instructions that, when executed by a computer, cause the computer to perform a flash-based data storage method of any of the above-described method embodiments, e.g., to perform the functions of method steps S101-S103 of fig. 2, method steps S11-S13 of fig. 3, method steps S201-S206 of fig. 5, modules 33-35 of fig. 6, and modules 31-36 of fig. 7, described above.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a general hardware platform, and certainly can also be implemented by hardware. It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware related to instructions of a computer program, which can be stored in a computer readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; within the idea of the invention, also technical features in the above embodiments or in different embodiments may be combined, steps may be implemented in any order, and there are many other variations of the different aspects of the invention as described above, which are not provided in detail for the sake of brevity; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.