A method for processing log blocks in a file system
By merging and initializing log blocks, the resource utilization of log blocks in the file system is optimized, solving the problems of uneven log block resource distribution and duplicate allocation, and improving resource utilization efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 上海睿赛德电子科技有限公司
- Filing Date
- 2022-08-24
- Publication Date
- 2026-04-14
AI Technical Summary
In existing technologies, the problems of uneven resource utilization and duplicate allocation of log blocks in file systems have not been effectively solved.
By traversing log blocks, merging used log blocks, allocating and initializing new physical blocks, and updating the mapping relationship between logical blocks and physical blocks, log block merging and resource optimization are achieved.
It reduces the problem of resource duplication and uneven allocation in the file system, and improves resource utilization efficiency.
Smart Images

Figure CN115292271B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a physical block optimization method in a file system, specifically a log block processing method in a file system. Background Technology
[0002] During operation, a file system accomplishes its storage, read / write, and management functions by setting up physical blocks and assigning them different functions. A physical block refers to all the blocks that can be allocated within a Flash chip. A physical block can be used as any functional block. When a physical block is assigned a management function, it becomes a management block; similarly, when it is assigned a location recording function, it becomes a logical block.
[0003] Some of the aforementioned functions need to be completed in the log layer, where the physical blocks are called log blocks. In the entire file system, the transport layer is responsible for data reading and writing. Whether it's a write or read operation, the first operation is on the log blocks. Each log block stores a mapping relationship between logical blocks and physical blocks. When the physical resources in the log block are exhausted, a merge operation is triggered. The merge operation transfers the stored mapping relationship to the data blocks for unified storage, and the data is also migrated accordingly, while updating the mapping relationship of the management blocks. Summary of the Invention
[0004] To address the aforementioned technical problems, this invention provides a method for processing log blocks in a file system.
[0005] The present invention is achieved through the following technical solutions.
[0006] This invention provides a method for processing log blocks in a file system, comprising the following steps:
[0007] (S100) The transport layer traverses all log blocks and finds the log blocks that have been used;
[0008] (S200) Check if the number of log blocks used is greater than 2. If so, proceed to (S300); otherwise, the merging ends.
[0009] (S300) Merge used log blocks;
[0010] (S400) Enter the first cycle;
[0011] (S500) Allocate the second physical block and initialize it;
[0012] (S600) Traverse all pages in the above log block.
[0013] (S700) Enter the second cycle;
[0014] (S800) Log block merging complete.
[0015] Furthermore, (S400) entering the first cycle includes the following steps:
[0016] (S401) The transport layer traverses all physical blocks. Based on the logical block index in the log block, the transport layer traverses all physical blocks in the transport layer to find if there is a corresponding first physical block. If there is, proceed to (S402); otherwise, proceed to the third loop.
[0017] (S402) Traverse all pages in the log block;
[0018] (S403) Check if there is data on page i in the corresponding log block. If there is, proceed to (S404); otherwise, proceed to (S410).
[0019] (S404) Check whether the state of page i of the first physical block is used. If it is, proceed to (S405); otherwise, proceed to (S410).
[0020] (S405) Set all page states of the first physical block to unused and exit the first loop;
[0021] (S410) Check if all pages in the log block have been traversed. If yes, proceed to (S411); otherwise, return to (S402).
[0022] (S411) Traverse all pages in the log block;
[0023] (S412) For pages containing data in the log block, obtain the actual Flash offset based on the physical block index and page index of the log block;
[0024] (S413) Read the content of the page from Flash according to the offset;
[0025] (S414) Write the read content into the page corresponding to the third physical block of the transport layer;
[0026] (S415) Check if all pages in the log block have been traversed. If yes, proceed to (S416); otherwise, return to (S411).
[0027] (S416) Set the third physical block corresponding to the physical block index stored in the log block to dirt2.
[0028] Furthermore, (S700) entering the second cycle includes the following steps:
[0029] (S701) Detect whether the i-th page of the fourth physical block corresponding to the transport layer is used. If it is, proceed to (S702); otherwise, proceed to (S710).
[0030] (S702) The actual Flash offset is obtained based on the fourth physical block index and the i-th page index corresponding to the transport layer;
[0031] (S703) Read the content of the page from the Flash memory according to the actual Flash offset;
[0032] (S704) Write the read content to the page corresponding to the fifth physical block;
[0033] (S705) Check if all pages of the log block have been traversed. If yes, proceed to (S706); otherwise, return to (S600).
[0034] (S706) Update the physical block index corresponding to the transport layer to the newly allocated second physical block index;
[0035] (S707) Set the physical block status corresponding to the fifth physical block index to dirt2;
[0036] (S708) Set the status of the fifth physical block corresponding to the physical block index stored in the log block to dirt2;
[0037] (S709) Initialize the log block;
[0038] (S710) Check whether the sixth physical block corresponding to the transport layer has been used. If it has, proceed to (S711); otherwise, return to (S600).
[0039] (S711) Check whether the i-th page of the sixth physical block corresponding to the transport layer is used. If it is, proceed to (S712); otherwise, return to (S600).
[0040] (S712) The actual Flash offset is obtained based on the sixth physical block index and the i-th page index corresponding to the transport layer;
[0041] (S713) Read the content of the page from Flash according to the offset;
[0042] (S714) Write the read content into the corresponding page of the newly allocated second physical block;
[0043] (S715) Proceed to (S704), and the second cycle ends.
[0044] Furthermore, the third cycle includes the following steps:
[0045] (S801) Traverse all pages of this log block;
[0046] (S802) Check whether the i-th page in the log block contains data. If it does, proceed to (S803); otherwise, return to (S801).
[0047] (S803) Check if the value of page i in the log block is equal to i. If not, exit the third loop and enter the fourth loop; if yes, proceed to (S810).
[0048] (S880) Check whether the transport layer has traversed all pages in the log block. If not, return (S801); if so, proceed to (S881).
[0049] (S881) Assign the physical block index and logical block index corresponding to the physical block index of the log block to the transport layer;
[0050] (S882) Set all page states in the physical block to used.
[0051] Furthermore, the fourth cycle includes the following steps:
[0052] (S804) Allocate a seventh physical block and initialize it;
[0053] (S805) Traverse all pages in the log block;
[0054] (S806) Obtain the actual Flash offset of the non-blank pages in the log block based on the physical block index and page index of the log block;
[0055] (S807) Read the content of the page from Flash according to the offset, and write the read content into the corresponding page of the seventh physical block;
[0056] (S808) Check if all pages in the log block have been traversed. If yes, proceed to (S809); otherwise, return to (S805).
[0057] (S810) Store the index of the seventh physical block (just allocated) in the transport layer;
[0058] (S811) Set the status of the second physical block corresponding to the physical block index stored in the log block to dirt2;
[0059] (S813) Log block initialization, fourth loop ends.
[0060] Furthermore, (S300) merging used log blocks includes the following steps:
[0061] The transport layer merges log blocks in descending order of the number of log block pages used.
[0062] Furthermore, the log blocks record the mapping relationship between logical page indexes and physical page indexes, and the mapping relationship between logical block indexes and physical block indexes.
[0063] The beneficial effects of this invention are that by continuously calling and writing log blocks, physical blocks are merged, which can reduce problems such as resource duplication and uneven distribution in the file system. Attached Figure Description
[0064] Figure 1 This is a schematic diagram of the overall logical relationship of the present invention;
[0065] Figure 2 This is a schematic diagram of the first loop logic relationship of the present invention;
[0066] Figure 3 This is a schematic diagram of the second loop logic relationship of the present invention;
[0067] Figure 4 This is a schematic diagram of the third loop logic relationship of the present invention. Detailed Implementation
[0068] The technical solution of the present invention is further described below, but the scope of protection is not limited to what is described.
[0069] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0070] (S100) The transport layer traverses all log blocks and finds the log blocks that have been used;
[0071] (S200) Check if the number of log blocks used is greater than 2. If so, proceed to (S300); otherwise, the merging ends.
[0072] (S300) Merge used log blocks;
[0073] (S400) Enter the first cycle;
[0074] (S500) Allocate the second physical block and initialize it;
[0075] (S600) Traverse all pages in the above log block.
[0076] (S700) Enter the second cycle;
[0077] (S800) Log block merging complete.
[0078] Furthermore, (S400) entering the first cycle includes the following steps:
[0079] (S401) The transport layer traverses all physical blocks. Based on the logical block index in the log block, the transport layer traverses all physical blocks in the transport layer to find if there is a corresponding first physical block. If there is, proceed to (S402); otherwise, proceed to the third loop.
[0080] (S402) Traverse all pages in the log block;
[0081] (S403) Check if there is data on page i in the corresponding log block. If there is, proceed to (S404); otherwise, proceed to (S410).
[0082] (S404) Check whether the state of page i of the first physical block is used. If it is, proceed to (S405); otherwise, proceed to (S410).
[0083] (S405) Set all page states of the first physical block to unused and exit the first loop;
[0084] (S410) Check if all pages in the log block have been traversed. If yes, proceed to (S411); otherwise, return to (S402).
[0085] (S411) Traverse all pages in the log block;
[0086] (S412) For pages containing data in the log block, obtain the actual Flash offset based on the physical block index and page index of the log block;
[0087] (S413) Read the content of the page from Flash according to the offset;
[0088] (S414) Write the read content into the page corresponding to the third physical block of the transport layer;
[0089] (S415) Check if all pages in the log block have been traversed. If yes, proceed to (S416); otherwise, return to (S411).
[0090] (S416) Set the third physical block corresponding to the physical block index stored in the log block to dirt2.
[0091] Furthermore, (S700) entering the second cycle includes the following steps:
[0092] (S701) Detect whether the i-th page of the fourth physical block corresponding to the transport layer is used. If it is, proceed to (S702); otherwise, proceed to (S710).
[0093] (S702) The actual Flash offset is obtained based on the fourth physical block index and the i-th page index corresponding to the transport layer;
[0094] (S703) Read the content of the page from the Flash memory according to the actual Flash offset;
[0095] (S704) Write the read content to the page corresponding to the fifth physical block;
[0096] (S705) Check if all pages of the log block have been traversed. If yes, proceed to (S706); otherwise, return to (S600).
[0097] (S706) Update the physical block index corresponding to the transport layer to the newly allocated second physical block index;
[0098] (S707) Set the physical block status corresponding to the fifth physical block index to dirt2;
[0099] (S708) Set the status of the fifth physical block corresponding to the physical block index stored in the log block to dirt2;
[0100] (S709) Initialize the log block;
[0101] (S710) Check whether the sixth physical block corresponding to the transport layer has been used. If it has, proceed to (S711); otherwise, return to (S600).
[0102] (S711) Check whether the i-th page of the sixth physical block corresponding to the transport layer is used. If it is, proceed to (S712); otherwise, return to (S600).
[0103] (S712) The actual Flash offset is obtained based on the sixth physical block index and the i-th page index corresponding to the transport layer;
[0104] (S713) Read the content of the page from Flash according to the offset;
[0105] (S714) Write the read content into the corresponding page of the newly allocated second physical block;
[0106] (S715) Proceed to (S704), and the second cycle ends.
[0107] Furthermore, the third cycle includes the following steps:
[0108] (S801) Traverse all pages of this log block;
[0109] (S802) Check whether the i-th page in the log block contains data. If it does, proceed to (S803); otherwise, return to (S801).
[0110] (S803) Check if the value of page i in the log block is equal to i. If not, exit the third loop and enter the fourth loop; if yes, proceed to (S810).
[0111] (S880) Check whether the transport layer has traversed all pages in the log block. If not, return (S801); if so, proceed to (S881).
[0112] (S881) Assign the physical block index and logical block index corresponding to the physical block index of the log block to the transport layer;
[0113] (S882) Set all page states in the physical block to used.
[0114] Furthermore, the fourth cycle includes the following steps:
[0115] (S804) Allocate a seventh physical block and initialize it;
[0116] (S805) Traverse all pages in the log block;
[0117] (S806) Obtain the actual Flash offset of the non-blank pages in the log block based on the physical block index and page index of the log block;
[0118] (S807) Read the content of the page from Flash according to the offset, and write the read content into the corresponding page of the seventh physical block;
[0119] (S808) Check if all pages in the log block have been traversed. If yes, proceed to (S809); otherwise, return to (S805).
[0120] (S810) Store the index of the seventh physical block (just allocated) in the transport layer;
[0121] (S811) Set the status of the second physical block corresponding to the physical block index stored in the log block to dirt2;
[0122] (S813) Log block initialization, fourth loop ends.
[0123] Furthermore, (S300) merging used log blocks includes the following steps:
[0124] The transport layer merges log blocks in descending order of the number of log block pages used.
[0125] Furthermore, the log blocks record the mapping relationship between logical page indexes and physical page indexes, and the mapping relationship between logical block indexes and physical block indexes.
Claims
1. A method for processing log blocks in a file system, characterized in that... Includes the following steps: (S100) The transport layer traverses all log blocks and finds the log blocks that have been used; (S200) Check if the number of log blocks used is greater than 2. If so, proceed to (S300); otherwise, the merging ends. (S300) Merge used log blocks; (S400) Enter the first cycle; (S500) Allocate the second physical block and initialize it; (S600) Traverse all pages in the above log block; (S700) Enter the second cycle; (S800) Log block merging complete; Entering the first cycle (S400) includes the following steps: (S401) The transport layer traverses all physical blocks. Based on the logical block index in the log block, the transport layer traverses all physical blocks in the transport layer to find if there is a corresponding first physical block. If there is, proceed to (S402); otherwise, proceed to the third loop. (S402) Traverse all pages in the log block; (S403) Check if there is data on page i in the corresponding log block. If there is, proceed to (S404); otherwise, proceed to (S410). (S404) Check whether the state of page i of the first physical block is used. If it is, proceed to (S405); otherwise, proceed to (S410). (S405) Set all page states of the first physical block to unused and exit the first loop; (S410) Check if all pages in the log block have been traversed. If yes, proceed to (S411); otherwise, return to (S402). (S411) Traverse all pages in the log block; (S412) For pages containing data in the log block, obtain the actual Flash offset based on the physical block index and page index of the log block; (S413) Read the content of the page from Flash according to the offset; (S414) Write the read content into the page corresponding to the third physical block of the transport layer; (S415) Check if all pages in the log block have been traversed. If yes, proceed to (S416); otherwise, return to (S411). (S416) Set the third physical block corresponding to the physical block index stored in the log block to dirt2; The step of entering the second cycle (S700) includes the following steps: (S701) Detect whether the i-th page of the fourth physical block corresponding to the transport layer is used. If it is, proceed to (S702); otherwise, proceed to (S710). (S702) The actual Flash offset is obtained based on the fourth physical block index and the i-th page index corresponding to the transport layer; (S703) Read the content of the page from the Flash memory according to the actual Flash offset; (S704) Write the read content to the page corresponding to the fifth physical block; (S705) Check if all pages of the log block have been traversed. If yes, proceed to (S706); otherwise, return to (S600). (S706) Update the physical block index corresponding to the transport layer to the newly allocated second physical block index; (S707) Set the physical block status corresponding to the fifth physical block index to dirt2; (S708) Set the status of the fifth physical block corresponding to the physical block index stored in the log block to dirt2; (S709) Initialize the log block; (S710) Check whether the sixth physical block corresponding to the transport layer has been used. If it has, proceed to (S711); otherwise, return to (S600). (S711) Check whether the i-th page of the sixth physical block corresponding to the transport layer is used. If it is, proceed to (S712); otherwise, return to (S600). (S712) The actual Flash offset is obtained based on the sixth physical block index and the i-th page index corresponding to the transport layer; (S713) Read the content of the page from Flash according to the offset; (S714) Write the read content into the corresponding page of the newly allocated second physical block; (S715) Proceed to (S704), and the second cycle ends.
2. The log block processing method in a file system as described in claim 1, characterized in that... The third cycle includes the following steps: (S801) Traverse all pages of this log block; (S802) Check whether the i-th page in the log block contains data. If it does, proceed to (S803); otherwise, return to (S801). (S803) Check if the value of page i in the log block is equal to i. If not, exit the third loop and enter the fourth loop; if yes, proceed to (S810). (S880) Check whether the transport layer has traversed all pages in the log block. If not, return (S801); if so, proceed to (S881). (S881) Assign the physical block index and logical block index corresponding to the physical block index of the log block to the transport layer; (S882) Set all page states in the physical block to used.
3. The log block processing method in a file system as described in claim 2, characterized in that... The fourth cycle includes the following steps: (S804) Allocate a seventh physical block and initialize it; (S805) Traverse all pages in the log block; (S806) Obtain the actual Flash offset of the non-blank pages in the log block based on the physical block index and page index of the log block; (S807) Read the content of the page from Flash according to the offset, and write the read content into the corresponding page of the seventh physical block; (S808) Check if all pages in the log block have been traversed. If yes, proceed to (S809); otherwise, return to (S805). (S809) Store the index of the seventh physical block in the transport layer; (S810) Set the status of the second physical block corresponding to the physical block index stored in the log block to dirt2; (S811) Proceed to (S709), the fourth cycle ends.
4. The method for processing log blocks in a file system as described in claim 1, characterized in that... The step (S300) of merging used log blocks includes the following steps: The transport layer merges log blocks in descending order of the number of log block pages used.
5. The method for processing log blocks in a file system as described in claim 1, characterized in that... The log blocks record the mapping relationship between logical page indexes and physical page indexes, and the mapping relationship between logical block indexes and physical block indexes.
Citation Information
Patent Citations
Method and system for merging logs of memory database
CN101625703A
Nand writing balance processing method
CN102339255A