Lines Matching refs:wb
85 static bool wb_io_lists_populated(struct bdi_writeback *wb)
87 if (wb_has_dirty_io(wb)) {
90 set_bit(WB_has_dirty_io, &wb->state);
91 WARN_ON_ONCE(!wb->avg_write_bandwidth);
92 atomic_long_add(wb->avg_write_bandwidth,
93 &wb->bdi->tot_write_bandwidth);
98 static void wb_io_lists_depopulated(struct bdi_writeback *wb)
100 if (wb_has_dirty_io(wb) && list_empty(&wb->b_dirty) &&
101 list_empty(&wb->b_io) && list_empty(&wb->b_more_io)) {
102 clear_bit(WB_has_dirty_io, &wb->state);
103 WARN_ON_ONCE(atomic_long_sub_return(wb->avg_write_bandwidth,
104 &wb->bdi->tot_write_bandwidth) < 0);
111 * @wb: target bdi_writeback
112 * @head: one of @wb->b_{dirty|io|more_io|dirty_time}
114 * Move @inode->i_io_list to @list of @wb and set %WB_has_dirty_io.
119 struct bdi_writeback *wb,
122 assert_spin_locked(&wb->list_lock);
129 if (head != &wb->b_dirty_time)
130 return wb_io_lists_populated(wb);
132 wb_io_lists_depopulated(wb);
136 static void wb_wakeup(struct bdi_writeback *wb)
138 spin_lock_irq(&wb->work_lock);
139 if (test_bit(WB_registered, &wb->state))
140 mod_delayed_work(bdi_wq, &wb->dwork, 0);
141 spin_unlock_irq(&wb->work_lock);
144 static void finish_writeback_work(struct bdi_writeback *wb,
160 static void wb_queue_work(struct bdi_writeback *wb,
163 trace_writeback_queue(wb, work);
168 spin_lock_irq(&wb->work_lock);
170 if (test_bit(WB_registered, &wb->state)) {
171 list_add_tail(&work->list, &wb->work_list);
172 mod_delayed_work(bdi_wq, &wb->dwork, 0);
174 finish_writeback_work(wb, work);
176 spin_unlock_irq(&wb->work_lock);
243 struct bdi_writeback *wb = NULL;
250 wb = wb_get_create(bdi, memcg_css, GFP_ATOMIC);
254 wb = wb_get_create(bdi, memcg_css, GFP_ATOMIC);
259 if (!wb)
260 wb = &bdi->wb;
266 if (unlikely(cmpxchg(&inode->i_wb, NULL, wb)))
267 wb_put(wb);
272 * inode_cgwb_move_to_attached - put the inode onto wb->b_attached list
274 * @wb: target bdi_writeback
276 * Remove the inode from wb's io lists and if necessarily put onto b_attached
280 struct bdi_writeback *wb)
282 assert_spin_locked(&wb->list_lock);
287 if (wb != &wb->bdi->wb)
288 list_move(&inode->i_io_list, &wb->b_attached);
291 wb_io_lists_depopulated(wb);
295 * locked_inode_to_wb_and_lock_list - determine a locked inode's wb and lock it
298 * Returns @inode's wb with its list_lock held. @inode->i_lock must be
299 * held on entry and is released on return. The returned wb is guaranteed
300 * to stay @inode's associated wb until its list_lock is released.
305 __acquires(&wb->list_lock)
308 struct bdi_writeback *wb = inode_to_wb(inode);
312 * @inode->i_lock and @wb->list_lock but list_lock nests
316 wb_get(wb);
318 spin_lock(&wb->list_lock);
321 if (likely(wb == inode->i_wb)) {
322 wb_put(wb); /* @inode already has ref */
323 return wb;
326 spin_unlock(&wb->list_lock);
327 wb_put(wb);
334 * inode_to_wb_and_lock_list - determine an inode's wb and lock it
341 __acquires(&wb->list_lock)
456 * ensures that the new wb is visible if they see !I_WB_SWITCH.
484 * since I_WB_SWITCH assertion and all wb stat update transactions
489 * gives us exclusion against all wb related operations on @inode
553 * inode_switch_wbs - change the wb association of an inode
555 * @new_wb_id: ID of the new wb
557 * Switch @inode's wb association to the wb identified by @new_wb_id. The
580 /* find and pin the new wb */
636 * @wb: target wb
638 * Switch all inodes attached to @wb to a nearest living ancestor's wb in order
639 * to eventually release the dying @wb. Returns %true if not all inodes were
642 bool cleanup_offline_cgwb(struct bdi_writeback *wb)
656 for (memcg_css = wb->memcg_css->parent; memcg_css;
658 isw->new_wb = wb_get_create(wb->bdi, memcg_css, GFP_KERNEL);
663 isw->new_wb = &wb->bdi->wb; /* wb_get() is noop for bdi's wb */
666 spin_lock(&wb->list_lock);
675 restart = isw_prepare_wbs_switch(isw, &wb->b_attached, &nr);
677 restart = isw_prepare_wbs_switch(isw, &wb->b_dirty_time, &nr);
678 spin_unlock(&wb->list_lock);
718 wbc->wb = inode_to_wb(inode);
721 wbc->wb_id = wbc->wb->memcg_css->id;
728 wb_get(wbc->wb);
732 * A dying wb indicates that either the blkcg associated with the
734 * case, a replacement wb should already be available and we should
735 * refresh the wb immediately. In the second case, trying to
738 if (unlikely(wb_dying(wbc->wb) && !css_is_dying(wbc->wb->memcg_css)))
769 * current wb and the last round's winner wb (max of last round's current
770 * wb, the winner from two rounds ago, and the last round's majority
782 struct bdi_writeback *wb = wbc->wb;
788 if (!wb)
815 wb->avg_write_bandwidth);
826 * The switch verdict is reached if foreign wb's consume
843 * Switch if the current wb isn't the consistent winner.
847 * the wrong wb for an extended period of time.
861 wb_put(wbc->wb);
862 wbc->wb = NULL;
889 if (!wbc->wb || wbc->no_cgroup_owner)
920 * @wb: target bdi_writeback to split @nr_pages to
923 * Split @wb's portion of @nr_pages according to @wb's write bandwidth in
924 * relation to the total write bandwidth of all wb's w/ dirty inodes on
925 * @wb->bdi.
927 static long wb_split_bdi_pages(struct bdi_writeback *wb, long nr_pages)
929 unsigned long this_bw = wb->avg_write_bandwidth;
930 unsigned long tot_bw = atomic_long_read(&wb->bdi->tot_write_bandwidth);
936 * This may be called on clean wb's and proportional distribution
947 * bdi_split_work_to_wbs - split a wb_writeback_work to all wb's of a bdi
950 * @skip_if_busy: skip wb's which already have writeback in progress
952 * Split and issue @base_work to all wb's (bdi_writeback's) of @bdi which
954 * distributed to the busy wbs according to each wb's proportion in the
962 struct bdi_writeback *wb = list_entry(&bdi->wb_list,
968 list_for_each_entry_continue_rcu(wb, &bdi->wb_list, bdi_node) {
980 if (!wb_has_dirty_io(wb) &&
982 list_empty(&wb->b_dirty_time)))
984 if (skip_if_busy && writeback_in_progress(wb))
987 nr_pages = wb_split_bdi_pages(wb, base_work->nr_pages);
994 wb_queue_work(wb, work);
999 * If wb_tryget fails, the wb has been shutdown, skip it.
1001 * Pin @wb so that it stays on @bdi->wb_list. This allows
1002 * continuing iteration from @wb after dropping and
1005 if (!wb_tryget(wb))
1015 wb_queue_work(wb, work);
1016 last_wb = wb;
1043 struct bdi_writeback *wb;
1064 * And find the associated wb. If the wb isn't there already
1067 wb = wb_get_lookup(bdi, memcg_css);
1068 if (!wb) {
1095 wb_queue_work(wb, work);
1101 wb_put(wb);
1110 * cgroup_writeback_umount - flush inode wb switches for umount
1113 * flushes in-flight inode wb switches. An inode wb switch goes through
1115 * that all previously scheduled switches are finished. As wb switches are
1117 * flushing iff wb switches are in flight.
1130 * ensure that all in-flight wb switches are in the workqueue.
1152 struct bdi_writeback *wb)
1154 assert_spin_locked(&wb->list_lock);
1160 wb_io_lists_depopulated(wb);
1166 __acquires(&wb->list_lock)
1168 struct bdi_writeback *wb = inode_to_wb(inode);
1171 spin_lock(&wb->list_lock);
1172 return wb;
1176 __acquires(&wb->list_lock)
1178 struct bdi_writeback *wb = inode_to_wb(inode);
1180 spin_lock(&wb->list_lock);
1181 return wb;
1184 static long wb_split_bdi_pages(struct bdi_writeback *wb, long nr_pages)
1195 if (!skip_if_busy || !writeback_in_progress(&bdi->wb)) {
1197 wb_queue_work(&bdi->wb, base_work);
1213 static void wb_start_writeback(struct bdi_writeback *wb, enum wb_reason reason)
1215 if (!wb_has_dirty_io(wb))
1226 if (test_bit(WB_start_all, &wb->state) ||
1227 test_and_set_bit(WB_start_all, &wb->state))
1230 wb->start_all_reason = reason;
1231 wb_wakeup(wb);
1236 * @wb: bdi_writback to write from
1240 * this function returns, it is only guaranteed that for given wb
1244 void wb_start_background_writeback(struct bdi_writeback *wb)
1250 trace_writeback_wake_background(wb);
1251 wb_wakeup(wb);
1259 struct bdi_writeback *wb;
1261 wb = inode_to_wb_and_lock_list(inode);
1266 wb_io_lists_depopulated(wb);
1269 spin_unlock(&wb->list_lock);
1318 static void redirty_tail_locked(struct inode *inode, struct bdi_writeback *wb)
1330 wb_io_lists_depopulated(wb);
1333 if (!list_empty(&wb->b_dirty)) {
1336 tail = wb_inode(wb->b_dirty.next);
1340 inode_io_list_move_locked(inode, wb, &wb->b_dirty);
1343 static void redirty_tail(struct inode *inode, struct bdi_writeback *wb)
1346 redirty_tail_locked(inode, wb);
1353 static void requeue_io(struct inode *inode, struct bdi_writeback *wb)
1355 inode_io_list_move_locked(inode, wb, &wb->b_more_io);
1449 static void queue_io(struct bdi_writeback *wb, struct wb_writeback_work *work,
1455 assert_spin_locked(&wb->list_lock);
1456 list_splice_init(&wb->b_more_io, &wb->b_io);
1457 moved = move_expired_inodes(&wb->b_dirty, &wb->b_io, dirtied_before);
1460 moved += move_expired_inodes(&wb->b_dirty_time, &wb->b_io,
1463 wb_io_lists_populated(wb);
1464 trace_writeback_queue_io(wb, work, dirtied_before, moved);
1538 static void requeue_inode(struct inode *inode, struct bdi_writeback *wb,
1561 redirty_tail_locked(inode, wb);
1563 inode_cgwb_move_to_attached(inode, wb);
1574 requeue_io(inode, wb);
1583 redirty_tail_locked(inode, wb);
1591 redirty_tail_locked(inode, wb);
1594 inode_io_list_move_locked(inode, wb, &wb->b_dirty_time);
1598 inode_cgwb_move_to_attached(inode, wb);
1711 struct bdi_writeback *wb;
1750 wb = inode_to_wb_and_lock_list(inode);
1763 inode_cgwb_move_to_attached(inode, wb);
1766 redirty_tail_locked(inode, wb);
1770 wb,
1771 &wb->b_dirty_time);
1776 spin_unlock(&wb->list_lock);
1783 static long writeback_chunk_size(struct bdi_writeback *wb,
1804 pages = min(wb->avg_write_bandwidth / 2,
1819 * NOTE! This is called with wb->list_lock held, and will
1824 struct bdi_writeback *wb,
1841 while (!list_empty(&wb->b_io)) {
1842 struct inode *inode = wb_inode(wb->b_io.prev);
1853 redirty_tail(inode, wb);
1872 redirty_tail_locked(inode, wb);
1886 requeue_io(inode, wb);
1891 spin_unlock(&wb->list_lock);
1902 spin_lock(&wb->list_lock);
1908 write_chunk = writeback_chunk_size(wb, work);
1939 * have been switched to another wb in the meantime.
1949 if (unlikely(tmp_wb != wb)) {
1951 spin_lock(&wb->list_lock);
1968 static long __writeback_inodes_wb(struct bdi_writeback *wb,
1974 while (!list_empty(&wb->b_io)) {
1975 struct inode *inode = wb_inode(wb->b_io.prev);
1984 redirty_tail(inode, wb);
1987 wrote += writeback_sb_inodes(sb, wb, work);
2002 static long writeback_inodes_wb(struct bdi_writeback *wb, long nr_pages,
2014 spin_lock(&wb->list_lock);
2015 if (list_empty(&wb->b_io))
2016 queue_io(wb, &work, jiffies);
2017 __writeback_inodes_wb(wb, &work);
2018 spin_unlock(&wb->list_lock);
2039 static long wb_writeback(struct bdi_writeback *wb,
2063 !list_empty(&wb->work_list))
2070 if (work->for_background && !wb_over_bg_thresh(wb))
2074 spin_lock(&wb->list_lock);
2088 trace_writeback_start(wb, work);
2089 if (list_empty(&wb->b_io))
2090 queue_io(wb, work, dirtied_before);
2092 progress = writeback_sb_inodes(work->sb, wb, work);
2094 progress = __writeback_inodes_wb(wb, work);
2095 trace_writeback_written(wb, work);
2106 spin_unlock(&wb->list_lock);
2113 if (list_empty(&wb->b_more_io)) {
2114 spin_unlock(&wb->list_lock);
2123 trace_writeback_wait(wb, work);
2124 inode = wb_inode(wb->b_more_io.prev);
2126 spin_unlock(&wb->list_lock);
2138 static struct wb_writeback_work *get_next_work_item(struct bdi_writeback *wb)
2142 spin_lock_irq(&wb->work_lock);
2143 if (!list_empty(&wb->work_list)) {
2144 work = list_entry(wb->work_list.next,
2148 spin_unlock_irq(&wb->work_lock);
2152 static long wb_check_background_flush(struct bdi_writeback *wb)
2154 if (wb_over_bg_thresh(wb)) {
2164 return wb_writeback(wb, &work);
2170 static long wb_check_old_data_flush(struct bdi_writeback *wb)
2181 expired = wb->last_old_flush +
2186 wb->last_old_flush = jiffies;
2198 return wb_writeback(wb, &work);
2204 static long wb_check_start_all(struct bdi_writeback *wb)
2208 if (!test_bit(WB_start_all, &wb->state))
2214 .nr_pages = wb_split_bdi_pages(wb, nr_pages),
2217 .reason = wb->start_all_reason,
2220 nr_pages = wb_writeback(wb, &work);
2223 clear_bit(WB_start_all, &wb->state);
2231 static long wb_do_writeback(struct bdi_writeback *wb)
2236 set_bit(WB_writeback_running, &wb->state);
2237 while ((work = get_next_work_item(wb)) != NULL) {
2238 trace_writeback_exec(wb, work);
2239 wrote += wb_writeback(wb, work);
2240 finish_writeback_work(wb, work);
2246 wrote += wb_check_start_all(wb);
2251 wrote += wb_check_old_data_flush(wb);
2252 wrote += wb_check_background_flush(wb);
2253 clear_bit(WB_writeback_running, &wb->state);
2264 struct bdi_writeback *wb = container_of(to_delayed_work(work),
2268 set_worker_desc("flush-%s", bdi_dev_name(wb->bdi));
2271 !test_bit(WB_registered, &wb->state))) {
2273 * The normal path. Keep writing back @wb until its
2275 * if @wb is shutting down even when we're running off the
2279 pages_written = wb_do_writeback(wb);
2281 } while (!list_empty(&wb->work_list));
2288 pages_written = writeback_inodes_wb(wb, 1024,
2293 if (!list_empty(&wb->work_list))
2294 wb_wakeup(wb);
2295 else if (wb_has_dirty_io(wb) && dirty_writeback_interval)
2296 wb_wakeup_delayed(wb);
2306 struct bdi_writeback *wb;
2311 list_for_each_entry_rcu(wb, &bdi->wb_list, bdi_node)
2312 wb_start_writeback(wb, reason);
2365 struct bdi_writeback *wb;
2367 list_for_each_entry_rcu(wb, &bdi->wb_list, bdi_node)
2368 if (!list_empty(&wb->b_dirty_time))
2369 wb_wakeup(wb);
2424 struct bdi_writeback *wb = NULL;
2486 * Grab inode's wb early because it requires dropping i_lock and we
2492 wb = locked_inode_to_wb_and_lock_list(inode);
2529 dirty_list = &wb->b_dirty;
2531 dirty_list = &wb->b_dirty_time;
2533 wakeup_bdi = inode_io_list_move_locked(inode, wb,
2536 spin_unlock(&wb->list_lock);
2547 (wb->bdi->capabilities & BDI_CAP_WRITEBACK))
2548 wb_wakeup_delayed(wb);
2553 if (wb)
2554 spin_unlock(&wb->list_lock);
2606 * Move each inode back to the wb list before we drop the lock
2615 * do not have the mapping lock. Skip it here, wb completion
2755 /* protect against inode wb switch, see inode_switch_wbs_work_fn() */