Skip to content

Convert data reservations to the ticketing infrastructure

Josef Bacik linux-btrfs 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest23 patches 18 repliesIn review
  2. v324 patches 8 repliesSuperseded
  3. v223 patches 26 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v1 RFC20 patches12 repliesSuperseded

Changes in v4 from the cover letter

- merged the patch that stopped forcing commit for data with the patch that removed the bytes_needed parameter to may_commit_transaction.
- fixed the wording in the comment patch as per Nikolay.
- Added the reviewed-by's and tested-by's to everything

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/23btrfs: change nr to u64 in btrfs_start_delalloc_rootsfs/btrfs/ctree.h fs/btrfs/dev-replace.c fs/btrfs/inode.c +2 more+15 -201 reply
2/23btrfs: remove orig from shrink_delallocfs/btrfs/space-info.c+2 -20 replies
3/23btrfs: handle U64_MAX for shrink_delallocfs/btrfs/space-info.c+14 -30 replies
4/23btrfs: make shrink_delalloc take space_info as an argfs/btrfs/space-info.c+4 -50 replies
5/23btrfs: make ALLOC_CHUNK use the space info flagsfs/btrfs/space-info.c+2 -10 replies
6/23btrfs: call btrfs_try_granting_tickets when freeing reserved bytesfs/btrfs/block-group.c+2 -01 reply
7/23btrfs: call btrfs_try_granting_tickets when unpinning anythingfs/btrfs/extent-tree.c+3 -40 replies
8/23btrfs: call btrfs_try_granting_tickets when reserving spacefs/btrfs/block-group.c+7 -01 reply
9/23btrfs: use the btrfs_space_info_free_bytes_may_use helper for delallocfs/btrfs/delalloc-space.c+1 -30 replies
10/23btrfs: use btrfs_start_delalloc_roots in shrink_delallocfs/btrfs/space-info.c+1 -541 reply
11/23btrfs: check tickets after waiting on ordered extentsfs/btrfs/space-info.c+9 -81 reply
12/23btrfs: add flushing states for handling data reservationsfs/btrfs/ctree.h fs/btrfs/space-info.c+8 -01 reply
13/23btrfs: add the data transaction commit logic into may_commit_transactionfs/btrfs/space-info.c+19 -51 reply
14/23btrfs: add btrfs_reserve_data_bytes and use itfs/btrfs/delalloc-space.c fs/btrfs/space-info.c fs/btrfs/space-info.h+98 -1151 reply
15/23btrfs: use ticketing for data space reservationsfs/btrfs/space-info.c+67 -581 reply
16/23btrfs: serialize data reservations if we are flushingfs/btrfs/space-info.c+5 -11 reply
17/23btrfs: use the same helper for data and metadata reservationsfs/btrfs/space-info.c+14 -341 reply
18/23btrfs: drop the commit_cycles stuff for data reservationsfs/btrfs/space-info.c+2 -201 reply
19/23btrfs: don't force commit if we are datafs/btrfs/space-info.c+5 -191 reply
20/23btrfs: run delayed iputs before committing the transaction for datafs/btrfs/space-info.c+1 -11 reply
21/23btrfs: flush delayed refs when trying to reserve data spacefs/btrfs/space-info.c+1 -01 reply
22/23btrfs: do async reclaim for data reservationsfs/btrfs/ctree.h fs/btrfs/disk-io.c fs/btrfs/space-info.c +1 more+93 -371 reply
23/23btrfs: add a comment explaining the data flush stepsfs/btrfs/space-info.c+47 -02 replies

Reviews trailers per patch

All 23 patches have a Reviewed-by or Acked-by.

PatchNikolay BorisovJohannes Thumshirn
1/23R-b T-b R-b
2/23R-b T-b R-b
3/23R-b T-b R-b
4/23R-b T-b R-b
5/23R-b T-b R-b
6/23R-b T-b R-b
7/23R-b T-b R-b
8/23R-b T-b R-b
9/23R-b T-b R-b
10/23R-b T-b R-b
11/23T-b R-b
12/23R-b T-b R-b
13/23R-b T-b R-b
14/23R-b T-b R-b
15/23R-b T-b R-b
16/23R-b T-b R-b
17/23R-b T-b R-b
18/23R-b T-b R-b
19/23R-b T-b R-b
20/23R-b T-b
21/23T-b R-b
22/23R-b T-b R-b
23/23R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH 0/23][v4] Convert data reservations to the ticketing infrastructure

v3->v4:
- merged the patch that stopped forcing commit for data with the patch that removed the bytes_needed parameter to may_commit_transaction.
- fixed the wording in the comment patch as per Nikolay.
- Added the reviewed-by's and tested-by's to everything

v2->v3:
- added a comment patch for the flushing states for data.
- I forgot to add cancel_work_sync() for the new async data flusher thread.
- Cleaned up a few of Nikolay's nits.

v1->v2:
- dropped the RFC
- realized that I mis-translated the transaction commit logic from the old way to the new way, so I've reworked a bunch of patches to clearly pull that behavior into the generic flushing code. I've then cleaned it up later to make it easy to bisect down to behavior changes.
- Cleaned up the priority flushing, there's no need for an explicit state array.
- Removed the CHUNK_FORCE_ALLOC from the normal flushing as well, simply keep the logic of allocating chunks until we've made our reservation or we are full, then fall back on the normal flushing mechanism.

-------------- Original email --------------
Nikolay reported a problem where we'd occasionally fail generic/371. This test has two tasks running in a loop, one that fallocate and rm's, and one that pwrite's and rm's. There is enough space for both of these files to exist at one time, but sometimes the pwrite would fail.

It would fail because we do not serialize data reseravtions. If one task is stuck doing the reclaim work, and another task comes in and steals it's reservation enough times, we'll give up and return ENOSPC. We validated this by adding a printk to the data reservation path to tell us that it was succeeding at making a reservation while another task was flushing.

To solve this problem I've converted data reservations over to the ticketing system that metadata uses. There are some cleanups and some fixes that have to come before we could do that. The following are simply cleanups

[PATCH 01/20] btrfs: change nr to u64 in btrfs_start_delalloc_roots [PATCH 02/20] btrfs: remove orig from shrink_delalloc [PATCH 03/20] btrfs: handle U64_MAX for shrink_delalloc

The following are fixes that are needed to handle data space infos properly.

[PATCH 04/20] btrfs: make shrink_delalloc take space_info as an arg [PATCH 05/20] btrfs: make ALLOC_CHUNK use the space info flags [PATCH 06/20] btrfs: call btrfs_try_granting_tickets when freeing [PATCH 07/20] btrfs: call btrfs_try_granting_tickets when unpinning [PATCH 08/20] btrfs: call btrfs_try_granting_tickets when reserving [PATCH 09/20] btrfs: use the btrfs_space_info_free_bytes_may_use

I then converted the data reservation path over to the ticketing infrastructure, but I did it in a way that mirrored exactly what we currently have. The idea is that I want to be able to bisect regressions that happen from behavior change, and doing that would be hard if I just had a single patch doing the whole conversion at once. So the following patches are only moving code around logically, but preserve the same behavior as before

[PATCH 10/20] btrfs: add flushing states for handling data [PATCH 11/20] btrfs: add btrfs_reserve_data_bytes and use it [PATCH 12/20] btrfs: use ticketing for data space reservations

And then the following patches were changing the behavior of how we flush space for data reservations.

[PATCH 13/20] btrfs: run delayed iputs before committing the [PATCH 14/20] btrfs: flush delayed refs when trying to reserve data [PATCH 15/20] btrfs: serialize data reservations if we are flushing [PATCH 16/20] btrfs: rework chunk allocate for data reservations [PATCH 17/20] btrfs: drop the commit_cycles stuff for data

And then a cleanup now that the data reservation code is the same as the metadata reservation code.

[PATCH 18/20] btrfs: use the same helper for data and metadata

Finally a patch to change the flushing from direct to asynchronous, mirroring what we do for metadata for better latency.

[PATCH 19/20] btrfs: do async reclaim for data reservations

And then a final cleanup now that we're where we want to be with the data reservation path.

[PATCH 20/20] btrfs: kill the priority_reclaim_space helper

I've marked this as an RFC because I've only tested this with generic/371. I'm starting my overnight runs of xfstests now and will likely find regressions, but I'd like to get review started so this can get merged ASAP. Thanks,

Josef