mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: liubaolin <liubaolin12138@163.com>
To: Matthias Goergens <matthias.goergens@gmail.com>,
	Namjae Jeon <linkinjeon@kernel.org>,
	Hyunchul Lee <hyc.lee@gmail.com>
Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] ntfs: restart the zone search when the allocation hint fails
Date: Mon, 28 Sep 2026 02:06:42 +0800	[thread overview]
Message-ID: <80e893c7-5373-4690-ac66-7b5952d7e99d@163.com> (raw)
In-Reply-To: <79878c7323e37a500c540b3b140102b73d46bafe.1790503811.git.matthias.goergens@gmail.com>



在 2026/9/27 18:57, Matthias Goergens 写道:
> When ntfs_cluster_alloc() is given a start_lcn, it first tries the
> clusters from there on.  If that does not satisfy the request, it moves
> on to the zone's current position, but keeps the pass, the zone_end and
> the has_guess state it had.  That loses free clusters in two ways.  If
> the search had already moved on to pass 2, whose range ends at the hint,
> it scans only from the zone position to the hint and misses every free
> cluster between the start of the zone and the zone position.  If no
> cluster had been tested yet, has_guess is still set, so the cluster at
> the zone position is tried as if it had been the hint, and when that
> cluster is in use the rest of the bitmap buffer is skipped.
> 
> Both happen when the hint lies at or past the end of the volume, which
> ntfs_attr_map_cluster() produces when it extrapolates from the last
> allocated run across a hole.  The allocator then finds nothing, shrinks
> the MFT zone to nothing trying to satisfy the request, and fails with
> -ENOSPC.
> 
> To reproduce on a 128 MiB volume with 4 KiB clusters, extend two files
> in turn by one cluster at a time, alternating between fallocate(),
> write() past EOF and truncate() up, so that the runs of each file are
> separated by holes.  When the volume is full, truncate both files back
> to 1 MiB and start again.  During the second round a one-cluster
> fallocate() fails with ENOSPC while 40 MiB is free.
> 
> Start the zone over as if no hint had been given.
> 
> Fixes: 11ccc9107dc4 ("ntfs: update runlist handling and cluster allocator")
> Signed-off-by: Matthias Goergens <matthias.goergens@gmail.com>
> ---
>   fs/ntfs/lcnalloc.c | 18 +++++++++++++++---
>   1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ntfs/lcnalloc.c b/fs/ntfs/lcnalloc.c
> index 0d6cd08ee2e76..30faf422a5424 100644
> --- a/fs/ntfs/lcnalloc.c
> +++ b/fs/ntfs/lcnalloc.c
> @@ -506,13 +506,25 @@ struct runlist_element *ntfs_cluster_alloc(struct ntfs_volume *vol, const s64 st
>   		}
>   
>   		if (!used_zone_pos) {
> +			/*
> +			 * Leaving @start_lcn for the zone position starts the
> +			 * zone over as if no hint had been given, even if the
> +			 * search had already reached pass 2, whose range ends
> +			 * at @start_lcn.
> +			 */
>   			used_zone_pos = 1;
> -			if (search_zone == 1)
> +			has_guess = 0;
> +			pass = 1;

Hi Matthias,
   Resetting pass, zone_end and has_guess here fixes the missed free 
clusters when falling back from the hint to the zone position.

   However, !used_zone_pos only means that the zone position has not 
been used yet; it does not mean that no clusters have been allocated.
   A partial hint allocation can also reach this block at the end of the 
bitmap buffer. Clearing has_guess then allows a nonadjacent run to be 
appended even when is_contig is true.

   Could we return the existing partial run before resetting the search 
state, like this?

   	if (!used_zone_pos) {
   		if (is_contig && rlpos)
   			goto out;

   		used_zone_pos = 1;
   		has_guess = 0;
   		pass = 1;
   		...
   	}

Thanks,
Baolin.

> +			if (search_zone == 1) {
>   				zone_start = vol->mft_zone_pos;
> -			else if (search_zone == 2)
> +				zone_end = vol->mft_zone_end;
> +			} else if (search_zone == 2) {
>   				zone_start = vol->data1_zone_pos;
> -			else
> +				zone_end = vol->nr_clusters;
> +			} else {
>   				zone_start = vol->data2_zone_pos;
> +				zone_end = vol->mft_zone_start;
> +			}
>   
>   			if (!zone_start || zone_start == vol->mft_zone_start ||
>   			    zone_start == vol->mft_zone_end)


  reply	other threads:[~2026-09-27 18:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-27 10:57 [PATCH 0/3] ntfs: fix spurious EIO and ENOSPC on nearly full volumes Matthias Goergens
2026-09-27 10:57 ` [PATCH 1/3] ntfs: set the attribute list size before reserving space for it Matthias Goergens
2026-09-27 18:11   ` liubaolin
2026-09-27 10:57 ` [PATCH 2/3] ntfs: restart the zone search when the allocation hint fails Matthias Goergens
2026-09-27 18:06   ` liubaolin [this message]
2026-09-27 10:57 ` [PATCH 3/3] ntfs: do not refuse fallocate() when the MFT zone is empty Matthias Goergens
2026-09-27 18:11   ` liubaolin

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=80e893c7-5373-4690-ac66-7b5952d7e99d@163.com \
    --to=liubaolin12138@163.com \
    --cc=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthias.goergens@gmail.com \
    --cc=ntfs@lists.linux.dev \
    /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®