From: Dave Chen <davechen@synology.com>
To: dsterba@suse.cz
Cc: cccheng@synology.com, davechen@synology.com, dsterba@suse.com,
linux-btrfs@vger.kernel.org, robbieko@synology.com
Subject: Re: [PATCH] btrfs: fix unnecessary flush on close when truncating zero-sized files
Date: Tue, 24 Mar 2026 13:40:39 +0800 [thread overview]
Message-ID: <20260324054039.887316-1-davechen@synology.com> (raw)
In-Reply-To: <20260323140748.GK5735@twin.jikos.cz>
On Mon, Mar 23, 2026 at 03:07:48PM +0100, David Sterba wrote:
> 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.
Yes, this comes from a real workload. We have a backup service that
creates temporary files via mkstemp(), closes them, and later reopens
them with O_TRUNC for writing. The O_TRUNC is defensive -- the file is
always empty at that point, but the temp file creation and usage are in
separate components, so removing it from userspace isn't straightforward.
This pattern repeats for a large number of files per backup job, and
each close() triggers an unnecessary filemap_flush().
When oldsize is already 0, the flag provides no protection -- there is
no data being truncated away, so the filemap_flush() on close serves
no purpose. The fix simply makes the condition match what the comment
already describes.
Thanks.
Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.
next prev parent reply other threads:[~2026-03-24 5:40 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
2026-03-24 5:39 ` Dave Chen
2026-03-24 5:40 ` Dave Chen [this message]
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=20260324054039.887316-1-davechen@synology.com \
--to=davechen@synology.com \
--cc=cccheng@synology.com \
--cc=dsterba@suse.com \
--cc=dsterba@suse.cz \
--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