aboutsummaryrefslogtreecommitdiffstats
path: root/mm/backing-dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/backing-dev.c')
-rw-r--r--mm/backing-dev.c454
1 files changed, 217 insertions, 237 deletions
diff --git a/mm/backing-dev.c b/mm/backing-dev.c
index 123bcef13e51..65d420499a61 100644
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -10,6 +10,7 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/writeback.h> 11#include <linux/writeback.h>
12#include <linux/device.h> 12#include <linux/device.h>
13#include <trace/events/writeback.h>
13 14
14static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0); 15static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
15 16
@@ -29,6 +30,7 @@ EXPORT_SYMBOL_GPL(default_backing_dev_info);
29 30
30struct backing_dev_info noop_backing_dev_info = { 31struct backing_dev_info noop_backing_dev_info = {
31 .name = "noop", 32 .name = "noop",
33 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
32}; 34};
33EXPORT_SYMBOL_GPL(noop_backing_dev_info); 35EXPORT_SYMBOL_GPL(noop_backing_dev_info);
34 36
@@ -49,8 +51,6 @@ static struct timer_list sync_supers_timer;
49static int bdi_sync_supers(void *); 51static int bdi_sync_supers(void *);
50static void sync_supers_timer_fn(unsigned long); 52static void sync_supers_timer_fn(unsigned long);
51 53
52static void bdi_add_default_flusher_task(struct backing_dev_info *bdi);
53
54#ifdef CONFIG_DEBUG_FS 54#ifdef CONFIG_DEBUG_FS
55#include <linux/debugfs.h> 55#include <linux/debugfs.h>
56#include <linux/seq_file.h> 56#include <linux/seq_file.h>
@@ -65,31 +65,25 @@ static void bdi_debug_init(void)
65static int bdi_debug_stats_show(struct seq_file *m, void *v) 65static int bdi_debug_stats_show(struct seq_file *m, void *v)
66{ 66{
67 struct backing_dev_info *bdi = m->private; 67 struct backing_dev_info *bdi = m->private;
68 struct bdi_writeback *wb; 68 struct bdi_writeback *wb = &bdi->wb;
69 unsigned long background_thresh; 69 unsigned long background_thresh;
70 unsigned long dirty_thresh; 70 unsigned long dirty_thresh;
71 unsigned long bdi_thresh; 71 unsigned long bdi_thresh;
72 unsigned long nr_dirty, nr_io, nr_more_io, nr_wb; 72 unsigned long nr_dirty, nr_io, nr_more_io, nr_wb;
73 struct inode *inode; 73 struct inode *inode;
74 74
75 /*
76 * inode lock is enough here, the bdi->wb_list is protected by
77 * RCU on the reader side
78 */
79 nr_wb = nr_dirty = nr_io = nr_more_io = 0; 75 nr_wb = nr_dirty = nr_io = nr_more_io = 0;
80 spin_lock(&inode_lock); 76 spin_lock(&inode_lock);
81 list_for_each_entry(wb, &bdi->wb_list, list) { 77 list_for_each_entry(inode, &wb->b_dirty, i_list)
82 nr_wb++; 78 nr_dirty++;
83 list_for_each_entry(inode, &wb->b_dirty, i_list) 79 list_for_each_entry(inode, &wb->b_io, i_list)
84 nr_dirty++; 80 nr_io++;
85 list_for_each_entry(inode, &wb->b_io, i_list) 81 list_for_each_entry(inode, &wb->b_more_io, i_list)
86 nr_io++; 82 nr_more_io++;
87 list_for_each_entry(inode, &wb->b_more_io, i_list)
88 nr_more_io++;
89 }
90 spin_unlock(&inode_lock); 83 spin_unlock(&inode_lock);
91 84
92 get_dirty_limits(&background_thresh, &dirty_thresh, &bdi_thresh, bdi); 85 global_dirty_limits(&background_thresh, &dirty_thresh);
86 bdi_thresh = bdi_dirty_limit(bdi, dirty_thresh);
93 87
94#define K(x) ((x) << (PAGE_SHIFT - 10)) 88#define K(x) ((x) << (PAGE_SHIFT - 10))
95 seq_printf(m, 89 seq_printf(m,
@@ -98,19 +92,16 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
98 "BdiDirtyThresh: %8lu kB\n" 92 "BdiDirtyThresh: %8lu kB\n"
99 "DirtyThresh: %8lu kB\n" 93 "DirtyThresh: %8lu kB\n"
100 "BackgroundThresh: %8lu kB\n" 94 "BackgroundThresh: %8lu kB\n"
101 "WritebackThreads: %8lu\n"
102 "b_dirty: %8lu\n" 95 "b_dirty: %8lu\n"
103 "b_io: %8lu\n" 96 "b_io: %8lu\n"
104 "b_more_io: %8lu\n" 97 "b_more_io: %8lu\n"
105 "bdi_list: %8u\n" 98 "bdi_list: %8u\n"
106 "state: %8lx\n" 99 "state: %8lx\n",
107 "wb_list: %8u\n",
108 (unsigned long) K(bdi_stat(bdi, BDI_WRITEBACK)), 100 (unsigned long) K(bdi_stat(bdi, BDI_WRITEBACK)),
109 (unsigned long) K(bdi_stat(bdi, BDI_RECLAIMABLE)), 101 (unsigned long) K(bdi_stat(bdi, BDI_RECLAIMABLE)),
110 K(bdi_thresh), K(dirty_thresh), 102 K(bdi_thresh), K(dirty_thresh),
111 K(background_thresh), nr_wb, nr_dirty, nr_io, nr_more_io, 103 K(background_thresh), nr_dirty, nr_io, nr_more_io,
112 !list_empty(&bdi->bdi_list), bdi->state, 104 !list_empty(&bdi->bdi_list), bdi->state);
113 !list_empty(&bdi->wb_list));
114#undef K 105#undef K
115 106
116 return 0; 107 return 0;
@@ -247,89 +238,18 @@ static int __init default_bdi_init(void)
247 sync_supers_tsk = kthread_run(bdi_sync_supers, NULL, "sync_supers"); 238 sync_supers_tsk = kthread_run(bdi_sync_supers, NULL, "sync_supers");
248 BUG_ON(IS_ERR(sync_supers_tsk)); 239 BUG_ON(IS_ERR(sync_supers_tsk));
249 240
250 init_timer(&sync_supers_timer);
251 setup_timer(&sync_supers_timer, sync_supers_timer_fn, 0); 241 setup_timer(&sync_supers_timer, sync_supers_timer_fn, 0);
252 bdi_arm_supers_timer(); 242 bdi_arm_supers_timer();
253 243
254 err = bdi_init(&default_backing_dev_info); 244 err = bdi_init(&default_backing_dev_info);
255 if (!err) 245 if (!err)
256 bdi_register(&default_backing_dev_info, NULL, "default"); 246 bdi_register(&default_backing_dev_info, NULL, "default");
247 err = bdi_init(&noop_backing_dev_info);
257 248
258 return err; 249 return err;
259} 250}
260subsys_initcall(default_bdi_init); 251subsys_initcall(default_bdi_init);
261 252
262static void bdi_wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi)
263{
264 memset(wb, 0, sizeof(*wb));
265
266 wb->bdi = bdi;
267 wb->last_old_flush = jiffies;
268 INIT_LIST_HEAD(&wb->b_dirty);
269 INIT_LIST_HEAD(&wb->b_io);
270 INIT_LIST_HEAD(&wb->b_more_io);
271}
272
273static void bdi_task_init(struct backing_dev_info *bdi,
274 struct bdi_writeback *wb)
275{
276 struct task_struct *tsk = current;
277
278 spin_lock(&bdi->wb_lock);
279 list_add_tail_rcu(&wb->list, &bdi->wb_list);
280 spin_unlock(&bdi->wb_lock);
281
282 tsk->flags |= PF_FLUSHER | PF_SWAPWRITE;
283 set_freezable();
284
285 /*
286 * Our parent may run at a different priority, just set us to normal
287 */
288 set_user_nice(tsk, 0);
289}
290
291static int bdi_start_fn(void *ptr)
292{
293 struct bdi_writeback *wb = ptr;
294 struct backing_dev_info *bdi = wb->bdi;
295 int ret;
296
297 /*
298 * Add us to the active bdi_list
299 */
300 spin_lock_bh(&bdi_lock);
301 list_add_rcu(&bdi->bdi_list, &bdi_list);
302 spin_unlock_bh(&bdi_lock);
303
304 bdi_task_init(bdi, wb);
305
306 /*
307 * Clear pending bit and wakeup anybody waiting to tear us down
308 */
309 clear_bit(BDI_pending, &bdi->state);
310 smp_mb__after_clear_bit();
311 wake_up_bit(&bdi->state, BDI_pending);
312
313 ret = bdi_writeback_task(wb);
314
315 /*
316 * Remove us from the list
317 */
318 spin_lock(&bdi->wb_lock);
319 list_del_rcu(&wb->list);
320 spin_unlock(&bdi->wb_lock);
321
322 /*
323 * Flush any work that raced with us exiting. No new work
324 * will be added, since this bdi isn't discoverable anymore.
325 */
326 if (!list_empty(&bdi->work_list))
327 wb_do_writeback(wb, 1);
328
329 wb->task = NULL;
330 return ret;
331}
332
333int bdi_has_dirty_io(struct backing_dev_info *bdi) 253int bdi_has_dirty_io(struct backing_dev_info *bdi)
334{ 254{
335 return wb_has_dirty_io(&bdi->wb); 255 return wb_has_dirty_io(&bdi->wb);
@@ -348,10 +268,10 @@ static void bdi_flush_io(struct backing_dev_info *bdi)
348} 268}
349 269
350/* 270/*
351 * kupdated() used to do this. We cannot do it from the bdi_forker_task() 271 * kupdated() used to do this. We cannot do it from the bdi_forker_thread()
352 * or we risk deadlocking on ->s_umount. The longer term solution would be 272 * or we risk deadlocking on ->s_umount. The longer term solution would be
353 * to implement sync_supers_bdi() or similar and simply do it from the 273 * to implement sync_supers_bdi() or similar and simply do it from the
354 * bdi writeback tasks individually. 274 * bdi writeback thread individually.
355 */ 275 */
356static int bdi_sync_supers(void *unused) 276static int bdi_sync_supers(void *unused)
357{ 277{
@@ -387,144 +307,201 @@ static void sync_supers_timer_fn(unsigned long unused)
387 bdi_arm_supers_timer(); 307 bdi_arm_supers_timer();
388} 308}
389 309
390static int bdi_forker_task(void *ptr) 310static void wakeup_timer_fn(unsigned long data)
311{
312 struct backing_dev_info *bdi = (struct backing_dev_info *)data;
313
314 spin_lock_bh(&bdi->wb_lock);
315 if (bdi->wb.task) {
316 trace_writeback_wake_thread(bdi);
317 wake_up_process(bdi->wb.task);
318 } else {
319 /*
320 * When bdi tasks are inactive for long time, they are killed.
321 * In this case we have to wake-up the forker thread which
322 * should create and run the bdi thread.
323 */
324 trace_writeback_wake_forker_thread(bdi);
325 wake_up_process(default_backing_dev_info.wb.task);
326 }
327 spin_unlock_bh(&bdi->wb_lock);
328}
329
330/*
331 * This function is used when the first inode for this bdi is marked dirty. It
332 * wakes-up the corresponding bdi thread which should then take care of the
333 * periodic background write-out of dirty inodes. Since the write-out would
334 * starts only 'dirty_writeback_interval' centisecs from now anyway, we just
335 * set up a timer which wakes the bdi thread up later.
336 *
337 * Note, we wouldn't bother setting up the timer, but this function is on the
338 * fast-path (used by '__mark_inode_dirty()'), so we save few context switches
339 * by delaying the wake-up.
340 */
341void bdi_wakeup_thread_delayed(struct backing_dev_info *bdi)
342{
343 unsigned long timeout;
344
345 timeout = msecs_to_jiffies(dirty_writeback_interval * 10);
346 mod_timer(&bdi->wb.wakeup_timer, jiffies + timeout);
347}
348
349/*
350 * Calculate the longest interval (jiffies) bdi threads are allowed to be
351 * inactive.
352 */
353static unsigned long bdi_longest_inactive(void)
354{
355 unsigned long interval;
356
357 interval = msecs_to_jiffies(dirty_writeback_interval * 10);
358 return max(5UL * 60 * HZ, interval);
359}
360
361static int bdi_forker_thread(void *ptr)
391{ 362{
392 struct bdi_writeback *me = ptr; 363 struct bdi_writeback *me = ptr;
393 364
394 bdi_task_init(me->bdi, me); 365 current->flags |= PF_FLUSHER | PF_SWAPWRITE;
366 set_freezable();
367
368 /*
369 * Our parent may run at a different priority, just set us to normal
370 */
371 set_user_nice(current, 0);
395 372
396 for (;;) { 373 for (;;) {
397 struct backing_dev_info *bdi, *tmp; 374 struct task_struct *task = NULL;
398 struct bdi_writeback *wb; 375 struct backing_dev_info *bdi;
376 enum {
377 NO_ACTION, /* Nothing to do */
378 FORK_THREAD, /* Fork bdi thread */
379 KILL_THREAD, /* Kill inactive bdi thread */
380 } action = NO_ACTION;
399 381
400 /* 382 /*
401 * Temporary measure, we want to make sure we don't see 383 * Temporary measure, we want to make sure we don't see
402 * dirty data on the default backing_dev_info 384 * dirty data on the default backing_dev_info
403 */ 385 */
404 if (wb_has_dirty_io(me) || !list_empty(&me->bdi->work_list)) 386 if (wb_has_dirty_io(me) || !list_empty(&me->bdi->work_list)) {
387 del_timer(&me->wakeup_timer);
405 wb_do_writeback(me, 0); 388 wb_do_writeback(me, 0);
389 }
406 390
407 spin_lock_bh(&bdi_lock); 391 spin_lock_bh(&bdi_lock);
392 set_current_state(TASK_INTERRUPTIBLE);
408 393
409 /* 394 list_for_each_entry(bdi, &bdi_list, bdi_list) {
410 * Check if any existing bdi's have dirty data without 395 bool have_dirty_io;
411 * a thread registered. If so, set that up. 396
412 */ 397 if (!bdi_cap_writeback_dirty(bdi) ||
413 list_for_each_entry_safe(bdi, tmp, &bdi_list, bdi_list) { 398 bdi_cap_flush_forker(bdi))
414 if (bdi->wb.task)
415 continue;
416 if (list_empty(&bdi->work_list) &&
417 !bdi_has_dirty_io(bdi))
418 continue; 399 continue;
419 400
420 bdi_add_default_flusher_task(bdi); 401 WARN(!test_bit(BDI_registered, &bdi->state),
421 } 402 "bdi %p/%s is not registered!\n", bdi, bdi->name);
422 403
423 set_current_state(TASK_INTERRUPTIBLE); 404 have_dirty_io = !list_empty(&bdi->work_list) ||
405 wb_has_dirty_io(&bdi->wb);
424 406
425 if (list_empty(&bdi_pending_list)) { 407 /*
426 unsigned long wait; 408 * If the bdi has work to do, but the thread does not
409 * exist - create it.
410 */
411 if (!bdi->wb.task && have_dirty_io) {
412 /*
413 * Set the pending bit - if someone will try to
414 * unregister this bdi - it'll wait on this bit.
415 */
416 set_bit(BDI_pending, &bdi->state);
417 action = FORK_THREAD;
418 break;
419 }
420
421 spin_lock(&bdi->wb_lock);
422
423 /*
424 * If there is no work to do and the bdi thread was
425 * inactive long enough - kill it. The wb_lock is taken
426 * to make sure no-one adds more work to this bdi and
427 * wakes the bdi thread up.
428 */
429 if (bdi->wb.task && !have_dirty_io &&
430 time_after(jiffies, bdi->wb.last_active +
431 bdi_longest_inactive())) {
432 task = bdi->wb.task;
433 bdi->wb.task = NULL;
434 spin_unlock(&bdi->wb_lock);
435 set_bit(BDI_pending, &bdi->state);
436 action = KILL_THREAD;
437 break;
438 }
439 spin_unlock(&bdi->wb_lock);
440 }
441 spin_unlock_bh(&bdi_lock);
427 442
428 spin_unlock_bh(&bdi_lock); 443 /* Keep working if default bdi still has things to do */
429 wait = msecs_to_jiffies(dirty_writeback_interval * 10); 444 if (!list_empty(&me->bdi->work_list))
430 if (wait) 445 __set_current_state(TASK_RUNNING);
431 schedule_timeout(wait); 446
447 switch (action) {
448 case FORK_THREAD:
449 __set_current_state(TASK_RUNNING);
450 task = kthread_create(bdi_writeback_thread, &bdi->wb,
451 "flush-%s", dev_name(bdi->dev));
452 if (IS_ERR(task)) {
453 /*
454 * If thread creation fails, force writeout of
455 * the bdi from the thread.
456 */
457 bdi_flush_io(bdi);
458 } else {
459 /*
460 * The spinlock makes sure we do not lose
461 * wake-ups when racing with 'bdi_queue_work()'.
462 * And as soon as the bdi thread is visible, we
463 * can start it.
464 */
465 spin_lock_bh(&bdi->wb_lock);
466 bdi->wb.task = task;
467 spin_unlock_bh(&bdi->wb_lock);
468 wake_up_process(task);
469 }
470 break;
471
472 case KILL_THREAD:
473 __set_current_state(TASK_RUNNING);
474 kthread_stop(task);
475 break;
476
477 case NO_ACTION:
478 if (!wb_has_dirty_io(me) || !dirty_writeback_interval)
479 /*
480 * There are no dirty data. The only thing we
481 * should now care about is checking for
482 * inactive bdi threads and killing them. Thus,
483 * let's sleep for longer time, save energy and
484 * be friendly for battery-driven devices.
485 */
486 schedule_timeout(bdi_longest_inactive());
432 else 487 else
433 schedule(); 488 schedule_timeout(msecs_to_jiffies(dirty_writeback_interval * 10));
434 try_to_freeze(); 489 try_to_freeze();
490 /* Back to the main loop */
435 continue; 491 continue;
436 } 492 }
437 493
438 __set_current_state(TASK_RUNNING);
439
440 /*
441 * This is our real job - check for pending entries in
442 * bdi_pending_list, and create the tasks that got added
443 */
444 bdi = list_entry(bdi_pending_list.next, struct backing_dev_info,
445 bdi_list);
446 list_del_init(&bdi->bdi_list);
447 spin_unlock_bh(&bdi_lock);
448
449 wb = &bdi->wb;
450 wb->task = kthread_run(bdi_start_fn, wb, "flush-%s",
451 dev_name(bdi->dev));
452 /* 494 /*
453 * If task creation fails, then readd the bdi to 495 * Clear pending bit and wakeup anybody waiting to tear us down.
454 * the pending list and force writeout of the bdi
455 * from this forker thread. That will free some memory
456 * and we can try again.
457 */ 496 */
458 if (IS_ERR(wb->task)) { 497 clear_bit(BDI_pending, &bdi->state);
459 wb->task = NULL; 498 smp_mb__after_clear_bit();
460 499 wake_up_bit(&bdi->state, BDI_pending);
461 /*
462 * Add this 'bdi' to the back, so we get
463 * a chance to flush other bdi's to free
464 * memory.
465 */
466 spin_lock_bh(&bdi_lock);
467 list_add_tail(&bdi->bdi_list, &bdi_pending_list);
468 spin_unlock_bh(&bdi_lock);
469
470 bdi_flush_io(bdi);
471 }
472 } 500 }
473 501
474 return 0; 502 return 0;
475} 503}
476 504
477static void bdi_add_to_pending(struct rcu_head *head)
478{
479 struct backing_dev_info *bdi;
480
481 bdi = container_of(head, struct backing_dev_info, rcu_head);
482 INIT_LIST_HEAD(&bdi->bdi_list);
483
484 spin_lock(&bdi_lock);
485 list_add_tail(&bdi->bdi_list, &bdi_pending_list);
486 spin_unlock(&bdi_lock);
487
488 /*
489 * We are now on the pending list, wake up bdi_forker_task()
490 * to finish the job and add us back to the active bdi_list
491 */
492 wake_up_process(default_backing_dev_info.wb.task);
493}
494
495/*
496 * Add the default flusher task that gets created for any bdi
497 * that has dirty data pending writeout
498 */
499void static bdi_add_default_flusher_task(struct backing_dev_info *bdi)
500{
501 if (!bdi_cap_writeback_dirty(bdi))
502 return;
503
504 if (WARN_ON(!test_bit(BDI_registered, &bdi->state))) {
505 printk(KERN_ERR "bdi %p/%s is not registered!\n",
506 bdi, bdi->name);
507 return;
508 }
509
510 /*
511 * Check with the helper whether to proceed adding a task. Will only
512 * abort if we two or more simultanous calls to
513 * bdi_add_default_flusher_task() occured, further additions will block
514 * waiting for previous additions to finish.
515 */
516 if (!test_and_set_bit(BDI_pending, &bdi->state)) {
517 list_del_rcu(&bdi->bdi_list);
518
519 /*
520 * We must wait for the current RCU period to end before
521 * moving to the pending list. So schedule that operation
522 * from an RCU callback.
523 */
524 call_rcu(&bdi->rcu_head, bdi_add_to_pending);
525 }
526}
527
528/* 505/*
529 * Remove bdi from bdi_list, and ensure that it is no longer visible 506 * Remove bdi from bdi_list, and ensure that it is no longer visible
530 */ 507 */
@@ -541,23 +518,16 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent,
541 const char *fmt, ...) 518 const char *fmt, ...)
542{ 519{
543 va_list args; 520 va_list args;
544 int ret = 0;
545 struct device *dev; 521 struct device *dev;
546 522
547 if (bdi->dev) /* The driver needs to use separate queues per device */ 523 if (bdi->dev) /* The driver needs to use separate queues per device */
548 goto exit; 524 return 0;
549 525
550 va_start(args, fmt); 526 va_start(args, fmt);
551 dev = device_create_vargs(bdi_class, parent, MKDEV(0, 0), bdi, fmt, args); 527 dev = device_create_vargs(bdi_class, parent, MKDEV(0, 0), bdi, fmt, args);
552 va_end(args); 528 va_end(args);
553 if (IS_ERR(dev)) { 529 if (IS_ERR(dev))
554 ret = PTR_ERR(dev); 530 return PTR_ERR(dev);
555 goto exit;
556 }
557
558 spin_lock_bh(&bdi_lock);
559 list_add_tail_rcu(&bdi->bdi_list, &bdi_list);
560 spin_unlock_bh(&bdi_lock);
561 531
562 bdi->dev = dev; 532 bdi->dev = dev;
563 533
@@ -569,21 +539,21 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent,
569 if (bdi_cap_flush_forker(bdi)) { 539 if (bdi_cap_flush_forker(bdi)) {
570 struct bdi_writeback *wb = &bdi->wb; 540 struct bdi_writeback *wb = &bdi->wb;
571 541
572 wb->task = kthread_run(bdi_forker_task, wb, "bdi-%s", 542 wb->task = kthread_run(bdi_forker_thread, wb, "bdi-%s",
573 dev_name(dev)); 543 dev_name(dev));
574 if (IS_ERR(wb->task)) { 544 if (IS_ERR(wb->task))
575 wb->task = NULL; 545 return PTR_ERR(wb->task);
576 ret = -ENOMEM;
577
578 bdi_remove_from_list(bdi);
579 goto exit;
580 }
581 } 546 }
582 547
583 bdi_debug_register(bdi, dev_name(dev)); 548 bdi_debug_register(bdi, dev_name(dev));
584 set_bit(BDI_registered, &bdi->state); 549 set_bit(BDI_registered, &bdi->state);
585exit: 550
586 return ret; 551 spin_lock_bh(&bdi_lock);
552 list_add_tail_rcu(&bdi->bdi_list, &bdi_list);
553 spin_unlock_bh(&bdi_lock);
554
555 trace_writeback_bdi_register(bdi);
556 return 0;
587} 557}
588EXPORT_SYMBOL(bdi_register); 558EXPORT_SYMBOL(bdi_register);
589 559
@@ -598,31 +568,29 @@ EXPORT_SYMBOL(bdi_register_dev);
598 */ 568 */
599static void bdi_wb_shutdown(struct backing_dev_info *bdi) 569static void bdi_wb_shutdown(struct backing_dev_info *bdi)
600{ 570{
601 struct bdi_writeback *wb;
602
603 if (!bdi_cap_writeback_dirty(bdi)) 571 if (!bdi_cap_writeback_dirty(bdi))
604 return; 572 return;
605 573
606 /* 574 /*
607 * If setup is pending, wait for that to complete first 575 * Make sure nobody finds us on the bdi_list anymore
608 */ 576 */
609 wait_on_bit(&bdi->state, BDI_pending, bdi_sched_wait, 577 bdi_remove_from_list(bdi);
610 TASK_UNINTERRUPTIBLE);
611 578
612 /* 579 /*
613 * Make sure nobody finds us on the bdi_list anymore 580 * If setup is pending, wait for that to complete first
614 */ 581 */
615 bdi_remove_from_list(bdi); 582 wait_on_bit(&bdi->state, BDI_pending, bdi_sched_wait,
583 TASK_UNINTERRUPTIBLE);
616 584
617 /* 585 /*
618 * Finally, kill the kernel threads. We don't need to be RCU 586 * Finally, kill the kernel thread. We don't need to be RCU
619 * safe anymore, since the bdi is gone from visibility. Force 587 * safe anymore, since the bdi is gone from visibility. Force
620 * unfreeze of the thread before calling kthread_stop(), otherwise 588 * unfreeze of the thread before calling kthread_stop(), otherwise
621 * it would never exet if it is currently stuck in the refrigerator. 589 * it would never exet if it is currently stuck in the refrigerator.
622 */ 590 */
623 list_for_each_entry(wb, &bdi->wb_list, list) { 591 if (bdi->wb.task) {
624 thaw_process(wb->task); 592 thaw_process(bdi->wb.task);
625 kthread_stop(wb->task); 593 kthread_stop(bdi->wb.task);
626 } 594 }
627} 595}
628 596
@@ -644,7 +612,9 @@ static void bdi_prune_sb(struct backing_dev_info *bdi)
644void bdi_unregister(struct backing_dev_info *bdi) 612void bdi_unregister(struct backing_dev_info *bdi)
645{ 613{
646 if (bdi->dev) { 614 if (bdi->dev) {
615 trace_writeback_bdi_unregister(bdi);
647 bdi_prune_sb(bdi); 616 bdi_prune_sb(bdi);
617 del_timer_sync(&bdi->wb.wakeup_timer);
648 618
649 if (!bdi_cap_flush_forker(bdi)) 619 if (!bdi_cap_flush_forker(bdi))
650 bdi_wb_shutdown(bdi); 620 bdi_wb_shutdown(bdi);
@@ -655,6 +625,18 @@ void bdi_unregister(struct backing_dev_info *bdi)
655} 625}
656EXPORT_SYMBOL(bdi_unregister); 626EXPORT_SYMBOL(bdi_unregister);
657 627
628static void bdi_wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi)
629{
630 memset(wb, 0, sizeof(*wb));
631
632 wb->bdi = bdi;
633 wb->last_old_flush = jiffies;
634 INIT_LIST_HEAD(&wb->b_dirty);
635 INIT_LIST_HEAD(&wb->b_io);
636 INIT_LIST_HEAD(&wb->b_more_io);
637 setup_timer(&wb->wakeup_timer, wakeup_timer_fn, (unsigned long)bdi);
638}
639
658int bdi_init(struct backing_dev_info *bdi) 640int bdi_init(struct backing_dev_info *bdi)
659{ 641{
660 int i, err; 642 int i, err;
@@ -665,9 +647,7 @@ int bdi_init(struct backing_dev_info *bdi)
665 bdi->max_ratio = 100; 647 bdi->max_ratio = 100;
666 bdi->max_prop_frac = PROP_FRAC_BASE; 648 bdi->max_prop_frac = PROP_FRAC_BASE;
667 spin_lock_init(&bdi->wb_lock); 649 spin_lock_init(&bdi->wb_lock);
668 INIT_RCU_HEAD(&bdi->rcu_head);
669 INIT_LIST_HEAD(&bdi->bdi_list); 650 INIT_LIST_HEAD(&bdi->bdi_list);
670 INIT_LIST_HEAD(&bdi->wb_list);
671 INIT_LIST_HEAD(&bdi->work_list); 651 INIT_LIST_HEAD(&bdi->work_list);
672 652
673 bdi_wb_init(&bdi->wb, bdi); 653 bdi_wb_init(&bdi->wb, bdi);