xfs: add reverse-mapping, reflink, and dedupe support
PATCH v4 76/76 xfs: try to prevent failed rmap btree expansion during cow
In reply to Darrick J. WongIt's possible, if reflink and rmap are both enabled, for CoW to create a lot of small mappings that cause an rmap btree expansion to run out of space. If both are enabled, keep the AGFL fully stocked at all times, refuse to CoW if we start to run out of space in the AGFL, and hope that's good enough.
--- fs/xfs/libxfs/xfs_alloc.c | 8 ++++++++ fs/xfs/xfs_reflink.c | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+)
fs/xfs/libxfs/xfs_alloc.c +8 -0
@@ -2000,6 +2000,14 @@ xfs_alloc_min_freelist( min_free += min_t(unsigned int, pag->pagf_levels[XFS_BTNUM_RMAPi] +1 , mp->m_ag_maxlevels); +/* +* The rmapbt can explode if we have reflink enabled and someone +* creates a lot of small mappings... so max out the AGFL to try +* to prevent that. +*/ +if (xfs_sb_version_hasrmapbt (&mp->m_sb) && +xfs_sb_version_hasreflink (&mp->m_sb)) + min_free =XFS_AGFL_SIZE (mp) - min_free;return min_free; }
fs/xfs/xfs_reflink.c +20 -0
@@ -49,6 +49,7 @@#include "xfs_bmap_btree.h" #include "xfs_reflink.h" #include "xfs_iomap.h" +#include "xfs_sb.h" /* * Copy on Write of Shared Blocks
@@ -191,6 +192,8 @@ xfs_reflink_reserve_cow_extent( struct xfs_bmbt_irec *irec) {struct xfs_bmbt_irec rec; +struct xfs_perag *pag; +unsigned int resblks;xfs_agnumber_t agno;xfs_agblock_t agbno;xfs_extlen_t aglen;
@@ -225,6 +228,23 @@ xfs_reflink_reserve_cow_extent( goto advloop; } +/* +* XXX: The rmapbt can ENOSPC if we do evil things like +* CoW every other block of a long shared segment. Don't +* let the CoW happen if we lack sufficient space in the AG. +* We overinflate the AGFL in the hopes that this will never +* have to happen. +*/ +if (xfs_sb_version_hasrmapbt (&ip->i_mount->m_sb)) { + pag =xfs_perag_get (ip->i_mount, agno); + resblks = pag->pagf_flcount; +xfs_perag_put (pag); +if (resblks <50 ) { + error = -ENOSPC ; +break ; + } + } +/* Add as much as we can to the cow fork */ foffset =XFS_FSB_TO_B (ip->i_mount, lblk + fbno - agbno); fsize =XFS_FSB_TO_B (ip->i_mount, flen);
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 2 lines · Darrick J. Wong
Hi all,
...
Quoted 22 lines
Fixed since RFCv3:
* The reflink and dedupe ioctls are being hoisted to the VFS, as provided in the first few patches. Patch 81 connects to this functionality.
* Copy on write has been rewritten for v4. We now use the existing delayed allocation mechanism to coalesce writes together, deferring allocation until writeout time. This enables CoW to make better block placement decisions and significantly reduces overhead. CoW is still pretty slow, but not as slow as before.
* Direct IO CoW has been implemented using the same mechanism as above, but modified to perform the allocation and remapping right then and there. Throughput is much higher than pushing data through the page cache CoW. (It's the same mechanism, but we're playing with chunks bigger than a single memory page.)
* CoW ENOSPC works correctly now, except in the pathological case that the AG fills up and the rmap btree cannot expand. That will be addressed for v5.
Quoted 8 lines
* fallocate will now unshare blocks to prevent future ENOSPC, as you'd expect.
* refcount btree blocks are preallocated at mount time to prevent ENOSPC while trying to expand the tree. This also has the effect of grouping the btree blocks together, which can speed up CoW remapping.
Can you elaborate on how these blocks are preallocated? E.g., is the tree "preconstructed" in some sense? However that is done, is this the anticipated solution or a temporary workaround..?
Also, shouldn't the enospc condition be handled by the agfl? I take it there is something going on here that renders that solution flawed, so I'm just curious what it is.
(Sorry if this is all explained elsewhere, but I haven't yet had a chance to take a close enough look at this feature..).
Brian
Quoted 36 lines
Issues:
* The extent swapping ioctl still allocates a bigger fixed-size transaction. That's most likely a stupid thing to do, so getting a better grip on how the journalling code works and auditing all the new transaction users will have to happen. Right now it mostly gets lucky.
* EFI tracking for the allocated-but-not-yet-mapped blocks is nonexistant. A crash will leak them.
* ENOSPC while expanding the rmap btree can crash the FS. For now we work around this problem by making the AGFL as big as possible, failing CoW attempts with ENOSPC if there aren't enough AGFL blocks available, and hoping that doesn't actually happen.
If you're going to start using this mess, you probably ought to just pull from my github trees for kernel[1], xfsprogs[2], and xfstests[3]. There are also updates for xfs-docs[4] and man-pages[5].
The patches have been xfstested with x64, i386, and ppc64; while in general the tests run to completion, there are still periodic bugs that will be addressed by the next RFC. There's a persistent crash on arm64 and ppc64el that I haven't been able to triage.
This is an extraordinary way to eat your data. Enjoy! Comments and questions are, as always, welcome.
--D
[1] https://github.com/djwong/linux/tree/for-dave
[2] https://github.com/djwong/xfsprogs/tree/for-dave
[3] https://github.com/djwong/xfstests/tree/for-dave
[4] https://github.com/djwong/xfs-documentation/tree/for-dave
[5] https://github.com/djwong/man-pages/commits/for-mtk
Quoted 4 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 39 lines · Brian Foster
Quoted 2 lines · Darrick J. Wong
Hi all,
...
Quoted 22 lines
Fixed since RFCv3:
* The reflink and dedupe ioctls are being hoisted to the VFS, as provided in the first few patches. Patch 81 connects to this functionality.
* Copy on write has been rewritten for v4. We now use the existing delayed allocation mechanism to coalesce writes together, deferring allocation until writeout time. This enables CoW to make better block placement decisions and significantly reduces overhead. CoW is still pretty slow, but not as slow as before.
* Direct IO CoW has been implemented using the same mechanism as above, but modified to perform the allocation and remapping right then and there. Throughput is much higher than pushing data through the page cache CoW. (It's the same mechanism, but we're playing with chunks bigger than a single memory page.)
* CoW ENOSPC works correctly now, except in the pathological case that the AG fills up and the rmap btree cannot expand. That will be addressed for v5.
Quoted 8 lines
* fallocate will now unshare blocks to prevent future ENOSPC, as you'd expect.
* refcount btree blocks are preallocated at mount time to prevent ENOSPC while trying to expand the tree. This also has the effect of grouping the btree blocks together, which can speed up CoW remapping.
Can you elaborate on how these blocks are preallocated? E.g., is the tree "preconstructed" in some sense? However that is done, is this the anticipated solution or a temporary workaround..?
Quoted 6 lines
Also, shouldn't the enospc condition be handled by the agfl? I take it there is something going on here that renders that solution flawed, so I'm just curious what it is.
(Sorry if this is all explained elsewhere, but I haven't yet had a chance to take a close enough look at this feature..).
Reference count btree blocks aren't allocated from the AGFL; they're allocated from the free space in the same manner as the inobt, per a review comment from Dave a looong time ago. :)
As such, we can get ourselves into the nasty situation where every block in the AG has been allocated to file data. If we then see a bunch of reference count changes that are scattered around the AG, the reference count btree has to expand to hold all the new records... but there isn't space, and the operation fails. Given that we know the maximum possible size of the refcount btree (it's 0.3% of the AG size with 4k blocks), I figured it was easy enough to avoid ENOSPC for reflink operations.
I've temporarily fixed this by adding code that figures out how many blocks we need if the reference count btree has to have a unique record for every block in the AG and holding that many blocks until either they're allocated to the refcount btree or freed at umount time. Right now it's a temporary fix (if the FS crashes, the reserved blocks are lost) but it wouldn't be difficult for the FS to make a permanent reservation that's recorded on disk somehow. But that's involves writing things to disk + making xfsprogs understand the reservation; let's see what people say about the reserved pool idea at all.
Does that make sense? :)
--D
Quoted 44 lines
Brian
Quoted 36 lines
Issues:
* The extent swapping ioctl still allocates a bigger fixed-size transaction. That's most likely a stupid thing to do, so getting a better grip on how the journalling code works and auditing all the new transaction users will have to happen. Right now it mostly gets lucky.
* EFI tracking for the allocated-but-not-yet-mapped blocks is nonexistant. A crash will leak them.
* ENOSPC while expanding the rmap btree can crash the FS. For now we work around this problem by making the AGFL as big as possible, failing CoW attempts with ENOSPC if there aren't enough AGFL blocks available, and hoping that doesn't actually happen.
If you're going to start using this mess, you probably ought to just pull from my github trees for kernel[1], xfsprogs[2], and xfstests[3]. There are also updates for xfs-docs[4] and man-pages[5].
The patches have been xfstested with x64, i386, and ppc64; while in general the tests run to completion, there are still periodic bugs that will be addressed by the next RFC. There's a persistent crash on arm64 and ppc64el that I haven't been able to triage.
This is an extraordinary way to eat your data. Enjoy! Comments and questions are, as always, welcome.
--D
[1] https://github.com/djwong/linux/tree/for-dave
[2] https://github.com/djwong/xfsprogs/tree/for-dave
[3] https://github.com/djwong/xfstests/tree/for-dave
[4] https://github.com/djwong/xfs-documentation/tree/for-dave
[5] https://github.com/djwong/man-pages/commits/for-mtkQuoted 4 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 4 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 44 lines · Darrick J. Wong
Quoted 43 lines · Brian Foster
Quoted 2 lines · Darrick J. Wong
Hi all,
...
Quoted 22 lines
Fixed since RFCv3:
* The reflink and dedupe ioctls are being hoisted to the VFS, as provided in the first few patches. Patch 81 connects to this functionality.
* Copy on write has been rewritten for v4. We now use the existing delayed allocation mechanism to coalesce writes together, deferring allocation until writeout time. This enables CoW to make better block placement decisions and significantly reduces overhead. CoW is still pretty slow, but not as slow as before.
* Direct IO CoW has been implemented using the same mechanism as above, but modified to perform the allocation and remapping right then and there. Throughput is much higher than pushing data through the page cache CoW. (It's the same mechanism, but we're playing with chunks bigger than a single memory page.)
* CoW ENOSPC works correctly now, except in the pathological case that the AG fills up and the rmap btree cannot expand. That will be addressed for v5.
Quoted 8 lines
* fallocate will now unshare blocks to prevent future ENOSPC, as you'd expect.
* refcount btree blocks are preallocated at mount time to prevent ENOSPC while trying to expand the tree. This also has the effect of grouping the btree blocks together, which can speed up CoW remapping.
Can you elaborate on how these blocks are preallocated? E.g., is the tree "preconstructed" in some sense? However that is done, is this the anticipated solution or a temporary workaround..?
Also, shouldn't the enospc condition be handled by the agfl? I take it there is something going on here that renders that solution flawed, so I'm just curious what it is.
Quoted 7 lines
Quoted 2 lines
(Sorry if this is all explained elsewhere, but I haven't yet had a chance to take a close enough look at this feature..).
Reference count btree blocks aren't allocated from the AGFL; they're allocated from the free space in the same manner as the inobt, per a review comment from Dave a looong time ago. :)
Ah, Ok.
Quoted 8 lines
As such, we can get ourselves into the nasty situation where every block in the AG has been allocated to file data. If we then see a bunch of reference count changes that are scattered around the AG, the reference count btree has to expand to hold all the new records... but there isn't space, and the operation fails. Given that we know the maximum possible size of the refcount btree (it's 0.3% of the AG size with 4k blocks), I figured it was easy enough to avoid ENOSPC for reflink operations.
Sounds reasonable.
Quoted 11 lines
I've temporarily fixed this by adding code that figures out how many blocks we need if the reference count btree has to have a unique record for every block in the AG and holding that many blocks until either they're allocated to the refcount btree or freed at umount time. Right now it's a temporary fix (if the FS crashes, the reserved blocks are lost) but it wouldn't be difficult for the FS to make a permanent reservation that's recorded on disk somehow. But that's involves writing things to disk + making xfsprogs understand the reservation; let's see what people say about the reserved pool idea at all.
Does that make sense? :)
Yep, it sounds sort of like the reserve pool mechanism used to protect against ENOSPC when freeing blocks. Curious... why are the reserved blocks lost on fs crash? Wouldn't they be reserved again on the subsequent mount?
Thanks for the explanation...
Brian
Quoted 50 lines
--D
Quoted 48 lines
Brian
Quoted 36 lines
Issues:
* The extent swapping ioctl still allocates a bigger fixed-size transaction. That's most likely a stupid thing to do, so getting a better grip on how the journalling code works and auditing all the new transaction users will have to happen. Right now it mostly gets lucky.
* EFI tracking for the allocated-but-not-yet-mapped blocks is nonexistant. A crash will leak them.
* ENOSPC while expanding the rmap btree can crash the FS. For now we work around this problem by making the AGFL as big as possible, failing CoW attempts with ENOSPC if there aren't enough AGFL blocks available, and hoping that doesn't actually happen.
If you're going to start using this mess, you probably ought to just pull from my github trees for kernel[1], xfsprogs[2], and xfstests[3]. There are also updates for xfs-docs[4] and man-pages[5].
The patches have been xfstested with x64, i386, and ppc64; while in general the tests run to completion, there are still periodic bugs that will be addressed by the next RFC. There's a persistent crash on arm64 and ppc64el that I haven't been able to triage.
This is an extraordinary way to eat your data. Enjoy! Comments and questions are, as always, welcome.
--D
[1] https://github.com/djwong/linux/tree/for-dave
[2] https://github.com/djwong/xfsprogs/tree/for-dave
[3] https://github.com/djwong/xfstests/tree/for-dave
[4] https://github.com/djwong/xfs-documentation/tree/for-dave
[5] https://github.com/djwong/man-pages/commits/for-mtkQuoted 4 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 75 lines · Brian Foster
Quoted 44 lines · Darrick J. Wong
Quoted 43 lines · Brian Foster
Quoted 2 lines · Darrick J. Wong
Hi all,
...
Quoted 22 lines
Fixed since RFCv3:
* The reflink and dedupe ioctls are being hoisted to the VFS, as provided in the first few patches. Patch 81 connects to this functionality.
* Copy on write has been rewritten for v4. We now use the existing delayed allocation mechanism to coalesce writes together, deferring allocation until writeout time. This enables CoW to make better block placement decisions and significantly reduces overhead. CoW is still pretty slow, but not as slow as before.
* Direct IO CoW has been implemented using the same mechanism as above, but modified to perform the allocation and remapping right then and there. Throughput is much higher than pushing data through the page cache CoW. (It's the same mechanism, but we're playing with chunks bigger than a single memory page.)
* CoW ENOSPC works correctly now, except in the pathological case that the AG fills up and the rmap btree cannot expand. That will be addressed for v5.
Quoted 8 lines
* fallocate will now unshare blocks to prevent future ENOSPC, as you'd expect.
* refcount btree blocks are preallocated at mount time to prevent ENOSPC while trying to expand the tree. This also has the effect of grouping the btree blocks together, which can speed up CoW remapping.
Can you elaborate on how these blocks are preallocated? E.g., is the tree "preconstructed" in some sense? However that is done, is this the anticipated solution or a temporary workaround..?
Also, shouldn't the enospc condition be handled by the agfl? I take it there is something going on here that renders that solution flawed, so I'm just curious what it is.
Quoted 7 lines
Quoted 2 lines
(Sorry if this is all explained elsewhere, but I haven't yet had a chance to take a close enough look at this feature..).
Reference count btree blocks aren't allocated from the AGFL; they're allocated from the free space in the same manner as the inobt, per a review comment from Dave a looong time ago. :)
Ah, Ok.
Quoted 8 lines
As such, we can get ourselves into the nasty situation where every block in the AG has been allocated to file data. If we then see a bunch of reference count changes that are scattered around the AG, the reference count btree has to expand to hold all the new records... but there isn't space, and the operation fails. Given that we know the maximum possible size of the refcount btree (it's 0.3% of the AG size with 4k blocks), I figured it was easy enough to avoid ENOSPC for reflink operations.
Sounds reasonable.
Quoted 9 lines
I've temporarily fixed this by adding code that figures out how many blocks we need if the reference count btree has to have a unique record for every block in the AG and holding that many blocks until either they're allocated to the refcount btree or freed at umount time. Right now it's a temporary fix (if the FS crashes, the reserved blocks are lost) but it wouldn't be difficult for the FS to make a permanent reservation that's recorded on disk somehow. But that's involves writing things to disk + making xfsprogs understand the reservation; let's see what people say about the reserved pool idea at all.
Quoted 7 lines
Quoted 2 lines
Does that make sense? :)
Yep, it sounds sort of like the reserve pool mechanism used to protect against ENOSPC when freeing blocks. Curious... why are the reserved blocks lost on fs crash? Wouldn't they be reserved again on the subsequent mount?
They will, but the pre-crash reservation isn't (yet) written down anywhere on disk.
Thank /you/ for having a look at the reflink code! :)
--D
Quoted 56 lines
Thanks for the explanation...
Brian
Quoted 50 lines
--D
Quoted 48 lines
Brian
Quoted 36 lines
Issues:
* The extent swapping ioctl still allocates a bigger fixed-size transaction. That's most likely a stupid thing to do, so getting a better grip on how the journalling code works and auditing all the new transaction users will have to happen. Right now it mostly gets lucky.
* EFI tracking for the allocated-but-not-yet-mapped blocks is nonexistant. A crash will leak them.
* ENOSPC while expanding the rmap btree can crash the FS. For now we work around this problem by making the AGFL as big as possible, failing CoW attempts with ENOSPC if there aren't enough AGFL blocks available, and hoping that doesn't actually happen.
If you're going to start using this mess, you probably ought to just pull from my github trees for kernel[1], xfsprogs[2], and xfstests[3]. There are also updates for xfs-docs[4] and man-pages[5].
The patches have been xfstested with x64, i386, and ppc64; while in general the tests run to completion, there are still periodic bugs that will be addressed by the next RFC. There's a persistent crash on arm64 and ppc64el that I haven't been able to triage.
This is an extraordinary way to eat your data. Enjoy! Comments and questions are, as always, welcome.
--D
[1] https://github.com/djwong/linux/tree/for-dave
[2] https://github.com/djwong/xfsprogs/tree/for-dave
[3] https://github.com/djwong/xfstests/tree/for-dave
[4] https://github.com/djwong/xfs-documentation/tree/for-dave
[5] https://github.com/djwong/man-pages/commits/for-mtkQuoted 4 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 4 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 14 lines · Darrick J. Wong
Quoted 13 lines · Brian Foster
Quoted 11 lines · Darrick J. Wong
I've temporarily fixed this by adding code that figures out how many blocks we need if the reference count btree has to have a unique record for every block in the AG and holding that many blocks until either they're allocated to the refcount btree or freed at umount time. Right now it's a temporary fix (if the FS crashes, the reserved blocks are lost) but it wouldn't be difficult for the FS to make a permanent reservation that's recorded on disk somehow. But that's involves writing things to disk + making xfsprogs understand the reservation; let's see what people say about the reserved pool idea at all.
Does that make sense? :)
Quoted 7 lines
Quoted 4 lines
Yep, it sounds sort of like the reserve pool mechanism used to protect against ENOSPC when freeing blocks. Curious... why are the reserved blocks lost on fs crash? Wouldn't they be reserved again on the subsequent mount?
They will, but the pre-crash reservation isn't (yet) written down anywhere on disk.
Does it need to be? The global reserve pool is not "written down" anywhere. When we mount, we pull the reserve from the global free space accounting. Hence we given ENOSPC when we've used "total fs blocks - reserve pool blocks" in memory, and so if we crash we've still got at least that many free blocks on disk. hence on mount we re-reserve those blocks in memory and everything is back to the way it was prior to the crash.
I suspect the per-ag code is a bit different, but it should be able to work the same way. i.e. when we initialise the per-ag structure, we pull the reserve from the free block count in the AG, as well as from the global free space count. Then we will get correct global ENOSPC detection, as well as leave enough space free in each AG as we scan and skip them during allocation...
As long as the per-ag reservation is restored during mount before we do EFI recovery processing (i.e. between the two log recovery phases), it should restore the reserve pool to the same size as it was before a crash occurred....
Unless, of course, I'm missing something newly introduced by the reflink code...
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 38 lines · Dave Chinner
Quoted 14 lines · Darrick J. Wong
Quoted 13 lines · Brian Foster
Quoted 11 lines · Darrick J. Wong
I've temporarily fixed this by adding code that figures out how many blocks we need if the reference count btree has to have a unique record for every block in the AG and holding that many blocks until either they're allocated to the refcount btree or freed at umount time. Right now it's a temporary fix (if the FS crashes, the reserved blocks are lost) but it wouldn't be difficult for the FS to make a permanent reservation that's recorded on disk somehow. But that's involves writing things to disk + making xfsprogs understand the reservation; let's see what people say about the reserved pool idea at all.
Does that make sense? :)
Quoted 7 lines
Quoted 4 lines
Yep, it sounds sort of like the reserve pool mechanism used to protect against ENOSPC when freeing blocks. Curious... why are the reserved blocks lost on fs crash? Wouldn't they be reserved again on the subsequent mount?
They will, but the pre-crash reservation isn't (yet) written down anywhere on disk.
Does it need to be? The global reserve pool is not "written down" anywhere. When we mount, we pull the reserve from the global free space accounting. Hence we given ENOSPC when we've used "total fs blocks - reserve pool blocks" in memory, and so if we crash we've still got at least that many free blocks on disk. hence on mount we re-reserve those blocks in memory and everything is back to the way it was prior to the crash.
I suspect the per-ag code is a bit different, but it should be able to work the same way. i.e. when we initialise the per-ag structure, we pull the reserve from the free block count in the AG, as well as from the global free space count. Then we will get correct global ENOSPC detection, as well as leave enough space free in each AG as we scan and skip them during allocation...
Quoted 7 lines
As long as the per-ag reservation is restored during mount before we do EFI recovery processing (i.e. between the two log recovery phases), it should restore the reserve pool to the same size as it was before a crash occurred....
Unless, of course, I'm missing something newly introduced by the reflink code...
Technically you were, but I've fixed the reservation code to exist purely as in-core magic that works more or less how you outlined above. No more on-disk artifacts, no more need to write a persistence and recovery mechanism. :)
--D
Quoted 7 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs