* [PATCH] fs/remap_range: avoid spurious writeback on zero length request
@ 2022-11-28 16:08 Brian Foster
2022-11-28 17:22 ` Darrick J. Wong
0 siblings, 1 reply; 5+ messages in thread
From: Brian Foster @ 2022-11-28 16:08 UTC (permalink / raw)
To: linux-fsdevel
generic_remap_checks() can reduce the effective request length (i.e.,
after the reflink extend to EOF case is handled) down to zero. If this
occurs, __generic_remap_file_range_prep() proceeds through dio
serialization, file mapping flush calls, and may invoke file_modified()
before returning back to the filesystem caller, all of which immediately
check for len == 0 and return.
While this is mostly harmless, it is spurious and not completely
without side effect. A filemap write call can submit I/O (but not
wait on it) when the specified end byte precedes the start but
happens to land on the same aligned page boundary, which can occur
from __generic_remap_file_range_prep() when len is 0.
The dedupe path already has a len == 0 check to break out before doing
range comparisons. Lift this check a bit earlier in the function to
cover the general case of len == 0 and avoid the unnecessary work.
Signed-off-by: Brian Foster <bfoster@redhat.com>
---
fs/remap_range.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/fs/remap_range.c b/fs/remap_range.c
index 654912d06862..32ea992f9acc 100644
--- a/fs/remap_range.c
+++ b/fs/remap_range.c
@@ -306,6 +306,8 @@ __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
remap_flags);
if (ret)
return ret;
+ if (*len == 0)
+ return 0;
/* Wait for the completion of any pending IOs on both files */
inode_dio_wait(inode_in);
@@ -328,9 +330,6 @@ __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
if (remap_flags & REMAP_FILE_DEDUP) {
bool is_same = false;
- if (*len == 0)
- return 0;
-
if (!IS_DAX(inode_in))
ret = vfs_dedupe_file_range_compare(file_in, pos_in,
file_out, pos_out, *len, &is_same);
--
2.37.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] fs/remap_range: avoid spurious writeback on zero length request
2022-11-28 16:08 [PATCH] fs/remap_range: avoid spurious writeback on zero length request Brian Foster
@ 2022-11-28 17:22 ` Darrick J. Wong
2022-11-29 11:29 ` Brian Foster
0 siblings, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2022-11-28 17:22 UTC (permalink / raw)
To: Brian Foster; +Cc: linux-fsdevel
On Mon, Nov 28, 2022 at 11:08:13AM -0500, Brian Foster wrote:
> generic_remap_checks() can reduce the effective request length (i.e.,
> after the reflink extend to EOF case is handled) down to zero. If this
> occurs, __generic_remap_file_range_prep() proceeds through dio
> serialization, file mapping flush calls, and may invoke file_modified()
> before returning back to the filesystem caller, all of which immediately
> check for len == 0 and return.
>
> While this is mostly harmless, it is spurious and not completely
> without side effect. A filemap write call can submit I/O (but not
> wait on it) when the specified end byte precedes the start but
> happens to land on the same aligned page boundary, which can occur
> from __generic_remap_file_range_prep() when len is 0.
>
> The dedupe path already has a len == 0 check to break out before doing
> range comparisons. Lift this check a bit earlier in the function to
> cover the general case of len == 0 and avoid the unnecessary work.
>
> Signed-off-by: Brian Foster <bfoster@redhat.com>
Looks correct,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Should there be an(other) "if (!*len) return 0;" after the
generic_remap_check_len call to skip the mtime update if the remap
request gets shortened to avoid remapping an unaligned eofblock into the
middle of the destination file?
--D
> ---
> fs/remap_range.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/fs/remap_range.c b/fs/remap_range.c
> index 654912d06862..32ea992f9acc 100644
> --- a/fs/remap_range.c
> +++ b/fs/remap_range.c
> @@ -306,6 +306,8 @@ __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
> remap_flags);
> if (ret)
> return ret;
> + if (*len == 0)
> + return 0;
>
> /* Wait for the completion of any pending IOs on both files */
> inode_dio_wait(inode_in);
> @@ -328,9 +330,6 @@ __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
> if (remap_flags & REMAP_FILE_DEDUP) {
> bool is_same = false;
>
> - if (*len == 0)
> - return 0;
> -
> if (!IS_DAX(inode_in))
> ret = vfs_dedupe_file_range_compare(file_in, pos_in,
> file_out, pos_out, *len, &is_same);
> --
> 2.37.3
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] fs/remap_range: avoid spurious writeback on zero length request
2022-11-28 17:22 ` Darrick J. Wong
@ 2022-11-29 11:29 ` Brian Foster
2022-11-29 18:18 ` Darrick J. Wong
0 siblings, 1 reply; 5+ messages in thread
From: Brian Foster @ 2022-11-29 11:29 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: linux-fsdevel
On Mon, Nov 28, 2022 at 09:22:53AM -0800, Darrick J. Wong wrote:
> On Mon, Nov 28, 2022 at 11:08:13AM -0500, Brian Foster wrote:
> > generic_remap_checks() can reduce the effective request length (i.e.,
> > after the reflink extend to EOF case is handled) down to zero. If this
> > occurs, __generic_remap_file_range_prep() proceeds through dio
> > serialization, file mapping flush calls, and may invoke file_modified()
> > before returning back to the filesystem caller, all of which immediately
> > check for len == 0 and return.
> >
> > While this is mostly harmless, it is spurious and not completely
> > without side effect. A filemap write call can submit I/O (but not
> > wait on it) when the specified end byte precedes the start but
> > happens to land on the same aligned page boundary, which can occur
> > from __generic_remap_file_range_prep() when len is 0.
> >
> > The dedupe path already has a len == 0 check to break out before doing
> > range comparisons. Lift this check a bit earlier in the function to
> > cover the general case of len == 0 and avoid the unnecessary work.
> >
> > Signed-off-by: Brian Foster <bfoster@redhat.com>
>
> Looks correct,
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
>
> Should there be an(other) "if (!*len) return 0;" after the
> generic_remap_check_len call to skip the mtime update if the remap
> request gets shortened to avoid remapping an unaligned eofblock into the
> middle of the destination file?
>
Looks sensible to me, though I guess I would do something like the
appended diff. Do you want to just fold that into this patch?
Brian
--- 8< ---
diff --git a/fs/remap_range.c b/fs/remap_range.c
index 32ea992f9acc..2f236c9c5802 100644
--- a/fs/remap_range.c
+++ b/fs/remap_range.c
@@ -347,7 +347,7 @@ __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
ret = generic_remap_check_len(inode_in, inode_out, pos_out, len,
remap_flags);
- if (ret)
+ if (ret || *len == 0)
return ret;
/* If can't alter the file contents, we're done. */
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] fs/remap_range: avoid spurious writeback on zero length request
2022-11-29 11:29 ` Brian Foster
@ 2022-11-29 18:18 ` Darrick J. Wong
2022-11-29 18:43 ` Brian Foster
0 siblings, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2022-11-29 18:18 UTC (permalink / raw)
To: Brian Foster; +Cc: linux-fsdevel
On Tue, Nov 29, 2022 at 06:29:51AM -0500, Brian Foster wrote:
> On Mon, Nov 28, 2022 at 09:22:53AM -0800, Darrick J. Wong wrote:
> > On Mon, Nov 28, 2022 at 11:08:13AM -0500, Brian Foster wrote:
> > > generic_remap_checks() can reduce the effective request length (i.e.,
> > > after the reflink extend to EOF case is handled) down to zero. If this
> > > occurs, __generic_remap_file_range_prep() proceeds through dio
> > > serialization, file mapping flush calls, and may invoke file_modified()
> > > before returning back to the filesystem caller, all of which immediately
> > > check for len == 0 and return.
> > >
> > > While this is mostly harmless, it is spurious and not completely
> > > without side effect. A filemap write call can submit I/O (but not
> > > wait on it) when the specified end byte precedes the start but
> > > happens to land on the same aligned page boundary, which can occur
> > > from __generic_remap_file_range_prep() when len is 0.
> > >
> > > The dedupe path already has a len == 0 check to break out before doing
> > > range comparisons. Lift this check a bit earlier in the function to
> > > cover the general case of len == 0 and avoid the unnecessary work.
> > >
> > > Signed-off-by: Brian Foster <bfoster@redhat.com>
> >
> > Looks correct,
> > Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> >
> > Should there be an(other) "if (!*len) return 0;" after the
> > generic_remap_check_len call to skip the mtime update if the remap
> > request gets shortened to avoid remapping an unaligned eofblock into the
> > middle of the destination file?
> >
>
> Looks sensible to me, though I guess I would do something like the
> appended diff. Do you want to just fold that into this patch?
Yes, could you fold it in and send a v2 with my rvb on it, please?
--D
> Brian
>
> --- 8< ---
>
> diff --git a/fs/remap_range.c b/fs/remap_range.c
> index 32ea992f9acc..2f236c9c5802 100644
> --- a/fs/remap_range.c
> +++ b/fs/remap_range.c
> @@ -347,7 +347,7 @@ __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
>
> ret = generic_remap_check_len(inode_in, inode_out, pos_out, len,
> remap_flags);
> - if (ret)
> + if (ret || *len == 0)
> return ret;
>
> /* If can't alter the file contents, we're done. */
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] fs/remap_range: avoid spurious writeback on zero length request
2022-11-29 18:18 ` Darrick J. Wong
@ 2022-11-29 18:43 ` Brian Foster
0 siblings, 0 replies; 5+ messages in thread
From: Brian Foster @ 2022-11-29 18:43 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: linux-fsdevel
On Tue, Nov 29, 2022 at 10:18:53AM -0800, Darrick J. Wong wrote:
> On Tue, Nov 29, 2022 at 06:29:51AM -0500, Brian Foster wrote:
> > On Mon, Nov 28, 2022 at 09:22:53AM -0800, Darrick J. Wong wrote:
> > > On Mon, Nov 28, 2022 at 11:08:13AM -0500, Brian Foster wrote:
> > > > generic_remap_checks() can reduce the effective request length (i.e.,
> > > > after the reflink extend to EOF case is handled) down to zero. If this
> > > > occurs, __generic_remap_file_range_prep() proceeds through dio
> > > > serialization, file mapping flush calls, and may invoke file_modified()
> > > > before returning back to the filesystem caller, all of which immediately
> > > > check for len == 0 and return.
> > > >
> > > > While this is mostly harmless, it is spurious and not completely
> > > > without side effect. A filemap write call can submit I/O (but not
> > > > wait on it) when the specified end byte precedes the start but
> > > > happens to land on the same aligned page boundary, which can occur
> > > > from __generic_remap_file_range_prep() when len is 0.
> > > >
> > > > The dedupe path already has a len == 0 check to break out before doing
> > > > range comparisons. Lift this check a bit earlier in the function to
> > > > cover the general case of len == 0 and avoid the unnecessary work.
> > > >
> > > > Signed-off-by: Brian Foster <bfoster@redhat.com>
> > >
> > > Looks correct,
> > > Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> > >
> > > Should there be an(other) "if (!*len) return 0;" after the
> > > generic_remap_check_len call to skip the mtime update if the remap
> > > request gets shortened to avoid remapping an unaligned eofblock into the
> > > middle of the destination file?
> > >
> >
> > Looks sensible to me, though I guess I would do something like the
> > appended diff. Do you want to just fold that into this patch?
>
> Yes, could you fold it in and send a v2 with my rvb on it, please?
>
Sure. I'll change both lines to do 'if (ret || *len == 0),' not sure why
I didn't do that the first time..
Brian
> --D
>
> > Brian
> >
> > --- 8< ---
> >
> > diff --git a/fs/remap_range.c b/fs/remap_range.c
> > index 32ea992f9acc..2f236c9c5802 100644
> > --- a/fs/remap_range.c
> > +++ b/fs/remap_range.c
> > @@ -347,7 +347,7 @@ __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
> >
> > ret = generic_remap_check_len(inode_in, inode_out, pos_out, len,
> > remap_flags);
> > - if (ret)
> > + if (ret || *len == 0)
> > return ret;
> >
> > /* If can't alter the file contents, we're done. */
> >
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-11-29 18:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-28 16:08 [PATCH] fs/remap_range: avoid spurious writeback on zero length request Brian Foster
2022-11-28 17:22 ` Darrick J. Wong
2022-11-29 11:29 ` Brian Foster
2022-11-29 18:18 ` Darrick J. Wong
2022-11-29 18:43 ` Brian Foster
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).