1. Technology Field
The present invention generally relates to a data writing method, and more particularly, to a method for writing data into a rewritable non-volatile memory and a memory controller and a memory storage apparatus using the same.
2. Description of Related Art
Along with the widespread of digital cameras, cell phones, and MP3 in recently years, the consumers' demand to storage media has increased drastically. Rewritable non-volatile memory is one of the most adaptable storage media to portable electronic products (for example, notebook computers) due to its many characteristics such as data non-volatility, low power consumption, small volume, non-mechanical structure, and fast access speed. A solid state drive (SSD) is a storage apparatus which uses a flash memory as its storage medium. Thereby, the flash memory industry has become a very important part of the electronic industry in recent years.
A flash memory module has a plurality of physical blocks, and each of the physical blocks has a plurality of physical pages, wherein data has to be written into a physical block according to the sequence of the physical pages. Besides, a physical page storing data has to be erased before it is used again for writing data. In particular, because physical block is the smallest erasing unit and physical page is the smallest programming (i.e., writing) unit, a flash memory module is usually managed by grouping the physical blocks thereof into a data area and a spare area.
Physical blocks in the data area are used for storing data written by a host system. To be specific, a memory management circuit converts a logical access address accessed by the host system into a logical page of a logical block and maps the logical page of the logical block to a physical page of a physical block in the data area. Namely, in the management of the flash memory module, the physical blocks in the data area are considered as used physical blocks (for example, containing data written by the host system). The memory management circuit may record the mapping relationship between the logical blocks and the physical blocks in the data area in a logical block-physical block mapping table, wherein the logical pages of a logical block are sequentially corresponding to the physical pages of a physical block mapped to the logical block.
Physical blocks in the spare area are used for substituting physical blocks in the data area. To be specific, as described above, a physical block storing data has to be erased before it is used for writing data again, and a physical block in the spare area is used for writing the update data and substituting the physical block originally mapped to the logical block. Accordingly, the physical blocks in the spare area are blank or available blocks (i.e., no data is recorded therein or data recorded therein is marked as invalid data).
Namely, the physical pages of the physical blocks in the data area and the spare area are alternatively mapped to the logical pages of the logical blocks for storing data written by the host system. For example, the memory management circuit of a storage apparatus selects one or more physical blocks from the spare area as substitute physical blocks, and when the logical access address into which the host system is about to write an update data is corresponding to a specific logical page of a specific logical block in the storage apparatus, the memory management circuit of the storage apparatus writes the update data into a physical page of the substitute physical blocks. In addition, the memory management circuit records that this physical page stores update data of a specific logical page in a redundant bit area of the physical page or a data mapping table, and the memory management circuit marks the physical page in the data area that is originally mapped to the logical page as invalid.
Particularly, if the number of available physical blocks in the spare area is smaller than a predetermined threshold, while executing a write command, the memory management circuit has to perform a data merging procedure in order to prevent the physical blocks in the spare area from being exhausted. To be specific, during the data merging procedure, the memory management circuit gets a blank physical block from the spare area and copies valid data in the substitute physical block and in the physical block in the data area that belongs to the same logical block into the selected physical block, so that the substitute physical block or the physical block in the data area that stores only invalid data can be erased and associated with the spare area. Because during the data merging procedure, the memory management circuit has to search for the valid data belonging to the same logical block and copy the valid data belonging to the same logical block into the blank physical block, the time spent by the memory management circuit for executing a write command is considerably prolonged. Thereby, how to shorten the execution time of a write command has become one of the major subjects in the industry.
Nothing herein should be construed as an admission of knowledge in the prior art of any portion of the present invention. Furthermore, citation or identification of any document in this application is not an admission that such document is available as prior art to the present invention, or that any reference forms a part of the common general knowledge in the art.