Embodiment
The embodiment of the invention provides a kind of flash memory data processing method and device, is used to improve the performance of data random writing.
See also Fig. 1, flash memory data processing method first embodiment comprises in the embodiment of the invention:
101, according to the target data inquiry source data to be updated that gets access to;
In the present embodiment, when the data of certain one page are upgraded in need be to the flash data piece, at first can obtain new data, i.e. target data is afterwards again according to the position enquiring source data to be updated of the required storage of this target data.
For example, when the user needs to replace a file in operating system, (be specifically as follows the user and pasted a file that filename is identical, and selected " covering "), then operating system can be known the position of this document correspondence flash memory from the position that the user pastes, and read the data that originally are stored in this position in the flash memory, can obtain source data to be updated.
102, described target data is write in first data page that presets Blank data block, the data page at described source data place is labeled as invalid page or leaf;
After having determined source data to be updated, in the Blank data block group that presets, obtain a Blank data block, target data is write in some data pages of this Blank data block, be recorded as first data page.
And the data page at source data place is labeled as invalid page or leaf, concrete mark mode can for: in the label of this data page or attribute field, insert invalid flag, this invalid flag is used to indicate this data page invalid, promptly temporarily can not carry out read-write operation to this data page, need to prove, in actual applications, the mode that specifically marks invalid page or leaf can also have a variety of, does not limit herein.
The list item of the described invalid page or leaf in the page or leaf level logical mappings table that 103, will preset replaces with the list item of described first data page.
Because the data page with the source data place in the step 102 is labeled as invalid page or leaf, for guaranteeing that the data in original and the related data page of this data page were kept perfectly, then can be in the page or leaf level logical mappings table that presets will this list item of invalid page replace with the list item of first data page.
Record the logical address of the data page that respectively stores data in the page or leaf level logical mappings table in the present embodiment, physical address, and the incidence relation between each data page.
In the present embodiment, the list item of the invalid page or leaf in the page or leaf level logical mappings table is replaced with the list item of first data page, can make the data in the invalid page or leaf of data replacement in the data page of winning, and originally the incidence relation between each data page remained unchanged, and had promptly realized the renewal of data.
In the present embodiment, get access to after the target data, target data is write in first data page that presets Blank data block, and the data page at source data place is labeled as invalid page or leaf, the list item of the invalid page or leaf in the page or leaf level logical mappings table that also will preset simultaneously replaces with the list item of first data page, therefore, in the process of Data Update, need not the data block at invalid page or leaf place is wiped, and directly adopt alternative this invalid page or leaf of first data page in the Blank data block to carry out data storage, therefore save the operation of Data Update, thereby improved the performance of data random writings.
See also Fig. 2 (a), flash memory data processing method second embodiment comprises in the embodiment of the invention:
201, search Blank data block is set up page or leaf level logical mappings table;
In the present embodiment, when system powers on, each physical data block is traveled through, inquires about not the physical data block of record data and the physical data block that has been wiped free of, with the physical data block of described not record data and the physical data block that has been wiped free of as presetting Blank data block.
Suppose to have 3 data blocks, be respectively X, Y and Z had wherein originally recorded data and be not wiped free of among the X, and record data not among Y and the Z then can inquire Y by traversal and Z is a Blank data block.
Need to prove, in the present embodiment, can also set up page or leaf level logical mappings table in advance, record the logical address of the data page that respectively stores data in this page level logical mappings table, physical address, and the incidence relation between each data page, the page or leaf level logical mappings table in the present embodiment can adopt binary tree, or data storage method such as B+ tree is with record data.
Be that example describes page or leaf level logical mappings table with the binary tree in the present embodiment, be understandable that, can be the data storage method of other types equally:
See also Fig. 2 (b), comprise 6 nodes altogether among the figure, be respectively A, B, C, D, E, F, wherein each node is represented a data page, each node is made up of four partial contents, from left to right be respectively " left sibling sign ", " logical address ", " physical address " and " right node identification ", each node in the present embodiment can be made up of 16 bytes, and every part takies 4 bytes in four parts.
Among Fig. 2 (b),, represent that then this node does not have left sibling, or do not have right node if " left sibling sign " or " the right node identification " of certain node are " NULL ".
202, according to the target data inquiry source data to be updated that gets access to;
In the present embodiment, when the data of certain one page are upgraded in need be to the flash data piece, at first can obtain new data, i.e. target data is afterwards again according to the position enquiring source data to be updated of the required storage of this target data.
Suppose that the user wishes to replace source data " 300 " with target data " 500 ", can determine that then target data is " 500 ", source data is " 300 ".
203, described target data is write in first data page that presets Blank data block, the data page at described source data place is labeled as invalid page or leaf;
After having determined source data to be updated, in the Blank data block group that presets, obtain a Blank data block, target data is write in some data pages of this Blank data block, be recorded as first data page.
And the data page at source data place is labeled as invalid page or leaf, concrete mark mode can for: in the label of this data page or attribute field, insert invalid flag, this invalid flag is used to indicate this data page invalid, promptly temporarily can not carry out read-write operation to this data page, need to prove, in actual applications, the mode that specifically marks invalid page or leaf can also have a variety of, does not limit herein.
Suppose that source data " 300 " is stored in data page and represents (shown in Fig. 2 (b)) by node E, then the logical address of this data page is 70 as can be known, physical address is 8, left sibling is D, right node is F, because the source data " 300 " in this data page lost efficacy, then this data page is labeled as invalid page or leaf.
Current Blank data block is Y and Z, can choose one arbitrarily, for example choose Y and be Blank data block to write data, then target data " 500 " can be write in the some data pages (i.e. first data page) among the Blank data block Y, the physical address of supposing this first data page is 9.
The list item of the described invalid page or leaf in the page or leaf level logical mappings table that 204, will preset replaces with the list item of described first data page;
Because the data page with the source data place in the step 203 is labeled as invalid page or leaf, for guaranteeing that the data in original and the related data page of this data page were kept perfectly, then can be in the page or leaf level logical mappings table that presets will this list item of invalid page replace with the list item of first data page.
The mode of concrete replacement can be the list item of inquiring about described invalid page or leaf place, physical address in the list item is revised as the physical address of first data page, keep the original related information of list item, this related information is used to represent the incidence relation between this list item and other list items.
Promptly, the list item at invalid page or leaf place is node E, obtains the physical address 9 of first data page, and the physical address among the node E is revised as 9 by 8, and keep this node E original " left sibling sign " and " right node identification ", then realized of the replacement of first data page invalid page or leaf.
205, judge whether to satisfy the update condition that presets,, if not, then continue to judge if then execution in step 206;
In the present embodiment, owing to some data page in the data block can be labeled as invalid page or leaf in the step 203, then these invalid pages or leaves temporarily can not carry out read-write operation, for improving the utilization factor of storage resources, need in some cases the data in these data blocks are upgraded, to eliminate invalid page or leaf, concrete condition can comprise:
(1), the number of the invalid page or leaf in a certain data block reaches default value:
The number of the invalid page or leaf in a certain data block reaches a certain threshold value, and (this threshold value can be set according to user's request, be traditionally arranged to be one more than or equal to 2 numeral) time, may make storage space reduce, then can upgrade the data block at invalid page or leaf place according to the target data in first data page in the case.
(2), system is in idle condition:
When system does not carry out read-write operation, when promptly being in idle condition, can utilize this section free time the data block at invalid page or leaf place to be upgraded equally according to the target data in first data page.
Need to prove, above-mentionedly only the update condition that presets is illustrated, be understandable that, in actual applications, can not limit for other the update condition that presets equally herein with two examples.
206, according to the target data in first data page data block at invalid page or leaf place is upgraded.
In the present embodiment, concrete renewal process can for:
Data in other data pages except that invalid page or leaf in the data block are saved in buffer memory;
Data block is wiped;
Obtain the target data in first data page;
Described target data write in original invalid page or leaf obtain revising page or leaf;
To comprise the data content of preserving in the modification page or leaf of target data and the buffer memory writes in the data block after wiping;
The list item of first data page in the page or leaf level logical mappings table that presets is replaced with the described list item of revising page or leaf.
In the above-mentioned more new technological process, because the characteristic of flash memory, therefore minimum unit of erase is a data block, for target data is write in original data page again, then can be earlier the content of other data pages in the data block be copied to buffer memory, writes new data more again, thereby realize the renewal of data block, the process of Data Update is similar in process that this data block is upgraded and the prior art, repeats no more herein.
After Data Update is intact, revise in the page or leaf (promptly having write original invalid page or leaf of target data) and promptly preserve target data, can adjust page or leaf level logical mappings table this moment again, replace the list item of the first original data page with the list item of revising page or leaf, concrete replacement process and aforementioned replacement process are similar, repeat no more, after replacement was finished, then the physical address among the node E was modified to 8 once more herein.
Need to prove, owing to be provided with page or leaf level logical mappings table in the present embodiment, then may take certain system resource, for reducing resource occupation, when system is idle, or the resource that takies of this page level logical mappings table can put in order this page level logical mappings table when reaching the threshold value that presets, concrete Collator Mode can for:
At first obtain the data page to be put in order that belongs to same data block, data in valid data in this data block and the data page to be put in order are merged, concrete merging can realize by the COPY_BACK operation, be understandable that, can adopt other similar operation to realize that data merge, and do not limit herein in actual applications equally.
After merging is finished, the copying data after merging to blank block, is deleted the list item of data page to be put in order simultaneously in page or leaf level logical mappings table.
By above-mentioned housekeeping operation, can the data in the data block under the data in the data page and this data page be merged, thereby reduced the quantity of data page, promptly reduced the content in the page or leaf level logical mappings table.
Need to prove that above-mentioned Collator Mode only for an example of arrangement page or leaf level logical mappings table, in actual applications, can also adopt other Collator Mode equally, does not limit herein.
In the present embodiment, owing to after satisfying the update condition preset, just the data block at invalid page or leaf place is upgraded, then can guarantee need not when each Data Update, all data block to be wiped, thereby saved the flow process of Data Update, improved the performance of data random writings;
Secondly, owing to adopt the storage mode of binary tree in the present embodiment, therefore can improve the search efficiency of page or leaf level logical mappings table effectively as page or leaf level logical mappings table;
Once more, owing to can put in order page or leaf level logical mappings table in the present embodiment, therefore can reduce taking of system resource effectively.
In sum, in the present embodiment, owing to there is the page or leaf level logical mappings table that presets, and the physical address that includes each data page in this page level logical mappings table, logical address, and the incidence relation between each data page, so when the content of a certain data page is upgraded, only need in this page level logical mappings table, replace the renewal that can realize data to the physical address of this data page, and need not to wipe the whole data block at this data page place, so present embodiment can utilize this page level logical mappings table to improve the performance of data random writing.
Introduce another embodiment of flash memory data processing method in the embodiment of the invention below:
At first, need to prove, in the flash data storing process in the prior art, minimum storage cell is a data page, can also be that unit stores equally with the data block, but only establish the logical relation table between the data block in the prior art, be piece level logical mappings table, when the user need repeatedly store low volume data, may make each storage all take a data block, and most of space of this data block may remain blank, therefore can waste a large amount of storage spaces.
A kind of flash memory data processing method is provided in the embodiment of the invention, in order to address the aforementioned drawbacks, has specifically seen also Fig. 3, flash memory data processing method the 3rd embodiment comprises in the embodiment of the invention:
301, obtain the length information of data to be written;
When the user need write data, at first obtain the length of data to be written, the unit of this length can be a unit with the sector, supposes to comprise 64 data pages in the data block, comprises 4 sectors in each data page.
302, according to the number of a length information and a sector that data block comprised data to be written are split as piece progression and reach page or leaf level data according to this;
In the present embodiment, the length information of data to be written is converted to the corresponding required number of sectors L that takies (if data to be written were the unit computational length with the sector promptly originally, then need not conversion), concrete conversion regime does not limit herein;
Obtain the number N of a sector that data block comprised;
L and N are carried out rounding operation, determine piece level data according to the B as a result of rounding operation;
L and N are carried out complementation, according to the definite page or leaf level of the result of complementation data.
Suppose above-mentioned L=260, N=64*4=256, L div N=1 then, L mod N=4, B=1 then, then piece level data are the data that a complete Blank data block can be stored, page or leaf level data are the data that 4 sectors (i.e. data page) can be stored.
303,, write page or leaf level data and a page or leaf level logical mappings table that presets is upgraded according to the page or leaf writing mode according to piece writing mode write-in block level data.
For ease of understanding, at first introduce the flow process that sets in advance in the present embodiment below:
At first can set up four tables of data, be respectively:
Piece level logical mappings table: be used for the logical mappings relation of recording data blocks, logical address and physical address one-to-one relationship;
Page or leaf level logical mappings table: be used for the logical mappings relation of record data page or leaf, adopt the mode record of binary tree, comprise the logical address of data page, the incidence relation between physical address and each data page;
Piece erasing times tabulation: the erasing times that is used to write down each data block;
Not erase block tabulation: be used to write down the data block that is not wiped free of.
Need to prove that concrete piece level logical mappings table can be as shown in the table:
Table 1
Piece level mapping item |
Corresponding logical address |
Physical address corresponding |
0 |
0*n | 0x00000000 | |
1 |
1*n |
0x00000005 |
2 |
2*n |
0x80000010 |
... |
... |
... |
N |
N*n |
0xFFFFFFFF |
N+1 |
(N+1)*n |
0xFFFFFFFF |
... |
... |
... |
In the above-mentioned table 1 each is realized that by 4 bytes each all identifies the logical address of a data block and the corresponding relation between the physical address.
Can carry out the write operation of data after finishing above-mentioned the setting, below piece level data be write and page or leaf level data write respectively and describe:
(1) piece level data write, specifically as shown in Figure 4:
A, from the Blank data block that presets, choose B Blank data block;
When system powers on, each data block traveled through to inquire the Blank data block that does not write data, perhaps can also wipe and obtain Blank data block the data block in the erase block tabulation not.
Need to prove, the number of times that before the data block during erase block is not tabulated is wiped, can also be wiped free of by each data block of piece erasing times list query earlier, preferential selection is wiped free of the few data block of number of times and wipes, so that the number of times that each data block is wiped free of is roughly suitable, thus the bulk life time of raising flash memory.
B, piece level data are write in B the Blank data block;
Above-mentionedly determined to need a Blank data block, then can read a part of data in order, made this part data just can fill full data block with the storage data, and with in this data block of this part data storage.
C, the logical address and the physical address of B Blank data block are inserted the piece level logical mappings table that presets;
After the data filling was finished, this data block was promptly preserved data, then the logical address and the physical address of this data block is inserted in the piece level logical mappings table, is used for indicating this data block to have data.
D, obtain ranges of logical addresses according to the logical address of B Blank data block;
The corresponding one section logical address of each data block, then this step is obtained the ranges of logical addresses of this data block correspondence.
E, in the page or leaf level logical mappings table that presets the list item of deletion logical address in this ranges of logical addresses.
Owing to be filled with data in this data block, store data in the data page that then can't continue to comprise in this data block, then can from page or leaf level logical mappings table, delete the list item of logical address in this ranges of logical addresses.
(2) piece level data write, specifically as shown in Figure 5:
A, from the Blank data block that presets, choose a Blank data block;
When system powers on, each data block traveled through to inquire the Blank data block that does not write data, perhaps can also wipe and obtain Blank data block the data block in the erase block tabulation not.
Need to prove, the number of times that before the data block during erase block is not tabulated is wiped, can also be wiped free of by each data block of piece erasing times list query earlier, preferential selection is wiped free of the few data block of number of times and wipes, so that the number of times that each data block is wiped free of is roughly suitable, thus the bulk life time of raising flash memory.
B, page or leaf level data are write data page in this Blank data block in order;
By above-mentioned steps 302 as can be known, write the space that page or leaf level data need 4 sectors (i.e. data page) altogether, it is consistent to be according to data page that unit writes the process of data in the process that specifically writes page or leaf grade data and the prior art, does not limit herein.
C, in the page or leaf level logical mappings table that presets, write the logical address of the data page that has this page level data in this Blank data block, the incidence relation between physical address and this data page and other data pages;
When page or leaf level data write finish after, then this data page promptly has data, then can in page or leaf level logical mappings table, increase a node newly, be used to represent this data page, concrete newly-increased process can be the logical address and the physical address that obtain this data page, and determine the left sibling and the right node of this data page according to the relation between the data of storing in this data page and other data, form new node afterwards and insert in the page or leaf level logical mappings table.
D, in the piece level logical mappings table that presets, revise the sign of Blank data block, be used for indicating this Blank data block to have a page or leaf level logical mappings table.
In the present embodiment, after writing data in certain data page in a certain Blank data block, then only can't completely read the content of this data block by piece level logical mappings table, the page or leaf level logical mappings table that then also need read this data block can completely read the content of this data block, therefore, need in piece level logical mappings table, adjust, specifically the most significant digit of the physical address corresponding of this data block can be revised as 1 to make a check mark the physical address of this data block.
For example the physical address of the data block shown in the list item " 2 " is 0x80000010 in the table 1, being converted into binary number is: 1,000 0,000 0,000 0,000 0,000 0,000 0,000 0,001 0000, then its most significant digit is 1, represent that this data block includes page or leaf level logical mappings table, when reading the content of this data block, need read the content that page or leaf level logical mappings table can intactly obtain this data block simultaneously.
In the present embodiment, owing to be provided with page or leaf level logical mappings table, then may take certain system resource, for reducing resource occupation, when system is idle, or the resource that takies of this page level logical mappings table can be put in order this page level logical mappings table when reaching the threshold value that presets, concrete Collator Mode is consistent with the Collator Mode in the previous embodiment, repeats no more herein.
In the present embodiment, because data to be written can be split as piece progression and reach page or leaf level data according to this, therefore can be in the write-once process distribute data piece and data page carry out data and write simultaneously, avoid low volume data to take the situation of a full block of data, thereby saved storage space;
Secondly, in the present embodiment, can write down the number of times that each data block is wiped free of, and preferentially select to be wiped free of the few data block of number of times and wipe, so that the number of times that each data block is wiped free of is roughly suitable, thus the bulk life time of raising flash memory;
Once more, owing to can put in order page or leaf level logical mappings table in the present embodiment, therefore can reduce taking of system resource effectively.
In sum, in the present embodiment, owing to there is the page or leaf level logical mappings table that presets, and the physical address that includes each data page in this page level logical mappings table, logical address, and the incidence relation between each data page, so when writing page or leaf level data to Blank data block, can be in the page or leaf level logical mappings table of this Blank data block correspondingly increase corresponding list item, thereby make the page or leaf level data that to store several data pages in this Blank data block, therefore and the data that each data page can not occur all need independently to take the situation of a data block, conserve storage effectively.
Introduce two kinds of flash memory data processing methods in the foregoing description and all be based on the page or leaf level logical mappings table that presets page or leaf level data (comprising that the page or leaf progression of storing in the flash memory reaches the page or leaf level data that write to flash memory according to this) are managed, therefore can improve the performance that flash data is handled effectively.
Below the flash memory data processing device in the embodiment of the invention is introduced:
See also Fig. 6, flash memory data processing device first embodiment comprises in the embodiment of the invention:
Source data query unit 601 is used for according to the target data inquiry source data to be updated that gets access to;
Writing unit 602 is used for described target data is write first data page that presets Blank data block;
Mark unit 603, the data page that is used for described source data place is labeled as invalid page or leaf;
Replace unit 604, described invalid page list item of the page or leaf level logical mappings table that is used for presetting replaces with the list item of described first data page.
Flash memory data processing device in the present embodiment can further include:
Upgrade trigger element 605, be used to judge whether to satisfy the update condition that presets, if then trigger updating block and carry out corresponding operating;
Updating block 606 is used under the triggering of described renewal trigger element, according to the target data in described first data page data block at described invalid page or leaf place is upgraded.
Renewal trigger element 605 in the present embodiment comprises:
First trigger element 6051, whether the number that is used for invalid page or leaf in the judgment data piece reaches default value, if then trigger updating block and carry out corresponding operating;
Or,
Second trigger element 6052 is used to judge the current idle condition that whether is in, if then trigger updating block and carry out corresponding operating.
Updating block 606 in the present embodiment comprises:
Data updating unit 6061, be used for the data in described data block other data pages except that invalid page or leaf are saved in buffer memory, described data block is wiped, obtain the target data in described first data page, will comprise the data content of preserving in the modification page or leaf of described target data and the buffer memory and write in the data block after described the wiping;
Mapping table updating block 6062, the list item of described first data page of the page or leaf level logical mappings table that is used for presetting replaces with the list item of described modification page or leaf.
Flash memory data processing device in the present embodiment can further include:
Blank data block search unit 607, be used for when system powers on, each physical data block is traveled through, inquire about not the physical data block of record data and the physical data block that has been wiped free of, with the physical data block of described not record data and the physical data block that has been wiped free of as presetting Blank data block.
Flash memory data processing device in the present embodiment can further include:
Mapping table generation unit 608 is used for setting up page or leaf level logical mappings table, comprises the logical address of the data page that respectively has data in the described page or leaf level logical mappings table, the incidence relation between physical address and this data page and other data pages.
Flash memory data processing device in the present embodiment can further include:
Mapping table arrangement unit 609 is used for described page or leaf level logical mappings table is put in order.
In the present embodiment, writing unit 602 writes target data in first data page that presets Blank data block, mark unit 603 is labeled as invalid page or leaf with the data page at source data place, the list item of replacing the invalid page or leaf in the page or leaf level logical mappings table that will preset unit 604 replaces with the list item of first data page, therefore, in the process of Data Update, need not the data block at invalid page or leaf place is wiped, and directly adopt alternative this invalid page or leaf of first data page in the Blank data block to carry out data storage, therefore save the operation of Data Update, thereby improved the performance of data random writings.
See also Fig. 7, flash memory data processing device second embodiment comprises in the embodiment of the invention:
Length information acquiring unit 701 is used to obtain the length information of data to be written;
Data split cells 702 is used for according to the number of a described length information and a sector that data block comprised described data to be written being split as piece progression and reaches page or leaf level data according to this;
Data write unit 703 is used for writing described level data according to the piece writing mode, writes described page or leaf level data according to the page or leaf writing mode.
Data write unit 703 in the present embodiment comprises:
Piece writing unit 7031, be used for choosing B Blank data block from the Blank data block that presets, described level data are write in the described B Blank data block, the logical address and the physical address of a described B Blank data block are inserted the piece level logical mappings table that presets, logical address according to a described B Blank data block is obtained ranges of logical addresses, the list item of deletion logical address in described ranges of logical addresses in the page or leaf level logical mappings table that presets;
Page or leaf writing unit 7032, be used for choosing a Blank data block M from the Blank data block that presets, described page or leaf level data are write data page among the described Blank data block M in order, in the page or leaf level logical mappings table that presets, write the described logical address that has the data page of data, incidence relation between physical address and this data page and other data pages, in the piece level logical mappings table that presets, revise the sign of described Blank data block M, be used for indicating described Blank data block M to have page or leaf level logical mappings table.
In the present embodiment, because data to be written can be split as piece progression by data split cells 702 and reach page or leaf level data according to this, and write respectively by piece writing unit 7031 in the data write unit 703 and page or leaf writing unit 7032, therefore can be in the write-once process distribute data piece and data page carry out data and write simultaneously, avoid low volume data to take the situation of a full block of data, thereby saved storage space.
One of ordinary skill in the art will appreciate that all or part of step that realizes in the foregoing description method is to instruct relevant hardware to finish by program, described program can be stored in a kind of computer-readable recording medium, this program comprises the steps: when carrying out
According to the target data inquiry source data to be updated that gets access to;
Described target data is write in first data page that presets Blank data block, the data page at described source data place is labeled as invalid page or leaf;
The list item of the described invalid page or leaf in the page or leaf level logical mappings table that presets is replaced with the described list item that presets first data page of Blank data block.
The above-mentioned storage medium of mentioning can be a ROM (read-only memory), disk or CD etc.
More than a kind of flash memory data processing method provided by the present invention and device are described in detail, for one of ordinary skill in the art, thought according to the embodiment of the invention, part in specific embodiments and applications all can change, in sum, this description should not be construed as limitation of the present invention.