Skip to content

Commit 208bca0

Browse files
committed
Merge branch 'writeback-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/wfg/linux
* 'writeback-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/wfg/linux: writeback: Add a 'reason' to wb_writeback_work writeback: send work item to queue_io, move_expired_inodes writeback: trace event balance_dirty_pages writeback: trace event bdi_dirty_ratelimit writeback: fix ppc compile warnings on do_div(long long, unsigned long) writeback: per-bdi background threshold writeback: dirty position control - bdi reserve area writeback: control dirty pause time writeback: limit max dirty pause time writeback: IO-less balance_dirty_pages() writeback: per task dirty rate limit writeback: stabilize bdi->dirty_ratelimit writeback: dirty rate control writeback: add bg_threshold parameter to __bdi_update_bandwidth() writeback: dirty position control writeback: account per-bdi accumulated dirtied pages
2 parents 6aad373 + 0e175a1 commit 208bca0

File tree

15 files changed

+806
-225
lines changed

15 files changed

+806
-225
lines changed

fs/btrfs/extent-tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3340,7 +3340,8 @@ static int shrink_delalloc(struct btrfs_trans_handle *trans,
33403340
smp_mb();
33413341
nr_pages = min_t(unsigned long, nr_pages,
33423342
root->fs_info->delalloc_bytes >> PAGE_CACHE_SHIFT);
3343-
writeback_inodes_sb_nr_if_idle(root->fs_info->sb, nr_pages);
3343+
writeback_inodes_sb_nr_if_idle(root->fs_info->sb, nr_pages,
3344+
WB_REASON_FS_FREE_SPACE);
33443345

33453346
spin_lock(&space_info->lock);
33463347
if (reserved > space_info->bytes_reserved)

fs/buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static void free_more_memory(void)
288288
struct zone *zone;
289289
int nid;
290290

291-
wakeup_flusher_threads(1024);
291+
wakeup_flusher_threads(1024, WB_REASON_FREE_MORE_MEM);
292292
yield();
293293

294294
for_each_online_node(nid) {

fs/ext4/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,7 @@ static int ext4_nonda_switch(struct super_block *sb)
23722372
* start pushing delalloc when 1/2 of free blocks are dirty.
23732373
*/
23742374
if (free_blocks < 2 * dirty_blocks)
2375-
writeback_inodes_sb_if_idle(sb);
2375+
writeback_inodes_sb_if_idle(sb, WB_REASON_FS_FREE_SPACE);
23762376

23772377
return 0;
23782378
}

fs/fs-writeback.c

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,23 @@ struct wb_writeback_work {
4141
unsigned int for_kupdate:1;
4242
unsigned int range_cyclic:1;
4343
unsigned int for_background:1;
44+
enum wb_reason reason; /* why was writeback initiated? */
4445

4546
struct list_head list; /* pending work list */
4647
struct completion *done; /* set if the caller waits */
4748
};
4849

50+
const char *wb_reason_name[] = {
51+
[WB_REASON_BACKGROUND] = "background",
52+
[WB_REASON_TRY_TO_FREE_PAGES] = "try_to_free_pages",
53+
[WB_REASON_SYNC] = "sync",
54+
[WB_REASON_PERIODIC] = "periodic",
55+
[WB_REASON_LAPTOP_TIMER] = "laptop_timer",
56+
[WB_REASON_FREE_MORE_MEM] = "free_more_memory",
57+
[WB_REASON_FS_FREE_SPACE] = "fs_free_space",
58+
[WB_REASON_FORKER_THREAD] = "forker_thread"
59+
};
60+
4961
/*
5062
* Include the creation of the trace points after defining the
5163
* wb_writeback_work structure so that the definition remains local to this
@@ -115,7 +127,7 @@ static void bdi_queue_work(struct backing_dev_info *bdi,
115127

116128
static void
117129
__bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages,
118-
bool range_cyclic)
130+
bool range_cyclic, enum wb_reason reason)
119131
{
120132
struct wb_writeback_work *work;
121133

@@ -135,6 +147,7 @@ __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages,
135147
work->sync_mode = WB_SYNC_NONE;
136148
work->nr_pages = nr_pages;
137149
work->range_cyclic = range_cyclic;
150+
work->reason = reason;
138151

139152
bdi_queue_work(bdi, work);
140153
}
@@ -150,9 +163,10 @@ __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages,
150163
* completion. Caller need not hold sb s_umount semaphore.
151164
*
152165
*/
153-
void bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages)
166+
void bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages,
167+
enum wb_reason reason)
154168
{
155-
__bdi_start_writeback(bdi, nr_pages, true);
169+
__bdi_start_writeback(bdi, nr_pages, true, reason);
156170
}
157171

158172
/**
@@ -251,7 +265,7 @@ static bool inode_dirtied_after(struct inode *inode, unsigned long t)
251265
*/
252266
static int move_expired_inodes(struct list_head *delaying_queue,
253267
struct list_head *dispatch_queue,
254-
unsigned long *older_than_this)
268+
struct wb_writeback_work *work)
255269
{
256270
LIST_HEAD(tmp);
257271
struct list_head *pos, *node;
@@ -262,8 +276,8 @@ static int move_expired_inodes(struct list_head *delaying_queue,
262276

263277
while (!list_empty(delaying_queue)) {
264278
inode = wb_inode(delaying_queue->prev);
265-
if (older_than_this &&
266-
inode_dirtied_after(inode, *older_than_this))
279+
if (work->older_than_this &&
280+
inode_dirtied_after(inode, *work->older_than_this))
267281
break;
268282
if (sb && sb != inode->i_sb)
269283
do_sb_sort = 1;
@@ -302,13 +316,13 @@ static int move_expired_inodes(struct list_head *delaying_queue,
302316
* |
303317
* +--> dequeue for IO
304318
*/
305-
static void queue_io(struct bdi_writeback *wb, unsigned long *older_than_this)
319+
static void queue_io(struct bdi_writeback *wb, struct wb_writeback_work *work)
306320
{
307321
int moved;
308322
assert_spin_locked(&wb->list_lock);
309323
list_splice_init(&wb->b_more_io, &wb->b_io);
310-
moved = move_expired_inodes(&wb->b_dirty, &wb->b_io, older_than_this);
311-
trace_writeback_queue_io(wb, older_than_this, moved);
324+
moved = move_expired_inodes(&wb->b_dirty, &wb->b_io, work);
325+
trace_writeback_queue_io(wb, work, moved);
312326
}
313327

314328
static int write_inode(struct inode *inode, struct writeback_control *wbc)
@@ -641,31 +655,40 @@ static long __writeback_inodes_wb(struct bdi_writeback *wb,
641655
return wrote;
642656
}
643657

644-
long writeback_inodes_wb(struct bdi_writeback *wb, long nr_pages)
658+
long writeback_inodes_wb(struct bdi_writeback *wb, long nr_pages,
659+
enum wb_reason reason)
645660
{
646661
struct wb_writeback_work work = {
647662
.nr_pages = nr_pages,
648663
.sync_mode = WB_SYNC_NONE,
649664
.range_cyclic = 1,
665+
.reason = reason,
650666
};
651667

652668
spin_lock(&wb->list_lock);
653669
if (list_empty(&wb->b_io))
654-
queue_io(wb, NULL);
670+
queue_io(wb, &work);
655671
__writeback_inodes_wb(wb, &work);
656672
spin_unlock(&wb->list_lock);
657673

658674
return nr_pages - work.nr_pages;
659675
}
660676

661-
static inline bool over_bground_thresh(void)
677+
static bool over_bground_thresh(struct backing_dev_info *bdi)
662678
{
663679
unsigned long background_thresh, dirty_thresh;
664680

665681
global_dirty_limits(&background_thresh, &dirty_thresh);
666682

667-
return (global_page_state(NR_FILE_DIRTY) +
668-
global_page_state(NR_UNSTABLE_NFS) > background_thresh);
683+
if (global_page_state(NR_FILE_DIRTY) +
684+
global_page_state(NR_UNSTABLE_NFS) > background_thresh)
685+
return true;
686+
687+
if (bdi_stat(bdi, BDI_RECLAIMABLE) >
688+
bdi_dirty_limit(bdi, background_thresh))
689+
return true;
690+
691+
return false;
669692
}
670693

671694
/*
@@ -675,7 +698,7 @@ static inline bool over_bground_thresh(void)
675698
static void wb_update_bandwidth(struct bdi_writeback *wb,
676699
unsigned long start_time)
677700
{
678-
__bdi_update_bandwidth(wb->bdi, 0, 0, 0, 0, start_time);
701+
__bdi_update_bandwidth(wb->bdi, 0, 0, 0, 0, 0, start_time);
679702
}
680703

681704
/*
@@ -727,7 +750,7 @@ static long wb_writeback(struct bdi_writeback *wb,
727750
* For background writeout, stop when we are below the
728751
* background dirty threshold
729752
*/
730-
if (work->for_background && !over_bground_thresh())
753+
if (work->for_background && !over_bground_thresh(wb->bdi))
731754
break;
732755

733756
if (work->for_kupdate) {
@@ -738,7 +761,7 @@ static long wb_writeback(struct bdi_writeback *wb,
738761

739762
trace_writeback_start(wb->bdi, work);
740763
if (list_empty(&wb->b_io))
741-
queue_io(wb, work->older_than_this);
764+
queue_io(wb, work);
742765
if (work->sb)
743766
progress = writeback_sb_inodes(work->sb, wb, work);
744767
else
@@ -811,13 +834,14 @@ static unsigned long get_nr_dirty_pages(void)
811834

812835
static long wb_check_background_flush(struct bdi_writeback *wb)
813836
{
814-
if (over_bground_thresh()) {
837+
if (over_bground_thresh(wb->bdi)) {
815838

816839
struct wb_writeback_work work = {
817840
.nr_pages = LONG_MAX,
818841
.sync_mode = WB_SYNC_NONE,
819842
.for_background = 1,
820843
.range_cyclic = 1,
844+
.reason = WB_REASON_BACKGROUND,
821845
};
822846

823847
return wb_writeback(wb, &work);
@@ -851,6 +875,7 @@ static long wb_check_old_data_flush(struct bdi_writeback *wb)
851875
.sync_mode = WB_SYNC_NONE,
852876
.for_kupdate = 1,
853877
.range_cyclic = 1,
878+
.reason = WB_REASON_PERIODIC,
854879
};
855880

856881
return wb_writeback(wb, &work);
@@ -969,7 +994,7 @@ int bdi_writeback_thread(void *data)
969994
* Start writeback of `nr_pages' pages. If `nr_pages' is zero, write back
970995
* the whole world.
971996
*/
972-
void wakeup_flusher_threads(long nr_pages)
997+
void wakeup_flusher_threads(long nr_pages, enum wb_reason reason)
973998
{
974999
struct backing_dev_info *bdi;
9751000

@@ -982,7 +1007,7 @@ void wakeup_flusher_threads(long nr_pages)
9821007
list_for_each_entry_rcu(bdi, &bdi_list, bdi_list) {
9831008
if (!bdi_has_dirty_io(bdi))
9841009
continue;
985-
__bdi_start_writeback(bdi, nr_pages, false);
1010+
__bdi_start_writeback(bdi, nr_pages, false, reason);
9861011
}
9871012
rcu_read_unlock();
9881013
}
@@ -1203,7 +1228,9 @@ static void wait_sb_inodes(struct super_block *sb)
12031228
* on how many (if any) will be written, and this function does not wait
12041229
* for IO completion of submitted IO.
12051230
*/
1206-
void writeback_inodes_sb_nr(struct super_block *sb, unsigned long nr)
1231+
void writeback_inodes_sb_nr(struct super_block *sb,
1232+
unsigned long nr,
1233+
enum wb_reason reason)
12071234
{
12081235
DECLARE_COMPLETION_ONSTACK(done);
12091236
struct wb_writeback_work work = {
@@ -1212,6 +1239,7 @@ void writeback_inodes_sb_nr(struct super_block *sb, unsigned long nr)
12121239
.tagged_writepages = 1,
12131240
.done = &done,
12141241
.nr_pages = nr,
1242+
.reason = reason,
12151243
};
12161244

12171245
WARN_ON(!rwsem_is_locked(&sb->s_umount));
@@ -1228,9 +1256,9 @@ EXPORT_SYMBOL(writeback_inodes_sb_nr);
12281256
* on how many (if any) will be written, and this function does not wait
12291257
* for IO completion of submitted IO.
12301258
*/
1231-
void writeback_inodes_sb(struct super_block *sb)
1259+
void writeback_inodes_sb(struct super_block *sb, enum wb_reason reason)
12321260
{
1233-
return writeback_inodes_sb_nr(sb, get_nr_dirty_pages());
1261+
return writeback_inodes_sb_nr(sb, get_nr_dirty_pages(), reason);
12341262
}
12351263
EXPORT_SYMBOL(writeback_inodes_sb);
12361264

@@ -1241,11 +1269,11 @@ EXPORT_SYMBOL(writeback_inodes_sb);
12411269
* Invoke writeback_inodes_sb if no writeback is currently underway.
12421270
* Returns 1 if writeback was started, 0 if not.
12431271
*/
1244-
int writeback_inodes_sb_if_idle(struct super_block *sb)
1272+
int writeback_inodes_sb_if_idle(struct super_block *sb, enum wb_reason reason)
12451273
{
12461274
if (!writeback_in_progress(sb->s_bdi)) {
12471275
down_read(&sb->s_umount);
1248-
writeback_inodes_sb(sb);
1276+
writeback_inodes_sb(sb, reason);
12491277
up_read(&sb->s_umount);
12501278
return 1;
12511279
} else
@@ -1262,11 +1290,12 @@ EXPORT_SYMBOL(writeback_inodes_sb_if_idle);
12621290
* Returns 1 if writeback was started, 0 if not.
12631291
*/
12641292
int writeback_inodes_sb_nr_if_idle(struct super_block *sb,
1265-
unsigned long nr)
1293+
unsigned long nr,
1294+
enum wb_reason reason)
12661295
{
12671296
if (!writeback_in_progress(sb->s_bdi)) {
12681297
down_read(&sb->s_umount);
1269-
writeback_inodes_sb_nr(sb, nr);
1298+
writeback_inodes_sb_nr(sb, nr, reason);
12701299
up_read(&sb->s_umount);
12711300
return 1;
12721301
} else
@@ -1290,6 +1319,7 @@ void sync_inodes_sb(struct super_block *sb)
12901319
.nr_pages = LONG_MAX,
12911320
.range_cyclic = 0,
12921321
.done = &done,
1322+
.reason = WB_REASON_SYNC,
12931323
};
12941324

12951325
WARN_ON(!rwsem_is_locked(&sb->s_umount));

fs/quota/quota.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
286286
/* caller already holds s_umount */
287287
if (sb->s_flags & MS_RDONLY)
288288
return -EROFS;
289-
writeback_inodes_sb(sb);
289+
writeback_inodes_sb(sb, WB_REASON_SYNC);
290290
return 0;
291291
default:
292292
return -EINVAL;

fs/sync.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static int __sync_filesystem(struct super_block *sb, int wait)
4343
if (wait)
4444
sync_inodes_sb(sb);
4545
else
46-
writeback_inodes_sb(sb);
46+
writeback_inodes_sb(sb, WB_REASON_SYNC);
4747

4848
if (sb->s_op->sync_fs)
4949
sb->s_op->sync_fs(sb, wait);
@@ -98,7 +98,7 @@ static void sync_filesystems(int wait)
9898
*/
9999
SYSCALL_DEFINE0(sync)
100100
{
101-
wakeup_flusher_threads(0);
101+
wakeup_flusher_threads(0, WB_REASON_SYNC);
102102
sync_filesystems(0);
103103
sync_filesystems(1);
104104
if (unlikely(laptop_mode))

fs/ubifs/budget.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
static void shrink_liability(struct ubifs_info *c, int nr_to_write)
6464
{
6565
down_read(&c->vfs_sb->s_umount);
66-
writeback_inodes_sb(c->vfs_sb);
66+
writeback_inodes_sb(c->vfs_sb, WB_REASON_FS_FREE_SPACE);
6767
up_read(&c->vfs_sb->s_umount);
6868
}
6969

include/linux/backing-dev.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef int (congested_fn)(void *, int);
4040
enum bdi_stat_item {
4141
BDI_RECLAIMABLE,
4242
BDI_WRITEBACK,
43+
BDI_DIRTIED,
4344
BDI_WRITTEN,
4445
NR_BDI_STAT_ITEMS
4546
};
@@ -74,10 +75,20 @@ struct backing_dev_info {
7475
struct percpu_counter bdi_stat[NR_BDI_STAT_ITEMS];
7576

7677
unsigned long bw_time_stamp; /* last time write bw is updated */
78+
unsigned long dirtied_stamp;
7779
unsigned long written_stamp; /* pages written at bw_time_stamp */
7880
unsigned long write_bandwidth; /* the estimated write bandwidth */
7981
unsigned long avg_write_bandwidth; /* further smoothed write bw */
8082

83+
/*
84+
* The base dirty throttle rate, re-calculated on every 200ms.
85+
* All the bdi tasks' dirty rate will be curbed under it.
86+
* @dirty_ratelimit tracks the estimated @balanced_dirty_ratelimit
87+
* in small steps and is much more smooth/stable than the latter.
88+
*/
89+
unsigned long dirty_ratelimit;
90+
unsigned long balanced_dirty_ratelimit;
91+
8192
struct prop_local_percpu completions;
8293
int dirty_exceeded;
8394

@@ -107,7 +118,8 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent,
107118
int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev);
108119
void bdi_unregister(struct backing_dev_info *bdi);
109120
int bdi_setup_and_register(struct backing_dev_info *, char *, unsigned int);
110-
void bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages);
121+
void bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages,
122+
enum wb_reason reason);
111123
void bdi_start_background_writeback(struct backing_dev_info *bdi);
112124
int bdi_writeback_thread(void *data);
113125
int bdi_has_dirty_io(struct backing_dev_info *bdi);

include/linux/sched.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,13 @@ struct task_struct {
15221522
int make_it_fail;
15231523
#endif
15241524
struct prop_local_single dirties;
1525+
/*
1526+
* when (nr_dirtied >= nr_dirtied_pause), it's time to call
1527+
* balance_dirty_pages() for some dirty throttling pause
1528+
*/
1529+
int nr_dirtied;
1530+
int nr_dirtied_pause;
1531+
15251532
#ifdef CONFIG_LATENCYTOP
15261533
int latency_record_count;
15271534
struct latency_record latency_record[LT_SAVECOUNT];

0 commit comments

Comments
 (0)