few hacks to optimize write-back
Subsystems (3)
RFC PATCH 1/1 write-back: do not wake up unnecessarily
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Subject: [PATCH] write-back: do not wake up unnecessarily
This patch is an optimization, targeted to lessen idle mode power consumption.
At the moment the periodic write-back threads (pdflush) are woken up every 5 seconds (by default). They wake up and flush dirty data which is old enough. And even if there are no dirty date, they still wake up.
This patch makes the periodic write-back wake up only when there are dirty data. Otherwise they just sleep and do not interfere CPU which is sleeping/being in a low frequency and low power consumption mode.
--- fs/fs-writeback.c | 17 ++++++++++ include/linux/writeback.h | 3 ++ mm/page-writeback.c | 74 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 90 insertions(+), 4 deletions(-)
fs/fs-writeback.c +17 -0
@@ -94,6 +94,7 @@ static void writeback_release(struct backing_dev_info *bdi)void __mark_inode_dirty (struct inode *inode,int flags) {struct super_block *sb = inode->i_sb; +int start_pwb =0 ;/* * Don't do this for I_DIRTY_PAGES - that doesn't actually
@@ -164,10 +165,26 @@ void __mark_inode_dirty(struct inode *inode, int flags)if (!was_dirty) { inode->dirtied_when = jiffies;list_move (&inode->i_list, &sb->s_dirty); +/* +* If periodic write-back is disabled - enable it +* again. +*/ +if (periodic_wb_stopped) { +struct backing_dev_info *bdi; + + bdi = inode->i_mapping->backing_dev_info; +if (bdi_cap_writeback_dirty (bdi)) { + start_pwb =1 ; + periodic_wb_stopped =0 ; + } + } } } out:spin_unlock (&inode_lock); + +if (start_pwb) +start_periodic_wb (); }EXPORT_SYMBOL (__mark_inode_dirty);
include/linux/writeback.h +3 -0
@@ -13,6 +13,9 @@ extern spinlock_t inode_lock;extern struct list_head inode_in_use;extern struct list_head inode_unused; +extern int periodic_wb_stopped; +extern void start_periodic_wb (void ); +/* * Yes, writeback.h requires sched.h * No, sched.h is not included from here.
mm/page-writeback.c +70 -4
92 lines not on this page · raw message
Signature · 1 line
1.6.0.6
RFC PATCH 1/1 write-back: introduce a handy helper function
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Subject: [PATCH] write-back: introduce a handy helper function
This patch is just a clean up and a preparation for the following wb_timer patches. It introduces a helper 'setup_wb_timer()' function which sets up the periodic write-back timer to the specified value. The code just looks neater with this helper.
--- mm/page-writeback.c | 25 +++++++++++++++++++------ 1 files changed, 19 insertions(+), 6 deletions(-)
mm/page-writeback.c +19 -6
@@ -738,6 +738,21 @@ static DEFINE_TIMER(wb_timer, wb_timer_fn, 0, 0); static DEFINE_TIMER(laptop_mode_wb_timer, laptop_timer_fn, 0, 0);/* +* Setup the periodic write-back timer to expires at @expires jiffies. If +* @expires is zero, the timer is set up to the default interval. +*/ +static void setup_wb_timer (unsigned long expires) +{ +if (!expires) { +/* Setup to the default wake-up period value */ + expires = jiffies; + expires +=msecs_to_jiffies (dirty_writeback_interval *10 ); + } + +mod_timer (&wb_timer, expires); +} + +/* * Periodic writeback of "old" data. * * Define "old": the first time one of an inode's pages is dirtied, we mark the
@@ -792,7 +807,7 @@ static void wb_kupdate(unsigned long arg)if (time_before (next_jif, jiffies +HZ )) next_jif = jiffies +HZ ;if (dirty_writeback_interval) -mod_timer (&wb_timer, next_jif); +setup_wb_timer (next_jif); }/*
@@ -803,8 +818,7 @@ int dirty_writeback_centisecs_handler(ctl_table *table, int write, {proc_dointvec (table, write, file, buffer, length, ppos);if (dirty_writeback_interval) -mod_timer (&wb_timer, jiffies + -msecs_to_jiffies (dirty_writeback_interval *10 )); +setup_wb_timer (0 );else del_timer (&wb_timer);return 0 ;
@@ -813,7 +827,7 @@ int dirty_writeback_centisecs_handler(ctl_table *table, int write,static void wb_timer_fn (unsigned long unused) {if (pdflush_operation (wb_kupdate,0 ) <0 ) -mod_timer (&wb_timer, jiffies +HZ );/* delay 1 second */ +setup_wb_timer ( jiffies +HZ );/* delay 1 second */ }static void laptop_flush (unsigned long unused)
@@ -906,8 +920,7 @@ void __init page_writeback_init(void) {int shift; -mod_timer (&wb_timer, - jiffies +msecs_to_jiffies (dirty_writeback_interval *10 )); +setup_wb_timer (0 );writeback_set_ratelimit ();register_cpu_notifier (&ratelimit_nb);
Signature · 1 line
1.6.0.6
Hi,
I've spotted that the periodic write-back threads wakes up every 5 seconds, even though there are no dirty data. And it still wakes up and wake up and disturbs the CPU which is resting in a low power consumption state.
I've tried to optimize this a bit and make the periodic write-back stop when there are no dirty data.
Here are 2 patches which kind of help. They are just quick hacks. I did not want to spend much time on this and I'd like to get some comments/directions first:
* I'm not sure I went the right path;
* there are new per-BDI patches from Jens, and I probably should work on top of them.
AFAIU, the periodic write-back may be stopped if there are no dirty inodes and no dirty super-blocks. And it should start an inode or superblock is marked as dirty.
For inodes, I've hooked to '__mark_inode_dirty()'.
For superblocks. Well, probably a new VFS helper like 'mark_sb_dirty()' should be introduced. Also, FSes currently may mark SB as clean directly, but probably they should use a 'mark_sb_clean()' helper. FSes should not touch sb->s_dirt directly. Anyway, I have not implemented this part.
Signature · 6 lines
Best Regards, Artem Bityutskiy (�ртём Битюцкий) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html