Skip to contentSkip to conversation

f2fs: skip f2fs_preallocate_blocks() for overwrite case

PATCH In review Chao Yu 2 participants 3 messages Feb 4, 2022 – Feb 8, 2022 F2FS file system

lore
Share & tools
lore

Chao Yu

author maintainer
#0 lore raw

PATCH v2 1/1 f2fs: skip f2fs_preallocate_blocks() for overwrite case

There is potential hangtask happened during swapfile's writeback:

- loop_kthread_worker_fn - do_checkpoint
- kthread_worker_fn
- loop_queue_work
- lo_rw_aio
- f2fs_file_write_iter
- f2fs_preallocate_blocks
- f2fs_map_blocks
- down_write
- down_read
- rwsem_down_read_slowpath
- schedule

One cause is f2fs_preallocate_blocks() will always be called no matter the physical block addresses are allocated or not.

This patch tries to check whether block addresses are all allocated with i_size and i_blocks of inode, it's rough because blocks can be allocated beyond i_size, however, we can afford skipping block preallocation in this condition since it's not necessary to do preallocation all the time.

---
v2:
- check overwrite case with i_size and i_blocks roughly.

 fs/f2fs/file.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/f2fs/file.c +10 -0
index cfdc41f87f5d..09565d10611d 100644
@@ -4390,6 +4390,16 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter,
 	int flag;
 	int ret;
 
+	/*
+	 * It tries to check whether block addresses are all allocated,
+	 * it's rough because blocks can be allocated beyond i_size,
+	 * however, we can afford skipping block preallocation since
+	 * it's not necessary all the time.
+	 */
+	if (F2FS_BLK_ALIGN(i_size_read(inode)) ==
+			SECTOR_TO_BLOCK(inode->i_blocks))
+		return 0;
+
 	/* If it will be an out-of-place direct write, don't bother. */
 	if (dio && f2fs_lfs_mode(sbi))
 		return 0;
Signature · 8 lines
2.32.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
maintainer
#1 lore raw
Quoted 35 lines · Chao Yu

There is potential hangtask happened during swapfile's writeback:

- loop_kthread_worker_fn - do_checkpoint
- kthread_worker_fn
- loop_queue_work
- lo_rw_aio
- f2fs_file_write_iter
- f2fs_preallocate_blocks
- f2fs_map_blocks
- down_write
- down_read
- rwsem_down_read_slowpath
- schedule

One cause is f2fs_preallocate_blocks() will always be called no matter the physical block addresses are allocated or not.

This patch tries to check whether block addresses are all allocated with i_size and i_blocks of inode, it's rough because blocks can be allocated beyond i_size, however, we can afford skipping block preallocation in this condition since it's not necessary to do preallocation all the time.

---
v2:
- check overwrite case with i_size and i_blocks roughly.

 fs/f2fs/file.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/f2fs/file.c +0 -0
index cfdc41f87f5d..09565d10611d 100644
@@ -4390,6 +4390,16 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter,
 	int flag;

fs/f2fs/file.c static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter, · line 4400

Quoted 10 lines
fs/f2fs/file.c +8 -0
 	int ret;
 
+	/*
+	 * It tries to check whether block addresses are all allocated,
+	 * it's rough because blocks can be allocated beyond i_size,
+	 * however, we can afford skipping block preallocation since
+	 * it's not necessary all the time.
+	 */
+	if (F2FS_BLK_ALIGN(i_size_read(inode)) ==
+			SECTOR_TO_BLOCK(inode->i_blocks))

Do we count i_blocks only for data?

Quoted 7 lines
fs/f2fs/file.c +2 -0
+		return 0;
+
 	/* If it will be an out-of-place direct write, don't bother. */
 	if (dio && f2fs_lfs_mode(sbi))
 		return 0;
Signature · 1 line
2.32.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#2 lore raw
Quoted 38 lines · Jaegeuk Kim
Quoted 37 lines · Chao Yu

There is potential hangtask happened during swapfile's writeback:

- loop_kthread_worker_fn - do_checkpoint
- kthread_worker_fn
- loop_queue_work
- lo_rw_aio
- f2fs_file_write_iter
- f2fs_preallocate_blocks
- f2fs_map_blocks
- down_write
- down_read
- rwsem_down_read_slowpath
- schedule

One cause is f2fs_preallocate_blocks() will always be called no matter the physical block addresses are allocated or not.

This patch tries to check whether block addresses are all allocated with i_size and i_blocks of inode, it's rough because blocks can be allocated beyond i_size, however, we can afford skipping block preallocation in this condition since it's not necessary to do preallocation all the time.

---
v2:
- check overwrite case with i_size and i_blocks roughly.

  fs/f2fs/file.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
fs/f2fs/file.c +0 -0
index cfdc41f87f5d..09565d10611d 100644
@@ -4390,6 +4390,16 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter,
  	int flag;
  	int ret;
 
Quoted 10 lines

fs/f2fs/file.c static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter, · line 4400

Quoted 8 lines
fs/f2fs/file.c +8 -0
+	/*
+	 * It tries to check whether block addresses are all allocated,
+	 * it's rough because blocks can be allocated beyond i_size,
+	 * however, we can afford skipping block preallocation since
+	 * it's not necessary all the time.
+	 */
+	if (F2FS_BLK_ALIGN(i_size_read(inode)) ==
+			SECTOR_TO_BLOCK(inode->i_blocks))

Do we count i_blocks only for data?

Oops, it seems it's not...

Needs to introduce another function to calculate node block count based on i_size?

Thanks,

Quoted 8 lines
Quoted 8 lines
fs/f2fs/file.c +2 -0
+		return 0;
+
  	/* If it will be an out-of-place direct write, don't bother. */
  	if (dio && f2fs_lfs_mode(sbi))
  		return 0;
Signature · 1 line
2.32.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel