From: David Sterba <dsterba@suse.cz>
To: Dave Chen <davechen@synology.com>
Cc: linux-btrfs@vger.kernel.org, dsterba@suse.com,
cccheng@synology.com, robbieko@synology.com
Subject: Re: [PATCH] btrfs: fix unnecessary flush on close when truncating zero-sized files
Date: Mon, 23 Mar 2026 15:07:48 +0100 [thread overview]
Message-ID: <20260323140748.GK5735@twin.jikos.cz> (raw)
In-Reply-To: <20260323034322.105163-1-davechen@synology.com>
On Mon, Mar 23, 2026 at 11:43:22AM +0800, Dave Chen wrote:
> In btrfs_setsize(), when a file is truncated to size 0, the
> BTRFS_INODE_FLUSH_ON_CLOSE flag is unconditionally set to ensure
> pending writes get flushed on close. This flag was designed to protect
> the "truncate-then-rewrite" pattern, where an application truncates a
> file with existing data down to zero and writes new content, ensuring
> the new data reaches disk on close.
>
> However, when a file already has a size of 0 (e.g., a newly created
> file opened with O_CREAT | O_TRUNC), oldsize and newsize are both 0.
> In this case, setting BTRFS_INODE_FLUSH_ON_CLOSE is unnecessary because
> no "good data" was truncated away. The subsequent filemap_flush() in
> btrfs_release_file() then triggers avoidable writeback that disrupts
> the normal delayed writeback batching, adding I/O overhead.
Does this have a measurable impact? Truncating 0 -> 0 without any
intermediate writes could happen but I kind of doubt it's worth
optimizing. I'm not against adding the patch but would like to know if
it's fixing some problem for you. Thanks.
next prev parent reply other threads:[~2026-03-23 14:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 3:43 [PATCH] btrfs: fix unnecessary flush on close when truncating zero-sized files Dave Chen
2026-03-23 14:07 ` David Sterba [this message]
2026-03-24 5:39 ` Dave Chen
2026-03-24 5:40 ` Dave Chen
2026-03-24 15:26 ` David Sterba
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=20260323140748.GK5735@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=cccheng@synology.com \
--cc=davechen@synology.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=robbieko@synology.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