History

btrfs: qgroup: remove ASYNC_COMMIT mechanism in favor of reserve retry-after-EDQUOT

commit a514d63882c3 ("btrfs: qgroup: Commit transaction in advance to reduce early EDQUOT") tries to reduce the early EDQUOT problems by checking the qgroup free against threshold and tries to wake up commit kthread to free some space. The problem of that mechanism is, it can only free qgroup per-trans metadata space, can't do anything to data, nor prealloc qgroup space. Now since we have the ability to flush qgroup space, and implemented retry-after-EDQUOT behavior, such mechanism can be completely replaced. So this patch will cleanup such mechanism in favor of retry-after-EDQUOT.

Qu Wenruo committed 6 years ago

Commit adca4d91 parent c53e9655 files · +2 −62Browse files

Unified · Split

5 files
  1. fs/btrfs/ctree.h +0 −5
  2. fs/btrfs/disk-io.c +0 −1
  3. fs/btrfs/qgroup.c +2 −41
  4. fs/btrfs/transaction.c +0 −1
  5. fs/btrfs/transaction.h +0 −14
fs/btrfs/ctree.h+0−5
@@ -545,11 +545,6 @@ enum { · 544 unmodified lines
545 * (device replace, resize, device add/delete, balance)545 * (device replace, resize, device add/delete, balance)
546 */546 */
547 BTRFS_FS_EXCL_OP,547 BTRFS_FS_EXCL_OP,
548 /*
549 * To info transaction_kthread we need an immediate commit so it
550 * doesn't need to wait for commit_interval
551 */
552 BTRFS_FS_NEED_ASYNC_COMMIT,
553 /*548 /*
554 * Indicate that balance has been set up from the ioctl and is in the549 * Indicate that balance has been set up from the ioctl and is in the
555 * main phase. The fs_info::balance_ctl is initialized.550 * main phase. The fs_info::balance_ctl is initialized.
fs/btrfs/disk-io.c+0−1
@@ -1810,7 +1810,6 @@ static int transaction_kthread(void *arg) · 1809 unmodified lines
1810 1810
1811 now = ktime_get_seconds();1811 now = ktime_get_seconds();
1812 if (cur->state < TRANS_STATE_COMMIT_START &&1812 if (cur->state < TRANS_STATE_COMMIT_START &&
1813 !test_bit(BTRFS_FS_NEED_ASYNC_COMMIT, &fs_info->flags) &&
1814 (now < cur->start_time ||1813 (now < cur->start_time ||
1815 now - cur->start_time < fs_info->commit_interval)) {1814 now - cur->start_time < fs_info->commit_interval)) {
1816 spin_unlock(&fs_info->trans_lock);1815 spin_unlock(&fs_info->trans_lock);
fs/btrfs/qgroup.c+2−41
@@ -11,7 +11,6 @@ · 10 unmodified lines
11#include <linux/slab.h>11#include <linux/slab.h>
12#include <linux/workqueue.h>12#include <linux/workqueue.h>
13#include <linux/btrfs.h>13#include <linux/btrfs.h>
14#include <linux/sizes.h>
15 14
16#include "ctree.h"15#include "ctree.h"
17#include "transaction.h"16#include "transaction.h"
@@ -2895,20 +2894,8 @@ out: · 2877 unmodified lines
2895 return ret;2894 return ret;
2896}2895}
2897 2896
2898/*2897static bool qgroup_check_limits(const struct btrfs_qgroup *qg, u64 num_bytes)
2899 * Two limits to commit transaction in advance.
2900 *
2901 * For RATIO, it will be 1/RATIO of the remaining limit as threshold.
2902 * For SIZE, it will be in byte unit as threshold.
2903 */
2904#define QGROUP_FREE_RATIO 32
2905#define QGROUP_FREE_SIZE SZ_32M
2906static bool qgroup_check_limits(struct btrfs_fs_info *fs_info,
2907 const struct btrfs_qgroup *qg, u64 num_bytes)
2908{2898{
2909 u64 free;
2910 u64 threshold;
2911
2912 if ((qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_RFER) &&2899 if ((qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_RFER) &&
2913 qgroup_rsv_total(qg) + (s64)qg->rfer + num_bytes > qg->max_rfer)2900 qgroup_rsv_total(qg) + (s64)qg->rfer + num_bytes > qg->max_rfer)
2914 return false;2901 return false;
@@ -2917,32 +2904,6 @@ static bool qgroup_check_limits(struct btrfs_fs_info *fs_info, · 2 unmodified lines
2917 qgroup_rsv_total(qg) + (s64)qg->excl + num_bytes > qg->max_excl)2904 qgroup_rsv_total(qg) + (s64)qg->excl + num_bytes > qg->max_excl)
2918 return false;2905 return false;
2919 2906
2920 /*
2921 * Even if we passed the check, it's better to check if reservation
2922 * for meta_pertrans is pushing us near limit.
2923 * If there is too much pertrans reservation or it's near the limit,
2924 * let's try commit transaction to free some, using transaction_kthread
2925 */
2926 if ((qg->lim_flags & (BTRFS_QGROUP_LIMIT_MAX_RFER |
2927 BTRFS_QGROUP_LIMIT_MAX_EXCL))) {
2928 if (qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_EXCL) {
2929 free = qg->max_excl - qgroup_rsv_total(qg) - qg->excl;
2930 threshold = min_t(u64, qg->max_excl / QGROUP_FREE_RATIO,
2931 QGROUP_FREE_SIZE);
2932 } else {
2933 free = qg->max_rfer - qgroup_rsv_total(qg) - qg->rfer;
2934 threshold = min_t(u64, qg->max_rfer / QGROUP_FREE_RATIO,
2935 QGROUP_FREE_SIZE);
2936 }
2937
2938 /*
2939 * Use transaction_kthread to commit transaction, so we no
2940 * longer need to bother nested transaction nor lock context.
2941 */
2942 if (free < threshold)
2943 btrfs_commit_transaction_locksafe(fs_info);
2944 }
2945
2946 return true;2907 return true;
2947}2908}
2948 2909
@@ -2990,7 +2951,7 @@ static int qgroup_reserve(struct btrfs_root *root, u64 num_bytes, bool enforce, · 41 unmodified lines
2990 2951
2991 qg = unode_aux_to_qgroup(unode);2952 qg = unode_aux_to_qgroup(unode);
2992 2953
2993 if (enforce && !qgroup_check_limits(fs_info, qg, num_bytes)) {2954 if (enforce && !qgroup_check_limits(qg, num_bytes)) {
2994 ret = -EDQUOT;2955 ret = -EDQUOT;
2995 goto out;2956 goto out;
2996 }2957 }
fs/btrfs/transaction.c+0−1
@@ -2351,7 +2351,6 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) · 2350 unmodified lines
2351 */2351 */
2352 cur_trans->state = TRANS_STATE_COMPLETED;2352 cur_trans->state = TRANS_STATE_COMPLETED;
2353 wake_up(&cur_trans->commit_wait);2353 wake_up(&cur_trans->commit_wait);
2354 clear_bit(BTRFS_FS_NEED_ASYNC_COMMIT, &fs_info->flags);
2355 2354
2356 spin_lock(&fs_info->trans_lock);2355 spin_lock(&fs_info->trans_lock);
2357 list_del_init(&cur_trans->list);2356 list_del_init(&cur_trans->list);
fs/btrfs/transaction.h+0−14
@@ -210,20 +210,6 @@ int btrfs_clean_one_deleted_snapshot(struct btrfs_root *root); · 209 unmodified lines
210int btrfs_commit_transaction(struct btrfs_trans_handle *trans);210int btrfs_commit_transaction(struct btrfs_trans_handle *trans);
211int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,211int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
212 int wait_for_unblock);212 int wait_for_unblock);
213
214/*
215 * Try to commit transaction asynchronously, so this is safe to call
216 * even holding a spinlock.
217 *
218 * It's done by informing transaction_kthread to commit transaction without
219 * waiting for commit interval.
220 */
221static inline void btrfs_commit_transaction_locksafe(
222 struct btrfs_fs_info *fs_info)
223{
224 set_bit(BTRFS_FS_NEED_ASYNC_COMMIT, &fs_info->flags);
225 wake_up_process(fs_info->transaction_kthread);
226}
227int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans);213int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans);
228int btrfs_should_end_transaction(struct btrfs_trans_handle *trans);214int btrfs_should_end_transaction(struct btrfs_trans_handle *trans);
229void btrfs_throttle(struct btrfs_fs_info *fs_info);215void btrfs_throttle(struct btrfs_fs_info *fs_info);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t