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.c445
1 files changed, 210 insertions, 235 deletions
diff --git a/mm/backing-dev.c b/mm/backing-dev.c
index f9fd3dd3916b..08d357522e78 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
@@ -49,8 +50,6 @@ static struct timer_list sync_supers_timer;
49static int bdi_sync_supers(void *); 50static int bdi_sync_supers(void *);
50static void sync_supers_timer_fn(unsigned long); 51static void sync_supers_timer_fn(unsigned long);
51 52
52static void bdi_add_default_flusher_task(struct backing_dev_info *bdi);
53
54#ifdef CONFIG_DEBUG_FS 53#ifdef CONFIG_DEBUG_FS
55#include <linux/debugfs.h> 54#include <linux/debugfs.h>
56#include <linux/seq_file.h> 55#include <linux/seq_file.h>
@@ -65,28 +64,21 @@ static void bdi_debug_init(void)
65static int bdi_debug_stats_show(struct seq_file *m, void *v) 64static int bdi_debug_stats_show(struct seq_file *m, void *v)
66{ 65{
67 struct backing_dev_info *bdi = m->private; 66 struct backing_dev_info *bdi = m->private;
68 struct bdi_writeback *wb; 67 struct bdi_writeback *wb = &bdi->wb;
69 unsigned long background_thresh; 68 unsigned long background_thresh;
70 unsigned long dirty_thresh; 69 unsigned long dirty_thresh;
71 unsigned long bdi_thresh; 70 unsigned long bdi_thresh;
72 unsigned long nr_dirty, nr_io, nr_more_io, nr_wb; 71 unsigned long nr_dirty, nr_io, nr_more_io, nr_wb;
73 struct inode *inode; 72 struct inode *inode;
74 73
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; 74 nr_wb = nr_dirty = nr_io = nr_more_io = 0;
80 spin_lock(&inode_lock); 75 spin_lock(&inode_lock);
81 list_for_each_entry(wb, &bdi->wb_list, list) { 76 list_for_each_entry(inode, &wb->b_dirty, i_list)
82 nr_wb++; 77 nr_dirty++;
83 list_for_each_entry(inode, &wb->b_dirty, i_list) 78 list_for_each_entry(inode, &wb->b_io, i_list)
84 nr_dirty++; 79 nr_io++;
85 list_for_each_entry(inode, &wb->b_io, i_list) 80 list_for_each_entry(inode, &wb->b_more_io, i_list)
86 nr_io++; 81 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); 82 spin_unlock(&inode_lock);
91 83
92 get_dirty_limits(&background_thresh, &dirty_thresh, &bdi_thresh, bdi); 84 get_dirty_limits(&background_thresh, &dirty_thresh, &bdi_thresh, bdi);
@@ -98,19 +90,16 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
98 "BdiDirtyThresh: %8lu kB\n" 90 "BdiDirtyThresh: %8lu kB\n"
99 "DirtyThresh: %8lu kB\n" 91 "DirtyThresh: %8lu kB\n"
100 "BackgroundThresh: %8lu kB\n" 92 "BackgroundThresh: %8lu kB\n"
101 "WritebackThreads: %8lu\n"
102 "b_dirty: %8lu\n" 93 "b_dirty: %8lu\n"
103 "b_io: %8lu\n" 94 "b_io: %8lu\n"
104 "b_more_io: %8lu\n" 95 "b_more_io: %8lu\n"
105 "bdi_list: %8u\n" 96 "bdi_list: %8u\n"
106 "state: %8lx\n" 97 "state: %8lx\n",
107 "wb_list: %8u\n",
108 (unsigned long) K(bdi_stat(bdi, BDI_WRITEBACK)), 98 (unsigned long) K(bdi_stat(bdi, BDI_WRITEBACK)),
109 (unsigned long) K(bdi_stat(bdi, BDI_RECLAIMABLE)), 99 (unsigned long) K(bdi_stat(bdi, BDI_RECLAIMABLE)),
110 K(bdi_thresh), K(dirty_thresh), 100 K(bdi_thresh), K(dirty_thresh),
111 K(background_thresh), nr_wb, nr_dirty, nr_io, nr_more_io, 101 K(background_thresh), nr_dirty, nr_io, nr_more_io,
112 !list_empty(&bdi->bdi_list), bdi->state, 102 !list_empty(&bdi->bdi_list), bdi->state);
113 !list_empty(&bdi->wb_list));
114#undef K 103#undef K
115 104
116 return 0; 105 return 0;
@@ -247,7 +236,6 @@ static int __init default_bdi_init(void)
247 sync_supers_tsk = kthread_run(bdi_sync_supers, NULL, "sync_supers"); 236 sync_supers_tsk = kthread_run(bdi_sync_supers, NULL, "sync_supers");
248 BUG_ON(IS_ERR(sync_supers_tsk)); 237 BUG_ON(IS_ERR(sync_supers_tsk));
249 238
250 init_timer(&sync_supers_timer);
251 setup_timer(&sync_supers_timer, sync_supers_timer_fn, 0); 239 setup_timer(&sync_supers_timer, sync_supers_timer_fn, 0);
252 bdi_arm_supers_timer(); 240 bdi_arm_supers_timer();
253 241
@@ -259,77 +247,6 @@ static int __init default_bdi_init(void)
259} 247}
260subsys_initcall(default_bdi_init); 248subsys_initcall(default_bdi_init);
261 249
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) 250int bdi_has_dirty_io(struct backing_dev_info *bdi)
334{ 251{
335 return wb_has_dirty_io(&bdi->wb); 252 return wb_has_dirty_io(&bdi->wb);
@@ -348,10 +265,10 @@ static void bdi_flush_io(struct backing_dev_info *bdi)
348} 265}
349 266
350/* 267/*
351 * kupdated() used to do this. We cannot do it from the bdi_forker_task() 268 * 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 269 * 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 270 * to implement sync_supers_bdi() or similar and simply do it from the
354 * bdi writeback tasks individually. 271 * bdi writeback thread individually.
355 */ 272 */
356static int bdi_sync_supers(void *unused) 273static int bdi_sync_supers(void *unused)
357{ 274{
@@ -387,144 +304,198 @@ static void sync_supers_timer_fn(unsigned long unused)
387 bdi_arm_supers_timer(); 304 bdi_arm_supers_timer();
388} 305}
389 306
390static int bdi_forker_task(void *ptr) 307static void wakeup_timer_fn(unsigned long data)
308{
309 struct backing_dev_info *bdi = (struct backing_dev_info *)data;
310
311 spin_lock_bh(&bdi->wb_lock);
312 if (bdi->wb.task) {
313 trace_writeback_wake_thread(bdi);
314 wake_up_process(bdi->wb.task);
315 } else {
316 /*
317 * When bdi tasks are inactive for long time, they are killed.
318 * In this case we have to wake-up the forker thread which
319 * should create and run the bdi thread.
320 */
321 trace_writeback_wake_forker_thread(bdi);
322 wake_up_process(default_backing_dev_info.wb.task);
323 }
324 spin_unlock_bh(&bdi->wb_lock);
325}
326
327/*
328 * This function is used when the first inode for this bdi is marked dirty. It
329 * wakes-up the corresponding bdi thread which should then take care of the
330 * periodic background write-out of dirty inodes. Since the write-out would
331 * starts only 'dirty_writeback_interval' centisecs from now anyway, we just
332 * set up a timer which wakes the bdi thread up later.
333 *
334 * Note, we wouldn't bother setting up the timer, but this function is on the
335 * fast-path (used by '__mark_inode_dirty()'), so we save few context switches
336 * by delaying the wake-up.
337 */
338void bdi_wakeup_thread_delayed(struct backing_dev_info *bdi)
339{
340 unsigned long timeout;
341
342 timeout = msecs_to_jiffies(dirty_writeback_interval * 10);
343 mod_timer(&bdi->wb.wakeup_timer, jiffies + timeout);
344}
345
346/*
347 * Calculate the longest interval (jiffies) bdi threads are allowed to be
348 * inactive.
349 */
350static unsigned long bdi_longest_inactive(void)
351{
352 unsigned long interval;
353
354 interval = msecs_to_jiffies(dirty_writeback_interval * 10);
355 return max(5UL * 60 * HZ, interval);
356}
357
358static int bdi_forker_thread(void *ptr)
391{ 359{
392 struct bdi_writeback *me = ptr; 360 struct bdi_writeback *me = ptr;
393 361
394 bdi_task_init(me->bdi, me); 362 current->flags |= PF_FLUSHER | PF_SWAPWRITE;
363 set_freezable();
364
365 /*
366 * Our parent may run at a different priority, just set us to normal
367 */
368 set_user_nice(current, 0);
395 369
396 for (;;) { 370 for (;;) {
397 struct backing_dev_info *bdi, *tmp; 371 struct task_struct *task = NULL;
398 struct bdi_writeback *wb; 372 struct backing_dev_info *bdi;
373 enum {
374 NO_ACTION, /* Nothing to do */
375 FORK_THREAD, /* Fork bdi thread */
376 KILL_THREAD, /* Kill inactive bdi thread */
377 } action = NO_ACTION;
399 378
400 /* 379 /*
401 * Temporary measure, we want to make sure we don't see 380 * Temporary measure, we want to make sure we don't see
402 * dirty data on the default backing_dev_info 381 * dirty data on the default backing_dev_info
403 */ 382 */
404 if (wb_has_dirty_io(me) || !list_empty(&me->bdi->work_list)) 383 if (wb_has_dirty_io(me) || !list_empty(&me->bdi->work_list)) {
384 del_timer(&me->wakeup_timer);
405 wb_do_writeback(me, 0); 385 wb_do_writeback(me, 0);
386 }
406 387
407 spin_lock_bh(&bdi_lock); 388 spin_lock_bh(&bdi_lock);
389 set_current_state(TASK_INTERRUPTIBLE);
408 390
409 /* 391 list_for_each_entry(bdi, &bdi_list, bdi_list) {
410 * Check if any existing bdi's have dirty data without 392 bool have_dirty_io;
411 * a thread registered. If so, set that up. 393
412 */ 394 if (!bdi_cap_writeback_dirty(bdi) ||
413 list_for_each_entry_safe(bdi, tmp, &bdi_list, bdi_list) { 395 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; 396 continue;
419 397
420 bdi_add_default_flusher_task(bdi); 398 WARN(!test_bit(BDI_registered, &bdi->state),
421 } 399 "bdi %p/%s is not registered!\n", bdi, bdi->name);
422 400
423 set_current_state(TASK_INTERRUPTIBLE); 401 have_dirty_io = !list_empty(&bdi->work_list) ||
402 wb_has_dirty_io(&bdi->wb);
424 403
425 if (list_empty(&bdi_pending_list)) { 404 /*
426 unsigned long wait; 405 * If the bdi has work to do, but the thread does not
406 * exist - create it.
407 */
408 if (!bdi->wb.task && have_dirty_io) {
409 /*
410 * Set the pending bit - if someone will try to
411 * unregister this bdi - it'll wait on this bit.
412 */
413 set_bit(BDI_pending, &bdi->state);
414 action = FORK_THREAD;
415 break;
416 }
417
418 spin_lock(&bdi->wb_lock);
419
420 /*
421 * If there is no work to do and the bdi thread was
422 * inactive long enough - kill it. The wb_lock is taken
423 * to make sure no-one adds more work to this bdi and
424 * wakes the bdi thread up.
425 */
426 if (bdi->wb.task && !have_dirty_io &&
427 time_after(jiffies, bdi->wb.last_active +
428 bdi_longest_inactive())) {
429 task = bdi->wb.task;
430 bdi->wb.task = NULL;
431 spin_unlock(&bdi->wb_lock);
432 set_bit(BDI_pending, &bdi->state);
433 action = KILL_THREAD;
434 break;
435 }
436 spin_unlock(&bdi->wb_lock);
437 }
438 spin_unlock_bh(&bdi_lock);
427 439
428 spin_unlock_bh(&bdi_lock); 440 /* Keep working if default bdi still has things to do */
429 wait = msecs_to_jiffies(dirty_writeback_interval * 10); 441 if (!list_empty(&me->bdi->work_list))
430 if (wait) 442 __set_current_state(TASK_RUNNING);
431 schedule_timeout(wait); 443
444 switch (action) {
445 case FORK_THREAD:
446 __set_current_state(TASK_RUNNING);
447 task = kthread_run(bdi_writeback_thread, &bdi->wb, "flush-%s",
448 dev_name(bdi->dev));
449 if (IS_ERR(task)) {
450 /*
451 * If thread creation fails, force writeout of
452 * the bdi from the thread.
453 */
454 bdi_flush_io(bdi);
455 } else {
456 /*
457 * The spinlock makes sure we do not lose
458 * wake-ups when racing with 'bdi_queue_work()'.
459 */
460 spin_lock_bh(&bdi->wb_lock);
461 bdi->wb.task = task;
462 spin_unlock_bh(&bdi->wb_lock);
463 }
464 break;
465
466 case KILL_THREAD:
467 __set_current_state(TASK_RUNNING);
468 kthread_stop(task);
469 break;
470
471 case NO_ACTION:
472 if (!wb_has_dirty_io(me) || !dirty_writeback_interval)
473 /*
474 * There are no dirty data. The only thing we
475 * should now care about is checking for
476 * inactive bdi threads and killing them. Thus,
477 * let's sleep for longer time, save energy and
478 * be friendly for battery-driven devices.
479 */
480 schedule_timeout(bdi_longest_inactive());
432 else 481 else
433 schedule(); 482 schedule_timeout(msecs_to_jiffies(dirty_writeback_interval * 10));
434 try_to_freeze(); 483 try_to_freeze();
484 /* Back to the main loop */
435 continue; 485 continue;
436 } 486 }
437 487
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 /* 488 /*
453 * If task creation fails, then readd the bdi to 489 * 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 */ 490 */
458 if (IS_ERR(wb->task)) { 491 clear_bit(BDI_pending, &bdi->state);
459 wb->task = NULL; 492 smp_mb__after_clear_bit();
460 493 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 } 494 }
473 495
474 return 0; 496 return 0;
475} 497}
476 498
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/* 499/*
529 * Remove bdi from bdi_list, and ensure that it is no longer visible 500 * Remove bdi from bdi_list, and ensure that it is no longer visible
530 */ 501 */
@@ -541,23 +512,16 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent,
541 const char *fmt, ...) 512 const char *fmt, ...)
542{ 513{
543 va_list args; 514 va_list args;
544 int ret = 0;
545 struct device *dev; 515 struct device *dev;
546 516
547 if (bdi->dev) /* The driver needs to use separate queues per device */ 517 if (bdi->dev) /* The driver needs to use separate queues per device */
548 goto exit; 518 return 0;
549 519
550 va_start(args, fmt); 520 va_start(args, fmt);
551 dev = device_create_vargs(bdi_class, parent, MKDEV(0, 0), bdi, fmt, args); 521 dev = device_create_vargs(bdi_class, parent, MKDEV(0, 0), bdi, fmt, args);
552 va_end(args); 522 va_end(args);
553 if (IS_ERR(dev)) { 523 if (IS_ERR(dev))
554 ret = PTR_ERR(dev); 524 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 525
562 bdi->dev = dev; 526 bdi->dev = dev;
563 527
@@ -569,21 +533,21 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent,
569 if (bdi_cap_flush_forker(bdi)) { 533 if (bdi_cap_flush_forker(bdi)) {
570 struct bdi_writeback *wb = &bdi->wb; 534 struct bdi_writeback *wb = &bdi->wb;
571 535
572 wb->task = kthread_run(bdi_forker_task, wb, "bdi-%s", 536 wb->task = kthread_run(bdi_forker_thread, wb, "bdi-%s",
573 dev_name(dev)); 537 dev_name(dev));
574 if (IS_ERR(wb->task)) { 538 if (IS_ERR(wb->task))
575 wb->task = NULL; 539 return PTR_ERR(wb->task);
576 ret = -ENOMEM;
577
578 bdi_remove_from_list(bdi);
579 goto exit;
580 }
581 } 540 }
582 541
583 bdi_debug_register(bdi, dev_name(dev)); 542 bdi_debug_register(bdi, dev_name(dev));
584 set_bit(BDI_registered, &bdi->state); 543 set_bit(BDI_registered, &bdi->state);
585exit: 544
586 return ret; 545 spin_lock_bh(&bdi_lock);
546 list_add_tail_rcu(&bdi->bdi_list, &bdi_list);
547 spin_unlock_bh(&bdi_lock);
548
549 trace_writeback_bdi_register(bdi);
550 return 0;
587} 551}
588EXPORT_SYMBOL(bdi_register); 552EXPORT_SYMBOL(bdi_register);
589 553
@@ -598,31 +562,29 @@ EXPORT_SYMBOL(bdi_register_dev);
598 */ 562 */
599static void bdi_wb_shutdown(struct backing_dev_info *bdi) 563static void bdi_wb_shutdown(struct backing_dev_info *bdi)
600{ 564{
601 struct bdi_writeback *wb;
602
603 if (!bdi_cap_writeback_dirty(bdi)) 565 if (!bdi_cap_writeback_dirty(bdi))
604 return; 566 return;
605 567
606 /* 568 /*
607 * If setup is pending, wait for that to complete first 569 * Make sure nobody finds us on the bdi_list anymore
608 */ 570 */
609 wait_on_bit(&bdi->state, BDI_pending, bdi_sched_wait, 571 bdi_remove_from_list(bdi);
610 TASK_UNINTERRUPTIBLE);
611 572
612 /* 573 /*
613 * Make sure nobody finds us on the bdi_list anymore 574 * If setup is pending, wait for that to complete first
614 */ 575 */
615 bdi_remove_from_list(bdi); 576 wait_on_bit(&bdi->state, BDI_pending, bdi_sched_wait,
577 TASK_UNINTERRUPTIBLE);
616 578
617 /* 579 /*
618 * Finally, kill the kernel threads. We don't need to be RCU 580 * Finally, kill the kernel thread. We don't need to be RCU
619 * safe anymore, since the bdi is gone from visibility. Force 581 * safe anymore, since the bdi is gone from visibility. Force
620 * unfreeze of the thread before calling kthread_stop(), otherwise 582 * unfreeze of the thread before calling kthread_stop(), otherwise
621 * it would never exet if it is currently stuck in the refrigerator. 583 * it would never exet if it is currently stuck in the refrigerator.
622 */ 584 */
623 list_for_each_entry(wb, &bdi->wb_list, list) { 585 if (bdi->wb.task) {
624 thaw_process(wb->task); 586 thaw_process(bdi->wb.task);
625 kthread_stop(wb->task); 587 kthread_stop(bdi->wb.task);
626 } 588 }
627} 589}
628 590
@@ -644,7 +606,9 @@ static void bdi_prune_sb(struct backing_dev_info *bdi)
644void bdi_unregister(struct backing_dev_info *bdi) 606void bdi_unregister(struct backing_dev_info *bdi)
645{ 607{
646 if (bdi->dev) { 608 if (bdi->dev) {
609 trace_writeback_bdi_unregister(bdi);
647 bdi_prune_sb(bdi); 610 bdi_prune_sb(bdi);
611 del_timer_sync(&bdi->wb.wakeup_timer);
648 612
649 if (!bdi_cap_flush_forker(bdi)) 613 if (!bdi_cap_flush_forker(bdi))
650 bdi_wb_shutdown(bdi); 614 bdi_wb_shutdown(bdi);
@@ -655,6 +619,18 @@ void bdi_unregister(struct backing_dev_info *bdi)
655} 619}
656EXPORT_SYMBOL(bdi_unregister); 620EXPORT_SYMBOL(bdi_unregister);
657 621
622static void bdi_wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi)
623{
624 memset(wb, 0, sizeof(*wb));
625
626 wb->bdi = bdi;
627 wb->last_old_flush = jiffies;
628 INIT_LIST_HEAD(&wb->b_dirty);
629 INIT_LIST_HEAD(&wb->b_io);
630 INIT_LIST_HEAD(&wb->b_more_io);
631 setup_timer(&wb->wakeup_timer, wakeup_timer_fn, (unsigned long)bdi);
632}
633
658int bdi_init(struct backing_dev_info *bdi) 634int bdi_init(struct backing_dev_info *bdi)
659{ 635{
660 int i, err; 636 int i, err;
@@ -666,7 +642,6 @@ int bdi_init(struct backing_dev_info *bdi)
666 bdi->max_prop_frac = PROP_FRAC_BASE; 642 bdi->max_prop_frac = PROP_FRAC_BASE;
667 spin_lock_init(&bdi->wb_lock); 643 spin_lock_init(&bdi->wb_lock);
668 INIT_LIST_HEAD(&bdi->bdi_list); 644 INIT_LIST_HEAD(&bdi->bdi_list);
669 INIT_LIST_HEAD(&bdi->wb_list);
670 INIT_LIST_HEAD(&bdi->work_list); 645 INIT_LIST_HEAD(&bdi->work_list);
671 646
672 bdi_wb_init(&bdi->wb, bdi); 647 bdi_wb_init(&bdi->wb, bdi);