diff mbox series

[02/11] filemap: Remove filemap_check_and_keep_errors()

Message ID 20230109051823.480289-3-willy@infradead.org (mailing list archive)
State New
Headers show
Series Remove AS_EIO and AS_ENOSPC | expand

Commit Message

Matthew Wilcox (Oracle) Jan. 9, 2023, 5:18 a.m. UTC
Convert both callers to use the "new" errseq infrastructure.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/filemap.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

Comments

Jeff Layton Jan. 9, 2023, 1:48 p.m. UTC | #1
On Mon, 2023-01-09 at 05:18 +0000, Matthew Wilcox (Oracle) wrote:
> Convert both callers to use the "new" errseq infrastructure.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>  mm/filemap.c | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index c4d4ace9cc70..48daedc224d9 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -355,16 +355,6 @@ int filemap_check_errors(struct address_space *mapping)
>  }
>  EXPORT_SYMBOL(filemap_check_errors);
>  
> -static int filemap_check_and_keep_errors(struct address_space *mapping)
> -{
> -	/* Check for outstanding write errors */
> -	if (test_bit(AS_EIO, &mapping->flags))
> -		return -EIO;
> -	if (test_bit(AS_ENOSPC, &mapping->flags))
> -		return -ENOSPC;
> -	return 0;
> -}
> -
>  /**
>   * filemap_fdatawrite_wbc - start writeback on mapping dirty pages in range
>   * @mapping:	address space structure to write
> @@ -567,8 +557,10 @@ EXPORT_SYMBOL(filemap_fdatawait_range);
>  int filemap_fdatawait_range_keep_errors(struct address_space *mapping,
>  		loff_t start_byte, loff_t end_byte)
>  {
> +	errseq_t since = filemap_sample_wb_err(mapping);
> +
>  	__filemap_fdatawait_range(mapping, start_byte, end_byte);
> -	return filemap_check_and_keep_errors(mapping);
> +	return filemap_check_wb_err(mapping, since);
>  }
>  EXPORT_SYMBOL(filemap_fdatawait_range_keep_errors);

I looked at making this sort of change across the board alongside the
original wb_err patches, but I backed off at the time.

With the above patch, this function will no longer report a writeback
error that occurs before the sample. Given that writeback can happen at
any time, that seemed like it might be an undesirable change, and I
didn't follow through.

It is true that the existing flag-based code may miss errors too, if
multiple tasks are test_and_clear'ing the bits, but I think the above is
even more likely to happen, esp. under memory pressure.

To do this right, we probably need to look at these callers and have
them track a long-term errseq_t "since" value before they ever dirty the
pages, and then continually check-and-advance vs. that.

For instance, the main caller of the above function is jbd2. Would it be
reasonable to add in a new errseq_t value to the jnode for tracking
errors?

>  
> @@ -613,8 +605,10 @@ EXPORT_SYMBOL(file_fdatawait_range);
>   */
>  int filemap_fdatawait_keep_errors(struct address_space *mapping)
>  {
> +	errseq_t since = filemap_sample_wb_err(mapping);
> +
>  	__filemap_fdatawait_range(mapping, 0, LLONG_MAX);
> -	return filemap_check_and_keep_errors(mapping);
> +	return filemap_check_wb_err(mapping, since);
>  }
>  EXPORT_SYMBOL(filemap_fdatawait_keep_errors);
>
Matthew Wilcox (Oracle) Jan. 9, 2023, 2:02 p.m. UTC | #2
On Mon, Jan 09, 2023 at 08:48:49AM -0500, Jeff Layton wrote:
> On Mon, 2023-01-09 at 05:18 +0000, Matthew Wilcox (Oracle) wrote:
> > Convert both callers to use the "new" errseq infrastructure.
> 
> I looked at making this sort of change across the board alongside the
> original wb_err patches, but I backed off at the time.
> 
> With the above patch, this function will no longer report a writeback
> error that occurs before the sample. Given that writeback can happen at
> any time, that seemed like it might be an undesirable change, and I
> didn't follow through.
> 
> It is true that the existing flag-based code may miss errors too, if
> multiple tasks are test_and_clear'ing the bits, but I think the above is
> even more likely to happen, esp. under memory pressure.
> 
> To do this right, we probably need to look at these callers and have
> them track a long-term errseq_t "since" value before they ever dirty the
> pages, and then continually check-and-advance vs. that.
> 
> For instance, the main caller of the above function is jbd2. Would it be
> reasonable to add in a new errseq_t value to the jnode for tracking
> errors?

Doesn't b4678df184b3 address this problem?  If nobody has seen the
error, we return 0 instead of the current value of wb_err, ensuring
that somebody always sees the error.
Jeff Layton Jan. 9, 2023, 2:31 p.m. UTC | #3
On Mon, 2023-01-09 at 14:02 +0000, Matthew Wilcox wrote:
> On Mon, Jan 09, 2023 at 08:48:49AM -0500, Jeff Layton wrote:
> > On Mon, 2023-01-09 at 05:18 +0000, Matthew Wilcox (Oracle) wrote:
> > > Convert both callers to use the "new" errseq infrastructure.
> > 
> > I looked at making this sort of change across the board alongside the
> > original wb_err patches, but I backed off at the time.
> > 
> > With the above patch, this function will no longer report a writeback
> > error that occurs before the sample. Given that writeback can happen at
> > any time, that seemed like it might be an undesirable change, and I
> > didn't follow through.
> > 
> > It is true that the existing flag-based code may miss errors too, if
> > multiple tasks are test_and_clear'ing the bits, but I think the above is
> > even more likely to happen, esp. under memory pressure.
> > 
> > To do this right, we probably need to look at these callers and have
> > them track a long-term errseq_t "since" value before they ever dirty the
> > pages, and then continually check-and-advance vs. that.
> > 
> > For instance, the main caller of the above function is jbd2. Would it be
> > reasonable to add in a new errseq_t value to the jnode for tracking
> > errors?
> 
> Doesn't b4678df184b3 address this problem?  If nobody has seen the
> error, we return 0 instead of the current value of wb_err, ensuring
> that somebody always sees the error.
> 

I was originally thinking no, but now I think you're correct.

We do initialize the "since" value to 0 if an error has never been seen,
so that (sort of) emulates the behavior of the existing AS_EIO/AS_ENOSPC
flags.

It's still not quite as reliable as plumbing a "since" value through all
of the callers (particularly in the case where there are multiple
waiters), but maybe it's good enough here.

I'll look over the rest of the set.

Thanks,
--
Jeff Layton <jlayton@redhat.com>
Matthew Wilcox (Oracle) Jan. 9, 2023, 3:02 p.m. UTC | #4
On Mon, Jan 09, 2023 at 09:31:00AM -0500, Jeff Layton wrote:
> On Mon, 2023-01-09 at 14:02 +0000, Matthew Wilcox wrote:
> > On Mon, Jan 09, 2023 at 08:48:49AM -0500, Jeff Layton wrote:
> > > On Mon, 2023-01-09 at 05:18 +0000, Matthew Wilcox (Oracle) wrote:
> > > > Convert both callers to use the "new" errseq infrastructure.
> > > 
> > > I looked at making this sort of change across the board alongside the
> > > original wb_err patches, but I backed off at the time.
> > > 
> > > With the above patch, this function will no longer report a writeback
> > > error that occurs before the sample. Given that writeback can happen at
> > > any time, that seemed like it might be an undesirable change, and I
> > > didn't follow through.
> > > 
> > > It is true that the existing flag-based code may miss errors too, if
> > > multiple tasks are test_and_clear'ing the bits, but I think the above is
> > > even more likely to happen, esp. under memory pressure.
> > > 
> > > To do this right, we probably need to look at these callers and have
> > > them track a long-term errseq_t "since" value before they ever dirty the
> > > pages, and then continually check-and-advance vs. that.
> > > 
> > > For instance, the main caller of the above function is jbd2. Would it be
> > > reasonable to add in a new errseq_t value to the jnode for tracking
> > > errors?
> > 
> > Doesn't b4678df184b3 address this problem?  If nobody has seen the
> > error, we return 0 instead of the current value of wb_err, ensuring
> > that somebody always sees the error.
> > 
> 
> I was originally thinking no, but now I think you're correct.
> 
> We do initialize the "since" value to 0 if an error has never been seen,
> so that (sort of) emulates the behavior of the existing AS_EIO/AS_ENOSPC
> flags.
> 
> It's still not quite as reliable as plumbing a "since" value through all
> of the callers (particularly in the case where there are multiple
> waiters), but maybe it's good enough here.

I actually think we may have the opposite problem; that for some of
these scenarios, we never mark the error as seen.  ie we always end
up calling errseq_check() and never errseq_check_and_advance().  So
every time we write something, it'll remind us that we have an error.
diff mbox series

Patch

diff --git a/mm/filemap.c b/mm/filemap.c
index c4d4ace9cc70..48daedc224d9 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -355,16 +355,6 @@  int filemap_check_errors(struct address_space *mapping)
 }
 EXPORT_SYMBOL(filemap_check_errors);
 
-static int filemap_check_and_keep_errors(struct address_space *mapping)
-{
-	/* Check for outstanding write errors */
-	if (test_bit(AS_EIO, &mapping->flags))
-		return -EIO;
-	if (test_bit(AS_ENOSPC, &mapping->flags))
-		return -ENOSPC;
-	return 0;
-}
-
 /**
  * filemap_fdatawrite_wbc - start writeback on mapping dirty pages in range
  * @mapping:	address space structure to write
@@ -567,8 +557,10 @@  EXPORT_SYMBOL(filemap_fdatawait_range);
 int filemap_fdatawait_range_keep_errors(struct address_space *mapping,
 		loff_t start_byte, loff_t end_byte)
 {
+	errseq_t since = filemap_sample_wb_err(mapping);
+
 	__filemap_fdatawait_range(mapping, start_byte, end_byte);
-	return filemap_check_and_keep_errors(mapping);
+	return filemap_check_wb_err(mapping, since);
 }
 EXPORT_SYMBOL(filemap_fdatawait_range_keep_errors);
 
@@ -613,8 +605,10 @@  EXPORT_SYMBOL(file_fdatawait_range);
  */
 int filemap_fdatawait_keep_errors(struct address_space *mapping)
 {
+	errseq_t since = filemap_sample_wb_err(mapping);
+
 	__filemap_fdatawait_range(mapping, 0, LLONG_MAX);
-	return filemap_check_and_keep_errors(mapping);
+	return filemap_check_wb_err(mapping, since);
 }
 EXPORT_SYMBOL(filemap_fdatawait_keep_errors);