mm: Do not reclaim private data from pinned page
Subsystems (4)
Jan Kara
reviewerPATCH 1/1 mm: Do not reclaim private data from pinned page
If the page is pinned, there's no point in trying to reclaim it. Furthermore if the page is from the page cache we don't want to reclaim fs-private data from the page because the pinning process may be writing to the page at any time and reclaiming fs private info on a dirty page can upset the filesystem (see link below).
--- mm/vmscan.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
This was the non-controversial part of my series [1] dealing with pinned pages in filesystems. It is already a win as it avoids crashes in the filesystem and we can drop workarounds for this in ext4. Can we merge it please?
[1] https://lore.kernel.org/all/[email protected]/
mm/vmscan.c +10 -0
@@ -1901,6 +1901,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, } } +/* +* Folio is unmapped now so it cannot be newly pinned anymore. +* No point in trying to reclaim folio if it is pinned. +* Furthermore we don't want to reclaim underlying fs metadata +* if the folio is pinned and thus potentially modified by the +* pinning process as that may upset the filesystem. +*/ +if (folio_maybe_dma_pinned (folio)) + goto activate_locked; + mapping =folio_mapping (folio);if (folio_test_dirty (folio)) {/*
Signature · 1 line
2.35.3
Quoted 8 lines · Jan Kara
If the page is pinned, there's no point in trying to reclaim it. Furthermore if the page is from the page cache we don't want to reclaim fs-private data from the page because the pinning process may be writing to the page at any time and reclaiming fs private info on a dirty page can upset the filesystem (see link below).
Quoted 40 lines · Jan Kara
If the page is pinned, there's no point in trying to reclaim it. Furthermore if the page is from the page cache we don't want to reclaim fs-private data from the page because the pinning process may be writing to the page at any time and reclaiming fs private info on a dirty page can upset the filesystem (see link below).
Signed-off-by Jan Kara <[email protected]>--- mm/vmscan.c | 10 ++++++++++ 1 file changed, 10 insertions(+)This was the non-controversial part of my series [1] dealing with pinned pages in filesystems. It is already a win as it avoids crashes in the filesystem and we can drop workarounds for this in ext4. Can we merge it please?
[1] https://lore.kernel.org/all/[email protected]/
mm/vmscan.c +10
-1@@ -1901,6 +1901,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, } } +/* +* Folio is unmapped now so it cannot be newly pinned anymore. +* No point in trying to reclaim folio if it is pinned. +* Furthermore we don't want to reclaim underlying fs metadata +* if the folio is pinned and thus potentially modified by the +* pinning process as that may upset the filesystem. +*/ +if (folio_maybe_dma_pinned (folio)) + goto activate_locked; + mapping =folio_mapping (folio);if (folio_test_dirty (folio)) {/* --
Quoted 2 lines
2.35.3
This seems very sensible and helps ameliorate problematic GUP/file interactions so this seems a no-brainer.
Quoted 5 lines · Jan Kara
If the page is pinned, there's no point in trying to reclaim it. Furthermore if the page is from the page cache we don't want to reclaim fs-private data from the page because the pinning process may be writing to the page at any time and reclaiming fs private info on a dirty page can upset the filesystem (see link below).
Looks good:
Quoted 26 lines · Jan Kara
If the page is pinned, there's no point in trying to reclaim it. Furthermore if the page is from the page cache we don't want to reclaim fs-private data from the page because the pinning process may be writing to the page at any time and reclaiming fs private info on a dirty page can upset the filesystem (see link below).
Signed-off-by Jan Kara <[email protected]>--- mm/vmscan.c | 10 ++++++++++ 1 file changed, 10 insertions(+)This was the non-controversial part of my series [1] dealing with pinned pages in filesystems. It is already a win as it avoids crashes in the filesystem and we can drop workarounds for this in ext4. Can we merge it please?
[1] https://lore.kernel.org/all/[email protected]/
mm/vmscan.c +0
-0@@ -1901,6 +1901,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, } }
mm/vmscan.c static unsigned int shrink_folio_list(struct list_head *folio_list, · line 1913
Quoted 10 lines
mm/vmscan.c +10
-0+/* +* Folio is unmapped now so it cannot be newly pinned anymore. +* No point in trying to reclaim folio if it is pinned. +* Furthermore we don't want to reclaim underlying fs metadata +* if the folio is pinned and thus potentially modified by the +* pinning process as that may upset the filesystem. +*/ +if (folio_maybe_dma_pinned (folio)) + goto activate_locked; +
This is huge! At long last. In fact, with this in the queue, I'm going to close out our internal bug report from 2018 that launched this whole maybe-dma-pinned odyssey. :)
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Quoted 3 lines
mm/vmscan.c +0
-0mapping =folio_mapping (folio);if (folio_test_dirty (folio)) {/*
Quoted 29 lines · Jan Kara
If the page is pinned, there's no point in trying to reclaim it. Furthermore if the page is from the page cache we don't want to reclaim fs-private data from the page because the pinning process may be writing to the page at any time and reclaiming fs private info on a dirty page can upset the filesystem (see link below).
Signed-off-by Jan Kara <[email protected]>--- mm/vmscan.c | 10 ++++++++++ 1 file changed, 10 insertions(+)This was the non-controversial part of my series [1] dealing with pinned pages in filesystems. It is already a win as it avoids crashes in the filesystem and we can drop workarounds for this in ext4. Can we merge it please?
[1] https://lore.kernel.org/all/[email protected]/
mm/vmscan.c +3
-0@@ -1901,6 +1901,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, } } +/* +* Folio is unmapped now so it cannot be newly pinned anymore. +* No point in trying to reclaim folio if it is pinned.
mm/vmscan.c static unsigned int shrink_folio_list(struct list_head *folio_list, · line 1916
Quoted 10 lines
mm/vmscan.c +7
-0+* Furthermore we don't want to reclaim underlying fs metadata +* if the folio is pinned and thus potentially modified by the +* pinning process as that may upset the filesystem. +*/ +if (folio_maybe_dma_pinned (folio)) + goto activate_locked; + mapping =folio_mapping (folio);if (folio_test_dirty (folio)) {/*
Thanks!
Signature · 3 lines
Thanks, David / dhildenb
Quoted 43 lines · Jan Kara
If the page is pinned, there's no point in trying to reclaim it. Furthermore if the page is from the page cache we don't want to reclaim fs-private data from the page because the pinning process may be writing to the page at any time and reclaiming fs private info on a dirty page can upset the filesystem (see link below).
Signed-off-by Jan Kara <[email protected]>--- mm/vmscan.c | 10 ++++++++++ 1 file changed, 10 insertions(+)This was the non-controversial part of my series [1] dealing with pinned pages in filesystems. It is already a win as it avoids crashes in the filesystem and we can drop workarounds for this in ext4. Can we merge it please?
[1] https://lore.kernel.org/all/[email protected]/
mm/vmscan.c +10
-0@@ -1901,6 +1901,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, } } +/* +* Folio is unmapped now so it cannot be newly pinned anymore. +* No point in trying to reclaim folio if it is pinned. +* Furthermore we don't want to reclaim underlying fs metadata +* if the folio is pinned and thus potentially modified by the +* pinning process as that may upset the filesystem. +*/ +if (folio_maybe_dma_pinned (folio)) + goto activate_locked; + mapping =folio_mapping (folio);if (folio_test_dirty (folio)) {/* Signature · 1 line
2.35.3
IIUC we have similar handling for anon (feb889fb40fafc). Should we merge the two sites and just move the check earlier? Thanks,
Signature · 1 line
Peter Xu
Quoted 39 lines · Peter Xu
Quoted 38 lines · Jan Kara
If the page is pinned, there's no point in trying to reclaim it. Furthermore if the page is from the page cache we don't want to reclaim fs-private data from the page because the pinning process may be writing to the page at any time and reclaiming fs private info on a dirty page can upset the filesystem (see link below).
Signed-off-by Jan Kara <[email protected]>--- mm/vmscan.c | 10 ++++++++++ 1 file changed, 10 insertions(+)This was the non-controversial part of my series [1] dealing with pinned pages in filesystems. It is already a win as it avoids crashes in the filesystem and we can drop workarounds for this in ext4. Can we merge it please?
[1] https://lore.kernel.org/all/[email protected]/
mm/vmscan.c +10
-0@@ -1901,6 +1901,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, } } +/* +* Folio is unmapped now so it cannot be newly pinned anymore. +* No point in trying to reclaim folio if it is pinned. +* Furthermore we don't want to reclaim underlying fs metadata +* if the folio is pinned and thus potentially modified by the +* pinning process as that may upset the filesystem. +*/ +if (folio_maybe_dma_pinned (folio)) + goto activate_locked; + mapping =folio_mapping (folio);if (folio_test_dirty (folio)) {
Quoted 9 lines
Quoted 5 lines
mm/vmscan.c +0
-0/* Signature · 1 line
2.35.3IIUC we have similar handling for anon (
feb889fb40fafc). Should we merge the two sites and just move the check earlier? Thanks,
feb889fb40fafc introduced a best-effort check that is racy, as the page is still mapped (can still get pinned). Further, we get false positives most only if a page is shared very often (1024 times), which happens rarely with anon pages. Now that we handle COW+pinning correctly using PageAnonExclusive, that check only optimizes for the "already pinned" case. But it's not required for correctness anymore (so it can be racy).
Here, however, we want more precision, and not false positives simply because a page is mapped many times (which can happen easily) or can still get pinned while mapped.
Signature · 3 lines
Thanks, David / dhildenb
Peter Xu
Acked-byQuoted 56 lines · David Hildenbrand
Quoted 38 lines · Peter Xu
Quoted 37 lines · Jan Kara
If the page is pinned, there's no point in trying to reclaim it. Furthermore if the page is from the page cache we don't want to reclaim fs-private data from the page because the pinning process may be writing to the page at any time and reclaiming fs private info on a dirty page can upset the filesystem (see link below).
Signed-off-by Jan Kara <[email protected]>--- mm/vmscan.c | 10 ++++++++++ 1 file changed, 10 insertions(+)This was the non-controversial part of my series [1] dealing with pinned pages in filesystems. It is already a win as it avoids crashes in the filesystem and we can drop workarounds for this in ext4. Can we merge it please?
[1] https://lore.kernel.org/all/[email protected]/
mm/vmscan.c +10
-0@@ -1901,6 +1901,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, } } +/* +* Folio is unmapped now so it cannot be newly pinned anymore. +* No point in trying to reclaim folio if it is pinned. +* Furthermore we don't want to reclaim underlying fs metadata +* if the folio is pinned and thus potentially modified by the +* pinning process as that may upset the filesystem. +*/ +if (folio_maybe_dma_pinned (folio)) + goto activate_locked; + mapping =folio_mapping (folio);if (folio_test_dirty (folio)) {Quoted 9 lines
Quoted 5 lines
mm/vmscan.c +0
-0/* Signature · 1 line
2.35.3IIUC we have similar handling for anon (
feb889fb40fafc). Should we merge the two sites and just move the check earlier? Thanks,
feb889fb40fafcintroduced a best-effort check that is racy, as the page is still mapped (can still get pinned). Further, we get false positives most only if a page is shared very often (1024 times), which happens rarely with anon pages. Now that we handle COW+pinning correctly using PageAnonExclusive, that check only optimizes for the "already pinned" case. But it's not required for correctness anymore (so it can be racy).
Quoted 3 lines
Here, however, we want more precision, and not false positives simply because a page is mapped many times (which can happen easily) or can still get pinned while mapped.
Ah makes sense, thanks.
This seems not obvious, though, if we simply read the two commits. It'll be great if we mention it somewhere in either comment or commit message on the relationship of the two checks.
Signature · 1 line
Peter Xu
Quoted 61 lines · Peter Xu
Quoted 56 lines · David Hildenbrand
Quoted 38 lines · Peter Xu
Quoted 37 lines · Jan Kara
If the page is pinned, there's no point in trying to reclaim it. Furthermore if the page is from the page cache we don't want to reclaim fs-private data from the page because the pinning process may be writing to the page at any time and reclaiming fs private info on a dirty page can upset the filesystem (see link below).
Signed-off-by Jan Kara <[email protected]>--- mm/vmscan.c | 10 ++++++++++ 1 file changed, 10 insertions(+)This was the non-controversial part of my series [1] dealing with pinned pages in filesystems. It is already a win as it avoids crashes in the filesystem and we can drop workarounds for this in ext4. Can we merge it please?
[1] https://lore.kernel.org/all/[email protected]/
mm/vmscan.c +10
-0@@ -1901,6 +1901,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, } } +/* +* Folio is unmapped now so it cannot be newly pinned anymore. +* No point in trying to reclaim folio if it is pinned. +* Furthermore we don't want to reclaim underlying fs metadata +* if the folio is pinned and thus potentially modified by the +* pinning process as that may upset the filesystem. +*/ +if (folio_maybe_dma_pinned (folio)) + goto activate_locked; + mapping =folio_mapping (folio);if (folio_test_dirty (folio)) {Quoted 9 lines
Quoted 5 lines
mm/vmscan.c +0
-0/* Signature · 1 line
2.35.3IIUC we have similar handling for anon (
feb889fb40fafc). Should we merge the two sites and just move the check earlier? Thanks,
feb889fb40fafcintroduced a best-effort check that is racy, as the page is still mapped (can still get pinned). Further, we get false positives most only if a page is shared very often (1024 times), which happens rarely with anon pages. Now that we handle COW+pinning correctly using PageAnonExclusive, that check only optimizes for the "already pinned" case. But it's not required for correctness anymore (so it can be racy).Quoted 3 lines
Here, however, we want more precision, and not false positives simply because a page is mapped many times (which can happen easily) or can still get pinned while mapped.
Quoted 7 lines
Ah makes sense, thanks.
Acked-by Peter Xu <[email protected]>This seems not obvious, though, if we simply read the two commits. It'll be great if we mention it somewhere in either comment or commit message on the relationship of the two checks.
I once had a patch lying around to document the existing check:
https://github.com/davidhildenbrand/linux/commit/abb01d42a99b56e2c5e707ba80ddc8b05ad7d618
Signature · 3 lines
Thanks, David / dhildenb
Andrew Morton
maintainerQuoted 5 lines · On Fri, 28 Apr 2023 14:41:40 +0200 Jan Kara <[email protected]> wrote:
If the page is pinned, there's no point in trying to reclaim it. Furthermore if the page is from the page cache we don't want to reclaim fs-private data from the page because the pinning process may be writing to the page at any time and reclaiming fs private info on a dirty page can upset the filesystem (see link below).
Obviously I'll add a cc:stable here. I'm suspecting it's so old that there's no real Fixes: target that makes sense?
Quoted 6 lines
mm/vmscan.c +0
-0@@ -1901,6 +1901,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, } }
mm/vmscan.c static unsigned int shrink_folio_list(struct list_head *folio_list, · line 1913
Quoted 10 lines
mm/vmscan.c +10
-0+/* +* Folio is unmapped now so it cannot be newly pinned anymore. +* No point in trying to reclaim folio if it is pinned. +* Furthermore we don't want to reclaim underlying fs metadata +* if the folio is pinned and thus potentially modified by the +* pinning process as that may upset the filesystem. +*/ +if (folio_maybe_dma_pinned (folio)) + goto activate_locked; +
So I expect the -stable maintainers will be looking for a pre-folios version of this when the time comes.
Jan Kara
reviewerQuoted 10 lines · Andrew Morton
Quoted 5 lines · On Fri, 28 Apr 2023 14:41:40 +0200 Jan Kara <[email protected]> wrote:
If the page is pinned, there's no point in trying to reclaim it. Furthermore if the page is from the page cache we don't want to reclaim fs-private data from the page because the pinning process may be writing to the page at any time and reclaiming fs private info on a dirty page can upset the filesystem (see link below).
Obviously I'll add a cc:stable here. I'm suspecting it's so old that there's no real Fixes: target that makes sense?
In principle the problem is there ever since MM started to track dirty shared pages and filesystems started to use .page_mkwrite callbacks. So for very long, yes. That being said the fix makes sense only since we've added page pinning infrastructure and started using it in various places which is not that long ago (in 2020, first patches in this direction have been merged to 5.7). So we could mark it for stable with 5.7+.
Quoted 6 lines
Quoted 6 lines
mm/vmscan.c +0
-0@@ -1901,6 +1901,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, } }
Quoted 13 lines
mm/vmscan.c static unsigned int shrink_folio_list(struct list_head *folio_list, · line 1913
Quoted 10 lines
mm/vmscan.c +10
-0+/* +* Folio is unmapped now so it cannot be newly pinned anymore. +* No point in trying to reclaim folio if it is pinned. +* Furthermore we don't want to reclaim underlying fs metadata +* if the folio is pinned and thus potentially modified by the +* pinning process as that may upset the filesystem. +*/ +if (folio_maybe_dma_pinned (folio)) + goto activate_locked; +So I expect the -stable maintainers will be looking for a pre-folios version of this when the time comes.
Yeah, right. Luckily that's going to be pretty easy :).
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR