public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, Chao Yu <chao@kernel.org>
Subject: [PATCH v2] f2fs: skip f2fs_preallocate_blocks() for overwrite case
Date: Fri,  4 Feb 2022 17:10:05 +0800	[thread overview]
Message-ID: <20220204091005.49407-1-chao@kernel.org> (raw)

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.

Signed-off-by: Chao Yu <chao@kernel.org>
---
v2:
- check overwrite case with i_size and i_blocks roughly.
 fs/f2fs/file.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index cfdc41f87f5d..09565d10611d 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -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;
-- 
2.32.0


             reply	other threads:[~2022-02-04  9:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-04  9:10 Chao Yu [this message]
2022-02-07 19:16 ` [PATCH v2] f2fs: skip f2fs_preallocate_blocks() for overwrite case Jaegeuk Kim
2022-02-08  1:41   ` Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220204091005.49407-1-chao@kernel.org \
    --to=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox