A garbage collection method for log-structured file systems
By optimizing the garbage collection method of the log-structured file system and screening and calculating the candidate segments with the lowest migration overhead, the performance degradation and energy consumption increase problems caused by free space fragmentation are solved, and efficient garbage collection and energy consumption reduction are achieved.
Patent Information
- Application Number
- CN202211491811.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-25
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2042-11-25
AI Technical Summary
Existing technologies fail to effectively reduce free space fragmentation in log-structured file systems, resulting in decreased file system performance and increased energy consumption. Existing garbage collection methods fail to fully consider the impact of free space fragmentation.
By screening candidate segments and calculating the candidate segments with the lowest migration overhead as the segments to be cleaned, segments with high free space fragmentation, cold data, and high non-valid space ratio are selected for garbage collection. The garbage collection process is optimized by taking advantage of the inverse correlation between the weighted sum of the free space fragmentation coefficient, data coldness, and non-valid space ratio.
It effectively reduces free space fragmentation, reduces garbage collection times and energy consumption, and improves the energy efficiency of invalid space recovery, in line with the pre-reading mechanism and user I/O characteristics of the Linux system.
Smart Images

Figure CN115878575B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer storage, and more particularly, relates to a garbage collection method for a log structure file system. Background Art
[0002] In the era of big data, the reading and writing of massive amounts of data poses a high-performance challenge to storage systems. Flash memory, with its advantages of large capacity, low power consumption, and low access latency, is gradually replacing traditional disks as the mainstream storage device. The Flash-Friendly File System (F2FS), a widely used log-structured file system, leverages its file layout, which is friendly to the physical unit organization of flash memory, and uses a log-structured append-write approach to improve random write performance. When a file system runs out of continuous free space, a large amount of free space fragmentation remains in the system. This requires triggering garbage collection (GC) to obtain free segments, or using a threaded log write approach to overwrite free space fragments, directly resulting in fragmentation of newly written files. Both approaches degrade file system read and write performance. Experimental analysis has found that free space fragmentation significantly increases storage system energy consumption. Using GC to defragment free space fragments consumes significant energy, while its effectiveness in reducing free space fragmentation is limited. In short, improving the energy efficiency of dead space reclamation in log-structured file systems is key to ensuring the high performance of flash storage systems. Free space fragmentation refers to dead space and discrete small free spaces. In F2FS, free space fragmentation primarily consists of dead space.
[0003] F2FS performs garbage collection in sections. The current version of F2FS defaults to one section containing one segment. F2FS uses two garbage collection methods: foreground garbage collection and background garbage collection. Foreground garbage collection is triggered only when there is insufficient free space, while background garbage collection is triggered by periodically waking up kernel threads. Foreground garbage collection uses a greedy algorithm to select objects for cleanup, while background garbage collection uses a cost-benefit algorithm. Both garbage collection processes increase the amount of data read and written, degrading file system performance and shortening the life of the flash memory.
[0004] The garbage collection process consists of three steps: selecting cleaning objects, identifying valid data and migrating them, and waiting for checkpoint synchronization data to recycle the cleaned segments. The garbage collection process can be optimized by optimizing the distribution of valid data in dirty segments, the selection of cleaning objects, and the cleaning frequency, thereby reducing the number of garbage collection triggers. Li et al. proposed a high-detection-frequency background garbage collection method in "Optimizing Fragmentation and Segment Cleaning for CPS-based Storage Devices". This method dynamically adjusts the background garbage collection frequency according to the amount of free space, effectively improving garbage collection performance and reducing the impact on flash memory life. Wu et al. proposed a reinforcement learning-assisted background garbage collection method, RLBC, in "Reinforcement Learning based Background SegmentCleaning for Log-structured File System on Mobile Devices". By learning the behavior of the input / output workload and the state of the logical address space, it adaptively determines when to trigger background garbage collection based on the reinforcement learning method, achieving the goal of balancing system performance and storage life. In addition, the F2FS garbage collection strategy ATGC (Age-Threshold based Garbage Collection) proposed by Yu et al. has been integrated into the Linux kernel version 5.10 and later. ATGC performs garbage collection based on an age threshold, screening older objects for cleaning according to the defined age threshold. ATGC is the latest garbage collection strategy used by F2FS in addition to foreground GC and background GC, and improves the efficiency of the file system's background GC.
[0005] The above GC optimization solutions can optimize the garbage collection process to a certain extent and improve the overall performance of the file system. However, these solutions do not fully consider the free space fragmentation of the file system. The effectiveness of the energy-intensive background GC in reducing free space fragmentation needs to be further improved. Summary of the Invention
[0006] In response to the defects of the existing technology and the need for improvement, the present invention provides a garbage collection method for a log-structured file system, the purpose of which is to optimize the garbage collection process in a log-structured file system to effectively reduce free space fragmentation, improve the energy efficiency of recycling invalid space in the file system, and reduce recycling energy consumption.
[0007] To achieve the above object, according to one aspect of the present invention, a garbage collection method for a log-structured file system is provided, comprising:
[0008] Filter out some segments that need to be cleaned as candidate segments;
[0009] For each candidate segment, the migration cost of migrating valid data in the candidate segment is calculated, and the candidate segment with the lowest migration cost is selected as the segment to be cleaned. The migration cost of a segment is inversely correlated with the weighted sum of the segment's free space fragmentation level, data coolness, and the proportion of ineffective space.
[0010] Select a target segment for the cleaned segment, migrate the valid data in the cleaned segment to the target segment, reclaim the space of the cleaned segment, and complete garbage collection.
[0011] Furthermore, the degree of free space fragmentation of a segment is characterized by a free space fragmentation coefficient f, and the calculation formula of the free space fragmentation coefficient f is:
[0012]
[0013] Among them, n represents the number of fragments in the segment, i represents the fragment sequence number, and X i Indicates the number of logical blocks contained in the i-th fragment; m is the free space fragment threshold, and the space smaller than m KB in the segment is a free space fragment.
[0014] Furthermore, m=128.
[0015] Furthermore, the coolness of the data in a segment is represented by the age of the segment, and the calculation formula of age is:
[0016]
[0017] Among them, max_mtime represents the maximum update time of the segment in the log structure file system, mtime represents the update time of the current candidate segment, and total_time represents the total time.
[0018] Furthermore, the calculation formula for the non-effective space ratio of a segment is:
[0019]
[0020] Among them, u represents the proportion of non-valid space in the segment, vblocks represents the number of logical blocks that store valid data in the segment, and tblocks represents the total number of logical blocks contained in the segment.
[0021] Furthermore, the calculation formula for the segment migration cost is:
[0022] cost=UINT_MAX-10000*(f*f_weight+age*age_weight+u*u_weight)
[0023] Among them, cost represents the migration cost of the segment, f_weight, age_weight and u_weight represent the weights of the free space fragmentation coefficient f, age age and non-valid space ratio u respectively, f_weight+age_weight+u_weight=100, and UNIT_MAX is the preset maximum value.
[0024] Furthermore, the target segment is the segment closest in age to the cleaned segment.
[0025] Furthermore, the selected candidate segment is a segment with the greatest degree of free space fragmentation, or the selected candidate segment is a segment with the highest data coolness, or the selected candidate segment is a segment with the highest proportion of non-valid space.
[0026] According to another aspect of the present invention, a computer-readable storage medium is provided, comprising a stored computer program. When the computer program is executed by a processor, the device where the computer-readable storage medium is located is controlled to execute the garbage collection method for a log-structured file system provided by the present invention.
[0027] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects:
[0028] (1) When performing garbage collection, the present invention first calculates the migration overhead of valid data in the candidate segment, and selects the candidate segment with the lowest migration overhead as the object to be cleaned, that is, the cleaned segment. Since the migration overhead calculated by the present invention is inversely correlated with the weighted sum of the free space fragmentation degree, data coldness and non-valid space ratio of the segment, the basis for the present invention to select the cleaned segment is the result of the combined effect of multiple factors. The cleaned segment finally selected is a segment with a high degree of free space fragmentation, cold data and a high non-valid space ratio; since the free space fragmentation degree of the cleaned segment is high, the free space fragmentation can be effectively reduced after garbage collection is executed; since the data in the cleaned segment is cold, the probability of the segment where the relevant data is located being used as the cleaned object again after data migration is low, thereby reducing the number of garbage collections and reducing energy consumption; since the non-valid space ratio of the cleaned segment is high, the number of valid blocks that need to be migrated is small, the amount of read and write data is small, and the energy efficiency of invalid space recovery is improved. In general, when performing garbage collection on a log-structured file system, the present invention selects segments with a high degree of free space fragmentation, cold data, and a high proportion of non-valid space as the segments to be cleaned, which can effectively reduce free space fragmentation, reduce energy consumption, and improve the energy efficiency of recovering invalid space.
[0029] (2) In the preferred embodiment of the present invention, according to the formula Calculate the free space fragmentation coefficient f used to characterize the degree of free space fragmentation of the segment, where Xi Indicates the number of logical blocks contained in the i-th fragment (i.e., space smaller than m KB), Accurately reflects the degree of fragmentation of a fragment, X i The smaller it is, the smaller the fragments are. The larger the value, the cumulative sum of the fragmentation degrees of each fragment in the segment is used as the free space fragmentation degree of the entire segment, which accurately reflects the free space fragmentation degree of the segment; on this basis, the present invention corresponds to the free space fragmentation degree of each fragment in the segment. By multiplying (m-2)*(m-1) by the value of (m-2)*(m-1), the calculation results corresponding to free space fragments of different sizes can be different integers, avoiding the use of floating-point operations in the kernel. At the same time, free space fragments of different sizes can be quickly distinguished.
[0030] (3) In the preferred embodiment of the present invention, the threshold for identifying free space fragments in a segment is m=128, so that the space in a segment smaller than 128KB is considered free space fragments. The present invention studies the existing GC benefits and finds that the benefits of background GC in sorting free space with a size range of 128KB or more to obtain continuous free space are smaller than those of sorting free space smaller than 128KB to obtain continuous free space. Therefore, the present invention uses 128KB as the threshold for identifying free space fragments in a segment, which can ensure that garbage collection has a higher benefit. The present invention further studies the system's read and write mechanism and the characteristics of user I / O and finds that since the Linux kernel sets 128KB as the default pre-read size, using 128KB as the threshold for identifying free space fragments can ensure that the pre-read operation can be completed with only one I / O request and will not be split into multiple I / O requests. At the same time, more than 80% of the read and write I / O sizes in user I / O do not exceed 128KB. Therefore, using 128KB as the threshold for identifying free space fragments can ensure that most I / O requests are satisfied. In general, the present invention uses 128KB as the threshold for identifying free space fragments, which is consistent with the pre-reading mechanism of the existing Linux system and the user's read and write I / O characteristics, and can effectively improve the comprehensive benefits of garbage collection.
[0031] (4) In the preferred embodiment of the present invention, a maximum value UNIT_MAX is preset, and then the free space fragmentation coefficient f, age age and non-valid space ratio u are weightedly summed, and the weighted summation result is multiplied by 10000 for amplification, and the difference between the maximum value UNIT_MAX and the amplified result is taken as the migration cost of the segment. This calculation method can accurately calculate the migration cost of valid data in the segment and makes it easy to distinguish the migration costs of different segments.
[0032] (5) In the preferred embodiment of the present invention, the segment closest in age to the segment being cleaned is selected as the target segment for migrating valid data. Since the data in segments with similar ages have similar hotness and coldness, and similar expiration times, the probability of the overall data in the target segment being invalid after migration is relatively high, thereby effectively reducing the migration overhead in the subsequent garbage collection process. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 A schematic diagram illustrating the severity of fragmentation in a segment according to an embodiment of the present invention;
[0034] Figure 2 A schematic diagram of a garbage collection method for a log-structured file system provided by an embodiment of the present invention;
[0035] Figure 3 Schematic diagram of data migration between traditional F2FS and FAGC provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0036] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely for the purpose of explaining the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below may be combined with each other as long as they do not conflict with each other.
[0037] In the present invention, the terms "first", "second", etc. (if any) in the present invention and the drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0038] The garbage collection process in a log-structured file system is optimized to effectively reduce free space fragmentation, improve the recovery efficiency of invalid space in the file system, and reduce recovery energy consumption. The present invention provides a garbage collection method for a log-structured file system. The overall idea is: during the garbage collection process, the impact of the degree of free space fragmentation in the segment on the recovery efficiency and energy consumption of the free space in the garbage collection process is fully considered, and segments with a high degree of free space fragmentation, cold data, and a high proportion of non-valid space are selected as cleaned segments for recovery. Accordingly, a threshold value for accurately identifying free space fragmentation is proposed.
[0039] Before explaining the technical solution of the present invention in detail, the following explanation is given on free space fragmentation and the degree of free space fragmentation.
[0040] In a log-structured file system, data is typically organized into segments, each containing a fixed number of logical blocks. Taking F2FS as an example, each logical block is 4KB in size, and each segment contains 512 logical blocks, resulting in a segment size of 2MB. During garbage collection, spaces smaller than a segment size must be consolidated to create contiguous space of 2MB or more.
[0041] Distinguishing between free space and free space fragmentation is a key issue in selecting garbage collection targets. Large free spaces can satisfy most I / O tasks without splitting I / O requests and are therefore considered available space, not free space fragmentation. The traditional definition of fragmentation—that only completely continuous free space is considered free—leads to more aggressive garbage collection in log-structured file systems. To ensure continuous free space, the number of GCs increases, leading to higher GC overhead.
[0042] by Figure 1 For example, assuming that each segment consists of 16 logical blocks, segments a, b, and c contain the same number of valid blocks, but the distribution of valid blocks in segments a, b, and c is different, accompanied by different degrees of free space fragmentation. Figure 1 The three segments a, b, and c have the same number of valid blocks. Regardless of which segment is selected for cleanup, the migration overhead is to migrate eight valid blocks. However, considering the situation before migration, if a 16KB file is to be written, it is split into four I / O requests in segment a, two I / O requests in segment b, and only one I / O request in segment c. Because the free space in segment c is the least fragmented, choosing segment a as the cleanup target has the greatest garbage collection benefit. According to traditional definitions, segment c is considered to contain free space fragments. In fact, the continuous free space in segment c is large enough that only one I / O request can be used to satisfy the reading and writing of most files. It is unnecessary to select segment c to reclaim invalid space. The existing F2FS garbage collection policy may select segment c for garbage collection. Therefore, it is urgent to define the appropriate free space fragment size based on data analysis.
[0043] Based on the premise of not affecting user performance experience, the present invention defines an appropriate free space fragment size, considers the degree of free space fragmentation during GC, and optimizes the defragmentation strategy.
[0044] After analyzing the energy consumption of the log-structured file system, it was found that file fragmentation and free space fragmentation increase the number of read and write times of I / O tasks, resulting in a significant increase in the energy consumption of the CPU module and UFS module of the smartphone to complete I / O tasks. At present, there are many methods for reducing file fragmentation. The existing method of reducing free space fragmentation in F2FS is garbage collection, and the background GC frequently called by the system needs to migrate valid blocks, which has large read and write overhead and energy consumption overhead, and the effect of background GC in reducing free space fragmentation is limited. The present invention found that the existing background GC mainly organizes free space fragments with a size range of 128KB to 1MB to obtain 2MB and above of continuous free space, which is less profitable than organizing smaller free space fragments to obtain continuous free space.
[0045] Further research and analysis of the system's read and write mechanisms and user I / O characteristics revealed that, on the one hand, because the Linux kernel sets 128KB as the default pre-read size, a 128KB free space can be satisfied with a single I / O request if 128KB of pre-read data is placed in that free space, rather than being split into multiple I / O requests. Furthermore, analysis of application startup traces revealed a large number of 64KB synchronous and asynchronous read requests. Using a 128KB free space allows for continuous storage of read request data. Using the MobiBench tool to capture traces of an average user using different applications throughout the day, analysis of the number of read and writes of data blocks of different sizes revealed that read I / Os of 128KB or less accounted for 85%, and write I / Os of 128KB or less accounted for 87%. Furthermore, among the larger requests in applications, only 2% of Baidu Maps requests were 512KB in size, while 128KB requests accounted for only 4%, 2%, and 6%, respectively, for Gallery, QQ, and Taobao.
[0046] Based on the above analysis, the present invention defines free space less than 128KB as free space fragmentation. That is, the free space fragmentation threshold is 128KB. This threshold is consistent with the pre-read mechanism of existing Linux systems and the user's read and write I / O characteristics, effectively improving the overall benefits of garbage collection. In the following embodiments, free space fragmentation is identified using a threshold of 128KB, and the degree of free space fragmentation is measured to focus on a single segment when triggering garbage collection.
[0047] The following are examples.
[0048] Example 1:
[0049] A garbage collection method for log-structured file systems, such as Figure 2 Shown, including:
[0050] Filter out some segments that need to be cleaned as candidate segments;
[0051] For each candidate segment, the migration cost of migrating valid data in the candidate segment is calculated, and the candidate segment with the lowest migration cost is selected as the segment to be cleaned. The migration cost of a segment is inversely correlated with the weighted sum of the segment's free space fragmentation level, data coolness, and the proportion of ineffective space.
[0052] Select a target segment for the cleaned segment, migrate the valid data in the cleaned segment to the target segment, reclaim the space of the cleaned segment, and complete garbage collection.
[0053] To facilitate quantification of the degree of free space fragmentation in a segment, this embodiment uses a valid bitmap for each segment, namely valid_map. Each bit in the valid bitmap is used to record the status of a 4KB logical block in the segment. 0 indicates that the logical block is free, and 1 indicates that valid data is stored in the logical block. The number of consecutive 0s in the valid bitmap indicates the size of the free space. Based on data analysis, the free space fragmentation threshold is set to 128KB, divided by the size of each block (4KB), and assigned a value of 32. If the number of consecutive 0s in the bitmap is less than 32, it indicates that the corresponding space is free space fragmentation.
[0054] In this embodiment, the degree of free space fragmentation of a segment is represented by the free space fragmentation coefficient f, the calculation process of which is shown in Algorithm 1. The specific process is as follows:
[0055] (1) Lines 3-6: Make a judgment. Free space larger than 128KB (with greater than or equal to 32 consecutive zeros in the valid bitmap) is not considered as free space fragmentation (Lines 3-6);
[0056] (2) Lines 7-11: Calculate f. Based on the size of the free space fragments, there are several consecutive zeros in the valid bitmap, denoted as X. There are n fragments in a segment. The sum of 1 / X of n fragments is calculated. The larger f is, the more discrete the free space is and the more serious the degree of free space fragmentation is.
[0057] Because floating-point operations are not recommended in the kernel, the free space fragmentation degree f is calculated by multiplying it by 16002 (i.e., 126*127) times, so that f is a positive integer, and free space fragments from 1 to 127KB have unique f values. Among them, multiplying by 127 (i.e., 128-1) is for rounding, and multiplying by 126 (i.e., 128-2) times is for quickly distinguishing free space fragments of different sizes. For example, the f of a 127KB free space fragment is 126, i.e., The f of a 126KB free space fragment is 127, that is, The free space fragmentation coefficient f can be used not only to calculate the free space fragmentation degree of F2FS, but also to calculate the free space fragmentation degree of other file systems.
[0058] Based on the above analysis, in this embodiment, the calculation formula of the free space fragmentation coefficient f is:
[0059]
[0060] Among them, n represents the number of fragments in the segment, i represents the fragment sequence number, and X i Indicates the number of logical blocks contained in the i-th fragment. The larger the free space fragmentation coefficient of a segment, the more serious the degree of free space fragmentation of the segment. After recycling the segment, the free space fragmentation in the segment can be effectively reduced.
[0061]
[0062] Based on the above calculation formula of free space fragmentation coefficient, Figure 1 In the example, the free space fragmentation coefficient of segment a is That is 128016; the free space fragmentation coefficient of segment b is That is 32004; the free space fragmentation coefficient of segment c is That is 8001. The most serious free space fragmentation is segment a, which has the largest free space fragmentation coefficient. The free space fragmentation degree can be quickly distinguished based on the free space fragmentation coefficients of the three segments.
[0063] This embodiment considers the degree of free space fragmentation when determining segments to be cleaned. Therefore, the garbage collection method provided by this embodiment is a free space fragmentation-aware garbage collection method (FAGC). This embodiment also considers the hotness and coldness of data in the segment and the proportion of inactive space when calculating the segment migration overhead to determine the segments to be cleaned. The specific calculation process is shown in Algorithm 2.
[0064] In this embodiment, the coolness of the data in a segment is represented by the age of the segment, and the calculation formula of age is:
[0065]
[0066] Among them, max_mtime represents the maximum update time of a segment in a log-structured file system, mtime represents the update time of the current candidate segment, and total_time represents the total time, that is, the difference between the maximum update time and the minimum update time. The older the segment, the colder the data on the segment.
[0067] In this embodiment, the calculation formula for the non-effective space ratio of a segment is:
[0068]
[0069] Among them, u represents the non-valid space ratio of the segment, vblocks represents the number of logical blocks storing valid data in the segment, and tblocks represents the total number of logical blocks contained in the segment. The larger the non-valid space ratio of the segment, the more free space is obtained after the segment is recycled.
[0070] Optionally, in this embodiment, when performing garbage collection, the candidate segment selected is the partial segment with the greatest degree of free space fragmentation; in some other embodiments of the present invention, the candidate segment selected may also be the partial segment with the highest data coolness, or the candidate segment selected may be the partial segment with the highest proportion of non-valid space.
[0071] When calculating the migration overhead of valid data in a segment based on the segment's free space fragmentation coefficient f, age age, and non-valid space ratio u, we refer to the weight of age in traditional background GC. In Algorithm 2, the weight of age_weight is set to 40. The weight f_weight of the free space fragmentation coefficient f is the same as the weight of age, so the weight of the non-valid space ratio u in the segment is 20.
[0072] The calculation formula for the segment migration cost is:
[0073] cost=UINT_MAX-10000*(f*f_weight+age*age_weight+u*u_weight)
[0074] Among them, cost represents the migration cost of the segment, f_weight, age_weight and u_weight represent the weights of the free space fragmentation coefficient f, age age and non-valid space ratio u respectively, f_weight+age_weight+u_weight=100; UNIT_MAX is a preset maximum value. In this embodiment, UNIT_MAX is specifically the largest unsigned integer value in the system, so that continuous free space can be obtained with the minimum migration cost. Age, u and f are all normalized during calculation (lines 2-4) so that the migration cost will not be affected by a single factor.
[0075]
[0076]
[0077] Considering that the data in segments with similar age have similar hot and cold degrees and similar expiration times, in order to effectively reduce free space fragmentation, as a preferred implementation method, in this embodiment, the target segment selected is the segment with the closest age to the segment to be cleaned. During the specific migration process, the valid data in the segment to be cleaned will be written one by one to the invalid blocks on the target segment through thread log writing. When performing garbage collection in traditional F2FS, when migrating valid data on the segment to be cleaned, the log structure writing method will occupy a new segment, such as Figure 3 As shown; the FAGC provided by this embodiment uses a thread log write method to directly write to the invalid area on the target segment, without occupying new free segments. Therefore, compared with the traditional F2FS, the garbage collection method for log-structured file systems provided by this embodiment can minimize the free space fragmentation of the target segment. It is easy to understand that when the currently selected target segment is not large enough to accommodate the valid data in the segment to be cleaned, the segment closest in age to the segment to be cleaned can be selected to migrate the valid data in the segment to be cleaned.
[0078] Example 2:
[0079] A computer-readable storage medium includes a stored computer program. When the computer program is executed by a processor, the device where the computer-readable storage medium is located is controlled to execute the garbage collection method for a log-structured file system provided in the above-mentioned embodiment 1.
[0080] It will be easily understood by those skilled in the art that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A garbage collection method for a log-structured file system, characterized in that: include: Filter out some segments that need to be cleaned as candidate segments; For each candidate segment, the migration cost of migrating valid data in the candidate segment is calculated, and the candidate segment with the lowest migration cost is selected as the segment to be cleaned. The migration cost of a segment is inversely correlated with the weighted sum of the segment's free space fragmentation level, data coolness, and the proportion of ineffective space. Selecting a target segment for the cleaned segment, migrating valid data in the cleaned segment to the target segment, and reclaiming the space of the cleaned segment to complete garbage collection; The degree of free space fragmentation of a segment is measured by the free space fragmentation factor f Characterization, and free space fragmentation coefficient f The calculation formula is: The coolness of the data in a segment is determined by the age of the segment. age Characterization and age age The calculation formula is: The calculation formula for the non-effective space ratio of a segment is: in, n Indicates the number of fragments in the segment, i Indicates the fragment number, X i Indicates the i The number of logical blocks contained in each fragment; m Indicates the free space fragmentation threshold, which is less than m KB of space is free space fragment; max_mtime represents the maximum update time of a segment in the log-structured file system, mtime Indicates the update time of the current candidate segment, total_time Indicates the total time; u Indicates the non-effective space ratio of the segment, vblocks Indicates the number of logical blocks in the segment that store valid data. tblocks Indicates the total number of logical blocks contained in the segment.
2. The garbage collection method for a log-structured file system according to claim 1, wherein: m = 128。 3. The garbage collection method for a log-structured file system according to claim 1, wherein: The calculation formula for the segment migration cost is: in, cost represents the migration cost of the segment, f_weight 、 age_weight and u_weight Represents the free space fragmentation coefficient f ,age age and ineffective space ratios u The weight of f_weight + age_weight + u_weight =100, UNIT_MAX is the preset maximum value.
4. The garbage collection method for a log-structured file system according to claim 1, wherein: The target segment is the segment closest in age to the cleaned segment.
5. The garbage collection method for a log-structured file system according to claim 1 or 2, wherein: The selected candidate segment is a segment with the greatest degree of free space fragmentation, or the selected candidate segment is a segment with the highest data coolness, or the selected candidate segment is a segment with the highest proportion of non-valid space.
6. A computer-readable storage medium, characterized in that The invention comprises a stored computer program, which, when executed by a processor, controls the device where the computer-readable storage medium is located to execute the garbage collection method for a log-structured file system according to any one of claims 1 to 5.
Citation Information
Patent Citations
Trash recycling method for log file system on basis of repeated data deleting
CN107391774A
Heat-based log structure file system data management method
CN111913924A