mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Zhiguo Niu <zhiguo.niu@unisoc.com>,
	daehojeong@google.com, jaegeuk@kernel.org
Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, niuzhiguo84@gmail.com,
	ke.wang@unisoc.com, Hao_hao.Wang@unisoc.com
Subject: Re: [RFC PATCH] f2fs: remove some redundant flow about FI_ATOMIC_DIRTIED
Date: Wed, 26 Mar 2025 17:26:18 +0800	[thread overview]
Message-ID: <e4fb11ea-a97b-4ba0-aa28-f6f93e5a6134@kernel.org> (raw)
In-Reply-To: <1742978761-16264-1-git-send-email-zhiguo.niu@unisoc.com>

On 3/26/25 16:46, Zhiguo Niu wrote:
> Commit fccaa81de87e ("f2fs: prevent atomic file from being dirtied before commit")
> adds the processing of FI_ATOMIC_DIRTIED in the following two positions,
> [1]
> f2fs_commit_atomic_write
>  - __f2fs_commit_atomic_write
>   - sbi->committed_atomic_block += fi->atomic_write_cnt;
>   - set_inode_flag(inode, FI_ATOMIC_COMMITTED);
>   - if (is_inode_flag_set(inode, FI_ATOMIC_DIRTIED)) {
>   -    clear_inode_flag(inode, FI_ATOMIC_DIRTIED);
>   -    f2fs_mark_inode_dirty_sync(inode, true);
>   - }
> [2]
> f2fs_abort_atomic_write
>   - if (is_inode_flag_set(inode, FI_ATOMIC_DIRTIED)) {
>   -    clear_inode_flag(inode, FI_ATOMIC_DIRTIED);
>   -    f2fs_mark_inode_dirty_sync(inode, true);
>   - }
> 
> but [1] seems to be redundant:
> The atomic file flag FI_ATOMIC_FILE is still set here, so f2fs_mark_inode_dirty_sync
> still does not set the dirty state to vfs. If FI_ATOMIC_DIRTIED was originally set
> when atomic file is committing, then FI_ATOMIC_DIRTIED is just cleared here, and
> then do the repeating action of setting FI_ATOMIC_DIRTIED?
> So is it enough to do this only in [2]?

Hi Zhiguo,

I checked the code again, finally, I got this, could you please take
a look?

Ping Daeho as well.

Subject: [PATCH] f2fs: fix to set atomic write status more clear

1. After we start atomic write in a database file, before committing
all data, we'd better not set inode w/ vfs dirty status to avoid
redundant updates, instead, we only set inode w/ atomic dirty status.

2. After we commit all data, before committing metadata, we need to
clear atomic dirty status, and set vfs dirty status to allow vfs flush
dirty inode.

Signed-off-by: Chao Yu <chao@kernel.org>
---
 fs/f2fs/inode.c   |  4 +++-
 fs/f2fs/segment.c | 10 ++++++----
 fs/f2fs/super.c   |  4 +++-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 5c8634eaef7b..f5991e8751b9 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -34,7 +34,9 @@ void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync)
 	if (f2fs_inode_dirtied(inode, sync))
 		return;

-	if (f2fs_is_atomic_file(inode))
+	/* only atomic file w/ FI_ATOMIC_COMMITTED can be set vfs dirty */
+	if (f2fs_is_atomic_file(inode) &&
+			!is_inode_flag_set(inode, FI_ATOMIC_COMMITTED))
 		return;

 	mark_inode_dirty_sync(inode);
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index dc360b4b0569..28659a71891a 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -376,10 +376,12 @@ static int __f2fs_commit_atomic_write(struct inode *inode)
 	} else {
 		sbi->committed_atomic_block += fi->atomic_write_cnt;
 		set_inode_flag(inode, FI_ATOMIC_COMMITTED);
-		if (is_inode_flag_set(inode, FI_ATOMIC_DIRTIED)) {
-			clear_inode_flag(inode, FI_ATOMIC_DIRTIED);
-			f2fs_mark_inode_dirty_sync(inode, true);
-		}
+
+		f2fs_bug_on(sbi, !is_inode_flag_set(inode, FI_ATOMIC_DIRTIED));
+
+		/* clear atomic dirty status and set vfs dirty status */
+		clear_inode_flag(inode, FI_ATOMIC_DIRTIED);
+		f2fs_mark_inode_dirty_sync(inode, true);
 	}

 	__complete_revoke_list(inode, &revoke_list, ret ? true : false);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 9a42a1323f42..a5cc9f6ee16a 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1532,7 +1532,9 @@ int f2fs_inode_dirtied(struct inode *inode, bool sync)
 	}
 	spin_unlock(&sbi->inode_lock[DIRTY_META]);

-	if (!ret && f2fs_is_atomic_file(inode))
+	/* if atomic write is not committed, set inode w/ atomic dirty */
+	if (!ret && f2fs_is_atomic_file(inode) &&
+			!is_inode_flag_set(inode, FI_ATOMIC_COMMITTED))
 		set_inode_flag(inode, FI_ATOMIC_DIRTIED);

 	return ret;
-- 
2.48.1


> 
> Cc: Daeho Jeong <daehojeong@google.com>
> Fixes: fccaa81de87e ("f2fs: prevent atomic file from being dirtied before commit")
> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
> ---
>  fs/f2fs/segment.c | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 396ef71..d4ea3af 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -376,10 +376,6 @@ static int __f2fs_commit_atomic_write(struct inode *inode)
>  	} else {
>  		sbi->committed_atomic_block += fi->atomic_write_cnt;
>  		set_inode_flag(inode, FI_ATOMIC_COMMITTED);
> -		if (is_inode_flag_set(inode, FI_ATOMIC_DIRTIED)) {
> -			clear_inode_flag(inode, FI_ATOMIC_DIRTIED);
> -			f2fs_mark_inode_dirty_sync(inode, true);
> -		}
>  	}
>  
>  	__complete_revoke_list(inode, &revoke_list, ret ? true : false);


  reply	other threads:[~2025-03-26  9:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-26  8:46 Zhiguo Niu
2025-03-26  9:26 ` Chao Yu [this message]
2025-03-26 10:51   ` Zhiguo Niu
2025-03-26 12:10     ` Chao Yu
2025-03-26 18:51       ` [f2fs-dev] " Daeho Jeong
2025-03-27  3:21         ` 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=e4fb11ea-a97b-4ba0-aa28-f6f93e5a6134@kernel.org \
    --to=chao@kernel.org \
    --cc=Hao_hao.Wang@unisoc.com \
    --cc=daehojeong@google.com \
    --cc=jaegeuk@kernel.org \
    --cc=ke.wang@unisoc.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=niuzhiguo84@gmail.com \
    --cc=zhiguo.niu@unisoc.com \
    /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

all inboxes | Powered by JetHome®