CN104834477B - Method for writing data and device based on flash memory - Google Patents

Method for writing data and device based on flash memory Download PDF

Info

Publication number
CN104834477B
CN104834477B CN201410048077.6A CN201410048077A CN104834477B CN 104834477 B CN104834477 B CN 104834477B CN 201410048077 A CN201410048077 A CN 201410048077A CN 104834477 B CN104834477 B CN 104834477B
Authority
CN
China
Prior art keywords
data
block
written
address
flash memory
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
CN201410048077.6A
Other languages
Chinese (zh)
Other versions
CN104834477A (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.)
Tencent Technology Shenzhen Co Ltd
Tencent Cloud Computing Beijing Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201410048077.6A priority Critical patent/CN104834477B/en
Publication of CN104834477A publication Critical patent/CN104834477A/en
Application granted granted Critical
Publication of CN104834477B publication Critical patent/CN104834477B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Read Only Memory (AREA)
  • Techniques For Improving Reliability Of Storages (AREA)
  • Memory System (AREA)

Abstract

The present invention provides a kind of method for writing data based on flash memory, which comprises receives initial data write request;It polymerize multiple initial data write requests according to the data volume of the corresponding data to be written of the initial data write request, matches the data volume total amount of the corresponding data to be written of data write request of polymerization with the positive integer times of block capacity;According to the data write request of the polymerization, the free physical block of quantity corresponding with the multiple of the matched piece of capacity is determined in a flash memory, the corresponding data to be written of the data write request of the polymerization are written to the free physical block of the determination.Method for writing data provided by the invention based on flash memory, it is all to carry out in blocks that data and erasing data, which are written, ensure that the consistent of write-in and erasing, can effectively avoid write-in scale-up problem.The present invention also provides a kind of data transfer apparatus based on flash memory.

Description

Method for writing data and device based on flash memory
Technical field
The present invention relates to field of computer technology, more particularly to a kind of method for writing data and device based on flash memory.
Background technique
Flash memory is a kind of widely used storage medium, wherein Nand Flash(Nand type flash memory, a kind of non-volatile sudden strain of a muscle Deposit) it is a kind of novel flash memory, have read or write speed fast, vibrationless with solid state hard disk, the storage card etc. of Nand type flash memory production Advantage is widely used in the fields such as military, vehicle-mounted, industry control, video monitoring, electric power, medical treatment, internet.
The basic structure of Nand type flash memory includes several pieces, and each piece includes several pages again.The size of block is greater than the ruler of page Very little, by taking current typical case's Nand type flash memory as an example, block size is generally 2M byte, and page size is generally 8K byte.
Nand type flash memory can repeat to write, but repeat to have to carry out erasing operation before writing, and to Nand type flash memory Erasing operation will affect its service life.Wherein, the erasing of Nand type flash memory is in blocks, and to Nand type flash memory Read-write is usually as unit of page.If repeating to write to the same address of Nand type flash memory, need in corresponding piece of the address Data are read out, and after data content to be written more new data, then execute erasing operation, then again by updated data In block after write-in erasing.This process leads to very slow repetition writing rate, while also bringing the problem of write-in is amplified.It writes Enter scale-up problem refer to be written into data write-in Nand type flash memory in during, the data volume of write-in, than data to be written The data volume of itself is more.
To solve the problems, such as write-in amplification in traditional technology, using Nand type flash memory as the solid state hard disk of storage medium and storage Card design scheme introduces hardware mapping layer.The read/write address of Nand type flash memory is divided into two kinds of addresses, physics by hardware mapping layer Address and logical address.The read/write address of user's triggering is logical address, and logical address passes through the conversion of hardware mapping layer, from patrolling It collects address and switchs to physical address, just really execute read-write.The same logical address is write in repetition, by the conversion of hardware mapping layer Afterwards, different physical address can be write, and is invalid data by the corresponding data markers of physical address before, therefore avoid Erasing operation, can reduce write-in scale-up problem.
But Nand type flash memory is after multiple read-write operation, and in the same in Nand type flash memory, part is significant figure According to part is invalid data, and empty block is no or seldom, just needs to carry out garbage reclamation at this time.Garbage reclamation needs to read Valid data in multiple pieces are integrated into the redundant space reserved in Nand type flash memory by the valid data in multiple pieces Then block is wiped the block of only invalid data, to discharge the block of invalid data occupancy.But the process of garbage reclamation introduces The write operation of Nand type flash memory internal, is exaggerated the number write, and may cause the lost of life of Nand type flash memory.And reserved Redundant space causes the memory space for user storage data to reduce, and redundant space is bigger, easier to store in user Garbage reclamation is carried out in the case that space is full, write-in scale-up problem is more serious.
Summary of the invention
Based on this, it is necessary to there are problems that write-in amplification Nand type flash memory, provide a kind of data based on flash memory Wiring method and device.
A kind of method for writing data based on flash memory, which comprises
Receive initial data write request;
It polymerize multiple initial data according to the data volume of the corresponding data to be written of the initial data write request Write request makes the data volume total amount of the corresponding data to be written of data write request of polymerization and the positive integer times of block capacity Match;
According to the data write request of the polymerization, the determining multiple with the matched piece of capacity in Nand type flash memory The determination is written in the corresponding data to be written of the data write request of the polymerization by the free physical block of corresponding quantity Free physical block.
A kind of data transfer apparatus based on flash memory, described device include:
Data write request receiving module, for receiving initial data write request;
Aggregation module, it is multiple for being polymerize according to the data volume of the corresponding data to be written of the initial data write request The initial data write request makes the data volume total amount and block capacity of the corresponding data to be written of data write request of polymerization Positive integer times matching;
Data write. module, for the data write request according to the polymerization, determined in Nand type flash memory with it is described The free physical block of the corresponding quantity of the multiple of matched piece of capacity, the data write request of the polymerization is corresponding to be written The free physical block of the determination is written in data.
Multiple initial data write requests polymerize by the above-mentioned method for writing data based on flash memory, and the data polymerizeing are write Enter and the data volume total amount of corresponding data to be written requested to match with the positive integer times of block capacity, then to matched piece of capacity The corresponding quantity of multiple free physical block in data to be written corresponding to the data write request of polymerization are written.It is every in this way It is secondary that data, the data volume total amount energy of the corresponding data to be written of the data write request of the polymerization of write-in is written to free physical block It is enough to cover one or more physical blocks, the operation such as movement and erasing of data is not needed, realizes and is write in blocks Enter.It is all to carry out in blocks that data and erasing data, which are written, ensure that the consistent of write-in and erasing, can effectively avoid write-in Scale-up problem.
Detailed description of the invention
Fig. 1 is the flow diagram of the method for writing data based on flash memory in one embodiment;
Fig. 2 is the data write request in one embodiment according to polymerization, is determined and matched piece in Nand type flash memory The free physical block of the corresponding quantity of the multiple of capacity determines the corresponding data write-in to be written of the data write request of polymerization Free physical block the step of process;
Fig. 3 is the structural block diagram of the data writing systems based on flash memory in one embodiment;
Fig. 4 is the structural block diagram of the data transfer apparatus based on flash memory in one embodiment;
Fig. 5 is the structural block diagram of one embodiment of the Data write. module in Fig. 4;
Fig. 6 is the structural block diagram of one embodiment of the block mapping block in Fig. 5;
Fig. 7 is the structural block diagram of the data transfer apparatus based on flash memory in another embodiment;
Fig. 8 is the structural block diagram of the data transfer apparatus based on flash memory in one embodiment.
Specific embodiment
In order to make the objectives, technical solutions, and advantages of the present invention clearer, with reference to the accompanying drawings and embodiments, right The present invention is further elaborated.It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, and It is not used in the restriction present invention.
The description of specific distinct unless the context otherwise, the present invention in element and component, the shape that quantity both can be single Formula exists, and form that can also be multiple exists, and the present invention is defined not to this.Although step in the present invention with label into It has gone arrangement, but is not used to limit the precedence of step, unless expressly stated the order of step or holding for certain step Based on row needs other steps, otherwise the relative rank of step is adjustable.It is appreciated that used herein Term "and/or" one of is related to and covers associated listed item or one or more of any and all possible groups It closes.
As shown in Figure 1, in one embodiment, provide a kind of method for writing data based on flash memory, the present embodiment with This method is applied to Nand type flash memory and illustrates, it is to be appreciated that this method can be applied to it is any in blocks into The flash memory of row erasing.This method comprises:
Step 102, initial data write request is received.
When user is intended to that data are written into Nand type flash memory, initial data write-in is triggered by preset data-interface of writing Request, write-in request of data correspond to data to be written.Terminal receive the initial data request and with write-in request of data it is corresponding Data to be written.
Step 104, multiple initial data are polymerize according to the data volume of the corresponding data to be written of initial data write request Write request makes the data volume total amount of the corresponding data to be written of data write request of polymerization and the positive integer times of block capacity Match.
Terminal pre-set buffer area, the size of buffer area are set according to actual needs, herein without limitation.Terminal exists Multiple write-in request of data and corresponding data to be written are buffered in buffer area, thus according to corresponding to initial data write request Data to be written data volume, multiple initial data write requests are polymerize, it is desirable that the data write request pair of polymerization The data volume total amount for the data to be written answered is matched with the positive integer times of block capacity.
Wherein, block capacity refers to the data volume that a physical block or logical block can accommodate, such as a block institute energy The data volume of receiving is 2M byte, then block capacity is 2M byte.The positive integer times of block capacity such as can be 2M byte, 4M word Section, 6M byte, 8M byte etc..
The data volume total amount of the corresponding data to be written of the data write request of polymerization is matched with the positive integer times of block capacity, It can be the positive integer times that above-mentioned data volume total amount is equal to block capacity;Or above-mentioned data volume total amount be greater than the total amount of data The deviation of the block capacity of immediate positive integer times is in default value range.Here the deviation of two values can refer to two values Difference or difference absolute value, be also possible to the ratio of two values.
For example, another is former if the data volume of the corresponding data to be written of an initial data write request is 1M The data volume of the corresponding data to be written of beginning data write request is 0.9M, it is assumed that when data volume total amount and is greater than the total amount of data The ratio of block capacity of immediate positive integer times polymerize when [0.9,1] is interior.Then since the ratio of 1.9M and 2M exist Within [0.9,1], so two initial data write requests can polymerize, and the data volume total amount of corresponding data to be written For 1.9M.For another example, if the data volume of the corresponding data to be written of three initial data write requests be respectively 1.5M, 1.5M and 0.8M, due to total amount of data and be 3.8M, with the block capacity, that is, 4M for being greater than the total amount of data and immediate positive integer times Ratio is within [0.9,1], so three initial data write requests can polymerize.
Step 106, according to the data write request of polymerization, determination is corresponding with the multiple of matched piece of capacity in a flash memory The free physical block of quantity, by the determining free physical block of the corresponding data write-in to be written of the data write request of polymerization.
Specifically, according to the data write request of polymerization, respective numbers need to be determined according to the multiple of matched piece of capacity Free physical block.It, can be by the data write request of polymerization when data to be written are written into determining multiple free physical blocks After corresponding data to be written are divided equally according to the quantity of determining free physical block, it is respectively written into the free physical of each determination Block;Or can write it is full a free physical block is subsequent continues next physical block, here with no restrictions.
For example, if the data volume of the corresponding data to be written of three initial data write requests be respectively 1.5M, 1.5M and 0.8M, then the multiple of matched piece of capacity is 2 times, needs to determine 2 free physical blocks in Nand type flash memory at this time, The total 3.8M of data is written into again to be bisected into 2 free physical blocks of data write-in determination of two 1.9M.
Multiple initial data write requests polymerize by the above-mentioned method for writing data based on flash memory, and the data polymerizeing are write Enter and the data volume total amount of corresponding data to be written requested to match with the positive integer times of block capacity, then to matched piece of capacity The corresponding quantity of multiple free physical block in data to be written corresponding to the data write request of polymerization are written.It is every in this way It is secondary that data, the data volume total amount energy of the corresponding data to be written of the data write request of the polymerization of write-in is written to free physical block It is enough to cover one or more physical blocks, the operation such as movement and erasing of data is not needed, realizes and is write in blocks Enter.It is all to carry out in blocks that data and erasing data, which are written, ensure that the consistent of write-in and erasing, can effectively avoid write-in Scale-up problem.
Erasing to Nand type flash memory physical block is the process to charge to physical block, and physical structure causes erasing to be grasped The minimum operation unit of work must be physical block.It is wiped in traditional technology by page read-write, by block, reads and writes the size with erasing in this way It is inconsistent, be cause write-in amplify basic reason.The present embodiment is realized from software level guarantees that write-in is consistent with erasing, Cost of implementation is low.And will not cause to generate junk data because of multiple write operations are carried out to same, it does not need to set Redundant space is set to carry out garbage reclamation, the memory space so as to which these are originally used for garbage reclamation releases, and is used to Storing data enhances the performance of Nand type flash memory.And under the mixed mode of read-write, garbage reclamation is avoided, it will not be because of Nand type flash memory carries out garbage reclamation and corresponding block unit is prevented to ensure that readwrite performance from responding read-write requests, even if Reusability will not cause performance to decline.
As shown in Fig. 2, in one embodiment, step 106 specifically includes:
Step 202, corresponding for the data write request of polymerization as unit of logical block according to the data write request of polymerization Data to be written distribute continuous logical address;The quantity of the corresponding logical block of the logical address of distribution and matched piece of capacity Multiple it is consistent.
It take basic unit as the data write request pair of polymerization of logical block after terminal obtains the data write request of polymerization The data to be written answered distribute continuous logical address.Wherein logical block is virtual block, virtual capacity and physical block one It causes.Logical address is virtual address, can be a binary sequence, can determine the position in logical block according to logical address It sets.Logical address can specifically include logical block address, logical page address and logic column address, and wherein logical row address indicates to patrol Collect specific byte location in page;Or logical address may include logical block address, logical block bias internal amount.
The corresponding data to be written of data write request as unit of logical block for polymerization distribute continuous logical address, The logical address for referring to the corresponding data to be written of the data write request of polymerization is at least continuous in logical block.It is multiple to patrol The logical address collected between block is also possible to continuously, indicates that write a full logical block writes next logical block again at this time.Such as The corresponding logical address of data to be written is 1000-2000 in the corresponding data to be written of the data write request of polymerization, The corresponding logical address of so next data to be written just must be since 2001.
The quantity of the corresponding logical block of the logical address of distribution is consistent with the multiple of matched piece of capacity, so that distribution is patrolled The quantity for collecting the corresponding logical block in address is equal with the multiple of block capacity, to guarantee to have enough spaces that data to be written are written.
Step 204, the free physical block by the corresponding logical block maps of the logical address of distribution into flash memory, is corresponded to The physical address of the corresponding data to be written of the data write request of polymerization, and the corresponding logical block of logical address for recording distribution With the mapping relations of the physical block of mapping.
Specifically, its corresponding logical block can be determined according to the logical address of distribution, by the corresponding logical block maps To the free physical block in Nand type flash memory, and then obtain physical address.
Physical address may include physical block address, physical page address and physics column address, wherein the object in physical address Manage page address and physics column address can in the logical address of distribution logical page address and logic column address it is consistent, only need true Determine physical block address, and physical block address can be determined according to the block identification of the physical block of mapping.
After completing mapping, the mapping for needing to record the corresponding logical block of logical address of distribution and the physical block of mapping is closed System, or can recorde the mapping relations of logical address and physical address, according to the data to be read when in order to read data Logical address determine its physical address in Nand type flash memory, thus complete read data operation.
Step 206, the data write request of polymerization is written into the free physical block of mapping according to the physical address of acquisition Corresponding data to be written.
Physical address can be accurately located at the specific location in free physical block, can be according to the physical address directly to sky Data to be written corresponding to the data write request of polymerization are written in not busy physical block.
Even if being written by block, but data are repeatedly written to same physical block and also result in write-in scale-up problem.Therefore, In the present embodiment, by step 202~step 206, logical address is first distributed as unit of logical block, then by the logic of distribution For the corresponding logical block maps in address to the free physical block in Nand type flash memory, the data write request for obtaining corresponding polymerization is corresponding Data to be written physical address, and the data write-in of polymerization is written according to the physical address into the free physical block of mapping The corresponding data to be written of request.It can avoid directly being repeatedly written data to same physical block by mapping block in this way and lead Cause write-in scale-up problem.
And the problem of due to production technology, Nand type flash memory can all have bad object when leaving the factory or in subsequent use Block is managed, if directly may result in write-in failure to physical block write-in data, therefore can avoid by mapping block because of bad physical block Caused write-in failure problem.
In one embodiment, in step 204, by sky of the corresponding logical block maps of the logical address of distribution into flash memory The step of not busy physical block, including step 11)~step 12):
Step 11) obtains the erasing of idle physical block in flash memory or has been written into number.
Each physical block of Nand type flash memory can correspond to a block message, wiped or had been written into including the physical block Number can also include indicating whether the data in the physical block information such as effectively mark.Or it can be by real time to object The erase or write operation of reason block is counted to obtain the erasing of idle physical block in Nand type flash memory or have been written into number.
Step 12) will according to the preferential mapping order for having wiped or having had been written into number ascending order of physical block idle in flash memory Free physical block of the corresponding logical block maps of the logical address of distribution into flash memory.
Since the service life of flash memory is limited, it cannot wipe or be written infinitely, so certain mechanism should be used, with Guarantee that each physical block approximate equalization uses, avoids certain physical blocks from reaching service life in advance, to influence entire flash memory Use.
Therefore, specifically, in the present embodiment, free physical block chained list can be established, it is corresponding every in free physical block chained list A physical block has wiped or has had been written into the sequence arrangement of number ascending order according to it.When the physical block that selection needs to map every time, root It is preferentially chosen according to free physical block chained list and has currently wiped or had been written into the least free physical block of number and mapped
In the present embodiment, by step 11)~step 12), by the wiping for obtaining idle physical block in Nand type flash memory Number is removed or has been written into, to wipe or have been written into preferentially reflecting for number ascending order according to physical block idle in Nand type flash memory It penetrates sequence and carries out block mapping, preferentially used so that wiping or being written the few physical block of number, made with reaching the equilibrium of physical block With avoiding the use that a small number of physical blocks reach service life in advance and influence entire Nand type flash memory.
In one embodiment, being somebody's turn to do the method for writing data based on flash memory further includes step 21)~step 22):
Step 21) receives data read request, according to the mapping relations of the logical block and physical block that have recorded, and number According to the logical address of data to be read corresponding to read requests, the physical address of data to be read in a flash memory is determined.
It according to the logical address of distribution when write-in data, is mapped by block, is finally single with physical block according to physical address Data are written into Nand type flash memory in position, and have recorded the mapping relations of logical block and physical block.It, can root when therefore reading data Corresponding logical block is determined according to the logical address of data to be read, to close according to the mapping of the logical block and physical block recorded System determines the physical block in the Nand type flash memory where data to be read, so as to according to determining physics block identification and to The logical address for reading data determines the physical address of data to be read.
Step 22) reads unit by preset data according to determining physical address and reads data;The default unit that reads is less than Or it is equal to a block capacity.
Unit is read according to preset data and reads data, is referred to and is read the data that preset data reads unit-sized every time, The default unit that reads can be a byte, perhaps can be a page capacity or is also possible to a block capacity, can basis Need to set suitable default reading unit.
In the present embodiment, above-mentioned steps 21) in~step 22), it not will lead to write-in scale-up problem when reading data, because This is not limited to read data by page, in fact data can be read according to any default unit that reads, to guarantee to read data Flexibility.
It in one embodiment, should method for writing data based on flash memory further include: every prefixed time interval or every Preset time point obtains the erasing for having the physical block of data in Nand type flash memory or has been written into number, will wipe or Write-in number is transferred to lower than the data of frequency threshold value having in the physical block of data and has currently wiped or had been written into number most Few free physical block, and the mapping relations of the logical block of more new record and physical block.
According to active degree difference, the data stored in Nand type flash memory can be divided into dynamic data and static data, wherein Dynamic data refers to the data often operated, and static data refers to the lower data of operating frequency.Static number is stored in this way According to physical block seldom carry out erase or write operation so that these physical blocks erasing or write-in number be far below other physics The erasing of block or write-in number, cause each physical block using unbalanced.
Therefore, in the present embodiment, every prefixed time interval or every preset time point, such as at interval of 1 day or January, Or 9 points etc. at night of every Friday, it obtains the erasing for having the physical block of data in Nand type flash memory or has been written into number.So It is static data that number, which will have been wiped or had been written into afterwards, lower than the data judging in the physical block for having data of frequency threshold value, from And static data is transferred to and has currently wiped or had been written into the least free physical block of number, to reach the equal of each physical block Weighing apparatus uses, and guarantees the service life of Nand type flash memory.
Wherein, frequency threshold value can be the use with Nand type flash memory and dynamic change, for example frequency threshold value can be with It is positively correlated with the average value for having wiped or having had been written into number of free physical blocks all in Nand type flash memory or frequency threshold value can To be the difference for currently having wiped or having had been written into number at least value and a preset constant.
In one embodiment, the above-mentioned method for writing data based on flash memory can be applied to a kind of data based on flash memory and write Enter system, is somebody's turn to do the structure of the data writing systems based on flash memory as shown in figure 3, including application layer module, software image layer Module and hardware flash memory device layer module.
Specifically, application layer module is asked for receiving initial data write request, and then according to initial data write-in It asks the data volume of corresponding data to be written to polymerize multiple initial data write requests, keeps the data write request of polymerization corresponding The data volume total amount of data to be written is matched with the positive integer times of block capacity.It is subsequently used for the data write request according to polymerization, The corresponding data to be written of data write request as unit of logical block for polymerization distribute continuous logical address;Wherein, divide The quantity of the corresponding logical block of the logical address matched is consistent with the multiple of matched piece of capacity.
Software image layer module, for obtaining the erasing of idle physical block in Nand type flash memory or having been written into number;It presses According to the preferential mapping order for having wiped or having had been written into number ascending order of physical block idle in Nand type flash memory, logically by distribution For the corresponding logical block maps in location to the free physical block in Nand type flash memory, the data write request for obtaining corresponding polymerization is corresponding The physical address of data to be written, and the mapping of the corresponding logical block of logical address for recording distribution and the physical block of mapping is closed System.
Polymerization is written for the physical address according to acquisition into the free physical block of mapping for hardware flash memory device layer module Data write request corresponding to data to be written.
As shown in figure 4, in one embodiment, providing a kind of data transfer apparatus based on flash memory, which includes: Data write request receiving module 420, aggregation module 440 and Data write. module 460.
Data write request receiving module 420, for receiving initial data write request.
Aggregation module 440, it is multiple for being polymerize according to the data volume of the corresponding data to be written of initial data write request Initial data write request, the data volume total amount for making the corresponding data to be written of data write request of polymerization and block capacity are just Integral multiple matching.
Aggregation module 440 is used to buffer multiple write-in request of data and corresponding data to be written in pre-set buffer area, To the data volume of the data to be written according to corresponding to initial data write request, multiple initial data write requests are carried out Polymerization, wherein the positive integer times of the data volume total amount of the corresponding data to be written of the data write request polymerizeing and block capacity Match.
The data volume total amount of the corresponding data to be written of the data write request of polymerization is matched with the positive integer times of block capacity, It can be the positive integer times that above-mentioned data volume total amount is equal to block capacity;Or above-mentioned data volume total amount be greater than the total amount of data The deviation of the block capacity of immediate positive integer times is in default value range.Here the deviation of two values can refer to two values Difference or difference absolute value, be also possible to the ratio of two values.
Data write. module 460 determines and matched piece of capacity in a flash memory for the data write request according to polymerization The corresponding quantity of multiple free physical block, by the determining sky of the corresponding data to be written write-in of the data write request of polymerization Not busy physical block.
Specifically, Data write. module 460 is used for the data write request according to polymerization, according to times of matched piece of capacity Number determines the free physical block of respective numbers.When the data write request institute that polymerization is written into determining multiple free physical blocks When corresponding data to be written, the corresponding data to be written of the data write request that Data write. module 460 can be used for polymerize After dividing equally according to the quantity of determining free physical block, it is respectively written into the free physical block of each determination;Or full one can write A free physical block is subsequent to continue next physical block, here with no restrictions.
Multiple initial data write requests polymerize by the above-mentioned data transfer apparatus based on flash memory, and the data polymerizeing are write Enter and the data volume total amount of corresponding data to be written requested to match with the positive integer times of block capacity, then to matched piece of capacity The corresponding quantity of multiple free physical block in data to be written corresponding to the data write request of polymerization are written.It is every in this way It is secondary that data, the data volume total amount energy of the corresponding data to be written of the data write request of the polymerization of write-in is written to free physical block It is enough to cover one or more physical blocks, the operation such as movement and erasing of data is not needed, realizes and is write in blocks Enter.It is all to carry out in blocks that data and erasing data, which are written, ensure that the consistent of write-in and erasing, can effectively avoid write-in Scale-up problem.
Erasing to Nand type flash memory physical block is the process to charge to physical block, and physical structure causes erasing to be grasped The minimum operation unit of work must be physical block.It is wiped in traditional technology by page read-write, by block, reads and writes the size with erasing in this way It is inconsistent, be cause write-in amplify basic reason.It will not cause to generate rubbish because of multiple write operations are carried out to same Rubbish data, therefore setting redundant space is not needed to carry out garbage reclamation, so as to which these are originally used for depositing for garbage reclamation Storage space releases, and is used to storing data, enhances the performance of Nand type flash memory.And read and write under mixed mode, it avoids Garbage reclamation will not prevent corresponding block unit from responding read-write requests because Nand type flash memory carries out garbage reclamation, It ensure that readwrite performance, performance will not be caused to decline Reusability.
As shown in figure 5, in one embodiment, Data write. module 460 includes: that logical address distribution module 462, block reflect Penetrate module 464 and write-in execution module 466.
Logical address distribution module 462 is polymerization as unit of logical block for the data write request according to polymerization The corresponding data to be written of data write request distribute continuous logical address;The number of the corresponding logical block of the logical address of distribution It measures consistent with the multiple of matched piece of capacity.
After logical address distribution module 462 is used to obtain the data write request of polymerization, it is by basic unit of logical block The corresponding data to be written of the data write request of polymerization distribute continuous logical address.Wherein logical block is virtual block, Virtual capacity is consistent with physical block.Logical address is virtual address, can be a binary sequence, can according to logical address To determine the position in logical block.Logical address can specifically include logical block address, logical page address and logic column address, Wherein logical row address indicates specific byte location in logical page (LPAGE);Or logical address may include logical block address, logic Block bias internal amount.
Data write request of the logical address distribution module 462 for as unit of logical block for polymerization is corresponding to be written Data distribute continuous logical address, refer to that the logical address of the corresponding data to be written of the data write request of polymerization at least exists It is continuous in logical block.Logical address between multiple logical blocks is also possible to continuously, indicates to write a full logic at this time Block writes next logical block again.
The quantity of the corresponding logical block of the logical address of distribution is consistent with the multiple of matched piece of capacity, so that distribution is patrolled The quantity for collecting the corresponding logical block in address is equal with the multiple of block capacity, to guarantee that the data for having enough space write-in polymerizations are write Enter the corresponding data to be written of request.
Block mapping block 464, free physical of the corresponding logical block maps of logical address into flash memory for that will distribute Block, obtains the physical address of the corresponding data to be written of data write request of corresponding polymerization, and records the logical address of distribution The mapping relations of corresponding logical block and the physical block of mapping.
Specifically, block mapping block 464 is used to determine its corresponding logical block according to the logical address of distribution, by this Corresponding logical block maps obtain physical address to the free physical block in Nand type flash memory.
Physical address may include physical block address, physical page address and physics column address, wherein the object in physical address Manage page address and physics column address can in the logical address of distribution logical page address and logic column address it is consistent, only need true Determine physical block address, and physical block address can be determined according to the block identification of the physical block of mapping.
Block mapping block 464 is used for after completing mapping, records the corresponding logical block of logical address and the mapping of distribution The mapping relations of physical block, or can recorde the mapping relations of logical address and physical address, root when in order to read data Its physical address in a flash memory is determined according to the logical address for the data to be read, to complete the operation of reading data.
Execution module 466 is written, polymerization is written into the free physical block of mapping for the physical address according to acquisition Data to be written corresponding to data write request.
The specific position that write-in execution module 466 is used to be accurately located at according to determining physical address in free physical block It sets, so that number to be written corresponding to the data write request of polymerization directly be written into free physical block according to the physical address According to.
Even if being written by block, but data are repeatedly written to same physical block and also result in write-in scale-up problem.Therefore, In the present embodiment, logical address is first distributed as unit of logical block, then by the corresponding logical block maps of the logical address of distribution To the free physical block in Nand type flash memory, the corresponding data to be written of data write request of corresponding polymerization are obtained physically Location, and number to be written corresponding to the data write request of polymerization is written into the free physical block of mapping according to the physical address According to.Data can be avoided directly being repeatedly written by mapping block in this way to same physical block leads to that scale-up problem is written.
And the problem of due to production technology, Nand type flash memory can all have bad object when leaving the factory or in subsequent use Block is managed, if directly may result in write-in failure to physical block write-in data, therefore can avoid by mapping block because of bad physical block Caused write-in failure problem.
As shown in fig. 6, in one embodiment, block mapping block 464 includes: to have wiped or had been written into number to obtain module 464a and mapping execution module 464b.
It has wiped or has had been written into number and obtained module 464a, for obtaining the erasing of idle physical block in flash memory or having write Indegree.
Each physical block of Nand type flash memory can correspond to a block message, wiped or had been written into including the physical block Number can also include indicating whether the data in the physical block information such as effectively mark.Or it wipes or has had been written into and is secondary Number acquisition module 464a can be used for hollow to obtain flash memory by being counted in real time to the erase or write operation of physical block The erasing of not busy physical block has been written into number.
Execution module 464b is mapped, for having wiped or having had been written into the excellent of number ascending order according to physical block idle in flash memory Free physical block of the corresponding logical block maps of the logical address of distribution into flash memory is obtained corresponding polymerization by first mapping order The corresponding data to be written of data write request physical address, and the corresponding logical block of logical address for recording distribution with reflect The mapping relations for the physical block penetrated.
In the present embodiment, free physical block chained list can be established, in free physical block chained list corresponding each physical block according to Its sequence arrangement for having wiped or having had been written into number ascending order.Mapping execution module 464b can be used for the object for selecting to need to map every time When managing block, is preferentially chosen according to free physical block chained list and current wiped or had been written into the least free physical block of number and reflected It penetrates.
In the present embodiment, by obtaining the erasing of idle physical block in Nand type flash memory or having been written into number, to press Block mapping is carried out according to the preferential mapping order for having wiped or having had been written into number ascending order of physical block idle in Nand type flash memory, so that It wipes or is written the few physical block of number preferentially to be used, used with reaching the balanced of physical block, avoid a small number of physical blocks and mention Before reach service life and influence the use of entire Nand type flash memory.
As shown in fig. 7, in one embodiment, which further includes data read module 480, comprising: physical address is true Cover half block 482 and reading execution module 484.
Physical address determining module 482, read requests for receiving data, according to the logical block and physical block recorded The logical address of data to be read corresponding to mapping relations and data read request, determines data to be read in a flash memory Physical address.
It according to the logical address of distribution when write-in data, is mapped by block, is finally single with physical block according to physical address Data are written into Nand type flash memory in position, and have recorded the mapping relations of logical block and physical block.When therefore reading data, physics Address determination module 482 can be used for determining corresponding logical block according to the logical address of data to be read, thus according to having recorded Logical block and the mapping relations of physical block determine the physical block in the Nand type flash memory where data to be read, so as to In the physical address for determining data to be read according to the logical address of determining physics block identification and data to be read.
Execution module 484 is read, reads data for reading unit by preset data according to determining physical address;It is default It reads unit and is less than or equal to a block capacity.
Unit is read according to preset data and reads data, is referred to and is read the data that preset data reads unit-sized every time, The default unit that reads can be a byte, perhaps can be a page capacity or is also possible to a block capacity, can basis Need to set suitable default reading unit.
In the present embodiment, write-in scale-up problem not will lead to when reading data, therefore be not limited to read number by page According in fact data can be read according to any default unit that reads, to guarantee to read the flexibility of data.
As shown in figure 8, in one embodiment, which further includes data migration module 490, for every preset time Interval or every preset time point obtain the erasing for having the physical block of data in Nand type flash memory or have been written into number, will It has wiped or has had been written into number and be transferred to lower than the data of frequency threshold value having in the physical block of data and currently wiped or The least free physical block of number, and the mapping relations of the logical block of more new record and physical block are written.
In the present embodiment, data migration module 490 is used for every prefixed time interval or every preset time point, it obtains There is the erasing of the physical block of data in Nand type flash memory or has been written into number.Then number will have been wiped or has had been written into be lower than The data judging of frequency threshold value having in the physical block of data is static data, has currently been wiped so that static data is transferred to The least free physical block of number is removed or had been written into, is used with reaching the balanced of each physical block, guarantees making for Nand type flash memory Use the service life.
Wherein, frequency threshold value can be the use with Nand type flash memory and dynamic change, for example frequency threshold value can be with It is positively correlated with the average value for having wiped or having had been written into number of free physical blocks all in Nand type flash memory or frequency threshold value can To be the difference for currently having wiped or having had been written into number at least value and a preset constant.
Those of ordinary skill in the art will appreciate that realizing all or part of the process in above-described embodiment method, being can be with Relevant hardware is instructed to complete by computer program, the program can be stored in a computer-readable storage and be situated between In matter, the program is when being executed, it may include such as the process of the embodiment of above-mentioned each method.Wherein, the storage medium can be Magnetic disk, CD, read-only memory (Read-Only Memory, ROM) or random access memory (Random Access Memory, RAM) etc..
The embodiments described above only express several embodiments of the present invention, and the description thereof is more specific and detailed, but simultaneously Limitations on the scope of the patent of the present invention therefore cannot be interpreted as.It should be pointed out that for those of ordinary skill in the art For, without departing from the inventive concept of the premise, various modifications and improvements can be made, these belong to guarantor of the invention Protect range.Therefore, the scope of protection of the patent of the invention shall be subject to the appended claims.

Claims (5)

1. a kind of method for writing data based on flash memory, which comprises
Receive initial data write request;
According to the multiple initial data write-ins of the data volume of the corresponding data to be written of initial data write request polymerization Request matches the data volume total amount of the corresponding data to be written of data write request of polymerization with the positive integer times of block capacity;
According to the data write request of the polymerization, quantity corresponding with the multiple of the matched piece of capacity is determined in a flash memory Free physical block, the corresponding data to be written of the data write request of the polymerization are written to the free physical of the determination Block;
Wherein, the data write request according to the polymerization determines the multiple with the matched piece of capacity in a flash memory The determination is written in the corresponding data to be written of the data write request of the polymerization by the free physical block of corresponding quantity Free physical block, comprising:
According to the data write request of the polymerization, as unit of logical block be the polymerization data write request it is corresponding to Data are written and distribute continuous logical address;The quantity of the corresponding logical block of the logical address of the distribution with described matched piece The multiple of capacity is consistent;
By free physical block of the corresponding logical block maps of the logical address of the distribution into flash memory, the corresponding polymerization is obtained The corresponding data to be written of data write request physical address, and the corresponding logical block of logical address for recording the distribution With the mapping relations of the physical block of the mapping, the free physical block is to have wiped or had been written into number lower than preset threshold The least non-bad physical block of number has currently been wiped or had been written into free physical block, and the preset threshold is to make with flash memory With and the frequency threshold value of dynamic change, physical address include physical block address, physical page address and physics column address, wherein physics Physical page address and physics column address in address in the logical address of distribution logical page address and logic column address it is consistent;
Every prefixed time interval or every preset time point, obtain the physical block for having data in the flash memory erasing or Number is had been written into, will wipe or had been written into number and be transferred to lower than the data in the physical block for having data of frequency threshold value and worked as It is preceding to have wiped or had been written into the least free physical block of number, and the mapping for updating the logical block and physical block of the record is closed System;
The data write request of the polymerization is written into the free physical block of the mapping according to the physical address of the acquisition Corresponding data to be written;
Data read request is received, according to the mapping relations of the logical block and physical block recorded and data read request institute The logical address of corresponding data to be read determines the physical address of the data to be read in a flash memory;
Unit, which is read, by preset data according to the physical address of the determination reads data;The default reading unit is less than or waits In a block capacity, including a byte perhaps a page capacity or a block capacity.
2. the method according to claim 1, wherein the corresponding logical block of the logical address by the distribution The free physical block being mapped in flash memory obtains the physics of the corresponding data to be written of data write request of the corresponding polymerization Address, and the mapping relations of the corresponding logical block of logical address for recording the distribution and the physical block of the mapping, comprising:
It obtains the erasing of idle physical block in the flash memory or has been written into number;
According to the preferential mapping order for having wiped or having had been written into number ascending order of physical block idle in the flash memory, by the distribution Free physical block of the corresponding logical block maps of logical address into flash memory, obtain the data write request of the corresponding polymerization The physical address of corresponding data to be written, and the object for the logical address corresponding logical block and the mapping for recording the distribution Manage the mapping relations of block.
3. a kind of data transfer apparatus based on flash memory, which is characterized in that described device includes:
Data write request receiving module, for receiving initial data write request;
Aggregation module, for multiple described according to the polymerization of the data volume of the corresponding data to be written of the initial data write request Initial data write request, the data volume total amount for making the corresponding data to be written of data write request of polymerization and block capacity are just Integral multiple matching;
Data write. module determines and described matched piece appearance in a flash memory for the data write request according to the polymerization Institute is written in the corresponding data to be written of the data write request of the polymerization by the free physical block of the corresponding quantity of the multiple of amount State determining free physical block;
Wherein, the Data write. module includes:
Logical address distribution module is the polymerization as unit of logical block for the data write request according to the polymerization The corresponding data to be written of data write request distribute continuous logical address;The corresponding logic of the logical address of the distribution The quantity of block is consistent with the multiple of the matched piece of capacity;
Block mapping block, for the free physical block by the corresponding logical block maps of the logical address of the distribution into flash memory, The physical address of the corresponding data to be written of data write request of the corresponding polymerization is obtained, and records the logic of the distribution The mapping relations of the corresponding logical block in address and the physical block of the mapping, the free physical block are secondary to have wiped or having had been written into Number is current lower than in the free physical block of preset threshold to have wiped or has had been written into the least non-bad physical block of number, the default threshold Value is the use with flash memory and the frequency threshold value of dynamic change, physical address include physical block address, physical page address and object Column address is managed, wherein the logical page address in the physical page address in physical address and physics column address and the logical address of distribution It is consistent with logic column address;
Data migration module, for obtaining in the flash memory and having data every prefixed time interval or every preset time point Physical block erasing or have been written into number, will wipe or had been written into number be lower than frequency threshold value the physics for having data Data in block, which are transferred to, has currently wiped or has had been written into the least free physical block of number, and updates the logical block of the record With the mapping relations of physical block;
Execution module is written, is written for the physical address according to the acquisition into the free physical block of the mapping described poly- The corresponding data to be written of the data write request of conjunction;
Data read module, comprising:
Physical address determining module, read requests, are closed according to the mapping of the logical block and physical block recorded for receiving data The logical addresses of data to be read corresponding to system and data read request determines the data to be read in a flash memory Physical address;
Execution module is read, reads data for reading unit by preset data according to the physical address of the determination;It is described pre- If reading unit is less than or equal to a block capacity, including a byte perhaps a page capacity or a block capacity.
4. device according to claim 3, which is characterized in that described piece of mapping block include:
It has wiped or has had been written into number and obtained module, for obtaining the erasing of idle physical block in the flash memory or having been written into secondary Number;
Execution module is mapped, for having wiped or having had been written into preferentially reflecting for number ascending order according to physical block idle in the flash memory Penetrate sequence, by free physical block of the corresponding logical block maps of the logical address of the distribution into flash memory, corresponded to described in The physical address of the corresponding data to be written of the data write request of polymerization, and the logical address that records the distribution is corresponding patrols Collect the mapping relations of the physical block of block and the mapping.
5. a kind of computer readable storage medium, which is characterized in that be stored with computer program, the meter in the storage medium Calculation machine program is loaded by processor and is executed to realize the data write-in side based on flash memory as described in claim 1 to 2 is any Method.
CN201410048077.6A 2014-02-11 2014-02-11 Method for writing data and device based on flash memory Active CN104834477B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410048077.6A CN104834477B (en) 2014-02-11 2014-02-11 Method for writing data and device based on flash memory

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410048077.6A CN104834477B (en) 2014-02-11 2014-02-11 Method for writing data and device based on flash memory

Publications (2)

Publication Number Publication Date
CN104834477A CN104834477A (en) 2015-08-12
CN104834477B true CN104834477B (en) 2019-11-26

Family

ID=53812393

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410048077.6A Active CN104834477B (en) 2014-02-11 2014-02-11 Method for writing data and device based on flash memory

Country Status (1)

Country Link
CN (1) CN104834477B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106126124B (en) * 2016-06-29 2019-05-21 北京联想核芯科技有限公司 A kind of data processing method and electronic equipment
CN106294195B (en) * 2016-07-19 2019-06-21 深圳市领存技术有限公司 A kind of control method and system of 3D flash memory
CN108089822A (en) * 2017-12-20 2018-05-29 北京京存技术有限公司 Management method, system, equipment and the storage medium of storage chip
CN108959517B (en) * 2018-06-28 2021-06-01 河南思维轨道交通技术研究院有限公司 File management method and device and electronic equipment
WO2020000480A1 (en) * 2018-06-30 2020-01-02 华为技术有限公司 Data storage method and data storage device
CN111949560B (en) * 2019-05-16 2024-01-23 兆易创新科技集团股份有限公司 Data writing method and device and storage equipment
US11556275B2 (en) 2021-05-18 2023-01-17 Micron Technology, Inc. Techniques for page line filler data

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101727293A (en) * 2008-10-23 2010-06-09 成都市华为赛门铁克科技有限公司 Method, device and system for setting solid state disk (SSD) memory
CN103324273A (en) * 2012-03-19 2013-09-25 联想(北京)有限公司 Electronic equipment and control method thereof

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030001820A1 (en) * 2001-06-27 2003-01-02 Shaw-Yuan Hou Wireless keyboard based voice control module with display unit

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101727293A (en) * 2008-10-23 2010-06-09 成都市华为赛门铁克科技有限公司 Method, device and system for setting solid state disk (SSD) memory
CN103324273A (en) * 2012-03-19 2013-09-25 联想(北京)有限公司 Electronic equipment and control method thereof

Also Published As

Publication number Publication date
CN104834477A (en) 2015-08-12

Similar Documents

Publication Publication Date Title
CN104834477B (en) Method for writing data and device based on flash memory
EP3869316B1 (en) Hybrid storage
US10120588B2 (en) Sliding-window multi-class striping
US20180089074A1 (en) Techniques to Manage Key-Value Storage at a Memory or Storage Device
CN107111452B (en) Data migration method and device applied to computer system and computer system
CN106448737A (en) Flash memory data reading method and device and solid disk drive
CN104881259B (en) A kind of data processing method and device and storage device
CN106293521A (en) A kind of mapping granule adaptive flash translation layer (FTL) management method
KR20060120263A (en) Interface for a block addressable mass storage system
CN105573681A (en) Method and system for establishing RAID in SSD
CN105117351A (en) Method and apparatus for writing data into cache
CN101135994A (en) Method and apparatus for dividing cache space and cache controller thereof
CN105138282A (en) Storage space recycling method and storage system
CN102253985B (en) File system data management method and system
CN103136215A (en) Data read-write method and device of storage system
US20040088474A1 (en) NAND type flash memory disk device and method for detecting the logical address
US20120137107A1 (en) Method of decaying hot data
CN103309619A (en) NAND Flash memory data storage method
CN103176753B (en) Storing device and data managing method thereof
CN109542800A (en) Method, solid state hard disk and the storage device of garbage disposal based on flash memory
CN106547472A (en) Storage array management method and device
CN105389216A (en) Clipboard data caching method and apparatus and electronic device
CN106844229A (en) The method for organizing of solid state hard disc firmware mapping table, system and device
CN112015672A (en) Data processing method, device, equipment and storage medium in storage system
CN105302912B (en) A kind of date storage method and equipment

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20240104

Address after: 518057 Tencent Building, No. 1 High-tech Zone, Nanshan District, Shenzhen City, Guangdong Province, 35 floors

Patentee after: TENCENT TECHNOLOGY (SHENZHEN) Co.,Ltd.

Patentee after: TENCENT CLOUD COMPUTING (BEIJING) Co.,Ltd.

Address before: 2, 518000, East 403 room, SEG science and Technology Park, Zhenxing Road, Shenzhen, Guangdong, Futian District

Patentee before: TENCENT TECHNOLOGY (SHENZHEN) Co.,Ltd.

TR01 Transfer of patent right