From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_RED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20C8FC433ED for ; Mon, 10 May 2021 10:23:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9E2BD61424 for ; Mon, 10 May 2021 10:23:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E2BD61424 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F3BAA6B0070; Mon, 10 May 2021 06:23:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F12386B0071; Mon, 10 May 2021 06:23:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDA6F6B0072; Mon, 10 May 2021 06:23:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0248.hostedemail.com [216.40.44.248]) by kanga.kvack.org (Postfix) with ESMTP id C289E6B0070 for ; Mon, 10 May 2021 06:23:05 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 831538249980 for ; Mon, 10 May 2021 10:23:05 +0000 (UTC) X-FDA: 78124933530.12.B2537B8 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf01.hostedemail.com (Postfix) with ESMTP id 4CC4B500153B for ; Mon, 10 May 2021 10:23:02 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id b3so8889685plg.11 for ; Mon, 10 May 2021 03:23:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=SC3l9ot/NnrIlFH9F+9VvlqluJ48/wZ0HvAXIkGXJZs=; b=KsiOvL/wV7695uCIKkpWUl37lqlAZKZaXg5HPRqOWKZ0FRbWKl6l1KVawCravOw2Eg U3MrCQCGB+okOqR4/Gw2dvVOcuMhuJhN+TaTyS6Ob8Ymmbtgy3wVvYTnPWWb6ZiLIa4q 1Z/5sbtyOTAEpSKU+SSU1i8bvYU2floXeLkEekYy686XFt81uS7TMf0aoICutreut6I4 NB9ioG7k27GBujjyngBObw/tkCfW8S1oEYyD3mI+gEf0PGT8vbE4AdB5TpxCF26QcL2A VX0BAIwUhbosIXaA8gWWtVJOfLzQqIkN9V8kdexodE5iZISdiczN8xC/ZmCrlhEjWWqB T0Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=SC3l9ot/NnrIlFH9F+9VvlqluJ48/wZ0HvAXIkGXJZs=; b=Mv4oAjkss+sHYPfTjENMbO4rCRV/jsSOyb6vfdhjPEBcWwWFxpMbB/YEwExNBUs8Pv ss0MkUjQIVDqhk3VTgkHMquQVK9qvI+AZJO7L7wSvjwgMbQsxZlQgjwtitBftIlroJjI f4bwT/keAMUdaneXKdQePEoi8deE/iEr/9hXLRJSkARKJBMRA4zx98AnPo9/e9dPOAkV elJ7atGccUerh5qebCV4/Sv2sAfSCpWUjmnTtQ7DW60/Ja4wo+hlClFy0H0z4+fLiNxM 6op0+WnfF6KwzuEbPxnbZdfJUP15TfMchYUpdBJLNqypbnYxkn47glIpKDi010WJfrmh zlhQ== X-Gm-Message-State: AOAM533eBCmprTUgDpRWoVXA1oa4jNiBbL6xUp5+6LXxZfu/ffnjZ+50 z22t1+g52HHY6iS4skKED2AWzop924HAlQE30TI= X-Google-Smtp-Source: ABdhPJzlCpx0aMPDG1UTtHx9ORvSAqoLR+lQwLXGS36HfGe3zsY4SMHWTdYCDU1z6eHE+BRbHFkmE7hhGlwtP40PCPw= X-Received: by 2002:a17:90a:c297:: with SMTP id f23mr26676792pjt.197.1620642184074; Mon, 10 May 2021 03:23:04 -0700 (PDT) MIME-Version: 1.0 References: <20210428225046.16301-1-wuchi.zero@gmail.com> <20210509163633.ced3588cb92984c0d3835fc3@linux-foundation.org> In-Reply-To: <20210509163633.ced3588cb92984c0d3835fc3@linux-foundation.org> From: chi wu Date: Mon, 10 May 2021 18:22:53 +0800 Message-ID: Subject: Re: [PATCH] mm/page-writeback: Fix performance when BDI's share of ratio is 0. To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, tj@kernel.org, Howard Cochran , Miklos Szeredi , Jens Axboe , Jan Kara Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4CC4B500153B X-Stat-Signature: 4ftt6u19zjmep3wp55iyrjuxcdd9t441 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b="KsiOvL/w"; spf=pass (imf01.hostedemail.com: domain of wuchizero@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=wuchizero@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf01; identity=mailfrom; envelope-from=""; helo=mail-pl1-f182.google.com; client-ip=209.85.214.182 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620642182-987867 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Andrew Morton =E4=BA=8E2021=E5=B9=B45=E6=9C=881= 0=E6=97=A5=E5=91=A8=E4=B8=80 =E4=B8=8A=E5=8D=887:36=E5=86=99=E9=81=93=EF=BC= =9A > > On Thu, 29 Apr 2021 06:50:46 +0800 Chi Wu 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 =3D 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 th= e > > 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 work= s) Thanks, I'll correct it in the future. > > > Signed-off-by: Chi Wu > > 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 =3D &gdtc_stor; > > struct dirty_throttle_control * const mdtc =3D mdtc_valid(&mdtc_s= tor) ? > > &mdtc_stor : NULL; > > + unsigned long reclaimable; > > + unsigned long thresh; > > > > /* > > * Similar to balance_dirty_pages() but ignores pages being writt= en > > @@ -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 =3D wb_calc_thresh(gdtc->wb, gdtc->bg_thresh); > > + if (thresh < 2 * wb_stat_error()) > > + reclaimable =3D wb_stat_sum(wb, WB_RECLAIMABLE); > > + else > > + reclaimable =3D 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 =3D wb_calc_thresh(mdtc->wb, mdtc->bg_thresh); > > + if (thresh < 2 * wb_stat_error()) > > + reclaimable =3D wb_stat_sum(wb, WB_RECLAIMABLE); > > + else > > + reclaimable =3D wb_stat(wb, WB_RECLAIMABLE); > > + > > + if (reclaimable > thresh) > > return true; > > } > > > > -- > > 2.17.1