* Re: [PATCH] mm/page-writeback: Fix performance when BDI's share of ratio is 0.
2021-04-28 22:50 [PATCH] mm/page-writeback: Fix performance when BDI's share of ratio is 0 Chi Wu
@ 2021-05-08 2:17 ` chi wu
2021-05-08 2:31 ` chi wu
2021-05-09 23:36 ` Andrew Morton
2 siblings, 0 replies; 6+ messages in thread
From: chi wu @ 2021-05-08 2:17 UTC (permalink / raw)
To: akpm; +Cc: linux-mm, linux-kernel, tj
[-- Attachment #1: Type: text/plain, Size: 3305 bytes --]
Ping...
Chi Wu <wuchi.zero@gmail.com> 于2021年4月29日周四 上午6:51写道:
> Fix performance when BDI's share of ratio is 0.
>
> The issue is similar to commit 74d369443325 ("writeback: Fix
> performance regression in wb_over_bg_thresh()").
>
> Balance_dirty_pages and the writeback worker will also disagree on
> whether writeback when a BDI uses BDI_CAP_STRICTLIMIT and BDI's share
> of the thresh ratio is zero.
>
> For example, A thread on cpu0 writes 32 pages and then
> balance_dirty_pages, it will wake up background writeback and pauses
> because wb_dirty > wb->wb_thresh = 0 (share of thresh ratio is zero).
> A thread may runs on cpu0 again because scheduler prefers pre_cpu.
> Then writeback worker may runs on other cpus(1,2..) which causes the
> value of wb_stat(wb, WB_RECLAIMABLE) in wb_over_bg_thresh is 0 and does
> not writeback and returns.
>
> Thus, balance_dirty_pages keeps looping, sleeping and then waking up the
> worker who will do nothing. It remains stuck in this state until the
> writeback worker hit the right dirty cpu or the dirty pages expire.
>
> The fix that we should get the wb_stat_sum radically when thresh is low.
>
> Signed-off-by: Chi Wu <wuchi.zero@gmail.com>
> ---
> mm/page-writeback.c | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index 0062d5c57d41..bd7052295246 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -1945,6 +1945,8 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> struct dirty_throttle_control * const gdtc = &gdtc_stor;
> struct dirty_throttle_control * const mdtc =
> mdtc_valid(&mdtc_stor) ?
> &mdtc_stor : NULL;
> + unsigned long reclaimable;
> + unsigned long thresh;
>
> /*
> * Similar to balance_dirty_pages() but ignores pages being written
> @@ -1957,8 +1959,13 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> if (gdtc->dirty > gdtc->bg_thresh)
> return true;
>
> - if (wb_stat(wb, WB_RECLAIMABLE) >
> - wb_calc_thresh(gdtc->wb, gdtc->bg_thresh))
> + thresh = wb_calc_thresh(gdtc->wb, gdtc->bg_thresh);
> + if (thresh < 2 * wb_stat_error())
> + reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE);
> + else
> + reclaimable = wb_stat(wb, WB_RECLAIMABLE);
> +
> + if (reclaimable > thresh)
> return true;
>
> if (mdtc) {
> @@ -1972,8 +1979,13 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> if (mdtc->dirty > mdtc->bg_thresh)
> return true;
>
> - if (wb_stat(wb, WB_RECLAIMABLE) >
> - wb_calc_thresh(mdtc->wb, mdtc->bg_thresh))
> + thresh = wb_calc_thresh(mdtc->wb, mdtc->bg_thresh);
> + if (thresh < 2 * wb_stat_error())
> + reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE);
> + else
> + reclaimable = wb_stat(wb, WB_RECLAIMABLE);
> +
> + if (reclaimable > thresh)
> return true;
> }
>
> --
> 2.17.1
>
>
[-- Attachment #2: Type: text/html, Size: 4202 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/page-writeback: Fix performance when BDI's share of ratio is 0.
2021-04-28 22:50 [PATCH] mm/page-writeback: Fix performance when BDI's share of ratio is 0 Chi Wu
2021-05-08 2:17 ` chi wu
@ 2021-05-08 2:31 ` chi wu
2021-05-09 23:36 ` Andrew Morton
2 siblings, 0 replies; 6+ messages in thread
From: chi wu @ 2021-05-08 2:31 UTC (permalink / raw)
To: akpm; +Cc: linux-mm, linux-kernel, tj
Ping...
Chi Wu <wuchi.zero@gmail.com> 于2021年4月29日周四 上午6:51写道:
>
> Fix performance when BDI's share of ratio is 0.
>
> The issue is similar to commit 74d369443325 ("writeback: Fix
> performance regression in wb_over_bg_thresh()").
>
> Balance_dirty_pages and the writeback worker will also disagree on
> whether writeback when a BDI uses BDI_CAP_STRICTLIMIT and BDI's share
> of the thresh ratio is zero.
>
> For example, A thread on cpu0 writes 32 pages and then
> balance_dirty_pages, it will wake up background writeback and pauses
> because wb_dirty > wb->wb_thresh = 0 (share of thresh ratio is zero).
> A thread may runs on cpu0 again because scheduler prefers pre_cpu.
> Then writeback worker may runs on other cpus(1,2..) which causes the
> value of wb_stat(wb, WB_RECLAIMABLE) in wb_over_bg_thresh is 0 and does
> not writeback and returns.
>
> Thus, balance_dirty_pages keeps looping, sleeping and then waking up the
> worker who will do nothing. It remains stuck in this state until the
> writeback worker hit the right dirty cpu or the dirty pages expire.
>
> The fix that we should get the wb_stat_sum radically when thresh is low.
>
> Signed-off-by: Chi Wu <wuchi.zero@gmail.com>
> ---
> mm/page-writeback.c | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index 0062d5c57d41..bd7052295246 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -1945,6 +1945,8 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> struct dirty_throttle_control * const gdtc = &gdtc_stor;
> struct dirty_throttle_control * const mdtc = mdtc_valid(&mdtc_stor) ?
> &mdtc_stor : NULL;
> + unsigned long reclaimable;
> + unsigned long thresh;
>
> /*
> * Similar to balance_dirty_pages() but ignores pages being written
> @@ -1957,8 +1959,13 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> if (gdtc->dirty > gdtc->bg_thresh)
> return true;
>
> - if (wb_stat(wb, WB_RECLAIMABLE) >
> - wb_calc_thresh(gdtc->wb, gdtc->bg_thresh))
> + thresh = wb_calc_thresh(gdtc->wb, gdtc->bg_thresh);
> + if (thresh < 2 * wb_stat_error())
> + reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE);
> + else
> + reclaimable = wb_stat(wb, WB_RECLAIMABLE);
> +
> + if (reclaimable > thresh)
> return true;
>
> if (mdtc) {
> @@ -1972,8 +1979,13 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> if (mdtc->dirty > mdtc->bg_thresh)
> return true;
>
> - if (wb_stat(wb, WB_RECLAIMABLE) >
> - wb_calc_thresh(mdtc->wb, mdtc->bg_thresh))
> + thresh = wb_calc_thresh(mdtc->wb, mdtc->bg_thresh);
> + if (thresh < 2 * wb_stat_error())
> + reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE);
> + else
> + reclaimable = wb_stat(wb, WB_RECLAIMABLE);
> +
> + if (reclaimable > thresh)
> return true;
> }
>
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/page-writeback: Fix performance when BDI's share of ratio is 0.
2021-04-28 22:50 [PATCH] mm/page-writeback: Fix performance when BDI's share of ratio is 0 Chi Wu
2021-05-08 2:17 ` chi wu
2021-05-08 2:31 ` chi wu
@ 2021-05-09 23:36 ` Andrew Morton
2021-05-10 10:22 ` chi wu
2021-05-10 10:44 ` Jan Kara
2 siblings, 2 replies; 6+ messages in thread
From: Andrew Morton @ 2021-05-09 23:36 UTC (permalink / raw)
To: Chi Wu
Cc: linux-mm, linux-kernel, tj, Howard Cochran, Miklos Szeredi,
Jens Axboe, Jan Kara
On Thu, 29 Apr 2021 06:50:46 +0800 Chi Wu <wuchi.zero@gmail.com> wrote:
> Fix performance when BDI's share of ratio is 0.
>
> The issue is similar to commit 74d369443325 ("writeback: Fix
> performance regression in wb_over_bg_thresh()").
>
> Balance_dirty_pages and the writeback worker will also disagree on
> whether writeback when a BDI uses BDI_CAP_STRICTLIMIT and BDI's share
> of the thresh ratio is zero.
>
> For example, A thread on cpu0 writes 32 pages and then
> balance_dirty_pages, it will wake up background writeback and pauses
> because wb_dirty > wb->wb_thresh = 0 (share of thresh ratio is zero).
> A thread may runs on cpu0 again because scheduler prefers pre_cpu.
> Then writeback worker may runs on other cpus(1,2..) which causes the
> value of wb_stat(wb, WB_RECLAIMABLE) in wb_over_bg_thresh is 0 and does
> not writeback and returns.
>
> Thus, balance_dirty_pages keeps looping, sleeping and then waking up the
> worker who will do nothing. It remains stuck in this state until the
> writeback worker hit the right dirty cpu or the dirty pages expire.
>
> The fix that we should get the wb_stat_sum radically when thresh is low.
(optimistically Cc's various people who might remember how this code works)
> Signed-off-by: Chi Wu <wuchi.zero@gmail.com>
Thanks. I'll add it for some testing and hopefully someone will find
the time to review this.
> ---
> mm/page-writeback.c | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index 0062d5c57d41..bd7052295246 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -1945,6 +1945,8 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> struct dirty_throttle_control * const gdtc = &gdtc_stor;
> struct dirty_throttle_control * const mdtc = mdtc_valid(&mdtc_stor) ?
> &mdtc_stor : NULL;
> + unsigned long reclaimable;
> + unsigned long thresh;
>
> /*
> * Similar to balance_dirty_pages() but ignores pages being written
> @@ -1957,8 +1959,13 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> if (gdtc->dirty > gdtc->bg_thresh)
> return true;
>
> - if (wb_stat(wb, WB_RECLAIMABLE) >
> - wb_calc_thresh(gdtc->wb, gdtc->bg_thresh))
> + thresh = wb_calc_thresh(gdtc->wb, gdtc->bg_thresh);
> + if (thresh < 2 * wb_stat_error())
> + reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE);
> + else
> + reclaimable = wb_stat(wb, WB_RECLAIMABLE);
> +
> + if (reclaimable > thresh)
> return true;
>
> if (mdtc) {
> @@ -1972,8 +1979,13 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> if (mdtc->dirty > mdtc->bg_thresh)
> return true;
>
> - if (wb_stat(wb, WB_RECLAIMABLE) >
> - wb_calc_thresh(mdtc->wb, mdtc->bg_thresh))
> + thresh = wb_calc_thresh(mdtc->wb, mdtc->bg_thresh);
> + if (thresh < 2 * wb_stat_error())
> + reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE);
> + else
> + reclaimable = wb_stat(wb, WB_RECLAIMABLE);
> +
> + if (reclaimable > thresh)
> return true;
> }
>
> --
> 2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/page-writeback: Fix performance when BDI's share of ratio is 0.
2021-05-09 23:36 ` Andrew Morton
@ 2021-05-10 10:22 ` chi wu
2021-05-10 10:44 ` Jan Kara
1 sibling, 0 replies; 6+ messages in thread
From: chi wu @ 2021-05-10 10:22 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-mm, linux-kernel, tj, Howard Cochran, Miklos Szeredi,
Jens Axboe, Jan Kara
Andrew Morton <akpm@linux-foundation.org> 于2021年5月10日周一 上午7:36写道:
>
> On Thu, 29 Apr 2021 06:50:46 +0800 Chi Wu <wuchi.zero@gmail.com> wrote:
>
> > Fix performance when BDI's share of ratio is 0.
> >
> > The issue is similar to commit 74d369443325 ("writeback: Fix
> > performance regression in wb_over_bg_thresh()").
> >
> > Balance_dirty_pages and the writeback worker will also disagree on
> > whether writeback when a BDI uses BDI_CAP_STRICTLIMIT and BDI's share
> > of the thresh ratio is zero.
> >
> > For example, A thread on cpu0 writes 32 pages and then
> > balance_dirty_pages, it will wake up background writeback and pauses
> > because wb_dirty > wb->wb_thresh = 0 (share of thresh ratio is zero).
> > A thread may runs on cpu0 again because scheduler prefers pre_cpu.
> > Then writeback worker may runs on other cpus(1,2..) which causes the
> > value of wb_stat(wb, WB_RECLAIMABLE) in wb_over_bg_thresh is 0 and does
> > not writeback and returns.
> >
> > Thus, balance_dirty_pages keeps looping, sleeping and then waking up the
> > worker who will do nothing. It remains stuck in this state until the
> > writeback worker hit the right dirty cpu or the dirty pages expire.
> >
> > The fix that we should get the wb_stat_sum radically when thresh is low.
>
> (optimistically Cc's various people who might remember how this code works)
Thanks, I'll correct it in the future.
>
> > Signed-off-by: Chi Wu <wuchi.zero@gmail.com>
>
> Thanks. I'll add it for some testing and hopefully someone will find
> the time to review this.
>
> > ---
> > mm/page-writeback.c | 20 ++++++++++++++++----
> > 1 file changed, 16 insertions(+), 4 deletions(-)
> >
> > diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> > index 0062d5c57d41..bd7052295246 100644
> > --- a/mm/page-writeback.c
> > +++ b/mm/page-writeback.c
> > @@ -1945,6 +1945,8 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> > struct dirty_throttle_control * const gdtc = &gdtc_stor;
> > struct dirty_throttle_control * const mdtc = mdtc_valid(&mdtc_stor) ?
> > &mdtc_stor : NULL;
> > + unsigned long reclaimable;
> > + unsigned long thresh;
> >
> > /*
> > * Similar to balance_dirty_pages() but ignores pages being written
> > @@ -1957,8 +1959,13 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> > if (gdtc->dirty > gdtc->bg_thresh)
> > return true;
> >
> > - if (wb_stat(wb, WB_RECLAIMABLE) >
> > - wb_calc_thresh(gdtc->wb, gdtc->bg_thresh))
> > + thresh = wb_calc_thresh(gdtc->wb, gdtc->bg_thresh);
> > + if (thresh < 2 * wb_stat_error())
> > + reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE);
> > + else
> > + reclaimable = wb_stat(wb, WB_RECLAIMABLE);
> > +
> > + if (reclaimable > thresh)
> > return true;
> >
> > if (mdtc) {
> > @@ -1972,8 +1979,13 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> > if (mdtc->dirty > mdtc->bg_thresh)
> > return true;
> >
> > - if (wb_stat(wb, WB_RECLAIMABLE) >
> > - wb_calc_thresh(mdtc->wb, mdtc->bg_thresh))
> > + thresh = wb_calc_thresh(mdtc->wb, mdtc->bg_thresh);
> > + if (thresh < 2 * wb_stat_error())
> > + reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE);
> > + else
> > + reclaimable = wb_stat(wb, WB_RECLAIMABLE);
> > +
> > + if (reclaimable > thresh)
> > return true;
> > }
> >
> > --
> > 2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/page-writeback: Fix performance when BDI's share of ratio is 0.
2021-05-09 23:36 ` Andrew Morton
2021-05-10 10:22 ` chi wu
@ 2021-05-10 10:44 ` Jan Kara
1 sibling, 0 replies; 6+ messages in thread
From: Jan Kara @ 2021-05-10 10:44 UTC (permalink / raw)
To: Andrew Morton
Cc: Chi Wu, linux-mm, linux-kernel, tj, Howard Cochran,
Miklos Szeredi, Jens Axboe, Jan Kara
On Sun 09-05-21 16:36:33, Andrew Morton wrote:
> On Thu, 29 Apr 2021 06:50:46 +0800 Chi Wu <wuchi.zero@gmail.com> wrote:
>
> > Fix performance when BDI's share of ratio is 0.
> >
> > The issue is similar to commit 74d369443325 ("writeback: Fix
> > performance regression in wb_over_bg_thresh()").
> >
> > Balance_dirty_pages and the writeback worker will also disagree on
> > whether writeback when a BDI uses BDI_CAP_STRICTLIMIT and BDI's share
> > of the thresh ratio is zero.
> >
> > For example, A thread on cpu0 writes 32 pages and then
> > balance_dirty_pages, it will wake up background writeback and pauses
> > because wb_dirty > wb->wb_thresh = 0 (share of thresh ratio is zero).
> > A thread may runs on cpu0 again because scheduler prefers pre_cpu.
> > Then writeback worker may runs on other cpus(1,2..) which causes the
> > value of wb_stat(wb, WB_RECLAIMABLE) in wb_over_bg_thresh is 0 and does
> > not writeback and returns.
> >
> > Thus, balance_dirty_pages keeps looping, sleeping and then waking up the
> > worker who will do nothing. It remains stuck in this state until the
> > writeback worker hit the right dirty cpu or the dirty pages expire.
> >
> > The fix that we should get the wb_stat_sum radically when thresh is low.
>
> (optimistically Cc's various people who might remember how this code works)
Thanks for forwarding Andrew!
> > Signed-off-by: Chi Wu <wuchi.zero@gmail.com>
>
> Thanks. I'll add it for some testing and hopefully someone will find
> the time to review this.
Thanks for the patch! It looks good to me, good catch! Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> > ---
> > mm/page-writeback.c | 20 ++++++++++++++++----
> > 1 file changed, 16 insertions(+), 4 deletions(-)
> >
> > diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> > index 0062d5c57d41..bd7052295246 100644
> > --- a/mm/page-writeback.c
> > +++ b/mm/page-writeback.c
> > @@ -1945,6 +1945,8 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> > struct dirty_throttle_control * const gdtc = &gdtc_stor;
> > struct dirty_throttle_control * const mdtc = mdtc_valid(&mdtc_stor) ?
> > &mdtc_stor : NULL;
> > + unsigned long reclaimable;
> > + unsigned long thresh;
> >
> > /*
> > * Similar to balance_dirty_pages() but ignores pages being written
> > @@ -1957,8 +1959,13 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> > if (gdtc->dirty > gdtc->bg_thresh)
> > return true;
> >
> > - if (wb_stat(wb, WB_RECLAIMABLE) >
> > - wb_calc_thresh(gdtc->wb, gdtc->bg_thresh))
> > + thresh = wb_calc_thresh(gdtc->wb, gdtc->bg_thresh);
> > + if (thresh < 2 * wb_stat_error())
> > + reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE);
> > + else
> > + reclaimable = wb_stat(wb, WB_RECLAIMABLE);
> > +
> > + if (reclaimable > thresh)
> > return true;
> >
> > if (mdtc) {
> > @@ -1972,8 +1979,13 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
> > if (mdtc->dirty > mdtc->bg_thresh)
> > return true;
> >
> > - if (wb_stat(wb, WB_RECLAIMABLE) >
> > - wb_calc_thresh(mdtc->wb, mdtc->bg_thresh))
> > + thresh = wb_calc_thresh(mdtc->wb, mdtc->bg_thresh);
> > + if (thresh < 2 * wb_stat_error())
> > + reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE);
> > + else
> > + reclaimable = wb_stat(wb, WB_RECLAIMABLE);
> > +
> > + if (reclaimable > thresh)
> > return true;
> > }
> >
> > --
> > 2.17.1
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 6+ messages in thread