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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DA17D6ED0E for ; Thu, 21 Nov 2024 11:50:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA4636B00A6; Thu, 21 Nov 2024 06:49:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C2C176B00A7; Thu, 21 Nov 2024 06:49:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA57B6B00A8; Thu, 21 Nov 2024 06:49:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 895166B00A6 for ; Thu, 21 Nov 2024 06:49:59 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 39F6880A98 for ; Thu, 21 Nov 2024 11:49:59 +0000 (UTC) X-FDA: 82809932772.28.9EA44A7 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf06.hostedemail.com (Postfix) with ESMTP id 92655180008 for ; Thu, 21 Nov 2024 11:49:19 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=eL6cOxuP; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=DfPyXL+N; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=eL6cOxuP; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=DfPyXL+N; dmarc=none; spf=pass (imf06.hostedemail.com: domain of jack@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732189611; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GQJmzcEK5Mg1r3/eEDfuHI1PwGO7fARlwgDUnl7dBU0=; b=US28NnufL4KTBuFq0qbf8y33kRMb0+SmIAs9jHFHs6edJkFM1vOzxpPOZkb2OELt8wjzJf Q2FCwHwYOUkMjRz2sWQ1S+iDGgT3ltpOcdthxY0fyZ/t5G2VZL5PMi0lKGMHQoLvQvXyyL NHXSC7XBN6MwXAPjGKrT/MeRH7flshk= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=eL6cOxuP; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=DfPyXL+N; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=eL6cOxuP; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=DfPyXL+N; dmarc=none; spf=pass (imf06.hostedemail.com: domain of jack@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732189611; a=rsa-sha256; cv=none; b=kPEjZkeveaTevrctyYiGbCrsmf6u7bFurRSlO4gCXeyzUAy4QlbZABne2eEB0qpNf7YrQ+ J7elo3wN77sRaJhwtkT8kQsys7lHaHhj0NEpUAyzU41IQhmjZ8et+dC8LqEMor+dUYiuEA Aw5ytFPzKzs+yUrrl21KKakeK+AJXAQ= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 59E541F800; Thu, 21 Nov 2024 11:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1732189795; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GQJmzcEK5Mg1r3/eEDfuHI1PwGO7fARlwgDUnl7dBU0=; b=eL6cOxuP9bDelgonDV1jZ2wcdwkl1OHB24gfKYdtITJ81pRWhsgGz1d7DIraCwPCN2z8QC cQwB1UJgQD86Z/fdhZjb7pY93oNtQ4K4sIoVA5lS0uierVrh22brNUjHeJ1dp+kZHqVV1y /PmXPjoLf8FWAifs32H91vr4VregkUg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1732189795; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GQJmzcEK5Mg1r3/eEDfuHI1PwGO7fARlwgDUnl7dBU0=; b=DfPyXL+NfV2NK01c8fD3yGDfcmKtWjl2OyVz6xaI7ADqdO6+hvMw2kYjytRf44D9P/Qd99 ANXBVacXrm7sBHDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1732189795; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GQJmzcEK5Mg1r3/eEDfuHI1PwGO7fARlwgDUnl7dBU0=; b=eL6cOxuP9bDelgonDV1jZ2wcdwkl1OHB24gfKYdtITJ81pRWhsgGz1d7DIraCwPCN2z8QC cQwB1UJgQD86Z/fdhZjb7pY93oNtQ4K4sIoVA5lS0uierVrh22brNUjHeJ1dp+kZHqVV1y /PmXPjoLf8FWAifs32H91vr4VregkUg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1732189795; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GQJmzcEK5Mg1r3/eEDfuHI1PwGO7fARlwgDUnl7dBU0=; b=DfPyXL+NfV2NK01c8fD3yGDfcmKtWjl2OyVz6xaI7ADqdO6+hvMw2kYjytRf44D9P/Qd99 ANXBVacXrm7sBHDw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 49BB113927; Thu, 21 Nov 2024 11:49:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id reK2EWMeP2dJCQAAD6G6ig (envelope-from ); Thu, 21 Nov 2024 11:49:55 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id EA8D4A089E; Thu, 21 Nov 2024 12:49:50 +0100 (CET) Date: Thu, 21 Nov 2024 12:49:50 +0100 From: Jan Kara To: Jim Zhao Cc: jack@suse.cz, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org Subject: Re: [PATCH v2] mm/page-writeback: raise wb_thresh to prevent write blocking with strictlimit Message-ID: <20241121114950.5ie64l3lmi3dkoz5@quack3> References: <20241113100735.4jafa56p4td66z7a@quack3> <20241119114444.3925495-1-jimzhao.ai@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241119114444.3925495-1-jimzhao.ai@gmail.com> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 92655180008 X-Stat-Signature: ygo5d1y719ht4q9iupaabd1aq8p3ho45 X-Rspam-User: X-HE-Tag: 1732189759-442326 X-HE-Meta: U2FsdGVkX1+d+nJD4O/MFaTAHfgry5ERgYP1cH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uyVUkeoxI5hcSJhc3AoLwJd/Vhgj0PBLh55RO7Hn0q4po/9U5gRy+LqeBpHuWW7AMfm5K/3MIDIYeBhcRKRs8bQd/BNoRTtTBZP42zIH58rpUwtPT2AtAVFF/VJ9EkWQYcxZX1DK+qruGINUqQrIbKI9N71EiQq7R9hHpH1K9BX3Qzjnqhdn0R5r3KPtYIupjc4qdiYwLnD1s2ASyIxMHkRPLACoURafmjul/D3C1yIvoM/7iCWzIaSBocPAHt+TRFcH/fEoY4wKkIOO4B/k/63tJvg+pJpjXolMBdoezJcQoVdiXaWxVqOIFcTfkVKg5ZO0/kaEyGIO2Eg8mFPfoWB0Cw5vbQ6v5uH7B/ 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: List-Subscribe: List-Unsubscribe: On Tue 19-11-24 19:44:42, Jim Zhao wrote: > With the strictlimit flag, wb_thresh acts as a hard limit in > balance_dirty_pages() and wb_position_ratio(). When device write > operations are inactive, wb_thresh can drop to 0, causing writes to be > blocked. The issue occasionally occurs in fuse fs, particularly with > network backends, the write thread is blocked frequently during a period. > To address it, this patch raises the minimum wb_thresh to a controllable > level, similar to the non-strictlimit case. > > Signed-off-by: Jim Zhao > --- > Changes in v2: > 1. Consolidate all wb_thresh bumping logic in __wb_calc_thresh for consistency; > 2. Replace the limit variable with thresh for calculating the bump value, > as __wb_calc_thresh is also used to calculate the background threshold; > 3. Add domain_dirty_avail in wb_calc_thresh to get dtc->dirty. Since the odd value of BdiDirryThresh got explained (independent cosmetic bug), feel free to add: Reviewed-by: Jan Kara Honza > --- > mm/page-writeback.c | 48 ++++++++++++++++++++++----------------------- > 1 file changed, 23 insertions(+), 25 deletions(-) > > diff --git a/mm/page-writeback.c b/mm/page-writeback.c > index e5a9eb795f99..8b13bcb42de3 100644 > --- a/mm/page-writeback.c > +++ b/mm/page-writeback.c > @@ -917,7 +917,9 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc, > unsigned long thresh) > { > struct wb_domain *dom = dtc_dom(dtc); > + struct bdi_writeback *wb = dtc->wb; > u64 wb_thresh; > + u64 wb_max_thresh; > unsigned long numerator, denominator; > unsigned long wb_min_ratio, wb_max_ratio; > > @@ -931,11 +933,27 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc, > wb_thresh *= numerator; > wb_thresh = div64_ul(wb_thresh, denominator); > > - wb_min_max_ratio(dtc->wb, &wb_min_ratio, &wb_max_ratio); > + wb_min_max_ratio(wb, &wb_min_ratio, &wb_max_ratio); > > wb_thresh += (thresh * wb_min_ratio) / (100 * BDI_RATIO_SCALE); > - if (wb_thresh > (thresh * wb_max_ratio) / (100 * BDI_RATIO_SCALE)) > - wb_thresh = thresh * wb_max_ratio / (100 * BDI_RATIO_SCALE); > + > + /* > + * It's very possible that wb_thresh is close to 0 not because the > + * device is slow, but that it has remained inactive for long time. > + * Honour such devices a reasonable good (hopefully IO efficient) > + * threshold, so that the occasional writes won't be blocked and active > + * writes can rampup the threshold quickly. > + */ > + if (thresh > dtc->dirty) { > + if (unlikely(wb->bdi->capabilities & BDI_CAP_STRICTLIMIT)) > + wb_thresh = max(wb_thresh, (thresh - dtc->dirty) / 100); > + else > + wb_thresh = max(wb_thresh, (thresh - dtc->dirty) / 8); > + } > + > + wb_max_thresh = thresh * wb_max_ratio / (100 * BDI_RATIO_SCALE); > + if (wb_thresh > wb_max_thresh) > + wb_thresh = wb_max_thresh; > > return wb_thresh; > } > @@ -944,6 +962,7 @@ unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh) > { > struct dirty_throttle_control gdtc = { GDTC_INIT(wb) }; > > + domain_dirty_avail(&gdtc, true); > return __wb_calc_thresh(&gdtc, thresh); > } > > @@ -1120,12 +1139,6 @@ static void wb_position_ratio(struct dirty_throttle_control *dtc) > if (unlikely(wb->bdi->capabilities & BDI_CAP_STRICTLIMIT)) { > long long wb_pos_ratio; > > - if (dtc->wb_dirty < 8) { > - dtc->pos_ratio = min_t(long long, pos_ratio * 2, > - 2 << RATELIMIT_CALC_SHIFT); > - return; > - } > - > if (dtc->wb_dirty >= wb_thresh) > return; > > @@ -1196,14 +1209,6 @@ static void wb_position_ratio(struct dirty_throttle_control *dtc) > */ > if (unlikely(wb_thresh > dtc->thresh)) > wb_thresh = dtc->thresh; > - /* > - * It's very possible that wb_thresh is close to 0 not because the > - * device is slow, but that it has remained inactive for long time. > - * Honour such devices a reasonable good (hopefully IO efficient) > - * threshold, so that the occasional writes won't be blocked and active > - * writes can rampup the threshold quickly. > - */ > - wb_thresh = max(wb_thresh, (limit - dtc->dirty) / 8); > /* > * scale global setpoint to wb's: > * wb_setpoint = setpoint * wb_thresh / thresh > @@ -1459,17 +1464,10 @@ static void wb_update_dirty_ratelimit(struct dirty_throttle_control *dtc, > * balanced_dirty_ratelimit = task_ratelimit * write_bw / dirty_rate). > * Hence, to calculate "step" properly, we have to use wb_dirty as > * "dirty" and wb_setpoint as "setpoint". > - * > - * We rampup dirty_ratelimit forcibly if wb_dirty is low because > - * it's possible that wb_thresh is close to zero due to inactivity > - * of backing device. > */ > if (unlikely(wb->bdi->capabilities & BDI_CAP_STRICTLIMIT)) { > dirty = dtc->wb_dirty; > - if (dtc->wb_dirty < 8) > - setpoint = dtc->wb_dirty + 1; > - else > - setpoint = (dtc->wb_thresh + dtc->wb_bg_thresh) / 2; > + setpoint = (dtc->wb_thresh + dtc->wb_bg_thresh) / 2; > } > > if (dirty < setpoint) { > -- > 2.20.1 > -- Jan Kara SUSE Labs, CR