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 F0587C77B7E for ; Thu, 20 Apr 2023 20:23:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EF03900003; Thu, 20 Apr 2023 16:23:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79F87900002; Thu, 20 Apr 2023 16:23:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66772900003; Thu, 20 Apr 2023 16:23:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 547D1900002 for ; Thu, 20 Apr 2023 16:23:32 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1746F1C6290 for ; Thu, 20 Apr 2023 20:23:32 +0000 (UTC) X-FDA: 80702894664.26.59587A5 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by imf28.hostedemail.com (Postfix) with ESMTP id 2D5B5C0015 for ; Thu, 20 Apr 2023 20:23:29 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=EGJMPcsy; spf=pass (imf28.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.43 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682022210; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RDPS2kJGA9qHFAhB01dB7yBOdSjj/en4thGsxxtxQ0Y=; b=dbLwSlhJxb97IrutWg5ft/MssVZkPYrSKKPB0VqQNOEiBJaghkI6q3a/V+uWAlCGJBciyO ETU2DFSVWqRpI/V0DJAowMoDg8zfKp9txmPdK0SyTs4M9NU18ShMJv+1QGhDMPBG7/EHWs VHlwVVVK1iX7vh2b6Qw8pTB2EISCeso= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=EGJMPcsy; spf=pass (imf28.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.43 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682022210; a=rsa-sha256; cv=none; b=LYdxJWgnbb6Kn50+aKAF4tjO/b8C9j1a2U2cw6eS3erUX/CWNtVcTeGka1CiDAuqqHjBZO rTi9kQ2x0S4G8ol/01/jEW+N5cZ+jR9aAqSeuPwxHzEsos+QzG8XGDK1ZekXZtuiVpo9vf /utccgrIRbXWHoCwh/WXz4KquI6lD74= Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-94f109b1808so119869566b.1 for ; Thu, 20 Apr 2023 13:23:29 -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=CxfOI8k2sonHbieb2cvqkDZHm9nukOvju+W17COsyNDEHRkEGBkMBzUnbSWTPXmtyX HF4CBI4RM2CD02bYCVGYQrQJePWRGrHyqQhM0s+ybqaPzoi5Jwi71Oa0nCKTBL4fpizF 5uCIZwpziDKgh5HxcdH6+ZBy2po3dUuH8+zJ+dHc2GXk2lqneLkbwmamAVly3WttFO/h lwmSJRVV7ryY01Uo1tmuJIPtVip7KyY1j/9sJOhowhL5sgjZSRyqZMxDZLAVwQZ8Eelt 82rU+846GLbiWrCIZfEPLIpFXG2m0LZrL+OODYhS0BMhDcRYHs7yxQYb0Fdk46A/4FsV 68uQ== X-Gm-Message-State: AAQBX9fbCOBRhP7CiXfAaaSVhDfD969B9Eo9kQ2bBfA3TzYoEpSIrmvR 7Nb60TyEPsAwb3YEaiy+0yCRJeDhNK+lHIUT4gYsNw== X-Google-Smtp-Source: AKy350Y6JgZn+n32RVYt90ndNBzxPcxioaUY46Yi32s9vSyYFUTnxZMryzRw8uFSHj66bl/ng+HSO9ExYjhITUUmcQ4= 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 2D5B5C0015 X-Stat-Signature: wgzwcuawqkkjrcs3b3aejhypo3fe7ji5 X-Rspam-User: X-HE-Tag: 1682022209-766799 X-HE-Meta: U2FsdGVkX18WS+pNETdH/aCKNaeT0nVYZ/MxBSdKYUMqLRof5ktM3Dl0ZOT+jWczMqWyQXnK7GP3fkYDWkS/Bsw+yd7BvFU1p5PsmyrwIc/j8k0ug7mCSyzkSor2/cA7TPehh77kWOcUX8OTOndKq5FXqp1RcPA8NNHI3r3bFCQRmkppkxgJo2BJpTumsU9qPUU37A/69U54U6E46iIdLohr/TKRWW/00drTptnqmqgMIao0ZUN+kuM4Mwh0XzNiBLcjDOMKFUINtjhbvkD2vy5ZWmPyT5R5awokkcNDZJgzlfMtdrn4xqYv55KzUAv5va/ZU4xiK6R39gA9dlzuB0M637OxK/TuwHv7OXYbRNR4NkvG17eRzImrOHGOTe7OQUl3eXNk9yZ+Fca4iYbWM4ASR37/qKbpRS7s/zzWZpSPkLx5/mU4xJv1vKbfeIP/2IG7uanQW8ZhjU0+6Xd5HyMb0LTFepC+d08BV+Icg+ulIAbc/sfcfqkGMJodEvdM1kV+MlCOak4HBmcZzzJpzddquQxYjL53kiyBSIn43vPhW+t/Fvzr/7KCzCfBfWJpkKWxvhz9cxciKmytml7N71Brjo/32/VxO5dlL80h3nfZxq75Qiv1aXpfG2EV2VyuRbjAuXuQdDYsC2yMMSLe54I/d0gBkODCnZzyvQU7pr0Ja/m8CTz5IMJGiapzv0scwj3W5vjlQcF9I3UgD2oYFYGHPLi+47UAL4+M3dbu5eX8QzdE2oOWlrzRHKm6bDIe9KOgrKAwNudYZosv5ES0AeryqhLc7aeaoucW0Ttbw5hvnYTibYSRFurifOGuR/rBeKj/0qJ1PQXFWR6fZWoLX7myjM8WPnCZWxgI09GO4tnx2xxyKE7aNlx46HSA116Bf4tIw8D8QlfIxMMOrUM1l1fh+PZZ7Ln1SqdqsYVsBfJ8LNrBgRstlkEELUzbFVC/1EMPWLZ3uDte0qOMV2c hpwaIsS3 YRzDlEqiUrmdOUX7dacvLVvL7OJYMny/VMilTUAxAAgTkeDS8mJKCN6xUVMb4+r0zlPwZLjTFEMap6sah9gy5v6w0CYtN++rTO5FCnKOeopFPzky2s9DZ8+D6+w14oWcqWP0pXd9oNCLFeTy5kgzlSU40Zxhj5Wmz7DN1IfLzz+4EaGS/OJfC6oltJnT5INpYHWTnitYPHAWpBoDHhDttiq5xg0knCauz8eO+aUp0+8lOdFcNMeGOtaecjuPSK56wR4OzJRcmXTPowkHDE0Z2cc0XMomIiIH988y64/NsHz6oH+U= 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: 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 > >