Qu Wenruo
2013-Nov-07 05:51 UTC
[PATCH v3 00/17] Replace btrfs_workers with kernel workqueue based btrfs_workqueue_struct
Add a new btrfs_workqueue_struct which use kernel workqueue to implement most of the original btrfs_workers, to replace btrfs_workers. With this patchset, redundant workqueue codes are replaced with kernel workqueue infrastructure, which not only reduces the code size but also the effort to maintain it. More performace tests are ongoing, the result from sysbench shows minor improvement on the following server: CPU: two-way Xeon X5660 RAM: 4G HDD: SAS HDD, 150G total, 40G partition for btrfs test Test result: Mode|Num_threads|block size|extra flags|performance change vs 3.11 kernel rndrd 1 4K none +1.22% rndrd 1 32K none +1.00% rndrd 8 32K sync +1.35% seqrd 8 4K direct +5.56% seqwr 8 4K none -1.26% seqwr 8 32K sync +1.20% Changes below 1% are not mentioned. Overall the patchset doesn''t change the performance on HDD. Since more tests are needed, more test result are welcomed. ------ Changelog: v1->v2: - Fix some workqueue flags. v2->v3: - Add the thresholding mechanism to simulate the old behavior - Convert all the btrfs_workers to btrfs_workrqueue_struct. - Fix some potential deadlock when executed in IRQ handler. ------ Qu Wenruo (17): btrfs: Cleanup the unused struct async_sched. btrfs: Added btrfs_workqueue_struct implemented ordered execution based on kernel workqueue btrfs: Add high priority workqueue support for btrfs_workqueue_struct btrfs: Add threshold workqueue based on kernel workqueue btrfs: Replace fs_info->workers with btrfs_workqueue. btrfs: Replace fs_info->delalloc_workers with btrfs_workqueue btrfs: Replace fs_info->submit_workers with btrfs_workqueue. btrfs: Replace fs_info->flush_workers with btrfs_workqueue. btrfs: Replace fs_info->endio_* workqueue with btrfs_workqueue. btrfs: Replace fs_info->rmw_workers workqueue with btrfs_workqueue. btrfs: Replace fs_info->cache_workers workqueue with btrfs_workqueue. btrfs: Replace fs_info->readahead_workers workqueue with btrfs_workqueue. btrfs: Replace fs_info->fixup_workers workqueue with btrfs_workqueue. btrfs: Replace fs_info->delayed_workers workqueue with btrfs_workqueue. btrfs: Replace fs_info->qgroup_rescan_worker workqueue with btrfs_workqueue. btrfs: Replace fs_info->scrub_* workqueue with btrfs_workqueue. btrfs: Cleanup the old btrfs_worker. fs/btrfs/async-thread.c | 821 ++++++++++------------------------------------- fs/btrfs/async-thread.h | 152 ++++----- fs/btrfs/ctree.h | 45 ++- fs/btrfs/delayed-inode.c | 10 +- fs/btrfs/disk-io.c | 238 ++++++-------- fs/btrfs/extent-tree.c | 6 +- fs/btrfs/inode.c | 53 ++- fs/btrfs/ordered-data.c | 13 +- fs/btrfs/ordered-data.h | 4 +- fs/btrfs/qgroup.c | 17 +- fs/btrfs/raid56.c | 33 +- fs/btrfs/reada.c | 10 +- fs/btrfs/scrub.c | 94 +++--- fs/btrfs/super.c | 36 +-- fs/btrfs/volumes.c | 18 +- fs/btrfs/volumes.h | 2 +- 16 files changed, 503 insertions(+), 1049 deletions(-) -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:51 UTC
[PATCH v3 01/17] btrfs: Cleanup the unused struct async_sched.
The struct async_sched is not used by any codes and can be removed. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None. v2->v3: None. --- fs/btrfs/volumes.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index b0203b1..1bd573d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5316,13 +5316,6 @@ static void btrfs_end_bio(struct bio *bio, int err) } } -struct async_sched { - struct bio *bio; - int rw; - struct btrfs_fs_info *info; - struct btrfs_work work; -}; - /* * see run_scheduled_bios for a description of why bios are collected for * async submit. -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:51 UTC
[PATCH v3 02/17] btrfs: Added btrfs_workqueue_struct implemented ordered execution based on kernel workqueue
Use kernel workqueue to implement a new btrfs_workqueue_struct, which has the ordering execution feature like the btrfs_worker. The func is executed in a concurrency way, and the ordred_func/ordered_free is executed in the sequence them are queued after the corresponding func is done. The new btrfs_workqueue use 2 workqueues to implement the original btrfs_worker, one for the normal work and one for ordered work. At this patch, high priority work queue or thresholding is not added yet. The high priority feature and thresholding will be added in the following patches. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None. v2->v3: - Fix the potential deadline discovered by kernel lockdep. - Reuse the async-thread.[ch] files. - Make the ordered_func optional, which makes it adaptable to all btrfS_workers. --- fs/btrfs/async-thread.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/async-thread.h | 44 +++++++++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c index 08cc08f..00b4913 100644 --- a/fs/btrfs/async-thread.c +++ b/fs/btrfs/async-thread.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2007 Oracle. All rights reserved. + * Copyright (C) 2013 Fujitsu. All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public @@ -21,6 +22,8 @@ #include <linux/list.h> #include <linux/spinlock.h> #include <linux/freezer.h> +#include <linux/workqueue.h> +#include <linux/completion.h> #include "async-thread.h" #define WORK_QUEUED_BIT 0 @@ -725,3 +728,86 @@ void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work) wake_up_process(worker->task); spin_unlock_irqrestore(&worker->lock, flags); } + +struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, + char *ordered_name, + int flags, + int max_active) +{ + struct btrfs_workqueue_struct *ret = kzalloc(sizeof(*ret), GFP_NOFS); + flags |= WQ_UNBOUND; + if (unlikely(!ret)) + return NULL; + ret->normal_wq = alloc_workqueue(name, flags, max_active); + if (unlikely(!ret->normal_wq)) { + kfree(ret); + return NULL; + } + + if (ordered_name) { + ret->ordered_wq = alloc_ordered_workqueue(ordered_name, flags); + if (unlikely(!ret->ordered_wq)) { + destroy_workqueue(ret->normal_wq); + kfree(ret); + return NULL; + } + } + + spin_lock_init(&ret->insert_lock); + return ret; +} + +static void normal_work_helper(struct work_struct *arg) +{ + struct btrfs_work_struct *work; + work = container_of(arg, struct btrfs_work_struct, normal_work); + work->func(work); + complete(&work->normal_completion); +} + +static void ordered_work_helper(struct work_struct *arg) +{ + struct btrfs_work_struct *work; + work = container_of(arg, struct btrfs_work_struct, ordered_work); + wait_for_completion(&work->normal_completion); + work->ordered_func(work); + if (work->ordered_free) + work->ordered_free(work); +} + +void btrfs_init_work(struct btrfs_work_struct *work, + void (*func)(struct btrfs_work_struct *), + void (*ordered_func)(struct btrfs_work_struct *), + void (*ordered_free)(struct btrfs_work_struct *)) +{ + work->func = func; + work->ordered_func = ordered_func; + work->ordered_free = ordered_free; + INIT_WORK(&work->normal_work, normal_work_helper); + if (work->ordered_func) + INIT_WORK(&work->ordered_work, ordered_work_helper); + init_completion(&work->normal_completion); +} + +void btrfs_queue_work(struct btrfs_workqueue_struct *wq, + struct btrfs_work_struct *work) +{ + unsigned long flags; + spin_lock_irqsave(&wq->insert_lock, flags); + queue_work(wq->normal_wq, &work->normal_work); + if (wq->ordered_wq && work->ordered_func) + queue_work(wq->ordered_wq, &work->ordered_work); + spin_unlock_irqrestore(&wq->insert_lock, flags); +} + +void btrfs_destroy_workqueue(struct btrfs_workqueue_struct *wq) +{ + if (wq->ordered_wq) + destroy_workqueue(wq->ordered_wq); + destroy_workqueue(wq->normal_wq); +} + +void btrfs_workqueue_set_max(struct btrfs_workqueue_struct *wq, int max) +{ + workqueue_set_max_active(wq->normal_wq, max); +} diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h index 1f26792..eee6709 100644 --- a/fs/btrfs/async-thread.h +++ b/fs/btrfs/async-thread.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2007 Oracle. All rights reserved. + * Copyright (C) 2013 Fujitsu. All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public @@ -118,4 +119,47 @@ void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max, struct btrfs_workers *async_starter); void btrfs_requeue_work(struct btrfs_work *work); void btrfs_set_work_high_prio(struct btrfs_work *work); + +struct btrfs_workqueue_struct { + struct workqueue_struct *normal_wq; + struct workqueue_struct *ordered_wq; + + /* + * Spinlock to ensure that both ordered and normal work can + * be inserted to each workqueue at the same sequance, + * which will reduce the ordered_work waiting time and disk head moves. + */ + spinlock_t insert_lock; +}; + +struct btrfs_work_struct { + void (*func)(struct btrfs_work_struct *arg); + void (*ordered_func)(struct btrfs_work_struct *arg); + void (*ordered_free)(struct btrfs_work_struct *arg); + + /* Don''t touch things below */ + struct work_struct normal_work; + struct work_struct ordered_work; + struct completion normal_completion; +}; + +/* + * ordered_name is optional. If not given(NULL), the ordered + * workqueue will not be allocated and the ordered excution will not + * be available. The behavior will not be changed after init. + * + * flags will use the WQ_ flags, ORed with WQ_UNBOUND. + * */ +struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, + char *ordered_name, + int flags, + int max_active); +void btrfs_init_work(struct btrfs_work_struct *work, + void (*func)(struct btrfs_work_struct *), + void (*ordered_func)(struct btrfs_work_struct *), + void (*ordered_free)(struct btrfs_work_struct *)); +void btrfs_queue_work(struct btrfs_workqueue_struct *wq, + struct btrfs_work_struct *work); +void btrfs_destroy_workqueue(struct btrfs_workqueue_struct *wq); +void btrfs_workqueue_set_max(struct btrfs_workqueue_struct *wq, int max); #endif -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:51 UTC
[PATCH v3 03/17] btrfs: Add high priority workqueue support for btrfs_workqueue_struct
Add high priority workqueue, which added a new workqueue to btrfs_workqueue_struct. Whether using the high priority workqueue must be decided at initialization. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: None --- fs/btrfs/async-thread.c | 25 ++++++++++++++++++++++++- fs/btrfs/async-thread.h | 8 ++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c index 00b4913..925aa6d 100644 --- a/fs/btrfs/async-thread.c +++ b/fs/btrfs/async-thread.c @@ -731,6 +731,7 @@ void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work) struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, char *ordered_name, + char *high_name, int flags, int max_active) { @@ -753,6 +754,19 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, } } + if (high_name) { + ret->high_wq = alloc_workqueue(high_name, + flags | WQ_HIGHPRI, + max_active); + if (unlikely(!ret->high_wq)) { + destroy_workqueue(ret->normal_wq); + if (ret->ordered_wq) + destroy_workqueue(ret->ordered_wq); + kfree(ret); + return NULL; + } + } + spin_lock_init(&ret->insert_lock); return ret; } @@ -793,8 +807,13 @@ void btrfs_queue_work(struct btrfs_workqueue_struct *wq, struct btrfs_work_struct *work) { unsigned long flags; + struct workqueue_struct *dest_wq; + if (work->high && wq->high_wq) + dest_wq = wq->high_wq; + else + dest_wq = wq->normal_wq; spin_lock_irqsave(&wq->insert_lock, flags); - queue_work(wq->normal_wq, &work->normal_work); + queue_work(dest_wq, &work->normal_work); if (wq->ordered_wq && work->ordered_func) queue_work(wq->ordered_wq, &work->ordered_work); spin_unlock_irqrestore(&wq->insert_lock, flags); @@ -804,10 +823,14 @@ void btrfs_destroy_workqueue(struct btrfs_workqueue_struct *wq) { if (wq->ordered_wq) destroy_workqueue(wq->ordered_wq); + if (wq->high_wq) + destroy_workqueue(wq->high_wq); destroy_workqueue(wq->normal_wq); } void btrfs_workqueue_set_max(struct btrfs_workqueue_struct *wq, int max) { workqueue_set_max_active(wq->normal_wq, max); + if (wq->high_wq) + workqueue_set_max_active(wq->high_wq, max); } diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h index eee6709..4863c38 100644 --- a/fs/btrfs/async-thread.h +++ b/fs/btrfs/async-thread.h @@ -123,6 +123,7 @@ void btrfs_set_work_high_prio(struct btrfs_work *work); struct btrfs_workqueue_struct { struct workqueue_struct *normal_wq; struct workqueue_struct *ordered_wq; + struct workqueue_struct *high_wq; /* * Spinlock to ensure that both ordered and normal work can @@ -141,17 +142,20 @@ struct btrfs_work_struct { struct work_struct normal_work; struct work_struct ordered_work; struct completion normal_completion; + int high; }; /* * ordered_name is optional. If not given(NULL), the ordered * workqueue will not be allocated and the ordered excution will not * be available. The behavior will not be changed after init. + * The same rule is applied to high_name. * * flags will use the WQ_ flags, ORed with WQ_UNBOUND. * */ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, char *ordered_name, + char *high_name, int flags, int max_active); void btrfs_init_work(struct btrfs_work_struct *work, @@ -162,4 +166,8 @@ void btrfs_queue_work(struct btrfs_workqueue_struct *wq, struct btrfs_work_struct *work); void btrfs_destroy_workqueue(struct btrfs_workqueue_struct *wq); void btrfs_workqueue_set_max(struct btrfs_workqueue_struct *wq, int max); +static inline void btrfs_set_work_high_priority(struct btrfs_work_struct *work) +{ + work->high = 1; +} #endif -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:51 UTC
[PATCH v3 04/17] btrfs: Add threshold workqueue based on kernel workqueue
The original btrfs_workers has thresholding functions to dynamically create or destroy kthreads. Though there is no such function in kernel workqueue because the worker is not created manually, we can still use the workqueue_set_max_active to simulated the behavior, mainly to achieve a better HDD performance by setting a high threshold on submit_workers. (Sadly, no resource can be saved) So in this patch, extra workqueue pending counters are introduced to dynamically change the max active of each btrfs_workqueue_struct, hoping to restore the behavior of the original thresholding function. Also, workqueue_set_max_active use a mutex to protect workqueue_struct, which is not meant to be called too frequently, so a new interval mechanism is applied, that will only call workqueue_set_max_active after a count of work is queued. Hoping to balance both the random and sequence performance on HDD. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v2->v3: - Add thresholding mechanism to simulate the old thresholding mechanism. - Will not enable thresholding when thresh is set to small value. --- fs/btrfs/async-thread.c | 131 ++++++++++++++++++++++++++++++++++++++++++++---- fs/btrfs/async-thread.h | 24 ++++++++- 2 files changed, 144 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c index 925aa6d..1fde6a2 100644 --- a/fs/btrfs/async-thread.c +++ b/fs/btrfs/async-thread.c @@ -31,6 +31,9 @@ #define WORK_ORDER_DONE_BIT 2 #define WORK_HIGH_PRIO_BIT 3 +#define NO_THRESHOLD (-1) +#define DFT_THRESHOLD (32) + /* * container for the kthread task pointer and the list of pending work * One of these is allocated per thread. @@ -733,13 +736,31 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, char *ordered_name, char *high_name, int flags, - int max_active) + int max_active, + int thresh) { struct btrfs_workqueue_struct *ret = kzalloc(sizeof(*ret), GFP_NOFS); - flags |= WQ_UNBOUND; if (unlikely(!ret)) return NULL; - ret->normal_wq = alloc_workqueue(name, flags, max_active); + + ret->max_active = max_active; + ret->pending = 0; + /* default threshold */ + if (thresh == 0) + thresh = DFT_THRESHOLD; + /* for low threshold, no threshold is a better choice*/ + if (thresh < DFT_THRESHOLD) { + ret->current_max = max_active; + ret->thresh = NO_THRESHOLD; + } else { + ret->current_max = 1; + ret->thresh = thresh; + } + flags |= WQ_UNBOUND; + + /* The max_active of workqueue will change betwen [1,max_active], + * or just normal workqueue if NO_THRESHOLD is set*/ + ret->normal_wq = alloc_workqueue(name, flags, ret->current_max); if (unlikely(!ret->normal_wq)) { kfree(ret); return NULL; @@ -757,7 +778,7 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, if (high_name) { ret->high_wq = alloc_workqueue(high_name, flags | WQ_HIGHPRI, - max_active); + ret->current_max); if (unlikely(!ret->high_wq)) { destroy_workqueue(ret->normal_wq); if (ret->ordered_wq) @@ -767,16 +788,101 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, } } + spin_lock_init(&ret->thresh_lock); spin_lock_init(&ret->insert_lock); return ret; } +/* + * Hook for threshold which will be called in btrfs_queue_work. + * This hook WILL be called in IRQ context, + * so workqueue_set_max_active MUST NOT be called in this hook + */ +static inline void thresh_queue_hook(struct btrfs_workqueue_struct *wq) +{ + unsigned long flags; + /* Skip if no threshold is set */ + if (wq->thresh == NO_THRESHOLD) + return; + /* Since the hook may be executed in IRQ handle, we need to + * disable the IRQ */ + spin_lock_irqsave(&wq->thresh_lock, flags); + wq->pending++; + spin_unlock_irqrestore(&wq->thresh_lock, flags); +} + +/* + * Hook for threshold which will be called before executing the work, + * This hook is called in kthread content. + * So workqueue_set_max_active is called here. + */ +static inline void thresh_exec_hook(struct btrfs_workqueue_struct *wq) +{ + int new_max_active; + int need_change = 0; + unsigned long flags; + + /* Skip if no threshold is set */ + if (wq->thresh == NO_THRESHOLD) + return; + + spin_lock_irqsave(&wq->thresh_lock, flags); + wq->pending--; + wq->count++; + + /* Use 1/4 of the thresh as the interval to change the max active, + * Too high value(like twice) will make the max active change too slow, + * which will bring performance drop in random IO on HDD. + * Too small value(like 1/8 or static value) will make + * workqueue_set_max_active be called too frequently, where the mutex + * can slowdown the whole work.*/ + wq->count %= (wq->thresh / 4); + if (!wq->count) + goto out; + /* Recaculate the current max */ + new_max_active = wq->current_max; + if (wq->pending > wq->thresh) + new_max_active++; + if (wq->pending < wq->thresh / 2) + new_max_active--; + new_max_active = clamp_val(new_max_active, 1, wq->max_active); + if (new_max_active != wq->current_max) { + need_change = 1; + wq->current_max = new_max_active; + } + /* + * Workqueue is using mutex to set max active, + * so we should not call it with a spinlock hold. + * + * Also workqueue_set_max_active is somewhat expensive, + * we should not call it too frequently. + */ +out: + spin_unlock_irqrestore(&wq->thresh_lock, flags); + + if (need_change) { + workqueue_set_max_active(wq->normal_wq, wq->current_max); + if (wq->high_wq) + workqueue_set_max_active(wq->high_wq, wq->current_max); + } +} + static void normal_work_helper(struct work_struct *arg) { struct btrfs_work_struct *work; + /* + * Since some work may free the whole btrfs_work_struct in func, + * we should not access the completion which may be freed. + * But if it has ordered_func, that will be safe. + */ + int need_complete = 0; work = container_of(arg, struct btrfs_work_struct, normal_work); + if (work->ordered_func) + need_complete = 1; + thresh_exec_hook(work->wq); work->func(work); - complete(&work->normal_completion); + if (need_complete) + complete(&work->normal_completion); } static void ordered_work_helper(struct work_struct *arg) @@ -798,9 +904,10 @@ void btrfs_init_work(struct btrfs_work_struct *work, work->ordered_func = ordered_func; work->ordered_free = ordered_free; INIT_WORK(&work->normal_work, normal_work_helper); - if (work->ordered_func) + if (work->ordered_func) { INIT_WORK(&work->ordered_work, ordered_work_helper); - init_completion(&work->normal_completion); + init_completion(&work->normal_completion); + } } void btrfs_queue_work(struct btrfs_workqueue_struct *wq, @@ -808,10 +915,13 @@ void btrfs_queue_work(struct btrfs_workqueue_struct *wq, { unsigned long flags; struct workqueue_struct *dest_wq; + work->wq = wq; if (work->high && wq->high_wq) dest_wq = wq->high_wq; else dest_wq = wq->normal_wq; + + thresh_queue_hook(wq); spin_lock_irqsave(&wq->insert_lock, flags); queue_work(dest_wq, &work->normal_work); if (wq->ordered_wq && work->ordered_func) @@ -830,7 +940,8 @@ void btrfs_destroy_workqueue(struct btrfs_workqueue_struct *wq) void btrfs_workqueue_set_max(struct btrfs_workqueue_struct *wq, int max) { - workqueue_set_max_active(wq->normal_wq, max); - if (wq->high_wq) - workqueue_set_max_active(wq->high_wq, max); + unsigned long flags; + spin_lock_irqsave(&wq->thresh_lock, flags); + wq->max_active = max; + spin_unlock_irqrestore(&wq->thresh_lock, flags); } diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h index 4863c38..44942b1 100644 --- a/fs/btrfs/async-thread.h +++ b/fs/btrfs/async-thread.h @@ -131,6 +131,26 @@ struct btrfs_workqueue_struct { * which will reduce the ordered_work waiting time and disk head moves. */ spinlock_t insert_lock; + + /* + * extra variants to implement threshold workqueue + */ + int pending; /* How many works are pending */ + int max_active; /* Up limit of max running actives */ + int current_max; /* Current allowed number of running works */ + int thresh; /* Threshold, + when pending > threshold, add current_max + when pending < threshold/2, decrease + current max. When set to 0, default value + will be 32. + Also, if thresh < 8, threshold will be + disabled*/ + unsigned int count; /* Counter for preventing changing max active + too frequently. When reaching 1.5 * thresh, + then try to change current_max*/ + spinlock_t thresh_lock; /* Used to lock the above threshold related + variants. Not reuse the insert_lock to + reduce race on the same lock*/ }; struct btrfs_work_struct { @@ -142,6 +162,7 @@ struct btrfs_work_struct { struct work_struct normal_work; struct work_struct ordered_work; struct completion normal_completion; + struct btrfs_workqueue_struct *wq; int high; }; @@ -157,7 +178,8 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, char *ordered_name, char *high_name, int flags, - int max_active); + int max_active, + int thresh); void btrfs_init_work(struct btrfs_work_struct *work, void (*func)(struct btrfs_work_struct *), void (*ordered_func)(struct btrfs_work_struct *), -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:51 UTC
[PATCH v3 05/17] btrfs: Replace fs_info->workers with btrfs_workqueue.
Use the newly created btrfs_workqueue_struct to replace the original fs_info->workers Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: None --- fs/btrfs/ctree.h | 2 +- fs/btrfs/disk-io.c | 41 +++++++++++++++++++++-------------------- fs/btrfs/super.c | 2 +- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 0506f40..dbc6e2d 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1483,7 +1483,7 @@ struct btrfs_fs_info { * two */ struct btrfs_workers generic_worker; - struct btrfs_workers workers; + struct btrfs_workqueue_struct *workers; struct btrfs_workers delalloc_workers; struct btrfs_workers flush_workers; struct btrfs_workers endio_workers; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 62176ad..a467044 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -109,7 +109,7 @@ struct async_submit_bio { * can''t tell us where in the file the bio should go */ u64 bio_offset; - struct btrfs_work work; + struct btrfs_work_struct work; int error; }; @@ -749,12 +749,12 @@ int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio, unsigned long btrfs_async_submit_limit(struct btrfs_fs_info *info) { unsigned long limit = min_t(unsigned long, - info->workers.max_workers, + info->thread_pool_size, info->fs_devices->open_devices); return 256 * limit; } -static void run_one_async_start(struct btrfs_work *work) +static void run_one_async_start(struct btrfs_work_struct *work) { struct async_submit_bio *async; int ret; @@ -767,7 +767,7 @@ static void run_one_async_start(struct btrfs_work *work) async->error = ret; } -static void run_one_async_done(struct btrfs_work *work) +static void run_one_async_done(struct btrfs_work_struct *work) { struct btrfs_fs_info *fs_info; struct async_submit_bio *async; @@ -794,7 +794,7 @@ static void run_one_async_done(struct btrfs_work *work) async->bio_offset); } -static void run_one_async_free(struct btrfs_work *work) +static void run_one_async_free(struct btrfs_work_struct *work) { struct async_submit_bio *async; @@ -822,11 +822,9 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, async->submit_bio_start = submit_bio_start; async->submit_bio_done = submit_bio_done; - async->work.func = run_one_async_start; - async->work.ordered_func = run_one_async_done; - async->work.ordered_free = run_one_async_free; + btrfs_init_work(&async->work, run_one_async_start, + run_one_async_done, run_one_async_free); - async->work.flags = 0; async->bio_flags = bio_flags; async->bio_offset = bio_offset; @@ -835,9 +833,9 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, atomic_inc(&fs_info->nr_async_submits); if (rw & REQ_SYNC) - btrfs_set_work_high_prio(&async->work); + btrfs_set_work_high_priority(&async->work); - btrfs_queue_worker(&fs_info->workers, &async->work); + btrfs_queue_work(fs_info->workers, &async->work); while (atomic_read(&fs_info->async_submit_draining) && atomic_read(&fs_info->nr_async_submits)) { @@ -1997,7 +1995,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) btrfs_stop_workers(&fs_info->generic_worker); btrfs_stop_workers(&fs_info->fixup_workers); btrfs_stop_workers(&fs_info->delalloc_workers); - btrfs_stop_workers(&fs_info->workers); + btrfs_destroy_workqueue(fs_info->workers); btrfs_stop_workers(&fs_info->endio_workers); btrfs_stop_workers(&fs_info->endio_meta_workers); btrfs_stop_workers(&fs_info->endio_raid56_workers); @@ -2117,6 +2115,8 @@ int open_ctree(struct super_block *sb, int err = -EINVAL; int num_backups_tried = 0; int backup_index = 0; + int max_active; + int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE; bool create_uuid_tree; bool check_uuid_tree; @@ -2477,12 +2477,13 @@ int open_ctree(struct super_block *sb, goto fail_alloc; } + max_active = fs_info->thread_pool_size; btrfs_init_workers(&fs_info->generic_worker, "genwork", 1, NULL); - btrfs_init_workers(&fs_info->workers, "worker", - fs_info->thread_pool_size, - &fs_info->generic_worker); + fs_info->workers = btrfs_alloc_workqueue("worker", "worker-ordered", + "worker-high", flags, + max_active, 16); btrfs_init_workers(&fs_info->delalloc_workers, "delalloc", fs_info->thread_pool_size, NULL); @@ -2503,9 +2504,6 @@ int open_ctree(struct super_block *sb, */ fs_info->submit_workers.idle_thresh = 64; - fs_info->workers.idle_thresh = 16; - fs_info->workers.ordered = 1; - fs_info->delalloc_workers.idle_thresh = 2; fs_info->delalloc_workers.ordered = 1; @@ -2557,8 +2555,7 @@ int open_ctree(struct super_block *sb, * btrfs_start_workers can really only fail because of ENOMEM so just * return -ENOMEM if any of these fail. */ - ret = btrfs_start_workers(&fs_info->workers); - ret |= btrfs_start_workers(&fs_info->generic_worker); + ret = btrfs_start_workers(&fs_info->generic_worker); ret |= btrfs_start_workers(&fs_info->submit_workers); ret |= btrfs_start_workers(&fs_info->delalloc_workers); ret |= btrfs_start_workers(&fs_info->fixup_workers); @@ -2578,6 +2575,10 @@ int open_ctree(struct super_block *sb, err = -ENOMEM; goto fail_sb_buffer; } + if (!(fs_info->workers)) { + err = -ENOMEM; + goto fail_sb_buffer; + } fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super); fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages, diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index e913328..623be23 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1246,7 +1246,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, old_pool_size, new_pool_size); btrfs_set_max_workers(&fs_info->generic_worker, new_pool_size); - btrfs_set_max_workers(&fs_info->workers, new_pool_size); + btrfs_workqueue_set_max(fs_info->workers, new_pool_size); btrfs_set_max_workers(&fs_info->delalloc_workers, new_pool_size); btrfs_set_max_workers(&fs_info->submit_workers, new_pool_size); btrfs_set_max_workers(&fs_info->caching_workers, new_pool_size); -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:51 UTC
[PATCH v3 06/17] btrfs: Replace fs_info->delalloc_workers with btrfs_workqueue
Much like the fs_info->workers, replace the fs_info->delalloc_workers use the same btrfs_workqueue. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: None --- fs/btrfs/ctree.h | 2 +- fs/btrfs/disk-io.c | 14 ++++++-------- fs/btrfs/inode.c | 18 ++++++++---------- fs/btrfs/super.c | 2 +- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index dbc6e2d..f38285e 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1484,7 +1484,7 @@ struct btrfs_fs_info { */ struct btrfs_workers generic_worker; struct btrfs_workqueue_struct *workers; - struct btrfs_workers delalloc_workers; + struct btrfs_workqueue_struct *delalloc_workers; struct btrfs_workers flush_workers; struct btrfs_workers endio_workers; struct btrfs_workers endio_meta_workers; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index a467044..ed2eb52 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1994,7 +1994,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) { btrfs_stop_workers(&fs_info->generic_worker); btrfs_stop_workers(&fs_info->fixup_workers); - btrfs_stop_workers(&fs_info->delalloc_workers); + btrfs_destroy_workqueue(fs_info->delalloc_workers); btrfs_destroy_workqueue(fs_info->workers); btrfs_stop_workers(&fs_info->endio_workers); btrfs_stop_workers(&fs_info->endio_meta_workers); @@ -2485,8 +2485,10 @@ int open_ctree(struct super_block *sb, "worker-high", flags, max_active, 16); - btrfs_init_workers(&fs_info->delalloc_workers, "delalloc", - fs_info->thread_pool_size, NULL); + fs_info->delalloc_workers = btrfs_alloc_workqueue("delalloc", + "delalloc-ordered", + NULL, flags, + max_active, 2); btrfs_init_workers(&fs_info->flush_workers, "flush_delalloc", fs_info->thread_pool_size, NULL); @@ -2504,9 +2506,6 @@ int open_ctree(struct super_block *sb, */ fs_info->submit_workers.idle_thresh = 64; - fs_info->delalloc_workers.idle_thresh = 2; - fs_info->delalloc_workers.ordered = 1; - btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1, &fs_info->generic_worker); btrfs_init_workers(&fs_info->endio_workers, "endio", @@ -2557,7 +2556,6 @@ int open_ctree(struct super_block *sb, */ ret = btrfs_start_workers(&fs_info->generic_worker); ret |= btrfs_start_workers(&fs_info->submit_workers); - ret |= btrfs_start_workers(&fs_info->delalloc_workers); ret |= btrfs_start_workers(&fs_info->fixup_workers); ret |= btrfs_start_workers(&fs_info->endio_workers); ret |= btrfs_start_workers(&fs_info->endio_meta_workers); @@ -2575,7 +2573,7 @@ int open_ctree(struct super_block *sb, err = -ENOMEM; goto fail_sb_buffer; } - if (!(fs_info->workers)) { + if (!(fs_info->workers && fs_info->delalloc_workers)) { err = -ENOMEM; goto fail_sb_buffer; } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 3b4ffaf..42e3f81 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -306,7 +306,7 @@ struct async_cow { u64 start; u64 end; struct list_head extents; - struct btrfs_work work; + struct btrfs_work_struct work; }; static noinline int add_async_extent(struct async_cow *cow, @@ -978,7 +978,7 @@ out_unlock: /* * work queue call back to started compression on a file and pages */ -static noinline void async_cow_start(struct btrfs_work *work) +static noinline void async_cow_start(struct btrfs_work_struct *work) { struct async_cow *async_cow; int num_added = 0; @@ -996,7 +996,7 @@ static noinline void async_cow_start(struct btrfs_work *work) /* * work queue call back to submit previously compressed pages */ -static noinline void async_cow_submit(struct btrfs_work *work) +static noinline void async_cow_submit(struct btrfs_work_struct *work) { struct async_cow *async_cow; struct btrfs_root *root; @@ -1017,7 +1017,7 @@ static noinline void async_cow_submit(struct btrfs_work *work) submit_compressed_extents(async_cow->inode, async_cow); } -static noinline void async_cow_free(struct btrfs_work *work) +static noinline void async_cow_free(struct btrfs_work_struct *work) { struct async_cow *async_cow; async_cow = container_of(work, struct async_cow, work); @@ -1054,17 +1054,15 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page, async_cow->end = cur_end; INIT_LIST_HEAD(&async_cow->extents); - async_cow->work.func = async_cow_start; - async_cow->work.ordered_func = async_cow_submit; - async_cow->work.ordered_free = async_cow_free; - async_cow->work.flags = 0; + btrfs_init_work(&async_cow->work, async_cow_start, + async_cow_submit, async_cow_free); nr_pages = (cur_end - start + PAGE_CACHE_SIZE) >> PAGE_CACHE_SHIFT; atomic_add(nr_pages, &root->fs_info->async_delalloc_pages); - btrfs_queue_worker(&root->fs_info->delalloc_workers, - &async_cow->work); + btrfs_queue_work(root->fs_info->delalloc_workers, + &async_cow->work); if (atomic_read(&root->fs_info->async_delalloc_pages) > limit) { wait_event(root->fs_info->async_submit_wait, diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 623be23..6f0d206 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1247,7 +1247,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, btrfs_set_max_workers(&fs_info->generic_worker, new_pool_size); btrfs_workqueue_set_max(fs_info->workers, new_pool_size); - btrfs_set_max_workers(&fs_info->delalloc_workers, new_pool_size); + btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size); btrfs_set_max_workers(&fs_info->submit_workers, new_pool_size); btrfs_set_max_workers(&fs_info->caching_workers, new_pool_size); btrfs_set_max_workers(&fs_info->fixup_workers, new_pool_size); -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:51 UTC
[PATCH v3 07/17] btrfs: Replace fs_info->submit_workers with btrfs_workqueue.
Much like the fs_info->workers, replace the fs_info->submit_workers use the same btrfs_workqueue. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: None --- fs/btrfs/ctree.h | 2 +- fs/btrfs/disk-io.c | 22 +++++++++++----------- fs/btrfs/super.c | 2 +- fs/btrfs/volumes.c | 11 ++++++----- fs/btrfs/volumes.h | 2 +- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index f38285e..3edb9e6 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1493,7 +1493,7 @@ struct btrfs_fs_info { struct btrfs_workers endio_meta_write_workers; struct btrfs_workers endio_write_workers; struct btrfs_workers endio_freespace_worker; - struct btrfs_workers submit_workers; + struct btrfs_workqueue_struct *submit_workers; struct btrfs_workers caching_workers; struct btrfs_workers readahead_workers; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index ed2eb52..ec474c8 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2003,7 +2003,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) btrfs_stop_workers(&fs_info->endio_meta_write_workers); btrfs_stop_workers(&fs_info->endio_write_workers); btrfs_stop_workers(&fs_info->endio_freespace_worker); - btrfs_stop_workers(&fs_info->submit_workers); + btrfs_destroy_workqueue(fs_info->submit_workers); btrfs_stop_workers(&fs_info->delayed_workers); btrfs_stop_workers(&fs_info->caching_workers); btrfs_stop_workers(&fs_info->readahead_workers); @@ -2493,18 +2493,18 @@ int open_ctree(struct super_block *sb, btrfs_init_workers(&fs_info->flush_workers, "flush_delalloc", fs_info->thread_pool_size, NULL); - btrfs_init_workers(&fs_info->submit_workers, "submit", - min_t(u64, fs_devices->num_devices, - fs_info->thread_pool_size), NULL); - - btrfs_init_workers(&fs_info->caching_workers, "cache", - fs_info->thread_pool_size, NULL); - /* a higher idle thresh on the submit workers makes it much more * likely that bios will be send down in a sane order to the * devices */ - fs_info->submit_workers.idle_thresh = 64; + fs_info->submit_workers = btrfs_alloc_workqueue("submit", NULL, NULL, + flags, min_t(u64, + fs_devices->num_devices, + max_active), 64); + + btrfs_init_workers(&fs_info->caching_workers, "cache", + fs_info->thread_pool_size, NULL); + btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1, &fs_info->generic_worker); @@ -2555,7 +2555,6 @@ int open_ctree(struct super_block *sb, * return -ENOMEM if any of these fail. */ ret = btrfs_start_workers(&fs_info->generic_worker); - ret |= btrfs_start_workers(&fs_info->submit_workers); ret |= btrfs_start_workers(&fs_info->fixup_workers); ret |= btrfs_start_workers(&fs_info->endio_workers); ret |= btrfs_start_workers(&fs_info->endio_meta_workers); @@ -2573,7 +2572,8 @@ int open_ctree(struct super_block *sb, err = -ENOMEM; goto fail_sb_buffer; } - if (!(fs_info->workers && fs_info->delalloc_workers)) { + if (!(fs_info->workers && fs_info->delalloc_workers && + fs_info->submit_workers)) { err = -ENOMEM; goto fail_sb_buffer; } diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 6f0d206..4c5b4f2 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1248,7 +1248,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, btrfs_set_max_workers(&fs_info->generic_worker, new_pool_size); btrfs_workqueue_set_max(fs_info->workers, new_pool_size); btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size); - btrfs_set_max_workers(&fs_info->submit_workers, new_pool_size); + btrfs_workqueue_set_max(fs_info->submit_workers, new_pool_size); btrfs_set_max_workers(&fs_info->caching_workers, new_pool_size); btrfs_set_max_workers(&fs_info->fixup_workers, new_pool_size); btrfs_set_max_workers(&fs_info->endio_workers, new_pool_size); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1bd573d..321a687 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -416,7 +416,8 @@ loop_lock: device->running_pending = 1; spin_unlock(&device->io_lock); - btrfs_requeue_work(&device->work); + btrfs_queue_work(fs_info->submit_workers, + &device->work); goto done; } /* unplug every 64 requests just for good measure */ @@ -440,7 +441,7 @@ done: blk_finish_plug(&plug); } -static void pending_bios_fn(struct btrfs_work *work) +static void pending_bios_fn(struct btrfs_work_struct *work) { struct btrfs_device *device; @@ -5372,8 +5373,8 @@ static noinline void btrfs_schedule_bio(struct btrfs_root *root, spin_unlock(&device->io_lock); if (should_queue) - btrfs_queue_worker(&root->fs_info->submit_workers, - &device->work); + btrfs_queue_work(root->fs_info->submit_workers, + &device->work); } static int bio_size_ok(struct block_device *bdev, struct bio *bio, @@ -5651,7 +5652,7 @@ struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info, else generate_random_uuid(dev->uuid); - dev->work.func = pending_bios_fn; + btrfs_init_work(&dev->work, pending_bios_fn, NULL, NULL); return dev; } diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index b72f540..ab897cb 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -91,7 +91,7 @@ struct btrfs_device { /* per-device scrub information */ struct scrub_ctx *scrub_device; - struct btrfs_work work; + struct btrfs_work_struct work; struct rcu_head rcu; struct work_struct rcu_work; -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:51 UTC
[PATCH v3 08/17] btrfs: Replace fs_info->flush_workers with btrfs_workqueue.
Replace the fs_info->submit_workers with the newly created btrfs_workqueue. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: - Use the btrfs_workqueue_struct to replace submit_workers. --- fs/btrfs/ctree.h | 4 ++-- fs/btrfs/disk-io.c | 10 +++++----- fs/btrfs/inode.c | 7 ++++--- fs/btrfs/ordered-data.c | 13 +++++++------ fs/btrfs/ordered-data.h | 2 +- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 3edb9e6..c74f27e 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1485,7 +1485,7 @@ struct btrfs_fs_info { struct btrfs_workers generic_worker; struct btrfs_workqueue_struct *workers; struct btrfs_workqueue_struct *delalloc_workers; - struct btrfs_workers flush_workers; + struct btrfs_workqueue_struct *flush_workers; struct btrfs_workers endio_workers; struct btrfs_workers endio_meta_workers; struct btrfs_workers endio_raid56_workers; @@ -3625,7 +3625,7 @@ struct btrfs_delalloc_work { int delay_iput; struct completion completion; struct list_head list; - struct btrfs_work work; + struct btrfs_work_struct work; }; struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode, diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index ec474c8..3e4adff 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2007,7 +2007,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) btrfs_stop_workers(&fs_info->delayed_workers); btrfs_stop_workers(&fs_info->caching_workers); btrfs_stop_workers(&fs_info->readahead_workers); - btrfs_stop_workers(&fs_info->flush_workers); + btrfs_destroy_workqueue(fs_info->flush_workers); btrfs_stop_workers(&fs_info->qgroup_rescan_workers); } @@ -2490,8 +2490,9 @@ int open_ctree(struct super_block *sb, NULL, flags, max_active, 2); - btrfs_init_workers(&fs_info->flush_workers, "flush_delalloc", - fs_info->thread_pool_size, NULL); + fs_info->flush_workers = btrfs_alloc_workqueue("flush_delalloc", + NULL, NULL, flags, + max_active, 0); /* a higher idle thresh on the submit workers makes it much more * likely that bios will be send down in a sane order to the @@ -2566,14 +2567,13 @@ int open_ctree(struct super_block *sb, ret |= btrfs_start_workers(&fs_info->delayed_workers); ret |= btrfs_start_workers(&fs_info->caching_workers); ret |= btrfs_start_workers(&fs_info->readahead_workers); - ret |= btrfs_start_workers(&fs_info->flush_workers); ret |= btrfs_start_workers(&fs_info->qgroup_rescan_workers); if (ret) { err = -ENOMEM; goto fail_sb_buffer; } if (!(fs_info->workers && fs_info->delalloc_workers && - fs_info->submit_workers)) { + fs_info->submit_workers && fs_info->flush_workers)) { err = -ENOMEM; goto fail_sb_buffer; } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 42e3f81..5e5fc7f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8138,7 +8138,7 @@ out_notrans: return ret; } -static void btrfs_run_delalloc_work(struct btrfs_work *work) +static void btrfs_run_delalloc_work(struct btrfs_work_struct *work) { struct btrfs_delalloc_work *delalloc_work; @@ -8170,6 +8170,7 @@ struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode, work->inode = inode; work->wait = wait; work->delay_iput = delay_iput; + btrfs_init_work(&work->work, btrfs_run_delalloc_work, NULL, NULL); work->work.func = btrfs_run_delalloc_work; return work; @@ -8222,8 +8223,8 @@ static int __start_delalloc_inodes(struct btrfs_root *root, int delay_iput) goto out; } list_add_tail(&work->list, &works); - btrfs_queue_worker(&root->fs_info->flush_workers, - &work->work); + btrfs_queue_work(root->fs_info->flush_workers, + &work->work); cond_resched(); spin_lock(&root->delalloc_lock); diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index c702cb6..08b30e5 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -550,7 +550,7 @@ void btrfs_remove_ordered_extent(struct inode *inode, wake_up(&entry->wait); } -static void btrfs_run_ordered_extent_work(struct btrfs_work *work) +static void btrfs_run_ordered_extent_work(struct btrfs_work_struct *work) { struct btrfs_ordered_extent *ordered; @@ -582,10 +582,11 @@ void btrfs_wait_ordered_extents(struct btrfs_root *root) atomic_inc(&ordered->refs); spin_unlock(&root->ordered_extent_lock); - ordered->flush_work.func = btrfs_run_ordered_extent_work; + btrfs_init_work(&ordered->flush_work, + btrfs_run_ordered_extent_work, NULL, NULL); list_add_tail(&ordered->work_list, &works); - btrfs_queue_worker(&root->fs_info->flush_workers, - &ordered->flush_work); + btrfs_queue_work(root->fs_info->flush_workers, + &ordered->flush_work); cond_resched(); spin_lock(&root->ordered_extent_lock); @@ -686,8 +687,8 @@ int btrfs_run_ordered_operations(struct btrfs_trans_handle *trans, goto out; } list_add_tail(&work->list, &works); - btrfs_queue_worker(&root->fs_info->flush_workers, - &work->work); + btrfs_queue_work(root->fs_info->flush_workers, + &work->work); cond_resched(); spin_lock(&root->fs_info->ordered_root_lock); diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index 0c0b356..7496866 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -133,7 +133,7 @@ struct btrfs_ordered_extent { struct btrfs_work work; struct completion completion; - struct btrfs_work flush_work; + struct btrfs_work_struct flush_work; struct list_head work_list; }; -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:51 UTC
[PATCH v3 09/17] btrfs: Replace fs_info->endio_* workqueue with btrfs_workqueue.
Replace the fs_info->endio_* workqueues with the newly created btrfs_workqueue. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: - Use the btrfs_workqueue_struct to replace endio_*. --- fs/btrfs/ctree.h | 12 +++--- fs/btrfs/disk-io.c | 110 +++++++++++++++++++++++------------------------- fs/btrfs/inode.c | 20 ++++----- fs/btrfs/ordered-data.h | 2 +- fs/btrfs/super.c | 11 ++--- 5 files changed, 74 insertions(+), 81 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index c74f27e..e8916e3 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1486,13 +1486,13 @@ struct btrfs_fs_info { struct btrfs_workqueue_struct *workers; struct btrfs_workqueue_struct *delalloc_workers; struct btrfs_workqueue_struct *flush_workers; - struct btrfs_workers endio_workers; - struct btrfs_workers endio_meta_workers; - struct btrfs_workers endio_raid56_workers; + struct btrfs_workqueue_struct *endio_workers; + struct btrfs_workqueue_struct *endio_meta_workers; + struct btrfs_workqueue_struct *endio_raid56_workers; struct btrfs_workers rmw_workers; - struct btrfs_workers endio_meta_write_workers; - struct btrfs_workers endio_write_workers; - struct btrfs_workers endio_freespace_worker; + struct btrfs_workqueue_struct *endio_meta_write_workers; + struct btrfs_workqueue_struct *endio_write_workers; + struct btrfs_workqueue_struct *endio_freespace_worker; struct btrfs_workqueue_struct *submit_workers; struct btrfs_workers caching_workers; struct btrfs_workers readahead_workers; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 3e4adff..7099001 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -55,7 +55,7 @@ #endif static struct extent_io_ops btree_extent_io_ops; -static void end_workqueue_fn(struct btrfs_work *work); +static void end_workqueue_fn(struct btrfs_work_struct *work); static void free_fs_root(struct btrfs_root *root); static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, int read_only); @@ -87,7 +87,7 @@ struct end_io_wq { int error; int metadata; struct list_head list; - struct btrfs_work work; + struct btrfs_work_struct work; }; /* @@ -689,32 +689,31 @@ static void end_workqueue_bio(struct bio *bio, int err) fs_info = end_io_wq->info; end_io_wq->error = err; - end_io_wq->work.func = end_workqueue_fn; - end_io_wq->work.flags = 0; + btrfs_init_work(&end_io_wq->work, end_workqueue_fn, NULL, NULL); if (bio->bi_rw & REQ_WRITE) { if (end_io_wq->metadata == BTRFS_WQ_ENDIO_METADATA) - btrfs_queue_worker(&fs_info->endio_meta_write_workers, - &end_io_wq->work); + btrfs_queue_work(fs_info->endio_meta_write_workers, + &end_io_wq->work); else if (end_io_wq->metadata == BTRFS_WQ_ENDIO_FREE_SPACE) - btrfs_queue_worker(&fs_info->endio_freespace_worker, - &end_io_wq->work); + btrfs_queue_work(fs_info->endio_freespace_worker, + &end_io_wq->work); else if (end_io_wq->metadata == BTRFS_WQ_ENDIO_RAID56) - btrfs_queue_worker(&fs_info->endio_raid56_workers, - &end_io_wq->work); + btrfs_queue_work(fs_info->endio_raid56_workers, + &end_io_wq->work); else - btrfs_queue_worker(&fs_info->endio_write_workers, - &end_io_wq->work); + btrfs_queue_work(fs_info->endio_write_workers, + &end_io_wq->work); } else { if (end_io_wq->metadata == BTRFS_WQ_ENDIO_RAID56) - btrfs_queue_worker(&fs_info->endio_raid56_workers, - &end_io_wq->work); + btrfs_queue_work(fs_info->endio_raid56_workers, + &end_io_wq->work); else if (end_io_wq->metadata) - btrfs_queue_worker(&fs_info->endio_meta_workers, - &end_io_wq->work); + btrfs_queue_work(fs_info->endio_meta_workers, + &end_io_wq->work); else - btrfs_queue_worker(&fs_info->endio_workers, - &end_io_wq->work); + btrfs_queue_work(fs_info->endio_workers, + &end_io_wq->work); } } @@ -1667,7 +1666,7 @@ static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi) * called by the kthread helper functions to finally call the bio end_io * functions. This is where read checksum verification actually happens */ -static void end_workqueue_fn(struct btrfs_work *work) +static void end_workqueue_fn(struct btrfs_work_struct *work) { struct bio *bio; struct end_io_wq *end_io_wq; @@ -1996,13 +1995,13 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) btrfs_stop_workers(&fs_info->fixup_workers); btrfs_destroy_workqueue(fs_info->delalloc_workers); btrfs_destroy_workqueue(fs_info->workers); - btrfs_stop_workers(&fs_info->endio_workers); - btrfs_stop_workers(&fs_info->endio_meta_workers); - btrfs_stop_workers(&fs_info->endio_raid56_workers); + btrfs_destroy_workqueue(fs_info->endio_workers); + btrfs_destroy_workqueue(fs_info->endio_meta_workers); + btrfs_destroy_workqueue(fs_info->endio_raid56_workers); btrfs_stop_workers(&fs_info->rmw_workers); - btrfs_stop_workers(&fs_info->endio_meta_write_workers); - btrfs_stop_workers(&fs_info->endio_write_workers); - btrfs_stop_workers(&fs_info->endio_freespace_worker); + btrfs_destroy_workqueue(fs_info->endio_meta_write_workers); + btrfs_destroy_workqueue(fs_info->endio_write_workers); + btrfs_destroy_workqueue(fs_info->endio_freespace_worker); btrfs_destroy_workqueue(fs_info->submit_workers); btrfs_stop_workers(&fs_info->delayed_workers); btrfs_stop_workers(&fs_info->caching_workers); @@ -2509,26 +2508,32 @@ int open_ctree(struct super_block *sb, btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1, &fs_info->generic_worker); - btrfs_init_workers(&fs_info->endio_workers, "endio", - fs_info->thread_pool_size, - &fs_info->generic_worker); - btrfs_init_workers(&fs_info->endio_meta_workers, "endio-meta", - fs_info->thread_pool_size, - &fs_info->generic_worker); - btrfs_init_workers(&fs_info->endio_meta_write_workers, - "endio-meta-write", fs_info->thread_pool_size, - &fs_info->generic_worker); - btrfs_init_workers(&fs_info->endio_raid56_workers, - "endio-raid56", fs_info->thread_pool_size, - &fs_info->generic_worker); + /* + * endios are largely parallel and should have a very + * low idle thresh + */ + fs_info->endio_workers = btrfs_alloc_workqueue("endio", NULL, NULL, + flags, max_active, 4); + fs_info->endio_meta_workers = btrfs_alloc_workqueue("endio-meta", + NULL, NULL, flags, + max_active, 4); + fs_info->endio_meta_write_workers + btrfs_alloc_workqueue("endio-meta-write", NULL, NULL, + flags, max_active, 2); + fs_info->endio_raid56_workers = btrfs_alloc_workqueue("endio-raid56", + NULL, NULL, + flags, + max_active, 4); btrfs_init_workers(&fs_info->rmw_workers, "rmw", fs_info->thread_pool_size, &fs_info->generic_worker); - btrfs_init_workers(&fs_info->endio_write_workers, "endio-write", - fs_info->thread_pool_size, - &fs_info->generic_worker); - btrfs_init_workers(&fs_info->endio_freespace_worker, "freespace-write", - 1, &fs_info->generic_worker); + fs_info->endio_write_workers = btrfs_alloc_workqueue("endio-write", + NULL, NULL, + flags, + max_active, 2); + fs_info->endio_freespace_worker + btrfs_alloc_workqueue("freespace-write", NULL, NULL, + flags, max_active, 0); btrfs_init_workers(&fs_info->delayed_workers, "delayed-meta", fs_info->thread_pool_size, &fs_info->generic_worker); @@ -2538,17 +2543,8 @@ int open_ctree(struct super_block *sb, btrfs_init_workers(&fs_info->qgroup_rescan_workers, "qgroup-rescan", 1, &fs_info->generic_worker); - /* - * endios are largely parallel and should have a very - * low idle thresh - */ - fs_info->endio_workers.idle_thresh = 4; - fs_info->endio_meta_workers.idle_thresh = 4; - fs_info->endio_raid56_workers.idle_thresh = 4; fs_info->rmw_workers.idle_thresh = 2; - fs_info->endio_write_workers.idle_thresh = 2; - fs_info->endio_meta_write_workers.idle_thresh = 2; fs_info->readahead_workers.idle_thresh = 2; /* @@ -2557,13 +2553,7 @@ int open_ctree(struct super_block *sb, */ ret = btrfs_start_workers(&fs_info->generic_worker); ret |= btrfs_start_workers(&fs_info->fixup_workers); - ret |= btrfs_start_workers(&fs_info->endio_workers); - ret |= btrfs_start_workers(&fs_info->endio_meta_workers); ret |= btrfs_start_workers(&fs_info->rmw_workers); - ret |= btrfs_start_workers(&fs_info->endio_raid56_workers); - ret |= btrfs_start_workers(&fs_info->endio_meta_write_workers); - ret |= btrfs_start_workers(&fs_info->endio_write_workers); - ret |= btrfs_start_workers(&fs_info->endio_freespace_worker); ret |= btrfs_start_workers(&fs_info->delayed_workers); ret |= btrfs_start_workers(&fs_info->caching_workers); ret |= btrfs_start_workers(&fs_info->readahead_workers); @@ -2573,7 +2563,11 @@ int open_ctree(struct super_block *sb, goto fail_sb_buffer; } if (!(fs_info->workers && fs_info->delalloc_workers && - fs_info->submit_workers && fs_info->flush_workers)) { + fs_info->submit_workers && fs_info->flush_workers && + fs_info->endio_workers && fs_info->endio_meta_workers && + fs_info->endio_meta_write_workers && + fs_info->endio_write_workers && fs_info->endio_raid56_workers && + fs_info->endio_freespace_worker)) { err = -ENOMEM; goto fail_sb_buffer; } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5e5fc7f..9dd807d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2719,7 +2719,7 @@ out: return ret; } -static void finish_ordered_fn(struct btrfs_work *work) +static void finish_ordered_fn(struct btrfs_work_struct *work) { struct btrfs_ordered_extent *ordered_extent; ordered_extent = container_of(work, struct btrfs_ordered_extent, work); @@ -2732,7 +2732,7 @@ static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end, struct inode *inode = page->mapping->host; struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_ordered_extent *ordered_extent = NULL; - struct btrfs_workers *workers; + struct btrfs_workqueue_struct *workers; trace_btrfs_writepage_end_io_hook(page, start, end, uptodate); @@ -2741,14 +2741,13 @@ static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end, end - start + 1, uptodate)) return 0; - ordered_extent->work.func = finish_ordered_fn; - ordered_extent->work.flags = 0; + btrfs_init_work(&ordered_extent->work, finish_ordered_fn, NULL, NULL); if (btrfs_is_free_space_inode(inode)) - workers = &root->fs_info->endio_freespace_worker; + workers = root->fs_info->endio_freespace_worker; else - workers = &root->fs_info->endio_write_workers; - btrfs_queue_worker(workers, &ordered_extent->work); + workers = root->fs_info->endio_write_workers; + btrfs_queue_work(workers, &ordered_extent->work); return 0; } @@ -6835,10 +6834,9 @@ again: if (!ret) goto out_test; - ordered->work.func = finish_ordered_fn; - ordered->work.flags = 0; - btrfs_queue_worker(&root->fs_info->endio_write_workers, - &ordered->work); + btrfs_init_work(&ordered->work, finish_ordered_fn, NULL, NULL); + btrfs_queue_work(root->fs_info->endio_write_workers, + &ordered->work); out_test: /* * our bio might span multiple ordered extents. If we haven''t diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index 7496866..86a3a86 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -130,7 +130,7 @@ struct btrfs_ordered_extent { /* a per root list of all the pending ordered extents */ struct list_head root_extent_list; - struct btrfs_work work; + struct btrfs_work_struct work; struct completion completion; struct btrfs_work_struct flush_work; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 4c5b4f2..a8fc05d 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1251,11 +1251,12 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, btrfs_workqueue_set_max(fs_info->submit_workers, new_pool_size); btrfs_set_max_workers(&fs_info->caching_workers, new_pool_size); btrfs_set_max_workers(&fs_info->fixup_workers, new_pool_size); - btrfs_set_max_workers(&fs_info->endio_workers, new_pool_size); - btrfs_set_max_workers(&fs_info->endio_meta_workers, new_pool_size); - btrfs_set_max_workers(&fs_info->endio_meta_write_workers, new_pool_size); - btrfs_set_max_workers(&fs_info->endio_write_workers, new_pool_size); - btrfs_set_max_workers(&fs_info->endio_freespace_worker, new_pool_size); + btrfs_workqueue_set_max(fs_info->endio_workers, new_pool_size); + btrfs_workqueue_set_max(fs_info->endio_meta_workers, new_pool_size); + btrfs_workqueue_set_max(fs_info->endio_meta_write_workers, + new_pool_size); + btrfs_workqueue_set_max(fs_info->endio_write_workers, new_pool_size); + btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size); btrfs_set_max_workers(&fs_info->delayed_workers, new_pool_size); btrfs_set_max_workers(&fs_info->readahead_workers, new_pool_size); btrfs_set_max_workers(&fs_info->scrub_wr_completion_workers, -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:52 UTC
[PATCH v3 10/17] btrfs: Replace fs_info->rmw_workers workqueue with btrfs_workqueue.
Replace the fs_info->rmw_workers with the newly created btrfs_workqueue. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: - Use the btrfs_workqueue_struct to replace rmw_workers. --- fs/btrfs/ctree.h | 2 +- fs/btrfs/disk-io.c | 12 ++++-------- fs/btrfs/raid56.c | 33 +++++++++++++++------------------ 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index e8916e3..89a5411 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1489,7 +1489,7 @@ struct btrfs_fs_info { struct btrfs_workqueue_struct *endio_workers; struct btrfs_workqueue_struct *endio_meta_workers; struct btrfs_workqueue_struct *endio_raid56_workers; - struct btrfs_workers rmw_workers; + struct btrfs_workqueue_struct *rmw_workers; struct btrfs_workqueue_struct *endio_meta_write_workers; struct btrfs_workqueue_struct *endio_write_workers; struct btrfs_workqueue_struct *endio_freespace_worker; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 7099001..d6f5cf7 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1998,7 +1998,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) btrfs_destroy_workqueue(fs_info->endio_workers); btrfs_destroy_workqueue(fs_info->endio_meta_workers); btrfs_destroy_workqueue(fs_info->endio_raid56_workers); - btrfs_stop_workers(&fs_info->rmw_workers); + btrfs_destroy_workqueue(fs_info->rmw_workers); btrfs_destroy_workqueue(fs_info->endio_meta_write_workers); btrfs_destroy_workqueue(fs_info->endio_write_workers); btrfs_destroy_workqueue(fs_info->endio_freespace_worker); @@ -2524,9 +2524,8 @@ int open_ctree(struct super_block *sb, NULL, NULL, flags, max_active, 4); - btrfs_init_workers(&fs_info->rmw_workers, - "rmw", fs_info->thread_pool_size, - &fs_info->generic_worker); + fs_info->rmw_workers = btrfs_alloc_workqueue("rmw", NULL, NULL, flags, + max_active, 2); fs_info->endio_write_workers = btrfs_alloc_workqueue("endio-write", NULL, NULL, flags, @@ -2543,8 +2542,6 @@ int open_ctree(struct super_block *sb, btrfs_init_workers(&fs_info->qgroup_rescan_workers, "qgroup-rescan", 1, &fs_info->generic_worker); - fs_info->rmw_workers.idle_thresh = 2; - fs_info->readahead_workers.idle_thresh = 2; /* @@ -2553,7 +2550,6 @@ int open_ctree(struct super_block *sb, */ ret = btrfs_start_workers(&fs_info->generic_worker); ret |= btrfs_start_workers(&fs_info->fixup_workers); - ret |= btrfs_start_workers(&fs_info->rmw_workers); ret |= btrfs_start_workers(&fs_info->delayed_workers); ret |= btrfs_start_workers(&fs_info->caching_workers); ret |= btrfs_start_workers(&fs_info->readahead_workers); @@ -2567,7 +2563,7 @@ int open_ctree(struct super_block *sb, fs_info->endio_workers && fs_info->endio_meta_workers && fs_info->endio_meta_write_workers && fs_info->endio_write_workers && fs_info->endio_raid56_workers && - fs_info->endio_freespace_worker)) { + fs_info->endio_freespace_worker && fs_info->rmw_workers)) { err = -ENOMEM; goto fail_sb_buffer; } diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index d0ecfbd..c1c68cc 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c @@ -88,7 +88,7 @@ struct btrfs_raid_bio { /* * for scheduling work in the helper threads */ - struct btrfs_work work; + struct btrfs_work_struct work; /* * bio list and bio_list_lock are used @@ -167,8 +167,8 @@ struct btrfs_raid_bio { static int __raid56_parity_recover(struct btrfs_raid_bio *rbio); static noinline void finish_rmw(struct btrfs_raid_bio *rbio); -static void rmw_work(struct btrfs_work *work); -static void read_rebuild_work(struct btrfs_work *work); +static void rmw_work(struct btrfs_work_struct *work); +static void read_rebuild_work(struct btrfs_work_struct *work); static void async_rmw_stripe(struct btrfs_raid_bio *rbio); static void async_read_rebuild(struct btrfs_raid_bio *rbio); static int fail_bio_stripe(struct btrfs_raid_bio *rbio, struct bio *bio); @@ -1417,19 +1417,17 @@ cleanup: static void async_rmw_stripe(struct btrfs_raid_bio *rbio) { - rbio->work.flags = 0; - rbio->work.func = rmw_work; + btrfs_init_work(&rbio->work, rmw_work, NULL, NULL); - btrfs_queue_worker(&rbio->fs_info->rmw_workers, - &rbio->work); + btrfs_queue_work(rbio->fs_info->rmw_workers, + &rbio->work); } static void async_read_rebuild(struct btrfs_raid_bio *rbio) { - rbio->work.flags = 0; - rbio->work.func = read_rebuild_work; + btrfs_init_work(&rbio->work, read_rebuild_work, NULL, NULL); - btrfs_queue_worker(&rbio->fs_info->rmw_workers, + btrfs_queue_work(rbio->fs_info->rmw_workers, &rbio->work); } @@ -1591,7 +1589,7 @@ struct btrfs_plug_cb { struct blk_plug_cb cb; struct btrfs_fs_info *info; struct list_head rbio_list; - struct btrfs_work work; + struct btrfs_work_struct work; }; /* @@ -1655,7 +1653,7 @@ static void run_plug(struct btrfs_plug_cb *plug) * if the unplug comes from schedule, we have to push the * work off to a helper thread */ -static void unplug_work(struct btrfs_work *work) +static void unplug_work(struct btrfs_work_struct *work) { struct btrfs_plug_cb *plug; plug = container_of(work, struct btrfs_plug_cb, work); @@ -1668,10 +1666,9 @@ static void btrfs_raid_unplug(struct blk_plug_cb *cb, bool from_schedule) plug = container_of(cb, struct btrfs_plug_cb, cb); if (from_schedule) { - plug->work.flags = 0; - plug->work.func = unplug_work; - btrfs_queue_worker(&plug->info->rmw_workers, - &plug->work); + btrfs_init_work(&plug->work, unplug_work, NULL, NULL); + btrfs_queue_work(plug->info->rmw_workers, + &plug->work); return; } run_plug(plug); @@ -2083,7 +2080,7 @@ int raid56_parity_recover(struct btrfs_root *root, struct bio *bio, } -static void rmw_work(struct btrfs_work *work) +static void rmw_work(struct btrfs_work_struct *work) { struct btrfs_raid_bio *rbio; @@ -2091,7 +2088,7 @@ static void rmw_work(struct btrfs_work *work) raid56_rmw_stripe(rbio); } -static void read_rebuild_work(struct btrfs_work *work) +static void read_rebuild_work(struct btrfs_work_struct *work) { struct btrfs_raid_bio *rbio; -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:52 UTC
[PATCH v3 11/17] btrfs: Replace fs_info->cache_workers workqueue with btrfs_workqueue.
Replace the fs_info->cache_workers with the newly created btrfs_workqueue. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: - Use the btrfs_workqueue_struct to replace caching_workers. --- fs/btrfs/ctree.h | 4 ++-- fs/btrfs/disk-io.c | 12 ++++++------ fs/btrfs/extent-tree.c | 6 +++--- fs/btrfs/super.c | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 89a5411..edc3097 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1199,7 +1199,7 @@ struct btrfs_caching_control { struct list_head list; struct mutex mutex; wait_queue_head_t wait; - struct btrfs_work work; + struct btrfs_work_struct work; struct btrfs_block_group_cache *block_group; u64 progress; atomic_t count; @@ -1494,7 +1494,7 @@ struct btrfs_fs_info { struct btrfs_workqueue_struct *endio_write_workers; struct btrfs_workqueue_struct *endio_freespace_worker; struct btrfs_workqueue_struct *submit_workers; - struct btrfs_workers caching_workers; + struct btrfs_workqueue_struct *caching_workers; struct btrfs_workers readahead_workers; /* diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index d6f5cf7..38b65d4 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2004,7 +2004,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) btrfs_destroy_workqueue(fs_info->endio_freespace_worker); btrfs_destroy_workqueue(fs_info->submit_workers); btrfs_stop_workers(&fs_info->delayed_workers); - btrfs_stop_workers(&fs_info->caching_workers); + btrfs_destroy_workqueue(fs_info->caching_workers); btrfs_stop_workers(&fs_info->readahead_workers); btrfs_destroy_workqueue(fs_info->flush_workers); btrfs_stop_workers(&fs_info->qgroup_rescan_workers); @@ -2502,9 +2502,9 @@ int open_ctree(struct super_block *sb, fs_devices->num_devices, max_active), 64); - btrfs_init_workers(&fs_info->caching_workers, "cache", - fs_info->thread_pool_size, NULL); - + fs_info->caching_workers = btrfs_alloc_workqueue("cache", NULL, NULL, + flags, max_active, + 0); btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1, &fs_info->generic_worker); @@ -2551,7 +2551,6 @@ int open_ctree(struct super_block *sb, ret = btrfs_start_workers(&fs_info->generic_worker); ret |= btrfs_start_workers(&fs_info->fixup_workers); ret |= btrfs_start_workers(&fs_info->delayed_workers); - ret |= btrfs_start_workers(&fs_info->caching_workers); ret |= btrfs_start_workers(&fs_info->readahead_workers); ret |= btrfs_start_workers(&fs_info->qgroup_rescan_workers); if (ret) { @@ -2563,7 +2562,8 @@ int open_ctree(struct super_block *sb, fs_info->endio_workers && fs_info->endio_meta_workers && fs_info->endio_meta_write_workers && fs_info->endio_write_workers && fs_info->endio_raid56_workers && - fs_info->endio_freespace_worker && fs_info->rmw_workers)) { + fs_info->endio_freespace_worker && fs_info->rmw_workers && + fs_info->caching_workers)) { err = -ENOMEM; goto fail_sb_buffer; } diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index d58bef1..143acf7 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -378,7 +378,7 @@ static u64 add_new_free_space(struct btrfs_block_group_cache *block_group, return total_added; } -static noinline void caching_thread(struct btrfs_work *work) +static noinline void caching_thread(struct btrfs_work_struct *work) { struct btrfs_block_group_cache *block_group; struct btrfs_fs_info *fs_info; @@ -548,7 +548,7 @@ static int cache_block_group(struct btrfs_block_group_cache *cache, caching_ctl->block_group = cache; caching_ctl->progress = cache->key.objectid; atomic_set(&caching_ctl->count, 1); - caching_ctl->work.func = caching_thread; + btrfs_init_work(&caching_ctl->work, caching_thread, NULL, NULL); spin_lock(&cache->lock); /* @@ -639,7 +639,7 @@ static int cache_block_group(struct btrfs_block_group_cache *cache, btrfs_get_block_group(cache); - btrfs_queue_worker(&fs_info->caching_workers, &caching_ctl->work); + btrfs_queue_work(fs_info->caching_workers, &caching_ctl->work); return ret; } diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index a8fc05d..e76c9d5 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1249,7 +1249,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, btrfs_workqueue_set_max(fs_info->workers, new_pool_size); btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->submit_workers, new_pool_size); - btrfs_set_max_workers(&fs_info->caching_workers, new_pool_size); + btrfs_workqueue_set_max(fs_info->caching_workers, new_pool_size); btrfs_set_max_workers(&fs_info->fixup_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->endio_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->endio_meta_workers, new_pool_size); -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:52 UTC
[PATCH v3 12/17] btrfs: Replace fs_info->readahead_workers workqueue with btrfs_workqueue.
Replace the fs_info->readahead_workers with the newly created btrfs_workqueue. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: - Use the btrfs_workqueue_struct to replace readahead_workers. --- fs/btrfs/ctree.h | 2 +- fs/btrfs/disk-io.c | 12 +++++------- fs/btrfs/reada.c | 10 +++++----- fs/btrfs/super.c | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index edc3097..29fb7a6 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1495,7 +1495,7 @@ struct btrfs_fs_info { struct btrfs_workqueue_struct *endio_freespace_worker; struct btrfs_workqueue_struct *submit_workers; struct btrfs_workqueue_struct *caching_workers; - struct btrfs_workers readahead_workers; + struct btrfs_workqueue_struct *readahead_workers; /* * fixup workers take dirty pages that didn''t properly go through diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 38b65d4..fe3a8be 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2005,7 +2005,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) btrfs_destroy_workqueue(fs_info->submit_workers); btrfs_stop_workers(&fs_info->delayed_workers); btrfs_destroy_workqueue(fs_info->caching_workers); - btrfs_stop_workers(&fs_info->readahead_workers); + btrfs_destroy_workqueue(fs_info->readahead_workers); btrfs_destroy_workqueue(fs_info->flush_workers); btrfs_stop_workers(&fs_info->qgroup_rescan_workers); } @@ -2536,13 +2536,12 @@ int open_ctree(struct super_block *sb, btrfs_init_workers(&fs_info->delayed_workers, "delayed-meta", fs_info->thread_pool_size, &fs_info->generic_worker); - btrfs_init_workers(&fs_info->readahead_workers, "readahead", - fs_info->thread_pool_size, - &fs_info->generic_worker); + fs_info->readahead_workers = btrfs_alloc_workqueue("readahead", NULL, + NULL, flags, + max_active, 2); btrfs_init_workers(&fs_info->qgroup_rescan_workers, "qgroup-rescan", 1, &fs_info->generic_worker); - fs_info->readahead_workers.idle_thresh = 2; /* * btrfs_start_workers can really only fail because of ENOMEM so just @@ -2551,7 +2550,6 @@ int open_ctree(struct super_block *sb, ret = btrfs_start_workers(&fs_info->generic_worker); ret |= btrfs_start_workers(&fs_info->fixup_workers); ret |= btrfs_start_workers(&fs_info->delayed_workers); - ret |= btrfs_start_workers(&fs_info->readahead_workers); ret |= btrfs_start_workers(&fs_info->qgroup_rescan_workers); if (ret) { err = -ENOMEM; @@ -2563,7 +2561,7 @@ int open_ctree(struct super_block *sb, fs_info->endio_meta_write_workers && fs_info->endio_write_workers && fs_info->endio_raid56_workers && fs_info->endio_freespace_worker && fs_info->rmw_workers && - fs_info->caching_workers)) { + fs_info->caching_workers && fs_info->readahead_workers)) { err = -ENOMEM; goto fail_sb_buffer; } diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c index 1031b69..66b6fbe 100644 --- a/fs/btrfs/reada.c +++ b/fs/btrfs/reada.c @@ -91,8 +91,8 @@ struct reada_zone { }; struct reada_machine_work { - struct btrfs_work work; - struct btrfs_fs_info *fs_info; + struct btrfs_work_struct work; + struct btrfs_fs_info *fs_info; }; static void reada_extent_put(struct btrfs_fs_info *, struct reada_extent *); @@ -732,7 +732,7 @@ static int reada_start_machine_dev(struct btrfs_fs_info *fs_info, } -static void reada_start_machine_worker(struct btrfs_work *work) +static void reada_start_machine_worker(struct btrfs_work_struct *work) { struct reada_machine_work *rmw; struct btrfs_fs_info *fs_info; @@ -792,10 +792,10 @@ static void reada_start_machine(struct btrfs_fs_info *fs_info) /* FIXME we cannot handle this properly right now */ BUG(); } - rmw->work.func = reada_start_machine_worker; + btrfs_init_work(&rmw->work, reada_start_machine_worker, NULL, NULL); rmw->fs_info = fs_info; - btrfs_queue_worker(&fs_info->readahead_workers, &rmw->work); + btrfs_queue_work(fs_info->readahead_workers, &rmw->work); } #ifdef DEBUG diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index e76c9d5..8e26ec5 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1258,7 +1258,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, btrfs_workqueue_set_max(fs_info->endio_write_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size); btrfs_set_max_workers(&fs_info->delayed_workers, new_pool_size); - btrfs_set_max_workers(&fs_info->readahead_workers, new_pool_size); + btrfs_workqueue_set_max(fs_info->readahead_workers, new_pool_size); btrfs_set_max_workers(&fs_info->scrub_wr_completion_workers, new_pool_size); } -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:52 UTC
[PATCH v3 13/17] btrfs: Replace fs_info->fixup_workers workqueue with btrfs_workqueue.
Replace the fs_info->fixup_workers with the newly created btrfs_workqueue. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: - Use the btrfs_workqueue_struct to replace fixup_workers. --- fs/btrfs/ctree.h | 2 +- fs/btrfs/disk-io.c | 10 +++++----- fs/btrfs/inode.c | 8 ++++---- fs/btrfs/super.c | 1 - 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 29fb7a6..a01b399 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1502,7 +1502,7 @@ struct btrfs_fs_info { * the cow mechanism and make them safe to write. It happens * for the sys_munmap function call path */ - struct btrfs_workers fixup_workers; + struct btrfs_workqueue_struct *fixup_workers; struct btrfs_workers delayed_workers; struct task_struct *transaction_kthread; struct task_struct *cleaner_kthread; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index fe3a8be..ae8201c 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1992,7 +1992,7 @@ static noinline int next_root_backup(struct btrfs_fs_info *info, static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) { btrfs_stop_workers(&fs_info->generic_worker); - btrfs_stop_workers(&fs_info->fixup_workers); + btrfs_destroy_workqueue(fs_info->fixup_workers); btrfs_destroy_workqueue(fs_info->delalloc_workers); btrfs_destroy_workqueue(fs_info->workers); btrfs_destroy_workqueue(fs_info->endio_workers); @@ -2506,8 +2506,8 @@ int open_ctree(struct super_block *sb, flags, max_active, 0); - btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1, - &fs_info->generic_worker); + fs_info->fixup_workers = btrfs_alloc_workqueue("fixup", NULL, NULL, + flags, 1, 0); /* * endios are largely parallel and should have a very * low idle thresh @@ -2548,7 +2548,6 @@ int open_ctree(struct super_block *sb, * return -ENOMEM if any of these fail. */ ret = btrfs_start_workers(&fs_info->generic_worker); - ret |= btrfs_start_workers(&fs_info->fixup_workers); ret |= btrfs_start_workers(&fs_info->delayed_workers); ret |= btrfs_start_workers(&fs_info->qgroup_rescan_workers); if (ret) { @@ -2561,7 +2560,8 @@ int open_ctree(struct super_block *sb, fs_info->endio_meta_write_workers && fs_info->endio_write_workers && fs_info->endio_raid56_workers && fs_info->endio_freespace_worker && fs_info->rmw_workers && - fs_info->caching_workers && fs_info->readahead_workers)) { + fs_info->caching_workers && fs_info->readahead_workers && + fs_info->fixup_workers)) { err = -ENOMEM; goto fail_sb_buffer; } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9dd807d..f5dce0c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1729,10 +1729,10 @@ int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, /* see btrfs_writepage_start_hook for details on why this is required */ struct btrfs_writepage_fixup { struct page *page; - struct btrfs_work work; + struct btrfs_work_struct work; }; -static void btrfs_writepage_fixup_worker(struct btrfs_work *work) +static void btrfs_writepage_fixup_worker(struct btrfs_work_struct *work) { struct btrfs_writepage_fixup *fixup; struct btrfs_ordered_extent *ordered; @@ -1823,9 +1823,9 @@ static int btrfs_writepage_start_hook(struct page *page, u64 start, u64 end) SetPageChecked(page); page_cache_get(page); - fixup->work.func = btrfs_writepage_fixup_worker; + btrfs_init_work(&fixup->work, btrfs_writepage_fixup_worker, NULL, NULL); fixup->page = page; - btrfs_queue_worker(&root->fs_info->fixup_workers, &fixup->work); + btrfs_queue_work(root->fs_info->fixup_workers, &fixup->work); return -EBUSY; } diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 8e26ec5..841a72c 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1250,7 +1250,6 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->submit_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->caching_workers, new_pool_size); - btrfs_set_max_workers(&fs_info->fixup_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->endio_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->endio_meta_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->endio_meta_write_workers, -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:52 UTC
[PATCH v3 14/17] btrfs: Replace fs_info->delayed_workers workqueue with btrfs_workqueue.
Replace the fs_info->delayed_workers with the newly created btrfs_workqueue. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: None --- fs/btrfs/ctree.h | 2 +- fs/btrfs/delayed-inode.c | 10 +++++----- fs/btrfs/disk-io.c | 11 +++++------ fs/btrfs/super.c | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index a01b399..3493010 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1503,7 +1503,7 @@ struct btrfs_fs_info { * for the sys_munmap function call path */ struct btrfs_workqueue_struct *fixup_workers; - struct btrfs_workers delayed_workers; + struct btrfs_workqueue_struct *delayed_workers; struct task_struct *transaction_kthread; struct task_struct *cleaner_kthread; int thread_pool_size; diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index cbd9523..76589ad 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c @@ -1259,10 +1259,10 @@ void btrfs_remove_delayed_node(struct inode *inode) struct btrfs_async_delayed_work { struct btrfs_delayed_root *delayed_root; int nr; - struct btrfs_work work; + struct btrfs_work_struct work; }; -static void btrfs_async_run_delayed_root(struct btrfs_work *work) +static void btrfs_async_run_delayed_root(struct btrfs_work_struct *work) { struct btrfs_async_delayed_work *async_work; struct btrfs_delayed_root *delayed_root; @@ -1360,11 +1360,11 @@ static int btrfs_wq_run_delayed_node(struct btrfs_delayed_root *delayed_root, return -ENOMEM; async_work->delayed_root = delayed_root; - async_work->work.func = btrfs_async_run_delayed_root; - async_work->work.flags = 0; + btrfs_init_work(&async_work->work, btrfs_async_run_delayed_root, + NULL, NULL); async_work->nr = nr; - btrfs_queue_worker(&root->fs_info->delayed_workers, &async_work->work); + btrfs_queue_work(root->fs_info->delayed_workers, &async_work->work); return 0; } diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index ae8201c..4fc26d2 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2003,7 +2003,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) btrfs_destroy_workqueue(fs_info->endio_write_workers); btrfs_destroy_workqueue(fs_info->endio_freespace_worker); btrfs_destroy_workqueue(fs_info->submit_workers); - btrfs_stop_workers(&fs_info->delayed_workers); + btrfs_destroy_workqueue(fs_info->delayed_workers); btrfs_destroy_workqueue(fs_info->caching_workers); btrfs_destroy_workqueue(fs_info->readahead_workers); btrfs_destroy_workqueue(fs_info->flush_workers); @@ -2533,9 +2533,9 @@ int open_ctree(struct super_block *sb, fs_info->endio_freespace_worker btrfs_alloc_workqueue("freespace-write", NULL, NULL, flags, max_active, 0); - btrfs_init_workers(&fs_info->delayed_workers, "delayed-meta", - fs_info->thread_pool_size, - &fs_info->generic_worker); + fs_info->delayed_workers = btrfs_alloc_workqueue("delayed-meta", + NULL, NULL, flags, + max_active, 0); fs_info->readahead_workers = btrfs_alloc_workqueue("readahead", NULL, NULL, flags, max_active, 2); @@ -2548,7 +2548,6 @@ int open_ctree(struct super_block *sb, * return -ENOMEM if any of these fail. */ ret = btrfs_start_workers(&fs_info->generic_worker); - ret |= btrfs_start_workers(&fs_info->delayed_workers); ret |= btrfs_start_workers(&fs_info->qgroup_rescan_workers); if (ret) { err = -ENOMEM; @@ -2561,7 +2560,7 @@ int open_ctree(struct super_block *sb, fs_info->endio_write_workers && fs_info->endio_raid56_workers && fs_info->endio_freespace_worker && fs_info->rmw_workers && fs_info->caching_workers && fs_info->readahead_workers && - fs_info->fixup_workers)) { + fs_info->fixup_workers && fs_info->delayed_workers)) { err = -ENOMEM; goto fail_sb_buffer; } diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 841a72c..8940015 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1256,7 +1256,7 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, new_pool_size); btrfs_workqueue_set_max(fs_info->endio_write_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size); - btrfs_set_max_workers(&fs_info->delayed_workers, new_pool_size); + btrfs_workqueue_set_max(fs_info->delayed_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->readahead_workers, new_pool_size); btrfs_set_max_workers(&fs_info->scrub_wr_completion_workers, new_pool_size); -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:52 UTC
[PATCH v3 15/17] btrfs: Replace fs_info->qgroup_rescan_worker workqueue with btrfs_workqueue.
Replace the fs_info->qgroup_rescan_worker with the newly created btrfs_workqueue. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: - Use the btrfs_workqueue_struct to replace qgroup_rescan_workers. --- fs/btrfs/ctree.h | 4 ++-- fs/btrfs/disk-io.c | 12 ++++++------ fs/btrfs/qgroup.c | 17 +++++++++-------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 3493010..2e7e6a4 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1625,9 +1625,9 @@ struct btrfs_fs_info { /* qgroup rescan items */ struct mutex qgroup_rescan_lock; /* protects the progress item */ struct btrfs_key qgroup_rescan_progress; - struct btrfs_workers qgroup_rescan_workers; + struct btrfs_workqueue_struct *qgroup_rescan_workers; struct completion qgroup_rescan_completion; - struct btrfs_work qgroup_rescan_work; + struct btrfs_work_struct qgroup_rescan_work; /* filesystem state */ unsigned long fs_state; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 4fc26d2..6950570 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2007,7 +2007,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) btrfs_destroy_workqueue(fs_info->caching_workers); btrfs_destroy_workqueue(fs_info->readahead_workers); btrfs_destroy_workqueue(fs_info->flush_workers); - btrfs_stop_workers(&fs_info->qgroup_rescan_workers); + btrfs_destroy_workqueue(fs_info->qgroup_rescan_workers); } /* helper to cleanup tree roots */ @@ -2539,16 +2539,15 @@ int open_ctree(struct super_block *sb, fs_info->readahead_workers = btrfs_alloc_workqueue("readahead", NULL, NULL, flags, max_active, 2); - btrfs_init_workers(&fs_info->qgroup_rescan_workers, "qgroup-rescan", 1, - &fs_info->generic_worker); - + fs_info->qgroup_rescan_workers + btrfs_alloc_workqueue("qgroup-rescan", NULL, NULL, + flags, 1, 0); /* * btrfs_start_workers can really only fail because of ENOMEM so just * return -ENOMEM if any of these fail. */ ret = btrfs_start_workers(&fs_info->generic_worker); - ret |= btrfs_start_workers(&fs_info->qgroup_rescan_workers); if (ret) { err = -ENOMEM; goto fail_sb_buffer; @@ -2560,7 +2559,8 @@ int open_ctree(struct super_block *sb, fs_info->endio_write_workers && fs_info->endio_raid56_workers && fs_info->endio_freespace_worker && fs_info->rmw_workers && fs_info->caching_workers && fs_info->readahead_workers && - fs_info->fixup_workers && fs_info->delayed_workers)) { + fs_info->fixup_workers && fs_info->delayed_workers && + fs_info->qgroup_rescan_workers)) { err = -ENOMEM; goto fail_sb_buffer; } diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 4e6ef49..521144e 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1516,8 +1516,8 @@ int btrfs_run_qgroups(struct btrfs_trans_handle *trans, ret = qgroup_rescan_init(fs_info, 0, 1); if (!ret) { qgroup_rescan_zero_tracking(fs_info); - btrfs_queue_worker(&fs_info->qgroup_rescan_workers, - &fs_info->qgroup_rescan_work); + btrfs_queue_work(fs_info->qgroup_rescan_workers, + &fs_info->qgroup_rescan_work); } ret = 0; } @@ -1981,7 +1981,7 @@ out: return ret; } -static void btrfs_qgroup_rescan_worker(struct btrfs_work *work) +static void btrfs_qgroup_rescan_worker(struct btrfs_work_struct *work) { struct btrfs_fs_info *fs_info = container_of(work, struct btrfs_fs_info, qgroup_rescan_work); @@ -2092,7 +2092,8 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid, memset(&fs_info->qgroup_rescan_work, 0, sizeof(fs_info->qgroup_rescan_work)); - fs_info->qgroup_rescan_work.func = btrfs_qgroup_rescan_worker; + btrfs_init_work(&fs_info->qgroup_rescan_work, + btrfs_qgroup_rescan_worker, NULL, NULL); if (ret) { err: @@ -2155,8 +2156,8 @@ btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info) qgroup_rescan_zero_tracking(fs_info); - btrfs_queue_worker(&fs_info->qgroup_rescan_workers, - &fs_info->qgroup_rescan_work); + btrfs_queue_work(fs_info->qgroup_rescan_workers, + &fs_info->qgroup_rescan_work); return 0; } @@ -2187,6 +2188,6 @@ void btrfs_qgroup_rescan_resume(struct btrfs_fs_info *fs_info) { if (fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN) - btrfs_queue_worker(&fs_info->qgroup_rescan_workers, - &fs_info->qgroup_rescan_work); + btrfs_queue_work(fs_info->qgroup_rescan_workers, + &fs_info->qgroup_rescan_work); } -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-07 05:52 UTC
[PATCH v3 16/17] btrfs: Replace fs_info->scrub_* workqueue with btrfs_workqueue.
Replace the fs_info->scrub_* with the newly created btrfs_workqueue. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: - Use the btrfs_workqueue_struct to replace scrub_*. --- fs/btrfs/ctree.h | 6 ++-- fs/btrfs/scrub.c | 94 ++++++++++++++++++++++++++++++-------------------------- fs/btrfs/super.c | 4 +-- 3 files changed, 56 insertions(+), 48 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 2e7e6a4..1da2f33 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1582,9 +1582,9 @@ struct btrfs_fs_info { wait_queue_head_t scrub_pause_wait; struct rw_semaphore scrub_super_lock; int scrub_workers_refcnt; - struct btrfs_workers scrub_workers; - struct btrfs_workers scrub_wr_completion_workers; - struct btrfs_workers scrub_nocow_workers; + struct btrfs_workqueue_struct *scrub_workers; + struct btrfs_workqueue_struct *scrub_wr_completion_workers; + struct btrfs_workqueue_struct *scrub_nocow_workers; #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY u32 check_integrity_print_mask; diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index a18e0e2..e3cd62f 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -96,7 +96,8 @@ struct scrub_bio { #endif int page_count; int next_free; - struct btrfs_work work; + struct btrfs_work_struct + work; }; struct scrub_block { @@ -154,7 +155,8 @@ struct scrub_fixup_nodatasum { struct btrfs_device *dev; u64 logical; struct btrfs_root *root; - struct btrfs_work work; + struct btrfs_work_struct + work; int mirror_num; }; @@ -172,7 +174,8 @@ struct scrub_copy_nocow_ctx { int mirror_num; u64 physical_for_dev_replace; struct list_head inodes; - struct btrfs_work work; + struct btrfs_work_struct + work; }; struct scrub_warning { @@ -232,7 +235,7 @@ static int scrub_pages(struct scrub_ctx *sctx, u64 logical, u64 len, u64 gen, int mirror_num, u8 *csum, int force, u64 physical_for_dev_replace); static void scrub_bio_end_io(struct bio *bio, int err); -static void scrub_bio_end_io_worker(struct btrfs_work *work); +static void scrub_bio_end_io_worker(struct btrfs_work_struct *work); static void scrub_block_complete(struct scrub_block *sblock); static void scrub_remap_extent(struct btrfs_fs_info *fs_info, u64 extent_logical, u64 extent_len, @@ -249,14 +252,14 @@ static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx, struct scrub_page *spage); static void scrub_wr_submit(struct scrub_ctx *sctx); static void scrub_wr_bio_end_io(struct bio *bio, int err); -static void scrub_wr_bio_end_io_worker(struct btrfs_work *work); +static void scrub_wr_bio_end_io_worker(struct btrfs_work_struct *work); static int write_page_nocow(struct scrub_ctx *sctx, u64 physical_for_dev_replace, struct page *page); static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, struct scrub_copy_nocow_ctx *ctx); static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len, int mirror_num, u64 physical_for_dev_replace); -static void copy_nocow_pages_worker(struct btrfs_work *work); +static void copy_nocow_pages_worker(struct btrfs_work_struct *work); static void scrub_pending_bio_inc(struct scrub_ctx *sctx) @@ -394,7 +397,8 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace) sbio->index = i; sbio->sctx = sctx; sbio->page_count = 0; - sbio->work.func = scrub_bio_end_io_worker; + btrfs_init_work(&sbio->work, scrub_bio_end_io_worker, + NULL, NULL); if (i != SCRUB_BIOS_PER_SCTX - 1) sctx->bios[i]->next_free = i + 1; @@ -699,7 +703,7 @@ out: return -EIO; } -static void scrub_fixup_nodatasum(struct btrfs_work *work) +static void scrub_fixup_nodatasum(struct btrfs_work_struct *work) { int ret; struct scrub_fixup_nodatasum *fixup; @@ -963,9 +967,10 @@ nodatasum_case: fixup_nodatasum->root = fs_info->extent_root; fixup_nodatasum->mirror_num = failed_mirror_index + 1; scrub_pending_trans_workers_inc(sctx); - fixup_nodatasum->work.func = scrub_fixup_nodatasum; - btrfs_queue_worker(&fs_info->scrub_workers, - &fixup_nodatasum->work); + btrfs_init_work(&fixup_nodatasum->work, scrub_fixup_nodatasum, + NULL, NULL); + btrfs_queue_work(fs_info->scrub_workers, + &fixup_nodatasum->work); goto out; } @@ -1597,11 +1602,11 @@ static void scrub_wr_bio_end_io(struct bio *bio, int err) sbio->err = err; sbio->bio = bio; - sbio->work.func = scrub_wr_bio_end_io_worker; - btrfs_queue_worker(&fs_info->scrub_wr_completion_workers, &sbio->work); + btrfs_init_work(&sbio->work, scrub_wr_bio_end_io_worker, NULL, NULL); + btrfs_queue_work(fs_info->scrub_wr_completion_workers, &sbio->work); } -static void scrub_wr_bio_end_io_worker(struct btrfs_work *work) +static void scrub_wr_bio_end_io_worker(struct btrfs_work_struct *work) { struct scrub_bio *sbio = container_of(work, struct scrub_bio, work); struct scrub_ctx *sctx = sbio->sctx; @@ -2066,10 +2071,10 @@ static void scrub_bio_end_io(struct bio *bio, int err) sbio->err = err; sbio->bio = bio; - btrfs_queue_worker(&fs_info->scrub_workers, &sbio->work); + btrfs_queue_work(fs_info->scrub_workers, &sbio->work); } -static void scrub_bio_end_io_worker(struct btrfs_work *work) +static void scrub_bio_end_io_worker(struct btrfs_work_struct *work) { struct scrub_bio *sbio = container_of(work, struct scrub_bio, work); struct scrub_ctx *sctx = sbio->sctx; @@ -2782,34 +2787,37 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info, int is_dev_replace) { int ret = 0; + int flags = WQ_FREEZABLE; + int max_active = fs_info->thread_pool_size; mutex_lock(&fs_info->scrub_lock); if (fs_info->scrub_workers_refcnt == 0) { if (is_dev_replace) - btrfs_init_workers(&fs_info->scrub_workers, "scrub", 1, - &fs_info->generic_worker); + fs_info->scrub_workers + btrfs_alloc_workqueue("scrub", NULL, NULL, + flags, 1, 4); else - btrfs_init_workers(&fs_info->scrub_workers, "scrub", - fs_info->thread_pool_size, - &fs_info->generic_worker); - fs_info->scrub_workers.idle_thresh = 4; - ret = btrfs_start_workers(&fs_info->scrub_workers); - if (ret) + fs_info->scrub_workers + btrfs_alloc_workqueue("scrub", NULL, NULL, + flags, max_active, 4); + if (!fs_info->scrub_workers) { + ret = -ENOMEM; goto out; - btrfs_init_workers(&fs_info->scrub_wr_completion_workers, - "scrubwrc", - fs_info->thread_pool_size, - &fs_info->generic_worker); - fs_info->scrub_wr_completion_workers.idle_thresh = 2; - ret = btrfs_start_workers( - &fs_info->scrub_wr_completion_workers); - if (ret) + } + fs_info->scrub_wr_completion_workers + btrfs_alloc_workqueue("scrubwrc", NULL, NULL, flags, + max_active, 2); + if (!fs_info->scrub_wr_completion_workers) { + ret = -ENOMEM; goto out; - btrfs_init_workers(&fs_info->scrub_nocow_workers, "scrubnc", 1, - &fs_info->generic_worker); - ret = btrfs_start_workers(&fs_info->scrub_nocow_workers); - if (ret) + } + fs_info->scrub_nocow_workers + btrfs_alloc_workqueue("scrubnc", NULL, NULL, flags, + 1, 0); + if (!fs_info->scrub_nocow_workers) { + ret = -ENOMEM; goto out; + } } ++fs_info->scrub_workers_refcnt; out: @@ -2822,9 +2830,9 @@ static noinline_for_stack void scrub_workers_put(struct btrfs_fs_info *fs_info) { mutex_lock(&fs_info->scrub_lock); if (--fs_info->scrub_workers_refcnt == 0) { - btrfs_stop_workers(&fs_info->scrub_workers); - btrfs_stop_workers(&fs_info->scrub_wr_completion_workers); - btrfs_stop_workers(&fs_info->scrub_nocow_workers); + btrfs_destroy_workqueue(fs_info->scrub_workers); + btrfs_destroy_workqueue(fs_info->scrub_wr_completion_workers); + btrfs_destroy_workqueue(fs_info->scrub_nocow_workers); } WARN_ON(fs_info->scrub_workers_refcnt < 0); mutex_unlock(&fs_info->scrub_lock); @@ -3133,10 +3141,10 @@ static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len, nocow_ctx->len = len; nocow_ctx->mirror_num = mirror_num; nocow_ctx->physical_for_dev_replace = physical_for_dev_replace; - nocow_ctx->work.func = copy_nocow_pages_worker; + btrfs_init_work(&nocow_ctx->work, copy_nocow_pages_worker, NULL, NULL); INIT_LIST_HEAD(&nocow_ctx->inodes); - btrfs_queue_worker(&fs_info->scrub_nocow_workers, - &nocow_ctx->work); + btrfs_queue_work(fs_info->scrub_nocow_workers, + &nocow_ctx->work); return 0; } @@ -3158,7 +3166,7 @@ static int record_inode_for_nocow(u64 inum, u64 offset, u64 root, void *ctx) #define COPY_COMPLETE 1 -static void copy_nocow_pages_worker(struct btrfs_work *work) +static void copy_nocow_pages_worker(struct btrfs_work_struct *work) { struct scrub_copy_nocow_ctx *nocow_ctx container_of(work, struct scrub_copy_nocow_ctx, work); diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 8940015..65bfbdf 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1258,8 +1258,8 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size); btrfs_workqueue_set_max(fs_info->delayed_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->readahead_workers, new_pool_size); - btrfs_set_max_workers(&fs_info->scrub_wr_completion_workers, - new_pool_size); + btrfs_workqueue_set_max(fs_info->scrub_wr_completion_workers, + new_pool_size); } static inline void btrfs_remount_prepare(struct btrfs_fs_info *fs_info) -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Since all the btrfs_worker is replaced with the newly created btrfs_workqueue, the old codes can be easily remove. Signed-off-by: Quwenruo <quwenruo@cn.fujitsu.com> --- Changelog: v1->v2: None v2->v3: - Reuse the old async-thred.[ch] files. --- fs/btrfs/async-thread.c | 703 ------------------------------------------------ fs/btrfs/async-thread.h | 100 ------- fs/btrfs/ctree.h | 1 - fs/btrfs/disk-io.c | 12 - fs/btrfs/super.c | 8 - 5 files changed, 824 deletions(-) diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c index 1fde6a2..497cdb1 100644 --- a/fs/btrfs/async-thread.c +++ b/fs/btrfs/async-thread.c @@ -26,712 +26,9 @@ #include <linux/completion.h> #include "async-thread.h" -#define WORK_QUEUED_BIT 0 -#define WORK_DONE_BIT 1 -#define WORK_ORDER_DONE_BIT 2 -#define WORK_HIGH_PRIO_BIT 3 - #define NO_THRESHOLD (-1) #define DFT_THRESHOLD (32) -/* - * container for the kthread task pointer and the list of pending work - * One of these is allocated per thread. - */ -struct btrfs_worker_thread { - /* pool we belong to */ - struct btrfs_workers *workers; - - /* list of struct btrfs_work that are waiting for service */ - struct list_head pending; - struct list_head prio_pending; - - /* list of worker threads from struct btrfs_workers */ - struct list_head worker_list; - - /* kthread */ - struct task_struct *task; - - /* number of things on the pending list */ - atomic_t num_pending; - - /* reference counter for this struct */ - atomic_t refs; - - unsigned long sequence; - - /* protects the pending list. */ - spinlock_t lock; - - /* set to non-zero when this thread is already awake and kicking */ - int working; - - /* are we currently idle */ - int idle; -}; - -static int __btrfs_start_workers(struct btrfs_workers *workers); - -/* - * btrfs_start_workers uses kthread_run, which can block waiting for memory - * for a very long time. It will actually throttle on page writeback, - * and so it may not make progress until after our btrfs worker threads - * process all of the pending work structs in their queue - * - * This means we can''t use btrfs_start_workers from inside a btrfs worker - * thread that is used as part of cleaning dirty memory, which pretty much - * involves all of the worker threads. - * - * Instead we have a helper queue who never has more than one thread - * where we scheduler thread start operations. This worker_start struct - * is used to contain the work and hold a pointer to the queue that needs - * another worker. - */ -struct worker_start { - struct btrfs_work work; - struct btrfs_workers *queue; -}; - -static void start_new_worker_func(struct btrfs_work *work) -{ - struct worker_start *start; - start = container_of(work, struct worker_start, work); - __btrfs_start_workers(start->queue); - kfree(start); -} - -/* - * helper function to move a thread onto the idle list after it - * has finished some requests. - */ -static void check_idle_worker(struct btrfs_worker_thread *worker) -{ - if (!worker->idle && atomic_read(&worker->num_pending) < - worker->workers->idle_thresh / 2) { - unsigned long flags; - spin_lock_irqsave(&worker->workers->lock, flags); - worker->idle = 1; - - /* the list may be empty if the worker is just starting */ - if (!list_empty(&worker->worker_list) && - !worker->workers->stopping) { - list_move(&worker->worker_list, - &worker->workers->idle_list); - } - spin_unlock_irqrestore(&worker->workers->lock, flags); - } -} - -/* - * helper function to move a thread off the idle list after new - * pending work is added. - */ -static void check_busy_worker(struct btrfs_worker_thread *worker) -{ - if (worker->idle && atomic_read(&worker->num_pending) >- worker->workers->idle_thresh) { - unsigned long flags; - spin_lock_irqsave(&worker->workers->lock, flags); - worker->idle = 0; - - if (!list_empty(&worker->worker_list) && - !worker->workers->stopping) { - list_move_tail(&worker->worker_list, - &worker->workers->worker_list); - } - spin_unlock_irqrestore(&worker->workers->lock, flags); - } -} - -static void check_pending_worker_creates(struct btrfs_worker_thread *worker) -{ - struct btrfs_workers *workers = worker->workers; - struct worker_start *start; - unsigned long flags; - - rmb(); - if (!workers->atomic_start_pending) - return; - - start = kzalloc(sizeof(*start), GFP_NOFS); - if (!start) - return; - - start->work.func = start_new_worker_func; - start->queue = workers; - - spin_lock_irqsave(&workers->lock, flags); - if (!workers->atomic_start_pending) - goto out; - - workers->atomic_start_pending = 0; - if (workers->num_workers + workers->num_workers_starting >- workers->max_workers) - goto out; - - workers->num_workers_starting += 1; - spin_unlock_irqrestore(&workers->lock, flags); - btrfs_queue_worker(workers->atomic_worker_start, &start->work); - return; - -out: - kfree(start); - spin_unlock_irqrestore(&workers->lock, flags); -} - -static noinline void run_ordered_completions(struct btrfs_workers *workers, - struct btrfs_work *work) -{ - if (!workers->ordered) - return; - - set_bit(WORK_DONE_BIT, &work->flags); - - spin_lock(&workers->order_lock); - - while (1) { - if (!list_empty(&workers->prio_order_list)) { - work = list_entry(workers->prio_order_list.next, - struct btrfs_work, order_list); - } else if (!list_empty(&workers->order_list)) { - work = list_entry(workers->order_list.next, - struct btrfs_work, order_list); - } else { - break; - } - if (!test_bit(WORK_DONE_BIT, &work->flags)) - break; - - /* we are going to call the ordered done function, but - * we leave the work item on the list as a barrier so - * that later work items that are done don''t have their - * functions called before this one returns - */ - if (test_and_set_bit(WORK_ORDER_DONE_BIT, &work->flags)) - break; - - spin_unlock(&workers->order_lock); - - work->ordered_func(work); - - /* now take the lock again and drop our item from the list */ - spin_lock(&workers->order_lock); - list_del(&work->order_list); - spin_unlock(&workers->order_lock); - - /* - * we don''t want to call the ordered free functions - * with the lock held though - */ - work->ordered_free(work); - spin_lock(&workers->order_lock); - } - - spin_unlock(&workers->order_lock); -} - -static void put_worker(struct btrfs_worker_thread *worker) -{ - if (atomic_dec_and_test(&worker->refs)) - kfree(worker); -} - -static int try_worker_shutdown(struct btrfs_worker_thread *worker) -{ - int freeit = 0; - - spin_lock_irq(&worker->lock); - spin_lock(&worker->workers->lock); - if (worker->workers->num_workers > 1 && - worker->idle && - !worker->working && - !list_empty(&worker->worker_list) && - list_empty(&worker->prio_pending) && - list_empty(&worker->pending) && - atomic_read(&worker->num_pending) == 0) { - freeit = 1; - list_del_init(&worker->worker_list); - worker->workers->num_workers--; - } - spin_unlock(&worker->workers->lock); - spin_unlock_irq(&worker->lock); - - if (freeit) - put_worker(worker); - return freeit; -} - -static struct btrfs_work *get_next_work(struct btrfs_worker_thread *worker, - struct list_head *prio_head, - struct list_head *head) -{ - struct btrfs_work *work = NULL; - struct list_head *cur = NULL; - - if(!list_empty(prio_head)) - cur = prio_head->next; - - smp_mb(); - if (!list_empty(&worker->prio_pending)) - goto refill; - - if (!list_empty(head)) - cur = head->next; - - if (cur) - goto out; - -refill: - spin_lock_irq(&worker->lock); - list_splice_tail_init(&worker->prio_pending, prio_head); - list_splice_tail_init(&worker->pending, head); - - if (!list_empty(prio_head)) - cur = prio_head->next; - else if (!list_empty(head)) - cur = head->next; - spin_unlock_irq(&worker->lock); - - if (!cur) - goto out_fail; - -out: - work = list_entry(cur, struct btrfs_work, list); - -out_fail: - return work; -} - -/* - * main loop for servicing work items - */ -static int worker_loop(void *arg) -{ - struct btrfs_worker_thread *worker = arg; - struct list_head head; - struct list_head prio_head; - struct btrfs_work *work; - - INIT_LIST_HEAD(&head); - INIT_LIST_HEAD(&prio_head); - - do { -again: - while (1) { - - - work = get_next_work(worker, &prio_head, &head); - if (!work) - break; - - list_del(&work->list); - clear_bit(WORK_QUEUED_BIT, &work->flags); - - work->worker = worker; - - work->func(work); - - atomic_dec(&worker->num_pending); - /* - * unless this is an ordered work queue, - * ''work'' was probably freed by func above. - */ - run_ordered_completions(worker->workers, work); - - check_pending_worker_creates(worker); - cond_resched(); - } - - spin_lock_irq(&worker->lock); - check_idle_worker(worker); - - if (freezing(current)) { - worker->working = 0; - spin_unlock_irq(&worker->lock); - try_to_freeze(); - } else { - spin_unlock_irq(&worker->lock); - if (!kthread_should_stop()) { - cpu_relax(); - /* - * we''ve dropped the lock, did someone else - * jump_in? - */ - smp_mb(); - if (!list_empty(&worker->pending) || - !list_empty(&worker->prio_pending)) - continue; - - /* - * this short schedule allows more work to - * come in without the queue functions - * needing to go through wake_up_process() - * - * worker->working is still 1, so nobody - * is going to try and wake us up - */ - schedule_timeout(1); - smp_mb(); - if (!list_empty(&worker->pending) || - !list_empty(&worker->prio_pending)) - continue; - - if (kthread_should_stop()) - break; - - /* still no more work?, sleep for real */ - spin_lock_irq(&worker->lock); - set_current_state(TASK_INTERRUPTIBLE); - if (!list_empty(&worker->pending) || - !list_empty(&worker->prio_pending)) { - spin_unlock_irq(&worker->lock); - set_current_state(TASK_RUNNING); - goto again; - } - - /* - * this makes sure we get a wakeup when someone - * adds something new to the queue - */ - worker->working = 0; - spin_unlock_irq(&worker->lock); - - if (!kthread_should_stop()) { - schedule_timeout(HZ * 120); - if (!worker->working && - try_worker_shutdown(worker)) { - return 0; - } - } - } - __set_current_state(TASK_RUNNING); - } - } while (!kthread_should_stop()); - return 0; -} - -/* - * this will wait for all the worker threads to shutdown - */ -void btrfs_stop_workers(struct btrfs_workers *workers) -{ - struct list_head *cur; - struct btrfs_worker_thread *worker; - int can_stop; - - spin_lock_irq(&workers->lock); - workers->stopping = 1; - list_splice_init(&workers->idle_list, &workers->worker_list); - while (!list_empty(&workers->worker_list)) { - cur = workers->worker_list.next; - worker = list_entry(cur, struct btrfs_worker_thread, - worker_list); - - atomic_inc(&worker->refs); - workers->num_workers -= 1; - if (!list_empty(&worker->worker_list)) { - list_del_init(&worker->worker_list); - put_worker(worker); - can_stop = 1; - } else - can_stop = 0; - spin_unlock_irq(&workers->lock); - if (can_stop) - kthread_stop(worker->task); - spin_lock_irq(&workers->lock); - put_worker(worker); - } - spin_unlock_irq(&workers->lock); -} - -/* - * simple init on struct btrfs_workers - */ -void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max, - struct btrfs_workers *async_helper) -{ - workers->num_workers = 0; - workers->num_workers_starting = 0; - INIT_LIST_HEAD(&workers->worker_list); - INIT_LIST_HEAD(&workers->idle_list); - INIT_LIST_HEAD(&workers->order_list); - INIT_LIST_HEAD(&workers->prio_order_list); - spin_lock_init(&workers->lock); - spin_lock_init(&workers->order_lock); - workers->max_workers = max; - workers->idle_thresh = 32; - workers->name = name; - workers->ordered = 0; - workers->atomic_start_pending = 0; - workers->atomic_worker_start = async_helper; - workers->stopping = 0; -} - -/* - * starts new worker threads. This does not enforce the max worker - * count in case you need to temporarily go past it. - */ -static int __btrfs_start_workers(struct btrfs_workers *workers) -{ - struct btrfs_worker_thread *worker; - int ret = 0; - - worker = kzalloc(sizeof(*worker), GFP_NOFS); - if (!worker) { - ret = -ENOMEM; - goto fail; - } - - INIT_LIST_HEAD(&worker->pending); - INIT_LIST_HEAD(&worker->prio_pending); - INIT_LIST_HEAD(&worker->worker_list); - spin_lock_init(&worker->lock); - - atomic_set(&worker->num_pending, 0); - atomic_set(&worker->refs, 1); - worker->workers = workers; - worker->task = kthread_create(worker_loop, worker, - "btrfs-%s-%d", workers->name, - workers->num_workers + 1); - if (IS_ERR(worker->task)) { - ret = PTR_ERR(worker->task); - goto fail; - } - - spin_lock_irq(&workers->lock); - if (workers->stopping) { - spin_unlock_irq(&workers->lock); - goto fail_kthread; - } - list_add_tail(&worker->worker_list, &workers->idle_list); - worker->idle = 1; - workers->num_workers++; - workers->num_workers_starting--; - WARN_ON(workers->num_workers_starting < 0); - spin_unlock_irq(&workers->lock); - - wake_up_process(worker->task); - return 0; - -fail_kthread: - kthread_stop(worker->task); -fail: - kfree(worker); - spin_lock_irq(&workers->lock); - workers->num_workers_starting--; - spin_unlock_irq(&workers->lock); - return ret; -} - -int btrfs_start_workers(struct btrfs_workers *workers) -{ - spin_lock_irq(&workers->lock); - workers->num_workers_starting++; - spin_unlock_irq(&workers->lock); - return __btrfs_start_workers(workers); -} - -/* - * run through the list and find a worker thread that doesn''t have a lot - * to do right now. This can return null if we aren''t yet at the thread - * count limit and all of the threads are busy. - */ -static struct btrfs_worker_thread *next_worker(struct btrfs_workers *workers) -{ - struct btrfs_worker_thread *worker; - struct list_head *next; - int enforce_min; - - enforce_min = (workers->num_workers + workers->num_workers_starting) < - workers->max_workers; - - /* - * if we find an idle thread, don''t move it to the end of the - * idle list. This improves the chance that the next submission - * will reuse the same thread, and maybe catch it while it is still - * working - */ - if (!list_empty(&workers->idle_list)) { - next = workers->idle_list.next; - worker = list_entry(next, struct btrfs_worker_thread, - worker_list); - return worker; - } - if (enforce_min || list_empty(&workers->worker_list)) - return NULL; - - /* - * if we pick a busy task, move the task to the end of the list. - * hopefully this will keep things somewhat evenly balanced. - * Do the move in batches based on the sequence number. This groups - * requests submitted at roughly the same time onto the same worker. - */ - next = workers->worker_list.next; - worker = list_entry(next, struct btrfs_worker_thread, worker_list); - worker->sequence++; - - if (worker->sequence % workers->idle_thresh == 0) - list_move_tail(next, &workers->worker_list); - return worker; -} - -/* - * selects a worker thread to take the next job. This will either find - * an idle worker, start a new worker up to the max count, or just return - * one of the existing busy workers. - */ -static struct btrfs_worker_thread *find_worker(struct btrfs_workers *workers) -{ - struct btrfs_worker_thread *worker; - unsigned long flags; - struct list_head *fallback; - int ret; - - spin_lock_irqsave(&workers->lock, flags); -again: - worker = next_worker(workers); - - if (!worker) { - if (workers->num_workers + workers->num_workers_starting >- workers->max_workers) { - goto fallback; - } else if (workers->atomic_worker_start) { - workers->atomic_start_pending = 1; - goto fallback; - } else { - workers->num_workers_starting++; - spin_unlock_irqrestore(&workers->lock, flags); - /* we''re below the limit, start another worker */ - ret = __btrfs_start_workers(workers); - spin_lock_irqsave(&workers->lock, flags); - if (ret) - goto fallback; - goto again; - } - } - goto found; - -fallback: - fallback = NULL; - /* - * we have failed to find any workers, just - * return the first one we can find. - */ - if (!list_empty(&workers->worker_list)) - fallback = workers->worker_list.next; - if (!list_empty(&workers->idle_list)) - fallback = workers->idle_list.next; - BUG_ON(!fallback); - worker = list_entry(fallback, - struct btrfs_worker_thread, worker_list); -found: - /* - * this makes sure the worker doesn''t exit before it is placed - * onto a busy/idle list - */ - atomic_inc(&worker->num_pending); - spin_unlock_irqrestore(&workers->lock, flags); - return worker; -} - -/* - * btrfs_requeue_work just puts the work item back on the tail of the list - * it was taken from. It is intended for use with long running work functions - * that make some progress and want to give the cpu up for others. - */ -void btrfs_requeue_work(struct btrfs_work *work) -{ - struct btrfs_worker_thread *worker = work->worker; - unsigned long flags; - int wake = 0; - - if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags)) - return; - - spin_lock_irqsave(&worker->lock, flags); - if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags)) - list_add_tail(&work->list, &worker->prio_pending); - else - list_add_tail(&work->list, &worker->pending); - atomic_inc(&worker->num_pending); - - /* by definition we''re busy, take ourselves off the idle - * list - */ - if (worker->idle) { - spin_lock(&worker->workers->lock); - worker->idle = 0; - list_move_tail(&worker->worker_list, - &worker->workers->worker_list); - spin_unlock(&worker->workers->lock); - } - if (!worker->working) { - wake = 1; - worker->working = 1; - } - - if (wake) - wake_up_process(worker->task); - spin_unlock_irqrestore(&worker->lock, flags); -} - -void btrfs_set_work_high_prio(struct btrfs_work *work) -{ - set_bit(WORK_HIGH_PRIO_BIT, &work->flags); -} - -/* - * places a struct btrfs_work into the pending queue of one of the kthreads - */ -void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work) -{ - struct btrfs_worker_thread *worker; - unsigned long flags; - int wake = 0; - - /* don''t requeue something already on a list */ - if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags)) - return; - - worker = find_worker(workers); - if (workers->ordered) { - /* - * you''re not allowed to do ordered queues from an - * interrupt handler - */ - spin_lock(&workers->order_lock); - if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags)) { - list_add_tail(&work->order_list, - &workers->prio_order_list); - } else { - list_add_tail(&work->order_list, &workers->order_list); - } - spin_unlock(&workers->order_lock); - } else { - INIT_LIST_HEAD(&work->order_list); - } - - spin_lock_irqsave(&worker->lock, flags); - - if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags)) - list_add_tail(&work->list, &worker->prio_pending); - else - list_add_tail(&work->list, &worker->pending); - check_busy_worker(worker); - - /* - * avoid calling into wake_up_process if this thread has already - * been kicked - */ - if (!worker->working) - wake = 1; - worker->working = 1; - - if (wake) - wake_up_process(worker->task); - spin_unlock_irqrestore(&worker->lock, flags); -} - struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, char *ordered_name, char *high_name, diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h index 44942b1..4acb83a 100644 --- a/fs/btrfs/async-thread.h +++ b/fs/btrfs/async-thread.h @@ -20,106 +20,6 @@ #ifndef __BTRFS_ASYNC_THREAD_ #define __BTRFS_ASYNC_THREAD_ -struct btrfs_worker_thread; - -/* - * This is similar to a workqueue, but it is meant to spread the operations - * across all available cpus instead of just the CPU that was used to - * queue the work. There is also some batching introduced to try and - * cut down on context switches. - * - * By default threads are added on demand up to 2 * the number of cpus. - * Changing struct btrfs_workers->max_workers is one way to prevent - * demand creation of kthreads. - * - * the basic model of these worker threads is to embed a btrfs_work - * structure in your own data struct, and use container_of in a - * work function to get back to your data struct. - */ -struct btrfs_work { - /* - * func should be set to the function you want called - * your work struct is passed as the only arg - * - * ordered_func must be set for work sent to an ordered work queue, - * and it is called to complete a given work item in the same - * order they were sent to the queue. - */ - void (*func)(struct btrfs_work *work); - void (*ordered_func)(struct btrfs_work *work); - void (*ordered_free)(struct btrfs_work *work); - - /* - * flags should be set to zero. It is used to make sure the - * struct is only inserted once into the list. - */ - unsigned long flags; - - /* don''t touch these */ - struct btrfs_worker_thread *worker; - struct list_head list; - struct list_head order_list; -}; - -struct btrfs_workers { - /* current number of running workers */ - int num_workers; - - int num_workers_starting; - - /* max number of workers allowed. changed by btrfs_start_workers */ - int max_workers; - - /* once a worker has this many requests or fewer, it is idle */ - int idle_thresh; - - /* force completions in the order they were queued */ - int ordered; - - /* more workers required, but in an interrupt handler */ - int atomic_start_pending; - - /* - * are we allowed to sleep while starting workers or are we required - * to start them at a later time? If we can''t sleep, this indicates - * which queue we need to use to schedule thread creation. - */ - struct btrfs_workers *atomic_worker_start; - - /* list with all the work threads. The workers on the idle thread - * may be actively servicing jobs, but they haven''t yet hit the - * idle thresh limit above. - */ - struct list_head worker_list; - struct list_head idle_list; - - /* - * when operating in ordered mode, this maintains the list - * of work items waiting for completion - */ - struct list_head order_list; - struct list_head prio_order_list; - - /* lock for finding the next worker thread to queue on */ - spinlock_t lock; - - /* lock for the ordered lists */ - spinlock_t order_lock; - - /* extra name for this worker, used for current->name */ - char *name; - - int stopping; -}; - -void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work); -int btrfs_start_workers(struct btrfs_workers *workers); -void btrfs_stop_workers(struct btrfs_workers *workers); -void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max, - struct btrfs_workers *async_starter); -void btrfs_requeue_work(struct btrfs_work *work); -void btrfs_set_work_high_prio(struct btrfs_work *work); - struct btrfs_workqueue_struct { struct workqueue_struct *normal_wq; struct workqueue_struct *ordered_wq; diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 1da2f33..8979c4d 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1482,7 +1482,6 @@ struct btrfs_fs_info { * A third pool does submit_bio to avoid deadlocking with the other * two */ - struct btrfs_workers generic_worker; struct btrfs_workqueue_struct *workers; struct btrfs_workqueue_struct *delalloc_workers; struct btrfs_workqueue_struct *flush_workers; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 6950570..4e6d250 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1991,7 +1991,6 @@ static noinline int next_root_backup(struct btrfs_fs_info *info, /* helper to cleanup workers */ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) { - btrfs_stop_workers(&fs_info->generic_worker); btrfs_destroy_workqueue(fs_info->fixup_workers); btrfs_destroy_workqueue(fs_info->delalloc_workers); btrfs_destroy_workqueue(fs_info->workers); @@ -2477,8 +2476,6 @@ int open_ctree(struct super_block *sb, } max_active = fs_info->thread_pool_size; - btrfs_init_workers(&fs_info->generic_worker, - "genwork", 1, NULL); fs_info->workers = btrfs_alloc_workqueue("worker", "worker-ordered", "worker-high", flags, @@ -2543,15 +2540,6 @@ int open_ctree(struct super_block *sb, btrfs_alloc_workqueue("qgroup-rescan", NULL, NULL, flags, 1, 0); - /* - * btrfs_start_workers can really only fail because of ENOMEM so just - * return -ENOMEM if any of these fail. - */ - ret = btrfs_start_workers(&fs_info->generic_worker); - if (ret) { - err = -ENOMEM; - goto fail_sb_buffer; - } if (!(fs_info->workers && fs_info->delalloc_workers && fs_info->submit_workers && fs_info->flush_workers && fs_info->endio_workers && fs_info->endio_meta_workers && diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 65bfbdf..001a0f3 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1227,13 +1227,6 @@ error_fs_info: return ERR_PTR(error); } -static void btrfs_set_max_workers(struct btrfs_workers *workers, int new_limit) -{ - spin_lock_irq(&workers->lock); - workers->max_workers = new_limit; - spin_unlock_irq(&workers->lock); -} - static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, int new_pool_size, int old_pool_size) { @@ -1245,7 +1238,6 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, printk(KERN_INFO "btrfs: resize thread pool %d -> %d\n", old_pool_size, new_pool_size); - btrfs_set_max_workers(&fs_info->generic_worker, new_pool_size); btrfs_workqueue_set_max(fs_info->workers, new_pool_size); btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->submit_workers, new_pool_size); -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Stefan Behrens
2013-Nov-07 09:33 UTC
Re: [PATCH v3 02/17] btrfs: Added btrfs_workqueue_struct implemented ordered execution based on kernel workqueue
On Thu, 7 Nov 2013 13:51:52 +0800, Qu Wenruo wrote:> Use kernel workqueue to implement a new btrfs_workqueue_struct, which > has the ordering execution feature like the btrfs_worker. > > The func is executed in a concurrency way, and the > ordred_func/ordered_free is executed in the sequence them are queued > after the corresponding func is done. > The new btrfs_workqueue use 2 workqueues to implement the original > btrfs_worker, one for the normal work and one for ordered work. > > At this patch, high priority work queue or thresholding is not added yet. > The high priority feature and thresholding will be added in the following patches. > > Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>[...]> diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h > index 1f26792..eee6709 100644 > --- a/fs/btrfs/async-thread.h > +++ b/fs/btrfs/async-thread.h > @@ -1,5 +1,6 @@ > /* > * Copyright (C) 2007 Oracle. All rights reserved. > + * Copyright (C) 2013 Fujitsu. All rights reserved. > * > * This program is free software; you can redistribute it and/or > * modify it under the terms of the GNU General Public > @@ -118,4 +119,47 @@ void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max, > struct btrfs_workers *async_starter); > void btrfs_requeue_work(struct btrfs_work *work); > void btrfs_set_work_high_prio(struct btrfs_work *work); > + > +struct btrfs_workqueue_struct { > + struct workqueue_struct *normal_wq; > + struct workqueue_struct *ordered_wq; > + > + /* > + * Spinlock to ensure that both ordered and normal work can > + * be inserted to each workqueue at the same sequance, > + * which will reduce the ordered_work waiting time and disk head moves. > + */ > + spinlock_t insert_lock; > +}; > + > +struct btrfs_work_struct { > + void (*func)(struct btrfs_work_struct *arg); > + void (*ordered_func)(struct btrfs_work_struct *arg); > + void (*ordered_free)(struct btrfs_work_struct *arg); > + > + /* Don''t touch things below */ > + struct work_struct normal_work; > + struct work_struct ordered_work; > + struct completion normal_completion; > +};If you compare the Btrfs sources before applying your patchset and after applying all 17 patches, one change is this: -struct btrfs_work { +struct btrfs_work_struct { Which causes changes s/struct btrfs_work/struct btrfs_work_struct/ like in patch 16/17: - struct btrfs_work work; + struct btrfs_work_struct + work; -static void scrub_bio_end_io_worker(struct btrfs_work *work); +static void scrub_bio_end_io_worker(struct btrfs_work_struct *work); I just don''t see any good reason for renaming ''struct foo'' to ''struct foo_struct''. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2013-Nov-07 16:05 UTC
Re: [PATCH v3 02/17] btrfs: Added btrfs_workqueue_struct implemented ordered execution based on kernel workqueue
On Thu, Nov 07, 2013 at 10:33:32AM +0100, Stefan Behrens wrote:> > +struct btrfs_work_struct { > > + void (*func)(struct btrfs_work_struct *arg); > > + void (*ordered_func)(struct btrfs_work_struct *arg); > > + void (*ordered_free)(struct btrfs_work_struct *arg); > > + > > + /* Don''t touch things below */ > > + struct work_struct normal_work; > > + struct work_struct ordered_work; > > + struct completion normal_completion; > > +}; > > If you compare the Btrfs sources before applying your patchset and after > applying all 17 patches, one change is this: > -struct btrfs_work { > +struct btrfs_work_struct { > > Which causes changes s/struct btrfs_work/struct btrfs_work_struct/ like > in patch 16/17: > - struct btrfs_work work; > + struct btrfs_work_struct > + work; > > -static void scrub_bio_end_io_worker(struct btrfs_work *work); > +static void scrub_bio_end_io_worker(struct btrfs_work_struct *work); > > I just don''t see any good reason for renaming ''struct foo'' to ''struct > foo_struct''.It seems to be meaningfull only though out this patchset. The old contents of btrfs_work is different from btrfs_work_struct, I agree it''s right to have the name without _struct suffix. But then the change to new worker structs would have to be done in one single patch, while there are 10+ patches converting each worker type. I suggest to add one more patch to the end that removes the _struct suffix again, so the series does not have to be redone. david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2013-Nov-07 16:41 UTC
Re: [PATCH v3 03/17] btrfs: Add high priority workqueue support for btrfs_workqueue_struct
On Thu, Nov 07, 2013 at 01:51:53PM +0800, Qu Wenruo wrote:> @@ -753,6 +754,19 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, > } > } > > + if (high_name) { > + ret->high_wq = alloc_workqueue(high_name, > + flags | WQ_HIGHPRI, > + max_active);I''d really like to add the btrfs- prefix of the workqueue. Quoting our previous discussion:> > * the thread names lost the btrfs- prefix, this makes it hard to > > identify the processes and we want this, either debugging or > > performance monitoring > Yes, that''s right. > But the problem is, even I added "btrfs-" prefix to the wq, > the real work executor is kernel workers without any prefix. > Still hard to debugging due to the workqueue mechanism.AFAICS the string passed down to alloc_workqueue ends up in the process name, this is what I''m expecing and don''t understand what do you mean. david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Josef Bacik
2013-Nov-07 17:24 UTC
Re: [PATCH v3 01/17] btrfs: Cleanup the unused struct async_sched.
On Thu, Nov 07, 2013 at 01:51:51PM +0800, Qu Wenruo wrote:> The struct async_sched is not used by any codes and can be removed. > > Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>Reviewed-by: Josef Bacik <jbacik@fusionio.com> Thanks, Josef -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2013-Nov-07 17:52 UTC
Re: [PATCH v3 00/17] Replace btrfs_workers with kernel workqueue based btrfs_workqueue_struct
On Thu, Nov 07, 2013 at 01:51:50PM +0800, Qu Wenruo wrote:> Qu Wenruo (17): > btrfs: Cleanup the unused struct async_sched. > btrfs: Added btrfs_workqueue_struct implemented ordered execution > based on kernel workqueue > btrfs: Add high priority workqueue support for btrfs_workqueue_struct > btrfs: Add threshold workqueue based on kernel workqueue > btrfs: Replace fs_info->workers with btrfs_workqueue. > btrfs: Replace fs_info->delalloc_workers with btrfs_workqueue > btrfs: Replace fs_info->submit_workers with btrfs_workqueue. > btrfs: Replace fs_info->flush_workers with btrfs_workqueue. > btrfs: Replace fs_info->endio_* workqueue with btrfs_workqueue. > btrfs: Replace fs_info->rmw_workers workqueue with btrfs_workqueue. > btrfs: Replace fs_info->cache_workers workqueue with btrfs_workqueue. > btrfs: Replace fs_info->readahead_workers workqueue with > btrfs_workqueue. > btrfs: Replace fs_info->fixup_workers workqueue with btrfs_workqueue. > btrfs: Replace fs_info->delayed_workers workqueue with > btrfs_workqueue. > btrfs: Replace fs_info->qgroup_rescan_worker workqueue with > btrfs_workqueue. > btrfs: Replace fs_info->scrub_* workqueue with btrfs_workqueue. > btrfs: Cleanup the old btrfs_worker.One comment to all patches: please try to stick to the kernel coding style, you''re changing code that will hopefully stay untouched for a long time, please get the formatting right from the beginning. - comment formatting - blank line after declaration block The patches need functional review, I''m not happy to point out such things, but please understand that it distracts (and sometimes hurts eyes) during review. david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Chris Mason
2013-Nov-07 17:54 UTC
Re: [PATCH v3 00/17] Replace btrfs_workers with kernel workqueue based btrfs_workqueue_struct
Quoting Qu Wenruo (2013-11-07 00:51:50)> Add a new btrfs_workqueue_struct which use kernel workqueue to implement > most of the original btrfs_workers, to replace btrfs_workers. > > With this patchset, redundant workqueue codes are replaced with kernel > workqueue infrastructure, which not only reduces the code size but also the > effort to maintain it. > > More performace tests are ongoing, the result from sysbench shows minor > improvement on the following server: > CPU: two-way Xeon X5660 > RAM: 4G > HDD: SAS HDD, 150G total, 40G partition for btrfs test > > Test result: > Mode|Num_threads|block size|extra flags|performance change vs 3.11 kernel > rndrd 1 4K none +1.22% > rndrd 1 32K none +1.00% > rndrd 8 32K sync +1.35% > seqrd 8 4K direct +5.56% > seqwr 8 4K none -1.26% > seqwr 8 32K sync +1.20% > > Changes below 1% are not mentioned. > Overall the patchset doesn''t change the performance on HDD. > > Since more tests are needed, more test result are welcomed.Thanks for working on this, it''s really good to move toward a single set of workqueues in the kernel. Have you benchmarked with compression on? Especially on modern hardware, the crcs don''t exercise the workqueues very much. -chris -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Josef Bacik
2013-Nov-07 18:08 UTC
Re: [PATCH v3 02/17] btrfs: Added btrfs_workqueue_struct implemented ordered execution based on kernel workqueue
On Thu, Nov 07, 2013 at 01:51:52PM +0800, Qu Wenruo wrote:> Use kernel workqueue to implement a new btrfs_workqueue_struct, which > has the ordering execution feature like the btrfs_worker. > > The func is executed in a concurrency way, and the > ordred_func/ordered_free is executed in the sequence them are queued > after the corresponding func is done. > The new btrfs_workqueue use 2 workqueues to implement the original > btrfs_worker, one for the normal work and one for ordered work. > > At this patch, high priority work queue or thresholding is not added yet. > The high priority feature and thresholding will be added in the following patches. > > Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>Reviewed-by: Josef Bacik <jbacik@fusionio.com> Thanks, Josef -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Josef Bacik
2013-Nov-07 18:09 UTC
Re: [PATCH v3 02/17] btrfs: Added btrfs_workqueue_struct implemented ordered execution based on kernel workqueue
On Thu, Nov 07, 2013 at 01:08:26PM -0500, Josef Bacik wrote:> On Thu, Nov 07, 2013 at 01:51:52PM +0800, Qu Wenruo wrote: > > Use kernel workqueue to implement a new btrfs_workqueue_struct, which > > has the ordering execution feature like the btrfs_worker. > > > > The func is executed in a concurrency way, and the > > ordred_func/ordered_free is executed in the sequence them are queued > > after the corresponding func is done. > > The new btrfs_workqueue use 2 workqueues to implement the original > > btrfs_worker, one for the normal work and one for ordered work. > > > > At this patch, high priority work queue or thresholding is not added yet. > > The high priority feature and thresholding will be added in the following patches. > > > > Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> > > Reviewed-by: Josef Bacik <jbacik@fusionio.com> >Keep in mind I agree with Stefan and Dave''s comments so please make those changes, but after that you can add my reviewed by. Thanks, Josef -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-08 00:32 UTC
Re: [PATCH v3 02/17] btrfs: Added btrfs_workqueue_struct implemented ordered execution based on kernel workqueue
On thu, 7 Nov 2013 17:05:29 +0100, David Sterba wrote:> On Thu, Nov 07, 2013 at 10:33:32AM +0100, Stefan Behrens wrote: >>> +struct btrfs_work_struct { >>> + void (*func)(struct btrfs_work_struct *arg); >>> + void (*ordered_func)(struct btrfs_work_struct *arg); >>> + void (*ordered_free)(struct btrfs_work_struct *arg); >>> + >>> + /* Don''t touch things below */ >>> + struct work_struct normal_work; >>> + struct work_struct ordered_work; >>> + struct completion normal_completion; >>> +}; >> If you compare the Btrfs sources before applying your patchset and after >> applying all 17 patches, one change is this: >> -struct btrfs_work { >> +struct btrfs_work_struct { >> >> Which causes changes s/struct btrfs_work/struct btrfs_work_struct/ like >> in patch 16/17: >> - struct btrfs_work work; >> + struct btrfs_work_struct >> + work; >> >> -static void scrub_bio_end_io_worker(struct btrfs_work *work); >> +static void scrub_bio_end_io_worker(struct btrfs_work_struct *work); >> >> I just don''t see any good reason for renaming ''struct foo'' to ''struct >> foo_struct''. > It seems to be meaningfull only though out this patchset. The old > contents of btrfs_work is different from btrfs_work_struct, I agree it''s > right to have the name without _struct suffix. But then the change to > new worker structs would have to be done in one single patch, while > there are 10+ patches converting each worker type. > > I suggest to add one more patch to the end that removes the _struct > suffix again, so the series does not have to be redone. > > david > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >Yes, the "_struct" suffix is mostly used to distinguishfrom the original btrfs_workers, and also try to use the kernel workqueue naming, which has the "_struct" suffix. And itis true that the long struct name makes some original codes ugly. I''ll add a new patchafter all these patches to remove the long suffix. Thanks Qu -- ----------------------------------------------------- Qu Wenruo Development Dept.I Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST) No. 6 Wenzhu Road, Nanjing, 210012, China TEL: +86+25-86630566-8526 COINS: 7998-8526 FAX: +86+25-83317685 MAIL: quwenruo@cn.fujitsu.com ----------------------------------------------------- -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-08 00:53 UTC
Re: [PATCH v3 03/17] btrfs: Add high priority workqueue support for btrfs_workqueue_struct
On Thu, 7 Nov 2013 17:41:34 +0100, David Sterba wrote:> On Thu, Nov 07, 2013 at 01:51:53PM +0800, Qu Wenruo wrote: >> @@ -753,6 +754,19 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, >> } >> } >> >> + if (high_name) { >> + ret->high_wq = alloc_workqueue(high_name, >> + flags | WQ_HIGHPRI, >> + max_active); > I''d really like to add the btrfs- prefix of the workqueue. Quoting our > previous discussion:Sorry, I forgot to add the "btrfs-" prefix. But on the other hand, I prefer to add the prefix outside the alloc_btrfs_workqueue, which means change the strings passed to alloc_btrfs_workqueue. (Maybe add a small macro?) Which way do you prefer?> >>> * the thread names lost the btrfs- prefix, this makes it hard to >>> identify the processes and we want this, either debugging or >>> performance monitoring >> Yes, that''s right. >> But the problem is, even I added "btrfs-" prefix to the wq, >> the real work executor is kernel workers without any prefix. >> Still hard to debugging due to the workqueue mechanism. > AFAICS the string passed down to alloc_workqueue ends up in the process > name, this is what I''m expecing and don''t understand what do you mean. > > > david >Sorry for the misunderstanding words. What I mean is that, since we use the kernel workqueue, there will be no kthread named the "btrfs-worker" or something like it. (Only when WQ_MEM_RECLAIM is set, the rescuer kthread will have the name, See kernel/workqueue.c if(flags & WQ_MEM_RECLAIM) para). The real executor will be something like kworker/u8:6(Unbound workqueue), so even the prefix is added, it''s still harder than the original way to debug workqueue. What makes it worse is that, to simulate the thresholding and ordering, I added serveral helper functions, which even makes kernel tracing not so meaningful(all function queued to workqueue will all be normal_helper or ordered_helper). Neither way, the prefix will be added, but I consider this may not really help to debug or monitor. Qu. -- ----------------------------------------------------- Qu Wenruo Development Dept.I Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST) No. 6 Wenzhu Road, Nanjing, 210012, China TEL: +86+25-86630566-8526 COINS: 7998-8526 FAX: +86+25-83317685 MAIL: quwenruo@cn.fujitsu.com ----------------------------------------------------- -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-08 00:55 UTC
Re: [PATCH v3 00/17] Replace btrfs_workers with kernel workqueue based btrfs_workqueue_struct
On thu, 7 Nov 2013 18:52:14 +0100, David Sterba wrote:> On Thu, Nov 07, 2013 at 01:51:50PM +0800, Qu Wenruo wrote: >> Qu Wenruo (17): >> btrfs: Cleanup the unused struct async_sched. >> btrfs: Added btrfs_workqueue_struct implemented ordered execution >> based on kernel workqueue >> btrfs: Add high priority workqueue support for btrfs_workqueue_struct >> btrfs: Add threshold workqueue based on kernel workqueue >> btrfs: Replace fs_info->workers with btrfs_workqueue. >> btrfs: Replace fs_info->delalloc_workers with btrfs_workqueue >> btrfs: Replace fs_info->submit_workers with btrfs_workqueue. >> btrfs: Replace fs_info->flush_workers with btrfs_workqueue. >> btrfs: Replace fs_info->endio_* workqueue with btrfs_workqueue. >> btrfs: Replace fs_info->rmw_workers workqueue with btrfs_workqueue. >> btrfs: Replace fs_info->cache_workers workqueue with btrfs_workqueue. >> btrfs: Replace fs_info->readahead_workers workqueue with >> btrfs_workqueue. >> btrfs: Replace fs_info->fixup_workers workqueue with btrfs_workqueue. >> btrfs: Replace fs_info->delayed_workers workqueue with >> btrfs_workqueue. >> btrfs: Replace fs_info->qgroup_rescan_worker workqueue with >> btrfs_workqueue. >> btrfs: Replace fs_info->scrub_* workqueue with btrfs_workqueue. >> btrfs: Cleanup the old btrfs_worker. > One comment to all patches: please try to stick to the kernel coding > style, you''re changing code that will hopefully stay untouched for a > long time, please get the formatting right from the beginning. > > - comment formatting > - blank line after declaration block > > The patches need functional review, I''m not happy to point out such > things, but please understand that it distracts (and sometimes hurts > eyes) during review. > > david > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >Thanks for pointing out the coding style problem. I''ll check them again to fix the problem. Thanks. Qu -- ----------------------------------------------------- Qu Wenruo Development Dept.I Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST) No. 6 Wenzhu Road, Nanjing, 210012, China TEL: +86+25-86630566-8526 COINS: 7998-8526 FAX: +86+25-83317685 MAIL: quwenruo@cn.fujitsu.com ----------------------------------------------------- -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-08 00:56 UTC
Re: [PATCH v3 00/17] Replace btrfs_workers with kernel workqueue based btrfs_workqueue_struct
On Thu, 7 Nov 2013 12:54:56 -0500, Chris Mason wrote:> Quoting Qu Wenruo (2013-11-07 00:51:50) >> Add a new btrfs_workqueue_struct which use kernel workqueue to implement >> most of the original btrfs_workers, to replace btrfs_workers. >> >> With this patchset, redundant workqueue codes are replaced with kernel >> workqueue infrastructure, which not only reduces the code size but also the >> effort to maintain it. >> >> More performace tests are ongoing, the result from sysbench shows minor >> improvement on the following server: >> CPU: two-way Xeon X5660 >> RAM: 4G >> HDD: SAS HDD, 150G total, 40G partition for btrfs test >> >> Test result: >> Mode|Num_threads|block size|extra flags|performance change vs 3.11 kernel >> rndrd 1 4K none +1.22% >> rndrd 1 32K none +1.00% >> rndrd 8 32K sync +1.35% >> seqrd 8 4K direct +5.56% >> seqwr 8 4K none -1.26% >> seqwr 8 32K sync +1.20% >> >> Changes below 1% are not mentioned. >> Overall the patchset doesn''t change the performance on HDD. >> >> Since more tests are needed, more test result are welcomed. > Thanks for working on this, it''s really good to move toward a single set > of workqueues in the kernel. > > Have you benchmarked with compression on? Especially on modern > hardware, the crcs don''t exercise the workqueues very much. > > -chris >Iwill benchmarked on SSD and coompression both before next version of patch. Thanks. Qu -- ----------------------------------------------------- Qu Wenruo Development Dept.I Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST) No. 6 Wenzhu Road, Nanjing, 210012, China TEL: +86+25-86630566-8526 COINS: 7998-8526 FAX: +86+25-83317685 MAIL: quwenruo@cn.fujitsu.com ----------------------------------------------------- -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-08 00:58 UTC
Re: [PATCH v3 02/17] btrfs: Added btrfs_workqueue_struct implemented ordered execution based on kernel workqueue
On Thu, 7 Nov 2013 13:09:56 -0500, Josef Bacik wrote:> On Thu, Nov 07, 2013 at 01:08:26PM -0500, Josef Bacik wrote: >> On Thu, Nov 07, 2013 at 01:51:52PM +0800, Qu Wenruo wrote: >>> Use kernel workqueue to implement a new btrfs_workqueue_struct, which >>> has the ordering execution feature like the btrfs_worker. >>> >>> The func is executed in a concurrency way, and the >>> ordred_func/ordered_free is executed in the sequence them are queued >>> after the corresponding func is done. >>> The new btrfs_workqueue use 2 workqueues to implement the original >>> btrfs_worker, one for the normal work and one for ordered work. >>> >>> At this patch, high priority work queue or thresholding is not added yet. >>> The high priority feature and thresholding will be added in the following patches. >>> >>> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> >> Reviewed-by: Josef Bacik <jbacik@fusionio.com> >> > Keep in mind I agree with Stefan and Dave''s comments so please make those > changes, but after that you can add my reviewed by. Thanks, > > Josef >I''ll apply the Stefan and Dave''s comments in the next versionwith more benchmarks. Thanks. Qu -- ----------------------------------------------------- Qu Wenruo Development Dept.I Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST) No. 6 Wenzhu Road, Nanjing, 210012, China TEL: +86+25-86630566-8526 COINS: 7998-8526 FAX: +86+25-83317685 MAIL: quwenruo@cn.fujitsu.com ----------------------------------------------------- -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2013-Nov-12 16:59 UTC
Re: [PATCH v3 03/17] btrfs: Add high priority workqueue support for btrfs_workqueue_struct
On Fri, Nov 08, 2013 at 08:53:00AM +0800, Qu Wenruo wrote:> On Thu, 7 Nov 2013 17:41:34 +0100, David Sterba wrote: > >On Thu, Nov 07, 2013 at 01:51:53PM +0800, Qu Wenruo wrote: > >>@@ -753,6 +754,19 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, > >> } > >> } > >>+ if (high_name) { > >>+ ret->high_wq = alloc_workqueue(high_name, > >>+ flags | WQ_HIGHPRI, > >>+ max_active); > >I''d really like to add the btrfs- prefix of the workqueue. Quoting our > >previous discussion: > Sorry, I forgot to add the "btrfs-" prefix. > But on the other hand, I prefer to add the prefix outside the > alloc_btrfs_workqueue, > which means change the strings passed to alloc_btrfs_workqueue. > (Maybe add a small macro?) > > Which way do you prefer?It''s actually quite simple, alloc_workque takes a printk format string, so: alloc_workqueue("%s-%s", flags, max_active, "btrfs", name); but I consider the following to be harder to get around.> >>>* the thread names lost the btrfs- prefix, this makes it hard to > >>> identify the processes and we want this, either debugging or > >>> performance monitoring > >>Yes, that''s right. > >>But the problem is, even I added "btrfs-" prefix to the wq, > >>the real work executor is kernel workers without any prefix. > >>Still hard to debugging due to the workqueue mechanism. > >AFAICS the string passed down to alloc_workqueue ends up in the process > >name, this is what I''m expecing and don''t understand what do you mean. > > > Sorry for the misunderstanding words. > What I mean is that, since we use the kernel workqueue, > there will be no kthread named the "btrfs-worker" or something like it. > (Only when WQ_MEM_RECLAIM is set, the rescuer kthread will have the name, > See kernel/workqueue.c if(flags & WQ_MEM_RECLAIM) para).You''re right, I was not aware of that, and actually checked the workqueus that have the MEM_RECLAIM bit set. Most of the btrfs IO workers will have to have this bit set, there are some of them that do not need it (scrub or readahead).> The real executor will be something like kworker/u8:6(Unbound workqueue), > so even the prefix is added, it''s still harder than the original way to > debug workqueue.Right, the question is if we really need it that way. We can set the MEM_RECLAIM bit but it looks like an abuse of the interface.> What makes it worse is that, to simulate the thresholding and ordering, > I added serveral helper functions, which even makes kernel tracing not so > meaningful(all function queued to workqueue will all be normal_helper or > ordered_helper).That''s a valid concern. Can we extend the tracepoints to keep the btrfs-worker name? So, as a first step, we can add MEM_RECLAIM to all threads, this should do the conversion close to the current state. Next we can start tuning the workqueue flags. This is an internal change, should be safe to do later. david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-13 00:53 UTC
Re: [PATCH v3 03/17] btrfs: Add high priority workqueue support for btrfs_workqueue_struct
On Tue, 12 Nov 2013 17:59:23 +0100, David Sterba wrote:> On Fri, Nov 08, 2013 at 08:53:00AM +0800, Qu Wenruo wrote: >> On Thu, 7 Nov 2013 17:41:34 +0100, David Sterba wrote: >>> On Thu, Nov 07, 2013 at 01:51:53PM +0800, Qu Wenruo wrote: >>>> @@ -753,6 +754,19 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, >>>> } >>>> } >>>> + if (high_name) { >>>> + ret->high_wq = alloc_workqueue(high_name, >>>> + flags | WQ_HIGHPRI, >>>> + max_active); >>> I''d really like to add the btrfs- prefix of the workqueue. Quoting our >>> previous discussion: >> Sorry, I forgot to add the "btrfs-" prefix. >> But on the other hand, I prefer to add the prefix outside the >> alloc_btrfs_workqueue, >> which means change the strings passed to alloc_btrfs_workqueue. >> (Maybe add a small macro?) >> >> Which way do you prefer? > It''s actually quite simple, alloc_workque takes a printk format string, > so: > > alloc_workqueue("%s-%s", flags, max_active, "btrfs", name);Oh, I forgot the printk format way. Good idea.> > but I consider the following to be harder to get around. > >>>>> * the thread names lost the btrfs- prefix, this makes it hard to >>>>> identify the processes and we want this, either debugging or >>>>> performance monitoring >>>> Yes, that''s right. >>>> But the problem is, even I added "btrfs-" prefix to the wq, >>>> the real work executor is kernel workers without any prefix. >>>> Still hard to debugging due to the workqueue mechanism. >>> AFAICS the string passed down to alloc_workqueue ends up in the process >>> name, this is what I''m expecing and don''t understand what do you mean. >>> >> Sorry for the misunderstanding words. >> What I mean is that, since we use the kernel workqueue, >> there will be no kthread named the "btrfs-worker" or something like it. >> (Only when WQ_MEM_RECLAIM is set, the rescuer kthread will have the name, >> See kernel/workqueue.c if(flags & WQ_MEM_RECLAIM) para). > Qu > You''re right, I was not aware of that, and actually checked the > workqueus that have the MEM_RECLAIM bit set. Most of the btrfs IO > workers will have to have this bit set, there are some of them that do > not need it (scrub or readahead). > >> The real executor will be something like kworker/u8:6(Unbound workqueue), >> so even the prefix is added, it''s still harder than the original way to >> debug workqueue. > Right, the question is if we really need it that way. We can set the > MEM_RECLAIM bit but it looks like an abuse of the interface.Also forgot to mention is that, even the MEM_RECLAIM bit is set, the kthread is just a rescuer thread used for the following situiation: One kthread uses huge memory so other works can''t get memory for a new kthread, but some works is going to free the memory. So there will be a deadlock(memory is the resource that being raced). MEM_RECLAIM bit is used to solve this deadlock by pre-allocating a rescuer kthread, even no memory can be allocated, the works need to reclaim memory can directly use the pre-allocated kthread to reclaim memory. So even the MEM_RECLAIM bit is set, the real executor is still kworker... And it''s true that we are abusing the MEM_RECLAIM bit, but this abusing is somewhat the same behavior of the original btrfs workers since it also have at least one kthread even idle. (But it is easy to distinguish original btrfs workqueue from new btrfs workqueue and does not waste too much memory :)> >> What makes it worse is that, to simulate the thresholding and ordering, >> I added serveral helper functions, which even makes kernel tracing not so >> meaningful(all function queued to workqueue will all be normal_helper or >> ordered_helper). > That''s a valid concern. Can we extend the tracepoints to keep the > btrfs-worker name?Not familiar about the kernel tracing mechanism, but I''ll try it in later patches other than this patchset. (Also after some searching, it seems that btrfs does not have any tracepoints?!)> > So, as a first step, we can add MEM_RECLAIM to all threads, this should > do the conversion close to the current state. Next we can start tuning the > workqueue flags. This is an internal change, should be safe to do later.Yes, when fixing the comment style, I also changed the behavior of btrfs_alloc_workqueue function that not set the WQ_UNBOUND bit to allow further flags tunning. (I think some workqueue may benifit more from locality than distributing to other CPUs) Thanks. Qu> > > david >-- ----------------------------------------------------- Qu Wenruo Development Dept.I Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST) No. 6 Wenzhu Road, Nanjing, 210012, China TEL: +86+25-86630566-8526 COINS: 7998-8526 FAX: +86+25-83317685 MAIL: quwenruo@cn.fujitsu.com ----------------------------------------------------- -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-26 01:39 UTC
Re: [PATCH v3 00/17] Replace btrfs_workers with kernel workqueue based btrfs_workqueue_struct
On Thu, 7 Nov 2013 12:54:56 -0500, Chris Mason wrote:> Quoting Qu Wenruo (2013-11-07 00:51:50) >> Add a new btrfs_workqueue_struct which use kernel workqueue to implement >> most of the original btrfs_workers, to replace btrfs_workers. >> >> With this patchset, redundant workqueue codes are replaced with kernel >> workqueue infrastructure, which not only reduces the code size but also the >> effort to maintain it. >> >> More performace tests are ongoing, the result from sysbench shows minor >> improvement on the following server: >> CPU: two-way Xeon X5660 >> RAM: 4G >> HDD: SAS HDD, 150G total, 40G partition for btrfs test >> >> Test result: >> Mode|Num_threads|block size|extra flags|performance change vs 3.11 kernel >> rndrd 1 4K none +1.22% >> rndrd 1 32K none +1.00% >> rndrd 8 32K sync +1.35% >> seqrd 8 4K direct +5.56% >> seqwr 8 4K none -1.26% >> seqwr 8 32K sync +1.20% >> >> Changes below 1% are not mentioned. >> Overall the patchset doesn''t change the performance on HDD. >> >> Since more tests are needed, more test result are welcomed. > Thanks for working on this, it''s really good to move toward a single set > of workqueues in the kernel. > > Have you benchmarked with compression on? Especially on modern > hardware, the crcs don''t exercise the workqueues very much. > > -chris >The result with compression on is quite interesting. Overall minor improvement in random read, mixed but still minor changes in sequence write. Some impressive improvement and small regression in random write, as well as some improvement in sequence write. But overall, test result with compression is not as stable as the ones without compression,(some result data can change up to 15% using the same kernel) and the result seems good overall, even with some regression in some tests. I think the test machine should be modern enough as the following. CPU: Two way Xeon X5660 @ 2.80GHz(24 cores when full load) RAM: 4G(with mem=4G in kernel cmdline, physical RAM is 8G) HDD: SAS 150G HDD, test btrfs partition is 40G The detail test result is like the following:(Only changes over 1% is mentioned) Mode|Num_threads|block size|extra flags|performance change vs 3.11 kernel rndrd 1 32K async +1.98% rndrd 1 32K none +2.77% rndrd 8 4K async +5.16% rndrd 8 4K none +5.57% rndrd 8 32K async +5.11% seqrd 1 4K none +3.84% seqrd 1 32K async -2.84% seqrd 1 32K none +1.87% seqrd 8 4K none +4.75% seqrd 8 32K async +1.02% seqrd 8 32K none -1.38% rndwr 1 4K direct -7.84% rndwr 1 4K none +30.21% (*1) rndwr 1 32K async -7.84% rndwr 1 32K none -1.59% rndwr 8 4K async +32.60% (*2) rndwr 8 4K none +20.34% (*3) rndwr 8 32K async +1.06% rndwr 8 32K none -14.64% (*4) seqwr 1 4K async -1.87% seqwr 1 4K none +4.65% seqwr 1 32K async +1.72% seqwr 1 32K none +9.65% seqwr 8 4K async +6.47% seqwr 8 4K none -6.38% seqwr 8 32K async +15.14% seqwr 8 32K none +9.38% *1: The data on original kernel changes between 35~45MBytes/s, But on the patched kernel, the result tends to get a result of 70MBytes/s(about 50% chance), but sometimes, the result can also drops to the 35~45MBytes/s.(50% chance) *2: Much like *1, with patched kernel, result is more unstable and has a high chance to get a better result. Even the worst result with patched kernel, the data is still on par with the original kernel. *3: Much like *1 or *2, this time, the original kernel also have a chance to get a better result, but the possibility is much smaller than the patched kernel. *4: Sadly, this time the patched kernel is more unstable and has a high chance to get a worse result. *1~*4 only differ in the chance of unstable good/bad data, and the stable data seems on par. Qu -- ----------------------------------------------------- Qu Wenruo Development Dept.I Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST) No. 6 Wenzhu Road, Nanjing, 210012, China TEL: +86+25-86630566-8526 COINS: 7998-8526 FAX: +86+25-83317685 MAIL: quwenruo@cn.fujitsu.com ----------------------------------------------------- -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Liu Bo
2013-Nov-26 07:31 UTC
Re: [PATCH v3 00/17] Replace btrfs_workers with kernel workqueue based btrfs_workqueue_struct
On Tue, Nov 26, 2013 at 09:39:59AM +0800, Qu Wenruo wrote:> On Thu, 7 Nov 2013 12:54:56 -0500, Chris Mason wrote: > >Quoting Qu Wenruo (2013-11-07 00:51:50) > >>Add a new btrfs_workqueue_struct which use kernel workqueue to implement > >>most of the original btrfs_workers, to replace btrfs_workers. > >> > >>With this patchset, redundant workqueue codes are replaced with kernel > >>workqueue infrastructure, which not only reduces the code size but also the > >>effort to maintain it. > >> > >>More performace tests are ongoing, the result from sysbench shows minor > >>improvement on the following server: > >>CPU: two-way Xeon X5660 > >>RAM: 4G > >>HDD: SAS HDD, 150G total, 40G partition for btrfs test > >> > >>Test result: > >>Mode|Num_threads|block size|extra flags|performance change vs 3.11 kernel > >>rndrd 1 4K none +1.22% > >>rndrd 1 32K none +1.00% > >>rndrd 8 32K sync +1.35% > >>seqrd 8 4K direct +5.56% > >>seqwr 8 4K none -1.26% > >>seqwr 8 32K sync +1.20% > >> > >>Changes below 1% are not mentioned. > >>Overall the patchset doesn''t change the performance on HDD. > >> > >>Since more tests are needed, more test result are welcomed. > >Thanks for working on this, it''s really good to move toward a single set > >of workqueues in the kernel. > > > >Have you benchmarked with compression on? Especially on modern > >hardware, the crcs don''t exercise the workqueues very much. > > > >-chris > > > The result with compression on is quite interesting. > Overall minor improvement in random read, > mixed but still minor changes in sequence write. > Some impressive improvement and small regression in random write, > as well as some improvement in sequence write. > > But overall, test result with compression is not as stable as the > ones without compression,(some result data can change up to 15% > using the same kernel) > and the result seems good overall, even with some regression in some tests. > > I think the test machine should be modern enough as the following. > CPU: Two way Xeon X5660 @ 2.80GHz(24 cores when full load) > RAM: 4G(with mem=4G in kernel cmdline, physical RAM is 8G) > HDD: SAS 150G HDD, test btrfs partition is 40G > > The detail test result is like the following:(Only changes over 1% > is mentioned) > > Mode|Num_threads|block size|extra flags|performance change vs 3.11 kernel > rndrd 1 32K async +1.98% > rndrd 1 32K none +2.77% > rndrd 8 4K async +5.16% > rndrd 8 4K none +5.57% > rndrd 8 32K async +5.11% > seqrd 1 4K none +3.84% > seqrd 1 32K async -2.84% > seqrd 1 32K none +1.87% > seqrd 8 4K none +4.75% > seqrd 8 32K async +1.02% > seqrd 8 32K none -1.38% > rndwr 1 4K direct -7.84% > rndwr 1 4K none +30.21% (*1) > rndwr 1 32K async -7.84% > rndwr 1 32K none -1.59% > rndwr 8 4K async +32.60% (*2) > rndwr 8 4K none +20.34% (*3) > rndwr 8 32K async +1.06% > rndwr 8 32K none -14.64% (*4) > seqwr 1 4K async -1.87% > seqwr 1 4K none +4.65% > seqwr 1 32K async +1.72% > seqwr 1 32K none +9.65% > seqwr 8 4K async +6.47% > seqwr 8 4K none -6.38% > seqwr 8 32K async +15.14% > seqwr 8 32K none +9.38% > > *1: The data on original kernel changes between 35~45MBytes/s, > But on the patched kernel, the result tends to get a result of 70MBytes/s(about 50% chance), > but sometimes, the result can also drops to the 35~45MBytes/s.(50% chance) > > *2: Much like *1, with patched kernel, result is more unstable and has a high chance to > get a better result. Even the worst result with patched kernel, the data is still on par > with the original kernel. > > *3: Much like *1 or *2, this time, the original kernel also have a chance to get a better result, > but the possibility is much smaller than the patched kernel. > > *4: Sadly, this time the patched kernel is more unstable and has a high chance to get a worse result. > > *1~*4 only differ in the chance of unstable good/bad data, and the stable data seems on par.Can you verify if this is caused by overcommit stuff? Not sure if 40G is large enough to meet the metadata creation. thanks, -liubo -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Qu Wenruo
2013-Nov-26 08:33 UTC
Re: [PATCH v3 00/17] Replace btrfs_workers with kernel workqueue based btrfs_workqueue_struct
On Tue, 26 Nov 2013 15:31:10 +0800, Liu Bo wrote:> On Tue, Nov 26, 2013 at 09:39:59AM +0800, Qu Wenruo wrote: >> On Thu, 7 Nov 2013 12:54:56 -0500, Chris Mason wrote: >>> Quoting Qu Wenruo (2013-11-07 00:51:50) >>>> Add a new btrfs_workqueue_struct which use kernel workqueue to implement >>>> most of the original btrfs_workers, to replace btrfs_workers. >>>> >>>> With this patchset, redundant workqueue codes are replaced with kernel >>>> workqueue infrastructure, which not only reduces the code size but also the >>>> effort to maintain it. >>>> >>>> More performace tests are ongoing, the result from sysbench shows minor >>>> improvement on the following server: >>>> CPU: two-way Xeon X5660 >>>> RAM: 4G >>>> HDD: SAS HDD, 150G total, 40G partition for btrfs test >>>> >>>> Test result: >>>> Mode|Num_threads|block size|extra flags|performance change vs 3.11 kernel >>>> rndrd 1 4K none +1.22% >>>> rndrd 1 32K none +1.00% >>>> rndrd 8 32K sync +1.35% >>>> seqrd 8 4K direct +5.56% >>>> seqwr 8 4K none -1.26% >>>> seqwr 8 32K sync +1.20% >>>> >>>> Changes below 1% are not mentioned. >>>> Overall the patchset doesn''t change the performance on HDD. >>>> >>>> Since more tests are needed, more test result are welcomed. >>> Thanks for working on this, it''s really good to move toward a single set >>> of workqueues in the kernel. >>> >>> Have you benchmarked with compression on? Especially on modern >>> hardware, the crcs don''t exercise the workqueues very much. >>> >>> -chris >>> >> The result with compression on is quite interesting. >> Overall minor improvement in random read, >> mixed but still minor changes in sequence write. >> Some impressive improvement and small regression in random write, >> as well as some improvement in sequence write. >> >> But overall, test result with compression is not as stable as the >> ones without compression,(some result data can change up to 15% >> using the same kernel) >> and the result seems good overall, even with some regression in some tests. >> >> I think the test machine should be modern enough as the following. >> CPU: Two way Xeon X5660 @ 2.80GHz(24 cores when full load) >> RAM: 4G(with mem=4G in kernel cmdline, physical RAM is 8G) >> HDD: SAS 150G HDD, test btrfs partition is 40G >> >> The detail test result is like the following:(Only changes over 1% >> is mentioned) >> >> Mode|Num_threads|block size|extra flags|performance change vs 3.11 kernel >> rndrd 1 32K async +1.98% >> rndrd 1 32K none +2.77% >> rndrd 8 4K async +5.16% >> rndrd 8 4K none +5.57% >> rndrd 8 32K async +5.11% >> seqrd 1 4K none +3.84% >> seqrd 1 32K async -2.84% >> seqrd 1 32K none +1.87% >> seqrd 8 4K none +4.75% >> seqrd 8 32K async +1.02% >> seqrd 8 32K none -1.38% >> rndwr 1 4K direct -7.84% >> rndwr 1 4K none +30.21% (*1) >> rndwr 1 32K async -7.84% >> rndwr 1 32K none -1.59% >> rndwr 8 4K async +32.60% (*2) >> rndwr 8 4K none +20.34% (*3) >> rndwr 8 32K async +1.06% >> rndwr 8 32K none -14.64% (*4) >> seqwr 1 4K async -1.87% >> seqwr 1 4K none +4.65% >> seqwr 1 32K async +1.72% >> seqwr 1 32K none +9.65% >> seqwr 8 4K async +6.47% >> seqwr 8 4K none -6.38% >> seqwr 8 32K async +15.14% >> seqwr 8 32K none +9.38% >> >> *1: The data on original kernel changes between 35~45MBytes/s, >> But on the patched kernel, the result tends to get a result of 70MBytes/s(about 50% chance), >> but sometimes, the result can also drops to the 35~45MBytes/s.(50% chance) >> >> *2: Much like *1, with patched kernel, result is more unstable and has a high chance to >> get a better result. Even the worst result with patched kernel, the data is still on par >> with the original kernel. >> >> *3: Much like *1 or *2, this time, the original kernel also have a chance to get a better result, >> but the possibility is much smaller than the patched kernel. >> >> *4: Sadly, this time the patched kernel is more unstable and has a high chance to get a worse result. >> >> *1~*4 only differ in the chance of unstable good/bad data, and the stable data seems on par. > Can you verify if this is caused by overcommit stuff? > > Not sure if 40G is large enough to meet the metadata creation. > > thanks, > -liubo >Maybe, but has no extra space to verify it. Also even itisdue to the space, I still need to check why the original kernel has no such problem... Anyway thanks for the clue. Qu -- ----------------------------------------------------- Qu Wenruo Development Dept.I Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST) No. 6 Wenzhu Road, Nanjing, 210012, China TEL: +86+25-86630566-8526 COINS: 7998-8526 FAX: +86+25-83317685 MAIL: quwenruo@cn.fujitsu.com ----------------------------------------------------- -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html