Disclosure of Invention
Aiming at the defects in the prior art, the invention discloses a replacement and write-back self-adaptive buffer area management method, which not only can dynamically adjust a replacement strategy according to load read-write characteristics to improve the read-write hit rate of the buffer area, but also can retain a hot data page during cluster write-back and adjust a write-back strategy according to garbage recovery pressure of a Flash Translation Layer (FTL) to reduce the erasing times of a bottom layer flash memory block.
In order to realize the purpose of the invention, the invention adopts the following technical scheme:
a replacement and write-back self-adaptive buffer area management method is disclosed, wherein the buffer area is divided into a buffer block record table, a write buffer area and a read buffer area; the cache block record table is used for recording the position information of data pages belonging to the same logical data block in a buffer area, the write buffer area is used for caching the data pages which are modified in response to a write request, and the read buffer area is used for caching the data pages which are only in response to a read request and are not modified;
the management method comprises the following steps:
s1, when the access request comes, inquiring whether the cache block record table contains the cache block information corresponding to the request, if yes, executing S2, otherwise, executing S4;
s2, inquiring whether a position pointer pointing to the requested data page exists in the cache block record table, if so, executing S3, otherwise, executing S5;
s3, transferring the hit data page to the MRU position of the corresponding buffer area, and updating the position pointer list in the corresponding buffer block record table; then executing S8;
s4, adding corresponding record block information to the buffer block record table, initializing all information of the record block, and then executing S5;
s5, judging whether the current buffer area is full; if yes, executing S6, otherwise, executing S7;
s6, comparing the size of the read buffer with a target threshold Tau; if so, selecting the data page at the LRU position of the read buffer area to be removed, otherwise, selecting the data page at the LRU position of the write buffer area as a removal item and executing self-adaptive cluster write-back; updating record block information corresponding to the removed data page, and then executing S7;
s7, loading the missing request data page into the corresponding buffer area, adding the position pointing to the data page into the position pointer list of the corresponding cache block record table, and updating the corresponding record block information; then executing S8;
s8, starting a replacement strategy threshold value adjusting mechanism to adjust the threshold value Tau; and finally, ending the processing of the request.
Further, the read buffer and the write buffer adopt LRU management queues, and when the buffer hits requests and loads new data pages, the hit requests and the loaded new data pages are migrated to MRU positions of the queues.
Further, in the cache block record table, the information of one record block includes: the number BlkNum of the cache block, the number BlkSize of data pages belonging to the same record block in the buffer area, a clean page position pointer list C-list-index belonging to the same record block and a dirty page position pointer list D-list-index belonging to the same record block.
Further, in step S3, the step of updating the location pointer list in the corresponding cache block record table specifically includes:
removing an old position pointer pointing to the migration data page from the C-list-index or D-list-index list, then judging a migration position, and if the migration position is migrated into the read buffer area, storing the position pointer into the corresponding C-list-index in the cache block; otherwise, the position pointer of the data page is stored into the D-list-index in the record block.
Further, in step S6, the updating the record block information corresponding to the removed data page specifically includes:
and finding an old position pointer pointing to the removed data page from the C-list-index or D-list-index list, removing the old position pointer, and updating the BlkSize of the corresponding recording block to be BlkSize-1.
Further, in step S7, the adding the location pointing to the data page to the location pointer list of the corresponding cache block record table, and updating the corresponding record block information specifically includes:
judging the type of the request, and if the request is a read request, storing the position pointer of the newly added data page into the corresponding cache record block C-list-index; otherwise, the position pointer of the data page is stored in the D-list-index of the recording block, and then the BlkSize of the corresponding recording block is updated to be BlkSize + 1.
Further, in step S6, the adaptive clustering write-back process includes:
s61, selecting the data page at the position of the write buffer LRU as a removal object, inquiring the D-list-index information in the cache record block corresponding to the data page, and then executing S62;
s62, sequentially reading data pages pointed by the position pointers of the D-list-index, judging the data pages pointed by the position pointers of the D-list-index according to the principle that the data pages positioned at the front half part of the cache queue are hot data, adding the data pages judged to be hot into the reserved set phi, and then executing S63;
s63, calculating the current write amplification factor
Calculating the current write back threshold according to the current write amplification factor W
Wherein Bw is a statistical value of write-back times of the cache region in a fixed period; fw is a flash memory write operation frequency counting value in a fixed period; BlkMaxSize is the logical data block size, t is a constant coefficient;
then executing S64;
s64, calculating the filling page number E ═ BlkMaxSize-N, wherein N is the number of data pages of the current recording block in the writing buffer area, and then comparing the sizes of E and Th; if E is less than or equal to Th, executing S65; otherwise, go to S66;
s65, starting page filling, reading E filling pages from the bottom layer flash memory and writing back dirty pages to form a whole data block and writing back the whole data block into the bottom layer flash memory; then executing S67;
s66, not starting page filling, completely writing back the dirty pages in the D-list-index into the bottom layer flash memory, and executing S67;
s67, all data pages in the aggregate phi are moved to a read buffer area, the position information of the D-list-index in a cache block record table of an original data block is deleted, and a new position pointer after transfer is stored in the C-list-index; and finally ending the cluster write-back operation.
Further, in step S8, the starting of the replacement policy threshold adjustment mechanism adjusts the threshold Tau, and the specific adjustment process is as follows:
s81, judging whether the current request is hit, if yes, executing S82, otherwise, executing S83;
s82, judging the request type and the hit area, if the read buffer area hits, adding 1 to CRH; if the read buffer write hits, then CWH adds 1; if the write buffer area is read hit, DRH adds 1; if the write buffer zone is hit, adding 1 to CRH; finally, executing S83;
s83, updating the current TCount, that is, TCount +1, and updating the statistical value Bw and the statistical value Fw, and then executing S84;
s84, judging whether TCount reaches the threshold updating cycle cycleTime, if so, executing S85, otherwise, ending the updating operation of the threshold Tau;
wherein, CRH is the read hit statistical variable of the read buffer, CWH is the write hit statistical variable of the read buffer; DRH is a read hit statistical variable of a write buffer area, and DWH is a write hit statistical variable of the write buffer area; TCount is the current request operation count; the CycleTime is a threshold updating period;
s85, calculating a target write buffer unity gain DR, a target read buffer unity gain CR:
wherein BufSize is the size of the total read-write buffer, Tau' is the threshold before updating,
cr and Cw are normalized to obtain a read-write delay cost coefficient:
wherein, ReadDelay and WriteDelay are read delay and write delay in a period respectively; and then S86 is executed.
S86, update threshold Tau:
and simultaneously updating the write-back frequency statistic Bw of the period buffer area to be 0, the period flash memory write operation frequency statistic Fw to be 0, the period count value TCount to be 1, and finally ending the updating operation of the threshold Tau.
Compared with the prior art, the invention has the beneficial effects that:
the replacement and write-back self-adaptive buffer management method provided by the invention adopts a page-level management mode when loading and rejecting data pages, and can sense the change of load reading and writing characteristics by periodically and self-adaptively adjusting the read buffer threshold value, so that the management method can obtain higher cache hit rate under various load conditions. Secondly, when the dirty pages are clustered and written back, the management method provided by the invention can sense the pressure of FTL layer garbage recovery, adaptively adjust the write-back strategy, effectively reduce the number of times of erasing extra blocks caused by FTL garbage recovery, and improve the overall performance and service life of the solid state disk.
Detailed Description
In order that those skilled in the art will better understand the technical solutions of the present invention, the following detailed description of the present invention is provided in conjunction with the accompanying drawings and the specific embodiments.
For further detailed description of the invention, it is first necessary to give a definition of the concepts related to the invention:
caching a data page: the basic reading and writing unit of the cache is consistent with the physical page size of the flash memory.
Caching a data block: and carrying out division operation on the size of the physical block by the data request page address to obtain a set consisting of data pages with consistent quotient, wherein the maximum contained page number of the data block is consistent with the contained physical page number of the underlying physical block.
Logical page address: the host I/O request P is numbered according to the identified logical address (LPN) of its file system.
Logical block number: which is also the Number of the cached data Block (Block Number, BlkNum), specifies the BlkNum of the request P as its LPN divided by the maximum Number of pages of the data Block.
The invention provides a replacement and write-back self-adaptive buffer area management method, which divides a cache into three parts: a cache block record table, a Write Buffer (Write Buffer) and a Read Buffer (Read Buffer).
The buffer block record table is used for recording the position and the state of different data pages belonging to a data block in the buffer area. The cache block record table accelerates the query, update and write-back operations of the requested data page by recording the position pointers of different data pages.
As shown in fig. 1, in the cache block record table, the information of the record block specifically includes: the number of the current buffer block BlkNum, the number of data pages BlkSize which belong to the recording block in the current buffer area, a clean page position pointer list C-list-index which belongs to the recording block in the same way, and a dirty page position pointer list D-list-index which belongs to the recording block in the same way. The size of the cache block is consistent with the size of the physical block of the actual bottom layer, namely the number of the contained data pages is the same, and the size value of the cache block is BlkMaxSize. Dividing BlkMaxSize by the Logical Page Number (LPN) of the corresponding data Page, and recording the result as the Number of the cache block to which the data Page belongs, wherein the corresponding remainder is the offset of the cache block.
The write buffer area is used for caching modified data pages (dirty pages) after responding to the write request, and the data pages of the buffer area form a queue for management according to an LRU principle; meanwhile, the data pages in the buffer area are divided into cold pages and hot pages, the data pages in the first half are hot pages, and the data pages in the second half are cold pages.
The read buffer is used for buffering data pages (clean pages) which are not modified only in response to read requests, and the data pages of the buffer are also managed by an LRU queue. The data page in the buffer will be migrated to the write buffer after responding to the write request, and similarly, the hot data page in the write buffer will also be migrated to the read buffer when the write back occurs.
As shown in FIG. 2, the queue size of the read/write buffers changes due to the dynamic selection of the replacement object during the replacement process.
And carrying out cycle statistics on the hit condition of the read-write buffer, the bottom layer read-write delay, the write-back times of the buffer and the update-write times of the bottom layer data page.
Recording a read hit statistical variable of a write buffer area in a fixed observation period as DRH, and recording a write hit statistical variable of the write buffer area as DWH; recording a read hit statistical variable of the read buffer as CRH, and recording a write hit statistical variable of the read buffer as CWH; the number of write back times of the cache region in the period is recorded as Bw, and the number of write operation times of the flash memory in the period is recorded as Fw; the write delay in this cycle is denoted as WriteDelay and the read delay is denoted as ReadDelay.
When the data page of the write buffer is selected as a replacement object and written back to the flash memory, the self-adaptive clustering write-back mechanism is triggered.
As shown in fig. 3, in the adaptive clustering write-back mechanism, a write-back cache block is determined from a replacement data page, and a set of written-back dirty pages is determined by using record information of D-list-index in the cache block record while a hot dirty page is retained. And in the cluster write-back process, dynamically selecting whether to adopt page filling according to the current write amplification factor. The operation process is as follows:
s61, selecting the data page V of the write buffer LRU position as the elimination object, inquiring the D-list-index information in the cache record block corresponding to the data page, and then executing S62.
S62, data pages pointed by the position pointer of the D-list-index are sequentially read, the data pages are judged according to the principle that the data pages positioned at the front half part of the buffer queue are hot data, the data pages judged to be hot are added into the reserved set phi, and then S63 is executed.
S63, calculating the current write back threshold valueWherein,and then S64 is executed.
S64, calculating the filling page number E ═ BlkMaxSize-N, wherein N is the number of data pages of the current recording block in the writing buffer area, and then comparing the sizes of E and Th; if E is less than or equal to Th, executing S65; otherwise, S66 is executed.
And S65, enabling page filling, reading the E filling pages from the bottom layer flash memory and writing back the dirty pages to form a whole data block and writing back the whole data block into the bottom layer flash memory, and then executing S67.
S66, not starting page filling, writing all dirty pages in the D-list-index back to the bottom layer flash memory, and executing S67.
S67, all data pages in the aggregate phi are moved into a read buffer area, meanwhile, the position information of the D-list-index in the cache block record table of the original data block is deleted, meanwhile, the new position pointer after the transfer is stored into the C-list-index, and finally, the clustering write-back operation is finished.
In the management method proposed by the present invention, when a data page is replaced, a replacement buffer object is selected by comparing a threshold Tau (the size of a current target read buffer) with the size of a current read buffer. The threshold Tau will integrate the hit condition of the current read-write buffer and the read-write delay of the bottom layer, and perform periodic adjustment, the threshold adjustment mechanism is shown in fig. 4, and the process is as follows:
s81, judging whether the current request is hit, if yes, executing S82, otherwise, executing S83;
s82, judging the request type and the hit area, if the read buffer area hits, adding 1 to CRH; if the read buffer write hits, then CWH adds 1; if the write buffer area is read hit, DRH adds 1; if the write buffer zone is hit, adding 1 to CRH; finally, executing S83;
s83, updating the current TCount, that is, TCount +1, and updating the statistical value Bw and the statistical value Fw, and then executing S84;
s84, judging whether TCount reaches the threshold updating cycle cycleTime, if so, executing S85, otherwise, ending the threshold updating operation;
wherein, CRH is the read hit statistical variable of the read buffer, CWH is the write hit statistical variable of the read buffer; DRH is a read hit statistical variable of a write buffer area, and DWH is a write hit statistical variable of the write buffer area; TCount is the current request operation count; the CycleTime is a threshold updating period;
s85, calculating a target write buffer unity gain DR, a target read buffer unity gain CR:
wherein BufSize is the size of the total read-write buffer, Tau' is the threshold before updating,
cr and Cw are normalized to obtain a read-write delay cost coefficient:
wherein, ReadDelay and WriteDelay are read delay and write delay in a period respectively; and then S86 is executed.
S86, update threshold Tau:
and simultaneously updating the write-back frequency statistic Bw of the period buffer area to be 0, the period flash memory write operation frequency statistic Fw to be 0, the period count value TCount to be 1, and finally ending the updating operation of the threshold Tau.
As shown in fig. 5, the general flow of request processing of the present invention includes the following steps:
s1, when a request P arrives, the corresponding cache block number pBlkNum is found out according to the conversion of the LPN number of the request P, whether the cache block number exists in the cache block record table is inquired, if so, S2 is executed, otherwise, S4 is executed;
s2, traversing the position pointer in the cache block record table entry, inquiring whether the request P exists in the buffer area, if so, executing S3, otherwise, executing S5;
s3, interpreting the position of the buffer area where the requested data page is located, moving the hit data page to the MRU position of the corresponding buffer area, updating the position pointer list in the record table entry of the corresponding buffer block, removing the old pointer pointing to the data page, and storing the new pointer pointing to the position of the data page; then executing S8;
s4, adding number pBlkNum cache block table entry information into the cache block record table, initializing BlkNum ═ pBlkNum, BlkSize ═ 0, and executing S5 after D-list-index and C-list-index are null;
s5, judging whether the current buffer area is full, if so, executing S6, otherwise, executing S7;
s6, comparing the size of the current read buffer area with the size of the threshold Tau, if so, selecting the data page at the LRU position of the read buffer area to remove; otherwise, selecting the data page at the LRU position of the write buffer area as a replacement buffer area, and executing a self-adaptive clustering write-back mechanism; finding an old position pointer pointing to the removed data page from the C-list-index or D-list-index list, removing the old position pointer, and updating BlkSize of the corresponding recording block to BlkSize-1; thereafter, S7 is executed;
s7, reading the missing request data page from the flash memory into a buffer area, and simultaneously interpreting the request type; if the data page is a read request, loading the data page into a read buffer area, and simultaneously storing a pointer pointing to the position of the data page into a C-list-index of a cache block record; otherwise, loading the data page into a write buffer zone, and simultaneously storing the position pointer into the D-list-index of the corresponding buffer block record; then, update BlkSize ═ BlkSize +1 in the cache record table, and then execute S8;
and S8, starting the period threshold Tau, carrying out period adjustment on the threshold Tau, and finally ending the processing of the request.
In step S3, the step of updating the location pointer list in the corresponding cache block record table specifically includes:
s31, judging the position of the buffer area where the requested data page is located, and if the requested data page is the write buffer area, executing S32; if it is the read buffer, go to S33;
s32, moving the hit data page to the MRU position of the write buffer area, updating the D-list-index in the corresponding buffer block record table entry, removing the old pointer pointing to the data page, and storing the new pointer pointing to the data page position into the D-list-index; then executing S8;
s33, moving the hit data page to the MRU position of the read buffer area, updating the corresponding C-list-index, eliminating the old pointer pointing to the data page, and storing the new position pointer into the C-list-index; and then S8 is executed.
For further explanation of the processing flow of the management method of the present invention, a specific set of actual request processing examples is described, and the processing procedure of the example is shown in fig. 6.
In this example, the data block size is 4 data pages, the buffer size is 10 data pages, the read/write delay ratio is fixed to W/R4/1, the write amplification factor is constant to W1.5, the threshold update period is 10, the current period count value TCount is 1, and the initial value of the threshold Tau is 5.
In the present example, the request sequence is as shown in fig. 6, and consists of the logical address of the request and the request type, e.g. (R, 20), representing a read request with an access data page LPN of 20.
In this example, the process flow for the first request (R, 20):
c1, obtaining the cache block number pBlkNum of 20/4 of 5 by LPN conversion, and querying whether the record information of the cache block number exists in the cache block record table.
And C2, loading a record table entry of which pBlkNum is 5 into the cache block record table when the information of the cache block does not exist, and updating the block number BlkNum of the table entry which BlkSize is 0 and the C-list-index and the D-list-index are null.
C3, load request page into buffer, find buffer full, compare read buffer size RL (4) with current threshold Tau (5), and select write buffer LRU position LPN 13 as replacement object.
C4, replacement page (LPN 13) belongs to buffer block VBlkNum 13/4 3, dirty page LPN 14 belonging to the buffer block is reserved for hot requirement, current write back threshold valueGet 2 for integer, fill page is 2, select monoblock to write back, and read the buffer area and include other data pages, do not need extra reading operation, the direct monoblock writes back can.
C5, setting the D-list-index in the 3 buffer block with VBlkNum to be empty, moving the data page with LPN to be 14 to the tail part of the read buffer queue, and storing the position pointer pointing to the data page into the C-list-index
C6, loading the request into buffer, judging the request as read type, loading the data page with LPN-20 into MRU position of read buffer, storing the position pointer into C-list-index with pBlkNum-20/4-5, and updating BlkSize-1
And C7, starting the updating of the period threshold Tau, wherein the period count value TCount is accumulated to be 2 because of missing the request, and the TCount is judged to be less than the updating period cycleTime, so that the updating adjustment is directly finished, and the operation of the request is finished.
In this example, the process flow for the second request (W, 1):
c8, obtaining the cache block number pBlkNum 1/4 0 by LPN conversion, and querying whether the record information of the cache block number exists in the cache block record table.
C9, traversing the cache block C-list-index to find that the data page with LPN 1 is in the read buffer
C10, judging the type of the request is write request, moving the data page from the read buffer to the MRU position of the write buffer, clearing the position pointer of the C-list-index, storing the new position pointer of the data page into the D-list-index of the buffer block record table
C11, starting the updating of the period threshold Tau, because it is the write hit of the read buffer, the statistical value CWH is accumulated, then the period count value TCount is accumulated to 3, and the adjustment is finished after the update period is not reached, and the operation of this request is finished.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.