|
133 | 133 | * operations, however they won't be usable until the transaction commits.
|
134 | 134 | *
|
135 | 135 | * COMMIT_TRANS
|
136 |
| - * may_commit_transaction() is the ultimate arbiter on whether we commit the |
137 |
| - * transaction or not. In order to avoid constantly churning we do all the |
138 |
| - * above flushing first and then commit the transaction as the last resort. |
139 |
| - * However we need to take into account things like pinned space that would |
140 |
| - * be freed, plus any delayed work we may not have gotten rid of in the case |
141 |
| - * of metadata. |
142 |
| - * |
143 |
| - * FORCE_COMMIT_TRANS |
144 |
| - * For use by the preemptive flusher. We use this to bypass the ticketing |
145 |
| - * checks in may_commit_transaction, as we have more information about the |
146 |
| - * overall state of the system and may want to commit the transaction ahead |
147 |
| - * of actual ENOSPC conditions. |
| 136 | + * This will commit the transaction. Historically we had a lot of logic |
| 137 | + * surrounding whether or not we'd commit the transaction, but this waits born |
| 138 | + * out of a pre-tickets era where we could end up committing the transaction |
| 139 | + * thousands of times in a row without making progress. Now thanks to our |
| 140 | + * ticketing system we know if we're not making progress and can error |
| 141 | + * everybody out after a few commits rather than burning the disk hoping for |
| 142 | + * a different answer. |
148 | 143 | *
|
149 | 144 | * OVERCOMMIT
|
150 | 145 | *
|
@@ -575,109 +570,6 @@ static void shrink_delalloc(struct btrfs_fs_info *fs_info,
|
575 | 570 | }
|
576 | 571 | }
|
577 | 572 |
|
578 |
| -/** |
579 |
| - * Possibly commit the transaction if its ok to |
580 |
| - * |
581 |
| - * @fs_info: the filesystem |
582 |
| - * @space_info: space_info we are checking for commit, either data or metadata |
583 |
| - * |
584 |
| - * This will check to make sure that committing the transaction will actually |
585 |
| - * get us somewhere and then commit the transaction if it does. Otherwise it |
586 |
| - * will return -ENOSPC. |
587 |
| - */ |
588 |
| -static int may_commit_transaction(struct btrfs_fs_info *fs_info, |
589 |
| - struct btrfs_space_info *space_info) |
590 |
| -{ |
591 |
| - struct reserve_ticket *ticket = NULL; |
592 |
| - struct btrfs_block_rsv *delayed_rsv = &fs_info->delayed_block_rsv; |
593 |
| - struct btrfs_block_rsv *delayed_refs_rsv = &fs_info->delayed_refs_rsv; |
594 |
| - struct btrfs_block_rsv *trans_rsv = &fs_info->trans_block_rsv; |
595 |
| - struct btrfs_trans_handle *trans; |
596 |
| - u64 reclaim_bytes = 0; |
597 |
| - u64 bytes_needed = 0; |
598 |
| - u64 cur_free_bytes = 0; |
599 |
| - |
600 |
| - trans = (struct btrfs_trans_handle *)current->journal_info; |
601 |
| - if (trans) |
602 |
| - return -EAGAIN; |
603 |
| - |
604 |
| - spin_lock(&space_info->lock); |
605 |
| - cur_free_bytes = btrfs_space_info_used(space_info, true); |
606 |
| - if (cur_free_bytes < space_info->total_bytes) |
607 |
| - cur_free_bytes = space_info->total_bytes - cur_free_bytes; |
608 |
| - else |
609 |
| - cur_free_bytes = 0; |
610 |
| - |
611 |
| - if (!list_empty(&space_info->priority_tickets)) |
612 |
| - ticket = list_first_entry(&space_info->priority_tickets, |
613 |
| - struct reserve_ticket, list); |
614 |
| - else if (!list_empty(&space_info->tickets)) |
615 |
| - ticket = list_first_entry(&space_info->tickets, |
616 |
| - struct reserve_ticket, list); |
617 |
| - if (ticket) |
618 |
| - bytes_needed = ticket->bytes; |
619 |
| - |
620 |
| - if (bytes_needed > cur_free_bytes) |
621 |
| - bytes_needed -= cur_free_bytes; |
622 |
| - else |
623 |
| - bytes_needed = 0; |
624 |
| - spin_unlock(&space_info->lock); |
625 |
| - |
626 |
| - if (!bytes_needed) |
627 |
| - return 0; |
628 |
| - |
629 |
| - trans = btrfs_join_transaction(fs_info->extent_root); |
630 |
| - if (IS_ERR(trans)) |
631 |
| - return PTR_ERR(trans); |
632 |
| - |
633 |
| - /* |
634 |
| - * See if there is enough pinned space to make this reservation, or if |
635 |
| - * we have block groups that are going to be freed, allowing us to |
636 |
| - * possibly do a chunk allocation the next loop through. |
637 |
| - */ |
638 |
| - if (test_bit(BTRFS_TRANS_HAVE_FREE_BGS, &trans->transaction->flags) || |
639 |
| - __percpu_counter_compare(&space_info->total_bytes_pinned, |
640 |
| - bytes_needed, |
641 |
| - BTRFS_TOTAL_BYTES_PINNED_BATCH) >= 0) |
642 |
| - goto commit; |
643 |
| - |
644 |
| - /* |
645 |
| - * See if there is some space in the delayed insertion reserve for this |
646 |
| - * reservation. If the space_info's don't match (like for DATA or |
647 |
| - * SYSTEM) then just go enospc, reclaiming this space won't recover any |
648 |
| - * space to satisfy those reservations. |
649 |
| - */ |
650 |
| - if (space_info != delayed_rsv->space_info) |
651 |
| - goto enospc; |
652 |
| - |
653 |
| - spin_lock(&delayed_rsv->lock); |
654 |
| - reclaim_bytes += delayed_rsv->reserved; |
655 |
| - spin_unlock(&delayed_rsv->lock); |
656 |
| - |
657 |
| - spin_lock(&delayed_refs_rsv->lock); |
658 |
| - reclaim_bytes += delayed_refs_rsv->reserved; |
659 |
| - spin_unlock(&delayed_refs_rsv->lock); |
660 |
| - |
661 |
| - spin_lock(&trans_rsv->lock); |
662 |
| - reclaim_bytes += trans_rsv->reserved; |
663 |
| - spin_unlock(&trans_rsv->lock); |
664 |
| - |
665 |
| - if (reclaim_bytes >= bytes_needed) |
666 |
| - goto commit; |
667 |
| - bytes_needed -= reclaim_bytes; |
668 |
| - |
669 |
| - if (__percpu_counter_compare(&space_info->total_bytes_pinned, |
670 |
| - bytes_needed, |
671 |
| - BTRFS_TOTAL_BYTES_PINNED_BATCH) < 0) |
672 |
| - goto enospc; |
673 |
| - |
674 |
| -commit: |
675 |
| - return btrfs_commit_transaction(trans); |
676 |
| -enospc: |
677 |
| - btrfs_end_transaction(trans); |
678 |
| - return -ENOSPC; |
679 |
| -} |
680 |
| - |
681 | 573 | /*
|
682 | 574 | * Try to flush some data based on policy set by @state. This is only advisory
|
683 | 575 | * and may fail for various reasons. The caller is supposed to examine the
|
@@ -752,9 +644,7 @@ static void flush_space(struct btrfs_fs_info *fs_info,
|
752 | 644 | btrfs_wait_on_delayed_iputs(fs_info);
|
753 | 645 | break;
|
754 | 646 | case COMMIT_TRANS:
|
755 |
| - ret = may_commit_transaction(fs_info, space_info); |
756 |
| - break; |
757 |
| - case FORCE_COMMIT_TRANS: |
| 647 | + ASSERT(current->journal_info == NULL); |
758 | 648 | trans = btrfs_join_transaction(root);
|
759 | 649 | if (IS_ERR(trans)) {
|
760 | 650 | ret = PTR_ERR(trans);
|
@@ -1136,7 +1026,7 @@ static void btrfs_preempt_reclaim_metadata_space(struct work_struct *work)
|
1136 | 1026 | (delayed_block_rsv->reserved +
|
1137 | 1027 | delayed_refs_rsv->reserved)) {
|
1138 | 1028 | to_reclaim = space_info->bytes_pinned;
|
1139 |
| - flush = FORCE_COMMIT_TRANS; |
| 1029 | + flush = COMMIT_TRANS; |
1140 | 1030 | } else if (delayed_block_rsv->reserved >
|
1141 | 1031 | delayed_refs_rsv->reserved) {
|
1142 | 1032 | to_reclaim = delayed_block_rsv->reserved;
|
@@ -1206,12 +1096,8 @@ static void btrfs_preempt_reclaim_metadata_space(struct work_struct *work)
|
1206 | 1096 | * the information it needs to make the right decision.
|
1207 | 1097 | *
|
1208 | 1098 | * COMMIT_TRANS
|
1209 |
| - * This is where we reclaim all of the pinned space generated by the previous |
1210 |
| - * two stages. We will not commit the transaction if we don't think we're |
1211 |
| - * likely to satisfy our request, which means if our current free space + |
1212 |
| - * total_bytes_pinned < reservation we will not commit. This is why the |
1213 |
| - * previous states are actually important, to make sure we know for sure |
1214 |
| - * whether committing the transaction will allow us to make progress. |
| 1099 | + * This is where we reclaim all of the pinned space generated by running the |
| 1100 | + * iputs |
1215 | 1101 | *
|
1216 | 1102 | * ALLOC_CHUNK_FORCE
|
1217 | 1103 | * For data we start with alloc chunk force, however we could have been full
|
|
0 commit comments