Lines Matching defs:wb
63 struct bdi_writeback *wb)
67 spin_lock(&wb->list_lock);
68 list_for_each_entry(inode, &wb->b_dirty, i_io_list)
70 list_for_each_entry(inode, &wb->b_io, i_io_list)
72 list_for_each_entry(inode, &wb->b_more_io, i_io_list)
74 list_for_each_entry(inode, &wb->b_dirty_time, i_io_list)
77 spin_unlock(&wb->list_lock);
79 stats->nr_writeback += wb_stat(wb, WB_WRITEBACK);
80 stats->nr_reclaimable += wb_stat(wb, WB_RECLAIMABLE);
81 stats->nr_dirtied += wb_stat(wb, WB_DIRTIED);
82 stats->nr_written += wb_stat(wb, WB_WRITTEN);
83 stats->wb_thresh += wb_calc_thresh(wb, stats->dirty_thresh);
90 struct bdi_writeback *wb;
93 list_for_each_entry_rcu(wb, &bdi->wb_list, bdi_node) {
94 if (!wb_tryget(wb))
97 collect_wb_stats(stats, wb);
98 wb_put(wb);
106 collect_wb_stats(stats, &bdi->wb);
152 !list_empty(&bdi->bdi_list), bdi->wb.state);
158 static void wb_stats_show(struct seq_file *m, struct bdi_writeback *wb,
176 cgroup_ino(wb->memcg_css->cgroup),
185 K(wb->avg_write_bandwidth),
190 wb->state);
198 struct bdi_writeback *wb;
203 list_for_each_entry_rcu(wb, &bdi->wb_list, bdi_node) {
206 if (!wb_tryget(wb))
209 collect_wb_stats(&stats, wb);
212 * Calculate thresh of wb in writeback cgroup which is min of
217 if (mem_cgroup_wb_domain(wb)) {
219 stats.wb_thresh = min(stats.wb_thresh, cgwb_calc_thresh(wb));
223 wb_stats_show(m, wb, &stats);
225 wb_put(wb);
504 struct bdi_writeback *wb = container_of(to_delayed_work(work),
507 wb_update_bandwidth(wb);
515 static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,
520 memset(wb, 0, sizeof(*wb));
522 wb->bdi = bdi;
523 wb->last_old_flush = jiffies;
524 INIT_LIST_HEAD(&wb->b_dirty);
525 INIT_LIST_HEAD(&wb->b_io);
526 INIT_LIST_HEAD(&wb->b_more_io);
527 INIT_LIST_HEAD(&wb->b_dirty_time);
528 spin_lock_init(&wb->list_lock);
530 atomic_set(&wb->writeback_inodes, 0);
531 wb->bw_time_stamp = jiffies;
532 wb->balanced_dirty_ratelimit = INIT_BW;
533 wb->dirty_ratelimit = INIT_BW;
534 wb->write_bandwidth = INIT_BW;
535 wb->avg_write_bandwidth = INIT_BW;
537 spin_lock_init(&wb->work_lock);
538 INIT_LIST_HEAD(&wb->work_list);
539 INIT_DELAYED_WORK(&wb->dwork, wb_workfn);
540 INIT_DELAYED_WORK(&wb->bw_dwork, wb_update_bandwidth_workfn);
542 err = fprop_local_init_percpu(&wb->completions, gfp);
546 err = percpu_counter_init_many(wb->stat, 0, gfp, NR_WB_STAT_ITEMS);
548 fprop_local_destroy_percpu(&wb->completions);
553 static void cgwb_remove_from_bdi_list(struct bdi_writeback *wb);
558 static void wb_shutdown(struct bdi_writeback *wb)
561 spin_lock_irq(&wb->work_lock);
562 if (!test_and_clear_bit(WB_registered, &wb->state)) {
563 spin_unlock_irq(&wb->work_lock);
566 spin_unlock_irq(&wb->work_lock);
568 cgwb_remove_from_bdi_list(wb);
571 * tells wb_workfn() that @wb is dying and its work_list needs to
574 mod_delayed_work(bdi_wq, &wb->dwork, 0);
575 flush_delayed_work(&wb->dwork);
576 WARN_ON(!list_empty(&wb->work_list));
577 flush_delayed_work(&wb->bw_dwork);
580 static void wb_exit(struct bdi_writeback *wb)
582 WARN_ON(delayed_work_pending(&wb->dwork));
583 percpu_counter_destroy_many(wb->stat, NR_WB_STAT_ITEMS);
584 fprop_local_destroy_percpu(&wb->completions);
604 struct bdi_writeback *wb = container_of(rcu_head,
607 percpu_ref_exit(&wb->refcnt);
608 kfree(wb);
613 struct bdi_writeback *wb = container_of(work, struct bdi_writeback,
615 struct backing_dev_info *bdi = wb->bdi;
617 mutex_lock(&wb->bdi->cgwb_release_mutex);
618 wb_shutdown(wb);
620 css_put(wb->memcg_css);
621 css_put(wb->blkcg_css);
622 mutex_unlock(&wb->bdi->cgwb_release_mutex);
625 blkcg_unpin_online(wb->blkcg_css);
627 fprop_local_destroy_percpu(&wb->memcg_completions);
630 list_del(&wb->offline_node);
633 wb_exit(wb);
635 WARN_ON_ONCE(!list_empty(&wb->b_attached));
636 call_rcu(&wb->rcu, cgwb_free_rcu);
641 struct bdi_writeback *wb = container_of(refcnt, struct bdi_writeback,
643 queue_work(cgwb_release_wq, &wb->release_work);
646 static void cgwb_kill(struct bdi_writeback *wb)
650 WARN_ON(!radix_tree_delete(&wb->bdi->cgwb_tree, wb->memcg_css->id));
651 list_del(&wb->memcg_node);
652 list_del(&wb->blkcg_node);
653 list_add(&wb->offline_node, &offline_cgwbs);
654 percpu_ref_kill(&wb->refcnt);
657 static void cgwb_remove_from_bdi_list(struct bdi_writeback *wb)
660 list_del_rcu(&wb->bdi_node);
670 struct bdi_writeback *wb;
681 wb = radix_tree_lookup(&bdi->cgwb_tree, memcg_css->id);
682 if (wb && wb->blkcg_css != blkcg_css) {
683 cgwb_kill(wb);
684 wb = NULL;
687 if (wb)
691 wb = kmalloc(sizeof(*wb), gfp);
692 if (!wb) {
697 ret = wb_init(wb, bdi, gfp);
701 ret = percpu_ref_init(&wb->refcnt, cgwb_release, 0, gfp);
705 ret = fprop_local_init_percpu(&wb->memcg_completions, gfp);
709 wb->memcg_css = memcg_css;
710 wb->blkcg_css = blkcg_css;
711 INIT_LIST_HEAD(&wb->b_attached);
712 INIT_WORK(&wb->release_work, cgwb_release_workfn);
713 set_bit(WB_registered, &wb->state);
717 * The root wb determines the registered state of the whole bdi and
719 * whether they're still online. Don't link @wb if any is dead.
724 if (test_bit(WB_registered, &bdi->wb.state) &&
727 ret = radix_tree_insert(&bdi->cgwb_tree, memcg_css->id, wb);
729 list_add_tail_rcu(&wb->bdi_node, &bdi->wb_list);
730 list_add(&wb->memcg_node, memcg_cgwb_list);
731 list_add(&wb->blkcg_node, blkcg_cgwb_list);
747 fprop_local_destroy_percpu(&wb->memcg_completions);
749 percpu_ref_exit(&wb->refcnt);
751 wb_exit(wb);
753 kfree(wb);
760 * wb_get_lookup - get wb for a given memcg
764 * Try to get the wb for @memcg_css on @bdi. The returned wb has its
771 * A wb is keyed by its associated memcg. As blkcg implicitly enables
777 * and disabled closer to root in the hierarchy, each wb keeps track of
779 * each lookup. On mismatch, the existing wb is discarded and a new one is
785 struct bdi_writeback *wb;
788 return &bdi->wb;
791 wb = radix_tree_lookup(&bdi->cgwb_tree, memcg_css->id);
792 if (wb) {
797 if (unlikely(wb->blkcg_css != blkcg_css || !wb_tryget(wb)))
798 wb = NULL;
803 return wb;
807 * wb_get_create - get wb for a given memcg, create if necessary
812 * Try to get the wb for @memcg_css on @bdi. If it doesn't exist, try to
819 struct bdi_writeback *wb;
824 wb = wb_get_lookup(bdi, memcg_css);
825 } while (!wb && !cgwb_create(bdi, memcg_css, gfp));
827 return wb;
838 ret = wb_init(&bdi->wb, bdi, GFP_KERNEL);
840 bdi->wb.memcg_css = &root_mem_cgroup->css;
841 bdi->wb.blkcg_css = blkcg_root_css;
850 struct bdi_writeback *wb;
852 WARN_ON(test_bit(WB_registered, &bdi->wb.state));
862 wb = list_first_entry(&bdi->wb_list, struct bdi_writeback,
865 wb_shutdown(wb);
881 struct bdi_writeback *wb;
887 wb = list_first_entry(&offline_cgwbs, struct bdi_writeback,
889 list_move(&wb->offline_node, &processed);
892 * If wb is dirty, cleaning up the writeback by switching
900 if (wb_has_dirty_io(wb))
903 if (!wb_tryget(wb))
907 while (cleanup_offline_cgwb(wb))
911 wb_put(wb);
921 * wb_memcg_offline - kill all wb's associated with a memcg being offlined
924 * Also prevents creation of any new wb's associated with @memcg.
929 struct bdi_writeback *wb, *next;
932 list_for_each_entry_safe(wb, next, memcg_cgwb_list, memcg_node)
933 cgwb_kill(wb);
934 memcg_cgwb_list->next = NULL; /* prevent new wb's */
941 * wb_blkcg_offline - kill all wb's associated with a blkcg being offlined
944 * Also prevents creation of any new wb's associated with @blkcg.
948 struct bdi_writeback *wb, *next;
952 list_for_each_entry_safe(wb, next, list, blkcg_node)
953 cgwb_kill(wb);
954 list->next = NULL; /* prevent new wb's */
961 list_add_tail_rcu(&bdi->wb.bdi_node, &bdi->wb_list);
984 return wb_init(&bdi->wb, bdi, GFP_KERNEL);
991 list_add_tail_rcu(&bdi->wb.bdi_node, &bdi->wb_list);
994 static void cgwb_remove_from_bdi_list(struct bdi_writeback *wb)
996 list_del_rcu(&wb->bdi_node);
1102 set_bit(WB_registered, &bdi->wb.state);
1158 wb_shutdown(&bdi->wb);
1186 WARN_ON_ONCE(test_bit(WB_registered, &bdi->wb.state));
1188 wb_exit(&bdi->wb);