Lines Matching refs:wb

52 	struct bdi_writeback *wb = &bdi->wb;
60 spin_lock(&wb->list_lock);
61 list_for_each_entry(inode, &wb->b_dirty, i_io_list)
63 list_for_each_entry(inode, &wb->b_io, i_io_list)
65 list_for_each_entry(inode, &wb->b_more_io, i_io_list)
67 list_for_each_entry(inode, &wb->b_dirty_time, i_io_list)
70 spin_unlock(&wb->list_lock);
73 wb_thresh = wb_calc_thresh(wb, dirty_thresh);
90 (unsigned long) K(wb_stat(wb, WB_WRITEBACK)),
91 (unsigned long) K(wb_stat(wb, WB_RECLAIMABLE)),
95 (unsigned long) K(wb_stat(wb, WB_DIRTIED)),
96 (unsigned long) K(wb_stat(wb, WB_WRITTEN)),
97 (unsigned long) K(wb->write_bandwidth),
102 !list_empty(&bdi->bdi_list), bdi->wb.state);
376 * This function is used when the first inode for this wb is marked dirty. It
389 void wb_wakeup_delayed(struct bdi_writeback *wb)
394 spin_lock_irq(&wb->work_lock);
395 if (test_bit(WB_registered, &wb->state))
396 queue_delayed_work(bdi_wq, &wb->dwork, timeout);
397 spin_unlock_irq(&wb->work_lock);
402 struct bdi_writeback *wb = container_of(to_delayed_work(work),
405 wb_update_bandwidth(wb);
413 static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,
418 memset(wb, 0, sizeof(*wb));
420 wb->bdi = bdi;
421 wb->last_old_flush = jiffies;
422 INIT_LIST_HEAD(&wb->b_dirty);
423 INIT_LIST_HEAD(&wb->b_io);
424 INIT_LIST_HEAD(&wb->b_more_io);
425 INIT_LIST_HEAD(&wb->b_dirty_time);
426 spin_lock_init(&wb->list_lock);
428 atomic_set(&wb->writeback_inodes, 0);
429 wb->bw_time_stamp = jiffies;
430 wb->balanced_dirty_ratelimit = INIT_BW;
431 wb->dirty_ratelimit = INIT_BW;
432 wb->write_bandwidth = INIT_BW;
433 wb->avg_write_bandwidth = INIT_BW;
435 spin_lock_init(&wb->work_lock);
436 INIT_LIST_HEAD(&wb->work_list);
437 INIT_DELAYED_WORK(&wb->dwork, wb_workfn);
438 INIT_DELAYED_WORK(&wb->bw_dwork, wb_update_bandwidth_workfn);
440 err = fprop_local_init_percpu(&wb->completions, gfp);
445 err = percpu_counter_init(&wb->stat[i], 0, gfp);
454 percpu_counter_destroy(&wb->stat[i]);
455 fprop_local_destroy_percpu(&wb->completions);
459 static void cgwb_remove_from_bdi_list(struct bdi_writeback *wb);
464 static void wb_shutdown(struct bdi_writeback *wb)
467 spin_lock_irq(&wb->work_lock);
468 if (!test_and_clear_bit(WB_registered, &wb->state)) {
469 spin_unlock_irq(&wb->work_lock);
472 spin_unlock_irq(&wb->work_lock);
474 cgwb_remove_from_bdi_list(wb);
477 * tells wb_workfn() that @wb is dying and its work_list needs to
480 mod_delayed_work(bdi_wq, &wb->dwork, 0);
481 flush_delayed_work(&wb->dwork);
482 WARN_ON(!list_empty(&wb->work_list));
483 flush_delayed_work(&wb->bw_dwork);
486 static void wb_exit(struct bdi_writeback *wb)
490 WARN_ON(delayed_work_pending(&wb->dwork));
493 percpu_counter_destroy(&wb->stat[i]);
495 fprop_local_destroy_percpu(&wb->completions);
515 struct bdi_writeback *wb = container_of(rcu_head,
518 percpu_ref_exit(&wb->refcnt);
519 kfree(wb);
524 struct bdi_writeback *wb = container_of(work, struct bdi_writeback,
526 struct backing_dev_info *bdi = wb->bdi;
528 mutex_lock(&wb->bdi->cgwb_release_mutex);
529 wb_shutdown(wb);
531 css_put(wb->memcg_css);
532 css_put(wb->blkcg_css);
533 mutex_unlock(&wb->bdi->cgwb_release_mutex);
536 blkcg_unpin_online(wb->blkcg_css);
538 fprop_local_destroy_percpu(&wb->memcg_completions);
541 list_del(&wb->offline_node);
544 wb_exit(wb);
546 WARN_ON_ONCE(!list_empty(&wb->b_attached));
547 call_rcu(&wb->rcu, cgwb_free_rcu);
552 struct bdi_writeback *wb = container_of(refcnt, struct bdi_writeback,
554 queue_work(cgwb_release_wq, &wb->release_work);
557 static void cgwb_kill(struct bdi_writeback *wb)
561 WARN_ON(!radix_tree_delete(&wb->bdi->cgwb_tree, wb->memcg_css->id));
562 list_del(&wb->memcg_node);
563 list_del(&wb->blkcg_node);
564 list_add(&wb->offline_node, &offline_cgwbs);
565 percpu_ref_kill(&wb->refcnt);
568 static void cgwb_remove_from_bdi_list(struct bdi_writeback *wb)
571 list_del_rcu(&wb->bdi_node);
581 struct bdi_writeback *wb;
592 wb = radix_tree_lookup(&bdi->cgwb_tree, memcg_css->id);
593 if (wb && wb->blkcg_css != blkcg_css) {
594 cgwb_kill(wb);
595 wb = NULL;
598 if (wb)
602 wb = kmalloc(sizeof(*wb), gfp);
603 if (!wb) {
608 ret = wb_init(wb, bdi, gfp);
612 ret = percpu_ref_init(&wb->refcnt, cgwb_release, 0, gfp);
616 ret = fprop_local_init_percpu(&wb->memcg_completions, gfp);
620 wb->memcg_css = memcg_css;
621 wb->blkcg_css = blkcg_css;
622 INIT_LIST_HEAD(&wb->b_attached);
623 INIT_WORK(&wb->release_work, cgwb_release_workfn);
624 set_bit(WB_registered, &wb->state);
628 * The root wb determines the registered state of the whole bdi and
630 * whether they're still online. Don't link @wb if any is dead.
635 if (test_bit(WB_registered, &bdi->wb.state) &&
638 ret = radix_tree_insert(&bdi->cgwb_tree, memcg_css->id, wb);
640 list_add_tail_rcu(&wb->bdi_node, &bdi->wb_list);
641 list_add(&wb->memcg_node, memcg_cgwb_list);
642 list_add(&wb->blkcg_node, blkcg_cgwb_list);
658 fprop_local_destroy_percpu(&wb->memcg_completions);
660 percpu_ref_exit(&wb->refcnt);
662 wb_exit(wb);
664 kfree(wb);
671 * wb_get_lookup - get wb for a given memcg
675 * Try to get the wb for @memcg_css on @bdi. The returned wb has its
682 * A wb is keyed by its associated memcg. As blkcg implicitly enables
688 * and disabled closer to root in the hierarchy, each wb keeps track of
690 * each lookup. On mismatch, the existing wb is discarded and a new one is
696 struct bdi_writeback *wb;
699 return &bdi->wb;
702 wb = radix_tree_lookup(&bdi->cgwb_tree, memcg_css->id);
703 if (wb) {
708 if (unlikely(wb->blkcg_css != blkcg_css || !wb_tryget(wb)))
709 wb = NULL;
714 return wb;
718 * wb_get_create - get wb for a given memcg, create if necessary
723 * Try to get the wb for @memcg_css on @bdi. If it doesn't exist, try to
730 struct bdi_writeback *wb;
735 wb = wb_get_lookup(bdi, memcg_css);
736 } while (!wb && !cgwb_create(bdi, memcg_css, gfp));
738 return wb;
749 ret = wb_init(&bdi->wb, bdi, GFP_KERNEL);
751 bdi->wb.memcg_css = &root_mem_cgroup->css;
752 bdi->wb.blkcg_css = blkcg_root_css;
761 struct bdi_writeback *wb;
763 WARN_ON(test_bit(WB_registered, &bdi->wb.state));
773 wb = list_first_entry(&bdi->wb_list, struct bdi_writeback,
776 wb_shutdown(wb);
792 struct bdi_writeback *wb;
798 wb = list_first_entry(&offline_cgwbs, struct bdi_writeback,
800 list_move(&wb->offline_node, &processed);
803 * If wb is dirty, cleaning up the writeback by switching
811 if (wb_has_dirty_io(wb))
814 if (!wb_tryget(wb))
818 while (cleanup_offline_cgwb(wb))
822 wb_put(wb);
832 * wb_memcg_offline - kill all wb's associated with a memcg being offlined
835 * Also prevents creation of any new wb's associated with @memcg.
840 struct bdi_writeback *wb, *next;
843 list_for_each_entry_safe(wb, next, memcg_cgwb_list, memcg_node)
844 cgwb_kill(wb);
845 memcg_cgwb_list->next = NULL; /* prevent new wb's */
852 * wb_blkcg_offline - kill all wb's associated with a blkcg being offlined
855 * Also prevents creation of any new wb's associated with @blkcg.
859 struct bdi_writeback *wb, *next;
863 list_for_each_entry_safe(wb, next, list, blkcg_node)
864 cgwb_kill(wb);
865 list->next = NULL; /* prevent new wb's */
872 list_add_tail_rcu(&bdi->wb.bdi_node, &bdi->wb_list);
895 return wb_init(&bdi->wb, bdi, GFP_KERNEL);
902 list_add_tail_rcu(&bdi->wb.bdi_node, &bdi->wb_list);
905 static void cgwb_remove_from_bdi_list(struct bdi_writeback *wb)
907 list_del_rcu(&wb->bdi_node);
1013 set_bit(WB_registered, &bdi->wb.state);
1069 wb_shutdown(&bdi->wb);
1097 WARN_ON_ONCE(test_bit(WB_registered, &bdi->wb.state));
1099 wb_exit(&bdi->wb);