Skip to content

Commit e91eb62

Browse files
committed
Merge branch 'for-linus-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs cleanups and fixes from Chris Mason: "These are small cleanups, and also some fixes for our async worker thread initialization. I was having some trouble testing these, but it ended up being a combination of changing around my test servers and a shiny new schedule while atomic from the new start/finish_plug in writeback_sb_inodes(). That one only hits on btrfs raid5/6 or MD raid10, and if I wasn't changing a bunch of things in my test setup at once it would have been really clear. Fix for writeback_sb_inodes() on the way as well" * 'for-linus-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: Btrfs: cleanup: remove unnecessary check before btrfs_free_path is called btrfs: async_thread: Fix workqueue 'max_active' value when initializing btrfs: Add raid56 support for updating num_tolerated_disk_barrier_failures in btrfs_balance btrfs: Cleanup for btrfs_calc_num_tolerated_disk_barrier_failures btrfs: Remove noused chunk_tree and chunk_objectid from scrub_enumerate_chunks and scrub_chunk btrfs: Update out-of-date "skip parity stripe" comment
2 parents e013f74 + 527afb4 commit e91eb62

File tree

9 files changed

+82
-96
lines changed

9 files changed

+82
-96
lines changed

fs/btrfs/async-thread.c

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ struct __btrfs_workqueue {
4242

4343
/* Thresholding related variants */
4444
atomic_t pending;
45-
int max_active;
46-
int current_max;
45+
46+
/* Up limit of concurrency workers */
47+
int limit_active;
48+
49+
/* Current number of concurrency workers */
50+
int current_active;
51+
52+
/* Threshold to change current_active */
4753
int thresh;
4854
unsigned int count;
4955
spinlock_t thres_lock;
@@ -88,34 +94,39 @@ BTRFS_WORK_HELPER(scrubnc_helper);
8894
BTRFS_WORK_HELPER(scrubparity_helper);
8995

9096
static struct __btrfs_workqueue *
91-
__btrfs_alloc_workqueue(const char *name, unsigned int flags, int max_active,
97+
__btrfs_alloc_workqueue(const char *name, unsigned int flags, int limit_active,
9298
int thresh)
9399
{
94100
struct __btrfs_workqueue *ret = kzalloc(sizeof(*ret), GFP_NOFS);
95101

96102
if (!ret)
97103
return NULL;
98104

99-
ret->max_active = max_active;
105+
ret->limit_active = limit_active;
100106
atomic_set(&ret->pending, 0);
101107
if (thresh == 0)
102108
thresh = DFT_THRESHOLD;
103109
/* For low threshold, disabling threshold is a better choice */
104110
if (thresh < DFT_THRESHOLD) {
105-
ret->current_max = max_active;
111+
ret->current_active = limit_active;
106112
ret->thresh = NO_THRESHOLD;
107113
} else {
108-
ret->current_max = 1;
114+
/*
115+
* For threshold-able wq, let its concurrency grow on demand.
116+
* Use minimal max_active at alloc time to reduce resource
117+
* usage.
118+
*/
119+
ret->current_active = 1;
109120
ret->thresh = thresh;
110121
}
111122

112123
if (flags & WQ_HIGHPRI)
113124
ret->normal_wq = alloc_workqueue("%s-%s-high", flags,
114-
ret->max_active,
115-
"btrfs", name);
125+
ret->current_active, "btrfs",
126+
name);
116127
else
117128
ret->normal_wq = alloc_workqueue("%s-%s", flags,
118-
ret->max_active, "btrfs",
129+
ret->current_active, "btrfs",
119130
name);
120131
if (!ret->normal_wq) {
121132
kfree(ret);
@@ -134,7 +145,7 @@ __btrfs_destroy_workqueue(struct __btrfs_workqueue *wq);
134145

135146
struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
136147
unsigned int flags,
137-
int max_active,
148+
int limit_active,
138149
int thresh)
139150
{
140151
struct btrfs_workqueue *ret = kzalloc(sizeof(*ret), GFP_NOFS);
@@ -143,14 +154,14 @@ struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
143154
return NULL;
144155

145156
ret->normal = __btrfs_alloc_workqueue(name, flags & ~WQ_HIGHPRI,
146-
max_active, thresh);
157+
limit_active, thresh);
147158
if (!ret->normal) {
148159
kfree(ret);
149160
return NULL;
150161
}
151162

152163
if (flags & WQ_HIGHPRI) {
153-
ret->high = __btrfs_alloc_workqueue(name, flags, max_active,
164+
ret->high = __btrfs_alloc_workqueue(name, flags, limit_active,
154165
thresh);
155166
if (!ret->high) {
156167
__btrfs_destroy_workqueue(ret->normal);
@@ -180,7 +191,7 @@ static inline void thresh_queue_hook(struct __btrfs_workqueue *wq)
180191
*/
181192
static inline void thresh_exec_hook(struct __btrfs_workqueue *wq)
182193
{
183-
int new_max_active;
194+
int new_current_active;
184195
long pending;
185196
int need_change = 0;
186197

@@ -197,27 +208,27 @@ static inline void thresh_exec_hook(struct __btrfs_workqueue *wq)
197208
wq->count %= (wq->thresh / 4);
198209
if (!wq->count)
199210
goto out;
200-
new_max_active = wq->current_max;
211+
new_current_active = wq->current_active;
201212

202213
/*
203214
* pending may be changed later, but it's OK since we really
204215
* don't need it so accurate to calculate new_max_active.
205216
*/
206217
pending = atomic_read(&wq->pending);
207218
if (pending > wq->thresh)
208-
new_max_active++;
219+
new_current_active++;
209220
if (pending < wq->thresh / 2)
210-
new_max_active--;
211-
new_max_active = clamp_val(new_max_active, 1, wq->max_active);
212-
if (new_max_active != wq->current_max) {
221+
new_current_active--;
222+
new_current_active = clamp_val(new_current_active, 1, wq->limit_active);
223+
if (new_current_active != wq->current_active) {
213224
need_change = 1;
214-
wq->current_max = new_max_active;
225+
wq->current_active = new_current_active;
215226
}
216227
out:
217228
spin_unlock(&wq->thres_lock);
218229

219230
if (need_change) {
220-
workqueue_set_max_active(wq->normal_wq, wq->current_max);
231+
workqueue_set_max_active(wq->normal_wq, wq->current_active);
221232
}
222233
}
223234

@@ -351,13 +362,13 @@ void btrfs_destroy_workqueue(struct btrfs_workqueue *wq)
351362
kfree(wq);
352363
}
353364

354-
void btrfs_workqueue_set_max(struct btrfs_workqueue *wq, int max)
365+
void btrfs_workqueue_set_max(struct btrfs_workqueue *wq, int limit_active)
355366
{
356367
if (!wq)
357368
return;
358-
wq->normal->max_active = max;
369+
wq->normal->limit_active = limit_active;
359370
if (wq->high)
360-
wq->high->max_active = max;
371+
wq->high->limit_active = limit_active;
361372
}
362373

363374
void btrfs_set_work_high_priority(struct btrfs_work *work)

fs/btrfs/async-thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ BTRFS_WORK_HELPER_PROTO(scrubparity_helper);
6969

7070
struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
7171
unsigned int flags,
72-
int max_active,
72+
int limit_active,
7373
int thresh);
7474
void btrfs_init_work(struct btrfs_work *work, btrfs_work_func_t helper,
7575
btrfs_func_t func,

fs/btrfs/dev-replace.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
183183
}
184184

185185
out:
186-
if (path)
187-
btrfs_free_path(path);
186+
btrfs_free_path(path);
188187
return ret;
189188
}
190189

fs/btrfs/disk-io.c

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,6 +3443,26 @@ static int barrier_all_devices(struct btrfs_fs_info *info)
34433443
return 0;
34443444
}
34453445

3446+
int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags)
3447+
{
3448+
if ((flags & (BTRFS_BLOCK_GROUP_DUP |
3449+
BTRFS_BLOCK_GROUP_RAID0 |
3450+
BTRFS_AVAIL_ALLOC_BIT_SINGLE)) ||
3451+
((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0))
3452+
return 0;
3453+
3454+
if (flags & (BTRFS_BLOCK_GROUP_RAID1 |
3455+
BTRFS_BLOCK_GROUP_RAID5 |
3456+
BTRFS_BLOCK_GROUP_RAID10))
3457+
return 1;
3458+
3459+
if (flags & BTRFS_BLOCK_GROUP_RAID6)
3460+
return 2;
3461+
3462+
pr_warn("BTRFS: unknown raid type: %llu\n", flags);
3463+
return 0;
3464+
}
3465+
34463466
int btrfs_calc_num_tolerated_disk_barrier_failures(
34473467
struct btrfs_fs_info *fs_info)
34483468
{
@@ -3452,13 +3472,12 @@ int btrfs_calc_num_tolerated_disk_barrier_failures(
34523472
BTRFS_BLOCK_GROUP_SYSTEM,
34533473
BTRFS_BLOCK_GROUP_METADATA,
34543474
BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_METADATA};
3455-
int num_types = 4;
34563475
int i;
34573476
int c;
34583477
int num_tolerated_disk_barrier_failures =
34593478
(int)fs_info->fs_devices->num_devices;
34603479

3461-
for (i = 0; i < num_types; i++) {
3480+
for (i = 0; i < ARRAY_SIZE(types); i++) {
34623481
struct btrfs_space_info *tmp;
34633482

34643483
sinfo = NULL;
@@ -3476,44 +3495,21 @@ int btrfs_calc_num_tolerated_disk_barrier_failures(
34763495

34773496
down_read(&sinfo->groups_sem);
34783497
for (c = 0; c < BTRFS_NR_RAID_TYPES; c++) {
3479-
if (!list_empty(&sinfo->block_groups[c])) {
3480-
u64 flags;
3481-
3482-
btrfs_get_block_group_info(
3483-
&sinfo->block_groups[c], &space);
3484-
if (space.total_bytes == 0 ||
3485-
space.used_bytes == 0)
3486-
continue;
3487-
flags = space.flags;
3488-
/*
3489-
* return
3490-
* 0: if dup, single or RAID0 is configured for
3491-
* any of metadata, system or data, else
3492-
* 1: if RAID5 is configured, or if RAID1 or
3493-
* RAID10 is configured and only two mirrors
3494-
* are used, else
3495-
* 2: if RAID6 is configured, else
3496-
* num_mirrors - 1: if RAID1 or RAID10 is
3497-
* configured and more than
3498-
* 2 mirrors are used.
3499-
*/
3500-
if (num_tolerated_disk_barrier_failures > 0 &&
3501-
((flags & (BTRFS_BLOCK_GROUP_DUP |
3502-
BTRFS_BLOCK_GROUP_RAID0)) ||
3503-
((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK)
3504-
== 0)))
3505-
num_tolerated_disk_barrier_failures = 0;
3506-
else if (num_tolerated_disk_barrier_failures > 1) {
3507-
if (flags & (BTRFS_BLOCK_GROUP_RAID1 |
3508-
BTRFS_BLOCK_GROUP_RAID5 |
3509-
BTRFS_BLOCK_GROUP_RAID10)) {
3510-
num_tolerated_disk_barrier_failures = 1;
3511-
} else if (flags &
3512-
BTRFS_BLOCK_GROUP_RAID6) {
3513-
num_tolerated_disk_barrier_failures = 2;
3514-
}
3515-
}
3516-
}
3498+
u64 flags;
3499+
3500+
if (list_empty(&sinfo->block_groups[c]))
3501+
continue;
3502+
3503+
btrfs_get_block_group_info(&sinfo->block_groups[c],
3504+
&space);
3505+
if (space.total_bytes == 0 || space.used_bytes == 0)
3506+
continue;
3507+
flags = space.flags;
3508+
3509+
num_tolerated_disk_barrier_failures = min(
3510+
num_tolerated_disk_barrier_failures,
3511+
btrfs_get_num_tolerated_disk_barrier_failures(
3512+
flags));
35173513
}
35183514
up_read(&sinfo->groups_sem);
35193515
}

fs/btrfs/disk-io.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
139139
u64 objectid);
140140
int btree_lock_page_hook(struct page *page, void *data,
141141
void (*flush_fn)(void *));
142+
int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags);
142143
int btrfs_calc_num_tolerated_disk_barrier_failures(
143144
struct btrfs_fs_info *fs_info);
144145
int __init btrfs_end_io_wq_init(void);

fs/btrfs/inode.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6909,8 +6909,7 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
69096909

69106910
trace_btrfs_get_extent(root, em);
69116911

6912-
if (path)
6913-
btrfs_free_path(path);
6912+
btrfs_free_path(path);
69146913
if (trans) {
69156914
ret = btrfs_end_transaction(trans, root);
69166915
if (!err)

fs/btrfs/scrub.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3267,13 +3267,13 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
32673267
scrub_blocked_if_needed(fs_info);
32683268
}
32693269

3270-
/* for raid56, we skip parity stripe */
32713270
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
32723271
ret = get_raid56_logic_offset(physical, num, map,
32733272
&logical,
32743273
&stripe_logical);
32753274
logical += base;
32763275
if (ret) {
3276+
/* it is parity strip */
32773277
stripe_logical += base;
32783278
stripe_end = stripe_logical + increment;
32793279
ret = scrub_raid56_parity(sctx, map, scrub_dev,
@@ -3480,7 +3480,6 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
34803480

34813481
static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
34823482
struct btrfs_device *scrub_dev,
3483-
u64 chunk_tree, u64 chunk_objectid,
34843483
u64 chunk_offset, u64 length,
34853484
u64 dev_offset, int is_dev_replace)
34863485
{
@@ -3531,8 +3530,6 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
35313530
struct btrfs_root *root = sctx->dev_root;
35323531
struct btrfs_fs_info *fs_info = root->fs_info;
35333532
u64 length;
3534-
u64 chunk_tree;
3535-
u64 chunk_objectid;
35363533
u64 chunk_offset;
35373534
int ret = 0;
35383535
int slot;
@@ -3596,8 +3593,6 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
35963593
if (found_key.offset + length <= start)
35973594
goto skip;
35983595

3599-
chunk_tree = btrfs_dev_extent_chunk_tree(l, dev_extent);
3600-
chunk_objectid = btrfs_dev_extent_chunk_objectid(l, dev_extent);
36013596
chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent);
36023597

36033598
/*
@@ -3630,9 +3625,8 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
36303625
dev_replace->cursor_right = found_key.offset + length;
36313626
dev_replace->cursor_left = found_key.offset;
36323627
dev_replace->item_needs_writeback = 1;
3633-
ret = scrub_chunk(sctx, scrub_dev, chunk_tree, chunk_objectid,
3634-
chunk_offset, length, found_key.offset,
3635-
is_dev_replace);
3628+
ret = scrub_chunk(sctx, scrub_dev, chunk_offset, length,
3629+
found_key.offset, is_dev_replace);
36363630

36373631
/*
36383632
* flush, submit all pending read and write bios, afterwards

fs/btrfs/tree-defrag.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
115115
ret = -EAGAIN;
116116
}
117117
out:
118-
if (path)
119-
btrfs_free_path(path);
118+
btrfs_free_path(path);
120119
if (ret == -EAGAIN) {
121120
if (root->defrag_max.objectid > root->defrag_progress.objectid)
122121
goto done;

fs/btrfs/volumes.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3585,23 +3585,10 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
35853585
} while (read_seqretry(&fs_info->profiles_lock, seq));
35863586

35873587
if (bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) {
3588-
int num_tolerated_disk_barrier_failures;
3589-
u64 target = bctl->sys.target;
3590-
3591-
num_tolerated_disk_barrier_failures =
3592-
btrfs_calc_num_tolerated_disk_barrier_failures(fs_info);
3593-
if (num_tolerated_disk_barrier_failures > 0 &&
3594-
(target &
3595-
(BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID0 |
3596-
BTRFS_AVAIL_ALLOC_BIT_SINGLE)))
3597-
num_tolerated_disk_barrier_failures = 0;
3598-
else if (num_tolerated_disk_barrier_failures > 1 &&
3599-
(target &
3600-
(BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10)))
3601-
num_tolerated_disk_barrier_failures = 1;
3602-
3603-
fs_info->num_tolerated_disk_barrier_failures =
3604-
num_tolerated_disk_barrier_failures;
3588+
fs_info->num_tolerated_disk_barrier_failures = min(
3589+
btrfs_calc_num_tolerated_disk_barrier_failures(fs_info),
3590+
btrfs_get_num_tolerated_disk_barrier_failures(
3591+
bctl->sys.target));
36053592
}
36063593

36073594
ret = insert_balance_item(fs_info->tree_root, bctl);

0 commit comments

Comments
 (0)