Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2572950rwr; Fri, 21 Apr 2023 10:39:16 -0700 (PDT) X-Google-Smtp-Source: AKy350biukI1ETQkR1Es29qX1U3dDvXYAk1qS7cNruc86csefUEHRhwB/Xc7jqKuszKwVsB3E0ER X-Received: by 2002:a17:902:d503:b0:1a6:7b92:15c2 with SMTP id b3-20020a170902d50300b001a67b9215c2mr7208490plg.4.1682098756544; Fri, 21 Apr 2023 10:39:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682098756; cv=none; d=google.com; s=arc-20160816; b=mC7ePAQ5Zfd+FKrYD/7baxgHF9kdEVRXR9WzVYlDoThSvMIddE4k0M6/4SuvBZNNdM wTU5/000It613SdcdkZ4jYP+b2W1M0uijEjHL7Uk1K7oH0TMkS3Gj7ijlm6rIBJ6LGqU Bn36ECiaUaUCgHWLwaqgTEfTeO8cOIAk7OoY4jZJ8FlE6LZgw8Hw+iOblneukGtdZLb0 kiqOe7TtYtktnn6i6mPaXEbNugAOuttud459sHpYptwZcEqsj1pw+RYfjwlaUTrGKvoe mRdn2rIpxXzXz23X/p01fvyMcxbnf3nm3unLj4nVkPdsFHLQD6rGbERAnsoI8aYkF1iH iSKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=BfR9lcqvLbO+sXRYYQ4Al5uQ4a/w4jqcaiHNX0XG2d8=; b=AVIqb85t9xhAnT5PCLrUJP+cxF2meZhIHTn6Nuxd3MaaDXRzpsPfnMTmE9jNuFT0Dv E43VR+GxEPFrDm/wKErj06q18u2rAdornHUomWAFG1ZkW+qr85bC5IX3WAK3r6P0CpjG QzhZnRdGubfO3MURw9helGd6/9lG+axW8ln+MNHhw9zHCGGE3EM1Mut5adfESR3xdEoP wnWaIOV7UuHI5FgIeDZPLw0/X55W90bu9AUNo9fhmRuy3VnhnseQ7fxoqHn8gK9syjMD RhiY+dCHq3B2nLWV/e2ViIEbDDgJAKIdBad9voBuY3P98l8ufrzODuRqNFnm0guUCfHX eKDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=M7kgruF3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bb18-20020a17090b009200b0024666c4e8d8si7452313pjb.187.2023.04.21.10.39.04; Fri, 21 Apr 2023 10:39:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=M7kgruF3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232545AbjDURWT (ORCPT + 99 others); Fri, 21 Apr 2023 13:22:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232630AbjDURWS (ORCPT ); Fri, 21 Apr 2023 13:22:18 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A62393F4 for ; Fri, 21 Apr 2023 10:22:16 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-94a34d3812dso322824466b.3 for ; Fri, 21 Apr 2023 10:22:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682097734; x=1684689734; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BfR9lcqvLbO+sXRYYQ4Al5uQ4a/w4jqcaiHNX0XG2d8=; b=M7kgruF3UfRfDWNCLtS06HOrbY/My1F5qsoj3AdCxeDtL9AnMCKstRKn/+mzyTSJXD nUELrf0ki/bVD0Bf6VaQ/BPcAyOipMfOJft9lnwibEAhqePhPxl+6N2xFt8K2aLmxT4d eI7byFtpOOMmoO8AzyO787vo6Mv+NG+LT4/rW6D9JlgChyif1F0ltmnqqBIp/0Lsuu0m IO2ZCJHgpTWXkJgsbgBAHGD8t9exscbi9IJH23YwGaJndjTrVI5DhTELy21qO5sIXB3J AiAoU6sruhfjdjNyk8Fg+wuorOokt2S7FMxMvRhCaYZ/12NWLYAdQflE/0HQdBDR8ffd FQfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682097734; x=1684689734; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BfR9lcqvLbO+sXRYYQ4Al5uQ4a/w4jqcaiHNX0XG2d8=; b=WLXtoXJOX7E7YQZPsFlZlmCyb0Q6dDQhAt6FBZFk+OEZeuGp3me0Kjzd88E2wsdQ7g tA/+mGvvh+kwEZ/leU+e7q0SVbZhdkP32jV+rr707M3mDKx82iX7XkaTFii2G9WbI+Uw gunYRCL1OBPn7Aos11xkAoqqj/WJcOBaxkZn7fqb1JM0OUG78k5loiudsynEZDp8stRU dwrjY91nXr3/BaLxAM/tkKIWZzTlpidgTo5zE6VRvKa61eSJR/ms9j8uSlk02ZEaF47F 8pY2MlZBbMV7msHN0vDTMJqFAF7MmaXFH1ciBJdOKFkJb7uzLKkGMpUmGXGQ0gUdzFhE LHAg== X-Gm-Message-State: AAQBX9eLjmqYRPRqIAHxnXUoNVhuQoWrRFiDiTRTPPZTLDR2KPDtJRTE 1Uz2Y1Tx+y7NK4N7mE1CEN9n96DprixGvl63CB48pg== X-Received: by 2002:aa7:d385:0:b0:4fb:7ccf:3b33 with SMTP id x5-20020aa7d385000000b004fb7ccf3b33mr5514114edq.31.1682097734305; Fri, 21 Apr 2023 10:22:14 -0700 (PDT) MIME-Version: 1.0 References: <20230403220337.443510-1-yosryahmed@google.com> <20230403220337.443510-2-yosryahmed@google.com> <20230421085341.b2zvzeuc745bs6sa@quack3> In-Reply-To: <20230421085341.b2zvzeuc745bs6sa@quack3> From: Yosry Ahmed Date: Fri, 21 Apr 2023 10:21:36 -0700 Message-ID: Subject: Re: [PATCH mm-unstable RFC 1/5] writeback: move wb_over_bg_thresh() call outside lock section To: Jan Kara Cc: Alexander Viro , Christian Brauner , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 21, 2023 at 1:53=E2=80=AFAM Jan Kara wrote: > > On Mon 03-04-23 22:03:33, Yosry Ahmed wrote: > > wb_over_bg_thresh() calls mem_cgroup_wb_stats() which invokes an rstat > > flush, which can be expensive on large systems. Currently, > > wb_writeback() calls wb_over_bg_thresh() within a lock section, so we > > have to make the rstat flush atomically. On systems with a lot of > > cpus/cgroups, this can cause us to disable irqs for a long time, > > potentially causing problems. > > > > Move the call to wb_over_bg_thresh() outside the lock section in > > preparation to make the rstat flush in mem_cgroup_wb_stats() non-atomic= . > > The list_empty(&wb->work_list) should be okay outside the lock section > > of wb->list_lock as it is protected by a separate lock (wb->work_lock), > > and wb_over_bg_thresh() doesn't seem like it is modifying any of the b_= * > > lists the wb->list_lock is protecting. Also, the loop seems to be > > already releasing and reacquring the lock, so this refactoring looks > > safe. > > > > Signed-off-by: Yosry Ahmed > > The patch looks good to me. Nice find. Feel free to add: > > Reviewed-by: Jan Kara Thanks for taking a look! > > Honza > > > --- > > fs/fs-writeback.c | 16 +++++++++++----- > > 1 file changed, 11 insertions(+), 5 deletions(-) > > > > diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c > > index 195dc23e0d831..012357bc8daa3 100644 > > --- a/fs/fs-writeback.c > > +++ b/fs/fs-writeback.c > > @@ -2021,7 +2021,6 @@ static long wb_writeback(struct bdi_writeback *wb= , > > struct blk_plug plug; > > > > blk_start_plug(&plug); > > - spin_lock(&wb->list_lock); > > for (;;) { > > /* > > * Stop writeback when nr_pages has been consumed > > @@ -2046,6 +2045,9 @@ static long wb_writeback(struct bdi_writeback *wb= , > > if (work->for_background && !wb_over_bg_thresh(wb)) > > break; > > > > + > > + spin_lock(&wb->list_lock); > > + > > /* > > * Kupdate and background works are special and we want t= o > > * include all inodes that need writing. Livelock avoidan= ce is > > @@ -2075,13 +2077,19 @@ static long wb_writeback(struct bdi_writeback *= wb, > > * mean the overall work is done. So we keep looping as l= ong > > * as made some progress on cleaning pages or inodes. > > */ > > - if (progress) > > + if (progress) { > > + spin_unlock(&wb->list_lock); > > continue; > > + } > > + > > /* > > * No more inodes for IO, bail > > */ > > - if (list_empty(&wb->b_more_io)) > > + if (list_empty(&wb->b_more_io)) { > > + spin_unlock(&wb->list_lock); > > break; > > + } > > + > > /* > > * Nothing written. Wait for some inode to > > * become available for writeback. Otherwise > > @@ -2093,9 +2101,7 @@ static long wb_writeback(struct bdi_writeback *wb= , > > spin_unlock(&wb->list_lock); > > /* This function drops i_lock... */ > > inode_sleep_on_writeback(inode); > > - spin_lock(&wb->list_lock); > > } > > - spin_unlock(&wb->list_lock); > > blk_finish_plug(&plug); > > > > return nr_pages - work->nr_pages; > > -- > > 2.40.0.348.gf938b09366-goog > > > -- > Jan Kara > SUSE Labs, CR