This Application claims priority of Taiwan Patent Application No. 100143912, filed on Nov. 30, 2011, the entirety of which is incorporated by reference herein.
1. Field of the Invention
The invention relates to flash memories, and more particularly to data access of flash memories.
2. Description of the Related Art
A flash memory is usually installed in an electronic apparatus for data storage. The flash memory comprises a plurality of blocks for data storage. Because the flash memory can maintain data stored therein while power supplied to the flash memory is switched off, and a portable electronic device has a limited power supply, the flash memory is often used in a portable electronic device for data storage.
A controller controls data access of a flash memory. When a host sends a write command to the controller, the controller writes data to the flash memory according to the write command. When the host sends a read command to the controller, the controller reads data from the flash memory according to the read command, and then sends the data back to the host.
When a host reads data from a flash memory, the host often reads data from specific blocks of the flash memory at a high frequency. For example, the host may read a specific block at a frequency of several thousand Hz. An ordinary block, however, can tolerate predetermined times of data reading. When a read count of a block is greater than a threshold (such as 100,000 times), the data read from the block easily develops errors. The controller, however, cannot control the data reading of the host, and can only read data from the blocks of the flash memory according to instructions from the host. Because data read at a high frequency by the host is often system data with high importance, if the system data read out from the flash memory comprises errors, the errors in the system data induces severe errors to the operations of the host. Thus, to avoid errors in the reading of data from a flash memory, a data access method for a flash memory device is therefore required.
The invention provides a flash memory device. In one embodiment, the flash memory device is coupled to a host, and comprises a flash memory, a controller, and a random access memory. The flash memory comprises a plurality of blocks for data storage. The random access memory stores a read count table for recording read counts of the blocks. When the read counts of a plurality of original blocks are greater than a threshold according to the read count table, the controller obtains a plurality of spare blocks from the flash memory as mirror blocks respectively corresponding to the original blocks, and copies a portion of a plurality of data pages of the original blocks to the mirror blocks whenever the original blocks are read until all of the data pages of the original blocks have been copied to the mirror blocks.
The invention further comprises a data access method for a flash memory device. In one embodiment, the flash memory device is coupled to a host and comprises a flash memory and a random access memory, and the flash memory comprises a plurality of blocks for data storage. First, a read count table for recording read counts of the blocks is stored in the random access memory. When the read counts of a plurality of original blocks are greater than a threshold according to the read count table, a plurality of spare blocks are obtained from the flash memory as mirror blocks respectively corresponding to the original blocks. Whenever the original blocks are read, a portion of a plurality of data pages of the original blocks are copied to the mirror blocks, until all of the data pages of the original blocks have been copied to the mirror blocks
A detailed description is given in the following embodiments with reference to the accompanying drawings.
The invention can be more fully understood by reading the subsequent detailed description and examples with references made to the accompanying drawings, wherein:
The following description is of the best-contemplated mode of carrying out the invention. This description is made for the purpose of illustrating the general principles of the invention and should not be taken in a limiting sense. The scope of the invention is best determined by reference to the appended claims.
Referring to
The flash memory 106 comprises a plurality of blocks 121˜12N for data storage. The random access memory 104 stores a read count table 110. The frequency at which blocks of the flash memory 106 are read by the host is referred to as read counts corresponding to the blocks and are recorded in the read count table 110. Referring to
The controller 102 updates the read count table 110 stored in the random access memory 104 with time. For example, when the controller 102 receives a read command from the host, the controller 102 determines a target block to be read from the blocks of the flash memory 106 according to a read address of the read command. The controller 102 then increases the read count of the target block in the read count table 110 by one. The read count table 110 therefore always faithfully indicates the read frequency of the blocks of the flash memory 106.
When the controller 102 determines that a read count of an original block is greater than a threshold, the host therefore reads the original block at a high frequency, and the data stored in the original block may be damaged. To prevent data stored in the original block from being damaged, the controller 102 obtains a spare block from the flash memory 106 as a mirror block corresponding to the original block. The controller 102 then gradually copies the data stored in the original block to the mirror block. When all of the data stored in the original block have been copied to the mirror block, if the host wants to read data from the original block again, the controller 102 reads data from the mirror block in place of the original block. The read count of the original block is therefore not increased, and the data stored in the original block is prevented from being damaged.
For example, the controller 102 shown in
In one embodiment, physical block addresses of mirror blocks corresponding to original blocks are further recorded in the read count table 110. For example, in addition to read counts and logical block addresses of blocks, the read count table 200 further stores physical addresses of mirror blocks and a flag. The flag indicates whether a mirror block corresponding to an original block exists in the flash memory 106. When the flag corresponding to a target original block is set to be true, the controller 102 reads data from the mirror block instead of the target original block. For example, assume that a threshold for a read count is 300. Because the read counts of the blocks with logical addresses 100 and 200 are both 350, which is greater than the threshold 300, mirror blocks corresponding to the blocks with logical addresses 100 and 300 are built, and flags corresponding to the blocks with logical addresses 100 and 300 are set to be true.
Ordinarily, an original block comprises a plurality of pages. It requires a long time period to read all data pages from the original block and then write the data pages to the mirror blocks. According to the specification of data transmission between the controller 102 and the host, the controller 102 can only process a write command sent by the host within a limited time period. To prevent the time period in which the controller 102 processes a write command from becoming longer than the limit threshold, whenever the controller 102 receives a read command for reading a target original block from the host, the controller 102 reads a single data page from the target original block, and writes the single data page to a target mirror block corresponding to the target original block, thereby gradually implementing data copied from the target original block to the target mirror block.
Referring to
Referring to
When the read count of the original block is greater than the threshold (step 306), the controller 102 determines whether a mirror block corresponding to the original block exists in the flash memory 106 (step 314). In one embodiment, the controller 102 checks the flag corresponding to the original block in the read count table 110 to determine whether the mirror block corresponding to the original block exists in the flash memory 106. When the mirror block corresponding to the original block exists in the flash memory 106, the controller 102 reads the mirror block to obtain target data (step 324), and sends the target data back to the host to complete execution of the read command (step 326).
When the read count of the original block is greater than the threshold (step 306), and a mirror block corresponding to the original block does not exist in the flash memory 106 (step 314), data copy from the original block to the mirror block has not been completed. Thus, the controller 102 reads the original block to obtain target data (step 316), and sends the target data back to the host to complete execution of the read command (step 318). In addition, because data copy from the original block to the mirror block has not been completed, the controller 102 reads a data page from the original block (step 320), and writes the data page to the mirror block during the remaining time for processing the read command (step 322). If the data page is a last page of the original block, the controller 102 sets the value of the flag corresponding to the original block in the read count table 110 to be “true”, to indicate that the mirror block corresponding to the original block has been built.
After the mirror block is built, the data stored in the mirror block may also be damaged due to reading at a high frequency. When the controller 102 reads the data copy from the mirror block and finds that the data copy comprises errors which cannot be corrected by an error correction process, the controller 102 rebuilds a second mirror block corresponding to the original block. First, the controller 102 obtains a spare block from the flash memory 106 as the second mirror block. Whenever the host sends a read command for reading the original block to the controller 102, the controller 102 copies a data page from the original block to the second mirror block, until all data pages of the original block have been copied to the second mirror block. After the second mirror block is built, the controller 102 can read data from the second mirror block in place of the original block to execute a read command for reading the original block.
When power to the host is switched off, the flash memory device 100 cannot obtain power from the host, and the random access memory 104 cannot keep the read count table 110 stored therein. The controller 102 therefore writes the read count table 110 from the random access memory 104 to the flash memory 106 before power to the host is switched off. Referring to
While the invention has been described by way of example and in terms of preferred embodiment, it is to be understood that the invention is not limited thereto. On the contrary, it is intended to cover various modifications and similar arrangements (as would be apparent to those skilled in the art). Therefore, the scope of the appended claims should be accorded the broadest interpretation so as to encompass all such modifications and similar arrangements.
Number | Date | Country | Kind |
---|---|---|---|
100143912 | Nov 2011 | TW | national |