CN101526920B - Method and device for writing data - Google Patents

Method and device for writing data Download PDF

Info

Publication number
CN101526920B
CN101526920B CN2008102470519A CN200810247051A CN101526920B CN 101526920 B CN101526920 B CN 101526920B CN 2008102470519 A CN2008102470519 A CN 2008102470519A CN 200810247051 A CN200810247051 A CN 200810247051A CN 101526920 B CN101526920 B CN 101526920B
Authority
CN
China
Prior art keywords
storage block
data
block
random
empty storage
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN2008102470519A
Other languages
Chinese (zh)
Other versions
CN101526920A (en
Inventor
陆舟
于华章
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Feitian Technologies Co Ltd
Original Assignee
Beijing Feitian Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Feitian Technologies Co Ltd filed Critical Beijing Feitian Technologies Co Ltd
Priority to CN2008102470519A priority Critical patent/CN101526920B/en
Publication of CN101526920A publication Critical patent/CN101526920A/en
Application granted granted Critical
Publication of CN101526920B publication Critical patent/CN101526920B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The embodiment of the invention discloses a method and a device for writing data, which relate to the field of data storage and solve the problem that some storage blocks in memories are easy to have high extent of damage in the prior art. The method for writing data comprises the following steps: receiving an instruction for writing new data; locating the data storage block where the data to be modified is located; selecting a blank storage block from all blank storage blocks randomly; combining the data to be modified with new data into the refresh data and writing the refresh data in the randomly selected blank storage block; and erasing the located data storage block to a blank storage block. The embodiment of the invention is mainly applied to the situations of executing various operations on memories.

Description

Write the method and the device of data
Technical field
The present invention relates to field of data storage, relate in particular to a kind of method and device that writes data.
Background technology
Flash memory belongs to a kind of of type of memory, even if because it has mobility and is kept at the advantage that the data on the flash memory still can not lose and is developed rapidly under powering-off state.In flash memory, write the Flash operation and can only change to " 0 " to data among the Flash (Bit) from " 1 "; Erase operation can become " 1 " to " 0 ", but erase operation can only carry out for unit at whole " storage block ".For example: the size of a storage block is generally 256 bytes to 1024 bytes.
When the user revises the data of certain storage block in the storer at needs, generally be in empty storage block, to write the data that need modification.In the prior art, usually adopt and in some empty storage blocks, find out the method for an empty storage block in a certain order, and then be written to amended data in this sky storage block and wipe data in the DSB data store block before revising.But the number of times that each storage block can be written into and wipe all is limited, particularly work as frequent some data of modification of user or work as empty storage block number not for a long time, being easy to occur that sequence number is come the more preceding empty storage block of order carries out continually and writes or the situation of erase operation, the extent of damage of these sky storage blocks is increased, reduce serviceable life, even may therefore can't reuse this storage block, cause the inefficacy of whole storer.
Summary of the invention
Embodiments of the invention provide a kind of method and device that writes data.So that improve the number of times that storage block can be used in this storer.
For achieving the above object, embodiments of the invention adopt following technical scheme:
A kind ofly write the method for data, comprising to the Flash storer:
Receive the instruction that writes new data;
The location needs the DSB data store block at the data place of modification;
From all empty storage blocks, select an empty storage block at random; Judge whether the described empty DSB data store block of selecting at random is the empty storage block that record is arranged, wherein, all bytes that the described empty storage block that record arranged is a null data area not all are the empty storage blocks of 0xFF;
If then the empty memory block erasing of record is arranged is empty storage block with described, then described data and the new data that needs to revise is combined into more new data, described more new data is write be erased to the sky storage block described to be had in the empty storage block of record.
If not, then directly the described data that need revise are combined with new data and generate more new data, described more new data is write in the described empty storage block of selecting at random;
The DSB data store block that navigates to is erased to the sky storage block.
A kind ofly write the device of data, comprising to the Flash storer:
Receiver module is used to receive the instruction that writes new data;
Locating module is used to locate the DSB data store block at the data place that needs revise;
Select module, be used for selecting an empty storage block at random from all empty storage blocks;
First judge module is used to judge whether the described empty DSB data store block of selecting at random is the empty storage block that record is arranged, and wherein, all bytes that the described empty storage block that record arranged is a null data area not all are the empty storage blocks of 0xFF;
First removes module, be used for when the first judge module judged result when being, the empty memory block erasing of record is arranged is empty storage block with described;
Writing module, be used for the data that described needs are revised are combined with new data and generate more new data, in the judged result of first judge module for not the time, described more new data write direct in the described empty storage block of selecting at random or in the judged result of first judge module when being, described more new data write removes module by first and be erased to empty storage block;
Wipe module, the DSB data store block that is used for navigating to is erased to the sky storage block.
Method and the device that writes data provided by the invention has following having a few or beneficial effect: by adopting the technical scheme of selecting empty storage block in empty storage block at random, solved in the prior art because to be the easy appearance selecting empty storage block in order and caused come the more preceding empty storage block of order to sequence number and carried out continually and write or the technical matters of erase operation, and then obtained each storage block extent of damage in the balance storer, increase the beneficial effect of storage block access times.
Description of drawings
In order to be illustrated more clearly in the embodiment of the invention or technical scheme of the prior art, to do to introduce simply to the accompanying drawing of required use in embodiment or the description of the Prior Art below, apparently, accompanying drawing in describing below only is some embodiments of the present invention, for those of ordinary skills, under the prerequisite of not paying creative work, can also obtain other accompanying drawing according to these accompanying drawings.
Fig. 1 writes the process flow diagram of the method for data for the embodiment of the invention 1;
Fig. 2 writes the block diagram of the device of data for the embodiment of the invention 2;
Fig. 3 writes the process flow diagram of the method for data for the embodiment of the invention 3;
Fig. 4 writes the block diagram of the method for data for the embodiment of the invention 4.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the invention, the technical scheme in the embodiment of the invention is clearly and completely described, obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, those of ordinary skills belong to the scope of protection of the invention not making the every other embodiment that is obtained under the creative work prerequisite.
Embodiment 1
Present embodiment discloses a kind of method that writes data, and as shown in Figure 1, this method comprises the steps:
101, receive the instruction that in storage block, writes new data that send on upper strata (as computer operating system).
102, in all DSB data store block of storer, find out the DSB data store block at the data place of need revising.
103, in all empty storage blocks of storer at random select an empty storage block, and should the sky storage block as the empty storage block of selecting.
104, will need in the data revise part and make amendment, and amended new data combined with data become more new data, and with this more new data write in the above-mentioned empty storage block of selecting.
105, with the data erase in the DSB data store block that navigates in 101 steps, make this DSB data store block become an empty storage block.
The method that writes data that present embodiment provides is written in technical scheme in the empty storage block of selecting at random by adopting the data that will write, and has obtained the beneficial effect that can realize uniformly each storage block being carried out write operation.Further, again because the uniform numerical value of the number of times of the write operation that each storage block is performed, so overcome some other storage block because the number of times of the write operation that is performed is too much, the extent of damage that causes is more serious, even the technical matters that can't reuse, also improved the operable number of times of storage block simultaneously.
Embodiment 2
Present embodiment discloses a kind of device that writes data, and as shown in Figure 2, this device comprises: receiver module 21, and locating module 22 is selected module 23, and writing module 24 is wiped module 25.
Receiver module 21 is used to receive the instruction that writes new data; Locating module 22 is used to locate the DSB data store block at the data place that needs revise; Selecting module 23 is used for selecting an empty storage block at random from all empty storage blocks; Writing module 24 is used for that described data are combined the back with new data and is new data more, and described more new data is write in the described empty storage block of selecting at random; Wipe the DSB data store block that module 25 is used for navigating to and be erased to the sky storage block.
The device that writes data that present embodiment provides is convenient to write the realization of the method for data, also for example can improve simultaneously: flash memory etc., storage block is the serviceable life of impaired storer easily.
Embodiment 3
Scene when the present embodiment combination is made amendment to the data in the storage block specifically describes the method that writes data, and as shown in Figure 3, this method comprises the steps:
In order to set forth conveniently, suppose that the physical address in flash memory storage district is that establishing each storage block is 0x100 byte from 0x0000000 to 0x00007800 in the present embodiment, then total 0x78 storage block.Correspondingly, the physical block number of each storage block is that 0x00 is to 0x77.Be used for this storage block logical block number (LBN) of mark in the first byte of each storage block, file can regard that the set of a plurality of storage blocks and the storage block in the file are that logical block number (LBN) according to each storage block is tied as.
According to the difference of storage block logical block number (LBN), storage block is divided for two types in the present embodiment:
Empty storage block refers to that logical block number (LBN) is the storage block of 0xFF.Null data area refers to the zone that first byte in the sky storage block (being logical block number (LBN)) byte is in addition formed, if then all bytes of null data area all are 0xFF, this sky storage block can write data at any time; Otherwise this sky storage block is the empty storage block of the data of can not writing direct, and needs this sky storage block is carried out erase operation, even should all bytes of sky storage block become 0xFF, then empty storage block just becomes the empty storage block that can write data at any time.Especially, the empty storage block of the data of can not writing direct is called " the empty storage block that record is arranged ".
DSB data store block refers to the storage block of logical block number (LBN) in 0x01 arrives the 0x78 scope.The data that data field data index is stored according to first byte in the storage block (being logical block number (LBN)) byte in addition.The data field data are considered to effective file data.
301, after storer energising, the sum of statistical memory hollow storage block, and generate one and be not more than this total random number.
Be specially in the present embodiment: open up a variable N=0 at internal memory, pointer P is set points to flash memory storage district physics first address, be P=0x00000000, pointer P is from 0x00000000, finish to 0x00007800, the step-length of P is 0x100, i.e. P=P+0x100, and then P always points to the storage block logical block number (LBN).Judge whether P storage block logical block number (LBN) pointed is 0xFF.If 0xFF makes N=N+1, when P=0x00007800, the value of N is exactly the sum of sky storage block.Total N according to the empty storage block that obtains generates a random number M.The scope of the M of random number is 1<=M<=N.M produces by a relevant function f (M), also can be simple select integer between 1<=M<=N.These two kinds of methods may be used to generate the random number in the present embodiment.
302, judge whether the sum of empty storage block is identical with the random number that generates, identical with the random number of generation if sky is stored fast sum, then execution in step 303; If the sum of empty storage block is different with the random number of generation, then execution in step 309.
Be specially in the present embodiment: judge whether M equals N, execution in step 303 if M equals N; The execution in step 309 if M is not equal to N.
When the number of storer hollow storage block seldom the time, according to the random number that empty storage block sum generates, the possibility that equates with empty storage block sum will become big.In the present embodiment, utilize this possibility, judge the scheme whether sum of empty storage block equates with random number, obtain the technique effect that to recognize the present total situation of sky storage block by employing.And in this process of present embodiment, the random number that computing machine generates just is equivalent to the default value that the user is provided with, this default value is equivalent to a thresholding, can recognize whether current empty storage block sum is in situation seldom, so that take appropriate measures.
303, the sum of DSB data store block also generates a random number that is not more than this DSB data store block sum at random in the statistical memory; According to the sum of the empty storage block that counts in 301 steps, generate a random number that is not more than this sky storage block sum at random simultaneously.
Be specially in the present embodiment: apply for two memory variable A and B.Be recorded in the sum of the DSB data store block that finds in the storer with A, be recorded in the sum (make in the present embodiment B=N both can) of the empty storage block that finds in the storer with B, and generate a random number a according to the value of A, the scope of a is 1<=a<=A; Value according to B generates a random number b, and the scope of b is 1<=b<=B.
304, in DSB data store block, select a data storage block according to the random number that the DSB data store block sum generates; The random number that generates according to empty storage block sum is selected a target empty storage block in empty storage block simultaneously.
Be specially in the present embodiment: open up a local variable N4=0 at internal memory, pointer T is set points to flash memory storage district physics first address, be T=0x00000000, pointer T is from 0x00000000, finish to 0x00007800, the step-length of pointer T is 0x100, i.e. T=T+0x100, and then pointer T always points to the storage block logical block number (LBN).Judge that the current storage block logical block number (LBN) pointed of pointer T is whether in 0x01 to 0x78 scope.If, N4=N4+1 then.In the time of N4=a, the current DSB data store block pointed of pointer T is the DSB data store block n4 selected according to random number a, and selected this DSB data store block n4.
Simultaneously, open up a local variable N3=0 at internal memory, pointer S is set points to flash memory storage district physics first address, be S=0x00000000, pointer S finishes to 0x00007800 from 0x00000000, and the step-length of pointer S is 0x100, be S=S+0x100, then pointer S always points to the storage block logical block number (LBN).Judge whether the current storage block logical block number (LBN) pointed of pointer S is 0xFF.If 0xFF, then N3=N3+1.In the time of N3=b, the pairing empty storage block of pointer S is the empty storage block n3 selected according to random number b, and selected this sky storage block n3, is target empty storage block n3.
Process about the empty storage block n3 that selects at random in present embodiment 303,304 steps also can adopt following method to realize:
This method is mainly tabulated and is realized the purpose of an empty storage block of stochastic searching by setting up empty storage block.
3031, all storage blocks in the traversal storer, finding is free storage block in the present storer.
3041, set up one include find be free storage block address list or the physical block number tabulation of free storage block is arranged, from described tabulation, select an empty storage block at random.
In the present embodiment, concrete grammar can be: the first address that pointer P points to the storage block of physical address minimum in the flash memories is set.P=P+i* (0x100) just represents to point to the first address (because the length of each storage block is the 0x100 byte, so pointer P always points to each storage block first address) of i+1 storage block so.The value of i is from 0 to 0x77, and 0x78 storage block altogether then can find the first address of a storage block by the value of i.
In internal memory, open up an array freeblock[78] be used for writing down the value of the i of empty storage block.Allow the value of i traverse 0x77 from 0, judge whether the pairing storage block of i value is the sky storage block, if empty storage block, then with the value record of i in freeblock.Such as current time, the number of empty storage block is 5, and corresponding i value is respectively 0x2,0x12,0x33,0x40,0x59, freeblock[0 so]=0x2, freeblock[1]=0x12, freeblock[2]=0x33, freeblock[3]=0x 40, freeblock[4]=0x 59, the random number between producing 1~5.Such as this random number is 2, so just can by look for the 2nd value of freeblock array or 5-2 value (promptly look for freeblock[2-1] or look for freeblock[5-2], the 5th, the number of sky storage block), thus obtain the i value of an empty storage block.Also can be according to the i value, i*0x100 is exactly the first address of this sky storage block.So can in array freeblock, directly write down the first address of empty storage block, therefrom select an empty storage block then at random.
305, judge whether the described empty storage block of selecting at random is the empty storage block that record is arranged, if the result who judges is for being that then execution in step 306; Otherwise, direct execution in step 307.
Be specially in the present embodiment: judge whether empty storage block n3 is the empty storage block that record is arranged.
306, wiping this has the data of storing in the empty storage block of record, and making this empty storage block that record is arranged is empty storage block.
307, the data in the DSB data store block of selecting are written in the empty storage block of selecting, wipe the data in the DSB data store block of selecting then.
Be specially in the present embodiment: all be read into the data of storing among the DSB data store block n4 in the internal memory, then logical block number (LBN) (being first byte) data in addition are written among the empty storage block n3 that selects at random by 305 steps, after these data have all been write, logical block number (LBN) with DSB data store block n4 writes among the sky storage block n3 again, simultaneously the data of storing among the obliterated data storage block n4.Be about to empty storage block n3 and become DSB data store block n3, DSB data store block n4 is become sky storage block n4.
The scheme that present embodiment provides is because considered that some DSB data store block may be in case be written into permanently effective data, just seldom be performed the situation of write operation, so after the storer energising, adopted the technical scheme that the data in the DSB data store block of selecting at random can be transferred in the empty storage block of selecting at random, even if DSB data store block is written into permanently effective data so, still this DSB data store block can be become the sky storage block, it is participated in to be performed in the scene that writes data manipulation, obtained the number of times that can make storage block be performed write operation and obtained balanced beneficial effect.
308, counter being set and making the initial count value of this counter is zero, waits for that simultaneously upper strata (as: computer operating system) sends the instruction that writes new data.
Be specially in the present embodiment: variable J of application in internal memory, be used for the number of times of record modification storer, and the initial value that J is set is 0, wait for that then the needs that send on the upper strata revise the instruction of data.
When the storage block in the storer was carried out the write-once operation, counter then added up to add one on initial value, so that the number of times of the write operation that record storage was performed.
309, receive the instruction that writes new data of sending on the upper strata and find the DSB data store block at the data place of need revising.
Be specially in the present embodiment: if need the DSB data store block x logical block number (LBN) at the data place of modification is x, pointer P is set points to flash memory storage district physics first address, be P=0x00000000, pointer P is from 0x00000000, finish to 0x00007800, the step-length of P is 0x100, i.e. P=P+0x100, and then P always points to the storage block logical block number (LBN).Judge whether the current storage block logical block number (LBN) pointed of P is X.If then this DSB data store block is the DSB data store block x that needs the data place of modification.If not, then P=P+0x100 continues to search.
In the present embodiment, also can find the DSB data store block at the data place that needs modification by physical block number, if this need revise to such an extent that the physical block number of data storage block is Y, then make a pointer P from 0x00000000, finish to 0x00007800, the step-length of P is 0x100, though P=Y*0x100, the pairing storage block of P be need revise the data storage block.
310, the sum of statistical memory hollow storage block, and generate a random number that is not more than in this sky storage block sum scope.
Be specially in the present embodiment: open up a variable N 2=0 at internal memory, pointer P is set points to flash memory storage district physics first address, be P=0x00000000, pointer P is from 0x00000000, finish to 0x00007800, the step-length of P is 0x100, i.e. P=P+0x100, and then P always points to the storage block logical block number (LBN).Judge whether P storage block logical block number (LBN) pointed is 0xFF, if 0xFF then makes N2=N2+1.When P=0x00007800, the value of N2 is exactly the sum of sky storage block.Total N2 according to the empty storage block that obtains generates a random number w.The scope of random number w is 1<=w<=N2.W produces by a relevant function f (w), also can be simple select integer between 1<=w<=N2.These two kinds of methods may be used to generate the random number in the present embodiment.
311, in storer, search the sky storage block, each the empty storage block that finds is counted, when the value of counting when equating, select the current empty storage block that finds with random number, and the empty storage block of should the conduct of sky storage block selecting at random.
Be specially in the present embodiment: open up a local variable N5=0 at internal memory, pointer Y is set points to flash memory storage district physics first address, be Y=0x00000000, pointer Y is from 0x00000000, finish to 0x00007800, the step-length of pointer Y is 0x100, i.e. Y=Y+0x100, and then pointer S always points to the storage block logical block number (LBN).Judge whether the current storage block logical block number (LBN) pointed of pointer Y is 0xFF.If 0xFF, then N5=N5+1.In the time of N5=w, the pairing empty storage block of pointer Y is the empty storage block n5 selected according to random number w, and selected this sky storage block n5.
Also can adopt by setting up empty storage block about the process of the empty storage block n5 that selects at random in present embodiment 310,311 steps and tabulate and realize the method for an empty storage block of stochastic searching.Concrete method of operating is identical with the method for step 3031 and 3041, is not here giving unnecessary details.
312, judge whether the empty storage block of selecting at random is the empty storage block that record is arranged, if then execution in step 313; If not, then direct execution in step 314.
313, wiping this has the data of storing in the empty storage block of record, makes this have the empty storage block of record to become the sky storage block.
314, the data of storing in the DSB data store block that finds in 309 steps are read in the internal memory, keep logical block number (LBN) constant, in internal memory that the data modification that needs in the data field to revise is intact simultaneously, to revise the data more new data (not containing logical block number (LBN)) that generates that combines with the data field data then earlier and write in the empty storage block of selecting at random by 312 steps, logical block number (LBN) be written in this sky storage block again.
In the present embodiment, adopted first more new data to write described empty storage block, after logical block number (LBN) is write the technical scheme of described empty storage block, obtained and avoided in ablation process, because it is incomplete that the generation power down causes writing data, make this sky storage block be in the beneficial effect of " the empty storage block that record is arranged " state, also make the DSB data store block that becomes that this empty storage block that record is arranged can be wrong simultaneously.
315, wipe the data of storing in the DSB data store block that finds in 309 steps, make this DSB data store block become the sky storage block.
314 and 315 steps are specially in the present embodiment: the data of DSB data store block x are read in the internal memory, when keeping logical block number (LBN) constant, in internal memory that the data modification that needs in the data field to revise is intact, to revise earlier the back data combine with the data field data generation more new data all be written among the empty storage block n5 that finds by step 311, DSB data store block x logical block number (LBN) is written among this sky storage block n5 (promptly empty storage block n5 being become DSB data store block n5) again, the data of storing among the obliterated data storage block x make DSB data store block x become sky storage block (even all bytes of this DSB data store block become 0xFF) simultaneously.
316, add one on the count value to set counter.
Be specially in the present embodiment: make J=J+1.
317, judge whether the count value of counter reaches pre-determined number, if the result who judges is for reaching pre-determined number, then execution in step 318; If the result who judges is not for reaching pre-determined number, this EO then.
Be specially in the present embodiment: it is 30 that preset times is set, and judges whether the J value equals 30, if the J value equals 30, then execution in step 318; Otherwise, execution in step 324.
318, the sum of DSB data store block also generates a random number that is not more than this DSB data store block sum at random in the statistical memory; The sum of statistical memory hollow storage block also generates a random number that is not more than this sky storage block sum at random simultaneously.
Concrete grammar is identical with embodiment in 303 steps in the present embodiment.
319, in DSB data store block, select a data storage block according to the random number that the DSB data store block sum generates; The random number that generates according to empty storage block sum is selected a target empty storage block in empty storage block simultaneously.
Concrete grammar is identical with embodiment in 304 steps in the present embodiment.
320, judge whether this empty storage block of selecting at random is the empty storage block that record is arranged, if then execution in step 321; If not, then direct execution in step 322.
Concrete grammar is identical with embodiment in 305 steps in the present embodiment.
321, wiping this has the data of storing in the empty storage block of record, and making this empty storage block that record is arranged is empty storage block.
Concrete grammar is identical with embodiment in 306 steps in the present embodiment.
322, the data in the DSB data store block of selecting are written in the empty storage block of selecting, wipe the data in the DSB data store block of selecting then, make this DSB data store block become the sky storage block.
Concrete grammar is identical with embodiment in 307 steps in the present embodiment.
When the value of counter arrives pre-determined number, the number of times that the write operation that storer is performed is described has reached default number of times, and be subjected to damage to a certain extent with regard to having represented the sky storage piece that exists in the present storer because of the write operation that has been performed pre-determined number this moment.In order to reduce the empty storage block extent of damage of present existence, present embodiment adopts the data in the DSB data store block that will select at random to transfer to technical scheme in the empty storage block of selecting at random, also obtained the beneficial effect that can balanced each storage block be performed the write operation number of times when having reduced the present empty storage block extent of damage.
323, with the count value zero clearing of counter.
Be specially in the present embodiment: make J=0.
324, process ends.
The scheme that present embodiment provides, by adopting the data to need to revise to write the technical scheme of the empty storage block of selecting at random, overcome in the prior art, select the sky storage block in order and the easy appearance that causes comes the situation that the more preceding empty storage block of order is carried out write operation continually to sequence number because be, obtained the technique effect that can make to the execution write operation of each storage block equilibrium in the storer, improve the spendable number of times of storage block, also be equivalent to prolong the spendable life-span of storer.And in writing the process of data, write logical block number (LBN) after the first write data, thereby has good anti-lost electric work energy.
Embodiment 4
Present embodiment has specifically described a kind of device that writes data, and as shown in Figure 4, this device comprises: second judge module 401, second Switching Module 402 at random, receiver module 403, locating module 404, select module 405, first judge module 408, the first is removed module 409, writing module 406, wipe module 407, accumulative total module 410, the three judge modules 411, the three are Switching Module 412 at random.
Second judge module 401 is used for judging that whether current empty storage block sum is less than default value after the storer energising; Second when Switching Module 402 is used for current empty storage block sum less than default value at random, the data in the DSB data store block of selecting is at random write in the target empty storage block of selecting at random, and the described DSB data store block of selecting at random is erased to the sky storage block; Receiver module 403 is used to receive the instruction that writes new data; Locating module 404 is used to locate the DSB data store block at the data place that needs revise; Selecting module 405 is used for selecting an empty storage block at random from all empty storage blocks; First judge module 408 is used to judge whether the described DSB data store block of selecting at random is the empty storage block that record is arranged; First removes module 409 is used for when the judge module judgement is, the empty memory block erasing of record is arranged is empty storage block with described; Writing module 406 is used for described data and new data are combined into more new data, and described more new data is write in the described empty storage block of selecting at random; Wipe module 407 and be used to wipe data in the DSB data store block that navigates to; The number of times that accumulative total module 410 is used for the write operation that will at every turn storage block be carried out is accumulated to the total degree of write operation; The 3rd judge module 411 is used to judge that whether the total degree of said write operation is greater than preset times; The 3rd when Switching Module 412 is used for total degree when write operation greater than preset times at random, data in the DSB data store block of selecting are at random write in the target empty storage block of selecting at random, and the described DSB data store block of selecting at random is erased to the sky storage block, the total degree with write operation makes zero simultaneously.
In the present embodiment, second at random Switching Module 402 comprise: first selects unit 4021, the second selects unit 4022, the second judging units, 4025, the second clearing cells, 4026, the second writing units, 4023, the second erase units 4024.
First selects unit 4021 is used for selecting a data storage block at random from all DSB data store block; Second selects unit 4022 is used for selecting a target empty storage block at random from all empty storage blocks; Second judging unit 4025 is used to judge whether described target empty storage block is the empty storage block that record is arranged; Second clearing cell 4026 is used for when second judgment unit judges is, the empty memory block erasing that record will be arranged is empty storage block; Second writing unit 4023 is used for the data in the described DSB data store block are write described target empty storage block; The DSB data store block that second erase unit 4024 is used for selecting at random is erased to the sky storage block.
Wherein, first select unit 4021 and comprise: the first statistics subelement 40210, the first generates subelements 40211, the first locator unit 40212.
The first statistics subelement 40210 is used for the number of statistics storage block; First generates subelement 40211 is used to generate a random number that is not more than all DSB data store block sums; The first locator unit 40212 is used to utilize the data storage block in described random number location.
Especially, first select unit 4021 and can search subelement by second and replace in the device of present embodiment; Correspondingly, second select unit 4022 and can set up subelement by second; Correspondingly, second writing unit 4023 can be selected subelement by second and replaces.
Second searches subelement is used to travel through all storage blocks and searches institute free storage block arranged; Second set up subelement be used to set up one include find be free storage block address list or the physical block number tabulation of free storage block arranged; Second selects subelement is used for selecting a target empty storage block at random from described tabulation.
In the present embodiment, this second is selected unit 4022 and comprise: the second statistics subelement 40221, the second generates subelements 40222, the second locator unit 40223.
The second statistics subelement 40221 is used to add up the number of empty storage block; Second generate subelement 40222 be used to generate one be not more than the random number of free storage block sum arranged; The second locator unit 40223 is used to utilize the target empty storage block in described random number location.
In the present embodiment, select module 405 and comprise: statistic unit 4051, generation unit 4052, positioning unit 4053.
Statistic unit 4051 is used to add up the number of empty storage block; Generation unit 4052 be used to generate one be not more than the random number of free storage block sum arranged; Positioning unit 4053 is used to utilize the empty storage block in described random number location.
Especially, the statistic unit of selecting module 405 4051 in the present embodiment device, generation unit 4052, positioning unit 4053 can also be with searching the unit, set up the unit and select the unit to replace.Wherein, searching the unit is used to travel through all storage blocks and finds institute free storage block arranged; Set up the unit be used to set up one include find be free storage block address list or the physical block number tabulation of free storage block arranged; Selecting the unit is used for selecting an empty storage block at random from described tabulation.
The DSB data store block of 404 location of the locating module in the present embodiment device is made up of logical block number (LBN) and data field data in addition, and the then described data that need to revise are the data field data.So corresponding, writing module 406 combines the data field data earlier and writes in the described empty storage block of selecting at random with new data, described logical block number (LBN) is write in the described empty storage block of selecting at random again.
Writing module 406 in the present embodiment comprises: reading unit 4061, combining unit 4062, writing unit 4063.
Reading unit 4061 is used for described data are read into internal memory; Combining unit 4062 be used for internal memory with described data field data with generate more new data after new data combines; Writing unit 4063 is used for described more new data and logical block number (LBN) are write the described empty storage block of selecting at random.
In the present embodiment the 3rd Switching Module 412 at random comprises: the 3rd selects unit 4120, the four selects unit 4121, the three judging units, 4125, the three clearing cells, 4126, the three writing units, 4122, the three erase units, 4123, the Sangui terrace zero locations 4124.
The 3rd selects unit 4120 is used for selecting a data storage block at random from all DSB data store block; The 4th selects unit 4121 is used for selecting a target empty storage block at random from all empty storage blocks; The 3rd judging unit 4125 is used to judge whether described target empty storage block is the empty storage block that record is arranged; The 3rd clearing cell 4126 is used for when second judgment unit judges is, the empty memory block erasing that record will be arranged is empty storage block; The 3rd writing unit 4122 is used for the data in the described DSB data store block are write described target empty storage block; The 3rd erase unit 4123 is used for the described DSB data store block of selecting at random is erased to the sky storage block; Sangui terrace zero location 4124 is used for the total degree of write operation is made zero.
In the present embodiment device the 3rd selected unit 4120 and comprised: the 3rd statistics subelement 41200 is used for the number of statistics storage block; The 3rd generates subelement 41201 is used to generate a random number that is not more than all DSB data store block sums; The 3rd locator unit 41202 is used to utilize the data storage block in described random number location.
In the present embodiment device the 4th selected unit 4121 and comprised: the 4th statistics subelement 41210, the four generates subelement 41211, the four locator unit 41212.
The 4th adds up subelement 41210, is used to add up the number of empty storage block; The 4th generates subelement 41211, be used to generate one be not more than the random number of free storage block sum arranged; The 4th locator unit 41212 is used to utilize the target empty storage block in described random number location.
Especially, the 4th in the present embodiment device selected unit 4121 and can also be searched subelement, the 4th by the 4th and set up subelement, the 4th and select subelement and form, and wherein the 4th searches subelement, is used to travel through all storage blocks and searches institute free storage block is arranged; The 4th sets up subelement, be used to set up one include find be free storage block address list or the physical block number tabulation of free storage block arranged; The 4th selects subelement, is used for selecting a target empty storage block at random from described tabulation.
The embodiment of the invention mainly is used in the various storeies, for example: flash memory etc. also can prolong the serviceable life of storer simultaneously so that realize improving the operable number of times of storage block.
Through the above description of the embodiments, the those skilled in the art can be well understood to the present invention and can realize by the mode that software adds essential common hardware, can certainly pass through hardware, but the former is better embodiment under a lot of situation.Based on such understanding, the part that technical scheme of the present invention contributes to prior art in essence in other words can embody with the form of software product, this computer software product is stored in the storage medium that can read, floppy disk as computing machine, hard disk or CD etc. comprise that some instructions are used so that a method that contains each embodiment of terminal execution the present invention of storer.
The above; only be the specific embodiment of the present invention, but protection scope of the present invention is not limited thereto, anyly is familiar with those skilled in the art in the technical scope that the present invention discloses; the variation that can expect easily or replacement all should be encompassed within protection scope of the present invention.Therefore, protection scope of the present invention should be as the criterion with the protection domain of claim.

Claims (25)

1. one kind writes the method for data to the Flash storer, it is characterized in that, comprising:
Receive the instruction that writes new data;
The location needs the DSB data store block at the data place of modification;
From all empty storage blocks, select an empty storage block at random; Judge whether the described empty storage block of selecting at random is the empty storage block that record is arranged, wherein, all bytes that the described empty storage block that record arranged is a null data area not all are the empty storage blocks of 0xFF;
If then the empty memory block erasing of record is arranged is empty storage block with described, then described data and the new data that needs to revise is combined into more new data, described more new data is write be erased to the sky storage block described to be had in the empty storage block of record;
If not, then directly described data and the new data that needs to revise is combined into more new data, described more new data is write in the described empty storage block of selecting at random;
The DSB data store block that navigates to is erased to the sky storage block.
2. the method that writes data according to claim 1 is characterized in that, this method also comprises:
After the storer energising, add up the sum of empty storage block, and generate a random number that is not more than described sum, judge whether current empty storage block sum is identical with described random number;
If then the data in the DSB data store block that will select at random write in the target empty storage block of selecting at random; The described DSB data store block of selecting at random is erased to the sky storage block; Wait for and receive the instruction that writes new data;
If not, wait for that then reception writes the instruction of new data.
3. the method that writes data according to claim 1, it is characterized in that, the data of described DSB data store block are made up of logical block number (LBN) and data field data, described data and the new data that described needs are revised is combined into more new data, described more new data write in the described empty storage block of selecting at random comprise:
The data of described DSB data store block are read in the internal memory;
In internal memory, data field data in the described data and new data are combined into more new data;
Described more new data and logical block number (LBN) are write in the described empty storage block of selecting at random.
4. the method that writes data according to claim 3, it is characterized in that, described described more new data and logical block number (LBN) are write in the described empty storage block of selecting at random is: more new data writes in the described empty storage block of selecting at random earlier, logical block number (LBN) is write in the described empty storage block of selecting at random again.
5. the method that writes data according to claim 3 is characterized in that, describedly selects an empty storage block at random comprise from all empty storage blocks:
Generate one be not more than the random number of free storage block sum arranged; Utilize described random number to select an empty storage block; Perhaps
Traveling through all storage blocks finds institute free storage block is arranged; Set up one include find be free storage block address list or the physical block number tabulation of free storage block arranged; From tabulation, select an empty storage block at random.
6. the method that writes data according to claim 1 is characterized in that, with the data that navigate to
Memory block erasing is after the empty storage block, and this method also comprises:
The number of times of the write operation at every turn storage block carried out is accumulated in the total degree of write operation;
Whether the total degree of judging the said write operation is greater than preset times;
If then the data in the DSB data store block that will select at random write in the target empty storage block of selecting at random; The described DSB data store block of selecting at random is erased to the sky storage block; The total degree of write operation is made zero;
If not, then finish this operation.
7. according to claim 2 or the 6 described methods that write data, it is characterized in that the data in the described DSB data store block that will select at random write in the target empty storage block of selecting at random and comprise:
From all DSB data store block, select a data storage block at random;
From all empty storage blocks, select a target empty storage block at random;
Data in the described DSB data store block of selecting are at random write in the described target empty storage block.
8. the method that writes data according to claim 7 is characterized in that, describedly selects a data storage block at random comprise from all DSB data store block:
Generate a random number that is not more than all DSB data store block sums, utilize described data storage block in random number location that is not more than all DSB data store block sums.
9. the method that writes data according to claim 7 is characterized in that, describedly selects a target empty storage block at random comprise from all empty storage blocks:
Generate one be not more than the random number of free storage block sum is arranged, utilize described be not more than be the random number of free storage block sum to select a target empty storage block; Perhaps
Travel through all storage blocks and search institute free storage block is arranged, set up one and include the institute that finds and be the address list of free storage block or institute to be the physical block number of free storage block to tabulate, from tabulate, select a target empty storage block at random.
10. the method that writes data according to claim 9 is characterized in that, before the data in the DSB data store block that will select at random write in the target empty storage block of selecting at random, this method also comprised:
Judge whether the described target empty storage block of selecting at random is the empty storage block that record is arranged;
If then the empty memory block erasing of record is arranged is empty storage block with described;
If not, then directly utilize the described target empty storage block of selecting at random.
11. one kind writes the device of data to the Flash storer, it is characterized in that, comprising:
Receiver module is used to receive the instruction that writes new data;
Locating module is used to locate the DSB data store block at the data place that needs revise;
Select module, be used for selecting an empty storage block at random from all empty storage blocks;
First judge module is used to judge whether the described empty DSB data store block of selecting at random is the empty storage block that record is arranged, and wherein, all bytes that the described empty storage block that record arranged is a null data area not all are the empty storage blocks of 0xFF;
First removes module, be used for when the first judge module judged result when being, the empty memory block erasing of record is arranged is empty storage block with described;
Writing module, be used for data and new data that described needs are revised are combined into more new data, in the judged result of first judge module for not the time, described more new data write direct in the described empty storage block of selecting at random or in the judged result of first judge module when being, described more new data write removes module by first and be erased to empty storage block;
Wipe module, the DSB data store block that is used for navigating to is erased to the sky storage block.
12. the device that writes data according to claim 11, it is characterized in that, the DSB data store block of described locating module location is made up of logical block number (LBN) and data field data, the said write module is combined into more new data with data field data and new data earlier, and described more new data and logical block number (LBN) are write in the described empty storage block of selecting at random.
13. the device that writes data according to claim 12 is characterized in that, the said write module comprises:
Reading unit is used for described data field data are read into internal memory;
Combining unit, be used for internal memory with described data field data with generate more new data after new data combines;
Writing unit is used for described more new data and logical block number (LBN) are write the described empty storage block of selecting at random; The first more new data of wherein said writing unit writes in the described empty storage block of selecting at random, logical block number (LBN) is write in the described empty storage block of selecting at random again.
14. the device that writes data according to claim 12 is characterized in that, this device also comprises:
Second judge module is used for judging that whether current empty storage block sum is less than default value after the storer energising;
Second Switching Module at random when being used for current empty storage block sum less than default value, writes the data in the DSB data store block of selecting at random in the target empty storage block of selecting at random, and the described DSB data store block of selecting at random is erased to the sky storage block.
15. the device that writes data according to claim 14 is characterized in that, described second at random Switching Module comprise:
First selects the unit, is used for selecting a data storage block at random from all DSB data store block;
Second selects the unit, is used for selecting a target empty storage block at random from all empty storage blocks;
Second judging unit is used to judge whether described target empty storage block is the empty storage block that record is arranged;
Second clearing cell is used for when second judgment unit judges is, the empty memory block erasing that record will be arranged is empty storage block;
Second writing unit is used for the data in the described DSB data store block of selecting are at random write described target empty storage block;
Second erase unit, the DSB data store block that is used for selecting at random is erased to the sky storage block.
16. the device that writes data according to claim 15 is characterized in that, described first selects the unit comprises:
First generates subelement, is used to generate a random number that is not more than all DSB data store block sums;
The first locator unit is used to utilize the data storage block in described random number location.
17. the device that writes data according to claim 15 is characterized in that, described second selects the unit comprises:
Second generates subelement, be used to generate one be not more than the random number of free storage block sum arranged;
The second locator unit is used to utilize described random number to select a target empty storage block.
18. the device that writes data according to claim 12 is characterized in that, the described module of selecting comprises:
Generation unit, be used to generate one be not more than the random number of free storage block sum arranged;
Positioning unit is used to utilize the empty storage block in described random number location.
19. the device that writes data according to claim 12 is characterized in that, this device also comprises:
The accumulative total module, the number of times that is used for the write operation that will at every turn storage block be carried out is accumulated to the total degree of write operation;
The 3rd judge module is used to judge that whether the total degree of said write operation is greater than preset times;
The 3rd Switching Module at random, when being used for total degree when write operation greater than preset times, data in the DSB data store block of selecting are at random write in the target empty storage block of selecting at random, and the described DSB data store block of selecting at random is erased to the sky storage block, the total degree with write operation makes zero simultaneously.
20. the device that writes data according to claim 19 is characterized in that, the described the 3rd at random Switching Module comprise:
The 3rd selects the unit, is used for selecting a data storage block at random from all DSB data store block;
The 4th selects the unit, is used for selecting a target empty storage block at random from all empty storage blocks;
The 3rd judging unit is used to judge whether described target empty storage block is the empty storage block that record is arranged;
The 3rd clearing cell is used for when the 3rd judgment unit judges is, the empty memory block erasing that record will be arranged is empty storage block;
The 3rd writing unit is used for the data in the described DSB data store block are write described target empty storage block;
The 3rd erase unit is used for the described DSB data store block of selecting at random is erased to the sky storage block;
The Sangui terrace zero location is used for the total degree of write operation is made zero.
21. the device that writes data according to claim 20 is characterized in that, the described the 3rd selects the unit comprises:
The 3rd generates subelement, is used to generate a random number that is not more than all DSB data store block sums;
The 3rd locator unit is used to utilize the data storage block in described random number location.
22. the device that writes data according to claim 20 is characterized in that, the described the 4th selects the unit comprises:
The 4th generates subelement, be used to generate one be not more than the random number of free storage block sum arranged;
The 4th locator unit is used to utilize described random number to select a target empty storage block.
23. the device that writes data according to claim 20 is characterized in that, the described the 4th selects the unit comprises:
The 4th searches subelement, is used to travel through all storage blocks and searches institute free storage block arranged;
The 4th sets up subelement, be used to set up one include find be free storage block address list or the physical block number tabulation of free storage block arranged;
The 4th selects subelement, is used for selecting a target empty storage block at random from tabulation.
24. the device that writes data according to claim 15 is characterized in that, described second selects the unit comprises:
Second searches subelement, is used to travel through all storage blocks and searches institute free storage block arranged;
Second sets up subelement, be used to set up one include find be free storage block address list or the physical block number tabulation of free storage block arranged;
Second selects subelement, is used for selecting a target empty storage block at random from tabulation.
25. the device that writes data according to claim 12 is characterized in that, the described module of selecting comprises:
Search the unit, be used to travel through all storage blocks and find institute free storage block arranged;
Set up the unit, be used to set up one include find be free storage block address list or the physical block number tabulation of free storage block arranged;
Select the unit, be used for selecting an empty storage block at random from tabulation.
CN2008102470519A 2008-12-31 2008-12-31 Method and device for writing data Active CN101526920B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2008102470519A CN101526920B (en) 2008-12-31 2008-12-31 Method and device for writing data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2008102470519A CN101526920B (en) 2008-12-31 2008-12-31 Method and device for writing data

Publications (2)

Publication Number Publication Date
CN101526920A CN101526920A (en) 2009-09-09
CN101526920B true CN101526920B (en) 2011-04-27

Family

ID=41094790

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2008102470519A Active CN101526920B (en) 2008-12-31 2008-12-31 Method and device for writing data

Country Status (1)

Country Link
CN (1) CN101526920B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104657678B (en) * 2013-11-19 2018-01-09 北京兆易创新科技股份有限公司 Response protection monotone counter, read method and method of counting
CN107665090B (en) * 2016-07-27 2021-09-03 北京忆恒创源科技有限公司 Method for realizing global wear leveling
CN111649786B (en) * 2020-06-03 2022-04-08 东莞深证通信息技术有限公司 Data accumulation method and device, terminal equipment and storage medium
CN112231244B (en) * 2020-12-21 2021-04-20 深圳杰睿联科技有限公司 SIM card file erasing and writing system and method applied to SoftSIM and readable storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6442659B1 (en) * 1998-02-17 2002-08-27 Emc Corporation Raid-type storage system and technique
CN1658171A (en) * 2003-12-19 2005-08-24 雷克萨媒体公司 Faster write operations to nonvolatile memory by manipulation of frequently accessed sectors
CN100424654C (en) * 2005-11-25 2008-10-08 杭州中天微系统有限公司 Access method of matrix data and storage device of the matrix data

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6442659B1 (en) * 1998-02-17 2002-08-27 Emc Corporation Raid-type storage system and technique
CN1658171A (en) * 2003-12-19 2005-08-24 雷克萨媒体公司 Faster write operations to nonvolatile memory by manipulation of frequently accessed sectors
CN100424654C (en) * 2005-11-25 2008-10-08 杭州中天微系统有限公司 Access method of matrix data and storage device of the matrix data

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
JP特开2003-44344A 2003.02.14
JP特开平8-305614A 1996.11.22

Also Published As

Publication number Publication date
CN101526920A (en) 2009-09-09

Similar Documents

Publication Publication Date Title
CN102819496B (en) Address translation method of flash FTL (Flash Translation Layer)
CN101458658B (en) Data storage method and apparatus for flash memory
CN101097781B (en) Apparatus and method for determining data validity of the same
CN102890656B (en) The method improving FLASH service life
CN101354681A (en) Memory system, abrasion equilibrium method and apparatus of non-volatile memory
CN103440207A (en) Caching method and caching device
CN103164490B (en) A kind of efficient storage implementation method of not fixed-length data and device
US8433844B2 (en) Method for managing a memory device having multiple channels and multiple ways, and associated memory device and controller thereof
CN103325417A (en) Nonvolatile memory device, nonvolatile memory system, and program method of the same
CN101901169B (en) Scanner and method
CN101526920B (en) Method and device for writing data
US9075707B2 (en) Data writing method and data storage device
CN101452422B (en) Chip data read-write method, corresponding apparatus and system
CN102253901B (en) Read/write distinguished data storage replacing method based on phase change memory
CN109582593A (en) A kind of FTL address mapping method and data read-write method based on calculating
CN103279424A (en) Damaged queue management device and method of Nand Flash
US20130304971A1 (en) Control device, storage device, and data writing method
CN104484128A (en) Read-once and write-once storage based read-more and write more storage and implementation method thereof
CN103455284A (en) Method and device for reading and writing data
CN104484129A (en) One-read and one-write memory, multi-read and multi-write memory and read and write methods for memories
CN102520885B (en) Data management system for hybrid hard disk
CN102981972A (en) Wear-leveling method for phase change memory
CN103020323B (en) A kind of method of the flash data retrieve stored based on unknown lengths binary chop
CN102426601B (en) Data deleting method and device
CN203311409U (en) Bad queue management device for Nand Flash

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
C56 Change in the name or address of the patentee

Owner name: FEITIAN CHENGXIN TECHNOLOGY CO., LTD.

Free format text: FORMER NAME: BEIJING FEITIAN CHENGXIN SCIENCE + TECHNOLOGY CO. LTD.

CP03 Change of name, title or address

Address after: 100085 Beijing city Haidian District Xueqing Road No. 9 Ebizal building B block 17 layer

Patentee after: Feitian Technologies Co., Ltd.

Address before: 100083, Haidian District, Xueyuan Road, Beijing No. 40 research, 7A building, 5 floor

Patentee before: Beijing Feitian Chengxin Science & Technology Co., Ltd.