mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br>,
	linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/3] fat: remove cluster allocation size limit
Date: Tue, 13 Oct 2026 22:17:08 +0900	[thread overview]
Message-ID: <87ld81n3jf.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <20261012171106.146243-2-matheus.aalmeida@inf.ufrgs.br>

Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br> writes:

> fat_alloc_clusters() currently BUG()s when asked to allocate more than
> MAX_BUF_PER_PAGE / 2 clusters. This limit comes from the buffer_head
> array used to defer syncing and mirroring.
>
> Remove the allocation size limit by doing buffer_head batching like
> fat_free_clusters() does.
>
> Signed-off-by: Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br>

Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>

Looks good. Thanks.

> ---
>  fs/fat/fatent.c | 44 +++++++++++++++++++++++++++++++-------------
>  1 file changed, 31 insertions(+), 13 deletions(-)
>
> diff --git a/fs/fat/fatent.c b/fs/fat/fatent.c
> index f0801d99d..bfab8eab5 100644
> --- a/fs/fat/fatent.c
> +++ b/fs/fat/fatent.c
> @@ -468,6 +468,26 @@ static void fat_collect_bhs(struct buffer_head **bhs, int *nr_bhs,
>  	}
>  }
>  
> +static int fat_flush_bhs(struct super_block *sb, struct buffer_head **bhs,
> +			 int *nr_bhs, bool sync)
> +{
> +	int err, i;
> +
> +	if (sync) {
> +		err = fat_sync_bhs(bhs, *nr_bhs);
> +		if (err)
> +			return err;
> +	}
> +	err = fat_mirror_bhs(sb, bhs, *nr_bhs);
> +	if (err)
> +		return err;
> +	for (i = 0; i < *nr_bhs; i++)
> +		brelse(bhs[i]);
> +	*nr_bhs = 0;
> +
> +	return 0;
> +}
> +
>  int fat_alloc_clusters(struct inode *inode, int *cluster, int nr_cluster)
>  {
>  	struct super_block *sb = inode->i_sb;
> @@ -477,8 +497,6 @@ int fat_alloc_clusters(struct inode *inode, int *cluster, int nr_cluster)
>  	struct buffer_head *bhs[MAX_BUF_PER_PAGE];
>  	int i, count, err, nr_bhs, idx_clus;
>  
> -	BUG_ON(nr_cluster > (MAX_BUF_PER_PAGE / 2));	/* fixed limit */
> -
>  	lock_fat(sbi);
>  	if (sbi->free_clusters != -1 && sbi->free_clus_valid &&
>  	    sbi->free_clusters < nr_cluster) {
> @@ -509,14 +527,21 @@ int fat_alloc_clusters(struct inode *inode, int *cluster, int nr_cluster)
>  				if (prev_ent.nr_bhs)
>  					ops->ent_put(&prev_ent, entry);
>  
> -				fat_collect_bhs(bhs, &nr_bhs, &fatent);
> -
>  				sbi->prev_free = entry;
>  				if (sbi->free_clusters != -1)
>  					sbi->free_clusters--;
>  
>  				cluster[idx_clus] = entry;
>  				idx_clus++;
> +
> +				if (nr_bhs + fatent.nr_bhs > MAX_BUF_PER_PAGE) {
> +					err = fat_flush_bhs(sb, bhs, &nr_bhs,
> +							    inode_needs_sync(inode));
> +					if (err)
> +						goto out;
> +				}
> +				fat_collect_bhs(bhs, &nr_bhs, &fatent);
> +
>  				if (idx_clus == nr_cluster)
>  					goto out;
>  
> @@ -606,17 +631,10 @@ int fat_free_clusters(struct inode *inode, int cluster)
>  		}
>  
>  		if (nr_bhs + fatent.nr_bhs > MAX_BUF_PER_PAGE) {
> -			if (sb->s_flags & SB_SYNCHRONOUS) {
> -				err = fat_sync_bhs(bhs, nr_bhs);
> -				if (err)
> -					goto error;
> -			}
> -			err = fat_mirror_bhs(sb, bhs, nr_bhs);
> +			err = fat_flush_bhs(sb, bhs, &nr_bhs,
> +					    sb->s_flags & SB_SYNCHRONOUS);
>  			if (err)
>  				goto error;
> -			for (i = 0; i < nr_bhs; i++)
> -				brelse(bhs[i]);
> -			nr_bhs = 0;
>  		}
>  		fat_collect_bhs(bhs, &nr_bhs, &fatent);
>  	} while (cluster != FAT_ENT_EOF);

-- 
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>

  reply	other threads:[~2026-10-13 13:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 17:11 [PATCH v2 0/3] fat: allocate multiple clusters in fallocate Matheus Alves de Almeida
2026-10-12 17:11 ` [PATCH v2 1/3] fat: remove cluster allocation size limit Matheus Alves de Almeida
2026-10-13 13:17   ` OGAWA Hirofumi [this message]
2026-10-12 17:11 ` [PATCH v2 2/3] fat: support adding multiple clusters Matheus Alves de Almeida
2026-10-13 13:17   ` OGAWA Hirofumi
2026-10-12 17:11 ` [PATCH v2 3/3] fat: allocate multiple clusters in fallocate Matheus Alves de Almeida
2026-10-13 13:17   ` OGAWA Hirofumi

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=87ld81n3jf.fsf@mail.parknet.co.jp \
    --to=hirofumi@mail.parknet.co.jp \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matheus.aalmeida@inf.ufrgs.br \
    /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®