Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1238243rwr; Thu, 20 Apr 2023 11:55:29 -0700 (PDT) X-Google-Smtp-Source: AKy350Yg4wIU2kza+j/6x+hDIBbChQlUMeoZUN8DKcTmQxd0BKPXzweAPlHbrRnxbdo3lmFz29i0 X-Received: by 2002:a05:6a00:1a53:b0:63d:311a:a16b with SMTP id h19-20020a056a001a5300b0063d311aa16bmr2727900pfv.23.1682016928537; Thu, 20 Apr 2023 11:55:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682016928; cv=none; d=google.com; s=arc-20160816; b=pjSeBS5azZNFSY7MW6vhL6ILVCHj2ozLO+/9EhJVfgSHs8LX5Uggiu+GJRKs6UmIjG ur/amIto8kyXcIkaKOUH9mm3VFhsd/ar+G1GVxkk7+vhOUwfiapb6ahJv+aiWdEzK6Kv Jzbe/rv+f4Xy5uENewFR6NAT9BRiDmJjgClpA8WbWRyHwWEmBsmdditkCiV49czh8Hh2 qbKpUqLu7g2Hy0tXsTW0qh4OKOj/1Ya8uXLaN5NzUAUdd93Hkpi30cmN7mXe3LOycppg z6jMsLWfn/frVsMD5/K5jCUWWC8erNHUQF6N1NW9IAQV63OsTbhCV3cIYhkVb6l2urOz 2Bdg== 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=4sYlJSAfMy5ZKFxBnqgIBVbqBgUxlBgjbZy6mx61ZB0=; b=d7VpCWX13Rspb/vEuZ0idyVbdobvsB/6+oI8GnWpHPapfvtD42ojZl9rv23OYiYvvl oO5L40u7u9e7ZRadrq3AsT/E099PAtWoIXKKu39e1th2E3nGWk3X4BXNh+bZJzTasgt6 pXVcp4t+HimiwdLcfS8JCDqNK0ciiMROF8tjnXlujpclYP6XxNLOiY9C2ttSuZlbGGv/ E2/h4S9YM+/ZKTmU0x5IY5Q/lfRCRpKemrNIu7DKf2WaQ587sf65W5AKer+GSssBIxGW 4XyhIduion1/LkCyp5L28g5P0Faq/dBTJVjPlU4pGQNIXCzC9+gzhOspVgN60S3muDcT EoVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=wPs26Moc; 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 j123-20020a625581000000b0063b2399c58asi2204130pfb.195.2023.04.20.11.55.13; Thu, 20 Apr 2023 11:55:28 -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=wPs26Moc; 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 S230129AbjDTSya (ORCPT + 99 others); Thu, 20 Apr 2023 14:54:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231638AbjDTSyD (ORCPT ); Thu, 20 Apr 2023 14:54:03 -0400 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19CB155AF for ; Thu, 20 Apr 2023 11:53:33 -0700 (PDT) Received: by mail-qt1-x832.google.com with SMTP id d75a77b69052e-3ef34c49cb9so893121cf.1 for ; Thu, 20 Apr 2023 11:53:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682016812; x=1684608812; 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=4sYlJSAfMy5ZKFxBnqgIBVbqBgUxlBgjbZy6mx61ZB0=; b=wPs26Moc03UYXJfZwMIlURgsn2RCjMAbb7a+Kr6qiZim9sSPBSM+ZdRg4TYPr4vYxC QmCGtQFf+XPuri/obaV1duh6RAYA1qF/ZHAWZew0TZE7gE7UZb675H1CuZBgHJZA9Ze3 JQDW57Ph2p1gegrBk5yb+/Cugi0waHR4zf/tF/KJuRI6aDUUzOySpS2PNB/mXKSyqIaj D6omDunMmwh7KE2tnbKxW3RSmLqgYQtibyeHI+ZrrYfdfCGk4cwgkrE06btrC9PAEVdR Ph0y7LUZGeuxMPJOCKnLmZqnjGOPUXbAkl8GvlEHQuAkYggnt45ueFJhkm469/iP9wO1 wwEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682016812; x=1684608812; 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=4sYlJSAfMy5ZKFxBnqgIBVbqBgUxlBgjbZy6mx61ZB0=; b=NL1leC+875nsf5Kg3h6Go6QBBBXLLmSbsAxFw3WMyyJzogg1HjtAHirYfyepsRktqn xw78XG5xJemdK8/AYyQt4Pbgh8TPK21b0dlmgIz7t5vZ0ZQ12VjNQ2kXIvs7oBVfwze9 AXcqpC/1GO7REXGfOrX0G/E52VNi5dd8rddvTodZJHqV09Ysbo2sNEMJRKCYhyk3EF/e TBbee6BLqnVmPFEhXjwN90yH+5CNAn4rM+59SZiDobFXDAMzjvrIgbAqYsAMdzrOUMn6 oT2omPsJyczrDSsJida5Koa/JZK/NPbryj8pMTO30SR0oSZRP2h/XcqBUNDTD4xveZAR 2paA== X-Gm-Message-State: AAQBX9fe+2DOl5pK4gscBIK9vwZ/jJN7bBTTOYy3U3d7vOEOlROZ/YOP 1F/pSB/cQmlxKCoBbFUE2KwjPnH47fXuHVpFC2svPA== X-Received: by 2002:ac8:5b10:0:b0:3ef:343b:fe7e with SMTP id m16-20020ac85b10000000b003ef343bfe7emr59146qtw.2.1682016812108; Thu, 20 Apr 2023 11:53:32 -0700 (PDT) MIME-Version: 1.0 References: <20230403220337.443510-1-yosryahmed@google.com> <20230403220337.443510-2-yosryahmed@google.com> In-Reply-To: <20230403220337.443510-2-yosryahmed@google.com> From: Shakeel Butt Date: Thu, 20 Apr 2023 11:53:21 -0700 Message-ID: Subject: Re: [PATCH mm-unstable RFC 1/5] writeback: move wb_over_bg_thresh() call outside lock section To: Yosry Ahmed , Jan Kara , Jens Axboe Cc: Alexander Viro , Christian Brauner , Johannes Weiner , Michal Hocko , Roman Gushchin , 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=ham 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 +Jens & Jan The patch looks good but it would be nice to pass this patch through the eyes of experts of this area. On Mon, Apr 3, 2023 at 3:03=E2=80=AFPM 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 > --- > 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 >