Skip to contentSkip to conversation

do we really need PG_error at all?

LSF/MM TOPIC Jeff Layton 5 participants 15 messages Feb 26, 2017 – Feb 28, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Proposing this as a LSF/MM TOPIC, but it may turn out to be me just not understanding the semantics here.

As I was looking into -ENOSPC handling in cephfs, I noticed that PG_error is only ever tested in one place [1] __filemap_fdatawait_range, which does this:

	if (TestClearPageError(page))
		ret = -EIO;

This error code will override any AS_* error that was set in the mapping. Which makes me wonder...why don't we just set this error in the mapping and not bother with a per-page flag? Could we potentially free up a page flag by eliminating this?

The main argument I could see for keeping it is that removing it might subtly change the behavior of sync_file_range if you have tasks syncing different ranges in a file concurrently. I'm not sure if that would break any guarantees though.

Even if we do need it, I think we might need some cleanup here anyway. A lot of readpage operations end up setting that flag when they hit an error. Isn't it wrong to return an error on fsync, just because we had a read error somewhere in the file in a range that was never dirtied?

--
[1]: there is another place in f2fs, but it's more or less equivalent to the call site in __filemap_fdatawait_range.

Signature · 7 lines
Jeff Layton <[email protected]>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#1 lore raw

[added linux-scsi and linux-block because this is part of our error handling as well]

Quoted 7 lines · Jeff Layton

Proposing this as a LSF/MM TOPIC, but it may turn out to be me just not understanding the semantics here.

As I was looking into -ENOSPC handling in cephfs, I noticed that PG_error is only ever tested in one place [1] __filemap_fdatawait_range, which does this:

Quoted 7 lines
	if (TestClearPageError(page))
		ret = -EIO;

This error code will override any AS_* error that was set in the mapping. Which makes me wonder...why don't we just set this error in the mapping and not bother with a per-page flag? Could we potentially free up a page flag by eliminating this?

Note that currently the AS_* codes are only set for write errors not for reads and we have no mapping error handling at all for swap pages, but I'm sure this is fixable.

Quoted 1 line

From the I/O layer point of view we take great pains to try to pinpoint

the error exactly to the sector. We reflect this up by setting the PG_error flag on the page where the error occurred. If we only set the error on the mapping, we lose that granularity, because the mapping is mostly at the file level (or VMA level for anon pages).

So I think the question for filesystem people from us would be do you care about this accuracy? If it's OK just to know an error occurred somewhere in this file, then perhaps we don't need it.

James

Quoted 15 lines

The main argument I could see for keeping it is that removing it might subtly change the behavior of sync_file_range if you have tasks syncing different ranges in a file concurrently. I'm not sure if that would break any guarantees though.

Even if we do need it, I think we might need some cleanup here anyway. A lot of readpage operations end up setting that flag when they hit an error. Isn't it wrong to return an error on fsync, just because we had a read error somewhere in the file in a range that was never dirtied?

--
[1]: there is another place in f2fs, but it's more or less equivalent to the call site in __filemap_fdatawait_range.

#2 lore raw
Quoted 13 lines · James Bottomley

[added linux-scsi and linux-block because this is part of our error handling as well]

Quoted 10 lines · Jeff Layton

Proposing this as a LSF/MM TOPIC, but it may turn out to be me just not understanding the semantics here.

As I was looking into -ENOSPC handling in cephfs, I noticed that PG_error is only ever tested in one place [1] __filemap_fdatawait_range, which does this:

	if (TestClearPageError(page))
		ret = -EIO;
Quoted 8 lines
Quoted 4 lines

This error code will override any AS_* error that was set in the mapping. Which makes me wonder...why don't we just set this error in the mapping and not bother with a per-page flag? Could we potentially free up a page flag by eliminating this?

Note that currently the AS_* codes are only set for write errors not for reads and we have no mapping error handling at all for swap pages, but I'm sure this is fixable.

How is a read error different from a failure to set PG_uptodate? Does PG_error suppress retries?

Quoted 6 lines

From the I/O layer point of view we take great pains to try to pinpoint the error exactly to the sector. We reflect this up by setting the PG_error flag on the page where the error occurred. If we only set the error on the mapping, we lose that granularity, because the mapping is mostly at the file level (or VMA level for anon pages).

Are you saying that the IO layer finds the page in the bi_io_vec and explicitly sets PG_error, rather than just passing an error indication to bi_end_io ?? That would seem to be wrong as the page may not be in the page cache. So I guess I misunderstand you.

Quoted 4 lines

So I think the question for filesystem people from us would be do you care about this accuracy? If it's OK just to know an error occurred somewhere in this file, then perhaps we don't need it.

I had always assumed that a bio would either succeed or fail, and that no finer granularity could be available.

I think the question here is: Do filesystems need the pagecache to record which pages have seen an IO error?
I think that for write errors, there is no value in recording block-oriented error status - only file-oriented status.
For read errors, it might if help to avoid indefinite read retries, but I don't know the code well enough to be sure if this is an issue.

NeilBrown

Quoted 18 lines

James

Quoted 15 lines

The main argument I could see for keeping it is that removing it might subtly change the behavior of sync_file_range if you have tasks syncing different ranges in a file concurrently. I'm not sure if that would break any guarantees though.

Even if we do need it, I think we might need some cleanup here anyway. A lot of readpage operations end up setting that flag when they hit an error. Isn't it wrong to return an error on fsync, just because we had a read error somewhere in the file in a range that was never dirtied?

--
[1]: there is another place in f2fs, but it's more or less equivalent to the call site in __filemap_fdatawait_range.

#3 lore raw
Quoted 20 lines · NeilBrown
Quoted 18 lines · James Bottomley

[added linux-scsi and linux-block because this is part of our error handling as well]

Quoted 14 lines · Jeff Layton

Proposing this as a LSF/MM TOPIC, but it may turn out to be me just not understanding the semantics here.

As I was looking into -ENOSPC handling in cephfs, I noticed that PG_error is only ever tested in one place [1] __filemap_fdatawait_range, which does this:

	if (TestClearPageError(page))
		ret = -EIO;

This error code will override any AS_* error that was set in the mapping. Which makes me wonder...why don't we just set this error in the mapping and not bother with a per-page flag? Could we potentially free up a page flag by eliminating this?

Quoted 7 lines
Quoted 3 lines

Note that currently the AS_* codes are only set for write errors not for reads and we have no mapping error handling at all for swap pages, but I'm sure this is fixable.

How is a read error different from a failure to set PG_uptodate? Does PG_error suppress retries?

The thing is that we only ever TestClearError in write and fsync type codepaths. Does it make sense to report read errors _at_all_ in fsync?

Quoted 20 lines
Quoted 6 lines

From the I/O layer point of view we take great pains to try to pinpoint the error exactly to the sector. We reflect this up by setting the PG_error flag on the page where the error occurred. If we only set the error on the mapping, we lose that granularity, because the mapping is mostly at the file level (or VMA level for anon pages).

Are you saying that the IO layer finds the page in the bi_io_vec and explicitly sets PG_error, rather than just passing an error indication to bi_end_io ?? That would seem to be wrong as the page may not be in the page cache. So I guess I misunderstand you.

Quoted 4 lines

So I think the question for filesystem people from us would be do you care about this accuracy? If it's OK just to know an error occurred somewhere in this file, then perhaps we don't need it.

I had always assumed that a bio would either succeed or fail, and that no finer granularity could be available.

Quoted 7 lines

I think the question here is: Do filesystems need the pagecache to record which pages have seen an IO error?
I think that for write errors, there is no value in recording block-oriented error status - only file-oriented status.
For read errors, it might if help to avoid indefinite read retries, but I don't know the code well enough to be sure if this is an issue.

Yeah, it might be useful for preventing failing read retries, but I don't see that it's being used in that way today, unless I'm missing something.

If PG_error is ultimately needed, I'd like to have some more clearly defined semantics for it. It's sprinkled all over the place today, and it's not clear to me that it's being used correctly everywhere.

Signature · 7 lines
Jeff Layton <[email protected]>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#4 lore raw
In reply to NeilBrown
Quoted 20 lines · NeilBrown
Quoted 18 lines · James Bottomley

[added linux-scsi and linux-block because this is part of our error handling as well]

Quoted 14 lines · Jeff Layton

Proposing this as a LSF/MM TOPIC, but it may turn out to be me just not understanding the semantics here.

As I was looking into -ENOSPC handling in cephfs, I noticed that PG_error is only ever tested in one place [1] __filemap_fdatawait_range, which does this:

	if (TestClearPageError(page))
		ret = -EIO;

This error code will override any AS_* error that was set in the mapping. Which makes me wonder...why don't we just set this error in the mapping and not bother with a per-page flag? Could we potentially free up a page flag by eliminating this?

Quoted 6 lines
Quoted 3 lines

Note that currently the AS_* codes are only set for write errors not for reads and we have no mapping error handling at all for swap pages, but I'm sure this is fixable.

How is a read error different from a failure to set PG_uptodate? Does PG_error suppress retries?

We don't do any retries in the code above the block layer (or at least we shouldn't).

Quoted 10 lines
Quoted 7 lines

From the I/O layer point of view we take great pains to try to pinpoint the error exactly to the sector. We reflect this up by setting the PG_error flag on the page where the error occurred. If we only set the error on the mapping, we lose that granularity, because the mapping is mostly at the file level (or VMA level for anon pages).

Are you saying that the IO layer finds the page in the bi_io_vec and explicitly sets PG_error,

I didn't say anything about the mechanism. I think the function you're looking for is fs/mpage.c:mpage_end_io(). layers below block indicate the position in the request. Block maps the position to bio and the bio completion maps to page. So the actual granularity seen in the upper layer depends on how the page to bio mapping is done.

Quoted 2 lines

rather than just passing an error indication to bi_end_io ?? That
would seem to be wrong as the page may not be in the page cache.

Usually pages in the mpage_end_io path are pinned, I think.

Quoted 9 lines

So I guess I misunderstand you.

Quoted 4 lines

So I think the question for filesystem people from us would be do you care about this accuracy? If it's OK just to know an error occurred somewhere in this file, then perhaps we don't need it.

I had always assumed that a bio would either succeed or fail, and that no finer granularity could be available.

It does ... but a bio can be as small as a single page.

Quoted 2 lines

I think the question here is: Do filesystems need the pagecache to record which pages have seen an IO error?

It's not just filesystems. The partition code uses PageError() ... the metadata code might as well (those are things with no mapping). I'm not saying we can't remove PG_error; I am saying it's not going to be quite as simple as using the AS_ flags.

James

Quoted 26 lines

I think that for write errors, there is no value in recording block-oriented error status - only file-oriented status. For read errors, it might if help to avoid indefinite read retries, but I don't know the code well enough to be sure if this is an issue.

NeilBrown

Quoted 18 lines

James

Quoted 15 lines

The main argument I could see for keeping it is that removing it might subtly change the behavior of sync_file_range if you have tasks syncing different ranges in a file concurrently. I'm not sure if that would break any guarantees though.

Even if we do need it, I think we might need some cleanup here anyway. A lot of readpage operations end up setting that flag when they hit an error. Isn't it wrong to return an error on fsync, just because we had a read error somewhere in the file in a range that was never dirtied?

--
[1]: there is another place in f2fs, but it's more or less equivalent to the call site in __filemap_fdatawait_range.

#5 lore raw
Quoted 68 lines · James Bottomley
Quoted 20 lines · NeilBrown
Quoted 18 lines · James Bottomley

[added linux-scsi and linux-block because this is part of our error handling as well]

Quoted 14 lines · Jeff Layton

Proposing this as a LSF/MM TOPIC, but it may turn out to be me just not understanding the semantics here.

As I was looking into -ENOSPC handling in cephfs, I noticed that PG_error is only ever tested in one place [1] __filemap_fdatawait_range, which does this:

	if (TestClearPageError(page))
		ret = -EIO;

This error code will override any AS_* error that was set in the mapping. Which makes me wonder...why don't we just set this error in the mapping and not bother with a per-page flag? Could we potentially free up a page flag by eliminating this?

Quoted 6 lines
Quoted 3 lines

Note that currently the AS_* codes are only set for write errors not for reads and we have no mapping error handling at all for swap pages, but I'm sure this is fixable.

How is a read error different from a failure to set PG_uptodate? Does PG_error suppress retries?

We don't do any retries in the code above the block layer (or at least we shouldn't).

Quoted 10 lines
Quoted 7 lines

From the I/O layer point of view we take great pains to try to pinpoint the error exactly to the sector. We reflect this up by setting the PG_error flag on the page where the error occurred. If we only set the error on the mapping, we lose that granularity, because the mapping is mostly at the file level (or VMA level for anon pages).

Are you saying that the IO layer finds the page in the bi_io_vec and explicitly sets PG_error,

I didn't say anything about the mechanism. I think the function you're looking for is fs/mpage.c:mpage_end_io(). layers below block indicate the position in the request. Block maps the position to bio and the bio completion maps to page. So the actual granularity seen in the upper layer depends on how the page to bio mapping is done.

Quoted 2 lines

rather than just passing an error indication to bi_end_io ?? That
would seem to be wrong as the page may not be in the page cache.

Usually pages in the mpage_end_io path are pinned, I think.

Quoted 9 lines

So I guess I misunderstand you.

Quoted 4 lines

So I think the question for filesystem people from us would be do you care about this accuracy? If it's OK just to know an error occurred somewhere in this file, then perhaps we don't need it.

I had always assumed that a bio would either succeed or fail, and that no finer granularity could be available.

It does ... but a bio can be as small as a single page.

Quoted 2 lines

I think the question here is: Do filesystems need the pagecache to record which pages have seen an IO error?

Quoted 7 lines

It's not just filesystems. The partition code uses PageError() ... the metadata code might as well (those are things with no mapping). I'm not saying we can't remove PG_error; I am saying it's not going to be quite as simple as using the AS_ flags.

James

Ok, I see what you mean about the partition code. We may very well need to keep PG_error for things like that.

If we do, then it'd be good to spell out when and how filesystems should use it. Most of the usage seems to be the result of cargo-cult copying all over the place.

In particular, I think we might be best off not using PG_error for writeback errors in filesystems. It complicates the error path there and I don't see how it adds much benefit. It's also inconsistent as a stray sync() syscall can wipe the flag in most cases without reporting anything.

For filesystem read errors, it might make sense to keep it, but it'd be nice to see some guidelines about how it should be used there.

Quoted 26 lines
Quoted 26 lines

I think that for write errors, there is no value in recording block-oriented error status - only file-oriented status. For read errors, it might if help to avoid indefinite read retries, but I don't know the code well enough to be sure if this is an issue.

NeilBrown

Quoted 18 lines

James

Quoted 15 lines

The main argument I could see for keeping it is that removing it might subtly change the behavior of sync_file_range if you have tasks syncing different ranges in a file concurrently. I'm not sure if that would break any guarantees though.

Even if we do need it, I think we might need some cleanup here anyway. A lot of readpage operations end up setting that flag when they hit an error. Isn't it wrong to return an error on fsync, just because we had a read error somewhere in the file in a range that was never dirtied?

--
[1]: there is another place in f2fs, but it's more or less equivalent to the call site in __filemap_fdatawait_range.

Signature · 7 lines
Jeff Layton <[email protected]>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw
In reply to James Bottomley
Quoted 25 lines · James Bottomley
Quoted 24 lines · NeilBrown
Quoted 21 lines · James Bottomley

[added linux-scsi and linux-block because this is part of our error handling as well]

Quoted 7 lines · Jeff Layton

Proposing this as a LSF/MM TOPIC, but it may turn out to be me just not understanding the semantics here.

As I was looking into -ENOSPC handling in cephfs, I noticed that PG_error is only ever tested in one place [1] __filemap_fdatawait_range, which does this:

Quoted 7 lines
	if (TestClearPageError(page))
		ret = -EIO;

This error code will override any AS_* error that was set in the mapping. Which makes me wonder...why don't we just set this error in the mapping and not bother with a per-page flag? Could we potentially free up a page flag by eliminating this?

Note that currently the AS_* codes are only set for write errors not for reads and we have no mapping error handling at all for swap pages, but I'm sure this is fixable.

Quoted 5 lines
Quoted 2 lines

How is a read error different from a failure to set PG_uptodate? Does PG_error suppress retries?

We don't do any retries in the code above the block layer (or at least we shouldn't).

I was wondering about what would/should happen if a read request was re-issued for some reason. Should the error flag on the page cause an immediate failure, or should it try again.
If read-ahead sees a read-error on some future page, is it necessary to record the error so subsequent read-aheads don't notice the page is missing and repeatedly try to re-load it?
When the application eventually gets to the faulty page, should a read be tried then, or is the read-ahead failure permanent?

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

From the I/O layer point of view we take great pains to try to pinpoint the error exactly to the sector. We reflect this up by setting the PG_error flag on the page where the error occurred. If we only set the error on the mapping, we lose that granularity, because the mapping is mostly at the file level (or VMA level for anon pages).

Quoted 8 lines
Quoted 2 lines

Are you saying that the IO layer finds the page in the bi_io_vec and explicitly sets PG_error,

I didn't say anything about the mechanism. I think the function you're looking for is fs/mpage.c:mpage_end_io(). layers below block indicate the position in the request. Block maps the position to bio and the bio completion maps to page. So the actual granularity seen in the upper layer depends on how the page to bio mapping is done.

If the block layer is just returning the status at a per-bio level (which makes perfect sense), then this has nothing directly to do with the PG_error flag.

The page cache needs to do something with bi_error, but it isn't immediately clear that it needs to set PG_error.

Quoted 18 lines
Quoted 3 lines

rather than just passing an error indication to bi_end_io ?? That
would seem to be wrong as the page may not be in the page cache.

Usually pages in the mpage_end_io path are pinned, I think.

Quoted 9 lines

So I guess I misunderstand you.

Quoted 4 lines

So I think the question for filesystem people from us would be do you care about this accuracy? If it's OK just to know an error occurred somewhere in this file, then perhaps we don't need it.

I had always assumed that a bio would either succeed or fail, and that no finer granularity could be available.

It does ... but a bio can be as small as a single page.

Quoted 7 lines
Quoted 2 lines

I think the question here is: Do filesystems need the pagecache to record which pages have seen an IO error?

It's not just filesystems. The partition code uses PageError() ... the metadata code might as well (those are things with no mapping). I'm not saying we can't remove PG_error; I am saying it's not going to be quite as simple as using the AS_ flags.

The partition code could use PageUptodate().
mpage_end_io() calls page_endio() on each page, and on read error that calls:

			ClearPageUptodate(page);
			SetPageError(page);

are both of these necessary?

fs/buffer.c can use several bios to read a single page.
If any one returns an error, PG_error is set. When all of them have completed, if PG_error is clear, PG_uptodate is then set. This is an opportunistic use of PG_error, rather than an essential use. It could be "fixed", and would need to be fixed if we were to deprecate use of PG_error for read errors.
There are probably other usages like this.

Thanks,
NeilBrown

Quoted 29 lines

James

Quoted 26 lines

I think that for write errors, there is no value in recording block-oriented error status - only file-oriented status. For read errors, it might if help to avoid indefinite read retries, but I don't know the code well enough to be sure if this is an issue.

NeilBrown

Quoted 18 lines

James

Quoted 15 lines

The main argument I could see for keeping it is that removing it might subtly change the behavior of sync_file_range if you have tasks syncing different ranges in a file concurrently. I'm not sure if that would break any guarantees though.

Even if we do need it, I think we might need some cleanup here anyway. A lot of readpage operations end up setting that flag when they hit an error. Isn't it wrong to return an error on fsync, just because we had a read error somewhere in the file in a range that was never dirtied?

--
[1]: there is another place in f2fs, but it's more or less equivalent to the call site in __filemap_fdatawait_range.

#7 lore raw
Quoted 105 lines · NeilBrown
Quoted 25 lines · James Bottomley
Quoted 24 lines · NeilBrown
Quoted 21 lines · James Bottomley

[added linux-scsi and linux-block because this is part of our error handling as well]

Quoted 7 lines · Jeff Layton

Proposing this as a LSF/MM TOPIC, but it may turn out to be me just not understanding the semantics here.

As I was looking into -ENOSPC handling in cephfs, I noticed that PG_error is only ever tested in one place [1] __filemap_fdatawait_range, which does this:

Quoted 7 lines
	if (TestClearPageError(page))
		ret = -EIO;

This error code will override any AS_* error that was set in the mapping. Which makes me wonder...why don't we just set this error in the mapping and not bother with a per-page flag? Could we potentially free up a page flag by eliminating this?

Note that currently the AS_* codes are only set for write errors not for reads and we have no mapping error handling at all for swap pages, but I'm sure this is fixable.

Quoted 5 lines
Quoted 2 lines

How is a read error different from a failure to set PG_uptodate? Does PG_error suppress retries?

We don't do any retries in the code above the block layer (or at least we shouldn't).

I was wondering about what would/should happen if a read request was re-issued for some reason. Should the error flag on the page cause an immediate failure, or should it try again.
If read-ahead sees a read-error on some future page, is it necessary to record the error so subsequent read-aheads don't notice the page is missing and repeatedly try to re-load it?
When the application eventually gets to the faulty page, should a read be tried then, or is the read-ahead failure permanent?

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

From the I/O layer point of view we take great pains to try to pinpoint the error exactly to the sector. We reflect this up by setting the PG_error flag on the page where the error occurred. If we only set the error on the mapping, we lose that granularity, because the mapping is mostly at the file level (or VMA level for anon pages).

Quoted 8 lines
Quoted 2 lines

Are you saying that the IO layer finds the page in the bi_io_vec and explicitly sets PG_error,

I didn't say anything about the mechanism. I think the function you're looking for is fs/mpage.c:mpage_end_io(). layers below block indicate the position in the request. Block maps the position to bio and the bio completion maps to page. So the actual granularity seen in the upper layer depends on how the page to bio mapping is done.

If the block layer is just returning the status at a per-bio level (which makes perfect sense), then this has nothing directly to do with the PG_error flag.

The page cache needs to do something with bi_error, but it isn't immediately clear that it needs to set PG_error.

Quoted 18 lines

:q

Quoted 2 lines

rather than just passing an error indication to bi_end_io ?? That
would seem to be wrong as the page may not be in the page cache.

Usually pages in the mpage_end_io path are pinned, I think.

Quoted 9 lines

So I guess I misunderstand you.

Quoted 4 lines

So I think the question for filesystem people from us would be do you care about this accuracy? If it's OK just to know an error occurred somewhere in this file, then perhaps we don't need it.

I had always assumed that a bio would either succeed or fail, and that no finer granularity could be available.

It does ... but a bio can be as small as a single page.

Quoted 7 lines
Quoted 2 lines

I think the question here is: Do filesystems need the pagecache to record which pages have seen an IO error?

It's not just filesystems. The partition code uses PageError() ... the metadata code might as well (those are things with no mapping). I'm not saying we can't remove PG_error; I am saying it's not going to be quite as simple as using the AS_ flags.

The partition code could use PageUptodate().
mpage_end_io() calls page_endio() on each page, and on read error that calls:

			ClearPageUptodate(page);
			SetPageError(page);

are both of these necessary?

Quoted 8 lines

fs/buffer.c can use several bios to read a single page.
If any one returns an error, PG_error is set. When all of them have completed, if PG_error is clear, PG_uptodate is then set. This is an opportunistic use of PG_error, rather than an essential use. It could be "fixed", and would need to be fixed if we were to deprecate use of PG_error for read errors.
There are probably other usages like this.

Ok, I think I get it (somewhat):

The tricky part there is how to handle the PageError check in read_dev_sector if you don't use SetPageError in the result handler.

If we can count on read_pagecache_sector and read_dax_sector reliably returning an error when the page is considered to be in the cache (PageUpToDate) but had a read error, then that would work. I'm not sure how you'd indicate that without something like PG_error though if you don't want to retry on every attempt.

OTOH, if we want to always retry to read in pages that have had read errors when someone requests them, then we can simply not set PageUpToDate when readahead fails.

To chip away at the edges of this, what may make sense is to get this flag out of the writeback code as much as we can. When a write fails and SetPageError is called, we should also mark the mapping with an error. Then, we should be able to stop overriding the mapping error with -EIO in that codepath. Maybe call ClearPageError, or maybe leave it alone there?

Quoted 29 lines
Quoted 29 lines

James

Quoted 26 lines

I think that for write errors, there is no value in recording block-oriented error status - only file-oriented status. For read errors, it might if help to avoid indefinite read retries, but I don't know the code well enough to be sure if this is an issue.

NeilBrown

Quoted 18 lines

James

Quoted 15 lines

The main argument I could see for keeping it is that removing it might subtly change the behavior of sync_file_range if you have tasks syncing different ranges in a file concurrently. I'm not sure if that would break any guarantees though.

Even if we do need it, I think we might need some cleanup here anyway. A lot of readpage operations end up setting that flag when they hit an error. Isn't it wrong to return an error on fsync, just because we had a read error somewhere in the file in a range that was never dirtied?

--
[1]: there is another place in f2fs, but it's more or less equivalent to the call site in __filemap_fdatawait_range.

Signature · 7 lines
Jeff Layton <[email protected]>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#8 lore raw
Quoted 131 lines · Jeff Layton
Quoted 105 lines · NeilBrown
Quoted 25 lines · James Bottomley
Quoted 24 lines · NeilBrown
Quoted 21 lines · James Bottomley

[added linux-scsi and linux-block because this is part of our error handling as well]

Quoted 7 lines · Jeff Layton

Proposing this as a LSF/MM TOPIC, but it may turn out to be me just not understanding the semantics here.

As I was looking into -ENOSPC handling in cephfs, I noticed that PG_error is only ever tested in one place [1] __filemap_fdatawait_range, which does this:

Quoted 7 lines
	if (TestClearPageError(page))
		ret = -EIO;

This error code will override any AS_* error that was set in the mapping. Which makes me wonder...why don't we just set this error in the mapping and not bother with a per-page flag? Could we potentially free up a page flag by eliminating this?

Note that currently the AS_* codes are only set for write errors not for reads and we have no mapping error handling at all for swap pages, but I'm sure this is fixable.

Quoted 5 lines
Quoted 2 lines

How is a read error different from a failure to set PG_uptodate? Does PG_error suppress retries?

We don't do any retries in the code above the block layer (or at least we shouldn't).

I was wondering about what would/should happen if a read request was re-issued for some reason. Should the error flag on the page cause an immediate failure, or should it try again.
If read-ahead sees a read-error on some future page, is it necessary to record the error so subsequent read-aheads don't notice the page is missing and repeatedly try to re-load it?
When the application eventually gets to the faulty page, should a read be tried then, or is the read-ahead failure permanent?

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

From the I/O layer point of view we take great pains to try to pinpoint the error exactly to the sector. We reflect this up by setting the PG_error flag on the page where the error occurred. If we only set the error on the mapping, we lose that granularity, because the mapping is mostly at the file level (or VMA level for anon pages).

Quoted 8 lines
Quoted 2 lines

Are you saying that the IO layer finds the page in the bi_io_vec and explicitly sets PG_error,

I didn't say anything about the mechanism. I think the function you're looking for is fs/mpage.c:mpage_end_io(). layers below block indicate the position in the request. Block maps the position to bio and the bio completion maps to page. So the actual granularity seen in the upper layer depends on how the page to bio mapping is done.

If the block layer is just returning the status at a per-bio level (which makes perfect sense), then this has nothing directly to do with the PG_error flag.

The page cache needs to do something with bi_error, but it isn't immediately clear that it needs to set PG_error.

Quoted 18 lines

:q

Quoted 2 lines

rather than just passing an error indication to bi_end_io ?? That would seem to be wrong as the page may not be in the page cache.

Usually pages in the mpage_end_io path are pinned, I think.

Quoted 9 lines

So I guess I misunderstand you.

Quoted 4 lines

So I think the question for filesystem people from us would be do you care about this accuracy? If it's OK just to know an error occurred somewhere in this file, then perhaps we don't need it.

I had always assumed that a bio would either succeed or fail, and that no finer granularity could be available.

It does ... but a bio can be as small as a single page.

Quoted 7 lines
Quoted 2 lines

I think the question here is: Do filesystems need the pagecache to record which pages have seen an IO error?

It's not just filesystems. The partition code uses PageError() ... the metadata code might as well (those are things with no mapping). I'm not saying we can't remove PG_error; I am saying it's not going to be quite as simple as using the AS_ flags.

The partition code could use PageUptodate().
mpage_end_io() calls page_endio() on each page, and on read error that calls:

			ClearPageUptodate(page);
			SetPageError(page);

are both of these necessary?

Quoted 8 lines

fs/buffer.c can use several bios to read a single page.
If any one returns an error, PG_error is set. When all of them have completed, if PG_error is clear, PG_uptodate is then set. This is an opportunistic use of PG_error, rather than an essential use. It could be "fixed", and would need to be fixed if we were to deprecate use of PG_error for read errors.
There are probably other usages like this.

Ok, I think I get it (somewhat):

The tricky part there is how to handle the PageError check in read_dev_sector if you don't use SetPageError in the result handler.

If we can count on read_pagecache_sector and read_dax_sector reliably returning an error when the page is considered to be in the cache (PageUpToDate) but had a read error, then that would work. I'm not sure how you'd indicate that without something like PG_error though if you don't want to retry on every attempt.

OTOH, if we want to always retry to read in pages that have had read errors when someone requests them, then we can simply not set PageUpToDate when readahead fails.

Quoted 6 lines

To chip away at the edges of this, what may make sense is to get this flag out of the writeback code as much as we can. When a write fails and SetPageError is called, we should also mark the mapping with an error. Then, we should be able to stop overriding the mapping error with -EIO in that codepath. Maybe call ClearPageError, or maybe leave it alone there?

My thought is that PG_error is definitely useful for applications to get correct errors back when doing write()/sync_file_range() so that they know there is an error in the data that _they_ wrote, rather than receiving an error for data that may have been written by another thread, and in turn clearing the error from another thread so it *doesn't* know it had a write error.

As for stray sync() clearing PG_error from underneath an application, that shouldn't happen since filemap_fdatawait_keep_errors() doesn't clear errors and is used by device flushing code (fdatawait_one_bdev(), wait_sb_inodes()).

Cheers, Andreas

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines

James

Quoted 22 lines

I think that for write errors, there is no value in recording block-oriented error status - only file-oriented status. For read errors, it might if help to avoid indefinite read retries, but I don't know the code well enough to be sure if this is an issue.

NeilBrown

Quoted 14 lines

James

Quoted 11 lines

The main argument I could see for keeping it is that removing it might subtly change the behavior of sync_file_range if you have tasks syncing different ranges in a file concurrently. I'm not sure if that would break any guarantees though.

Even if we do need it, I think we might need some cleanup here anyway. A lot of readpage operations end up setting that flag when they hit an error. Isn't it wrong to return an error on fsync, just because we had a read error somewhere in the file in a range that was never dirtied?

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

--
[1]: there is another place in f2fs, but it's more or less equivalent to the call site in __filemap_fdatawait_range.

--
Jeff Layton <[email protected]>

Cheers, Andreas

#9 lore raw
Quoted 138 lines · Andreas Dilger
Quoted 130 lines · Jeff Layton
Quoted 104 lines · NeilBrown
Quoted 25 lines · James Bottomley
Quoted 24 lines · NeilBrown
Quoted 21 lines · James Bottomley

[added linux-scsi and linux-block because this is part of our error handling as well]

Quoted 7 lines · Jeff Layton

Proposing this as a LSF/MM TOPIC, but it may turn out to be me just not understanding the semantics here.

As I was looking into -ENOSPC handling in cephfs, I noticed that PG_error is only ever tested in one place [1] __filemap_fdatawait_range, which does this:

Quoted 7 lines
	if (TestClearPageError(page))
		ret = -EIO;

This error code will override any AS_* error that was set in the mapping. Which makes me wonder...why don't we just set this error in the mapping and not bother with a per-page flag? Could we potentially free up a page flag by eliminating this?

Note that currently the AS_* codes are only set for write errors not for reads and we have no mapping error handling at all for swap pages, but I'm sure this is fixable.

Quoted 5 lines
Quoted 2 lines

How is a read error different from a failure to set PG_uptodate? Does PG_error suppress retries?

We don't do any retries in the code above the block layer (or at least we shouldn't).

I was wondering about what would/should happen if a read request was re-issued for some reason. Should the error flag on the page cause an immediate failure, or should it try again.
If read-ahead sees a read-error on some future page, is it necessary to record the error so subsequent read-aheads don't notice the page is missing and repeatedly try to re-load it?
When the application eventually gets to the faulty page, should a read be tried then, or is the read-ahead failure permanent?

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

From the I/O layer point of view we take great pains to try to pinpoint the error exactly to the sector. We reflect this up by setting the PG_error flag on the page where the error occurred. If we only set the error on the mapping, we lose that granularity, because the mapping is mostly at the file level (or VMA level for anon pages).

Quoted 8 lines
Quoted 2 lines

Are you saying that the IO layer finds the page in the bi_io_vec and explicitly sets PG_error,

I didn't say anything about the mechanism. I think the function you're looking for is fs/mpage.c:mpage_end_io(). layers below block indicate the position in the request. Block maps the position to bio and the bio completion maps to page. So the actual granularity seen in the upper layer depends on how the page to bio mapping is done.

If the block layer is just returning the status at a per-bio level (which makes perfect sense), then this has nothing directly to do with the PG_error flag.

The page cache needs to do something with bi_error, but it isn't immediately clear that it needs to set PG_error.

Quoted 18 lines

:q

Quoted 2 lines

rather than just passing an error indication to bi_end_io ?? That would seem to be wrong as the page may not be in the page cache.

Usually pages in the mpage_end_io path are pinned, I think.

Quoted 9 lines

So I guess I misunderstand you.

Quoted 4 lines

So I think the question for filesystem people from us would be do you care about this accuracy? If it's OK just to know an error occurred somewhere in this file, then perhaps we don't need it.

I had always assumed that a bio would either succeed or fail, and that no finer granularity could be available.

It does ... but a bio can be as small as a single page.

Quoted 7 lines
Quoted 2 lines

I think the question here is: Do filesystems need the pagecache to record which pages have seen an IO error?

It's not just filesystems. The partition code uses PageError() ... the metadata code might as well (those are things with no mapping). I'm not saying we can't remove PG_error; I am saying it's not going to be quite as simple as using the AS_ flags.

The partition code could use PageUptodate().
mpage_end_io() calls page_endio() on each page, and on read error that calls:

			ClearPageUptodate(page);
			SetPageError(page);

are both of these necessary?

Quoted 8 lines

fs/buffer.c can use several bios to read a single page.
If any one returns an error, PG_error is set. When all of them have completed, if PG_error is clear, PG_uptodate is then set. This is an opportunistic use of PG_error, rather than an essential use. It could be "fixed", and would need to be fixed if we were to deprecate use of PG_error for read errors.
There are probably other usages like this.

Ok, I think I get it (somewhat):

The tricky part there is how to handle the PageError check in read_dev_sector if you don't use SetPageError in the result handler.

If we can count on read_pagecache_sector and read_dax_sector reliably returning an error when the page is considered to be in the cache (PageUpToDate) but had a read error, then that would work. I'm not sure how you'd indicate that without something like PG_error though if you don't want to retry on every attempt.

OTOH, if we want to always retry to read in pages that have had read errors when someone requests them, then we can simply not set PageUpToDate when readahead fails.

Quoted 6 lines

To chip away at the edges of this, what may make sense is to get this flag out of the writeback code as much as we can. When a write fails and SetPageError is called, we should also mark the mapping with an error. Then, we should be able to stop overriding the mapping error with -EIO in that codepath. Maybe call ClearPageError, or maybe leave it alone there?

Quoted 7 lines

My thought is that PG_error is definitely useful for applications to get correct errors back when doing write()/sync_file_range() so that they know there is an error in the data that _they_ wrote, rather than receiving an error for data that may have been written by another thread, and in turn clearing the error from another thread so it *doesn't* know it had a write error.

Right, that was my point about sync_file_range. Today I think you can call sync_file_range and if your range didn't hit errors (none of you PG_error bits are set), then you might get back 0 (iff the mapping had no error flagged on it).

The question I have is: is that the semantics that sync_file_range is supposed to have? It's not clear from the manpage whether errors are supposed to be that granular or not.

It's also the case that not all writepage implementations set the PG_error flag. There is a lot of variation here, and so we end up with different semantics on different filesystems. That's less than ideal.

Quoted 5 lines

As for stray sync() clearing PG_error from underneath an application, that shouldn't happen since filemap_fdatawait_keep_errors() doesn't clear errors and is used by device flushing code (fdatawait_one_bdev(), wait_sb_inodes()).

It sure looks like it does to me. Am I missing something?

filemap_fdatawait_keep_errors calls __filemap_fdatawait_range, which finds pages and waits on their writeback bit to clear. Once it does that, it calls TestClearPageError and sets the return to -EIO if the bit was set. That should result in all of the PG_error bits being cleared on a sync() call, right?

Signature · 1 line
Jeff Layton <[email protected]>
#10 lore raw
In reply to Andreas Dilger
Quoted 7 lines · Andreas Dilger

My thought is that PG_error is definitely useful for applications to get correct errors back when doing write()/sync_file_range() so that they know there is an error in the data that _they_ wrote, rather than receiving an error for data that may have been written by another thread, and in turn clearing the error from another thread so it *doesn't* know it had a write error.

It might be useful in that way, but it is not currently used that way. Such usage would be a change in visible behaviour.

sync_file_range() calls filemap_fdatawait_range(), which calls filemap_check_errors().
If there have been any errors in the file recently, inside or outside the range, the latter will return an error which will propagate up.

Quoted 4 lines

As for stray sync() clearing PG_error from underneath an application, that shouldn't happen since filemap_fdatawait_keep_errors() doesn't clear errors and is used by device flushing code (fdatawait_one_bdev(), wait_sb_inodes()).

filemap_fdatawait_keep_errors() calls __filemap_fdatawait_range() which clears PG_error on every page.
What it doesn't do is call filemap_check_errors(), and so doesn't clear AS_ENOSPC or AS_EIO.

NeilBrown

#11 lore raw
Quoted 19 lines · NeilBrown
Quoted 7 lines · Andreas Dilger

My thought is that PG_error is definitely useful for applications to get correct errors back when doing write()/sync_file_range() so that they know there is an error in the data that _they_ wrote, rather than receiving an error for data that may have been written by another thread, and in turn clearing the error from another thread so it *doesn't* know it had a write error.

It might be useful in that way, but it is not currently used that way. Such usage would be a change in visible behaviour.

sync_file_range() calls filemap_fdatawait_range(), which calls filemap_check_errors().
If there have been any errors in the file recently, inside or outside the range, the latter will return an error which will propagate up.

Quoted 1 line
Quoted 10 lines
Quoted 3 lines

As for stray sync() clearing PG_error from underneath an application, that shouldn't happen since filemap_fdatawait_keep_errors() doesn't clear errors and is used by device flushing code (fdatawait_one_bdev(), wait_sb_inodes()).

filemap_fdatawait_keep_errors() calls __filemap_fdatawait_range() which clears PG_error on every page.
What it doesn't do is call filemap_check_errors(), and so doesn't clear AS_ENOSPC or AS_EIO.

I think it's helpful to get a clear idea of what happens now in the face of errors and what we expect to happen, and I don't quite have that yet:

--------------------------8<----------------------------- void page_endio(struct page *page, bool is_write, int err) {
        if (!is_write) {
                if (!err) {
                        SetPageUptodate(page);
                } else {
                        ClearPageUptodate(page); SetPageError(page);
                }
                unlock_page(page);
        } else {
                if (err) {
                        SetPageError(page);
                        if (page->mapping) mapping_set_error(page->mapping, err); }
                end_page_writeback(page);
        }
}
--------------------------8<-----------------------------

...not everything uses page_endio, but it's a good place to look since we have both flavors of error handling in one place.

On a write error, we SetPageError and set the error in the mapping.

What I'm not clear on is:

1) what happens to the page at that point when we get a writeback error? Does it just remain in-core and is allowed to service reads (assuming that it was uptodate before)?

Can I redirty it and have it retry the write? Is there standard behavior for this or is it just up to the whim of the filesystem?

I'll probably have questions about the read side as well, but for now it looks like it's mostly used in an ad-hoc way to communicate errors across subsystems (block to fs layer, for instance).
--
Jeff Layton <[email protected]>

#12 lore raw

On 02/28/2017 03:11 AM, Jeff Layton wrote:
<>

Quoted 4 lines

I'll probably have questions about the read side as well, but for now it looks like it's mostly used in an ad-hoc way to communicate errors across subsystems (block to fs layer, for instance).

If memory does not fail me it used to be checked long time ago in the read-ahead case. On the buffered read case, the first page is read synchronous and any error is returned to the caller, but then a read-ahead chunk is read async all the while the original thread returned to the application. So any errors are only recorded on the page-bit, since otherwise the uptodate is off and the IO will be retransmitted. Then the move to read_iter changed all that I think.
But again this is like 5-6 years ago, and maybe I didn't even understand very well.

Quoted 3 lines

--
Jeff Layton <[email protected]>

I would like a Documentation of all this as well please. Where are the tests for this?

Thanks
Boaz

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw
Quoted 7 lines · Boaz Harrosh

On 02/28/2017 03:11 AM, Jeff Layton wrote:
<>

Quoted 4 lines

I'll probably have questions about the read side as well, but for now it looks like it's mostly used in an ad-hoc way to communicate errors across subsystems (block to fs layer, for instance).

Quoted 10 lines

If memory does not fail me it used to be checked long time ago in the read-ahead case. On the buffered read case, the first page is read synchronous and any error is returned to the caller, but then a read-ahead chunk is read async all the while the original thread returned to the application. So any errors are only recorded on the page-bit, since otherwise the uptodate is off and the IO will be retransmitted. Then the move to read_iter changed all that I think.
But again this is like 5-6 years ago, and maybe I didn't even understand very well.

Yep, that's what I meant about using it to communicate errors between layers. e.g. end_buffer_async_read will check PageError and only SetPageUptodate if it's not set. That has morphed a lot in the last few years though and it looks like it may rely on PG_error less than it used to.

Quoted 4 lines

I would like a Documentation of all this as well please. Where are the tests for this?

Documentation is certainly doable (and I'd like to write some once we have this all straightened out). In particular, I think we need clear guidelines for fs authors on how to handle pagecache read and write errors. Tests are a little tougher -- this is all kernel-internal stuff and not easily visible to userland.

The one thing I have noticed is that even if you set AS_ENOSPC in the mapping, you'll still get back -EIO on the first fsync if any PG_error bits are set. I think we ought to fix that by not doing the TestClearPageError call in __filemap_fdatawait_range, and just rely on the mapping error there.

We could maybe roll a test for that, but it's rather hard to test ENOSPC conditions in a fs-agnostic way. I'm open to suggestions here though.

Signature · 1 line
Jeff Layton <[email protected]>
#14 lore raw
In reply to Jeff Layton
Quoted 59 lines · Jeff Layton
Quoted 19 lines · NeilBrown
Quoted 7 lines · Andreas Dilger

My thought is that PG_error is definitely useful for applications to get correct errors back when doing write()/sync_file_range() so that they know there is an error in the data that _they_ wrote, rather than receiving an error for data that may have been written by another thread, and in turn clearing the error from another thread so it *doesn't* know it had a write error.

It might be useful in that way, but it is not currently used that way. Such usage would be a change in visible behaviour.

sync_file_range() calls filemap_fdatawait_range(), which calls filemap_check_errors().
If there have been any errors in the file recently, inside or outside the range, the latter will return an error which will propagate up.

Quoted 1 line
Quoted 10 lines
Quoted 3 lines

As for stray sync() clearing PG_error from underneath an application, that shouldn't happen since filemap_fdatawait_keep_errors() doesn't clear errors and is used by device flushing code (fdatawait_one_bdev(), wait_sb_inodes()).

filemap_fdatawait_keep_errors() calls __filemap_fdatawait_range() which clears PG_error on every page.
What it doesn't do is call filemap_check_errors(), and so doesn't clear AS_ENOSPC or AS_EIO.

I think it's helpful to get a clear idea of what happens now in the face of errors and what we expect to happen, and I don't quite have that yet:

--------------------------8<----------------------------- void page_endio(struct page *page, bool is_write, int err) {
        if (!is_write) {
                if (!err) {
                        SetPageUptodate(page);
                } else {
                        ClearPageUptodate(page); SetPageError(page);
                }
                unlock_page(page);
        } else {
                if (err) {
                        SetPageError(page);
                        if (page->mapping) mapping_set_error(page->mapping, err); }
                end_page_writeback(page);
        }
}
--------------------------8<-----------------------------

...not everything uses page_endio, but it's a good place to look since we have both flavors of error handling in one place.

Quoted 7 lines

On a write error, we SetPageError and set the error in the mapping.

What I'm not clear on is:

1) what happens to the page at that point when we get a writeback error? Does it just remain in-core and is allowed to service reads (assuming that it was uptodate before)?

Yes, it remains in core and can service reads. It is no different from a page on which a write recent succeeded, except that the write didn't succeed so the contents of backing store might be different from the contents of the page.

Quoted 3 lines

Can I redirty it and have it retry the write? Is there standard behavior for this or is it just up to the whim of the filesystem?

Everything is at the whim of the filesystem, but I doubt if many differ from the above.

NeilBrown

Quoted 6 lines

I'll probably have questions about the read side as well, but for now it looks like it's mostly used in an ad-hoc way to communicate errors across subsystems (block to fs layer, for instance).
--
Jeff Layton <[email protected]>