@@ -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
116128static 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/**
@@ -641,12 +655,14 @@ 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 );
@@ -825,6 +841,7 @@ static long wb_check_background_flush(struct bdi_writeback *wb)
825841 .sync_mode = WB_SYNC_NONE ,
826842 .for_background = 1 ,
827843 .range_cyclic = 1 ,
844+ .reason = WB_REASON_BACKGROUND ,
828845 };
829846
830847 return wb_writeback (wb , & work );
@@ -858,6 +875,7 @@ static long wb_check_old_data_flush(struct bdi_writeback *wb)
858875 .sync_mode = WB_SYNC_NONE ,
859876 .for_kupdate = 1 ,
860877 .range_cyclic = 1 ,
878+ .reason = WB_REASON_PERIODIC ,
861879 };
862880
863881 return wb_writeback (wb , & work );
@@ -976,7 +994,7 @@ int bdi_writeback_thread(void *data)
976994 * Start writeback of `nr_pages' pages. If `nr_pages' is zero, write back
977995 * the whole world.
978996 */
979- void wakeup_flusher_threads (long nr_pages )
997+ void wakeup_flusher_threads (long nr_pages , enum wb_reason reason )
980998{
981999 struct backing_dev_info * bdi ;
9821000
@@ -989,7 +1007,7 @@ void wakeup_flusher_threads(long nr_pages)
9891007 list_for_each_entry_rcu (bdi , & bdi_list , bdi_list ) {
9901008 if (!bdi_has_dirty_io (bdi ))
9911009 continue ;
992- __bdi_start_writeback (bdi , nr_pages , false);
1010+ __bdi_start_writeback (bdi , nr_pages , false, reason );
9931011 }
9941012 rcu_read_unlock ();
9951013}
@@ -1210,7 +1228,9 @@ static void wait_sb_inodes(struct super_block *sb)
12101228 * on how many (if any) will be written, and this function does not wait
12111229 * for IO completion of submitted IO.
12121230 */
1213- 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 )
12141234{
12151235 DECLARE_COMPLETION_ONSTACK (done );
12161236 struct wb_writeback_work work = {
@@ -1219,6 +1239,7 @@ void writeback_inodes_sb_nr(struct super_block *sb, unsigned long nr)
12191239 .tagged_writepages = 1 ,
12201240 .done = & done ,
12211241 .nr_pages = nr ,
1242+ .reason = reason ,
12221243 };
12231244
12241245 WARN_ON (!rwsem_is_locked (& sb -> s_umount ));
@@ -1235,9 +1256,9 @@ EXPORT_SYMBOL(writeback_inodes_sb_nr);
12351256 * on how many (if any) will be written, and this function does not wait
12361257 * for IO completion of submitted IO.
12371258 */
1238- void writeback_inodes_sb (struct super_block * sb )
1259+ void writeback_inodes_sb (struct super_block * sb , enum wb_reason reason )
12391260{
1240- return writeback_inodes_sb_nr (sb , get_nr_dirty_pages ());
1261+ return writeback_inodes_sb_nr (sb , get_nr_dirty_pages (), reason );
12411262}
12421263EXPORT_SYMBOL (writeback_inodes_sb );
12431264
@@ -1248,11 +1269,11 @@ EXPORT_SYMBOL(writeback_inodes_sb);
12481269 * Invoke writeback_inodes_sb if no writeback is currently underway.
12491270 * Returns 1 if writeback was started, 0 if not.
12501271 */
1251- 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 )
12521273{
12531274 if (!writeback_in_progress (sb -> s_bdi )) {
12541275 down_read (& sb -> s_umount );
1255- writeback_inodes_sb (sb );
1276+ writeback_inodes_sb (sb , reason );
12561277 up_read (& sb -> s_umount );
12571278 return 1 ;
12581279 } else
@@ -1269,11 +1290,12 @@ EXPORT_SYMBOL(writeback_inodes_sb_if_idle);
12691290 * Returns 1 if writeback was started, 0 if not.
12701291 */
12711292int writeback_inodes_sb_nr_if_idle (struct super_block * sb ,
1272- unsigned long nr )
1293+ unsigned long nr ,
1294+ enum wb_reason reason )
12731295{
12741296 if (!writeback_in_progress (sb -> s_bdi )) {
12751297 down_read (& sb -> s_umount );
1276- writeback_inodes_sb_nr (sb , nr );
1298+ writeback_inodes_sb_nr (sb , nr , reason );
12771299 up_read (& sb -> s_umount );
12781300 return 1 ;
12791301 } else
@@ -1297,6 +1319,7 @@ void sync_inodes_sb(struct super_block *sb)
12971319 .nr_pages = LONG_MAX ,
12981320 .range_cyclic = 0 ,
12991321 .done = & done ,
1322+ .reason = WB_REASON_SYNC ,
13001323 };
13011324
13021325 WARN_ON (!rwsem_is_locked (& sb -> s_umount ));
0 commit comments