diff mbox series

[11/43] xfs: reduce metafile reservations

Message ID 20250206064511.2323878-12-hch@lst.de (mailing list archive)
State Not Applicable, archived
Headers show
Series [01/43] xfs: factor out a xfs_rt_check_size helper | expand

Commit Message

Christoph Hellwig Feb. 6, 2025, 6:44 a.m. UTC
There is no point in reserving more space than actually available
on the data device for the worst case scenario that is unlikely to
happen.  Reserve at most 1/4th of the data device blocks, which is
still a heuristic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/libxfs/xfs_metafile.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Darrick J. Wong Feb. 6, 2025, 8:52 p.m. UTC | #1
On Thu, Feb 06, 2025 at 07:44:27AM +0100, Christoph Hellwig wrote:
> There is no point in reserving more space than actually available
> on the data device for the worst case scenario that is unlikely to
> happen.  Reserve at most 1/4th of the data device blocks, which is
> still a heuristic.

I wonder if this should be a bugfix for 6.14?  Since one could format a
filesystem with a 1T data volume and a 200T rt volume and immediately be
out of space on the data volume.

Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/xfs/libxfs/xfs_metafile.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/xfs/libxfs/xfs_metafile.c b/fs/xfs/libxfs/xfs_metafile.c
> index 88f011750add..225923e463c4 100644
> --- a/fs/xfs/libxfs/xfs_metafile.c
> +++ b/fs/xfs/libxfs/xfs_metafile.c
> @@ -260,6 +260,7 @@ xfs_metafile_resv_init(
>  	struct xfs_rtgroup	*rtg = NULL;
>  	xfs_filblks_t		used = 0, target = 0;
>  	xfs_filblks_t		hidden_space;
> +	xfs_rfsblock_t		dblocks_avail = mp->m_sb.sb_dblocks / 4;
>  	int			error = 0;
>  
>  	if (!xfs_has_metadir(mp))
> @@ -297,6 +298,8 @@ xfs_metafile_resv_init(
>  	 */
>  	if (used > target)
>  		target = used;
> +	else if (target > dblocks_avail)
> +		target = dblocks_avail;
>  	hidden_space = target - used;
>  
>  	error = xfs_dec_fdblocks(mp, hidden_space, true);
> -- 
> 2.45.2
> 
>
Christoph Hellwig Feb. 7, 2025, 4:19 a.m. UTC | #2
On Thu, Feb 06, 2025 at 12:52:49PM -0800, Darrick J. Wong wrote:
> On Thu, Feb 06, 2025 at 07:44:27AM +0100, Christoph Hellwig wrote:
> > There is no point in reserving more space than actually available
> > on the data device for the worst case scenario that is unlikely to
> > happen.  Reserve at most 1/4th of the data device blocks, which is
> > still a heuristic.
> 
> I wonder if this should be a bugfix for 6.14?  Since one could format a
> filesystem with a 1T data volume and a 200T rt volume and immediately be
> out of space on the data volume.

Yeah.  But for this to be safe I think we also need the previous patch
to sitch to the global reservations.  Which at least in the current
form sits on top of the freecounter refactoring..
Darrick J. Wong Feb. 7, 2025, 4:26 a.m. UTC | #3
On Fri, Feb 07, 2025 at 05:19:31AM +0100, Christoph Hellwig wrote:
> On Thu, Feb 06, 2025 at 12:52:49PM -0800, Darrick J. Wong wrote:
> > On Thu, Feb 06, 2025 at 07:44:27AM +0100, Christoph Hellwig wrote:
> > > There is no point in reserving more space than actually available
> > > on the data device for the worst case scenario that is unlikely to
> > > happen.  Reserve at most 1/4th of the data device blocks, which is
> > > still a heuristic.
> > 
> > I wonder if this should be a bugfix for 6.14?  Since one could format a
> > filesystem with a 1T data volume and a 200T rt volume and immediately be
> > out of space on the data volume.
> 
> Yeah.  But for this to be safe I think we also need the previous patch
> to sitch to the global reservations.  Which at least in the current
> form sits on top of the freecounter refactoring..

<nod> Well at the moment we're safe against that scenario because mkfs
will blow up and not complete the format. :D

--D
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_metafile.c b/fs/xfs/libxfs/xfs_metafile.c
index 88f011750add..225923e463c4 100644
--- a/fs/xfs/libxfs/xfs_metafile.c
+++ b/fs/xfs/libxfs/xfs_metafile.c
@@ -260,6 +260,7 @@  xfs_metafile_resv_init(
 	struct xfs_rtgroup	*rtg = NULL;
 	xfs_filblks_t		used = 0, target = 0;
 	xfs_filblks_t		hidden_space;
+	xfs_rfsblock_t		dblocks_avail = mp->m_sb.sb_dblocks / 4;
 	int			error = 0;
 
 	if (!xfs_has_metadir(mp))
@@ -297,6 +298,8 @@  xfs_metafile_resv_init(
 	 */
 	if (used > target)
 		target = used;
+	else if (target > dblocks_avail)
+		target = dblocks_avail;
 	hidden_space = target - used;
 
 	error = xfs_dec_fdblocks(mp, hidden_space, true);