The application relates in general to a method for managing a memory and computer readable medium thereof, and more particularly to a method for managing a non-violate memory and computer readable medium thereof.
Recently, information storage devices based on a non-violate memory, such as a flash memory, have been widely applied to computer platforms and portable devices. Such a device is regarded as a substitute for an information storage device based on magnetic disk memory, serving as a storage medium of a computer for storing operating systems and data files.
A flash memory differs with a magnetic disk memory in that the magnetic disk memory has the ability of random data access. In order to overwrite data in the flash memory, existing data must be deleted first. In other words, as for a flash memory having a number of memory cells, the memory cells should be returned to an initial state by erasing data stored therein. Besides, in order to modify data stored in a memory cell, a number of steps are required, such as the steps of reading the stored data in the memory cell, modifying the read data, and writing the modified data in an empty memory cell of the flash memory.
Due to the above mentioned characteristics, a mapping table is usually used to manage the flash memory. The mapping table can be referred to as a table that associates a logical address with a physical address. In practice, the logical address requested to read or write is changed into a physical address with reference to the mapping table, and data in the corresponding physical address of the flash memory is read or written. However, the mapping table may result in incorrect data access when power of the flash memory is suddenly cut-off. In other words, mapping table may fail in correctly associating the logical address with the physical address in the event of power failure or improper behaviors to power off the flash memory, thereby lowering the stability of the information storage device based on a flash memory.
There is provided an approach to enhance the stability for the flash memory, in which a mapping table is produced and corrected by scanning the entire flash memory when an information storage device based on the flash memory is booted. This approach, however, consumes lots of time in scanning the entire the flash memory, thereby reducing the efficiency of managing the flash memory. Therefore, it is a subject of the industrial endeavors to manage the flash memory with high efficiency and stability.
Embodiments being provided are directed to a method for managing a non-violate memory and computer readable medium thereof, which produces a mapping table by determining the validity of data for partial blocks of the non-violate memory, thereby increasing the efficiency of managing the non-violate memory and enhancing stability for the non-violate memory. Therefore, the data stored in the non-violate memory can be accessed correctly even in the event of power failure or an improper behavior to power off the non-violate memory.
An exemplary embodiment of a method for managing a non-violate memory is provided. The non-violate memory has a number of blocks, and each block has a number of sub-blocks. The method includes a number of steps. First, a last physical address is obtained. The last physical address corresponds to a sub-block which is close to another sub-block where data is newly stored. Next, it is determined, for each sub-block of at least one block, the validity of data being stored. The at least one block is at least one neighboring block of a block which contains the corresponding sub-block of the last physical address. Then, a mapping table is produced according to the step of determining the validity of data.
Another exemplary embodiment of a computer readable medium having computer executable data is provided. The computer executable data comprises executing codes and when executed by an electronic device, causes the electronic device to perform the method for managing a non-violate memory mentioned above.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosed embodiments, as claimed.
Embodiments of this application provide a method for managing a non-violate memory, in which a mapping table is produced by determining the validity of data for partial blocks of the non-violate memory. As compared to a conventional approach which produces the mapping table by scanning the entire memory, the present method for managing the non-violate memory is capable of increasing the efficiency of managing the non-violate memory while enhancing stability for the non-violate memory. Therefore, the present method allows the data stored in the non-violate memory to be accessed correctly even in the event of power failure or an improper behavior to power off the non-violate memory.
Refer to
Next, as shown in the step S120, the processor 221 determines the validity of stored data for each sub-block of at least one block. The at least one block can be at least one neighboring block of the block BL2 containing the sub-block BL2, such as the blocks BL1 to BL3. The processor 221 scans the at least one block, such as the blocks BL1 to BL3, and determines the validity of data being stored therein. The step S120 is performed to identify those data being determined as invalid, thereby enhancing stability for the non-violate memory. Then, as shown in the step S130, the processor 221 produces a mapping table according to the step S120 of determining the validity of data.
In response to a previous command for writing the non-violate memory 210, the processor 221 may store incomplete data in some sub-blocks which is regarded as being invalid when an abnormal event is triggered. A triggering of the abnormal event means that power failure is occurred, or an improper behavior to power off the non-violate memory is conducted, such as a behavior which a user conducts to remove the non-violate memory from the host system without requesting a command in advance. As such, when the non-violate memory system 200 is booted thereafter, the processor 221 can utilize the last physical address which is stored prior to the abnormal event to scan the neighboring blocks of the corresponding block, so as to identify the most possible place where invalid data might be stored. In this way, the non-violate memory system 200 can produce the mapping table by scanning partial blocks of the non-violate memory 210 instead of scanning the entire non-violate memory 210, thereby increasing the efficiency of managing the non-violate memory 210 while enhancing stability for the non-violate memory 210. Moreover, because the mapping table is produced according to the valid data stored in the non-violate memory 210, the non-violate memory system 200 are assured to utilize the mapping table to correctly associate a logical address with a corresponding physical address. Therefore, the present embodiment allows the data stored in the non-violate memory 210 to be accessed correctly even in the event of power failure or an improper behavior to power off the non-violate memory 210.
The steps S120 and S130 shown in
As shown in
Specifically, as shown in
For example, the assistant information being stored includes at least one of a logical address LA, a time mark TM, and a sequential length SL. As for each sub-block, the logical address LA is converted to the corresponding physical address PA with reference to the mapping table MT, and is stored in the spare area of the corresponding sub-block of the physical address PA. The time mark TM indicates the order of data being stored in the corresponding data area. In other words, the time mark TM indicates the time at which a command is requested to write data to the corresponding data area. The sequential length SL indicates the length of data being sequentially stored in a portion of sub-blocks. In practice, when a command for sequentially writing data to the non-violate memory 210 is received, such as a direct memory access (DMA) command for sequentially writing data to a sequence of sub-blocks, identical assistant information will be stored in the corresponding spare areas of the sub-blocks.
In an exemplary embodiment, the validity of stored data is determined according to at least one of the logical address LA, the time mark TM, and the sequential length SL, which is shown in
In this embodiment, when the processor 221 performs the step S420, it scans the assistant information to identify a sequence of sub-blocks in which identical assistant information are stored. In this way, the processor 221 can identify the two sub-blocks of the physical addresses of 304 and 305, in which identical assistant information including logical addresses of 100, time marks of 1500, and sequential lengths of 4 are stored. Next, for the two sub-blocks of the physical addresses of 304 and 305, the processor 221 determines the validity of data by comparing a length L of the two sub-blocks, which equals to 2, and the sequential length of 4, which is stored in one of the corresponding spare areas thereof. Because the sequential length SL is larger than the length L of the two sub-blocks (i.e., 4>2), the processor 221 determines the data being stored in the sub-blocks of the physical addresses of 304 and 305 as invalid.
In another exemplary embodiment, the validity of stored data is determined according to a last time mark LTM and the time mark TM as shown in
In this embodiment, when the processor 221 performs the step S420, it determines the validity of data stored in the corresponding data area by comparing the last time mark LTM and the time mark TM and for each sub-block of the block BL2. If any time mark is larger than the last time mark, which may indicate that power failure is occurred during a previous operation of the non-violate memory 210, so that the processor 221 determines the data being stored in those sub-blocks with larger time marks as invalid.
After the step S420 of determining the validity of data, if the stored data of each sub-block is determined as valid, the method proceeds to step S432. In the step S432, the processor 221 reads the mapping table 600 from the non-violate memory 210, regarding the mapping table 600 as a correct one that associates a logical address with a physical address for the non-violate memory 210. On the other hand, if the stored data of each sub-block is determined as invalid in the step S420, the method proceeds to steps S434 and S436. In the step S434, the processor 221 reads the mapping table 600 from the non-violate memory 210. In the step S436, the processor 221 corrects the mapping table according the assistant information, so as to produce a correct mapping table that associates a logical address with a physical address for the non-violate memory 210. Therefore, the data stored in the non-violate memory 210 can be accessed correctly according to the correct mapping table.
Next, the method enters step S440, in which the processor 221 receives commands CMD requested from the host system 230. The commands CMD can be request to read, write, or any one known to those of ordinary skill in the art. After that, in step S450, the processor 221 stores the last physical address LPA in the non-violate memory 210. As for the embodiment utilizing the last time mark LTM, when the last physical address LPA is stored in the step S450, the last time mark LTM is also stored, as shown in the step S450.
Besides, an embodiment of a computer readable medium having computer executable data is further provided, which comprises executing codes and when executed by an electronic device, causes the electronic device to perform the method for managing a non-violate. The computer readable medium of this embodiment includes, for example but non-limitedly, an optical information storage medium or a magnetic information storage medium. The optical information storage medium may be CD, DVD, HD-DVD, blue-ray DVD or the like. The magnetic information storage medium may be a floppy disk drive, a hard disk drive, a magnetic tape drive, a magnetic optical drive or the like. In addition, the computer readable medium also includes program codes that can be transferred through the network/transmission media (e.g., the air).
According to the present embodiments of the application, a method for managing a non-violate memory and computer readable medium thereof can produce a mapping table by determining the validity of data for partial blocks of the non-violate memory 210, thereby increasing the efficiency of managing the non-violate memory 210 and enhancing stability for the non-violate memory 210. Therefore, the data stored in the non-violate memory 210 can be accessed correctly even in the event of power failure or an improper behavior to power off the non-violate memory 210.
It will be appreciated by those skilled in the art that changes could be made to the disclosed embodiments described above without departing from the broad inventive concept thereof. It is understood, therefore, that the disclosed embodiments are not limited to the particular examples disclosed, but is intended to cover modifications within the spirit and scope of the disclosed embodiments as defined by the claims that follow.