Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1334784rwr; Thu, 20 Apr 2023 13:26:00 -0700 (PDT) X-Google-Smtp-Source: AKy350anq177XhTpQE1udfukr3cT41ijjc6oJL8XjroSsZfvtPBpR6D2o09K5+01eCun2u7jEI7a X-Received: by 2002:a17:90a:f292:b0:247:6022:9595 with SMTP id fs18-20020a17090af29200b0024760229595mr2688602pjb.45.1682022360112; Thu, 20 Apr 2023 13:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682022360; cv=none; d=google.com; s=arc-20160816; b=yL2/oIwnNVMiM5A1QrCA5KGFBl/w6B8xL4UFxYlkqTC8QtGPUAylNY8JpZza3X/TPp LLQAqybZ/0KR61XB5zSARAVx0IE+L+F1fnvkq6O6+Zcq4tV2Zas7e/Iy+0/dDVx6pECd pHXmwXJ4urT6Ph+VP6SWAsUacsk/CLSM/mptbhgVEcrWnKhj3pXRmi8BO0Z9ZDT1Io+j YR6pRfkn2AMkOuohdUHOG19HhKc5qpdPQn+Q5UpXM86T68GNhRLfBakoVzwqi36c9nef JDSPTUhVvtVojMIPUUNFRJDFOEt3hR9YIO7l/qlgT8V2opFlSu7qcTelRXHqqsr2cOlO T7DQ== 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=RDPS2kJGA9qHFAhB01dB7yBOdSjj/en4thGsxxtxQ0Y=; b=FXkIu8KunffXkZVusxbHeePrWfHBFsQMVqsxSrDgB/nSHJY3y597xmPl5pzjM1eoxK GZUVnoPcjry1V1OYBeUukjgPjjgDGb1triEPPsl+Pho8pUikm9c5aFAARiSwVaqqnr3G 5h+JZdFM+pylKU7ybMiN6y7nDwmqqJlu/cGbeZJqkKQEIkjUQmqrzynZdMh8mrZwbZY5 yniyJzel7ZLlI6ynJR1NLOgBsZJeMYVj1v0AhfxBqLd5KuP4RdXD37rAAOCLUS24b8JV UNzwrjhoDPwZ3lAGMztBjmrUL8UJ+UYnmKbGt+c1EGhuW4dlVE9PgYTLxhl0/n6sSHaa kOFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=EGJMPcsy; 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 l1-20020a170902f68100b001a6cb738b8csi2694411plg.550.2023.04.20.13.25.46; Thu, 20 Apr 2023 13:26:00 -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=EGJMPcsy; 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 S232358AbjDTUZX (ORCPT + 99 others); Thu, 20 Apr 2023 16:25:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232516AbjDTUYr (ORCPT ); Thu, 20 Apr 2023 16:24:47 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D85D72BE for ; Thu, 20 Apr 2023 13:23:30 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-94f6c285d92so118711366b.3 for ; Thu, 20 Apr 2023 13:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682022209; x=1684614209; 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=RDPS2kJGA9qHFAhB01dB7yBOdSjj/en4thGsxxtxQ0Y=; b=EGJMPcsyHoAX/3gJSN5xuzkkXvuy7iPOrcCdkFFe5y4qoCmbLuUudZ5/py08XvZhAD dTESHFeDumQ2LmNnLOMS8aDauca5eoCn+hdL6UEhIyzkE1wwZHtB7EaW0ttXr/UB1/yo 30CiV9bU0Ied0qmn7FdLPavRsZfDwtu9FTDG/cSmGQASCWDb3iAhYHICJ3KKwcZYnQUf LAFiq4XGTjTI7PcCQVTQHP286d/cKqQucx0gkmMRuQVaGQGuuLHbr6IW14F9/+HPpVwj hPkuaDIbBkTtFGVKEB4DEGjLzorQM0fNJEw/yASZ3odr6htflmHhSoLYzmq/4N7BOWd7 dALg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682022209; x=1684614209; 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=RDPS2kJGA9qHFAhB01dB7yBOdSjj/en4thGsxxtxQ0Y=; b=GBdSUY03WnMZGqgZZoftFcKAvDlEEY20yEecJ2uAFtLYO3hPIc4J5doembqVvybUzg QIhc1Sk+nshq6wBNGwqq2eUYsie0QYpiZBcE/Pgrs5DLYYgDT6nuDyEkfSDW2caaaHlv ld5ivvlN5GU+cT8yD/D2ZXUynY1MpZ8q1XqCD7NLk0lY6QMpbzWcqc5b6o6C2ko78HQf b+UFiNDHpjLTFd/6La2/mjsvQq78peiLqiKeNZGN8HdQUPhGepKUofen1PUI8OIdXrEA cOZyYpFUBiPVLYYp6a6LbQXtjqFBtbmnKwG3dictrLam4ZJoyyHvSKz8UVjeYu9SeSZP LMUQ== X-Gm-Message-State: AAQBX9fBi9g2cY/Se80+evnxmbss+QGNV3jxDfwRyqCdWdZ1XDeqpgkT Y6zFQmfIUkB84rQMMK2a67bik/sDyHsefIDqkKTITg== X-Received: by 2002:a17:907:50a1:b0:878:7c18:8fd9 with SMTP id fv33-20020a17090750a100b008787c188fd9mr149599ejc.44.1682022208633; Thu, 20 Apr 2023 13:23:28 -0700 (PDT) MIME-Version: 1.0 References: <20230403220337.443510-1-yosryahmed@google.com> <20230403220337.443510-2-yosryahmed@google.com> In-Reply-To: From: Yosry Ahmed Date: Thu, 20 Apr 2023 13:22:52 -0700 Message-ID: Subject: Re: [PATCH mm-unstable RFC 1/5] writeback: move wb_over_bg_thresh() call outside lock section To: Shakeel Butt Cc: Jan Kara , Jens Axboe , 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=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 Thu, Apr 20, 2023 at 11:53=E2=80=AFAM Shakeel Butt = wrote: > > +Jens & Jan > > The patch looks good but it would be nice to pass this patch through > the eyes of experts of this area. Thanks for taking a look and CC'ing folks. I will make sure to include them in the next rounds as well. FWIW, Jens & Jan did not show up when I ran scripts/get_maintainers.ph if I remember correctly. > > 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= to > > * include all inodes that need writing. Livelock avoid= ance is > > @@ -2075,13 +2077,19 @@ static long wb_writeback(struct bdi_writeback *= wb, > > * mean the overall work is done. So we keep looping as= long > > * 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 > >