* [PATCH 0/2] btrfs: fixes for nowait buffered writes
@ 2022-11-02 12:46 fdmanana
2022-11-02 12:46 ` [PATCH 1/2] btrfs: fix nowait buffered write returning -ENOSPC fdmanana
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: fdmanana @ 2022-11-02 12:46 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
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(-)
--
2.35.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] btrfs: fix nowait buffered write returning -ENOSPC
2022-11-02 12:46 [PATCH 0/2] btrfs: fixes for nowait buffered writes fdmanana
@ 2022-11-02 12:46 ` fdmanana
2022-11-02 12:46 ` [PATCH 2/2] btrfs: fix inode reserve space leak due to nowait buffered write fdmanana
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: fdmanana @ 2022-11-02 12:46 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
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")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/file.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index b7855f794ba6..75d4d0bc9d8f 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -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;
}
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] btrfs: fix inode reserve space leak due to nowait buffered write
2022-11-02 12:46 [PATCH 0/2] btrfs: fixes for nowait buffered writes fdmanana
2022-11-02 12:46 ` [PATCH 1/2] btrfs: fix nowait buffered write returning -ENOSPC fdmanana
@ 2022-11-02 12:46 ` fdmanana
2022-11-02 14:06 ` [PATCH 0/2] btrfs: fixes for nowait buffered writes Josef Bacik
2022-11-02 16:39 ` David Sterba
3 siblings, 0 replies; 5+ messages in thread
From: fdmanana @ 2022-11-02 12:46 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
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.
Reported-by: kernel test robot <yujie.liu@intel.com>
Link: https://lore.kernel.org/all/202210111304.d369bc32-yujie.liu@intel.com
Fixes: 965f47aeb5de ("btrfs: make btrfs_buffered_write nowait compatible")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/file.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 75d4d0bc9d8f..f8be9d629e75 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -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
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] btrfs: fixes for nowait buffered writes
2022-11-02 12:46 [PATCH 0/2] btrfs: fixes for nowait buffered writes fdmanana
2022-11-02 12:46 ` [PATCH 1/2] btrfs: fix nowait buffered write returning -ENOSPC fdmanana
2022-11-02 12:46 ` [PATCH 2/2] btrfs: fix inode reserve space leak due to nowait buffered write fdmanana
@ 2022-11-02 14:06 ` Josef Bacik
2022-11-02 16:39 ` David Sterba
3 siblings, 0 replies; 5+ messages in thread
From: Josef Bacik @ 2022-11-02 14:06 UTC (permalink / raw)
To: fdmanana; +Cc: linux-btrfs
On Wed, Nov 02, 2022 at 12:46:34PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> 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(-)
>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Thanks,
Josef
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] btrfs: fixes for nowait buffered writes
2022-11-02 12:46 [PATCH 0/2] btrfs: fixes for nowait buffered writes fdmanana
` (2 preceding siblings ...)
2022-11-02 14:06 ` [PATCH 0/2] btrfs: fixes for nowait buffered writes Josef Bacik
@ 2022-11-02 16:39 ` David Sterba
3 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2022-11-02 16:39 UTC (permalink / raw)
To: fdmanana; +Cc: linux-btrfs
On Wed, Nov 02, 2022 at 12:46:34PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> 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.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-11-02 16:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-02 12:46 [PATCH 0/2] btrfs: fixes for nowait buffered writes fdmanana
2022-11-02 12:46 ` [PATCH 1/2] btrfs: fix nowait buffered write returning -ENOSPC fdmanana
2022-11-02 12:46 ` [PATCH 2/2] btrfs: fix inode reserve space leak due to nowait buffered write fdmanana
2022-11-02 14:06 ` [PATCH 0/2] btrfs: fixes for nowait buffered writes Josef Bacik
2022-11-02 16:39 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox