mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <slava@dubeyko.com>
To: glaubitz@physik.fu-berlin.de, frank.li@vivo.com
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	vdubeyko@coreweave.com, Viacheslav Dubeyko <slava@dubeyko.com>
Subject: [PATCH 0/2] hfs/hfsplus: release preallocated blocks on truncate
Date: Tue, 10 Nov 2026 15:36:07 -0800	[thread overview]
Message-ID: <20261110233609.561557-1-slava@dubeyko.com> (raw)

HFS and HFS+ extend a fork in whole clumps, and when an inode
is loaded the number of allocated blocks comes from the on-disk
physical size of the fork, while i_size and phys_size come from
the logical size. So the fork can hold more blocks than i_size
needs even when phys_size equals i_size.

hfs_file_truncate() and hfsplus_file_truncate() return early when
i_size equals phys_size, before comparing the required block
count with the allocated one. This logic has been added
to avoid dirtying an unchanged inode, but it also skips
releasing the extra blocks:

 - a file whose size is aligned on the block size keeps its clump
   preallocation after the last close;

 - the catalog delete path does not free the data fork and relies
   on truncating the inode to zero size, so a file with zero
   logical size but allocated blocks leaves those blocks marked
   as used in the bitmap after it has been deleted.

Make the early return happen only when neither the
size nor the allocation needs to be trimmed, which keeps the
original intent of not dirtying an unchanged inode.

Viacheslav Dubeyko (2):
  hfsplus: release preallocated blocks in hfsplus_file_truncate()
  hfs: release preallocated blocks in hfs_file_truncate()

 fs/hfs/extent.c      | 13 +++++++++++--
 fs/hfsplus/extents.c | 11 +++++++++--
 2 files changed, 20 insertions(+), 4 deletions(-)

-- 
2.43.0


             reply	other threads:[~2026-11-10 23:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 23:36 Viacheslav Dubeyko [this message]
2026-11-10 23:36 ` [PATCH 1/2] hfsplus: release preallocated blocks in hfsplus_file_truncate() Viacheslav Dubeyko
2026-11-10 23:36 ` [PATCH 2/2] hfs: release preallocated blocks in hfs_file_truncate() Viacheslav Dubeyko

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=20261110233609.561557-1-slava@dubeyko.com \
    --to=slava@dubeyko.com \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vdubeyko@coreweave.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®