Summary of the invention
In view of this, the object of the present invention is to provide a kind of method and system of setting up logical block and physical block mapping relations, the in the situation that of the blank of the first sector of logical block, realize completion logic piece and effectively mapping one by one of physical block when not carrying out extra write operation.
For achieving the above object, there is following technical scheme:
A method of setting up logical block and physical block mapping relations, physical block comprises multiple Physical Page, described logical block comprises multiple sectors, and the quantity of the sector that comprises of the quantity of the Physical Page that comprises of physical block and logical block is positive integer n; Said method comprising the steps of:
The sector that finds out first non-blank-white in logical block is k sector; By the 0th Physical Page of the corresponding physical block in k sector;
Obtain shining upon formula according to the numerical value of sector number k in the logical block of k sector;
According to described mapping formula, other the each sectors beyond k sector in logical block are corresponded in physical block on corresponding Physical Page;
K is the nonnegative integer that is less than n.
The described numerical value according to sector number k in the logical block of k sector obtains shining upon formula and is specially:
Set mapping formula according to the rule of linear mapping.
Described mapping formula is specially:
When corresponding the 0th Physical Page and k ≠ 0, k sector, for the x sector beyond k sector, the numbering y of corresponding Physical Page in physical block calculates according to following formula;
As k < x < n, y=x-k;
As 0≤x < k, y=x+n-k;
X, y are the nonnegative integer that is less than n.
Described mapping formula is specially:
As corresponding the 0th Physical Page and the k=0 in k sector, for the x sector beyond k sector, the numbering y of corresponding Physical Page in physical block calculates according to following formula;
y=x;
X, y are the nonnegative integer that is less than n.
Describedly according to described mapping formula, other the each sectors beyond k sector in logical block are corresponded in physical block and are specially on corresponding Physical Page:
By sector number substitution mapping formula in the logical block of any sector beyond k sector, calculate the numbering of Physical Page corresponding to this sector in physical block;
Numbering by Physical Page corresponding to any sector beyond k sector in physical block, finds corresponding Physical Page;
Any sector beyond k sector is corresponded to corresponding Physical Page.
A system of setting up logical block and physical block mapping relations, physical block comprises multiple Physical Page, described logical block comprises multiple sectors, and the quantity of the sector that comprises of the quantity of the Physical Page that comprises of physical block and logical block is positive integer n; Described system specifically comprises:
Mapping block is k sector for finding out the sector of the first non-blank-white of logical block; By the 0th Physical Page of the corresponding physical block in k sector; And according to mapping formula, other the each sectors beyond k sector in logical block are corresponded in physical block on corresponding Physical Page;
Computing module, for obtaining shining upon formula according to the numerical value of sector number k in the logical block of k sector;
K is the nonnegative integer that is less than n.
The described numerical value according to sector number k in the logical block of k sector obtains shining upon formula and is specially:
Set mapping formula according to the rule of linear mapping.
Described mapping formula is specially:
When corresponding the 0th Physical Page and k ≠ 0, k sector, for the x sector beyond k sector, the numbering y of corresponding Physical Page in physical block calculates according to following formula;
As k < x < n, y=x-k;
As 0≤x < k, y=x+n-k;
X, y are the nonnegative integer that is less than n.
Described mapping formula is specially:
As corresponding the 0th Physical Page and the k=0 in k sector, for the x sector beyond k sector, the numbering y of corresponding Physical Page in physical block calculates according to following formula;
y=x;
X, y are the nonnegative integer that is less than n.
Described mapping block specifically comprises:
Searching unit, is k sector for finding out the sector of the first non-blank-white of logical block;
Numbering substitution unit, for by sector number substitution mapping formula in the logical block of any sector beyond k sector, calculates the numbering of Physical Page corresponding to this sector in physical block;
Physical Page unit, for the numbering at physical block by Physical Page corresponding to any sector beyond k sector, finds corresponding Physical Page;
Correspondence establishing unit, for by the 0th Physical Page of corresponding k sector physical block; And any sector beyond k sector is corresponded to corresponding Physical Page.
As seen through the above technical solutions, the beneficial effect that the present invention exists is: by the first Physical Page of the corresponding physical block in the first non-blank-white sector with logical block, and shine upon formula and calculate the corresponding relation of other sectors and Physical Page by formulation, in the situation that being not limited to the corresponding first Physical Page in first sector, realize the mapping one by one of logical block and physical block; Thereby under the prerequisite that does not increase extra write operation, avoid the blank of the first Physical Page of physical block; Not only perfect logical block first passage and physical block are set up and are shone upon one by one and present the process of data, have also farthest reduced the write operation of NAND chip, have extended the serviceable life of NAND chip.
Embodiment
For making object, technical scheme and the advantage of the embodiment of the present invention clearer, below in conjunction with the accompanying drawing in the embodiment of the present invention, technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is the present invention's part embodiment, instead of whole embodiment.Based on the embodiment in the present invention, those of ordinary skill in the art, not making the every other embodiment obtaining under creative work prerequisite, belong to the scope of protection of the invention.
The method of logical block provided by the invention and physical block mapping relations, is mainly used in the middle of NAND chip.Described logical block and sector are the logically storage unit of virtual structure of file system; And described physical block and Physical Page are actual storage medium, the data of preserving in storage medium are reflected on virtual logical block or sector by mapping relations, and set up the mapping relations of logical block and physical block, namely the Physical Page in physical block is corresponded to the sector in logical block.Described logical block presents data must, by setting up the relation of linear mapping with physical block, be called as data block with the physical block of logical block linear mapping, and the data that in data block, each Physical Page is preserved are the data that the each sector of logical block presents.And namely each Physical Page each sector in counterlogic piece in order in data block of described linear mapping.
For the ease of the method for the invention is explained and illustrated, first carry out concise and to the point explanation and explanation for linear mapping mode of the prior art herein.In prior art, the mapping relations between logical block and physical block belong to a kind of special form of linear mapping, are called as mapping one by one.Mapping namely meets sector and in logical block, numbers and equal the mapping relations that this Physical Page is numbered in physical block one by one.Shown in Figure 1, be the schematic diagram shining upon one by one.In Fig. 1, suppose that a physical block comprises 4 Physical Page, a logical block comprises 4 sectors.In Fig. 1,4 Physical Page in four square frame difference represents physical pieces, are respectively the 0th page, the 1st page, the 2nd page and the 3rd page according to order from left to right.Label in figure on each Physical Page represents the sector that this Physical Page is corresponding, is the 0th page of correspondence the 0th sector in Fig. 1, the 1st page of correspondence the 1st sector, and the rest may be inferred.
Shown in Figure 2, be a specific embodiment of the method for setting up logical block and physical block mapping relations of the present invention.In the present embodiment, when setting up linear mapping and present data for logical block first passage and physical block, the first sector blank of logical block will cause the abnormal conditions of first Physical Page blank of physical block, the technical scheme of having taked the first Physical Page (i.e. the 0th Physical Page) of the direct sector by first non-blank-white in logical block correspondence physical block, described method is specific as follows:
Described in the present embodiment, in method, physical block comprises multiple Physical Page, and described logical block comprises multiple sectors, and the quantity of the sector that comprises of the quantity of the Physical Page that comprises of physical block and logical block is positive integer n; Said method comprising the steps of;
Step 201, the sector that finds out first non-blank-white in logical block are k sector; By the 0th Physical Page of the corresponding physical block in k sector;
In the prior art, if set up the relation of linear mapping between logical block and physical block, first Physical Page in the inevitable corresponding physical block in first sector in logical block.To such an extent as to between arbitrarily a pair of corresponding sector and Physical Page, all meet this sector and in logical block, number and equal this Physical Page and number in physical block.
But the situation for fear of the first Physical Page blank of physical block occurs, the first Physical Page of the no longer fixing corresponding physical block in first sector with logical block in the present embodiment, but with the first Physical Page of the corresponding physical block in the sector of first non-blank-white in logical block, i.e. the 0th Physical Page.So just, the first Physical Page that has ensured physical block must not be blank, has avoided invalid physical block to occur as the situation of data block.In logical block, the sector of first non-blank-white may be the first sector of logical block, i.e. the 0th sector may be also other sectors.In the present embodiment, be referred to as k sector, k is the nonnegative integer that is less than n.
It should be noted that, according to traditional rule for Physical Page or sector number, the numbering of first sector or Physical Page is numeral 0, and in the situation that sector or Physical Page quantity are n, the Serial Number Range of sector or Physical Page is the arbitrary integer in 0 to n-1 interval so; That is to say last sector or being numbered n-1 of Physical Page and be not n.
Step 202, obtain shining upon formula according to the numerical value of sector number k in the logical block of k sector;
Owing to having changed the setting of the first Physical Page of the corresponding physical block in the first sector of logical block in the present embodiment, so in the present embodiment between corresponding sector and Physical Page, not necessarily always meet sector and number in logical block and equal this Physical Page and number in physical block.In order to set up in this case the relation of linear mapping between logical block and physical block, must reformulate the rule of correspondence of other sectors and Physical Page except k sector, to ensure in physical block each Physical Page each sector in counterlogic piece in order all the time.
In the present embodiment, formulate the rule of correspondence of other sectors and Physical Page except k sector and comprise k=0 and k ≠ 0 two kind of concrete condition.
First, be specifically described for the situation of k ≠ 0.According to the rule of linear mapping, the Physical Page quantity in number of sectors and physical block in logical block is under the prerequisite of n; When corresponding the 0th Physical Page in k sector, inevitable k+1 sector should corresponding the 1st Physical Page, and k+2 sector should corresponding the 2nd Physical Page, and the rest may be inferred, and can obtain n-1 sector should corresponding n-k-1 Physical Page.So far, the Physical Page that it should be corresponding has all been found in each sector k sector after of order, and each sector and also definite corresponding relation each other of order each Physical Page after n-k-1 Physical Page before order k sector.
Under regular situation, n-1 sector has been originally last sector of logical block, but in the present embodiment this by the first sector of logical block the 0th sector be placed on n-1 sector after with carry out corresponding with Physical Page.That is to say, when the corresponding n-k-1 Physical Page in n-1 sector, the 0th sector should corresponding n-k Physical Page.If also there are a series of other sectors between the 0th sector and k sector in order, after being still sequentially arranged in the 0th sector, and carry out equally in order corresponding each follow-up Physical Page.Namely, the 1st sector should corresponding n-k+1 Physical Page, and the 2nd sector should corresponding n-k+2 Physical Page, and the rest may be inferred, and can obtain k-1 sector should corresponding n-1 Physical Page.
So far, in logical block, each sector has all been found the Physical Page that it should be corresponding in order, between the each sector of logical block and the each Physical Page of physical block, has formed complete mutual corresponding rule.All there is Physical Page that in theory should be corresponding with it in each sector, only need be by each sector the corresponding relation of setting up with described Physical Page reality that in theory should be corresponding with it, completed the linear mapping of logical block and physical block.For more easy above-mentioned corresponding rule, the mapping formula of formulating in the present embodiment of explaining intuitively.Described mapping formula is specially:
When corresponding the 0th Physical Page and k ≠ 0, k sector, for the x sector beyond k sector, the numbering y of corresponding Physical Page in physical block calculates according to following formula;
As k < x < n, y=x-k;
As 0≤x < k, y=x+n-k;
X, y are the nonnegative integer that is less than n.
According to above-mentioned mapping formula, only need the sector number of any one sector in known logical block, can extrapolate the numbering of Physical Page corresponding to this sector in physical block, thereby learn that it in theory should be corresponding with that Physical Page.
The situation of k=0 belongs to the special circumstances in the present embodiment, and the first sector that shows logical block is that the 0th sector is exactly non-blank-white sector, so can be directly by the first Physical Page of the corresponding physical block in first sector in logical block.In this situation, the concrete mode of linear mapping and of the prior art shine upon one by one in full accord.Namely arbitrarily between a pair of corresponding sector and Physical Page, all meet this sector and in logical block, number and equal this Physical Page and number in physical block.Mapping formula in k=0 situation can be expressed as:
As corresponding the 0th Physical Page and the k=0 in k sector, for the x sector beyond k sector, the numbering y of corresponding Physical Page in physical block calculates according to following formula;
y=x;
X, y are the nonnegative integer that is less than n.
Step 203, according to described mapping formula, other the each sectors beyond k sector in logical block are corresponded to corresponding Physical Page in physical block;
This step is actual sector and the physical block corresponding relation set up, the process of completion logic piece and physical block linear mapping.Known from step 202, can learn by mapping formula the Physical Page that each sector should be corresponding in theory.So the result that only need calculate according to mapping formula corresponds to each Physical Page on corresponding sector, has also just realized the linear mapping of logical block and physical block.In the present embodiment, linear mapping is no longer limited to the first Physical Page of the inevitable corresponding physical block in first sector of logical block, has avoided first Physical Page to occur blank situation, and has not increased extra write operation.
Concrete, described according to described mapping formula, other the each sectors beyond k sector in logical block are corresponded in physical block to the step on corresponding Physical Page can be detailed be described as following:
Step 231, by sector number substitution mapping formula in the logical block of any sector beyond k sector, calculate the numbering of Physical Page corresponding to this sector in physical block;
Step 232, numbering by Physical Page corresponding to any sector beyond k sector in physical block, find corresponding Physical Page;
Step 233, any sector beyond k sector is corresponded to corresponding Physical Page.
Shown in Figure 3, be the schematic diagram of linear mapping described in the present embodiment.In Fig. 3, be in n=4 and k=2 situation, the concrete condition of linear mapping.In Fig. 3,4 Physical Page in four square frame difference represents physical pieces, are respectively the 0th page, the 1st page, the 2nd page and the 3rd page according to order from left to right.Label in figure on each Physical Page represents the sector that this Physical Page is corresponding.In the present embodiment, k equals 2, and namely first non-blank-white sector is the 2nd sector in logical block, the 2nd sector is corresponded to the 0th Physical Page of physical block.
By n=4 and the above-mentioned mapping formula of k=2 substitution, calculate corresponding the 2nd Physical Page in the 0th sector again, corresponding the 3rd Physical Page in the 1st sector, corresponding the 1st Physical Page in the 3rd sector.Set up the linear mapping relation of logical block and physical block according to above-mentioned result of calculation, as shown in Figure 3.
The beneficial effect that the present embodiment exists is, by the first Physical Page of the corresponding physical block in the first non-blank-white sector with logical block, and shine upon formula and calculate the corresponding relation of other sectors and Physical Page by formulation, in the situation that being not limited to the corresponding first Physical Page in first sector, realize the mapping one by one of logical block and physical block; Thereby under the prerequisite that does not increase extra write operation, avoid the blank of the first Physical Page of physical block; Not only perfect logical block first passage and physical block are set up and are shone upon one by one and present the process of data, have also farthest reduced the write operation of NAND chip, have extended the serviceable life of NAND chip.
Shown in Figure 4, be a specific embodiment of the system of setting up logical block and physical block mapping relations of the present invention.In the present embodiment, described system be corresponding embodiment illustrated in fig. 2 described in the virtual system that exists of method, the two technical scheme is in full accord in essence.Concrete, in the present embodiment, physical block comprises multiple Physical Page, and described logical block comprises multiple sectors, and the quantity of the sector that comprises of the quantity of the Physical Page that comprises of physical block and logical block is positive integer n; Described system specifically comprises:
Mapping block is k sector for finding out the sector of the first non-blank-white of logical block; By the 0th Physical Page of the corresponding physical block in k sector; And according to mapping formula, other the each sectors beyond k sector in logical block are corresponded in physical block on corresponding Physical Page;
Computing module, for obtaining shining upon formula according to the numerical value of sector number k in the logical block of k sector;
K is the nonnegative integer that is less than n.
The described numerical value according to sector number k in the logical block of k sector obtains shining upon formula and is specially:
Set mapping formula according to the rule of linear mapping.
Described mapping formula is specially:
When corresponding the 0th Physical Page and k ≠ 0, k sector, for the x sector beyond k sector, the numbering y of corresponding Physical Page in physical block calculates according to following formula;
As k < x < n, y=x-k;
As 0≤x < k, y=x+n-k;
X, y are the nonnegative integer that is less than n.
As corresponding the 0th Physical Page and the k=0 in k sector, for the x sector beyond k sector, the numbering y of corresponding Physical Page in physical block calculates according to following formula;
y=x;
X, y are the nonnegative integer that is less than n.
Described mapping block specifically comprises:
Searching unit, is k sector for finding out the sector of the first non-blank-white of logical block;
Numbering substitution unit, for by sector number substitution mapping formula in the logical block of any sector beyond k sector, calculates the numbering of Physical Page corresponding to this sector in physical block;
Physical Page unit, for the numbering at physical block by Physical Page corresponding to any sector beyond k sector, finds corresponding Physical Page;
Correspondence establishing unit, for by the 0th Physical Page of corresponding k sector physical block; And any sector beyond k sector is corresponded to corresponding Physical Page.
Accordingly, the beneficial effect that described in the present embodiment, system realizes is: by the first Physical Page of the corresponding physical block in the first non-blank-white sector with logical block, and shine upon formula and calculate the corresponding relation of other sectors and Physical Page by formulation, in the situation that being not limited to the corresponding first Physical Page in first sector, realize the mapping one by one of logical block and physical block; Thereby under the prerequisite that does not increase extra write operation, avoid the blank of the first Physical Page of physical block; Not only perfect logical block first passage and physical block are set up and are shone upon one by one and present the process of data, have also farthest reduced the write operation of NAND chip, have extended the serviceable life of NAND chip.
The above is only the preferred embodiment of the present invention; it should be pointed out that for those skilled in the art, under the premise without departing from the principles of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.