Small cleanup of bdi_forker_thread()
Subsystems (2)
v3 cover Small cleanup of bdi_forker_thread()
Hi Jens,
so after I realized how I underestimated subtlety of bdi_forker_thread()
here are two small cleanups to it. The first one puts clearing of BDI_pending in a more natural place, the second patch adds a comment so that fools like me don't try to optimize the function in a wrong place...
Honza
PATCH v3 1/2 mm: Cleanup clearing of BDI_pending bit in bdi_forker_thread()
bdi_forker_thread() clears BDI_pending bit at the end of the main loop. However clearing of this bit must not be done in some cases which is handled by calling 'continue' from switch statement. That's kind of unusual construct and without a good reason so change the function into more intuitive code flow.
--- mm/backing-dev.c | 23 ++++++++++++++--------- 1 files changed, 14 insertions(+), 9 deletions(-)
mm/backing-dev.c +14 -9
@@ -359,6 +359,17 @@ static unsigned long bdi_longest_inactive(void)return max (5UL *60 *HZ , interval); } +/* +* Clear pending bit and wakeup anybody waiting for flusher thread creation or +* shutdown +*/ +static void bdi_clear_pending (struct backing_dev_info *bdi) +{ +clear_bit (BDI_pending, &bdi->state); +smp_mb__after_clear_bit (); +wake_up_bit (&bdi->state, BDI_pending); +} +static int bdi_forker_thread (void *ptr) {struct bdi_writeback *me = ptr;
@@ -469,11 +480,13 @@ static int bdi_forker_thread(void *ptr)spin_unlock_bh (&bdi->wb_lock);wake_up_process (task); } +bdi_clear_pending (bdi);break ;case KILL_THREAD :__set_current_state (TASK_RUNNING );kthread_stop (task); +bdi_clear_pending (bdi);break ;case NO_ACTION :
@@ -489,16 +502,8 @@ static int bdi_forker_thread(void *ptr)else schedule_timeout (msecs_to_jiffies (dirty_writeback_interval *10 ));try_to_freeze (); -/* Back to the main loop */ -continue ; +break ; } - -/* -* Clear pending bit and wakeup anybody waiting to tear us down. -*/ -clear_bit (BDI_pending, &bdi->state); -smp_mb__after_clear_bit (); -wake_up_bit (&bdi->state, BDI_pending); }return 0 ;
Signature · 1 line
1.7.1
Re: [PATCH 1/2] mm: Cleanup clearing of BDI_pending bit in bdi_forker_thread()
Quoted 8 lines · Jan Kara
bdi_forker_thread()clearsBDI_pendingbit at the end of the main loop. However clearing of this bit must not be done in some cases which is handled by calling 'continue' from switch statement. That's kind of unusual construct and without a good reason so change the function into more intuitive code flow.CC Wu Fengguang <[email protected]>CC Andrew Morton <[email protected]>Signed-off-by Jan Kara <[email protected]>
It's pure code refactor.
Thanks,
Fengguang
Re: [PATCH 1/2] mm: Cleanup clearing of BDI_pending bit in bdi_forker_thread()
Quoted 6 lines · Wu Fengguang
Quoted 5 lines · Jan Kara
bdi_forker_thread()clearsBDI_pendingbit at the end of the main loop. However clearing of this bit must not be done in some cases which is handled by calling 'continue' from switch statement. That's kind of unusual construct and without a good reason so change the function into more intuitive code flow.
Quoted 7 lines
Quoted 3 lines
CC Wu Fengguang <[email protected]>CC Andrew Morton <[email protected]>Signed-off-by Jan Kara <[email protected]>It's pure code refactor.
Reviewed-by Wu Fengguang <[email protected]>
But I do suspect it will slightly increase the code size. What do you think?
Thanks,
Fengguang
Re: [PATCH 1/2] mm: Cleanup clearing of BDI_pending bit in bdi_forker_thread()
Quoted 11 lines · Wu Fengguang
Quoted 10 lines · Wu Fengguang
Quoted 8 lines · Jan Kara
bdi_forker_thread()clearsBDI_pendingbit at the end of the main loop. However clearing of this bit must not be done in some cases which is handled by calling 'continue' from switch statement. That's kind of unusual construct and without a good reason so change the function into more intuitive code flow.CC Wu Fengguang <[email protected]>CC Andrew Morton <[email protected]>Signed-off-by Jan Kara <[email protected]>
Quoted 6 lines
Quoted 3 lines
It's pure code refactor.
Reviewed-by Wu Fengguang <[email protected]>But I do suspect it will slightly increase the code size. What do you think?
I haven't checked, maybe it will if the compiler is not clever enough to
merge two occurences of the function which is going to be inlined. But the overhead will be really small and the code is not really performance critical so I think clarity has priority.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 1/2] mm: Cleanup clearing of BDI_pending bit in bdi_forker_thread()
Quoted 14 lines · Jan Kara
Quoted 13 lines · Wu Fengguang
Quoted 12 lines · Wu Fengguang
Quoted 8 lines · Jan Kara
bdi_forker_thread()clearsBDI_pendingbit at the end of the main loop. However clearing of this bit must not be done in some cases which is handled by calling 'continue' from switch statement. That's kind of unusual construct and without a good reason so change the function into more intuitive code flow.CC Wu Fengguang <[email protected]>CC Andrew Morton <[email protected]>Signed-off-by Jan Kara <[email protected]>It's pure code refactor.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Reviewed-by Wu Fengguang <[email protected]>But I do suspect it will slightly increase the code size. What do you think?
I haven't checked, maybe it will if the compiler is not clever enough to
merge two occurences of the function which is going to be inlined. But the overhead will be really small and the code is not really performance critical so I think clarity has priority.
I have no problem then. It's not a big matter.
Thanks,
Fengguang
PATCH v3 2/2 mm: Add comment explaining task state setting in bdi_forker_thread()
In reply to Jan Kara--- mm/backing-dev.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
mm/backing-dev.c +7 -0
@@ -401,6 +401,13 @@ static int bdi_forker_thread(void *ptr) }spin_lock_bh (&bdi_lock); +/* +* In the following loop we are going to check whether we have +* some work to do without any synchronization with tasks +* waking us up to do work for them. So we have to set task +* state already here so that we don't miss wakeups coming +* after we verify some condition. +*/ set_current_state (TASK_INTERRUPTIBLE );list_for_each_entry (bdi, &bdi_list, bdi_list) {
Signature · 1 line
1.7.1
Re: [PATCH 2/2] mm: Add comment explaining task state setting in bdi_forker_thread()
mm/backing-dev.c static int bdi_forker_thread(void *ptr) · line 408
Quoted 9 lines
mm/backing-dev.c +5
-0@@ -401,6 +401,13 @@ static int bdi_forker_thread(void *ptr) }spin_lock_bh (&bdi_lock); +/* +* In the following loop we are going to check whether we have +* some work to do without any synchronization with tasks +* waking us up to do work for them. So we have to set task +* state already here so that we don't miss wakeups coming
s/already/early/ ?
Quoted 7 lines
mm/backing-dev.c +2
-0+* after we verify some condition. +*/ set_current_state (TASK_INTERRUPTIBLE );list_for_each_entry (bdi, &bdi_list, bdi_list) {Signature · 1 line
1.7.1
Re: [PATCH 2/2] mm: Add comment explaining task state setting in bdi_forker_thread()
Quoted 11 lines · Wu Fengguang
mm/backing-dev.c static int bdi_forker_thread(void *ptr) · line 408
Quoted 9 lines
mm/backing-dev.c +5
-0@@ -401,6 +401,13 @@ static int bdi_forker_thread(void *ptr) }spin_lock_bh (&bdi_lock); +/* +* In the following loop we are going to check whether we have +* some work to do without any synchronization with tasks +* waking us up to do work for them. So we have to set task +* state already here so that we don't miss wakeups coming s/already/early/ ?
Thanks for review. We'd have to substitute 'already here' with 'early'
for the sentence to make make sense. But frankly I don't see why one would be better than the other one...
Honza
Quoted 10 lines
Acked-by Wu Fengguang <[email protected]>Quoted 7 lines
mm/backing-dev.c +2
-0+* after we verify some condition. +*/ set_current_state (TASK_INTERRUPTIBLE );list_for_each_entry (bdi, &bdi_list, bdi_list) {Signature · 1 line
1.7.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 2/2] mm: Add comment explaining task state setting in bdi_forker_thread()
Quoted 12 lines · Jan Kara
Quoted 11 lines · Wu Fengguang
mm/backing-dev.c static int bdi_forker_thread(void *ptr) · line 408
Quoted 9 lines
mm/backing-dev.c +5
-0@@ -401,6 +401,13 @@ static int bdi_forker_thread(void *ptr) }spin_lock_bh (&bdi_lock); +/* +* In the following loop we are going to check whether we have +* some work to do without any synchronization with tasks +* waking us up to do work for them. So we have to set task +* state already here so that we don't miss wakeups coming s/already/early/ ?
Quoted 3 lines
Thanks for review. We'd have to substitute 'already here' with 'early'
for the sentence to make make sense. But frankly I don't see why one would be better than the other one...
You are the native English speaker? OK, I have no more problems... ;)
Thanks,
Fengguang
Re: [PATCH 2/2] mm: Add comment explaining task state setting in bdi_forker_thread()
Quoted 13 lines · Wu Fengguang
Quoted 12 lines · Jan Kara
Quoted 11 lines · Wu Fengguang
mm/backing-dev.c static int bdi_forker_thread(void *ptr) · line 408
Quoted 9 lines
mm/backing-dev.c +5
-0@@ -401,6 +401,13 @@ static int bdi_forker_thread(void *ptr) }spin_lock_bh (&bdi_lock); +/* +* In the following loop we are going to check whether we have +* some work to do without any synchronization with tasks +* waking us up to do work for them. So we have to set task +* state already here so that we don't miss wakeups coming s/already/early/ ?
Quoted 5 lines
Quoted 3 lines
Thanks for review. We'd have to substitute 'already here' with 'early'
for the sentence to make make sense. But frankly I don't see why one would be better than the other one...You are the native English speaker? OK, I have no more problems... ;)
No, I'm not a native English speaker. Maybe that's why I don't see that
much difference :-))
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Andrew Morton
maintainerRe: [PATCH 2/2] mm: Add comment explaining task state setting in bdi_forker_thread()
Quoted 14 lines · On Mon, 5 Sep 2011 17:53:47 +0200 Jan Kara <[email protected]> wrote:
Quoted 13 lines · Wu Fengguang
Quoted 12 lines · Jan Kara
Quoted 11 lines · Wu Fengguang
Review static int bdi_forker_thread(void *ptr) · line 408
Quoted 9 lines
(quoted diff) +5
-0@@ -401,6 +401,13 @@ static int bdi_forker_thread(void *ptr) } spin_lock_bh(&bdi_lock); + /* + * In the following loop we are going to check whether we have + * some work to do without any synchronization with tasks + * waking us up to do work for them. So we have to set task + * state already here so that we don't miss wakeups comings/already/early/ ?
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Thanks for review. We'd have to substitute 'already here' with 'early'
for the sentence to make make sense. But frankly I don't see why one would be better than the other one...You are the native English speaker? OK, I have no more problems... ;)
No, I'm not a native English speaker. Maybe that's why I don't see that
much difference :-))
grammar can often be fixed/improved by deleting stuff ;)
mm/backing-dev.c renamed from mm/backing-dev.c~mm-add-comment-explaining-task-state-setting-in-bdi_forker_thread-fix +2 -3
@@ -404,9 +404,8 @@ static int bdi_forker_thread(void *ptr)/* * In the following loop we are going to check whether we have * some work to do without any synchronization with tasks -* waking us up to do work for them. So we have to set task -* state already here so that we don't miss wakeups coming -* after we verify some condition. +* waking us up to do work for them. Set the task state here +* so that we don't miss wakeups after verifying conditions. */ set_current_state (TASK_INTERRUPTIBLE );
_
Re: [PATCH 2/2] mm: Add comment explaining task state setting in bdi_forker_thread()
Quoted 5 lines
grammar can often be fixed/improved by deleting stuff ;)
mm/backing-dev.c static int bdi_forker_thread(void *ptr) · line 410
Quoted 10 lines
mm/backing-dev.c renamed from mm/backing-dev.c~mm-add-comment-explaining-task-state-setting-in-bdi_forker_thread-fix +2
-3@@ -404,9 +404,8 @@ static int bdi_forker_thread(void *ptr)/* * In the following loop we are going to check whether we have * some work to do without any synchronization with tasks -* waking us up to do work for them. So we have to set task -* state already here so that we don't miss wakeups coming -* after we verify some condition. +* waking us up to do work for them. Set the task state here +* so that we don't miss wakeups after verifying conditions. */ set_current_state (TASK_INTERRUPTIBLE );
That's nice and readable, thanks!
Regards,
Fengguang
Quoted 7 lines · Jan Kara
Hi Jens,
so after I realized how I underestimated subtlety of
bdi_forker_thread()
here are two small cleanups to it. The first one puts clearing ofBDI_pendingin a more natural place, the second patch adds a comment so that fools like me don't try to optimize the function in a wrong place...
Thanks Jan, I've queued it up for 3.1. I've marked it as stable, looks like we need it from 2.6.36 and above.
Signature · 1 line
Jens Axboe
Quoted 11 lines · Jens Axboe
Quoted 7 lines · Jan Kara
Hi Jens,
so after I realized how I underestimated subtlety of
bdi_forker_thread()
here are two small cleanups to it. The first one puts clearing ofBDI_pendingin a more natural place, the second patch adds a comment so that fools like me don't try to optimize the function in a wrong place...Thanks Jan, I've queued it up for 3.1. I've marked it as stable, looks like we need it from 2.6.36 and above.
Thanks. But is it really a stable material? It's just a cleanup after
all...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 10 lines · Jan Kara
Quoted 9 lines · Jens Axboe
Quoted 7 lines · Jan Kara
Hi Jens,
so after I realized how I underestimated subtlety of
bdi_forker_thread()
here are two small cleanups to it. The first one puts clearing ofBDI_pendingin a more natural place, the second patch adds a comment so that fools like me don't try to optimize the function in a wrong place...
Quoted 4 lines
Quoted 2 lines
Thanks Jan, I've queued it up for 3.1. I've marked it as stable, looks like we need it from 2.6.36 and above.
Thanks. But is it really a stable material? It's just a cleanup after
all...
I guess it's not strictly stable material, since it's not fixing a problematic issue.
Signature · 1 line
Jens Axboe