TWI612421B - Method of dynamically arranging data for flash memory - Google Patents

Method of dynamically arranging data for flash memory Download PDF

Info

Publication number
TWI612421B
TWI612421B TW106102092A TW106102092A TWI612421B TW I612421 B TWI612421 B TW I612421B TW 106102092 A TW106102092 A TW 106102092A TW 106102092 A TW106102092 A TW 106102092A TW I612421 B TWI612421 B TW I612421B
Authority
TW
Taiwan
Prior art keywords
data
start address
flash memory
offset
logical
Prior art date
Application number
TW106102092A
Other languages
Chinese (zh)
Other versions
TW201828065A (en
Inventor
楊易城
Original Assignee
宇瞻科技股份有限公司
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 宇瞻科技股份有限公司 filed Critical 宇瞻科技股份有限公司
Priority to TW106102092A priority Critical patent/TWI612421B/en
Application granted granted Critical
Publication of TWI612421B publication Critical patent/TWI612421B/en
Publication of TW201828065A publication Critical patent/TW201828065A/en

Links

Abstract

本發明公開一種快閃記憶體的動態對齊資料方法,運用於具有微控制器及快閃記憶體的快閃儲存裝置,包括下列步驟:微控制器接收包括邏輯起始位址的資料寫入指令;取得累積偏移量並依據邏輯起始位址及快閃記憶體的配置單位容量更新累積偏移量;將邏輯起始位址加上更新後累積偏移量以獲得實體起始位址;及,由快閃記憶體的實體起始位址開始將對應資料寫入指令的資料寫入快閃記憶體。本發明可有效提升快閃記憶體的隨機讀寫效率。 The invention discloses a method for dynamically aligning data of a flash memory, which is applied to a flash storage device having a microcontroller and a flash memory, and includes the following steps: the microcontroller receives a data writing instruction including a logical start address ; Obtain the cumulative offset and update the cumulative offset based on the logical start address and the configuration unit capacity of the flash memory; add the updated logical offset to the logical start address to obtain the physical start address; And, starting from the physical start address of the flash memory, the data corresponding to the data write command is written into the flash memory. The invention can effectively improve the random read and write efficiency of the flash memory.

Description

快閃記憶體的動態對齊資料方法 Method for dynamically aligning data of flash memory

本發明涉及快閃記憶體,特別涉及快閃記憶體的動態對齊資料方法。 The invention relates to flash memory, in particular to a method for dynamically aligning data of flash memory.

快閃記憶體(如圖1A、1B所示快閃記憶體10)具有整頁寫入及區塊抹除的特性,即進行資料寫入時必須以頁(page)為最小寫入單位,進行資料抹除時必須以包括多個頁的區塊(block)為最小抹除單位。 Flash memory (flash memory 10 as shown in FIGS. 1A and 1B) has the characteristics of full page writing and block erasing, that is, when data is written, the page must be used as the minimum writing unit. When erasing data, the minimum erasing unit must be the block containing multiple pages.

為了依據快閃記憶體的上述特性來增進快閃記憶體的資料寫入效率,現有的快閃儲存裝置是設置一組緩衝記憶體(如圖1A、1B所示緩衝記憶體12),其容量與快閃記憶體10的單頁容量(如4096位元組,即4KB)相同。於收到欲寫入快閃記憶體10的資料時,快閃儲存裝置是先將所收到的資料排列儲存於緩衝記憶體12中,並於填滿緩衝記憶體12的剩餘空間後,再將緩衝記憶體12中的已排列資料全部寫入至快閃記憶體10的特定實體起始位址。藉此,快閃儲存裝置可快速地以頁為單位寫入資料至快閃記憶體10。 In order to improve the data writing efficiency of the flash memory according to the above characteristics of the flash memory, the existing flash storage device is provided with a set of buffer memory (buffer memory 12 as shown in FIGS. 1A and 1B), and its capacity It is the same as the single page capacity of the flash memory 10 (such as 4096 bytes, or 4KB). When receiving the data to be written into the flash memory 10, the flash storage device arranges and stores the received data in the buffer memory 12, and fills the remaining space of the buffer memory 12, and then All the arranged data in the buffer memory 12 is written to the specific physical start address of the flash memory 10. In this way, the flash storage device can quickly write data to the flash memory 10 in units of pages.

請參閱圖1A,其為現有循序寫入的示意圖並用以說明現有的快閃儲存裝置如何以頁為單位執行循序寫入。首先,快閃儲存裝置自外部(通常為主機)依序接收三筆欲寫入的資料。接著,快閃儲存裝置以第一筆資料的部分資 料D11及快閃記憶體10的舊資料X1填滿緩衝記憶體12,並將緩衝記憶體12的所有資料直接寫入快閃記憶體10。接著,快閃儲存裝置清空緩衝記憶體12,以第一筆資料的剩餘資料D12及第二筆資料的部分資料D21填滿緩衝記憶體12(循序寫入的多筆資料,其記憶體位址是連續的),並將緩衝記憶體12的所有資料直接寫入快閃記憶體10。接著,快閃儲存裝置清空緩衝記憶體12,以第二筆資料的剩餘資料D22及第三筆資料的部分資料D31填滿緩衝記憶體12,並將緩衝記憶體12的所有資料直接寫入快閃記憶體10。最後,快閃儲存裝置以第三筆資料的剩餘資料D32及快閃記憶體10的舊資料X2填滿緩衝記憶體12,並將緩衝記憶體12的所有資料直接寫入快閃記憶體10。藉此,快閃儲存裝置可以頁為單位來寫入多筆資料至快閃記憶體12。 Please refer to FIG. 1A, which is a schematic diagram of an existing sequential write and is used to explain how an existing flash storage device performs sequential write in units of pages. First, the flash storage device sequentially receives three pieces of data to be written from the outside (usually the host). Then, the flash storage device uses part of the first data The data D11 and the old data X1 of the flash memory 10 fill the buffer memory 12, and all the data of the buffer memory 12 are directly written into the flash memory 10. Next, the flash storage device clears the buffer memory 12, and fills the buffer memory 12 with the remaining data D12 of the first data and part of the data D21 of the second data (the data addresses of multiple pieces of data written in sequence are Continuous), and write all the data of the buffer memory 12 directly into the flash memory 10. Next, the flash storage device clears the buffer memory 12, fills the buffer memory 12 with the remaining data D22 of the second data and part of the data D31 of the third data, and directly writes all the data of the buffer memory 12 to the flash memory Flash memory 10. Finally, the flash storage device fills the buffer memory 12 with the remaining data D32 of the third data and the old data X2 of the flash memory 10, and writes all the data of the buffer memory 12 directly into the flash memory 10. Thereby, the flash storage device can write multiple pieces of data to the flash memory 12 in units of pages.

續請參閱圖1B,為現有的隨機寫入的示意圖,用以說明現有的快閃儲存裝置如何以頁為單位執行隨機寫入。 Please continue to refer to FIG. 1B, which is a schematic diagram of an existing random write to illustrate how the existing flash storage device performs random write in units of pages.

首先,快閃儲存裝置自外部依序接收三筆欲寫入的資料及各資料的寫入位址。接著,快閃儲存裝置以第一筆資料的部分資料D11及快閃記憶體10的舊資料X1填滿緩衝記憶體12,並依據第一筆資料的寫入位址將緩衝記憶體12的所有資料直接寫入快閃記憶體10。接著,快閃儲存裝置清空緩衝記憶體12,以第一筆資料的剩餘資料D12及快閃記憶體10的舊資料X2填滿緩衝記憶體12,並依據第一筆資料的寫入位址將緩衝記憶體12的所有資料直接寫入快閃記憶體10。藉此,快閃儲存裝置完成第一筆資料的寫入。 First, the flash storage device sequentially receives three data to be written and the write address of each data from the outside. Then, the flash storage device fills the buffer memory 12 with the partial data D11 of the first data and the old data X1 of the flash memory 10, and according to the write address of the first data, all of the buffer memory 12 The data is written directly into the flash memory 10. Then, the flash storage device clears the buffer memory 12, fills the buffer memory 12 with the remaining data D12 of the first data and the old data X2 of the flash memory 10, and according to the write address of the first data All data in the buffer memory 12 is directly written into the flash memory 10. With this, the flash storage device completes the writing of the first data.

接著,快閃儲存裝置以第二筆資料的部分資料D21及舊資料X3填滿緩衝記憶體12,依據第二筆資料的寫入位址將緩衝記憶體12的所有資料寫入快閃記憶體10,清空緩衝記憶體12,以第二筆資料的剩餘資料D22及舊資料X4 填滿緩衝記憶體12,並依據第二筆資料的寫入位址將緩衝記憶體12的所有資料寫入快閃記憶體10。藉此,快閃儲存裝置完成第二筆資料的寫入。 Then, the flash storage device fills the buffer memory 12 with the partial data D21 of the second data and the old data X3, and writes all the data of the buffer memory 12 to the flash memory according to the write address of the second data 10. Empty the buffer memory 12, the remaining data D22 and the old data X4 of the second data The buffer memory 12 is filled, and all data of the buffer memory 12 is written into the flash memory 10 according to the writing address of the second data. With this, the flash storage device completes writing the second data.

接著,快閃儲存裝置以第三筆資料的部分資料D31及舊資料X5填滿緩衝記憶體12,依據第三筆資料的寫入位址將緩衝記憶體12的所有資料寫入快閃記憶體10,清空緩衝記憶體12,以第三筆資料的剩餘資料D32及舊資料X6填滿緩衝記憶體12,並依據第三筆資料的寫入位址將緩衝記憶體12的所有資料寫入快閃記憶體10。藉此,快閃儲存裝置完成第三筆資料的寫入。 Then, the flash storage device fills the buffer memory 12 with the partial data D31 of the third data and the old data X5, and writes all the data of the buffer memory 12 to the flash memory according to the write address of the third data 10. Empty the buffer memory 12, fill the buffer memory 12 with the remaining data D32 of the third data and the old data X6, and write all the data of the buffer memory 12 according to the write address of the third data Flash memory 10. With this, the flash storage device completes the writing of the third data.

現有的快閃儲存裝置為了以頁為單位執行隨機寫入,必須以快閃記憶體10的舊資料來填滿緩衝記憶體12的剩餘空間,而造成寫入效能不彰。 In order to perform random writing in units of pages, the existing flash storage device must fill the remaining space of the buffer memory 12 with the old data of the flash memory 10, resulting in poor writing performance.

以圖1B為例,若快閃記憶體10單頁容量(即緩衝記憶體12容量)為4KB,則現有的快閃儲存裝置為了寫入各筆資料(佔用空間為4KB),必須進行兩次寫入操作(共寫入8KB的資料),即必須額外寫入4KB的舊資料,而浪費寫入頻寬。 Taking FIG. 1B as an example, if the single-page capacity of flash memory 10 (that is, the capacity of buffer memory 12) is 4KB, the existing flash storage device must be performed twice in order to write each data (occupying 4KB of space) Write operation (a total of 8KB of data is written), that is, an additional 4KB of old data must be written, and the write bandwidth is wasted.

本發明的主要目的,在於提供一種快閃記憶體的動態對齊資料方法,可有效減少資料隨機寫入快閃記憶體時的冗餘資料量。 The main object of the present invention is to provide a method for dynamically aligning data in a flash memory, which can effectively reduce the amount of redundant data when data is randomly written into the flash memory.

於一實施例中,一種快閃記憶體的動態對齊資料方法,運用於具有一微控制器及一快閃記憶體的一快閃儲存裝置,包括:a)控制該微控制器持續偵測該快閃儲存裝置的一使用狀態;b)接收一資料寫入指令,其中該資料寫入指令包括一邏輯起始位址;c)於該使用狀態符合一需對齊狀態時取得一累積偏移量,並依據該邏輯起始位址及該快閃記憶體的一配置單位容量更新該累積 偏移量以獲得一更新後累積偏移量;d)將該邏輯起始位址加上該更新後累積偏移量以獲得一實體起始位址;及e)由該快閃記憶體的該實體起始位址開始將對應該資料寫入指令的資料寫入該快閃記憶體。 In one embodiment, a method for dynamically aligning data of a flash memory is applied to a flash storage device having a microcontroller and a flash memory, including: a) controlling the microcontroller to continuously detect the A usage state of the flash storage device; b) receiving a data write command, where the data write command includes a logical start address; c) obtaining a cumulative offset when the usage state matches a required alignment state , And update the accumulation based on the logical start address and a configuration unit capacity of the flash memory Offset to obtain an updated cumulative offset; d) the logical start address is added to the updated cumulative offset to obtain a physical start address; and e) from the flash memory The starting address of the entity starts writing data corresponding to the data writing instruction into the flash memory.

於一實施例中,一種快閃記憶體的動態對齊資料方法,運用於具有一微控制器及一快閃記憶體的一快閃儲存裝置,包括:a)控制該微控制器接收一第一資料寫入指令,其中該第一資料寫入指令包括一第一邏輯起始位址;b)依據該第一邏輯起始位址、該快閃記憶體的一配置單位容量及一初始累積偏移量計算一第一累積偏移量;c)將該第一邏輯起始位址加上該第一累積偏移量以獲得一第一實體起始位址;d)由該快閃記憶體的該第一實體起始位址開始將對應該第一資料寫入指令的資料寫入該快閃記憶體;e)接收一第二資料寫入指令,其中該第二資料寫入指令包括一第二邏輯起始位址;f)依據該第二邏輯起始位址、該配置單位容量及該第一累積偏移量計算一第二累積偏移量;g)將該第二邏輯起始位址加上該第二累積偏移量以獲得一第二實體起始位址;及h)由該快閃記憶體的該第二實體起始位址開始將對應該第二資料寫入指令的資料寫入該快閃記憶體。 In one embodiment, a method for dynamically aligning data of a flash memory is applied to a flash storage device having a microcontroller and a flash memory, including: a) controlling the microcontroller to receive a first A data writing instruction, wherein the first data writing instruction includes a first logical start address; b) according to the first logical start address, a configuration unit capacity of the flash memory and an initial cumulative bias Calculate a first cumulative offset; c) add the first logical start address to the first cumulative offset to obtain a first physical start address; d) from the flash memory The start address of the first entity starts to write data corresponding to the first data write command to the flash memory; e) receives a second data write command, wherein the second data write command includes a A second logical start address; f) calculating a second cumulative offset based on the second logical start address, the configuration unit capacity and the first cumulative offset; g) starting the second logical start Add the second cumulative offset to obtain a second physical start address; and h) from the fast The second physical start address of the flash memory starts to write data corresponding to the second data write command into the flash memory.

本發明可有效提升快閃記憶體的隨機讀寫效率。 The invention can effectively improve the random read and write efficiency of the flash memory.

10‧‧‧快閃記憶體 10‧‧‧Flash memory

12‧‧‧緩衝記憶體 12‧‧‧buffer memory

20‧‧‧快閃儲存裝置 20‧‧‧Flash storage device

200‧‧‧快閃記憶體 200‧‧‧Flash memory

202‧‧‧緩衝記憶體 202‧‧‧buffer memory

204‧‧‧微控制器 204‧‧‧Microcontroller

22‧‧‧主機 22‧‧‧Host

X1-X6‧‧‧舊資料 X1-X6‧‧‧Old data

D11、D12、D21、D22、D31、D32、A1、A2、B1、B2、C1、C2‧‧‧資料 D11, D12, D21, D22, D31, D32, A1, A2, B1, B2, C1, C2

O1、O2、O3‧‧‧單次偏移量 O1, O2, O3‧‧‧single offset

S10-S16‧‧‧寫入步驟 S10-S16‧‧‧ Writing procedure

S200-S220‧‧‧讀寫步驟 S200-S220‧‧‧Reading and writing steps

圖1A為現有的循序寫入的示意圖。 FIG. 1A is a schematic diagram of conventional sequential writing.

圖1B為現有的隨機寫入的示意圖。 FIG. 1B is a schematic diagram of existing random writing.

圖2為本發明第一實施例的快閃儲存裝置的架構圖。 FIG. 2 is a structural diagram of a flash storage device according to a first embodiment of the invention.

圖3為本發明第一實施例的動態對齊資料方法的流程圖。 FIG. 3 is a flowchart of a method for dynamically aligning data in a first embodiment of the present invention.

圖4為本發明第二實施例的動態對齊資料方法的流程圖。 4 is a flowchart of a method for dynamically aligning data in a second embodiment of the present invention.

圖5為本發明的連續對齊示意圖。 5 is a schematic diagram of continuous alignment of the present invention.

圖6為圖5的隨機寫入的示意圖。 FIG. 6 is a schematic diagram of the random write of FIG. 5.

圖7為本發明的條件對齊示意圖。 7 is a schematic diagram of conditional alignment of the present invention.

圖8為圖7的隨機寫入的示意圖。 FIG. 8 is a schematic diagram of the random write of FIG. 7.

茲就本發明的一較佳實施例,配合圖式,詳細說明如後。 The following is a detailed description of a preferred embodiment of the present invention with reference to the drawings.

首請參閱圖2,為本發明第一實施例的快閃儲存裝置的架構圖。本發明的快閃儲存裝置20主要包括快閃記憶體200、緩衝記憶體202及微控制器204。 Please refer first to FIG. 2, which is a structural diagram of a flash storage device according to a first embodiment of the present invention. The flash storage device 20 of the present invention mainly includes a flash memory 200, a buffer memory 202, and a microcontroller 204.

快閃記憶體200(如NAND快閃記憶體)用以儲存資料,包括多個區塊(Block,即資料抹除的最小單位),各區塊包括多個頁(page,即資料存取的最小單位)。 Flash memory 200 (such as NAND flash memory) is used to store data, including multiple blocks (Block, the smallest unit of data erasing), each block includes multiple pages (ie, data access The smallest unit).

緩衝記憶體202電性連接快閃記憶體200,用以暫存資料。並且,緩衝記憶體202的容量為快閃記憶體200的頁容量(如4KB、8KB或16KB)的倍數。 The buffer memory 202 is electrically connected to the flash memory 200 for temporarily storing data. Moreover, the capacity of the buffer memory 202 is a multiple of the page capacity of the flash memory 200 (such as 4KB, 8KB, or 16KB).

微控制器204(如MCU)電性連接緩衝記憶體202,並可電性連接(如經由USB介面或SATA介面)外部的主機22。微控制器204可依據來自主機22的資料寫入指令或資料讀取指令來將資料經由緩衝記憶體202寫入至快閃記憶體200,或將資料經由緩衝記憶體202自快閃記憶體200讀出。 The microcontroller 204 (such as an MCU) is electrically connected to the buffer memory 202 and can be electrically connected (such as via a USB interface or a SATA interface) to the external host 22. The microcontroller 204 can write data to the flash memory 200 via the buffer memory 202 or write data from the flash memory 200 via the buffer memory 202 according to the data writing instruction or the data reading instruction from the host 22 read out.

續請參閱圖3,為本發明第一實施例的動態對齊資料方法的流程圖。本發明各實施例的動態對齊資料方法主要是由圖2所示的快閃儲存裝置20來加以實現。具體而言,快閃儲存裝置20還包括韌體(firmware),韌體可被儲存 於微控制器204的內建記憶體中。並且,當微控制器204執行前述韌體後,可實現控制快閃儲存裝置20執行本發明各實施例的動態對齊資料方法的各步驟。本實施的動態對齊資料方法的包括以下步驟。 Please refer to FIG. 3 for a flow chart of the method for dynamically aligning data in the first embodiment of the present invention. The dynamic data alignment method in each embodiment of the present invention is mainly implemented by the flash storage device 20 shown in FIG. 2. Specifically, the flash storage device 20 further includes firmware, which can be stored In the built-in memory of the microcontroller 204. Moreover, after the microcontroller 204 executes the aforementioned firmware, the flash storage device 20 can be controlled to execute the steps of the dynamic data alignment method of each embodiment of the present invention. The dynamic alignment data method of this implementation includes the following steps.

步驟S10:微控制器204判斷是否收到資料寫入需求。具體而言,微控制器204判斷是否自主機22收到任何資料寫入指令。 Step S10: The microcontroller 204 determines whether a data writing request is received. Specifically, the microcontroller 204 determines whether any data writing instruction has been received from the host 22.

於一實施例中,資料寫入指令是包括基於邏輯區塊定址(Logic Block Address)機制的一組邏輯起始位址及欲寫入資料的資料長度。更具體地,邏輯區塊定址機制是一種描述電腦(如主機22)儲存裝置上資料所在位址的通用機制,基於此機制的邏輯起始位址可被大部分電腦識別。 In one embodiment, the data write command includes a set of logical start addresses based on the logic block address (Logic Block Address) mechanism and the data length of the data to be written. More specifically, the logical block addressing mechanism is a general mechanism that describes the address of the data on the storage device of the computer (such as the host 22), and the logical start address based on this mechanism can be recognized by most computers.

若微控制器204收到資料寫入指令,則執行步驟S12。否則,結束動態對齊資料方法。 If the microcontroller 204 receives the data writing instruction, step S12 is executed. Otherwise, the dynamic alignment data method ends.

步驟S12:微控制器204取得累積偏移量及快閃記憶體200的配置單位容量,並依據所取得的配置單位容量更新所取得的累積偏移量以獲得更新後累積偏移量。 Step S12: The microcontroller 204 obtains the cumulative offset and the configuration unit capacity of the flash memory 200, and updates the acquired cumulative offset according to the acquired configuration unit capacity to obtain the updated cumulative offset.

具體而言,微控制器204依據所取得的累積偏移量及配置單位容量計算更新後累積偏移量。配置單位容量(如4KB、8KB或16KB)是快閃記憶體200的單次最小存取容量,即快閃記憶體200的單頁的容量,其是於快閃記憶體200出廠時由製造商基於硬體規範所設定。 Specifically, the microcontroller 204 calculates the updated cumulative offset based on the acquired cumulative offset and the configuration unit capacity. The configuration unit capacity (such as 4KB, 8KB, or 16KB) is the single-time minimum access capacity of the flash memory 200, that is, the capacity of a single page of the flash memory 200, which is manufactured by the manufacturer when the flash memory 200 is shipped from the factory Set based on hardware specifications.

累積偏移量是用來指示通用的邏輯起始位址與基於快閃記憶體200的定址機制的實體起始位址之間的位址偏移量。 The cumulative offset is used to indicate the address offset between the general logical start address and the physical start address based on the addressing mechanism of the flash memory 200.

此外,累積偏移量的初始值為0(即快閃記憶體200未曾被寫入資料,或雖曾寫入資料但未執行位址偏移操作),並隨著位址偏移操作的執行次數逐漸增加。 In addition, the initial value of the accumulated offset is 0 (that is, the flash memory 200 has not been written with data, or the address offset operation has not been performed although data has been written), and is executed as the address offset operation is performed The frequency gradually increased.

步驟S14:微控制器204依據資料寫入指令的邏輯起始位址及更新後累積偏移量計算對應此邏輯起始位址的一組實體起始位址。 Step S14: The microcontroller 204 calculates a group of physical start addresses corresponding to the logical start address according to the logical start address of the data writing instruction and the updated cumulative offset.

於一實施例中,微控制器204是將邏輯起始位址加上更新後累積偏移量作為對應的實體起始位址,其中此對應之方式可由微控制器204自行判定,且此方式可為本領域中具有通常知識者所熟知,故在此不進行贅述。 In one embodiment, the microcontroller 204 uses the logical start address plus the updated cumulative offset as the corresponding physical start address, where the corresponding way can be determined by the microcontroller 204, and this way It can be well known to those with ordinary knowledge in the art, so it will not be repeated here.

步驟S16:微控制器204由快閃記憶體200的實體起始位址開始將對應資料寫入指令的資料寫入快閃記憶體200。 Step S16: The microcontroller 204 writes the data corresponding to the data write command into the flash memory 200 starting from the physical start address of the flash memory 200.

於一實施例中,微控制器204先將對應資料寫入指令的資料排列寫入至緩衝記憶體202,再由快閃記憶體200的實體起始位址開始將排列寫入後的資料自緩衝記憶體202直接寫入至快閃記憶體200中。 In one embodiment, the microcontroller 204 first writes the data arrangement corresponding to the data write instruction to the buffer memory 202, and then starts to write the arranged data from the physical start address of the flash memory 200. The buffer memory 202 is directly written into the flash memory 200.

值得一提的是,在先前技術中,當邏輯起始位址未對齊快閃記憶體200的任一頁的實體起始位址時,若直接將邏輯起始位址作為實體起始位址進行資料寫入,將使資料被分別寫入不同的二頁,而降低寫入效率(一筆資料需進行兩次寫入操作)。因此,本發明是於進行寫入操作時先執行位址偏移操作,計算邏輯起始位址與最接近頁的實體起始位址之間的位址偏移量(即步驟S12),並進行偏移量補償,來獲得特定頁的實體起始位址(即步驟S14)。藉此,當微控制器204自此實體起始位址開始連續寫入資料至快取記憶體200時(即步驟S16),所寫入的資料會位於同一頁,而可提升寫入效率(一筆資料僅需進行一次寫入操作)。 It is worth mentioning that in the prior art, when the logical start address is not aligned with the physical start address of any page of the flash memory 200, if the logical start address is directly used as the physical start address Writing data will cause the data to be written into two different pages, which reduces the writing efficiency (two write operations for one piece of data). Therefore, in the present invention, the address offset operation is first performed during the write operation to calculate the address offset between the logical start address and the physical start address closest to the page (ie step S12), and Perform offset compensation to obtain the physical start address of a specific page (ie, step S14). In this way, when the microcontroller 204 continuously writes data from the physical start address to the cache memory 200 (ie, step S16), the written data will be located on the same page, which can improve the writing efficiency ( (One write only needs to be written once).

接著,微控制器204再次執行步驟S10以判斷是否收到其他寫入需求。 Then, the microcontroller 204 executes step S10 again to determine whether another write request is received.

續請參閱圖5,為本發明的連續對齊示意圖,用以示例性說明本發明如何執行資料對齊及隨機寫入操作。圖5(A)所示為邏輯區塊定址機制示意 圖,圖5(B)所示為快閃記憶體200的定址機制示意圖。於本例子中,快閃記憶體200的單頁大小為8KB,累積偏移量的初始值(即初始累積偏移量)為0。 Please refer to FIG. 5, which is a schematic diagram of continuous alignment of the present invention to exemplify how the present invention performs data alignment and random write operations. Figure 5 (A) shows a schematic diagram of the logical block addressing mechanism FIG. 5 (B) is a schematic diagram of the addressing mechanism of the flash memory 200. In this example, the single page size of the flash memory 200 is 8 KB, and the initial value of the cumulative offset (that is, the initial cumulative offset) is 0.

微控制器204初次自主機22接收資料寫入指令,即第一資料寫入指令write(4,8),表示第一邏輯起始位址為4(意指4K,即4096),欲寫入資料的第一資料長度為8(單位為KB,即Kilo Bytes)。接著,微控制器204判斷第一邏輯起始位址並未對齊快閃記憶體200的任一可寫入頁的實體起始位址(如0、8、16...)而須執行位址偏移操作,並算出單次偏移量O1(即第一偏移量)為4(意指4K,即4096),即第一邏輯起始位址偏移第一偏移量後可對齊快閃記憶體200的特定可寫入頁的實體起始位址(即第一實體起始位址)。 The microcontroller 204 receives the data write command from the host 22 for the first time, that is, the first data write command write (4,8), which means that the first logical start address is 4 (meaning 4K, which is 4096), and is to be written The first data length of the data is 8 (the unit is KB, which is Kilo Bytes). Next, the microcontroller 204 determines that the first logical start address is not aligned with the physical start address (such as 0, 8, 16 ...) of any page that can be written to the flash memory 200 and the execution bit is required Address offset operation, and calculate the single offset O1 (ie the first offset) is 4 (meaning 4K, that is 4096), that is, the first logical start address can be aligned after offset by the first offset The physical start address of the specific writable page of the flash memory 200 (ie, the first physical start address).

接著,微控制器204更新初始累積偏移量以獲得更新後累積偏移量(為4,即第一累積偏移量),將第一邏輯起始位址(4)加上第一累積偏移量(4)來獲得對應的第一實體起始位址(8),並自快閃記憶體200的第一實體起始位址(8)開始連續寫入第一資料寫入指令的資料。藉此,原本未對齊至快閃記憶體200的任一可寫入頁的資料,即可被寫入至同一頁(即第一實體起始位址(8)所對應的頁)中。 Next, the microcontroller 204 updates the initial cumulative offset to obtain the updated cumulative offset (which is 4, which is the first cumulative offset), and adds the first cumulative offset to the first logical start address (4) Shift the amount (4) to obtain the corresponding first physical start address (8), and continuously write the data of the first data write command from the first physical start address (8) of the flash memory 200 . In this way, data that is not aligned to any writable page of the flash memory 200 can be written to the same page (that is, the page corresponding to the first physical start address (8)).

並且,微控制器204還可執行記錄指令record(4,4),來將第一邏輯起始位址(4)與所對應的第一累積偏移量(4)對應記錄於查找表,以供日後讀取此筆資料使用。 In addition, the microcontroller 204 can also execute a record instruction record (4, 4) to record the first logical start address (4) and the corresponding first cumulative offset (4) in the lookup table, to For reading this data in the future.

當微控制器204再次自主機22接收資料寫入指令(即第二資料寫入指令write(24,8))時,可判斷第二邏輯起始位址(24)加上最新的第一累積偏移量(4)並未對齊快閃記憶體200的任一可寫入頁的實體起始位址(如32),而須執行位址偏移操作,並算出單次偏移量O2(即第二偏移量)為4。 When the microcontroller 204 receives the data write command (ie, the second data write command write (24, 8)) from the host 22 again, it can determine the second logical start address (24) plus the latest first accumulation The offset (4) is not aligned with the physical start address (such as 32) of any writeable page of the flash memory 200, but the address offset operation must be performed and the single offset O2 ( That is, the second offset) is 4.

接著,微控制器204更新第一累積偏移量以獲得更新後累積偏移量(為8,即第二累積偏移量,為前次的第一累積偏移量(4)加上第二偏移量 (4)),將第二邏輯起始位址(24)加上第二累積偏移量(8)來獲得對應的第二實體起始位址(32),並自快閃記憶體200的第二實體起始位址(32)開始連續寫入第二資料寫入指令的資料。並且,微控制器204還執行記錄指令record(24,8)來將第二邏輯起始位址(24)與所對應的第二累積偏移量(8)對應記錄於查找表。 Next, the microcontroller 204 updates the first cumulative offset to obtain the updated cumulative offset (8, that is, the second cumulative offset, adding the second to the previous first cumulative offset (4) Offset (4)), add the second logical start address (24) to the second cumulative offset (8) to obtain the corresponding second physical start address (32), and from the flash memory 200 The second physical start address (32) starts to continuously write the data of the second data writing instruction. Furthermore, the microcontroller 204 also executes a record instruction record (24, 8) to record the second logical start address (24) and the corresponding second cumulative offset (8) in the lookup table.

當微控制器204再次自主機22接收資料寫入指令(即第三資料寫入指令write(36,8))時,可判斷第三邏輯起始位址(36)加上最新的第二累積偏移量(8)並未對齊快閃記憶體200的任一可寫入頁的實體起始位址(如48),而須執行位址偏移操作,並算出單次偏移量O3(即第三偏移量)為4。 When the microcontroller 204 receives the data write command (ie, the third data write command write (36, 8)) from the host 22 again, it can determine the third logical start address (36) plus the latest second accumulation The offset (8) is not aligned with the physical start address (such as 48) of any writable page of the flash memory 200, but the address offset operation must be performed and the single offset O3 ( That is, the third offset) is 4.

接著,微控制器204更新累積偏移量以獲得更新後累積偏移量(為12,即第三累積偏移量),將第三邏輯起始位址(36)加上第三累積偏移量(12)來獲得對應的第三實體起始位址(48),並自快閃記憶體200的第三實體起始位址(48)開始連續寫入第三資料寫入指令的資料。藉此,原本未對齊快閃記憶體200的任一頁的資料,會被寫入至同一頁(即實體起始位址(48)所對應的頁)中。並且,微控制器204還執行記錄指令record(36,12)來將第三邏輯起始位址(36)與所對應的第三累積偏移量(12)對應記錄於查找表。 Next, the microcontroller 204 updates the cumulative offset to obtain the updated cumulative offset (12, which is the third cumulative offset), and adds the third cumulative start offset (36) to the third cumulative offset (12) to obtain the corresponding third physical start address (48), and continuously write data of the third data write command from the third physical start address (48) of the flash memory 200. In this way, the data of any page of the originally unaligned flash memory 200 will be written to the same page (that is, the page corresponding to the physical start address (48)). Moreover, the microcontroller 204 also executes a record instruction record (36, 12) to record the third logical start address (36) and the corresponding third cumulative offset (12) in the lookup table.

續請參閱圖6,為圖5的隨機寫入的示意圖,用以更詳盡說明本發明如何執行隨機寫入操作。於本例子中,緩衝記憶體202的容量是與快閃記憶體200的單頁容量相同(如皆為8KB)。 Please continue to refer to FIG. 6, which is a schematic diagram of the random write of FIG. 5 to explain in more detail how the present invention performs a random write operation. In this example, the capacity of the buffer memory 202 is the same as the single page capacity of the flash memory 200 (for example, both are 8KB).

微控制器204是先將第一資料寫入指令的資料(包括子資料A1、A2)排列寫入至緩衝記憶體202,再自快閃記憶體200的第一實體起始位址開始將緩衝記憶體202的所有資料寫入快閃記憶體200的特定頁。 The microcontroller 204 first writes the data (including sub-data A1, A2) of the first data write command into the buffer memory 202, and then starts buffering from the first physical start address of the flash memory 200 All data of the memory 202 is written to a specific page of the flash memory 200.

接著,微控制器204清空緩衝記憶體202,並將第二資料寫入指令的資料(包括子資料B1、B2)排列寫入至緩衝記憶體202,再自快閃記憶體200的 第二實體起始位址開始將緩衝記憶體202的所有資料寫入快閃記憶體200的特定頁。 Next, the microcontroller 204 clears the buffer memory 202, and writes the data (including the sub-data B1, B2) of the second data write command to the buffer memory 202, and then from the flash memory 200 The second physical start address starts to write all the data of the buffer memory 202 to a specific page of the flash memory 200.

接著,微控制器204清空緩衝記憶體202,並將第三資料寫入指令的資料(包括子資料C1、C2)排列寫入至緩衝記憶體202,再自快閃記憶體200的第三實體起始位址開始將緩衝記憶體202的所有資料寫入快閃記憶體200的特定頁。 Next, the microcontroller 204 clears the buffer memory 202, and writes the data (including sub-data C1, C2) of the third data write command to the buffer memory 202, and then from the third entity of the flash memory 200 The starting address starts to write all the data of the buffer memory 202 to a specific page of the flash memory 200.

值得一提的是,經過前述操作後,各資料寫入指令的邏輯起始位址已被轉換為對齊快閃記憶體200中的特定頁的實體起始位址,即各資料寫入指令的資料會被寫入至同一頁(僅需進行一次寫入操作),而不會被寫入至不同頁(即不須進行多次寫入操作)。 It is worth mentioning that, after the foregoing operations, the logical start address of each data write command has been converted to the physical start address of the specific page in the aligned flash memory 200, that is, the The data will be written to the same page (only one write operation is required), but not to different pages (that is, multiple write operations are not required).

本發明經由對邏輯起始位址執行位址偏移操作,可有效將資料對齊寫入至快閃記憶體的同一頁,而可有效減少寫入次數,進而延長快閃記憶體壽命並有效快閃記憶體的隨機讀寫效率。 The present invention can effectively write data to the same page of the flash memory by performing an address offset operation on the logical start address, and can effectively reduce the number of writes, thereby extending the life of the flash memory and effectively fast Random read and write efficiency of flash memory.

前述實施例的動態對齊資料方法雖可有效減少快閃記憶體的寫入次數,然而,每次執行位址偏移操作都會造成快閃記憶體容量的浪費(如圖5所示的單次偏移量O1、O2、O3所對應的記憶體空間不會儲存資料),若對所有資料寫入指令執行位址偏移操作,將使快閃記憶體的可用容量快速降低。 Although the dynamic data alignment method in the foregoing embodiment can effectively reduce the number of flash memory writes, however, each time the address offset operation is performed, the capacity of the flash memory is wasted (a single offset shown in FIG. 5) The memory space corresponding to the shifts O1, O2, O3 will not store data.) If the address offset operation is performed on all data write commands, the available capacity of the flash memory will be quickly reduced.

為解決上述問題,本發明更提出另一種態樣的動態對齊資料方法,可於減少寫入次數及減少快閃記憶體容量浪費中取得平衡。續請參閱圖4,為本發明第二實施例的動態對齊資料方法的流程圖。本實施例的動態對齊資料方法包括以下步驟。 To solve the above problem, the present invention further proposes another dynamic data alignment method, which can achieve a balance between reducing the number of writes and reducing the waste of flash memory capacity. Please refer to FIG. 4 for a flow chart of a method for dynamically aligning data according to a second embodiment of the present invention. The method for dynamically aligning data in this embodiment includes the following steps.

步驟S200:微控制器204持續偵測快閃儲存裝置20的使用狀態。前述使用狀態可為持續未更新累積偏移量期間累積的寫入次數或持續時間、快 閃記憶體200的剩餘可用容量或特定區塊(Block)的總寫入次數或總抹除次數等,但不以此限定。 Step S200: The microcontroller 204 continuously detects the use state of the flash storage device 20. The aforementioned usage state may be the number of writes or duration accumulated during the period of unupdated cumulative offset, and the fast The remaining available capacity of the flash memory 200 or the total number of writing or erasing times of a specific block (block) are not limited thereto.

步驟S202:微控制器204判斷是否收到資料讀寫需求。具體而言,微控制器204是判斷是否自主機22收到任何資料寫入指令或任何資料讀取指令。 Step S202: The microcontroller 204 determines whether a data reading and writing request is received. Specifically, the microcontroller 204 determines whether any data writing instruction or any data reading instruction is received from the host 22.

於一實施例中,資料讀取指令是包括基於邏輯區塊定址機制的一組邏輯起始位址及欲讀取資料的資料長度。 In one embodiment, the data read command includes a set of logical start addresses based on the logical block addressing mechanism and the data length of the data to be read.

若微控制器204收到資料寫入指令,則執行步驟S204。若微控制器204收到資料讀取指令,則執行步驟S216。若微控制器204未收到任何資料讀寫指令,則結束動態對齊資料方法。 If the microcontroller 204 receives the data writing instruction, step S204 is executed. If the microcontroller 204 receives the data reading instruction, step S216 is executed. If the microcontroller 204 does not receive any data read and write commands, the dynamic data alignment method ends.

步驟S204:微控制器204判斷所偵測的使用狀態是否符合預設的需對齊狀態。 Step S204: The microcontroller 204 determines whether the detected usage state meets the preset required alignment state.

舉例來說,微控制器204可判斷持續未更新累積偏移量期間累積的寫入次數(如8次)是否不小於預設寫入次數(如10次)、持續未更新累積偏移量期間的持續時間(如3分鐘)是否不小於預設持續時間(如5分鐘)、快閃記憶體200的剩餘可用容量(如30GB)是否大於預設容量(如1GB)或特定區塊(Block)的總寫入次數或總抹除次數(如5萬次)是否大於預設寫入次數或預設抹除次數(如8萬次)。 For example, the microcontroller 204 can determine whether the cumulative number of writes (such as 8) during the period of continuous unupdated cumulative offset is not less than the preset number of writes (such as 10), and the period of continuous unupdated cumulative offset Whether the duration of the flash memory (such as 3 minutes) is not less than the preset duration (such as 5 minutes), and whether the remaining available capacity of the flash memory 200 (such as 30GB) is greater than the preset capacity (such as 1GB) or a specific block (Block) Whether the total write times or total erase times (such as 50,000 times) is greater than the preset write times or preset erase times (such as 80,000 times).

若微控制器204判斷當前的使用狀態符合需對齊狀態,則執行步驟S206以先執行位址偏移操作後再執行寫入操作。若判斷當前的使用狀態不符合需對齊狀態,微控制器204執行步驟S210以直接執行寫入操作。 If the micro-controller 204 determines that the current usage state meets the alignment-needed state, step S206 is executed to perform the address offset operation and then the write operation. If it is determined that the current use state does not match the alignment-required state, the microcontroller 204 executes step S210 to directly perform the write operation.

步驟S206:微控制器204依據資料寫入指令的邏輯起始位址、累積偏移量及快閃記憶體200的配置單位容量計算單次偏移量(如圖5所示第一偏移量O1、第二偏移量O2或第三偏移量O3)。 Step S206: The microcontroller 204 calculates a single offset (the first offset as shown in FIG. 5) according to the logical start address of the data writing instruction, the cumulative offset, and the configuration unit capacity of the flash memory 200 O1, the second offset O2 or the third offset O3).

於一實施例中,邏輯起始位址、累積偏移量及所算出的單次偏移量的和為快閃記憶體200的配置單位容量的倍數。舉例來說,若邏輯起始位址為4、累積偏移量為0,配置單位容量為8,則單次偏移量可為4(最佳)、12、20...等。 In one embodiment, the sum of the logical start address, the cumulative offset, and the calculated single offset is a multiple of the configuration unit capacity of the flash memory 200. For example, if the logical start address is 4, the cumulative offset is 0, and the configuration unit capacity is 8, then the single offset can be 4 (optimum), 12, 20, etc.

於另一例子中,微控制器204是計算邏輯起始位址(如24)與累積偏移量(如4)的和(28),再計算此和除以配置單位容量(如8)後的餘數(4),並計算配置單位容量(8)與此餘數(4)的差值(4),再以差值(4)做為單次偏移量(4)。 In another example, the microcontroller 204 calculates the sum (28) of the logical start address (such as 24) and the cumulative offset (such as 4), and then calculates the sum divided by the configured unit capacity (such as 8) The remainder (4), and calculate the difference (4) between the configuration unit capacity (8) and this remainder (4), and then use the difference (4) as the single offset (4).

步驟S208:微控制器204更新累積偏移量。具體而言,微控制器204將所算出的單次偏移量加上所取得的累積偏移量以獲得更新後累積偏移量。 Step S208: The microcontroller 204 updates the cumulative offset. Specifically, the microcontroller 204 adds the calculated single offset to the acquired cumulative offset to obtain the updated cumulative offset.

步驟S210:微控制器204將資料寫入指令的邏輯起始位址加上更新後累積偏移量以獲得實體起始位址。 Step S210: The microcontroller 204 adds the updated logical offset to the logical start address of the data write command to obtain the physical start address.

值得一提的是,若使用狀態符合需對齊狀態,則微控制器204是將邏輯起始位址加上於步驟S208中獲得的更新後累積偏移量以作為實體起始位址。若使用狀態不符合需對齊狀態(即於本次寫入操作累積偏移量不會更新),則微控制器204是將邏輯起始位址加上所取得的累積偏移量作為實體起始位址。 It is worth mentioning that, if the use state matches the alignment-needed state, the microcontroller 204 adds the updated cumulative offset obtained in step S208 as the physical start address. If the usage state does not match the alignment required state (that is, the cumulative offset will not be updated during this write operation), the microcontroller 204 uses the logical start address plus the acquired cumulative offset as the physical start Address.

步驟S212:微控制器204先將對應資料寫入指令的資料排列寫入至緩衝記憶體202,再由快閃記憶體200的實體起始位址開始將排列寫入後的資料自緩衝記憶體202直接寫入至快閃記憶體200中。 Step S212: The microcontroller 204 first writes the data arrangement corresponding to the data write command to the buffer memory 202, and then starts to write the arranged data from the buffer memory from the physical start address of the flash memory 200 202 is directly written into the flash memory 200.

步驟S214:微控制器204將資料寫入指令的邏輯起始位址及最新的累積偏移量(若有更新,則為更新後累積偏移量;若未更新,則為所取得的累積偏移量)對應記錄於查找表。接著微控制器204再次執行步驟S202。 Step S214: the microcontroller 204 writes the logical start address of the data write command and the latest cumulative offset (if updated, the updated cumulative offset; if not updated, the obtained cumulative offset The shift amount) corresponds to the record in the lookup table. Then the microcontroller 204 executes step S202 again.

若於步驟S202中微控制器204是收到資料讀取指令,則執行步驟S216:微控制器204查詢查找表以取得對應此資料讀取指令的邏輯起始位址的累 積偏移量(即於步驟S214中所記錄的更新後累積偏移量或所取得的累積偏移量)。 If the microcontroller 204 receives the data read command in step S202, step S216 is executed: the microcontroller 204 queries the lookup table to obtain the logical start address corresponding to the data read command. Product offset (ie, the updated cumulative offset recorded in step S214 or the acquired cumulative offset).

以圖5為例,查找表記錄有record(4,4)、record(24,8)及record(36,12)三筆資料。若資料讀取指令的邏輯起始位址為4,則對應的累積偏移量為4,若邏輯起始位址為24,則對應的累積偏移量為8,若邏輯起始位址為36,則對應的累積偏移量為12。 Taking Figure 5 as an example, the lookup table records three records of record (4, 4), record (24, 8), and record (36, 12). If the logical start address of the data read instruction is 4, the corresponding cumulative offset is 4, if the logical start address is 24, the corresponding cumulative offset is 8, if the logical start address is 36, the corresponding cumulative offset is 12.

步驟S218:微控制器204將資料讀取指令的邏輯起始位址加上所查到的累積偏移量來獲得對應的實體起始位址。舉例來說,若邏輯起始位址為24,累積偏移量為8,則對應的實體起始位址為32。 Step S218: The microcontroller 204 adds the logical start address of the data read instruction to the accumulated offset found to obtain the corresponding physical start address. For example, if the logical start address is 24 and the cumulative offset is 8, the corresponding physical start address is 32.

步驟S220:微控制器204依據資料讀取指令的資料長度自快閃記憶體200的實體起始位址開始連續讀取對應資料讀取指令的資料。 Step S220: The microcontroller 204 continuously reads the data corresponding to the data reading instruction from the physical start address of the flash memory 200 according to the data length of the data reading instruction.

於一實施例中,微控制器204是先自快閃記憶體200的實體起始位址開始連續讀取對應資料讀取指令的資料,並將所讀取的資料排列儲存於緩衝記憶體202中,再將儲存於緩衝記憶體202的資料傳送至資料讀取指令的來源(如主機22)。 In one embodiment, the microcontroller 204 first reads the data corresponding to the data read command continuously from the physical start address of the flash memory 200, and stores the read data in the buffer memory 202 In the process, the data stored in the buffer memory 202 is sent to the source of the data read command (such as the host 22).

值得一提的是,本發明由於已使快閃記憶體200所儲存的所有資料對齊各頁(即,使各資料寫入指令對應的資料會儲存於同頁),當欲讀取該筆資料時,微控制器204僅需對快閃記憶體200執行一次讀取操作(讀取單頁),而可有效提升讀取效率。。 It is worth mentioning that since the present invention has aligned all the data stored in the flash memory 200 with each page (ie, the data corresponding to each data write command will be stored on the same page), when the data is to be read At this time, the microcontroller 204 only needs to perform a read operation (read a single page) on the flash memory 200 once, which can effectively improve the read efficiency. .

續請參閱圖7,為本發明的條件對齊示意圖,用以示例性說明本發明如何有條件執行資料對齊及隨機寫入操作。圖7(A)所示為邏輯區塊定址機制示意圖,圖7(B)所示為快閃記憶體200的定址機制示意圖。於本例子中,快閃記憶體200的單頁大小為8KB,累積偏移量的初始值(即初始累積偏移量)為 0。並且,微控制器204是間隔執行位址偏移操作,即於奇數次(如第1、3、5、7...次)收到資料寫入指令時才執行資料對齊。 Please refer to FIG. 7, which is a schematic diagram of conditional alignment of the present invention, to exemplify how the present invention performs conditional data alignment and random write operations conditionally. FIG. 7 (A) shows a schematic diagram of the logical block addressing mechanism, and FIG. 7 (B) shows a schematic diagram of the flash memory 200 addressing mechanism. In this example, the single page size of the flash memory 200 is 8KB, and the initial value of the cumulative offset (that is, the initial cumulative offset) is 0. In addition, the microcontroller 204 performs the address offset operation at intervals, that is, the data alignment is performed only when the data write command is received an odd number of times (eg, 1, 3, 5, 7, ...).

微控制器204第一次自主機22接收資料寫入指令,即第一資料寫入指令write(4,8)。接著,微控制器204依據設定判斷需執行資料對齊(本次為奇數次),並進一步判斷第一邏輯起始位址未對齊快閃記憶體200的任一可寫入頁的實體起始位址而須執行位址偏移操作,並算出單次偏移量O1(即第一偏移量)為4。 The microcontroller 204 receives the data write command from the host 22 for the first time, namely the first data write command write (4, 8). Then, the microcontroller 204 judges that data alignment needs to be performed according to the setting (this is an odd number of times), and further determines that the first logical start address is not aligned with the physical start bit of any writable page of the flash memory 200 The address offset operation must be performed and the single offset O1 (ie the first offset) is calculated to be 4.

接著,微控制器204更新累積偏移量以獲得更新後累積偏移量(為4,即第一累積偏移量),將第一邏輯起始位址(4)加上第一累積偏移量(4)來獲得對應的第一實體起始位址(8),並自快閃記憶體200的第一實體起始位址(8)開始連續寫入第一資料寫入指令的資料。並且,微控制器204還執行記錄指令record(4,4),來將第一邏輯起始位址(4)與所對應的第一累積偏移量(4)對應記錄於查找表。 Then, the microcontroller 204 updates the cumulative offset to obtain the updated cumulative offset (4, that is, the first cumulative offset), and adds the first cumulative offset to the first logical start address (4) Amount (4) to obtain the corresponding first physical start address (8), and continuously write data of the first data write command from the first physical start address (8) of the flash memory 200. Moreover, the microcontroller 204 also executes a record instruction record (4, 4) to record the first logical start address (4) and the corresponding first cumulative offset (4) in the lookup table.

當微控制器204第二次自主機22接收資料寫入指令(即第二資料寫入指令write(24,8))時,可依據設定判斷不需執行資料對齊(本次為偶數次),而直接取得最新的第一累積偏移量(4)並直接作為第二累積偏移量,將第二邏輯起始位址(24)加上第二累積偏移量(4)來獲得對應的第二實體起始位址(28),並自快閃記憶體200的此實體起始位址(28)開始連續寫入第二資料寫入指令的資料。並且,微控制器204還執行記錄指令record(24,4)來將第二邏輯起始位址(24)與所對應的第二累積偏移量(4)對應記錄於查找表。 When the microcontroller 204 receives the data write command (ie, the second data write command write (24, 8)) from the host 22 for the second time, it can judge according to the setting that data alignment is not required (this time is an even number of times), And the latest first cumulative offset (4) is directly obtained and directly used as the second cumulative offset, and the second logical start address (24) is added to the second cumulative offset (4) to obtain the corresponding The second physical start address (28), and the data of the second data write command is continuously written from the physical start address (28) of the flash memory 200. Moreover, the microcontroller 204 also executes a record instruction record (24, 4) to record the second logical start address (24) and the corresponding second cumulative offset (4) in the lookup table.

由圖7(B)可看出,第二資料寫入指令的資料並未對齊快閃記憶體200的單頁,這使得此筆資料的讀寫效率較差。並且,由於未執行位址偏移操作,本次寫入操作不會浪費額外的容量。 As can be seen from FIG. 7 (B), the data of the second data writing instruction is not aligned with the single page of the flash memory 200, which makes the reading and writing efficiency of this data poor. Moreover, since the address offset operation is not performed, no extra capacity is wasted in this write operation.

當微控制器204第三次自主機22接收資料寫入指令(即第三資料寫入指令write(36,8))時,可依據設定判斷需執行資料對齊(本次為奇數次),並進一步判斷第三邏輯起始位址(36)加上最新的第二累積偏移量(4)已對齊快閃記憶體200的特定頁的實體起始位址(如40),而不須執行位址偏移操作,並算出單次偏移量O3(即第三偏移量)為0,而可直接將第二累積偏移量(4)作為第三累積偏移量。 When the microcontroller 204 receives the data write command from the host 22 for the third time (ie, the third data write command write (36, 8)), it can determine that the data alignment needs to be performed according to the setting (this is an odd number of times), and Further determine the third logical start address (36) plus the latest second cumulative offset (4) to align the physical start address (eg 40) of the specific page of the flash memory 200 without executing The address offset operation calculates the single offset O3 (ie, the third offset) as 0, and the second cumulative offset (4) can be directly used as the third cumulative offset.

接著,微控制器204將第三邏輯起始位址(36)加上第三累積偏移量(4)來獲得對應的第三實體起始位址(40),並自快閃記憶體200的第三實體起始位址(40)開始連續寫入第三資料寫入指令的資料。並且,微控制器204還執行記錄指令record(36,4)來將第三邏輯起始位址(36)與所對應的第三累積偏移量(4)對應記錄於查找表。 Next, the microcontroller 204 adds the third logical start address (36) to the third cumulative offset (4) to obtain the corresponding third physical start address (40), and then flash memory 200 The starting address (40) of the third entity starts to continuously write the data of the third data writing instruction. In addition, the microcontroller 204 also executes a record instruction record (36, 4) to record the third logical start address (36) and the corresponding third cumulative offset (4) in the lookup table.

藉此,原本未對齊的第三資料寫入指令的資料經過資料對齊後會被寫入至同頁。 In this way, the data of the originally unaligned third data writing instruction will be written to the same page after data alignment.

續請參閱圖8,為圖7的隨機寫入的示意圖,用以更詳盡說明本發明的如何執行隨機寫入操作。於本例子中,緩衝記憶體202的容量是與快閃記憶體200的單頁容量相同(如皆為8KB)。 Please continue to refer to FIG. 8, which is a schematic diagram of the random write of FIG. 7 to explain in more detail how the random write operation of the present invention is performed. In this example, the capacity of the buffer memory 202 is the same as the single page capacity of the flash memory 200 (for example, both are 8KB).

由於第一資料寫入指令的資料已經過資料對齊(其子資料A1、A2位於同頁),微控制器204僅需執行一次寫入操作即可將第一資料寫入指令的所有資料經由緩衝記憶體202寫入快閃記憶體200的特定頁。 Since the data of the first data write command has been data aligned (the sub data A1 and A2 are on the same page), the microcontroller 204 only needs to perform one write operation to buffer all the data of the first data write command The memory 202 writes a specific page of the flash memory 200.

由於第二資料寫入指令的資料未經過資料對齊(其子資料B1、B2分別位於不同頁),微控制器204必需執行兩次寫入操作才可將第二資料寫入指令的所有資料寫入快閃記憶體200,即第一次是以將子資料B1與快閃記憶體200的舊資料X1填滿緩衝記憶體202後,再寫入快閃記憶體200的特定頁,第二次是 以將子資料B2與快閃記憶體200的舊資料X2填滿緩衝記憶體202後,再寫入快閃記憶體200的特定頁。 Since the data of the second data write command is not aligned (the sub-data B1 and B2 are on different pages), the microcontroller 204 must perform two write operations to write all the data of the second data write command In the flash memory 200, the first time is to fill the buffer memory 202 with the sub-data B1 and the old data X1 of the flash memory 200, and then write to a specific page of the flash memory 200, the second time Yes After filling the buffer memory 202 with the sub-data B2 and the old data X2 of the flash memory 200, the specific page of the flash memory 200 is written.

由於第三資料寫入指令的資料已經過資料對齊(其子資料C1、C2位於同頁),微控制器204僅需執行一次寫入操作即可將第三資料寫入指令的所有資料經由緩衝記憶體202寫入快閃記憶體200的特定頁。 Since the data of the third data write command has been data aligned (the sub data C1 and C2 are on the same page), the microcontroller 204 only needs to perform one write operation to buffer all the data of the third data write command The memory 202 writes a specific page of the flash memory 200.

本發明經由有條件地執行資料對齊,可有效減少寫入次數,並可減少快閃記憶體容量浪費。 By performing data alignment conditionally, the present invention can effectively reduce the number of writes and reduce the waste of flash memory capacity.

以上所述僅為本發明的較佳具體實例,非因此即侷限本發明的專利範圍,故舉凡運用本發明內容所為的等效變化,均同理皆包含於本發明的範圍內,合予陳明。 The above are only the preferred specific examples of the present invention, and the patent scope of the present invention is not limited by this, so any equivalent changes in applying the content of the present invention are included in the scope of the present invention in the same way. Bright.

S10-S16‧‧‧寫入步驟 S10-S16‧‧‧ Writing procedure

Claims (10)

一種快閃記憶體的動態對齊資料方法,運用於具有一微控制器及一快閃記憶體的一快閃儲存裝置,包括以下步驟:a)控制該微控制器持續偵測該快閃儲存裝置的一使用狀態;b)接收一資料寫入指令,其中該資料寫入指令包括一邏輯起始位址;c)於該使用狀態符合一需對齊狀態時取得一累積偏移量,並依據該邏輯起始位址及該快閃記憶體的一配置單位容量更新該累積偏移量以獲得一更新後累積偏移量;d)將該邏輯起始位址及該更新後累積偏移量對應記錄於一查找表;e)將該邏輯起始位址加上該更新後累積偏移量以獲得一實體起始位址;f)於該步驟c)後,於該使用狀態不符合該需對齊狀態時將該邏輯起始位址加上該累積偏移量以獲得該實體起始位址;及g)由該快閃記憶體的該實體起始位址開始將對應該資料寫入指令的資料寫入該快閃記憶體。 A method for dynamically aligning data of a flash memory, applied to a flash storage device having a microcontroller and a flash memory, including the following steps: a) controlling the microcontroller to continuously detect the flash storage device A usage state of b; b) receiving a data write command, where the data write command includes a logical start address; c) obtaining a cumulative offset when the usage state matches a required alignment state, and according to the The logical start address and a configuration unit capacity of the flash memory update the cumulative offset to obtain an updated cumulative offset; d) the logical start address corresponds to the updated cumulative offset Record in a lookup table; e) add the logical start address to the updated cumulative offset to obtain a physical start address; f) after the step c), the use state does not meet the need In the aligned state, add the logical start address to the cumulative offset to obtain the physical start address; and g) Write the corresponding data from the physical start address of the flash memory The data is written to the flash memory. 如請求項1所述的快閃記憶體的動態對齊資料方法,其中該使用狀態為該微控制器持續未更新該累積偏移量期間的一寫入次數或一持續時間。 The method for dynamically aligning data of a flash memory according to claim 1, wherein the usage state is a number of writes or a duration during which the microcontroller has not updated the accumulated offset. 如請求項2所述的快閃記憶體的動態對齊資料方法,其中該步驟c是於該寫入次數不小於一預設寫入次數或該持續時間不小於一預設持續時間時更新該累積偏移量。 The method for dynamically aligning data of a flash memory as described in claim 2, wherein the step c is to update the accumulation when the write count is not less than a preset write count or the duration is not less than a preset duration Offset. 如請求項1所述的快閃記憶體的動態對齊資料方法,其中該步驟c更包括以下步驟:c1)計算一單次偏移量,其中該邏輯起始位址、所取得的該累積偏移量及該單次偏移量的和為該配置單位容量的倍數;及 c2)將該單次偏移量加上所取得的該累積偏移量以獲得該更新後累積偏移量。 The method for dynamically aligning data of a flash memory according to claim 1, wherein the step c further includes the following steps: c1) calculating a single offset, wherein the logical start address, the accumulated offset obtained The sum of the displacement and the single offset is a multiple of the unit capacity of the configuration; and c2) The single offset is added to the acquired cumulative offset to obtain the updated cumulative offset. 如請求項4所述的快閃記憶體的動態對齊資料方法,其中該步驟c1是計算該邏輯起始位址與所取得的該累積偏移量的和除以該配置單位容量後的一餘數,並計算該配置單位容量與該餘數的一差值以獲得該單次偏移量。 The method for dynamically aligning data of a flash memory according to claim 4, wherein the step c1 is to calculate a remainder after dividing the sum of the logical start address and the obtained cumulative offset by the configuration unit capacity And calculate a difference between the configuration unit capacity and the remainder to obtain the single offset. 如請求項1所述的快閃記憶體的動態對齊資料方法,其中更包括以下步驟:h1)接收一資料讀取指令,其中該資料讀取指令包括該邏輯起始位址及一資料長度;h2)查詢該查找表以取得對應該邏輯起始位址的該更新後累積偏移量;h3)將該邏輯起始位址加上該更新後累積偏移量來獲得該實體起始位址;及h4)依據該資料長度自該快閃記憶體的該實體起始位址開始連續讀取對應該資料讀取指令的資料。 The method for dynamically aligning data of a flash memory according to claim 1, further comprising the following steps: h1) receiving a data read command, wherein the data read command includes the logical start address and a data length; h2) Query the lookup table to obtain the updated cumulative offset corresponding to the logical start address; h3) Add the updated logical cumulative address to the logical start address to obtain the physical start address ; And h4) According to the data length, the data corresponding to the data read instruction is continuously read from the physical start address of the flash memory. 如請求項1所述的快閃記憶體的動態對齊資料方法,其中該步驟g)是先將資料排列寫入至該快閃儲存裝置的一緩衝記憶體,再將排列寫入後的資料自該緩衝記憶體直接複製至該快閃記憶體並由該實體起始位址開始寫入該快閃記憶體。 The method for dynamically aligning data of a flash memory according to claim 1, wherein the step g) is to first write the data into a buffer memory of the flash storage device, and then write the data after the arrangement into The buffer memory is directly copied to the flash memory and written into the flash memory from the physical start address. 一種快閃記憶體的動態對齊資料方法,運用於具有一微控制器及一快閃記憶體的一快閃儲存裝置,包括以下步驟:a)控制該微控制器接收一第一資料寫入指令,其中該第一資料寫入指令包括一第一邏輯起始位址;b)依據該第一邏輯起始位址及該快閃記憶體的一配置單位容量計算一第一偏移量,其中該第一邏輯起始位址及該第一偏移量的和為該配置單位容量的倍數; c)將該第一偏移量加上一初始累積偏移量以獲得一第一累積偏移量;d)將該第一邏輯起始位址及該第一累積偏移量對應記錄於一查找表;e)將該第一邏輯起始位址加上該第一累積偏移量以獲得一第一實體起始位址;f)由該快閃記憶體的該第一實體起始位址開始將對應該第一資料寫入指令的資料寫入該快閃記憶體;g)接收一第二資料寫入指令,其中該第二資料寫入指令包括一第二邏輯起始位址;h)依據該第二邏輯起始位址及該配置單位容量計算一第二偏移量,其中該第二邏輯起始位址及該第二偏移量的和為該配置單位容量的倍數;i)將該第二偏移量加上該第一累積偏移量以獲得一第二累積偏移量;j)將該第二邏輯起始位址及該第二累積偏移量對應記錄於該查找表;k)將該第二邏輯起始位址加上該第二累積偏移量以獲得一第二實體起始位址;及l)由該快閃記憶體的該第二實體起始位址開始將對應該第二資料寫入指令的資料寫入該快閃記憶體。 A method for dynamically aligning data of a flash memory, applied to a flash storage device having a microcontroller and a flash memory, including the following steps: a) controlling the microcontroller to receive a first data write command , Where the first data write instruction includes a first logical start address; b) calculate a first offset based on the first logical start address and a configuration unit capacity of the flash memory, wherein The sum of the first logical start address and the first offset is a multiple of the capacity of the configuration unit; c) add an initial cumulative offset to the first offset to obtain a first cumulative offset; d) record the first logical start address and the first cumulative offset in a corresponding Look-up table; e) adding the first logical start address to the first cumulative offset to obtain a first physical start address; f) the first physical start bit from the flash memory The address begins to write data corresponding to the first data write command to the flash memory; g) receives a second data write command, wherein the second data write command includes a second logical start address; h) Calculate a second offset based on the second logical start address and the configuration unit capacity, where the sum of the second logical start address and the second offset is a multiple of the configuration unit capacity; i) The second offset is added to the first cumulative offset to obtain a second cumulative offset; j) The second logical start address and the second cumulative offset are correspondingly recorded in The lookup table; k) adding the second logical start address to the second cumulative offset to obtain a second physical start address; and l) from the flash memory The second solid start address of the body will be the beginning of the second data write command to write data to the flash memory. 如請求項8所述的快閃記憶體的動態對齊資料方法,其中該步驟b是計算該第一邏輯起始位址與該初始累積偏移量的和除以該配置單位容量後的一第一餘數,並計算該配置單位容量與該第一餘數的一第一差值以獲得該第一偏移量;該步驟h是計算該第二邏輯起始位址與該第一累積偏移量的和除以該配置單位容量後的一第二餘數,並計算該配置單位容量與該第二餘數的一第二差值以獲得該第二偏移量。 The method for dynamically aligning data of a flash memory according to claim 8, wherein the step b is to calculate the sum of the first logical start address and the initial cumulative offset divided by the configuration unit capacity A remainder, and calculate a first difference between the configuration unit capacity and the first remainder to obtain the first offset; the step h is to calculate the second logical start address and the first cumulative offset The sum of is divided by a second remainder after the configuration unit capacity, and a second difference between the configuration unit capacity and the second remainder is calculated to obtain the second offset. 如請求項8所述的快閃記憶體的動態對齊資料方法,其中更包括以下步驟: m1)接收一第一資料讀取指令,其中該第一資料讀取指令包括該第一邏輯起始位址及一第一資料長度;m2)查詢該查找表以取得對應該第一邏輯起始位址的該第一累積偏移量;m3)將該第一邏輯起始位址加上該第一累積偏移量來獲得該第一實體起始位址;m4)依據該第一資料長度自該快閃記憶體的該第一實體起始位址開始連續讀取對應該第一資料讀取指令的資料;m5)接收一第二資料讀取指令,其中該第二資料讀取指令包括該第二邏輯起始位址及一第二資料長度;m6)查詢該查找表以取得對應該第二邏輯起始位址的該第二累積偏移量;m7)將該第二邏輯起始位址加上該第二累積偏移量來獲得該第二實體起始位址;及m8)依據該第二資料長度自該快閃記憶體的該第二實體起始位址開始連續讀取對應該第二資料讀取指令的資料。 The method for dynamically aligning data of a flash memory according to claim 8, further comprising the following steps: m1) Receive a first data read command, where the first data read command includes the first logical start address and a first data length; m2) query the lookup table to obtain the corresponding first logical start The first accumulated offset of the address; m3) the first logical start address is added to the first accumulated offset to obtain the first physical start address; m4) according to the first data length Continuously reading data corresponding to the first data reading instruction from the first physical start address of the flash memory; m5) receiving a second data reading instruction, wherein the second data reading instruction includes The second logical start address and a second data length; m6) query the lookup table to obtain the second cumulative offset corresponding to the second logical start address; m7) start the second logical start Add the second cumulative offset to obtain the second physical start address; and m8) continuously read from the second physical start address of the flash memory according to the second data length Data corresponding to the second data read instruction.
TW106102092A 2017-01-20 2017-01-20 Method of dynamically arranging data for flash memory TWI612421B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
TW106102092A TWI612421B (en) 2017-01-20 2017-01-20 Method of dynamically arranging data for flash memory

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
TW106102092A TWI612421B (en) 2017-01-20 2017-01-20 Method of dynamically arranging data for flash memory

Publications (2)

Publication Number Publication Date
TWI612421B true TWI612421B (en) 2018-01-21
TW201828065A TW201828065A (en) 2018-08-01

Family

ID=61728442

Family Applications (1)

Application Number Title Priority Date Filing Date
TW106102092A TWI612421B (en) 2017-01-20 2017-01-20 Method of dynamically arranging data for flash memory

Country Status (1)

Country Link
TW (1) TWI612421B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TWI787627B (en) 2020-07-02 2022-12-21 慧榮科技股份有限公司 Electronic device, flash memory controller and associated access method

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TW200401202A (en) * 2002-05-30 2004-01-16 Ibm Direct addressed shared compressed memory system
US20060136655A1 (en) * 2004-12-16 2006-06-22 Gorobets Sergey A Cluster auto-alignment
US20070143567A1 (en) * 2005-12-21 2007-06-21 Gorobets Sergey A Methods for data alignment in non-volatile memories with a directly mapped file storage system
US20100185830A1 (en) * 2009-01-21 2010-07-22 Micron Technology, Inc. Logical address offset

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TW200401202A (en) * 2002-05-30 2004-01-16 Ibm Direct addressed shared compressed memory system
US20060136655A1 (en) * 2004-12-16 2006-06-22 Gorobets Sergey A Cluster auto-alignment
US20070143567A1 (en) * 2005-12-21 2007-06-21 Gorobets Sergey A Methods for data alignment in non-volatile memories with a directly mapped file storage system
US20100185830A1 (en) * 2009-01-21 2010-07-22 Micron Technology, Inc. Logical address offset

Also Published As

Publication number Publication date
TW201828065A (en) 2018-08-01

Similar Documents

Publication Publication Date Title
CN112433956B (en) Sequential write based partitioning in a logical-to-physical table cache
TWI457756B (en) Memory system and operation method thereof
US8478796B2 (en) Uncorrectable error handling schemes for non-volatile memories
TWI775122B (en) Circuit for accessing at least one non-volatile memory
US9514057B2 (en) Storage module and method for managing logical-to-physical address mapping
US8347180B2 (en) Data storage system and method
WO2015185002A1 (en) Method and device for writing data
US9058255B2 (en) Solid state drive and method for constructing logical-to-physical table thereof
KR20200130742A (en) Apparatus and Method of Wear Leveling for Storage Class Memory
CN106802867B (en) Solid state storage device and data programming method thereof
TW201245959A (en) Dynamic and static data for a system having non-volatile memory
US20230342055A1 (en) Control method of flash memory controller and associated flash memory controller and storage device
US11704217B2 (en) Charge loss scan operation management in memory devices
TWI709074B (en) Apparatuses and methods for counter update operations
TWI556103B (en) Memory apparatus and data accessing method thereof
TWI612421B (en) Method of dynamically arranging data for flash memory
TW202044046A (en) A data storage device and a data processing method
JP6027567B2 (en) Cache memory and processor system
JP5066894B2 (en) Storage medium control device
CN108334276B (en) Dynamic data alignment method of flash memory
JP2012068765A (en) Memory controller, flash memory system with memory controller, and control method of flash memory
TWI748835B (en) Data processing method and the associated data storage device
JP2012037971A (en) Memory controller, nonvolatile memory system provided with memory controller, and method for controlling nonvolatile memory
TWI704454B (en) Mapping table management method applied to solid state storage device
TWI695264B (en) A data storage device and a data processing method