3 I've updated ext4 online defrag patches.
4 Changes are as followings (Ted pointed 1-4 out before).
5 1. Remove unneeded ioctls and related functions.
8 - EXT4_IOC_RESERVE_BLOCK
9 - EXT4_IOC_BLOCK_RELEASE
10 2. Implement new ioctl (EXT4_IOC_SUPER_INFO) which gets ext4_super_block.
11 3. Remove ext4_defrag_ioctl() not to have a double layer of ioctl's dispatch.
12 4. Fix defrag not to use block reservation in force defrag mode (-f),
13 because the legacy block allocator have been removed from ext4.
14 5. Add permission check to ext4_defrag_fiemap_ino and ext4_defag_move_victim.
15 Because non-permitted file should not be selected as victim file
16 in force defrag mode (-f).
20 - Remove unneeded ioctls.
21 - Add EXT4_IOC_SUPER_INFO which gets ext4_super_block.
22 - Fix defrag not to use block reservation in force defrag mode (-f).
23 - Remove ext4_defrag_ioctl() not to have a double layer of ioctl's dispatch.
26 - Support 1KB and 2KB block size.
27 - Implement EXT4_IOC_FIEMAP_INO which calls ext4_fiemap() for specified inode number
28 instead of EXT4_IOC_EXTENTS_INFO to get extents information.
29 - Merge "JC6-defrag-alloc-contiguous-blks-credit" and
30 "ext4-request-for-blocks-with-ar.excepted_group-1.patch" in the ext4 patch queue
32 - Handle s_dirtyblocks_counter correctly in defrag when delalloc enabled.
33 - Remove unneeded copy_from_user() in EXT4_IOC_GROUP_INFO ioctl. Ted pointed this out.
35 - Create some new functions (ext4_defrag_fill_ar(),
36 ext4_defrag_check_phase() ...) to separate block allocation function,
37 since the phase mode plug into the allocation function isn't good.
38 - Add the description of ext4_defrag() which is main function.
39 - Add the capability check.
42 Outline for ext4 online defragmentation:
43 Ext4 online defrag has the following three functions.
45 no option Solving a single file fragmentation.
46 Single file fragmentation is solved by moving file
47 data to contiguous free blocks.
49 -r Solving a relevant file fragmentation.
50 Relevant file fragmentation could be solved by moving
51 the files under the specified directory close together with
52 the block containing the directory data.
54 -f Solving a free space fragmentation.
55 If there is no contiguous free blocks in the filesystem,
56 the other files are moved to make sufficient space to allocate
57 contiguous blocks for the target file.
61 Address the following items that Ted pointed out before.
62 These are no functional impact.
63 - Rebuild defrag patches construction.
64 (low-level functions will be first)
65 - Move the defrag functions that are related to extents or mballoc
66 to the appropriate files.
67 - Add more descriptions each of defrag functions.
70 * The followings are new ext4 online defrag patches and they consist
71 of ioctl unit except 1-4. Because the EXT4_IOC_DEFRAG is too big for reviewing,
72 I divided it into 4 patches (I'll consider about appropriate construction
73 of defrag patches later).
75 [PATCH 1/9] EXT4_IOC_DEFRAG ioctl and defrag main function
76 - Create the temporary inode and do defrag per
77 defrag_size (defalut 64MB).
79 [PATCH 2/9] Allocate new contiguous blocks with mballoc
80 - Search contiguous free blocks with mutil-block allocation
81 and allocate them for the temporary inode.
83 [PATCH 3/9] Exchange the extents between two inodes
84 - For each page, exchange the extents between the temporary inode
85 and the original inode, and then write them.
87 [PATCH 4/9] Inside extents management and relevant defrag
88 - Merge extents of target inode which is increased by defragmentation.
89 - For relevant defrag, add the goal argument to related functions
90 to allocate data block to the specified offset.
92 [PATCH 5/9] EXT4_IOC_SUPER_INFO ioctl
93 - EXT4_IOC_SUPER_INFO gets super block information on disk.
95 Super block information is necessary for relevant (-r) and force (-f) defrag.
96 Non-root user can't get this information by opening the block device directly,
97 so implement this ioctl newly.
99 [PATCH 6/9] EXT4_IOC_FREE_BLOCKS_INFO ioctl
100 - The EXT4_IOC_FREE_BLOCKS_INFO ioctl gets free extents
101 information of the target block group.
102 This ioctl is used only in the force defrag (-f).
104 ext4_defrag_fblocks_distribution() was renamed as ext4_mb_search_free_extents()
105 and moved into mballoc.c. Because it uses ext4_buddy structure.
107 [PATCH 7/9] EXT4_IOC_FIEMAP_INO ioctl
108 - The EXT4_IOC_FIEMAP_INO is used to get extents information of
109 inode which set to ioctl.
110 The defragger uses this ioctl to check the fragment condition
111 and to get extents information in the specified block group.
113 Andreas Dilger suggested that implement EXT4_IOC_WRAPPER to call fiemap
114 for arbitrary inodes instead of this ioctl.
115 But there is a matter for consideration to use EXT4_IOC_WRAPPER,
116 so I passed up it in this time.
118 [PATCH 8/9] EXT4_IOC_MOVE_VICTIM ioctl
119 - The EXT4_IOC_MOVE_VICTIM moves the victim extents into other block group.
120 Therefore the contiguous free space is made in the target block group.
121 This ioctl is used only in the force defrag (-f).
123 [PATCH 9/9] Online defrag command
124 - The defrag command. Usage is as follows:
125 - Defrag for a single file.
127 - Defrag for all files on ext4.
128 # e4defrag device-name
129 - Put the multiple files closer together.
130 # e4defrag -r directory-name
131 - Defrag for free space fragmentation.
132 # e4defrag -f file-name
134 Any comments are welcome.