Embodiment
Below in conjunction with specification drawings and specific embodiments, the invention will be further described.
The management method embodiment of NVM
In the present embodiment, this NVM comprises a plurality of Physical Page, and a plurality of Physical Page are divided into data page and free page, and each Physical Page comprises top margin and data field.
As shown in Figure 1, be the schematic flow sheet of the management method embodiment of NVM of the present invention, the method can comprise the steps:
Step 11, by the page header that scans whole Physical Page, set up data page look-up table and free page look-up table in internal memory;
Wherein, the data page look-up table is for setting up the mapping from the logical page number (LPN) of data page to the physical page number of data page, and the free page look-up table is for storing the physical page number of free page; Preferably, this step is carried out when system powers on; Inside save as volatile memory;
Step 12, a free page pointer that points to a physical page number in the free page look-up table is set;
Step 13, when carrying out the write operation of target data page, write top margin and data according to the free page look-up table in the free page corresponding in the physical page number of free page pointed, wipe the data page corresponding to physical page number of target data page according to the data page look-up table, the physical page number of the free page that in the physical page number of target data page in the data page look-up table and free page look-up table, idle page pointer points to is exchanged to the next physical page number of configuration free page pointed free page look-up table.
In step 13, the logical page number (LPN) that is input as the target data page of write operation.While writing data, according to the free page pointer, search the physical page number that the free page look-up table obtains free page, calculate top margin, then according to the physical page number of free page, find free page in NVM, data and top margin are write in free page; Next, find the physical page number of target data page according to the data page look-up table, find the data page corresponding to physical page number of this target data page in NVM, then this data page is wiped.
In step 13, search time that free page look-up table and data page look-up table spend with respect to writing data and wipe the time that data spend and can ignore in NVM in internal memory.
In the present embodiment, carry out write operation and only need to carry out once page write operation and page erase operation once to NVM, need to write 4 times and wipe twice NVM with respect to carrying out a write operation in prior art, greatly save the running time, improve the efficiency of writing data.Because the number of operations to NVM has reduced, improved the life-span of NVM.
In addition, owing to having adopted the free page pointer to realize free page rotary press system, even each NVM data write, all focus on same logical address, the probability that each Physical Page is written into data is
the quantity that N is free page, be equivalent to the life-span of NVM has been improved to N+1 doubly, thus the life-span of greatly having improved NVM.
Further, in step 11, when data page look-up table and free page look-up table are set up in execution, while according to page header, judging the improper end of write operation last time, the execute exception handling procedure.Further, exception handler can comprise following two kinds of situations:
Situation 1, according to page header, judge in writing the process of data or power down in the process of obliterated data, the Physical Page that will write the Physical Page of partial data or wipe partial data is wiped as free page, then the physical page number of this free page is stored in the free page look-up table, thereby by the integrality with the assurance data by incomplete data erase.
Situation 2, according to page header judge after writing data, wipe before power down, will write the Physical Page of new data as data page, set up the mapping of the logical page number (LPN) of this data page to the physical page number of this data page in the data page look-up table, the Physical Page of not wiping is wiped as free page,, the physical page number of this free page is stored in the free page look-up table.
Alternatively, in step 11, during the page header of whole Physical Page of scan N VM, can adopt the mode of sequential scanning to read the page header of whole Physical Page or adopt the mode of random non-sequential scanning to read the page header of whole Physical Page.When the mode that adopts sequential scanning reads the page header of whole Physical Page, the idle Physical Page look-up table obtained is always inserted look-up table to the physical page number of free page according to a definite sequence, and like this, some Physical Page may always first have been used and write data; For fear of this situation, in step 12, for the free page pointer distributes a random number, make the free page pointer point at random a physical page number in the free page look-up table, like this, can choose randomly a Physical Page data writing from free page according to this free page pointer in step 13.
Alternatively, when carrying out the write operation of target data page, Physical Page corresponding to physical page number of judging the target data page according to the data page look-up table is blank page, in the direct Physical Page corresponding in the physical page number of target data page, write data, until after all having write once, then perform step 13 to all data pages.Wherein blank page means that this Physical Page never write data.
Alternatively, in order to save memory headroom, the data page look-up table be take the physical page number that the logical page number (LPN) of data page is the index stores data page, sets up in this way the mapping from the logical page number (LPN) of data page to the physical page number of data page.Now, in actual implementation procedure, also data page look-up table and free page look-up table can be synthesized to a table, and needn't be placed on separately two memory modules.
Alternatively, in the present embodiment, when carrying out the read operation of target data page, the reading out data the Physical Page corresponding from the physical page number of target data page according to the data page look-up table.The logical page number (LPN) that is input as the target data page of this step and page offset address.Particularly, the logical page number (LPN) that is input as the target data page of read operation and page offset address, the logical page number (LPN) of target data page is delivered to the data page look-up table, obtain the physical page number of target data page, according to the physical page number of target data page and page offset address, go in NVM to read the data in data page corresponding to the physical page number of target data page.
Alternatively, when the write operation that carries out the target data page or read operation, if be input as the logical address of target data page, the present embodiment can also comprise the steps: that the logical address according to the target data page calculates logical page number (LPN) and the page offset address of target data page.Particularly, the business's of logical page number (LPN)=(logical address/logical page (LPAGE) length) integral part, logical page (LPAGE) length=Physical Page length-Physical Page top margin length.For example: if Physical Page length is 256-byte, Physical Page top margin length is 8-byte, and logical page (LPAGE) length is 248-byte.
Describe the course of work of the present embodiment in detail below by an instantiation.
As shown in Figure 2, for a principle schematic of writing data instance in the management method embodiment of NVM of the present invention, NVM comprises 12 Physical Page: Physical Page 0-11, wherein 8 Physical Page are initialized to data page, 4 Physical Page are initialized to free page, and the addressing mode of NVM is physical page number+page offset address.Each NVM Physical Page comprises top margin and data field, and the length of top margin is 8 bytes, and the length of data field equals logical page (LPAGE) length.Wherein, top margin comprises logical page number (LPN), idle marker, meter digital, the first error-detecging code EDC1, trough RFU and the second error-detecging code EDC2; Wherein, the first error-detecging code EDC1 is used for the data except the second error-detecging code EDC2 to top margin and carries out error detection, the second error-detecging code EDC-2 is for carrying out error detection to the data of data field, meter digital is for writing and counted page according to logical page number (LPN), same logical page number (LPN) is carried out to write operation one time, this meter digital is once counted, and according to meter digital, can judge that the data of which Physical Page are up-to-date.For example: meter digital adopts 2 bit cycle counts, counting sequence is: 00-01-10-11-00, if corresponding two Physical Page of same logical page number (LPN), the meter digital of these two Physical Page is respectively 00 and 01, the data of the Physical Page that can to determine meter digital be 01 are up-to-date, and the data of the Physical Page that meter digital is 00 are old.
When system powers on, sequential scanning NVM sets up data page look-up table and free page look-up table in internal memory, wherein, and physical page number corresponding to sequential storage logical page (LPAGE) 0-7 in the data page look-up table, physical page number corresponding to storage free page 0-3 in the free page look-up table.The free page pointer points to the physical page number of free page 1 correspondence at random.For example: by the top margin of scanning Physical Page 5, obtaining its corresponding logical page number (LPN) is 0, fills in physical page number 5 in the form that is 0 in the data page look-up table index.Alternatively, during the top margin of the some Physical Page in scan N VM, adopt the first error-detecging code EDC1 to carry out error detection to top margin, if check out the top margin mistake, enter exception handler.Exception handler is specially: judge the power down in the process of data writing or obliterated data of this Physical Page, this Physical Page is erased to free page and the physical page number of this Physical Page is stored in the free page look-up table.
The write operation carried out is: write 3344 in logical page (LPAGE) 5, this write operation be input as logical address and data 3344, concrete execution step is as follows:
Step 21, according to the free page look-up table, obtain the corresponding physical page number 0 of free page 1 of free page pointed, output physical page number 0;
Step 22, according to logical address calculate logical page number (LPN) 5 and the page offset address;
Step 23, according to the data page look-up table, obtain the corresponding physical page number 7 of logical page number (LPN) 5, output physical page number 7;
Step 24, calculate new top margin, according to the page offset address, data 3344 and new top margin are write in the Physical Page 0 of physical page number 0 correspondence; Wherein, the meter digital in new top margin equals meter digital in the top margin of Physical Page 7+1.
Step 25, wipe the Physical Page 7 of physical page number 7 correspondences;
Step 26, renewal data page look-up table, be updated to 0 by the physical page number of logical page (LPAGE) 5 correspondences;
Step 27, renewal free page look-up table, be updated to 7 by the physical page number of free page 1 correspondence;
The physical page number of step 28, distribution free page pointed free page 2 correspondences.
If write data perform step 24 process in the data that write in causing Physical Page 0 of power down imperfect, in next time, power on while setting up the data page look-up table, just there will be two physical page number is the situation of physical page number 0 and 7 corresponding logical page number (LPN)s 5, now, can judge that by the EDC1 in the top margin of Physical Page 0 and 7 and EDC2 the data in Physical Page 0 are wrong respectively, and the data in Physical Page 7 are correct, then, by the data erase in Physical Page 0, physical page number 0 is stored in the free page look-up table, physical page number 7 is stored in the data page look-up table, thereby guarantee the integrality of data.
If in execution of step 24, power down before execution step 25, be that data in Physical Page 0 and 7 are all complete, but the data in Physical Page 0 are up-to-date, in next time, power on while setting up the data page look-up table, also there will be two physical page number is the situation of physical page number 0 and 7 corresponding logical page number (LPN)s 5, now, at first judge that by the EDC1 in the top margin of Physical Page 0 and 7 and EDC2 the data in Physical Page 0 and 7 are all correct, then, judge that according to the meter digital in top margin the data in Physical Page 0 are up-to-date, data in Physical Page 7 are old, finally by the data erase in Physical Page 7, deposit physical page number 7 in the free page look-up table, physical page number 0 is deposited in the data page look-up table, thereby guarantee that on the basis guaranteed data integrity data are up-to-date.
If be that in the process of obliterated data, the data of power down in causing Physical Page 7 are not wiped totally in execution step 25, in next time, power on while setting up the data page look-up table, also may occur that two physical page number are the situation of physical page number 0 and 7 corresponding logical page number (LPN)s 5, now, can judge that by the EDC1 in the top margin of Physical Page 0 and 7 and EDC2 the data in Physical Page 0 are correct respectively, and the data in Physical Page 7 are wrong, then, by the data erase in Physical Page 7, physical page number 7 is stored in the free page look-up table, physical page number 0 is stored in the data page look-up table, thereby guarantee the integrality of data.
While reading the data of logical page (LPAGE) 5 in schematic diagram shown in Fig. 2, according to logical address, calculate logical page number (LPN) 5 and page offset address, logical page number (LPN) 5 is delivered to the data page look-up table, obtain corresponding physical page number 7, according to physical page number 7 and page offset address, go in NVM to read the data in Physical Page 7.
The management devices embodiment of NVM
In the present embodiment, NVM can comprise a plurality of Physical Page, and a plurality of Physical Page are divided into data page and free page, and each Physical Page comprises top margin and data field.
As shown in Figure 3, be the structural representation of the management devices embodiment of nonvolatile memory of the present invention, this device can comprise that look-up table is set up module 32, pointer arranges module 33 and the first data writing module 34.
Wherein, look-up table is set up module 32 for scanning the page header of whole Physical Page, set up data page look-up table and free page look-up table in internal memory, wherein, the data page look-up table is for setting up the mapping from the logical page number (LPN) of data page to the physical page number of data page, and the free page look-up table is for storing the physical page number of free page.Preferably, look-up table is set up module 32 and is scanned when system powers on, because these two look-up tables are that the page header according to NVM re-establishes when powering at every turn, so they leave in the internal memory of volatile memory.Pointer arranges module 33 for a free page pointer that points to a physical page number of free page look-up table is set.The first data writing module 34 is for when carrying out the write operation of target data page, according to write top margin and data in the not busy page look-up table free page corresponding in the physical page number of free page pointed, wipe the data page corresponding to physical page number of target data page according to the data page look-up table, the physical page number of the free page that in the physical page number of target data page in the data page look-up table and free page look-up table, idle page pointer points to is exchanged, control the next physical page number of free page pointed free page look-up table.
In the first data writing module 34, the logical page number (LPN) that is input as the target data page of write operation.The first data writing module 34 is when writing data, search the free page look-up table according to logical page number (LPN), obtain the physical page number of free page, find free page according to the physical page number of this free page in NVM, then data and top margin are write in free page, then search the data page look-up table according to logical page number (LPN), obtain the physical page number with the target data page, then by the physical page number of target data page, corresponding data page is wiped.Search time that free page look-up table and data page look-up table spend with respect to writing data and wipe the time that data spend and can ignore in NVM in internal memory.
Alternatively, the mode that this device can adopt software, hardware circuit or software and hardware circuit to combine realizes.
The course of work of the present embodiment is as follows: when NVM powers on, look-up table is set up module 32 by the page header of the whole Physical Page of scanning, set up data page look-up table and free page look-up table in internal memory, wherein, the data page look-up table is for setting up the mapping from the logical page number (LPN) of data page to the physical page number of data page, the free page look-up table is for storing the physical page number of free page, and pointer arranges module 33 a free page pointer that points to a physical page number in the free page look-up table is set.When carrying out the write operation of target data page, write data page corresponding to physical page number that top margin and data based data page look-up table are wiped the target data page in the first data writing module 34 free page corresponding in the physical page number of free page pointed according to the free page look-up table, then the physical page number of the free page that in the physical page number of target data page in the data page look-up table and free page look-up table, idle page pointer points to is exchanged, finally control the next physical page number of free page pointed free page look-up table.
In the present embodiment, often write a secondary data, only need 34 couples of NVM of the first data writing module to carry out once page write operation and page erase operation once, need to write 4 times and wipe twice NVM with respect to carrying out a write operation in prior art, greatly save the running time, improved the efficiency of writing data.Because the number of operations to NVM has reduced, also improved the life-span of NVM.
Further, the present embodiment can also comprise abnormality processing module 35, set up module 32 with look-up table and be connected, and while for set up information that module 32 provides according to look-up table, judging the improper end of write operation last time, the execute exception handling procedure.Further, abnormality processing module 35 can comprise the first power down process unit 351 and the second power down process unit 352, wherein, power down in the process of writing data or the process in obliterated data is judged for the information of setting up module 35 according to look-up table and providing in the first power down process unit 351, and the Physical Page that will write the Physical Page of partial data or wipe partial data is wiped and the physical page number of this Physical Page is stored in the free page look-up table; The second power down process unit 352 for the information of setting up module 32 according to look-up table and providing judge after writing data, wipe before power down, in the data page look-up table, set up the mapping of the logical page number (LPN) of the Physical Page of preserving new data to physical page number, the Physical Page of preserving legacy data is wiped and the physical page number of this Physical Page is stored in the free page look-up table.
For example: the top margin of Physical Page comprises logical page number (LPN), idle marker, meter digital, the first error-detecging code and the second error-detecging code; Wherein, the first error-detecging code is used for the data except the second error-detecging code to top margin and carries out error detection, and the second error-detecging code is for the data of data field are carried out to error detection, and meter digital is for writing and counted page according to logical page number (LPN).After look-up table is set up module 32 scanning top margins, judge that according to the first error-detecging code in top margin whether top margin is correct, if top margin mistake, the physical page number of this Physical Page is sent to abnormality processing module 35, abnormality processing module 35 is judged the power down in the process of writing data or wiping data of Physical Page corresponding to this physical page number, wipe Physical Page corresponding to this physical page number, this physical page number is stored in the free page look-up table.When look-up table is set up module 32 and is set up the data page look-up table, if there is the top margin of the corresponding logical page number (LPN)s of two physical page number and Physical Page corresponding to two physical page number correct situation all, look-up table is set up module 32 can offer abnormality processing module 35 by two physical page number, abnormality processing module 35 is according to these two physical page number, obtain top margin and the data of corresponding Physical Page, can judge that according to the EDC2 in top margin whether the data in the data field of Physical Page are correct, the error in data of another Physical Page if the data in the data field of a Physical Page are correct, can judge that according to the meter digital in top margin the data in which Physical Page are new, if store the error in data of the Physical Page of new data, can judge power down in writing the process of data, if store the error in data of the Physical Page of legacy data, can judge power down in the process of wiping data, no matter be power down or power down in the process of wiping data in writing the process of data, the Physical Page of abnormality processing module 35 obliterated data mistakes also stores physical page number in the free page look-up table into, by data, the physical page number of correct Physical Page stores in the data page look-up table, if the data in two Physical Page are all correct, can judge that according to the meter digital in top margin the data in which Physical Page are new, the physical page number that stores the Physical Page of new data is stored in the data page look-up table, wipe the Physical Page that stores legacy data and physical page number is stored in free page.
Alternatively, when look-up table is set up the page header of the whole Physical Page of module 32 scanning, can adopt the mode of sequential scanning to read the page header of whole Physical Page or adopt the mode of random non-sequential scanning to read the page header of whole Physical Page.When scan module 31 adopts the mode of sequential scanning to read the page header of whole Physical Page, the idle Physical Page look-up table obtained is always inserted look-up table to the physical page number of free page according to a definite sequence, like this, some Physical Page may always first have been used and write data; For fear of this situation, pointer arranges module 33 can comprise random number generation unit 331 and pointer setting unit 332, and wherein, random number generation unit 331 is for generating random number; Pointer setting unit 332, for random number being distributed to the free page pointer, makes the free page pointer point at random a physical page number in the free page look-up table; Like this, the first data writing module 34 can be chosen a Physical Page data writing randomly according to this free page pointer from free page.
Alternatively, the present embodiment can also comprise the second data writing module 36, for when carrying out the write operation of target data page, judge that according to the data page look-up table target data page is as blank page, write data in the target data page, until after all having write once, then carry out write operation by the first data writing module 34 to all data pages.Wherein, blank page means that this Physical Page never write data.
Alternatively, in order to save memory headroom, the data page look-up table be take the physical page number that the logical page number (LPN) of data page is the index stores data page, sets up in this way the mapping from the logical page number (LPN) of data page to the physical page number of data page.Alternatively, in actual implementation procedure, also data page look-up table and free page look-up table can be synthesized to a table.
Alternatively, the present embodiment can also comprise data read through model 37, for when carrying out the read operation of target data page, according to data page look-up table reading out data from the target data page.
Alternatively, when the write operation that carries out the target data page or read operation, if be input as the logical address of target data page, the present embodiment can also comprise computing module 38, with the first data writing module 34, the second data writing module 36, with data read through model 37, be connected, for the logical address according to the target data page, calculate logical page number (LPN) and the page offset address of target data page.Particularly, the business's of logical page number (LPN)=(logical address/logical page (LPAGE) length) integral part, logical page (LPAGE) length=Physical Page length-Physical Page top margin length.For example: if Physical Page length is 256-byte, Physical Page top margin length is 8-byte, and logical page (LPAGE) length is 248-byte.
Finally it should be noted that: above embodiment is only unrestricted in order to technical scheme of the present invention to be described, although with reference to preferred embodiment, the present invention is had been described in detail, those of ordinary skill in the art is to be understood that, can modify or be equal to replacement technical scheme of the present invention, and not break away from the spirit and scope of technical solution of the present invention.