File system fragmentation method and related devices

By obtaining and using the superblock information and disk block bitmap of the file system for kernel-state fragmentation processing, the problem of low fragmentation efficiency in the existing technology is solved, and fast and efficient disk fragmentation is achieved.

CN114996235BActive Publication Date: 2025-07-08YULONG COMPUTER TELECOMM SCI (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210760308.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-30
Publication Date
2025-07-08
Estimated Expiration
2042-06-30

AI Technical Summary

Technical Problem

The existing file system fragmentation method is inefficient, especially when there are fewer continuous blank disk blocks in the later stage, the reading and writing speed of copying and deletion is slow, resulting in inefficient fragmentation.

Method used

By obtaining the super block information of the preset disk partition of the file system, obtaining the pre-written disk fragmentation state, and performing kernel-state fragmentation processing of the pre-set disk partition according to the disk fragmentation state, and using the disk block bitmap for assignment operations to achieve the required disk fragmentation state quickly.

Benefits of technology

It improves the speed and efficiency of fragmentation, and can complete the required disk fragmentation state in milliseconds, avoiding the slow reading and writing speed caused by multiple copy and deletion operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114996235B_ABST
    Figure CN114996235B_ABST
Patent Text Reader

Abstract

The present application discloses a file system fragmentation method, a file system fragmentation device, and a computer-readable storage medium, which are used to perform high-efficiency fragmentation processing on a preset disk partition of a file system to obtain a fragmented file system. The file system fragmentation method of the present application includes: obtaining superblock information of a preset disk partition of the file system, where the preset disk partition includes consecutively arranged disk block groups, and the disk block groups include consecutively arranged disk blocks, and the superblock information is used to describe the fragmentation state of the preset disk partition; obtaining the disk fragmentation state pre-written in the superblock information; and performing fragmentation processing on the preset disk partition according to the disk fragmentation state to obtain a fragmented file system. Performing fragmentation processing on the preset disk partition according to the disk fragmentation state to obtain a fragmented file system can quickly reach the required disk fragmentation state, improve the fragmentation speed, and have a relatively high fragmentation efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of file system fragmentation, and more specifically, to a file system fragmentation method, a file system fragmentation device, and a computer-readable storage medium. Background Art

[0002] To simulate the file system fragmentation situation, it is necessary to fragment the file system to the required disk fragmentation state through fragmentation software, and then evaluate the storage performance of the file system in this disk fragmentation state.

[0003] The existing method for file system fragmentation is to first write the target file into continuously arranged disk blocks in a preset disk partition of the file system in a loop, and then delete the target file. After multiple copy-delete operations, the first disk block and the second disk block can be obtained, where the first disk block is the disk block where the target file is written, and the second disk block is a blank disk block, so that the first disk block and the second disk block present an arrangement corresponding to the required disk fragmentation state, thereby achieving the purpose of file system fragmentation.

[0004] However, when using this user-mode file system fragmentation method to fragment the file system to the later stage, there are fewer continuous blank disk blocks. To achieve the preset fragmentation state, there will be more read-write requests involving copy-delete, and the read-write speed involving copy-delete is slower, resulting in lower fragmentation efficiency. Summary of the Invention

[0005] The embodiments of the present application provide a file system fragmentation method, a file system fragmentation device, and a computer-readable storage medium, which can perform high-efficiency fragmentation processing on a preset disk partition of the file system to obtain a fragmented file system.

[0006] In a first aspect, the embodiments of the present application provide a file system fragmentation method, including:

[0007] Obtain the superblock information of a preset disk partition of the file system; wherein the preset disk partition includes continuously arranged disk block groups, the disk block groups include continuously arranged disk blocks, and the superblock information is used to describe the fragmentation state of the preset disk partition;

[0008] Obtain the disk fragmentation state pre-written in the superblock information;

[0009] Perform fragmentation processing on the preset disk partition according to the disk fragmentation state to obtain a fragmented file system.

[0010] Optionally, the obtaining the superblock information of a preset disk partition of the file system includes:

[0011] Traverse the linked list according to the mount point name of the preset disk partition to determine the mount structure of the preset disk partition;

[0012] Read the virtual file system mount structure from the mount structure;

[0013] Read the superblock information from the virtual file system mount structure.

[0014] Optionally, the superblock information includes the disk block bitmap of the disk block group. Before obtaining the disk fragmentation state pre-written in the superblock information, the method further includes:

[0015] Obtain the disk fragmentation state;

[0016] Perform an assignment process on the disk block bitmap according to the disk fragmentation state to write the disk fragmentation state into the superblock information.

[0017] Optionally, the performing an assignment process on the disk block bitmap according to the disk fragmentation state includes:

[0018] Calculate the number N of disk block groups according to the superblock information, where N is greater than or equal to 1;

[0019] Determine that the number of disk block bitmaps is N according to the number N of disk block groups;

[0020] Perform an assignment process on the N disk block bitmaps according to the disk fragmentation state.

[0021] Optionally, the superblock information includes the total number of disk blocks in the preset disk partition and the number of disk blocks in the disk block group;

[0022] The calculating the number N of disk blocks according to the superblock information includes:

[0023] Determine the ratio of the total number of disk blocks in the preset disk partition to the number of disk blocks in the disk block group as the number N of disk block groups.

[0024] Optionally, the performing an assignment process on the N disk block bitmaps according to the disk fragmentation state includes:

[0025] Determine a first disk block and a second disk block according to the disk fragmentation state; where the first disk block is the disk block for writing the target file, and the second disk block is a blank disk block;

[0026] Assign the bit corresponding to the first disk block in the N disk block bitmaps to 1;

[0027] Assign the bit corresponding to the second disk block in the N disk block bitmaps to 0.

[0028] Optionally, the first disk block and the second disk block are arranged alternately.

[0029] In a second aspect, an embodiment of the present application provides a file fragmentation device, including:

[0030] An acquisition unit, configured to acquire superblock information of a preset disk partition of a file system; wherein the preset disk partition includes a continuously arranged disk block group, the disk block group includes continuously arranged disk blocks, and the superblock information is used to describe the fragmentation state of the preset disk partition;

[0031] The acquisition unit is further configured to acquire the disk fragmentation state pre-written in the superblock information;

[0032] A fragmentation unit, configured to perform fragmentation processing on the preset disk partition according to the disk fragmentation state to obtain a fragmented file system.

[0033] In a third aspect, an embodiment of the present application provides a file system fragmentation device, including:

[0034] A central processing unit, a memory;

[0035] The memory is a transient storage memory or a persistent storage memory;

[0036] The central processing unit is configured to communicate with the memory and execute instruction operations in the memory to execute the foregoing file system fragmentation method.

[0037] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, the computer-readable storage medium includes instructions, when the instructions run on a computer, the computer is caused to execute the foregoing file system fragmentation method.

[0038] In a fifth aspect, an embodiment of the present application provides a computer program product including instructions, when the computer program product runs on a computer, the computer is caused to execute the foregoing file system fragmentation method.

[0039] As can be seen from the above technical solutions, a file system fragmentation method provided by the present application has the following advantages: The kernel-mode file system fragmentation method provided by the present application can acquire superblock information of a preset disk partition of a file system, acquire the disk fragmentation state pre-written in the superblock information, perform fragmentation processing on the preset disk partition according to the disk fragmentation state to obtain a fragmented file system, can quickly reach the required disk fragmentation state, improve the fragmentation speed, and has a higher fragmentation efficiency. Description of the Drawings

[0040] Figure 1 Flow diagram of a file system fragmentation method disclosed in an embodiment of the present application;

[0041] Figure 2 Flow diagram of another file system fragmentation method disclosed in an embodiment of the present application;

[0042] Figure 3 Schematic diagram of the correspondence between disk blocks and bits in a disk block bitmap disclosed in an embodiment of the present application;

[0043] Figure 4 Schematic diagram of the arrangement of disk blocks with a disk bitmap of 10101010 disclosed in an embodiment of the present application;

[0044] Figure 5 Schematic diagram of the arrangement of disk blocks with a disk bitmap of 11110000 disclosed in an embodiment of the present application;

[0045] Figure 6 Schematic diagram of a 128G file system with blank disk blocks arranged continuously disclosed in an embodiment of the present application;

[0046] Figure 7 Schematic diagram of a 128G file system in which all disk blocks are circularly written to a target file disclosed in an embodiment of the present application;

[0047] Figure 8 Schematic diagram of a 128G file system in a fragmented state with the first disk block and the second disk block arranged alternately disclosed in an embodiment of the present application;

[0048] Figure 9 Schematic diagram of a 180G file system in which a 100G large file is statically filled disclosed in an embodiment of the present application;

[0049] Figure 10 Schematic diagram of a 128G file in which a target file is circularly written after a 100G large file is statically filled as disclosed in an embodiment of the present application;

[0050] Figure 11 Schematic diagram of a 128G file system in a fragmented state with the first disk block and the second disk block arranged alternately after a 100G large file is filled disclosed in an embodiment of the present application;

[0051] Figure 12 Schematic diagram of the relationship between disk blocks and pages disclosed in an embodiment of the present application;

[0052] Figure 13Schematic diagram of the time required for a 1G storage space to reach a disk fragmentation state where the first disk block and the second disk block are alternately arranged through multiple copy and delete operations in the embodiments of the present application;

[0053] Figure 14 Schematic diagram of the structure of a file system fragmentation device disclosed in the embodiments of the present application;

[0054] Figure 15 Schematic diagram of the structure of another file system fragmentation device disclosed in the embodiments of the present application;

[0055] Figure 16 Schematic diagram of the structure of yet another file system fragmentation device disclosed in the embodiments of the present application. Detailed implementation manners

[0056] The embodiments of the present application provide a file system fragmentation method, a file system fragmentation device, and a computer-readable storage medium, which can perform high-efficiency fragmentation processing on a preset disk partition of a file system to obtain a fragmented file system.

[0057] Please refer to Figure 1 , Figure 1 which is a flowchart of a file system fragmentation method disclosed in the embodiments of the present application. The method includes:

[0058] 101. Obtain the superblock information of the preset disk partition of the file system; the preset disk partition includes continuously arranged disk block groups, and the disk block groups include continuously arranged disk blocks. The superblock information is used to describe the fragmentation state of the preset disk partition.

[0059] In this embodiment, when performing file system fragmentation, the superblock information of the preset disk partition of the file system can be obtained; the preset disk partition includes continuously arranged disk block groups, and the disk block groups include continuously arranged disk blocks. The superblock information is used to describe the fragmentation state of the preset disk partition.

[0060] 102. Obtain the disk fragmentation state pre-written in the superblock information.

[0061] After obtaining the superblock information of the preset disk partition of the file system, the disk fragmentation state pre-written in the superblock information can be obtained. It can be understood that the pre-written disk fragmentation state can be the disk fragmentation state that the user wants the disk partition of the file system to reach, and the superblock information can pre-write this disk fragmentation state.

[0062] 103. Perform fragmentation processing on the preset disk partition according to the disk fragmentation state to obtain a fragmented file system.

[0063] After obtaining the disk fragmentation status pre-written in the superblock information, the preset disk partition can be fragmented according to the disk fragmentation status to obtain a fragmented file system. It can be understood that the fragmentation method can be in the way of filling the target file, or other fragmentation methods, which are not specifically limited here.

[0064] In the embodiment of the present application, it is a file system fragmentation method in the kernel state. It can obtain the superblock information of the preset disk partition of the file system, obtain the disk fragmentation status pre-written in the superblock information, and fragment the preset disk partition according to the disk fragmentation status to obtain a fragmented file system, which can quickly reach the required disk fragmentation status, improve the fragmentation speed, and have a higher fragmentation efficiency.

[0065] In the embodiment of the present application, there are various methods for fragmenting the preset disk partition according to the disk fragmentation status. One of them will be described below. For details, please refer to Figure 2 , Figure 2 is a schematic flowchart of another file system fragmentation method disclosed in the embodiment of the present application. The method includes:

[0066] 201. Traverse the linked list according to the mount point name of the preset disk partition to determine the mount structure of the preset disk partition.

[0067] In this embodiment, when performing file system fragmentation, the superblock information of the preset disk partition of the file system can be obtained. The preset disk partition includes continuously arranged disk block groups, and the disk block groups include continuously arranged disk blocks. The superblock information is used to describe the fragmentation status of the preset disk partition. It should be understood that any file system has a superblock information, which records the status information of the disk partition, such as the size of the disk partition, the disk block bitmap of the disk block group, the total number of disk blocks, and the number of disk blocks in the disk block group. Among them, there are various file systems, such as the Fourth extended filesystem (EXT4), the new open-source flash file system (F2FS) designed specifically for NAND-based storage devices, etc., which are not specifically limited here. The file system can be the file system of a mobile phone, or the file system of a tablet, or the file system of other devices, which are not specifically limited here.

[0068] Among them, the way to obtain the superblock information of the preset disk partition of the file system can be to first traverse the linked list according to the mount point name of the preset disk partition, and then determine the mount structure (struct mount structure) of the preset disk partition.

[0069] 202. Read the virtual file system mount structure from the mount structure.

[0070] After determining the mount structure (struct mount structure) of the preset disk partition, the virtual file system mount structure (struct vfsmount structure) can be read from the mount structure (struct mount structure).

[0071] 203. Read the superblock information from the virtual file system mount structure.

[0072] After reading the virtual file system mount structure (struct vfsmount structure), the superblock information can be read from the virtual file system mount structure (struct vfsmount structure). It can be understood that in addition to this method of reading the superblock information, there can also be other methods of reading the superblock information, which are not specifically limited here.

[0073] 204. Obtain the disk fragmentation status.

[0074] The disk fragmentation status can be obtained. Specifically, the way to obtain the disk fragmentation status can be to obtain the disk fragmentation status input by the user, or the disk fragmentation status obtained according to the relevant data input by the user, or other ways to obtain the disk fragmentation status, which are not specifically limited here.

[0075] 205. Determine the number N of disk block groups as the ratio of the total number of disk blocks in the preset disk partition to the number of disk blocks in the disk block group.

[0076] After reading the superblock information, which includes the total number of disk blocks in the preset disk partition and the number of disk blocks in the disk block group, the ratio of the total number of disk blocks in the preset disk partition to the number of disk blocks in the disk block group can be determined as the number N of disk block groups. It can be understood that in addition to this method of determining the number N of disk block groups, there can also be other ways to calculate the number N of disk block groups based on the superblock information, which are not specifically limited here.

[0077] 206. Determine that the number of disk block bitmaps is N according to the number N of disk block groups.

[0078] After determining the number N of disk block groups, the number of disk block bitmaps can be determined to be N according to the number N of disk block groups. It should be understood that one disk block group corresponds to one disk block bitmap. Therefore, the number N of disk block groups is the number of disk block bitmaps. Specifically, the disk block bitmap for each of the N disk block groups can be found in sequence. For example, in "struct ext2_group_desc", find "bg_block_bitmap", and the form of "bg_block_bitmap" can be "__le32 bg_block_bitmap". Here, "struct ext2_group_desc" is one of the disk block groups, and "bg_block_bitmap" is the disk block bitmap of the disk block group "struct ext2_group_desc".

[0079] 207. Determine the first disk block and the second disk block according to the disk fragmentation state; where the first disk block is the disk block written with the target file, the second disk block is the blank disk block, and the first disk block and the second disk block are arranged alternately.

[0080] After obtaining the disk fragmentation state, the first disk block and the second disk block can be determined according to the disk fragmentation state; where the first disk block is the disk block written with the target file, and the second disk block is the blank disk block. It should be understood that in addition to the first disk block and the second disk block being arranged alternately, the disk fragmentation state can also be other arrangement states, which are not specifically limited here. It should be understood that the file system can record the state of whether the disk block is written with the target file or is a blank disk block through the disk block bitmap. Among them, one bit in the disk block bitmap represents the write state of one disk block. 0 represents that the disk block corresponding to this bit has not been written with the target file and is a blank disk block, and the file system has not allocated this disk block yet. 1 represents that the disk block corresponding to this bit has been written with the target file, and the file system has allocated this disk block. For example, for a 128M file system with each disk block size of 4K, there are a total of (128M * 1024) / 4 = 32768 disk blocks, and a total of 32768 bits are required, that is, 32768 / 8 = 4096 bytes are required to record the usage of 32768 disk blocks. Please refer to Figure 3 , Figure 3 This is a schematic diagram of the correspondence between disk blocks and bits in the disk block bitmap disclosed in the embodiments of the present application. Among them, gray represents that a file has been written, and white represents a blank disk block. If "bit 0 = 0", it means that the 0th disk block is a blank disk block and is free and available. If "bit 4 = 1", it means that the 4th disk block has been allocated.

[0081] 208. Assign the bit corresponding to the first disk block in the N disk block bitmaps to 1.

[0082] After determining the first disk block, the bit corresponding to the first disk block in the N disk block bitmaps can be assigned to 1. 1 represents that the first disk block needs to be written to the target file, and the size of the target file is the same as the storage space size of the first disk block. It is worth mentioning that the bits in the disk block bitmap are also used to represent the status of the disk block corresponding to the bit being written to the target file. For example, if the value of the bit is 1, it means that the disk block corresponding to the bit has been written to the target file. If the value of the bit is 0, it means that the disk block corresponding to the bit has not been written to the target file and is a blank disk block. Therefore, if the value of the bit corresponding to a certain disk block is 1, it means that the disk block has been written to the target file. After determining that the disk block is the first disk block, it may not be necessary to repeatedly assign 1. Whether it is necessary to repeatedly assign 1 is not limited here.

[0083] 209. Assign the bit corresponding to the second disk block in the N disk block bitmaps to 0.

[0084] After determining the second disk block, the bit corresponding to the second disk block in the N disk block bitmaps can be assigned to 0. 0 represents that the second disk block needs to clear the file or remain in the state of not being written to the file. It is worth mentioning that if the value of the bit corresponding to a certain disk block is 0, it means that the disk block has not been written to the target file and has not been written to any file, and it is a blank disk block. After determining that the disk block is the second disk block, it may not be necessary to repeatedly assign 0. Whether it is necessary to repeatedly assign 0 is not limited here.

[0085] For example, a disk bitmap is 8 bits. If it is assigned 10101010, the disk fragmentation state of alternating first and second disk blocks can be achieved. Please refer to Figure 4 , Figure 4 FIG. Figure 5 , Figure 5 is a schematic diagram of the disk block arrangement with a disk bitmap of 10101010 disclosed in this application. If it is assigned 11110000, the disk fragmentation state of continuous arrangement of the first disk and continuous arrangement of the second disk can be achieved. Please refer to

[0086] It can be understood that in addition to the above method of assigning values to the N disk block bitmaps according to the disk fragmentation state, it can also be other methods of assigning values to the N disk block bitmaps according to the disk fragmentation state. It is not limited here specifically.

[0087] 210. Obtain the disk fragmentation state pre-written in the superblock information.

[0088] After setting the bit corresponding to the first disk block in the N disk block bitmaps to 1 and setting the bit corresponding to the second disk block in the N disk block bitmaps to 0, the obtained disk fragmentation state is the disk fragmentation state pre-written in the superblock information.

[0089] 211. Fragment the preset disk partition according to the disk fragmentation state to obtain a fragmented file system.

[0090] After obtaining the disk fragmentation state pre-written in the superblock information, the preset disk partition can be fragmented according to the disk fragmentation state to obtain a fragmented file system. The specific method of fragmentation is similar to step 103 of the embodiment shown in Figure 1 and will not be elaborated here specifically.

[0091] In this embodiment, a kernel-mode file system fragmentation method is adopted. The superblock information of the preset disk partition of the file system can be obtained, the disk fragmentation state pre-written in the superblock information can be obtained, the pre-written disk fragmentation state is the required disk fragmentation state, and the preset disk partition can be fragmented according to the disk fragmentation state to obtain a fragmented file system, which can quickly reach the required disk fragmentation state, improve the fragmentation speed, and have a high fragmentation efficiency. By setting some bits of the disk block bitmap to 1 or 0 in the kernel, the operation efficiency of assigning values to the disk bitmap is high, and the required disk fragmentation state can be achieved in milliseconds.

[0092] It can be understood that in various embodiments of the present application, the magnitudes of the sequence numbers of the above steps do not indicate the order of execution. The order of execution of each step should be determined according to its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.

[0093] To facilitate understanding of the beneficial effects of the embodiments of the present application, the differences between the prior art and the file system fragmentation methods of the embodiments of the present application are described below.

[0094] It should be understood that the existing file system fragmentation method is in user mode. It is necessary to copy the target file to the file system. The size of the target file is the disk block size. The target file is cyclically written into the disk blocks of the file system, and then the target file is deleted. After multiple copy and delete operations, the disk fragmentation state in which the first disk block and the second disk block are alternately arranged is achieved. Among them, there are various methods for cyclically writing the target file into the disk blocks of the file system, which are described separately below:

[0095] A: Cyclically write the target file into each disk block of the file system.

[0096] For example, there is a file system with a size of 128G currently, and the size of each disk block is 4K. Please refer to Figure 6 , Figure 6 which is a schematic diagram of a 128G file system with blank disk blocks arranged continuously disclosed in an embodiment of the present application. The blank disk blocks represent that the disk blocks are free and can be allocated by the file system to users. When fragmenting the 128G file system, a 4K-sized file can be circularly written into the file system until each disk block of the file system has been written with a file. Each disk block has been written with a 4K file, and each disk block has been used, and the file system can no longer allocate disk blocks to users. Please refer to Figure 7 , Figure 7 which is a schematic diagram of a 128G file system with all disk blocks circularly written with a target file disclosed in an embodiment of the present application. Then, after deleting the target file and performing multiple copy and delete operations, a file system in a fragmented state with the first disk block and the second disk block arranged alternately can be obtained. Please refer to Figure 8 , Figure 8 which is a schematic diagram of a 128G file system in a fragmented state with the first disk block and the second disk block arranged alternately disclosed in an embodiment of the present application. As can be seen from Figure 8 , there are no continuous blank disk blocks and no continuous available disk blocks.

[0097] B: First, write a large file larger than the disk block size into the continuous blank disk blocks in the file system, and then circularly write the target file into the remaining disk blocks. It can be understood that writing a large file larger than the disk block size into the continuous blank disk blocks in the file system as static filling only requires performing copy and delete operations on the target file for the remaining disk blocks to achieve a disk fragmentation state where the first disk block and the second disk block are arranged alternately in the remaining disk blocks.

[0098] For example, there is a file system with a size of 128G currently, and the size of each disk block is 4K. First, write a large file larger than the disk block size into the continuous blank disk blocks in the file system. The size of the large file is 100G. Please refer to Figure 9 , Figure 9 which is a schematic diagram of a 180G file system statically filled with a 100G large file disclosed in an embodiment of the present application. The middle part in the figure is the filled large file, and the adjacent part is the blank disk blocks. Then, circularly write a 4K-sized target file until each disk block of the entire file system has been written with a file. Please refer to Figure 10 , Figure 10This is a schematic diagram of a 128G file that cyclically writes to a target file after statically filling a 100G large file. Then, perform multiple copy and delete operations on the disk blocks that cyclically write to the 4K target file to achieve a disk fragmentation state where the first disk block and the second disk block are alternately arranged. Please refer to Figure 11 , Figure 11 This is a schematic diagram of a 128G file system in a fragmented state where the first disk block and the second disk block are alternately arranged after filling a 100G large file according to an embodiment of the present application.

[0099] It can be understood that both Method A and Method B can achieve a disk fragmentation state where the first disk block and the second disk block are alternately arranged. Moreover, for Method B compared to Method A, before fragmenting the file system, a large file is statically filled first, and only the remaining disk blocks need to be fragmented, reducing the space that needs to be fragmented. Therefore, compared to Method A, the fragmentation time of Method B is greatly reduced.

[0100] However, whether it is Method A or Method B, the fragmentation efficiency is relatively slow. First of all, for the fragmentation method of multiple copy and delete operations, the situation where blank disk blocks are continuously arranged becomes less and less towards the later stage. The read and write requests involved in subsequent copy and delete operations will increase more and more, and the read and write speed will become slower and slower. For example, assume that the size of each disk block in the file system is 4K, and the largest continuously arranged blank disk block in the file system is 1. When writing a 10M picture, the picture will be scattered and written in 10 * 1024 / 4 = 2560 non - continuously arranged blank disk blocks. Then, reading and writing this picture requires 2560 read and write requests, and the read and write speed is relatively slow. However, if there are 2560 continuously arranged blank disk blocks, only one or a few read and write requests are needed. Therefore, for the fragmentation method of multiple copy and delete operations, the read and write speed will become slower and slower towards the later stage.

[0101] Secondly, the file system reads and writes by page and erases by disk block. Here, the disk block is related to the hardware. Among them, a disk block contains multiple pages. Please refer to Figure 12 , Figure 12A schematic diagram of the relationship between disk blocks and pages disclosed in the embodiments of the present application. In the figure, the large square is a disk block, and the small square is a page. The file system does not support in-place update operations. If there is already data in a page and the page is written again, the entire disk block needs to be erased to write the data. The fragmentation method of multiple copy and delete operations becomes more fragmented as time goes on. After multiple copy and delete operations, some pages in the disk blocks in the file system have data, some pages have no data or contain invalid data. When the file system overwrites the pages with invalid data, since the hardware does not support in-place update, the hardware cannot directly write to this page. The hardware needs to write the data in the page with valid data to other locations, then erase the disk block, and then write the page to be written and the previous page with valid data back to the erased disk block together. The whole process involves steps of migration, erasure, and writing, with many steps, resulting in a significant reduction in performance and a longer time-consuming fragmentation process.

[0102] Furthermore, the file system needs to perform some sorting operations, such as discard and garbage collection (GC). These sorting operations require the use of hardware processing capabilities and occupy the flash bandwidth. The workload of discard, GC, etc. becomes larger as time goes on. The hardware processing capabilities of flash are constant. The fragmentation operation and the sorting operation need to share the hardware processing capabilities, resulting in a longer time-consuming fragmentation process.

[0103] Please refer to Figure 13 , Figure 13 is the time required to reach the disk fragmentation state where the first disk block and the second disk block are alternately arranged after multiple copy and delete operations on 1G of storage space in the embodiments of the present application. It can be understood that aging is fragmentation. As can be seen from Figure 13 , for fragmenting 1G of storage space, the fragmentation time required to reach a fragmentation score of 38 is 17 hours, the fragmentation time required to reach a fragmentation score of 56 is 28 hours, and the fragmentation time required to reach a fragmentation score of 89 is 61 hours. The higher the fragmentation score, the more fragmented the file system is and the more fragmentation time is required. It is easy to understand that for the fragmentation method of the user-mode file system, if the entire file system needs to be fragmented, it may take half a month to a month. If a compromise is made and only part of the storage space is fragmented, the fragmentation time is also long, and the fragmentation state of the entire file system cannot be fully simulated. For the fragmentation method of the user-mode after copy and delete operations, the required fragmentation time is positively correlated with the storage space to be fragmented. The larger the storage space to be fragmented, the more fragmentation time is required. However, in the embodiments of the present application, only the disk block bitmap needs to be assigned, and the fragmentation time required for fragmenting storage spaces of different sizes is basically the same, only taking milliseconds.

[0104] The file system fragmentation method in the embodiments of the present application has been described above. Next, the file system fragmentation device in the embodiments of the present application will be described. Please refer to Figure 14 , an embodiment of the file system fragmentation device in the embodiments of the present application includes:

[0105] An acquisition unit 1401, configured to acquire superblock information of a preset disk partition of the file system; wherein the preset disk partition includes continuously arranged disk block groups, and the disk block groups include continuously arranged disk blocks, and the superblock information is used to describe the fragmentation state of the preset disk partition;

[0106] The acquisition unit 1401 is further configured to acquire the disk fragmentation state pre-written in the superblock information;

[0107] A fragmentation unit 1402, configured to perform fragmentation processing on the preset disk partition according to the disk fragmentation state obtained by the acquisition unit 1401, to obtain a fragmented file system.

[0108] In the embodiments of the present application, it is a file system fragmentation method in the kernel state, which can acquire the superblock information of the preset disk partition of the file system, acquire the disk fragmentation state pre-written in the superblock information, perform fragmentation processing on the preset disk partition according to the disk fragmentation state, and obtain a fragmented file system, which can quickly achieve the preset fragmentation effect and improve the fragmentation speed.

[0109] Next, the file system fragmentation device in the embodiments of the present application will be described in detail. Please refer to Figure 15 , another embodiment of the file system fragmentation device in the embodiments of the present application includes:

[0110] An acquisition unit 1501, configured to acquire superblock information of a preset disk partition of the file system; wherein the preset disk partition includes continuously arranged disk block groups, and the disk block groups include continuously arranged disk blocks, and the superblock information is used to describe the fragmentation state of the preset disk partition;

[0111] The acquisition unit 1501 is further configured to acquire the disk fragmentation state pre-written in the superblock information;

[0112] A fragmentation unit 1502, configured to perform fragmentation processing on the preset disk partition according to the disk fragmentation state obtained by the acquisition unit 1501, to obtain a fragmented file system.

[0113] The obtaining unit 1501 is specifically configured to traverse a linked list according to the mount point name of a preset disk partition, find the struct mount structure of the preset disk partition, read the struct vfsmount structure from the struct mount structure, and read the superblock information from the struct vfsmount structure.

[0114] The file system fragmentation device further includes: an assignment unit 1503,

[0115] The obtaining unit 1501 is specifically configured to obtain the disk fragmentation status;

[0116] The assignment unit 1503 is configured to perform an assignment process on the disk block bitmap according to the disk fragmentation status obtained by the obtaining unit, so as to write the disk fragmentation status into the superblock information.

[0117] The assignment unit 1503 is specifically configured to calculate the number N of disk block groups according to the superblock information, where N is greater than or equal to 1, determine that the number of disk block bitmaps is N according to the number N of disk block groups, and perform an assignment process on the N disk block bitmaps according to the disk fragmentation status.

[0118] The assignment unit 1503 is specifically configured to: the superblock information includes the total number of disk blocks in the preset disk partition and the number of disk blocks in the disk block group, and determine the ratio of the total number of disk blocks in the preset disk partition to the number of disk blocks in the disk block group as the number N of disk block groups.

[0119] The assignment unit 1503 is specifically configured to determine a first disk block and a second disk block according to the disk fragmentation status, where the first disk block is the disk block for writing the target file, and the second disk block is a blank disk block, assign the bit corresponding to the first disk block in the N disk block bitmaps to 1, and assign the bit corresponding to the second disk block in the N disk block bitmaps to 0.

[0120] In this embodiment, each unit of the file system fragmentation device executes the operations of the file system fragmentation device in the foregoing Figure 1 and Figure 2 shown embodiments, and details are not described herein again.

[0121] Next, please refer to Figure 16 , another embodiment of the file system fragmentation device 1600 in the embodiments of the present application includes:

[0122] A central processing unit 1601, a memory 1605, an input / output interface 1604, a wired or wireless network interface 1603, and a power supply 1602;

[0123] The memory 1605 is a transient storage memory or a persistent storage memory;

[0124] The central processing unit 1601 is configured to communicate with the memory 1605 and execute the instruction operations in the memory 1605 to execute the methods in the foregoing Figure 1 and Figure 2 illustrated embodiments.

[0125] An embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium includes instructions that, when run on a computer, cause the computer to execute the methods in the foregoing Figure 1 and Figure 2 illustrated embodiments.

[0126] An embodiment of the present application also provides a computer program product containing instructions that, when the computer program product runs on a computer, cause the computer to execute the methods in the foregoing Figure 1 and Figure 2 illustrated embodiments.

[0127] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices, and units described above can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated herein.

[0128] In several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces, and the indirect couplings or communication connections of the devices or units can be in electrical, mechanical, or other forms.

[0129] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0130] In addition, in each embodiment of the present application, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.

[0131] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of this application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM, read-only memory), random access memories (RAM, random access memory), magnetic disks, or optical discs.

Claims

1. A file system fragmentation method, characterized in that, The method includes: Obtaining superblock information of a preset disk partition of a file system; wherein the preset disk partition includes consecutively arranged disk block groups, the disk block groups include consecutively arranged disk blocks, and the superblock information is used to describe the fragmentation state of the preset disk partition; Obtaining the disk fragmentation state pre-written in the superblock information; Performing fragmentation processing on the preset disk partition according to the disk fragmentation state to obtain a fragmented file system; The superblock information includes a disk block bitmap of the disk block group. Before obtaining the disk fragmentation state pre-written in the superblock information, the method further includes: Obtaining the disk fragmentation state; Performing an assignment process on the disk block bitmap according to the disk fragmentation state to write the disk fragmentation state into the superblock information.

2. The file system fragmentation method according to claim 1, wherein The obtaining of the superblock information of the preset disk partition of the file system includes: Traversing a linked list according to the mount point name of the preset disk partition to determine the mount structure of the preset disk partition; Reading a virtual file system mount structure from the mount structure; Reading the superblock information from the virtual file system mount structure.

3. The file system fragmentation method according to claim 1, wherein, The performing of the assignment process on the disk block bitmap according to the disk fragmentation state includes: Calculating the number N of disk block groups according to the superblock information, where N is greater than or equal to 1; Determining that the number of disk block bitmaps is N according to the number N of disk block groups; Performing an assignment process on the N disk block bitmaps according to the disk fragmentation state.

4. The file system fragmentation method according to claim 3, wherein The superblock information includes the total number of disk blocks in the preset disk partition and the number of disk blocks in the disk block group; The calculating of the number N of disk blocks according to the superblock information includes: Determining the ratio of the total number of disk blocks in the preset disk partition to the number of disk blocks in the disk block group as the number N of disk block groups.

5. The file system fragmentation method according to claim 3, wherein The performing of the assignment process on the N disk block bitmaps according to the disk fragmentation state includes: Determining a first disk block and a second disk block according to the disk fragmentation state; wherein the first disk block is the disk block for writing a target file, and the second disk block is a blank disk block; Assigning the bit corresponding to the first disk block in the N disk block bitmaps to 1; Assigning the bit corresponding to the second disk block in the N disk block bitmaps to 0.

6. The file system fragmentation method according to claim 5, wherein, The first disk block and the second disk block are arranged alternately.

7. A file system fragmentation device, characterized in that, Includes: An obtaining unit for obtaining superblock information of a preset disk partition of a file system; wherein the preset disk partition includes consecutively arranged disk block groups, the disk block groups include consecutively arranged disk blocks, and the superblock information is used to describe the fragmentation state of the preset disk partition; The obtaining unit is further used to obtain the disk fragmentation state pre-written in the superblock information; A fragmentation unit for performing fragmentation processing on the preset disk partition according to the disk fragmentation state to obtain a fragmented file system; The file system fragmentation device further includes: an assignment unit; The obtaining unit is further configured to obtain the disk fragmentation status; The assignment unit is configured to perform an assignment process on the disk block bitmap according to the disk fragmentation status, so as to write the disk fragmentation status into the superblock information.

8. A file system fragmentation device, characterized in that, Comprising: A central processing unit, a memory; The memory is a transient storage memory or a persistent storage memory; The central processing unit is configured to communicate with the memory and execute the instruction operations in the memory to execute the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes instructions that, when run on a computer, cause the computer to execute the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Video recording method and device of digital video recording equipment

    CN104065906A