Skip to contentSkip to conversation

btrfs: fixes for nowait buffered writes

PATCH In review [email protected] 3 participants 5 messages Nov 2, 2022 Btrfs file system

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 btrfs: fix nowait buffered write returning -ENOSPC

In reply to [email protected]

From: Filipe Manana <[email protected]>

If we are doing a buffered write in NOWAIT context and we can't reserve metadata space due to -ENOSPC, then we should return -EAGAIN so that we retry the write in a context allowed to block and do metadata reservation with flushing, which might succeed this time due to the allowed flushing.

Returning -ENOSPC while in NOWAIT context simply makes some writes fail with -ENOSPC when they would likely succeed after switching from NOWAIT context to blocking context. That is unexpected behaviour and even fio complains about it with a warning like this:

fio: io_u error on file /mnt/sdi/task_0.0.0: No space left on device: write offset=1535705088, buflen=65536
fio: pid=592630, err=28/file:io_u.c:1846, func=io_u error, error=No space left on device

The fio's job config is this:

[global]
bs=64K
ioengine=io_uring
iodepth=1
size=2236962133
nr_files=1
filesize=2236962133
direct=0
runtime=10
fallocate=posix
io_size=2236962133
group_reporting
time_based

[task_0]
rw=randwrite
directory=/mnt/sdi
numjobs=4

So fix this by returning -EAGAIN if we are in NOWAIT context and the metadata reservation failed with -ENOSPC.

Fixes 304e45acdb8f ("btrfs: plumb NOWAIT through the write path")
---
 fs/btrfs/file.c | 3 +++
 1 file changed, 3 insertions(+)
fs/btrfs/file.c +3 -0
index b7855f794ba6..75d4d0bc9d8f 100644
@@ -1286,6 +1286,9 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
 						write_bytes);
 			else
 				btrfs_check_nocow_unlock(BTRFS_I(inode));
+
+			if (nowait && ret == -ENOSPC)
+				ret = -EAGAIN;
 			break;
 		}
 
Signature · 1 line
2.35.1
#0 lore raw

cover btrfs: fixes for nowait buffered writes

From: Filipe Manana <[email protected]>

A couple fixes for the recently added support for nowait buffered writes. Trivial stuff, one of the bugs was reported sometime ago by the lkp test robot.

Filipe Manana (2):
btrfs: fix nowait buffered write returning -ENOSPC
btrfs: fix inode reserve space leak due to nowait buffered write

 fs/btrfs/file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.35.1
#2 lore raw

PATCH 2/2 btrfs: fix inode reserve space leak due to nowait buffered write

From: Filipe Manana <[email protected]>

During a nowait buffered write, if we fail to balance dirty pages we exit btrfs_buffered_write() without releasing the delalloc space reserved for an extent, resulting in leaking space from the inode's block reserve.

So fix that by releasing the delalloc space for the extent when balancing dirty pages fails.

Fixes 965f47aeb5de ("btrfs: make btrfs_buffered_write nowait compatible")
---
 fs/btrfs/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/file.c +3 -1
index 75d4d0bc9d8f..f8be9d629e75 100644
@@ -1295,8 +1295,10 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
 		release_bytes = reserve_bytes;
 again:
 		ret = balance_dirty_pages_ratelimited_flags(inode->i_mapping, bdp_flags);
-		if (ret)
+		if (ret) {
+			btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes);
 			break;
+		}
 
 		/*
 		 * This is going to setup the pages array with the number of
Signature · 1 line
2.35.1
Reviewed-by on the v1 series
#3 lore raw
In reply to [email protected]
Quoted 6 lines · On Wed, Nov 02, 2022 at 12:46:34PM +0000, [email protected] wrote:

From: Filipe Manana <[email protected]>

A couple fixes for the recently added support for nowait buffered writes. Trivial stuff, one of the bugs was reported sometime ago by the lkp test robot.

Quoted 7 lines

Filipe Manana (2):
btrfs: fix nowait buffered write returning -ENOSPC
btrfs: fix inode reserve space leak due to nowait buffered write

 fs/btrfs/file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Thanks,

Josef

#4 lore raw
In reply to [email protected]
Quoted 9 lines · On Wed, Nov 02, 2022 at 12:46:34PM +0000, [email protected] wrote:

From: Filipe Manana <[email protected]>

A couple fixes for the recently added support for nowait buffered writes. Trivial stuff, one of the bugs was reported sometime ago by the lkp test robot.

Filipe Manana (2):
btrfs: fix nowait buffered write returning -ENOSPC
btrfs: fix inode reserve space leak due to nowait buffered write

Added to misc-next, thanks.