Lines Matching refs:wb
85 static bool wb_io_lists_populated(struct bdi_writeback *wb) in wb_io_lists_populated() argument
87 if (wb_has_dirty_io(wb)) { in wb_io_lists_populated()
90 set_bit(WB_has_dirty_io, &wb->state); in wb_io_lists_populated()
91 WARN_ON_ONCE(!wb->avg_write_bandwidth); in wb_io_lists_populated()
92 atomic_long_add(wb->avg_write_bandwidth, in wb_io_lists_populated()
93 &wb->bdi->tot_write_bandwidth); in wb_io_lists_populated()
98 static void wb_io_lists_depopulated(struct bdi_writeback *wb) in wb_io_lists_depopulated() argument
100 if (wb_has_dirty_io(wb) && list_empty(&wb->b_dirty) && in wb_io_lists_depopulated()
101 list_empty(&wb->b_io) && list_empty(&wb->b_more_io)) { in wb_io_lists_depopulated()
102 clear_bit(WB_has_dirty_io, &wb->state); in wb_io_lists_depopulated()
103 WARN_ON_ONCE(atomic_long_sub_return(wb->avg_write_bandwidth, in wb_io_lists_depopulated()
104 &wb->bdi->tot_write_bandwidth) < 0); in wb_io_lists_depopulated()
119 struct bdi_writeback *wb, in inode_io_list_move_locked() argument
122 assert_spin_locked(&wb->list_lock); in inode_io_list_move_locked()
128 if (head != &wb->b_dirty_time) in inode_io_list_move_locked()
129 return wb_io_lists_populated(wb); in inode_io_list_move_locked()
131 wb_io_lists_depopulated(wb); in inode_io_list_move_locked()
135 static void wb_wakeup(struct bdi_writeback *wb) in wb_wakeup() argument
137 spin_lock_irq(&wb->work_lock); in wb_wakeup()
138 if (test_bit(WB_registered, &wb->state)) in wb_wakeup()
139 mod_delayed_work(bdi_wq, &wb->dwork, 0); in wb_wakeup()
140 spin_unlock_irq(&wb->work_lock); in wb_wakeup()
143 static void finish_writeback_work(struct bdi_writeback *wb, in finish_writeback_work() argument
159 static void wb_queue_work(struct bdi_writeback *wb, in wb_queue_work() argument
162 trace_writeback_queue(wb, work); in wb_queue_work()
167 spin_lock_irq(&wb->work_lock); in wb_queue_work()
169 if (test_bit(WB_registered, &wb->state)) { in wb_queue_work()
170 list_add_tail(&work->list, &wb->work_list); in wb_queue_work()
171 mod_delayed_work(bdi_wq, &wb->dwork, 0); in wb_queue_work()
173 finish_writeback_work(wb, work); in wb_queue_work()
175 spin_unlock_irq(&wb->work_lock); in wb_queue_work()
242 struct bdi_writeback *wb = NULL; in __inode_attach_wb() local
249 wb = wb_get_create(bdi, memcg_css, GFP_ATOMIC); in __inode_attach_wb()
253 wb = wb_get_create(bdi, memcg_css, GFP_ATOMIC); in __inode_attach_wb()
258 if (!wb) in __inode_attach_wb()
259 wb = &bdi->wb; in __inode_attach_wb()
265 if (unlikely(cmpxchg(&inode->i_wb, NULL, wb))) in __inode_attach_wb()
266 wb_put(wb); in __inode_attach_wb()
279 struct bdi_writeback *wb) in inode_cgwb_move_to_attached() argument
281 assert_spin_locked(&wb->list_lock); in inode_cgwb_move_to_attached()
285 if (wb != &wb->bdi->wb) in inode_cgwb_move_to_attached()
286 list_move(&inode->i_io_list, &wb->b_attached); in inode_cgwb_move_to_attached()
289 wb_io_lists_depopulated(wb); in inode_cgwb_move_to_attached()
303 __acquires(&wb->list_lock) in locked_inode_to_wb_and_lock_list()
306 struct bdi_writeback *wb = inode_to_wb(inode); in locked_inode_to_wb_and_lock_list() local
314 wb_get(wb); in locked_inode_to_wb_and_lock_list()
316 spin_lock(&wb->list_lock); in locked_inode_to_wb_and_lock_list()
319 if (likely(wb == inode->i_wb)) { in locked_inode_to_wb_and_lock_list()
320 wb_put(wb); /* @inode already has ref */ in locked_inode_to_wb_and_lock_list()
321 return wb; in locked_inode_to_wb_and_lock_list()
324 spin_unlock(&wb->list_lock); in locked_inode_to_wb_and_lock_list()
325 wb_put(wb); in locked_inode_to_wb_and_lock_list()
339 __acquires(&wb->list_lock) in inode_to_wb_and_lock_list()
638 bool cleanup_offline_cgwb(struct bdi_writeback *wb) in cleanup_offline_cgwb() argument
652 for (memcg_css = wb->memcg_css->parent; memcg_css; in cleanup_offline_cgwb()
654 isw->new_wb = wb_get_create(wb->bdi, memcg_css, GFP_KERNEL); in cleanup_offline_cgwb()
659 isw->new_wb = &wb->bdi->wb; /* wb_get() is noop for bdi's wb */ in cleanup_offline_cgwb()
662 spin_lock(&wb->list_lock); in cleanup_offline_cgwb()
671 restart = isw_prepare_wbs_switch(isw, &wb->b_attached, &nr); in cleanup_offline_cgwb()
673 restart = isw_prepare_wbs_switch(isw, &wb->b_dirty_time, &nr); in cleanup_offline_cgwb()
674 spin_unlock(&wb->list_lock); in cleanup_offline_cgwb()
714 wbc->wb = inode_to_wb(inode); in wbc_attach_and_unlock_inode()
717 wbc->wb_id = wbc->wb->memcg_css->id; in wbc_attach_and_unlock_inode()
724 wb_get(wbc->wb); in wbc_attach_and_unlock_inode()
734 if (unlikely(wb_dying(wbc->wb) && !css_is_dying(wbc->wb->memcg_css))) in wbc_attach_and_unlock_inode()
778 struct bdi_writeback *wb = wbc->wb; in wbc_detach_inode() local
784 if (!wb) in wbc_detach_inode()
811 wb->avg_write_bandwidth); in wbc_detach_inode()
857 wb_put(wbc->wb); in wbc_detach_inode()
858 wbc->wb = NULL; in wbc_detach_inode()
884 if (!wbc->wb || wbc->no_cgroup_owner) in wbc_account_cgroup_owner()
935 struct bdi_writeback *wb; in inode_congested() local
939 wb = unlocked_inode_to_wb_begin(inode, &lock_cookie); in inode_congested()
940 congested = wb_congested(wb, cong_bits); in inode_congested()
945 return wb_congested(&inode_to_bdi(inode)->wb, cong_bits); in inode_congested()
958 static long wb_split_bdi_pages(struct bdi_writeback *wb, long nr_pages) in wb_split_bdi_pages() argument
960 unsigned long this_bw = wb->avg_write_bandwidth; in wb_split_bdi_pages()
961 unsigned long tot_bw = atomic_long_read(&wb->bdi->tot_write_bandwidth); in wb_split_bdi_pages()
993 struct bdi_writeback *wb = list_entry(&bdi->wb_list, in bdi_split_work_to_wbs() local
999 list_for_each_entry_continue_rcu(wb, &bdi->wb_list, bdi_node) { in bdi_split_work_to_wbs()
1011 if (!wb_has_dirty_io(wb) && in bdi_split_work_to_wbs()
1013 list_empty(&wb->b_dirty_time))) in bdi_split_work_to_wbs()
1015 if (skip_if_busy && writeback_in_progress(wb)) in bdi_split_work_to_wbs()
1018 nr_pages = wb_split_bdi_pages(wb, base_work->nr_pages); in bdi_split_work_to_wbs()
1025 wb_queue_work(wb, work); in bdi_split_work_to_wbs()
1036 if (!wb_tryget(wb)) in bdi_split_work_to_wbs()
1046 wb_queue_work(wb, work); in bdi_split_work_to_wbs()
1047 last_wb = wb; in bdi_split_work_to_wbs()
1074 struct bdi_writeback *wb; in cgroup_writeback_by_id() local
1098 wb = wb_get_lookup(bdi, memcg_css); in cgroup_writeback_by_id()
1099 if (!wb) { in cgroup_writeback_by_id()
1126 wb_queue_work(wb, work); in cgroup_writeback_by_id()
1132 wb_put(wb); in cgroup_writeback_by_id()
1183 struct bdi_writeback *wb) in inode_cgwb_move_to_attached() argument
1185 assert_spin_locked(&wb->list_lock); in inode_cgwb_move_to_attached()
1190 wb_io_lists_depopulated(wb); in inode_cgwb_move_to_attached()
1196 __acquires(&wb->list_lock) in locked_inode_to_wb_and_lock_list()
1198 struct bdi_writeback *wb = inode_to_wb(inode); in locked_inode_to_wb_and_lock_list() local
1201 spin_lock(&wb->list_lock); in locked_inode_to_wb_and_lock_list()
1202 return wb; in locked_inode_to_wb_and_lock_list()
1206 __acquires(&wb->list_lock) in inode_to_wb_and_lock_list()
1208 struct bdi_writeback *wb = inode_to_wb(inode); in inode_to_wb_and_lock_list() local
1210 spin_lock(&wb->list_lock); in inode_to_wb_and_lock_list()
1211 return wb; in inode_to_wb_and_lock_list()
1214 static long wb_split_bdi_pages(struct bdi_writeback *wb, long nr_pages) in wb_split_bdi_pages() argument
1225 if (!skip_if_busy || !writeback_in_progress(&bdi->wb)) { in bdi_split_work_to_wbs()
1227 wb_queue_work(&bdi->wb, base_work); in bdi_split_work_to_wbs()
1243 static void wb_start_writeback(struct bdi_writeback *wb, enum wb_reason reason) in wb_start_writeback() argument
1245 if (!wb_has_dirty_io(wb)) in wb_start_writeback()
1256 if (test_bit(WB_start_all, &wb->state) || in wb_start_writeback()
1257 test_and_set_bit(WB_start_all, &wb->state)) in wb_start_writeback()
1260 wb->start_all_reason = reason; in wb_start_writeback()
1261 wb_wakeup(wb); in wb_start_writeback()
1274 void wb_start_background_writeback(struct bdi_writeback *wb) in wb_start_background_writeback() argument
1280 trace_writeback_wake_background(wb); in wb_start_background_writeback()
1281 wb_wakeup(wb); in wb_start_background_writeback()
1289 struct bdi_writeback *wb; in inode_io_list_del() local
1291 wb = inode_to_wb_and_lock_list(inode); in inode_io_list_del()
1296 wb_io_lists_depopulated(wb); in inode_io_list_del()
1299 spin_unlock(&wb->list_lock); in inode_io_list_del()
1348 static void redirty_tail_locked(struct inode *inode, struct bdi_writeback *wb) in redirty_tail_locked() argument
1352 if (!list_empty(&wb->b_dirty)) { in redirty_tail_locked()
1355 tail = wb_inode(wb->b_dirty.next); in redirty_tail_locked()
1359 inode_io_list_move_locked(inode, wb, &wb->b_dirty); in redirty_tail_locked()
1363 static void redirty_tail(struct inode *inode, struct bdi_writeback *wb) in redirty_tail() argument
1366 redirty_tail_locked(inode, wb); in redirty_tail()
1373 static void requeue_io(struct inode *inode, struct bdi_writeback *wb) in requeue_io() argument
1375 inode_io_list_move_locked(inode, wb, &wb->b_more_io); in requeue_io()
1471 static void queue_io(struct bdi_writeback *wb, struct wb_writeback_work *work, in queue_io() argument
1477 assert_spin_locked(&wb->list_lock); in queue_io()
1478 list_splice_init(&wb->b_more_io, &wb->b_io); in queue_io()
1479 moved = move_expired_inodes(&wb->b_dirty, &wb->b_io, dirtied_before); in queue_io()
1482 moved += move_expired_inodes(&wb->b_dirty_time, &wb->b_io, in queue_io()
1485 wb_io_lists_populated(wb); in queue_io()
1486 trace_writeback_queue_io(wb, work, dirtied_before, moved); in queue_io()
1560 static void requeue_inode(struct inode *inode, struct bdi_writeback *wb, in requeue_inode() argument
1583 redirty_tail_locked(inode, wb); in requeue_inode()
1585 inode_cgwb_move_to_attached(inode, wb); in requeue_inode()
1596 requeue_io(inode, wb); in requeue_inode()
1605 redirty_tail_locked(inode, wb); in requeue_inode()
1613 redirty_tail_locked(inode, wb); in requeue_inode()
1616 inode_io_list_move_locked(inode, wb, &wb->b_dirty_time); in requeue_inode()
1620 inode_cgwb_move_to_attached(inode, wb); in requeue_inode()
1725 struct bdi_writeback *wb; in writeback_single_inode() local
1764 wb = inode_to_wb_and_lock_list(inode); in writeback_single_inode()
1777 inode_cgwb_move_to_attached(inode, wb); in writeback_single_inode()
1780 redirty_tail_locked(inode, wb); in writeback_single_inode()
1784 wb, in writeback_single_inode()
1785 &wb->b_dirty_time); in writeback_single_inode()
1790 spin_unlock(&wb->list_lock); in writeback_single_inode()
1797 static long writeback_chunk_size(struct bdi_writeback *wb, in writeback_chunk_size() argument
1818 pages = min(wb->avg_write_bandwidth / 2, in writeback_chunk_size()
1838 struct bdi_writeback *wb, in writeback_sb_inodes() argument
1855 while (!list_empty(&wb->b_io)) { in writeback_sb_inodes()
1856 struct inode *inode = wb_inode(wb->b_io.prev); in writeback_sb_inodes()
1867 redirty_tail(inode, wb); in writeback_sb_inodes()
1886 redirty_tail_locked(inode, wb); in writeback_sb_inodes()
1900 requeue_io(inode, wb); in writeback_sb_inodes()
1905 spin_unlock(&wb->list_lock); in writeback_sb_inodes()
1916 spin_lock(&wb->list_lock); in writeback_sb_inodes()
1922 write_chunk = writeback_chunk_size(wb, work); in writeback_sb_inodes()
1963 if (unlikely(tmp_wb != wb)) { in writeback_sb_inodes()
1965 spin_lock(&wb->list_lock); in writeback_sb_inodes()
1982 static long __writeback_inodes_wb(struct bdi_writeback *wb, in __writeback_inodes_wb() argument
1988 while (!list_empty(&wb->b_io)) { in __writeback_inodes_wb()
1989 struct inode *inode = wb_inode(wb->b_io.prev); in __writeback_inodes_wb()
1998 redirty_tail(inode, wb); in __writeback_inodes_wb()
2001 wrote += writeback_sb_inodes(sb, wb, work); in __writeback_inodes_wb()
2016 static long writeback_inodes_wb(struct bdi_writeback *wb, long nr_pages, in writeback_inodes_wb() argument
2028 spin_lock(&wb->list_lock); in writeback_inodes_wb()
2029 if (list_empty(&wb->b_io)) in writeback_inodes_wb()
2030 queue_io(wb, &work, jiffies); in writeback_inodes_wb()
2031 __writeback_inodes_wb(wb, &work); in writeback_inodes_wb()
2032 spin_unlock(&wb->list_lock); in writeback_inodes_wb()
2053 static long wb_writeback(struct bdi_writeback *wb, in wb_writeback() argument
2063 spin_lock(&wb->list_lock); in wb_writeback()
2078 !list_empty(&wb->work_list)) in wb_writeback()
2085 if (work->for_background && !wb_over_bg_thresh(wb)) in wb_writeback()
2100 trace_writeback_start(wb, work); in wb_writeback()
2101 if (list_empty(&wb->b_io)) in wb_writeback()
2102 queue_io(wb, work, dirtied_before); in wb_writeback()
2104 progress = writeback_sb_inodes(work->sb, wb, work); in wb_writeback()
2106 progress = __writeback_inodes_wb(wb, work); in wb_writeback()
2107 trace_writeback_written(wb, work); in wb_writeback()
2122 if (list_empty(&wb->b_more_io)) in wb_writeback()
2129 trace_writeback_wait(wb, work); in wb_writeback()
2130 inode = wb_inode(wb->b_more_io.prev); in wb_writeback()
2132 spin_unlock(&wb->list_lock); in wb_writeback()
2135 spin_lock(&wb->list_lock); in wb_writeback()
2137 spin_unlock(&wb->list_lock); in wb_writeback()
2146 static struct wb_writeback_work *get_next_work_item(struct bdi_writeback *wb) in get_next_work_item() argument
2150 spin_lock_irq(&wb->work_lock); in get_next_work_item()
2151 if (!list_empty(&wb->work_list)) { in get_next_work_item()
2152 work = list_entry(wb->work_list.next, in get_next_work_item()
2156 spin_unlock_irq(&wb->work_lock); in get_next_work_item()
2160 static long wb_check_background_flush(struct bdi_writeback *wb) in wb_check_background_flush() argument
2162 if (wb_over_bg_thresh(wb)) { in wb_check_background_flush()
2172 return wb_writeback(wb, &work); in wb_check_background_flush()
2178 static long wb_check_old_data_flush(struct bdi_writeback *wb) in wb_check_old_data_flush() argument
2189 expired = wb->last_old_flush + in wb_check_old_data_flush()
2194 wb->last_old_flush = jiffies; in wb_check_old_data_flush()
2206 return wb_writeback(wb, &work); in wb_check_old_data_flush()
2212 static long wb_check_start_all(struct bdi_writeback *wb) in wb_check_start_all() argument
2216 if (!test_bit(WB_start_all, &wb->state)) in wb_check_start_all()
2222 .nr_pages = wb_split_bdi_pages(wb, nr_pages), in wb_check_start_all()
2225 .reason = wb->start_all_reason, in wb_check_start_all()
2228 nr_pages = wb_writeback(wb, &work); in wb_check_start_all()
2231 clear_bit(WB_start_all, &wb->state); in wb_check_start_all()
2239 static long wb_do_writeback(struct bdi_writeback *wb) in wb_do_writeback() argument
2244 set_bit(WB_writeback_running, &wb->state); in wb_do_writeback()
2245 while ((work = get_next_work_item(wb)) != NULL) { in wb_do_writeback()
2246 trace_writeback_exec(wb, work); in wb_do_writeback()
2247 wrote += wb_writeback(wb, work); in wb_do_writeback()
2248 finish_writeback_work(wb, work); in wb_do_writeback()
2254 wrote += wb_check_start_all(wb); in wb_do_writeback()
2259 wrote += wb_check_old_data_flush(wb); in wb_do_writeback()
2260 wrote += wb_check_background_flush(wb); in wb_do_writeback()
2261 clear_bit(WB_writeback_running, &wb->state); in wb_do_writeback()
2272 struct bdi_writeback *wb = container_of(to_delayed_work(work), in wb_workfn() local
2276 set_worker_desc("flush-%s", bdi_dev_name(wb->bdi)); in wb_workfn()
2280 !test_bit(WB_registered, &wb->state))) { in wb_workfn()
2288 pages_written = wb_do_writeback(wb); in wb_workfn()
2290 } while (!list_empty(&wb->work_list)); in wb_workfn()
2297 pages_written = writeback_inodes_wb(wb, 1024, in wb_workfn()
2302 if (!list_empty(&wb->work_list)) in wb_workfn()
2303 wb_wakeup(wb); in wb_workfn()
2304 else if (wb_has_dirty_io(wb) && dirty_writeback_interval) in wb_workfn()
2305 wb_wakeup_delayed(wb); in wb_workfn()
2317 struct bdi_writeback *wb; in __wakeup_flusher_threads_bdi() local
2322 list_for_each_entry_rcu(wb, &bdi->wb_list, bdi_node) in __wakeup_flusher_threads_bdi()
2323 wb_start_writeback(wb, reason); in __wakeup_flusher_threads_bdi()
2377 struct bdi_writeback *wb; in wakeup_dirtytime_writeback() local
2379 list_for_each_entry_rcu(wb, &bdi->wb_list, bdi_node) in wakeup_dirtytime_writeback()
2380 if (!list_empty(&wb->b_dirty_time)) in wakeup_dirtytime_writeback()
2381 wb_wakeup(wb); in wakeup_dirtytime_writeback()
2436 struct bdi_writeback *wb = NULL; in __mark_inode_dirty() local
2504 wb = locked_inode_to_wb_and_lock_list(inode); in __mark_inode_dirty()
2541 dirty_list = &wb->b_dirty; in __mark_inode_dirty()
2543 dirty_list = &wb->b_dirty_time; in __mark_inode_dirty()
2545 wakeup_bdi = inode_io_list_move_locked(inode, wb, in __mark_inode_dirty()
2548 spin_unlock(&wb->list_lock); in __mark_inode_dirty()
2559 (wb->bdi->capabilities & BDI_CAP_WRITEBACK)) in __mark_inode_dirty()
2560 wb_wakeup_delayed(wb); in __mark_inode_dirty()
2565 if (wb) in __mark_inode_dirty()
2566 spin_unlock(&wb->list_lock); in __mark_inode_dirty()