Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Oracle. All rights reserved. |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 3 | * Copyright (C) 2014 Fujitsu. All rights reserved. |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public |
| 7 | * License v2 as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public |
| 15 | * License along with this program; if not, write to the |
| 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 17 | * Boston, MA 021110-1307, USA. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/kthread.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 22 | #include <linux/list.h> |
| 23 | #include <linux/spinlock.h> |
Chris Mason | b51912c | 2009-02-04 09:23:24 -0500 | [diff] [blame] | 24 | #include <linux/freezer.h> |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 25 | #include <linux/workqueue.h> |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 26 | #include "async-thread.h" |
| 27 | |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 28 | #define WORK_QUEUED_BIT 0 |
| 29 | #define WORK_DONE_BIT 1 |
| 30 | #define WORK_ORDER_DONE_BIT 2 |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 31 | #define WORK_HIGH_PRIO_BIT 3 |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 32 | |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 33 | #define NO_THRESHOLD (-1) |
| 34 | #define DFT_THRESHOLD (32) |
| 35 | |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 36 | /* |
| 37 | * container for the kthread task pointer and the list of pending work |
| 38 | * One of these is allocated per thread. |
| 39 | */ |
| 40 | struct btrfs_worker_thread { |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 41 | /* pool we belong to */ |
| 42 | struct btrfs_workers *workers; |
| 43 | |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 44 | /* list of struct btrfs_work that are waiting for service */ |
| 45 | struct list_head pending; |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 46 | struct list_head prio_pending; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 47 | |
| 48 | /* list of worker threads from struct btrfs_workers */ |
| 49 | struct list_head worker_list; |
| 50 | |
| 51 | /* kthread */ |
| 52 | struct task_struct *task; |
| 53 | |
| 54 | /* number of things on the pending list */ |
| 55 | atomic_t num_pending; |
Chris Mason | 5386323 | 2008-08-15 15:34:18 -0400 | [diff] [blame] | 56 | |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 57 | /* reference counter for this struct */ |
| 58 | atomic_t refs; |
| 59 | |
Chris Mason | 4854ddd | 2008-08-15 15:34:17 -0400 | [diff] [blame] | 60 | unsigned long sequence; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 61 | |
| 62 | /* protects the pending list. */ |
| 63 | spinlock_t lock; |
| 64 | |
| 65 | /* set to non-zero when this thread is already awake and kicking */ |
| 66 | int working; |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 67 | |
| 68 | /* are we currently idle */ |
| 69 | int idle; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 70 | }; |
| 71 | |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 72 | static int __btrfs_start_workers(struct btrfs_workers *workers); |
| 73 | |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 74 | /* |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 75 | * btrfs_start_workers uses kthread_run, which can block waiting for memory |
| 76 | * for a very long time. It will actually throttle on page writeback, |
| 77 | * and so it may not make progress until after our btrfs worker threads |
| 78 | * process all of the pending work structs in their queue |
| 79 | * |
| 80 | * This means we can't use btrfs_start_workers from inside a btrfs worker |
| 81 | * thread that is used as part of cleaning dirty memory, which pretty much |
| 82 | * involves all of the worker threads. |
| 83 | * |
| 84 | * Instead we have a helper queue who never has more than one thread |
| 85 | * where we scheduler thread start operations. This worker_start struct |
| 86 | * is used to contain the work and hold a pointer to the queue that needs |
| 87 | * another worker. |
| 88 | */ |
| 89 | struct worker_start { |
| 90 | struct btrfs_work work; |
| 91 | struct btrfs_workers *queue; |
| 92 | }; |
| 93 | |
| 94 | static void start_new_worker_func(struct btrfs_work *work) |
| 95 | { |
| 96 | struct worker_start *start; |
| 97 | start = container_of(work, struct worker_start, work); |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 98 | __btrfs_start_workers(start->queue); |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 99 | kfree(start); |
| 100 | } |
| 101 | |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 102 | /* |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 103 | * helper function to move a thread onto the idle list after it |
| 104 | * has finished some requests. |
| 105 | */ |
| 106 | static void check_idle_worker(struct btrfs_worker_thread *worker) |
| 107 | { |
| 108 | if (!worker->idle && atomic_read(&worker->num_pending) < |
| 109 | worker->workers->idle_thresh / 2) { |
| 110 | unsigned long flags; |
| 111 | spin_lock_irqsave(&worker->workers->lock, flags); |
| 112 | worker->idle = 1; |
Chris Mason | 3e99d8e | 2009-09-15 19:57:42 -0400 | [diff] [blame] | 113 | |
| 114 | /* the list may be empty if the worker is just starting */ |
Ilya Dryomov | 964fb15a | 2013-10-02 19:39:50 +0300 | [diff] [blame] | 115 | if (!list_empty(&worker->worker_list) && |
| 116 | !worker->workers->stopping) { |
Chris Mason | 3e99d8e | 2009-09-15 19:57:42 -0400 | [diff] [blame] | 117 | list_move(&worker->worker_list, |
| 118 | &worker->workers->idle_list); |
| 119 | } |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 120 | spin_unlock_irqrestore(&worker->workers->lock, flags); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /* |
| 125 | * helper function to move a thread off the idle list after new |
| 126 | * pending work is added. |
| 127 | */ |
| 128 | static void check_busy_worker(struct btrfs_worker_thread *worker) |
| 129 | { |
| 130 | if (worker->idle && atomic_read(&worker->num_pending) >= |
| 131 | worker->workers->idle_thresh) { |
| 132 | unsigned long flags; |
| 133 | spin_lock_irqsave(&worker->workers->lock, flags); |
| 134 | worker->idle = 0; |
Chris Mason | 3e99d8e | 2009-09-15 19:57:42 -0400 | [diff] [blame] | 135 | |
Ilya Dryomov | 964fb15a | 2013-10-02 19:39:50 +0300 | [diff] [blame] | 136 | if (!list_empty(&worker->worker_list) && |
| 137 | !worker->workers->stopping) { |
Chris Mason | 3e99d8e | 2009-09-15 19:57:42 -0400 | [diff] [blame] | 138 | list_move_tail(&worker->worker_list, |
| 139 | &worker->workers->worker_list); |
| 140 | } |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 141 | spin_unlock_irqrestore(&worker->workers->lock, flags); |
| 142 | } |
| 143 | } |
| 144 | |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 145 | static void check_pending_worker_creates(struct btrfs_worker_thread *worker) |
| 146 | { |
| 147 | struct btrfs_workers *workers = worker->workers; |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 148 | struct worker_start *start; |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 149 | unsigned long flags; |
| 150 | |
| 151 | rmb(); |
| 152 | if (!workers->atomic_start_pending) |
| 153 | return; |
| 154 | |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 155 | start = kzalloc(sizeof(*start), GFP_NOFS); |
| 156 | if (!start) |
| 157 | return; |
| 158 | |
| 159 | start->work.func = start_new_worker_func; |
| 160 | start->queue = workers; |
| 161 | |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 162 | spin_lock_irqsave(&workers->lock, flags); |
| 163 | if (!workers->atomic_start_pending) |
| 164 | goto out; |
| 165 | |
| 166 | workers->atomic_start_pending = 0; |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 167 | if (workers->num_workers + workers->num_workers_starting >= |
| 168 | workers->max_workers) |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 169 | goto out; |
| 170 | |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 171 | workers->num_workers_starting += 1; |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 172 | spin_unlock_irqrestore(&workers->lock, flags); |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 173 | btrfs_queue_worker(workers->atomic_worker_start, &start->work); |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 174 | return; |
| 175 | |
| 176 | out: |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 177 | kfree(start); |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 178 | spin_unlock_irqrestore(&workers->lock, flags); |
| 179 | } |
| 180 | |
Jeff Mahoney | 143bede | 2012-03-01 14:56:26 +0100 | [diff] [blame] | 181 | static noinline void run_ordered_completions(struct btrfs_workers *workers, |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 182 | struct btrfs_work *work) |
| 183 | { |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 184 | if (!workers->ordered) |
Jeff Mahoney | 143bede | 2012-03-01 14:56:26 +0100 | [diff] [blame] | 185 | return; |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 186 | |
| 187 | set_bit(WORK_DONE_BIT, &work->flags); |
| 188 | |
Chris Mason | 4e3f9c5 | 2009-08-05 16:36:45 -0400 | [diff] [blame] | 189 | spin_lock(&workers->order_lock); |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 190 | |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 191 | while (1) { |
| 192 | if (!list_empty(&workers->prio_order_list)) { |
| 193 | work = list_entry(workers->prio_order_list.next, |
| 194 | struct btrfs_work, order_list); |
| 195 | } else if (!list_empty(&workers->order_list)) { |
| 196 | work = list_entry(workers->order_list.next, |
| 197 | struct btrfs_work, order_list); |
| 198 | } else { |
| 199 | break; |
| 200 | } |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 201 | if (!test_bit(WORK_DONE_BIT, &work->flags)) |
| 202 | break; |
| 203 | |
| 204 | /* we are going to call the ordered done function, but |
| 205 | * we leave the work item on the list as a barrier so |
| 206 | * that later work items that are done don't have their |
| 207 | * functions called before this one returns |
| 208 | */ |
| 209 | if (test_and_set_bit(WORK_ORDER_DONE_BIT, &work->flags)) |
| 210 | break; |
| 211 | |
Chris Mason | 4e3f9c5 | 2009-08-05 16:36:45 -0400 | [diff] [blame] | 212 | spin_unlock(&workers->order_lock); |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 213 | |
| 214 | work->ordered_func(work); |
| 215 | |
Chris Mason | e9fbcb4 | 2012-07-25 15:57:13 -0400 | [diff] [blame] | 216 | /* now take the lock again and drop our item from the list */ |
Chris Mason | 4e3f9c5 | 2009-08-05 16:36:45 -0400 | [diff] [blame] | 217 | spin_lock(&workers->order_lock); |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 218 | list_del(&work->order_list); |
Chris Mason | e9fbcb4 | 2012-07-25 15:57:13 -0400 | [diff] [blame] | 219 | spin_unlock(&workers->order_lock); |
| 220 | |
| 221 | /* |
| 222 | * we don't want to call the ordered free functions |
| 223 | * with the lock held though |
| 224 | */ |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 225 | work->ordered_free(work); |
Chris Mason | e9fbcb4 | 2012-07-25 15:57:13 -0400 | [diff] [blame] | 226 | spin_lock(&workers->order_lock); |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 227 | } |
| 228 | |
Chris Mason | 4e3f9c5 | 2009-08-05 16:36:45 -0400 | [diff] [blame] | 229 | spin_unlock(&workers->order_lock); |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 230 | } |
| 231 | |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 232 | static void put_worker(struct btrfs_worker_thread *worker) |
| 233 | { |
| 234 | if (atomic_dec_and_test(&worker->refs)) |
| 235 | kfree(worker); |
| 236 | } |
| 237 | |
| 238 | static int try_worker_shutdown(struct btrfs_worker_thread *worker) |
| 239 | { |
| 240 | int freeit = 0; |
| 241 | |
| 242 | spin_lock_irq(&worker->lock); |
Chris Mason | 627e421 | 2009-09-15 20:00:36 -0400 | [diff] [blame] | 243 | spin_lock(&worker->workers->lock); |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 244 | if (worker->workers->num_workers > 1 && |
| 245 | worker->idle && |
| 246 | !worker->working && |
| 247 | !list_empty(&worker->worker_list) && |
| 248 | list_empty(&worker->prio_pending) && |
Chris Mason | 6e74057 | 2009-09-15 20:02:33 -0400 | [diff] [blame] | 249 | list_empty(&worker->pending) && |
| 250 | atomic_read(&worker->num_pending) == 0) { |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 251 | freeit = 1; |
| 252 | list_del_init(&worker->worker_list); |
| 253 | worker->workers->num_workers--; |
| 254 | } |
Chris Mason | 627e421 | 2009-09-15 20:00:36 -0400 | [diff] [blame] | 255 | spin_unlock(&worker->workers->lock); |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 256 | spin_unlock_irq(&worker->lock); |
| 257 | |
| 258 | if (freeit) |
| 259 | put_worker(worker); |
| 260 | return freeit; |
| 261 | } |
| 262 | |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 263 | static struct btrfs_work *get_next_work(struct btrfs_worker_thread *worker, |
| 264 | struct list_head *prio_head, |
| 265 | struct list_head *head) |
| 266 | { |
| 267 | struct btrfs_work *work = NULL; |
| 268 | struct list_head *cur = NULL; |
| 269 | |
Stanislaw Gruszka | 51b98ef | 2014-02-08 23:18:43 +0100 | [diff] [blame] | 270 | if (!list_empty(prio_head)) { |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 271 | cur = prio_head->next; |
Stanislaw Gruszka | 51b98ef | 2014-02-08 23:18:43 +0100 | [diff] [blame] | 272 | goto out; |
| 273 | } |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 274 | |
| 275 | smp_mb(); |
| 276 | if (!list_empty(&worker->prio_pending)) |
| 277 | goto refill; |
| 278 | |
Stanislaw Gruszka | 51b98ef | 2014-02-08 23:18:43 +0100 | [diff] [blame] | 279 | if (!list_empty(head)) { |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 280 | cur = head->next; |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 281 | goto out; |
Stanislaw Gruszka | 51b98ef | 2014-02-08 23:18:43 +0100 | [diff] [blame] | 282 | } |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 283 | |
| 284 | refill: |
| 285 | spin_lock_irq(&worker->lock); |
| 286 | list_splice_tail_init(&worker->prio_pending, prio_head); |
| 287 | list_splice_tail_init(&worker->pending, head); |
| 288 | |
| 289 | if (!list_empty(prio_head)) |
| 290 | cur = prio_head->next; |
| 291 | else if (!list_empty(head)) |
| 292 | cur = head->next; |
| 293 | spin_unlock_irq(&worker->lock); |
| 294 | |
| 295 | if (!cur) |
| 296 | goto out_fail; |
| 297 | |
| 298 | out: |
| 299 | work = list_entry(cur, struct btrfs_work, list); |
| 300 | |
| 301 | out_fail: |
| 302 | return work; |
| 303 | } |
| 304 | |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 305 | /* |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 306 | * main loop for servicing work items |
| 307 | */ |
| 308 | static int worker_loop(void *arg) |
| 309 | { |
| 310 | struct btrfs_worker_thread *worker = arg; |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 311 | struct list_head head; |
| 312 | struct list_head prio_head; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 313 | struct btrfs_work *work; |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 314 | |
| 315 | INIT_LIST_HEAD(&head); |
| 316 | INIT_LIST_HEAD(&prio_head); |
| 317 | |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 318 | do { |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 319 | again: |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 320 | while (1) { |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 321 | |
| 322 | |
| 323 | work = get_next_work(worker, &prio_head, &head); |
| 324 | if (!work) |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 325 | break; |
| 326 | |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 327 | list_del(&work->list); |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 328 | clear_bit(WORK_QUEUED_BIT, &work->flags); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 329 | |
| 330 | work->worker = worker; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 331 | |
| 332 | work->func(work); |
| 333 | |
| 334 | atomic_dec(&worker->num_pending); |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 335 | /* |
| 336 | * unless this is an ordered work queue, |
| 337 | * 'work' was probably freed by func above. |
| 338 | */ |
| 339 | run_ordered_completions(worker->workers, work); |
| 340 | |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 341 | check_pending_worker_creates(worker); |
Chris Mason | 8f3b65a | 2011-12-15 09:29:43 -0500 | [diff] [blame] | 342 | cond_resched(); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 343 | } |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 344 | |
| 345 | spin_lock_irq(&worker->lock); |
| 346 | check_idle_worker(worker); |
| 347 | |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 348 | if (freezing(current)) { |
Chris Mason | b51912c | 2009-02-04 09:23:24 -0500 | [diff] [blame] | 349 | worker->working = 0; |
| 350 | spin_unlock_irq(&worker->lock); |
Tejun Heo | a0acae0 | 2011-11-21 12:32:22 -0800 | [diff] [blame] | 351 | try_to_freeze(); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 352 | } else { |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 353 | spin_unlock_irq(&worker->lock); |
Chris Mason | b51912c | 2009-02-04 09:23:24 -0500 | [diff] [blame] | 354 | if (!kthread_should_stop()) { |
| 355 | cpu_relax(); |
| 356 | /* |
| 357 | * we've dropped the lock, did someone else |
| 358 | * jump_in? |
| 359 | */ |
| 360 | smp_mb(); |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 361 | if (!list_empty(&worker->pending) || |
| 362 | !list_empty(&worker->prio_pending)) |
Chris Mason | b51912c | 2009-02-04 09:23:24 -0500 | [diff] [blame] | 363 | continue; |
| 364 | |
| 365 | /* |
| 366 | * this short schedule allows more work to |
| 367 | * come in without the queue functions |
| 368 | * needing to go through wake_up_process() |
| 369 | * |
| 370 | * worker->working is still 1, so nobody |
| 371 | * is going to try and wake us up |
| 372 | */ |
| 373 | schedule_timeout(1); |
| 374 | smp_mb(); |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 375 | if (!list_empty(&worker->pending) || |
| 376 | !list_empty(&worker->prio_pending)) |
Chris Mason | b51912c | 2009-02-04 09:23:24 -0500 | [diff] [blame] | 377 | continue; |
| 378 | |
Amit Gud | b5555f7 | 2009-04-02 17:01:27 -0400 | [diff] [blame] | 379 | if (kthread_should_stop()) |
| 380 | break; |
| 381 | |
Chris Mason | b51912c | 2009-02-04 09:23:24 -0500 | [diff] [blame] | 382 | /* still no more work?, sleep for real */ |
| 383 | spin_lock_irq(&worker->lock); |
| 384 | set_current_state(TASK_INTERRUPTIBLE); |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 385 | if (!list_empty(&worker->pending) || |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 386 | !list_empty(&worker->prio_pending)) { |
| 387 | spin_unlock_irq(&worker->lock); |
Chris Mason | ed3b3d314 | 2010-05-25 10:12:41 -0400 | [diff] [blame] | 388 | set_current_state(TASK_RUNNING); |
Chris Mason | 4f878e8 | 2009-08-07 09:27:38 -0400 | [diff] [blame] | 389 | goto again; |
| 390 | } |
Chris Mason | b51912c | 2009-02-04 09:23:24 -0500 | [diff] [blame] | 391 | |
| 392 | /* |
| 393 | * this makes sure we get a wakeup when someone |
| 394 | * adds something new to the queue |
| 395 | */ |
| 396 | worker->working = 0; |
| 397 | spin_unlock_irq(&worker->lock); |
| 398 | |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 399 | if (!kthread_should_stop()) { |
| 400 | schedule_timeout(HZ * 120); |
| 401 | if (!worker->working && |
| 402 | try_worker_shutdown(worker)) { |
| 403 | return 0; |
| 404 | } |
| 405 | } |
Chris Mason | b51912c | 2009-02-04 09:23:24 -0500 | [diff] [blame] | 406 | } |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 407 | __set_current_state(TASK_RUNNING); |
| 408 | } |
| 409 | } while (!kthread_should_stop()); |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * this will wait for all the worker threads to shutdown |
| 415 | */ |
Jeff Mahoney | 143bede | 2012-03-01 14:56:26 +0100 | [diff] [blame] | 416 | void btrfs_stop_workers(struct btrfs_workers *workers) |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 417 | { |
| 418 | struct list_head *cur; |
| 419 | struct btrfs_worker_thread *worker; |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 420 | int can_stop; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 421 | |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 422 | spin_lock_irq(&workers->lock); |
Ilya Dryomov | 964fb15a | 2013-10-02 19:39:50 +0300 | [diff] [blame] | 423 | workers->stopping = 1; |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 424 | list_splice_init(&workers->idle_list, &workers->worker_list); |
Chris Mason | d397712 | 2009-01-05 21:25:51 -0500 | [diff] [blame] | 425 | while (!list_empty(&workers->worker_list)) { |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 426 | cur = workers->worker_list.next; |
| 427 | worker = list_entry(cur, struct btrfs_worker_thread, |
| 428 | worker_list); |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 429 | |
| 430 | atomic_inc(&worker->refs); |
| 431 | workers->num_workers -= 1; |
| 432 | if (!list_empty(&worker->worker_list)) { |
| 433 | list_del_init(&worker->worker_list); |
| 434 | put_worker(worker); |
| 435 | can_stop = 1; |
| 436 | } else |
| 437 | can_stop = 0; |
| 438 | spin_unlock_irq(&workers->lock); |
| 439 | if (can_stop) |
| 440 | kthread_stop(worker->task); |
| 441 | spin_lock_irq(&workers->lock); |
| 442 | put_worker(worker); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 443 | } |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 444 | spin_unlock_irq(&workers->lock); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /* |
| 448 | * simple init on struct btrfs_workers |
| 449 | */ |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 450 | void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max, |
| 451 | struct btrfs_workers *async_helper) |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 452 | { |
| 453 | workers->num_workers = 0; |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 454 | workers->num_workers_starting = 0; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 455 | INIT_LIST_HEAD(&workers->worker_list); |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 456 | INIT_LIST_HEAD(&workers->idle_list); |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 457 | INIT_LIST_HEAD(&workers->order_list); |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 458 | INIT_LIST_HEAD(&workers->prio_order_list); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 459 | spin_lock_init(&workers->lock); |
Chris Mason | 4e3f9c5 | 2009-08-05 16:36:45 -0400 | [diff] [blame] | 460 | spin_lock_init(&workers->order_lock); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 461 | workers->max_workers = max; |
Chris Mason | 61b4944 | 2008-07-31 15:42:53 -0400 | [diff] [blame] | 462 | workers->idle_thresh = 32; |
Chris Mason | 5443be4 | 2008-08-15 15:34:16 -0400 | [diff] [blame] | 463 | workers->name = name; |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 464 | workers->ordered = 0; |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 465 | workers->atomic_start_pending = 0; |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 466 | workers->atomic_worker_start = async_helper; |
Ilya Dryomov | 964fb15a | 2013-10-02 19:39:50 +0300 | [diff] [blame] | 467 | workers->stopping = 0; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /* |
| 471 | * starts new worker threads. This does not enforce the max worker |
| 472 | * count in case you need to temporarily go past it. |
| 473 | */ |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 474 | static int __btrfs_start_workers(struct btrfs_workers *workers) |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 475 | { |
| 476 | struct btrfs_worker_thread *worker; |
| 477 | int ret = 0; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 478 | |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 479 | worker = kzalloc(sizeof(*worker), GFP_NOFS); |
| 480 | if (!worker) { |
| 481 | ret = -ENOMEM; |
| 482 | goto fail; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 483 | } |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 484 | |
| 485 | INIT_LIST_HEAD(&worker->pending); |
| 486 | INIT_LIST_HEAD(&worker->prio_pending); |
| 487 | INIT_LIST_HEAD(&worker->worker_list); |
| 488 | spin_lock_init(&worker->lock); |
| 489 | |
| 490 | atomic_set(&worker->num_pending, 0); |
| 491 | atomic_set(&worker->refs, 1); |
| 492 | worker->workers = workers; |
Ilya Dryomov | 964fb15a | 2013-10-02 19:39:50 +0300 | [diff] [blame] | 493 | worker->task = kthread_create(worker_loop, worker, |
| 494 | "btrfs-%s-%d", workers->name, |
| 495 | workers->num_workers + 1); |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 496 | if (IS_ERR(worker->task)) { |
| 497 | ret = PTR_ERR(worker->task); |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 498 | goto fail; |
| 499 | } |
Ilya Dryomov | 964fb15a | 2013-10-02 19:39:50 +0300 | [diff] [blame] | 500 | |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 501 | spin_lock_irq(&workers->lock); |
Ilya Dryomov | 964fb15a | 2013-10-02 19:39:50 +0300 | [diff] [blame] | 502 | if (workers->stopping) { |
| 503 | spin_unlock_irq(&workers->lock); |
Ilya Dryomov | ba69994 | 2013-11-03 19:06:40 +0200 | [diff] [blame] | 504 | ret = -EINVAL; |
Ilya Dryomov | 964fb15a | 2013-10-02 19:39:50 +0300 | [diff] [blame] | 505 | goto fail_kthread; |
| 506 | } |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 507 | list_add_tail(&worker->worker_list, &workers->idle_list); |
| 508 | worker->idle = 1; |
| 509 | workers->num_workers++; |
| 510 | workers->num_workers_starting--; |
| 511 | WARN_ON(workers->num_workers_starting < 0); |
| 512 | spin_unlock_irq(&workers->lock); |
| 513 | |
Ilya Dryomov | 964fb15a | 2013-10-02 19:39:50 +0300 | [diff] [blame] | 514 | wake_up_process(worker->task); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 515 | return 0; |
Ilya Dryomov | 964fb15a | 2013-10-02 19:39:50 +0300 | [diff] [blame] | 516 | |
| 517 | fail_kthread: |
| 518 | kthread_stop(worker->task); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 519 | fail: |
Ilya Dryomov | 964fb15a | 2013-10-02 19:39:50 +0300 | [diff] [blame] | 520 | kfree(worker); |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 521 | spin_lock_irq(&workers->lock); |
| 522 | workers->num_workers_starting--; |
| 523 | spin_unlock_irq(&workers->lock); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 524 | return ret; |
| 525 | } |
| 526 | |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 527 | int btrfs_start_workers(struct btrfs_workers *workers) |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 528 | { |
| 529 | spin_lock_irq(&workers->lock); |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 530 | workers->num_workers_starting++; |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 531 | spin_unlock_irq(&workers->lock); |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 532 | return __btrfs_start_workers(workers); |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 533 | } |
| 534 | |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 535 | /* |
| 536 | * run through the list and find a worker thread that doesn't have a lot |
| 537 | * to do right now. This can return null if we aren't yet at the thread |
| 538 | * count limit and all of the threads are busy. |
| 539 | */ |
| 540 | static struct btrfs_worker_thread *next_worker(struct btrfs_workers *workers) |
| 541 | { |
| 542 | struct btrfs_worker_thread *worker; |
| 543 | struct list_head *next; |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 544 | int enforce_min; |
| 545 | |
| 546 | enforce_min = (workers->num_workers + workers->num_workers_starting) < |
| 547 | workers->max_workers; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 548 | |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 549 | /* |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 550 | * if we find an idle thread, don't move it to the end of the |
| 551 | * idle list. This improves the chance that the next submission |
| 552 | * will reuse the same thread, and maybe catch it while it is still |
| 553 | * working |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 554 | */ |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 555 | if (!list_empty(&workers->idle_list)) { |
| 556 | next = workers->idle_list.next; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 557 | worker = list_entry(next, struct btrfs_worker_thread, |
| 558 | worker_list); |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 559 | return worker; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 560 | } |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 561 | if (enforce_min || list_empty(&workers->worker_list)) |
| 562 | return NULL; |
| 563 | |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 564 | /* |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 565 | * if we pick a busy task, move the task to the end of the list. |
Chris Mason | d352ac6 | 2008-09-29 15:18:18 -0400 | [diff] [blame] | 566 | * hopefully this will keep things somewhat evenly balanced. |
| 567 | * Do the move in batches based on the sequence number. This groups |
| 568 | * requests submitted at roughly the same time onto the same worker. |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 569 | */ |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 570 | next = workers->worker_list.next; |
| 571 | worker = list_entry(next, struct btrfs_worker_thread, worker_list); |
Chris Mason | 4854ddd | 2008-08-15 15:34:17 -0400 | [diff] [blame] | 572 | worker->sequence++; |
Chris Mason | d352ac6 | 2008-09-29 15:18:18 -0400 | [diff] [blame] | 573 | |
Chris Mason | 5386323 | 2008-08-15 15:34:18 -0400 | [diff] [blame] | 574 | if (worker->sequence % workers->idle_thresh == 0) |
Chris Mason | 4854ddd | 2008-08-15 15:34:17 -0400 | [diff] [blame] | 575 | list_move_tail(next, &workers->worker_list); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 576 | return worker; |
| 577 | } |
| 578 | |
Chris Mason | d352ac6 | 2008-09-29 15:18:18 -0400 | [diff] [blame] | 579 | /* |
| 580 | * selects a worker thread to take the next job. This will either find |
| 581 | * an idle worker, start a new worker up to the max count, or just return |
| 582 | * one of the existing busy workers. |
| 583 | */ |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 584 | static struct btrfs_worker_thread *find_worker(struct btrfs_workers *workers) |
| 585 | { |
| 586 | struct btrfs_worker_thread *worker; |
| 587 | unsigned long flags; |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 588 | struct list_head *fallback; |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 589 | int ret; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 590 | |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 591 | spin_lock_irqsave(&workers->lock, flags); |
Chris Mason | 8d532b2 | 2011-12-23 07:53:00 -0500 | [diff] [blame] | 592 | again: |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 593 | worker = next_worker(workers); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 594 | |
| 595 | if (!worker) { |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 596 | if (workers->num_workers + workers->num_workers_starting >= |
| 597 | workers->max_workers) { |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 598 | goto fallback; |
| 599 | } else if (workers->atomic_worker_start) { |
| 600 | workers->atomic_start_pending = 1; |
| 601 | goto fallback; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 602 | } else { |
Chris Mason | 61d92c3 | 2009-10-02 19:11:56 -0400 | [diff] [blame] | 603 | workers->num_workers_starting++; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 604 | spin_unlock_irqrestore(&workers->lock, flags); |
| 605 | /* we're below the limit, start another worker */ |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 606 | ret = __btrfs_start_workers(workers); |
Chris Mason | 8d532b2 | 2011-12-23 07:53:00 -0500 | [diff] [blame] | 607 | spin_lock_irqsave(&workers->lock, flags); |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 608 | if (ret) |
| 609 | goto fallback; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 610 | goto again; |
| 611 | } |
| 612 | } |
Chris Mason | 6e74057 | 2009-09-15 20:02:33 -0400 | [diff] [blame] | 613 | goto found; |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 614 | |
| 615 | fallback: |
| 616 | fallback = NULL; |
| 617 | /* |
| 618 | * we have failed to find any workers, just |
| 619 | * return the first one we can find. |
| 620 | */ |
| 621 | if (!list_empty(&workers->worker_list)) |
| 622 | fallback = workers->worker_list.next; |
| 623 | if (!list_empty(&workers->idle_list)) |
| 624 | fallback = workers->idle_list.next; |
| 625 | BUG_ON(!fallback); |
| 626 | worker = list_entry(fallback, |
| 627 | struct btrfs_worker_thread, worker_list); |
Chris Mason | 6e74057 | 2009-09-15 20:02:33 -0400 | [diff] [blame] | 628 | found: |
| 629 | /* |
| 630 | * this makes sure the worker doesn't exit before it is placed |
| 631 | * onto a busy/idle list |
| 632 | */ |
| 633 | atomic_inc(&worker->num_pending); |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 634 | spin_unlock_irqrestore(&workers->lock, flags); |
| 635 | return worker; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | /* |
| 639 | * btrfs_requeue_work just puts the work item back on the tail of the list |
| 640 | * it was taken from. It is intended for use with long running work functions |
| 641 | * that make some progress and want to give the cpu up for others. |
| 642 | */ |
Jeff Mahoney | 143bede | 2012-03-01 14:56:26 +0100 | [diff] [blame] | 643 | void btrfs_requeue_work(struct btrfs_work *work) |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 644 | { |
| 645 | struct btrfs_worker_thread *worker = work->worker; |
| 646 | unsigned long flags; |
Chris Mason | a683705 | 2009-02-04 09:19:41 -0500 | [diff] [blame] | 647 | int wake = 0; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 648 | |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 649 | if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags)) |
Jeff Mahoney | 143bede | 2012-03-01 14:56:26 +0100 | [diff] [blame] | 650 | return; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 651 | |
| 652 | spin_lock_irqsave(&worker->lock, flags); |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 653 | if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags)) |
| 654 | list_add_tail(&work->list, &worker->prio_pending); |
| 655 | else |
| 656 | list_add_tail(&work->list, &worker->pending); |
Chris Mason | b51912c | 2009-02-04 09:23:24 -0500 | [diff] [blame] | 657 | atomic_inc(&worker->num_pending); |
Chris Mason | 75ccf47 | 2008-09-30 19:24:06 -0400 | [diff] [blame] | 658 | |
| 659 | /* by definition we're busy, take ourselves off the idle |
| 660 | * list |
| 661 | */ |
| 662 | if (worker->idle) { |
Julia Lawall | 29c5e8c | 2009-07-22 16:49:00 -0400 | [diff] [blame] | 663 | spin_lock(&worker->workers->lock); |
Chris Mason | 75ccf47 | 2008-09-30 19:24:06 -0400 | [diff] [blame] | 664 | worker->idle = 0; |
| 665 | list_move_tail(&worker->worker_list, |
Chris Mason | 6e74057 | 2009-09-15 20:02:33 -0400 | [diff] [blame] | 666 | &worker->workers->worker_list); |
Julia Lawall | 29c5e8c | 2009-07-22 16:49:00 -0400 | [diff] [blame] | 667 | spin_unlock(&worker->workers->lock); |
Chris Mason | 75ccf47 | 2008-09-30 19:24:06 -0400 | [diff] [blame] | 668 | } |
Chris Mason | a683705 | 2009-02-04 09:19:41 -0500 | [diff] [blame] | 669 | if (!worker->working) { |
| 670 | wake = 1; |
| 671 | worker->working = 1; |
| 672 | } |
Chris Mason | 75ccf47 | 2008-09-30 19:24:06 -0400 | [diff] [blame] | 673 | |
Chris Mason | a683705 | 2009-02-04 09:19:41 -0500 | [diff] [blame] | 674 | if (wake) |
| 675 | wake_up_process(worker->task); |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 676 | spin_unlock_irqrestore(&worker->lock, flags); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 677 | } |
| 678 | |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 679 | void btrfs_set_work_high_prio(struct btrfs_work *work) |
| 680 | { |
| 681 | set_bit(WORK_HIGH_PRIO_BIT, &work->flags); |
| 682 | } |
| 683 | |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 684 | /* |
| 685 | * places a struct btrfs_work into the pending queue of one of the kthreads |
| 686 | */ |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 687 | void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work) |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 688 | { |
| 689 | struct btrfs_worker_thread *worker; |
| 690 | unsigned long flags; |
| 691 | int wake = 0; |
| 692 | |
| 693 | /* don't requeue something already on a list */ |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 694 | if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags)) |
Josef Bacik | 0dc3b84 | 2011-11-18 14:37:27 -0500 | [diff] [blame] | 695 | return; |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 696 | |
| 697 | worker = find_worker(workers); |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 698 | if (workers->ordered) { |
Chris Mason | 4e3f9c5 | 2009-08-05 16:36:45 -0400 | [diff] [blame] | 699 | /* |
| 700 | * you're not allowed to do ordered queues from an |
| 701 | * interrupt handler |
| 702 | */ |
| 703 | spin_lock(&workers->order_lock); |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 704 | if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags)) { |
| 705 | list_add_tail(&work->order_list, |
| 706 | &workers->prio_order_list); |
| 707 | } else { |
| 708 | list_add_tail(&work->order_list, &workers->order_list); |
| 709 | } |
Chris Mason | 4e3f9c5 | 2009-08-05 16:36:45 -0400 | [diff] [blame] | 710 | spin_unlock(&workers->order_lock); |
Chris Mason | 4a69a41 | 2008-11-06 22:03:00 -0500 | [diff] [blame] | 711 | } else { |
| 712 | INIT_LIST_HEAD(&work->order_list); |
| 713 | } |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 714 | |
| 715 | spin_lock_irqsave(&worker->lock, flags); |
Chris Mason | a683705 | 2009-02-04 09:19:41 -0500 | [diff] [blame] | 716 | |
Chris Mason | d313d7a | 2009-04-20 15:50:09 -0400 | [diff] [blame] | 717 | if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags)) |
| 718 | list_add_tail(&work->list, &worker->prio_pending); |
| 719 | else |
| 720 | list_add_tail(&work->list, &worker->pending); |
Chris Mason | 35d8ba6 | 2008-06-11 20:21:24 -0400 | [diff] [blame] | 721 | check_busy_worker(worker); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 722 | |
| 723 | /* |
| 724 | * avoid calling into wake_up_process if this thread has already |
| 725 | * been kicked |
| 726 | */ |
| 727 | if (!worker->working) |
| 728 | wake = 1; |
| 729 | worker->working = 1; |
| 730 | |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 731 | if (wake) |
| 732 | wake_up_process(worker->task); |
Chris Mason | 9042846 | 2009-08-04 16:56:34 -0400 | [diff] [blame] | 733 | spin_unlock_irqrestore(&worker->lock, flags); |
Chris Mason | 8b71284 | 2008-06-11 16:50:36 -0400 | [diff] [blame] | 734 | } |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 735 | |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 736 | struct __btrfs_workqueue_struct { |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 737 | struct workqueue_struct *normal_wq; |
| 738 | /* List head pointing to ordered work list */ |
| 739 | struct list_head ordered_list; |
| 740 | |
| 741 | /* Spinlock for ordered_list */ |
| 742 | spinlock_t list_lock; |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 743 | |
| 744 | /* Thresholding related variants */ |
| 745 | atomic_t pending; |
| 746 | int max_active; |
| 747 | int current_max; |
| 748 | int thresh; |
| 749 | unsigned int count; |
| 750 | spinlock_t thres_lock; |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 751 | }; |
| 752 | |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 753 | struct btrfs_workqueue_struct { |
| 754 | struct __btrfs_workqueue_struct *normal; |
| 755 | struct __btrfs_workqueue_struct *high; |
| 756 | }; |
| 757 | |
| 758 | static inline struct __btrfs_workqueue_struct |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 759 | *__btrfs_alloc_workqueue(char *name, int flags, int max_active, int thresh) |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 760 | { |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 761 | struct __btrfs_workqueue_struct *ret = kzalloc(sizeof(*ret), GFP_NOFS); |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 762 | |
| 763 | if (unlikely(!ret)) |
| 764 | return NULL; |
| 765 | |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 766 | ret->max_active = max_active; |
| 767 | atomic_set(&ret->pending, 0); |
| 768 | if (thresh == 0) |
| 769 | thresh = DFT_THRESHOLD; |
| 770 | /* For low threshold, disabling threshold is a better choice */ |
| 771 | if (thresh < DFT_THRESHOLD) { |
| 772 | ret->current_max = max_active; |
| 773 | ret->thresh = NO_THRESHOLD; |
| 774 | } else { |
| 775 | ret->current_max = 1; |
| 776 | ret->thresh = thresh; |
| 777 | } |
| 778 | |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 779 | if (flags & WQ_HIGHPRI) |
| 780 | ret->normal_wq = alloc_workqueue("%s-%s-high", flags, |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 781 | ret->max_active, |
| 782 | "btrfs", name); |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 783 | else |
| 784 | ret->normal_wq = alloc_workqueue("%s-%s", flags, |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 785 | ret->max_active, "btrfs", |
| 786 | name); |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 787 | if (unlikely(!ret->normal_wq)) { |
| 788 | kfree(ret); |
| 789 | return NULL; |
| 790 | } |
| 791 | |
| 792 | INIT_LIST_HEAD(&ret->ordered_list); |
| 793 | spin_lock_init(&ret->list_lock); |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 794 | spin_lock_init(&ret->thres_lock); |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 795 | return ret; |
| 796 | } |
| 797 | |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 798 | static inline void |
| 799 | __btrfs_destroy_workqueue(struct __btrfs_workqueue_struct *wq); |
| 800 | |
| 801 | struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name, |
| 802 | int flags, |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 803 | int max_active, |
| 804 | int thresh) |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 805 | { |
| 806 | struct btrfs_workqueue_struct *ret = kzalloc(sizeof(*ret), GFP_NOFS); |
| 807 | |
| 808 | if (unlikely(!ret)) |
| 809 | return NULL; |
| 810 | |
| 811 | ret->normal = __btrfs_alloc_workqueue(name, flags & ~WQ_HIGHPRI, |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 812 | max_active, thresh); |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 813 | if (unlikely(!ret->normal)) { |
| 814 | kfree(ret); |
| 815 | return NULL; |
| 816 | } |
| 817 | |
| 818 | if (flags & WQ_HIGHPRI) { |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 819 | ret->high = __btrfs_alloc_workqueue(name, flags, max_active, |
| 820 | thresh); |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 821 | if (unlikely(!ret->high)) { |
| 822 | __btrfs_destroy_workqueue(ret->normal); |
| 823 | kfree(ret); |
| 824 | return NULL; |
| 825 | } |
| 826 | } |
| 827 | return ret; |
| 828 | } |
| 829 | |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 830 | /* |
| 831 | * Hook for threshold which will be called in btrfs_queue_work. |
| 832 | * This hook WILL be called in IRQ handler context, |
| 833 | * so workqueue_set_max_active MUST NOT be called in this hook |
| 834 | */ |
| 835 | static inline void thresh_queue_hook(struct __btrfs_workqueue_struct *wq) |
| 836 | { |
| 837 | if (wq->thresh == NO_THRESHOLD) |
| 838 | return; |
| 839 | atomic_inc(&wq->pending); |
| 840 | } |
| 841 | |
| 842 | /* |
| 843 | * Hook for threshold which will be called before executing the work, |
| 844 | * This hook is called in kthread content. |
| 845 | * So workqueue_set_max_active is called here. |
| 846 | */ |
| 847 | static inline void thresh_exec_hook(struct __btrfs_workqueue_struct *wq) |
| 848 | { |
| 849 | int new_max_active; |
| 850 | long pending; |
| 851 | int need_change = 0; |
| 852 | |
| 853 | if (wq->thresh == NO_THRESHOLD) |
| 854 | return; |
| 855 | |
| 856 | atomic_dec(&wq->pending); |
| 857 | spin_lock(&wq->thres_lock); |
| 858 | /* |
| 859 | * Use wq->count to limit the calling frequency of |
| 860 | * workqueue_set_max_active. |
| 861 | */ |
| 862 | wq->count++; |
| 863 | wq->count %= (wq->thresh / 4); |
| 864 | if (!wq->count) |
| 865 | goto out; |
| 866 | new_max_active = wq->current_max; |
| 867 | |
| 868 | /* |
| 869 | * pending may be changed later, but it's OK since we really |
| 870 | * don't need it so accurate to calculate new_max_active. |
| 871 | */ |
| 872 | pending = atomic_read(&wq->pending); |
| 873 | if (pending > wq->thresh) |
| 874 | new_max_active++; |
| 875 | if (pending < wq->thresh / 2) |
| 876 | new_max_active--; |
| 877 | new_max_active = clamp_val(new_max_active, 1, wq->max_active); |
| 878 | if (new_max_active != wq->current_max) { |
| 879 | need_change = 1; |
| 880 | wq->current_max = new_max_active; |
| 881 | } |
| 882 | out: |
| 883 | spin_unlock(&wq->thres_lock); |
| 884 | |
| 885 | if (need_change) { |
| 886 | workqueue_set_max_active(wq->normal_wq, wq->current_max); |
| 887 | } |
| 888 | } |
| 889 | |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 890 | static void run_ordered_work(struct __btrfs_workqueue_struct *wq) |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 891 | { |
| 892 | struct list_head *list = &wq->ordered_list; |
| 893 | struct btrfs_work_struct *work; |
| 894 | spinlock_t *lock = &wq->list_lock; |
| 895 | unsigned long flags; |
| 896 | |
| 897 | while (1) { |
| 898 | spin_lock_irqsave(lock, flags); |
| 899 | if (list_empty(list)) |
| 900 | break; |
| 901 | work = list_entry(list->next, struct btrfs_work_struct, |
| 902 | ordered_list); |
| 903 | if (!test_bit(WORK_DONE_BIT, &work->flags)) |
| 904 | break; |
| 905 | |
| 906 | /* |
| 907 | * we are going to call the ordered done function, but |
| 908 | * we leave the work item on the list as a barrier so |
| 909 | * that later work items that are done don't have their |
| 910 | * functions called before this one returns |
| 911 | */ |
| 912 | if (test_and_set_bit(WORK_ORDER_DONE_BIT, &work->flags)) |
| 913 | break; |
| 914 | spin_unlock_irqrestore(lock, flags); |
| 915 | work->ordered_func(work); |
| 916 | |
| 917 | /* now take the lock again and drop our item from the list */ |
| 918 | spin_lock_irqsave(lock, flags); |
| 919 | list_del(&work->ordered_list); |
| 920 | spin_unlock_irqrestore(lock, flags); |
| 921 | |
| 922 | /* |
| 923 | * we don't want to call the ordered free functions |
| 924 | * with the lock held though |
| 925 | */ |
| 926 | work->ordered_free(work); |
| 927 | } |
| 928 | spin_unlock_irqrestore(lock, flags); |
| 929 | } |
| 930 | |
| 931 | static void normal_work_helper(struct work_struct *arg) |
| 932 | { |
| 933 | struct btrfs_work_struct *work; |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 934 | struct __btrfs_workqueue_struct *wq; |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 935 | int need_order = 0; |
| 936 | |
| 937 | work = container_of(arg, struct btrfs_work_struct, normal_work); |
| 938 | /* |
| 939 | * We should not touch things inside work in the following cases: |
| 940 | * 1) after work->func() if it has no ordered_free |
| 941 | * Since the struct is freed in work->func(). |
| 942 | * 2) after setting WORK_DONE_BIT |
| 943 | * The work may be freed in other threads almost instantly. |
| 944 | * So we save the needed things here. |
| 945 | */ |
| 946 | if (work->ordered_func) |
| 947 | need_order = 1; |
| 948 | wq = work->wq; |
| 949 | |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 950 | thresh_exec_hook(wq); |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 951 | work->func(work); |
| 952 | if (need_order) { |
| 953 | set_bit(WORK_DONE_BIT, &work->flags); |
| 954 | run_ordered_work(wq); |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | void btrfs_init_work(struct btrfs_work_struct *work, |
| 959 | void (*func)(struct btrfs_work_struct *), |
| 960 | void (*ordered_func)(struct btrfs_work_struct *), |
| 961 | void (*ordered_free)(struct btrfs_work_struct *)) |
| 962 | { |
| 963 | work->func = func; |
| 964 | work->ordered_func = ordered_func; |
| 965 | work->ordered_free = ordered_free; |
| 966 | INIT_WORK(&work->normal_work, normal_work_helper); |
| 967 | INIT_LIST_HEAD(&work->ordered_list); |
| 968 | work->flags = 0; |
| 969 | } |
| 970 | |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 971 | static inline void __btrfs_queue_work(struct __btrfs_workqueue_struct *wq, |
| 972 | struct btrfs_work_struct *work) |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 973 | { |
| 974 | unsigned long flags; |
| 975 | |
| 976 | work->wq = wq; |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 977 | thresh_queue_hook(wq); |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 978 | if (work->ordered_func) { |
| 979 | spin_lock_irqsave(&wq->list_lock, flags); |
| 980 | list_add_tail(&work->ordered_list, &wq->ordered_list); |
| 981 | spin_unlock_irqrestore(&wq->list_lock, flags); |
| 982 | } |
| 983 | queue_work(wq->normal_wq, &work->normal_work); |
| 984 | } |
| 985 | |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 986 | void btrfs_queue_work(struct btrfs_workqueue_struct *wq, |
| 987 | struct btrfs_work_struct *work) |
| 988 | { |
| 989 | struct __btrfs_workqueue_struct *dest_wq; |
| 990 | |
| 991 | if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags) && wq->high) |
| 992 | dest_wq = wq->high; |
| 993 | else |
| 994 | dest_wq = wq->normal; |
| 995 | __btrfs_queue_work(dest_wq, work); |
| 996 | } |
| 997 | |
| 998 | static inline void |
| 999 | __btrfs_destroy_workqueue(struct __btrfs_workqueue_struct *wq) |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 1000 | { |
| 1001 | destroy_workqueue(wq->normal_wq); |
| 1002 | kfree(wq); |
| 1003 | } |
| 1004 | |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 1005 | void btrfs_destroy_workqueue(struct btrfs_workqueue_struct *wq) |
| 1006 | { |
| 1007 | if (!wq) |
| 1008 | return; |
| 1009 | if (wq->high) |
| 1010 | __btrfs_destroy_workqueue(wq->high); |
| 1011 | __btrfs_destroy_workqueue(wq->normal); |
| 1012 | } |
| 1013 | |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 1014 | void btrfs_workqueue_set_max(struct btrfs_workqueue_struct *wq, int max) |
| 1015 | { |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 1016 | wq->normal->max_active = max; |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 1017 | if (wq->high) |
Qu Wenruo | 0bd9289 | 2014-02-28 10:46:05 +0800 | [diff] [blame^] | 1018 | wq->high->max_active = max; |
Qu Wenruo | 1ca0897 | 2014-02-28 10:46:04 +0800 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | void btrfs_set_work_high_priority(struct btrfs_work_struct *work) |
| 1022 | { |
| 1023 | set_bit(WORK_HIGH_PRIO_BIT, &work->flags); |
Qu Wenruo | 08a9ff3 | 2014-02-28 10:46:03 +0800 | [diff] [blame] | 1024 | } |