f2fs: ro: compress: fix to avoid caching unaligned extent
Chao Yu
maintainerPATCH 1/2 f2fs: ro: compress: fix to avoid caching unaligned extent
Mapping info from dump.f2fs:
i_addr[0x2d] cluster flag [0xfffffffe : 4294967294] i_addr[0x2e] [0x 10428 : 66600] i_addr[0x2f] [0x 10429 : 66601] i_addr[0x30] [0x 1042a : 66602]
f2fs_io fiemap 37 1 /mnt/f2fs/disk-58390c8c.raw
Previsouly, it missed to align fofs and ofs_in_node to cluster_size, result in adding incorrect read extent cache, fix it.
Before:f2fs_update_read_extent_tree_range: dev = (253,48), ino = 5, pgofs = 37, len = 4, blkaddr = 66600, c_len = 3
After:f2fs_update_read_extent_tree_range: dev = (253,48), ino = 5, pgofs = 36, len = 4, blkaddr = 66600, c_len = 3
--- fs/f2fs/compress.c | 10 ++++++---- fs/f2fs/f2fs.h | 6 ++++-- fs/f2fs/node.c | 20 ++++++++++++++------ 3 files changed, 24 insertions(+), 12 deletions(-)
fs/f2fs/compress.c +6 -4
@@ -1841,16 +1841,18 @@ void f2fs_put_page_dic(struct page *page, bool in_task)* check whether cluster blocks are contiguous, and add extent cache entry * only if cluster blocks are logically and physically contiguous. */ -unsigned int f2fs_cluster_blocks_are_contiguous (struct dnode_of_data *dn) +unsigned int f2fs_cluster_blocks_are_contiguous (struct dnode_of_data *dn, +unsigned int ofs_in_node) { -bool compressed =f2fs_data_blkaddr (dn) ==COMPRESS_ADDR ; +bool compressed =data_blkaddr (dn->inode, dn->node_page, + ofs_in_node) ==COMPRESS_ADDR ;int i = compressed ?1 :0 ;block_t first_blkaddr =data_blkaddr (dn->inode, dn->node_page, - dn->ofs_in_node + i); + ofs_in_node + i);for (i +=1 ; i <F2FS_I (dn->inode)->i_cluster_size; i++) {block_t blkaddr =data_blkaddr (dn->inode, dn->node_page, - dn->ofs_in_node + i); + ofs_in_node + i);if (!__is_valid_data_blkaddr (blkaddr))break ;
fs/f2fs/f2fs.h +4 -2
@@ -4307,7 +4307,8 @@ struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc);void f2fs_decompress_end_io (struct decompress_io_ctx *dic,bool failed,bool in_task);void f2fs_put_page_dic (struct page *page,bool in_task); -unsigned int f2fs_cluster_blocks_are_contiguous (struct dnode_of_data *dn); +unsigned int f2fs_cluster_blocks_are_contiguous (struct dnode_of_data *dn, +unsigned int ofs_in_node);int f2fs_init_compress_ctx (struct compress_ctx *cc);void f2fs_destroy_compress_ctx (struct compress_ctx *cc,bool reuse);void f2fs_init_compress_info (struct f2fs_sb_info *sbi);
@@ -4364,7 +4365,8 @@ static inline void f2fs_put_page_dic(struct page *page, bool in_task) {WARN_ON_ONCE (1 ); } -static inline unsigned int f2fs_cluster_blocks_are_contiguous (struct dnode_of_data *dn) {return 0 ; } +static inline unsigned int f2fs_cluster_blocks_are_contiguous ( +struct dnode_of_data *dn,unsigned int ofs_in_node) {return 0 ; }static inline bool f2fs_sanity_check_cluster (struct dnode_of_data *dn) {return false; }static inline int f2fs_init_compress_inode (struct f2fs_sb_info *sbi) {return 0 ; }static inline void f2fs_destroy_compress_inode (struct f2fs_sb_info *sbi) { }
fs/f2fs/node.c +14 -6
@@ -852,21 +852,29 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode)if (is_inode_flag_set (dn->inode,FI_COMPRESSED_FILE ) &&f2fs_sb_has_readonly (sbi)) { -unsigned int c_len =f2fs_cluster_blocks_are_contiguous (dn); +unsigned int cluster_size =F2FS_I (dn->inode)->i_cluster_size; +unsigned int ofs_in_node = dn->ofs_in_node; +pgoff_t fofs = index; +unsigned int c_len;block_t blkaddr; +/* should align fofs and ofs_in_node to cluster_size */ +if (fofs % cluster_size) { + fofs =round_down (fofs, cluster_size); + ofs_in_node =round_down (ofs_in_node, cluster_size); + } + + c_len =f2fs_cluster_blocks_are_contiguous (dn, ofs_in_node);if (!c_len) goto out; - blkaddr =f2fs_data_blkaddr (dn); + blkaddr =data_blkaddr (dn->inode, dn->node_page, ofs_in_node);if (blkaddr ==COMPRESS_ADDR ) blkaddr =data_blkaddr (dn->inode, dn->node_page, - dn->ofs_in_node +1 ); + ofs_in_node +1 );f2fs_update_read_extent_tree_range_compressed (dn->inode, - index, blkaddr, -F2FS_I (dn->inode)->i_cluster_size, - c_len); + fofs, blkaddr, cluster_size, c_len); } out:return 0 ;
Signature · 1 line
2.40.1
Chao Yu
maintainerPATCH 2/2 f2fs: ro: don't start discard thread for readonly image
[ 9299.893835] F2FS-fs (vdd): Allow to mount readonly mode only mount: /mnt/f2fs: WARNING: source write-protected, mounted read-only. root@qemu:/ ps -ef|grep f2fs root 94 2 0 03:46 ? 00:00:00 [kworker/u17:0-f2fs_post_read_wq] root 6282 2 0 06:21 ? 00:00:00 [f2fs_discard-253:48]
There will be no deletion in readonly image, let's skip starting discard thread to save system resources.
--- fs/f2fs/segment.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/f2fs/segment.c +6 -0
@@ -2253,6 +2253,12 @@ int f2fs_start_discard_thread(struct f2fs_sb_info *sbi)struct discard_cmd_control *dcc =SM_I (sbi)->dcc_info;int err =0 ; +if (f2fs_sb_has_readonly (sbi)) { +f2fs_info (sbi, +"Skip to start discard thread for readonly image" ); +return 0 ; + } +if (!f2fs_realtime_discard_enable (sbi))return 0 ;
Signature · 1 line
2.40.1
This series was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 9 lines · On Mon, 26 Feb 2024 15:35:38 +0800 you wrote:
Mapping info from dump.f2fs:
i_addr[0x2d] cluster flag [0xfffffffe : 4294967294] i_addr[0x2e] [0x 10428 : 66600] i_addr[0x2f] [0x 10429 : 66601] i_addr[0x30] [0x 1042a : 66602]
f2fs_iofiemap 37 1/mnt/f2fs/disk-58390c8c.raw[...]
Here is the summary with links:
- [f2fs-dev,1/2] f2fs: ro: compress: fix to avoid caching unaligned extent
https://git.kernel.org/jaegeuk/f2fs/c/4b99ecd30429 - [f2fs-dev,2/2] f2fs: ro: don't start discard thread for readonly image https://git.kernel.org/jaegeuk/f2fs/c/a217f1873ab9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html