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 46C3AEB64D7 for ; Thu, 29 Jun 2023 00:02:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFAEE8D0002; Wed, 28 Jun 2023 20:02:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C83B88D0001; Wed, 28 Jun 2023 20:02:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B25198D0002; Wed, 28 Jun 2023 20:02:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A00978D0001 for ; Wed, 28 Jun 2023 20:02:06 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 719078064F for ; Thu, 29 Jun 2023 00:02:06 +0000 (UTC) X-FDA: 80953832652.06.08AE00E Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 0779C120024 for ; Thu, 29 Jun 2023 00:02:03 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=b9KvWHJr; dmarc=none; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687996924; a=rsa-sha256; cv=none; b=qTy/ZHYrpGrD0p7hR/Fkxt0haatzjHsS2qYZ8kL14J+SJRG4wTZ+dGLasjPe6+Cqo+wtsG 5CMczIMNZ2GLZNWyLTMvJ2HCf+56V5WIyjQHOvSn7dxkjEifELKxwNdCBDgfhDAySAJeUC Lf/h+d1BI3+8561CIePIHgwR9eYI4b0= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=b9KvWHJr; dmarc=none; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687996924; 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=EesjQ1CwpnFXfNGbq1/L/h6YQv0U8+XJ4R+B/3hRf58=; b=UPJMwRzJBc+0yZmqzqbSr/xJjAkbjmlW6BK+C4tXuWOOyF5w/+P8ZQgkEQUIQX5Y6ByBMl WxgxuQT9GHxv313do472EkglwAZi/AGYu34b2EstyeVfEf9gu7SMn7jcVGnBTilhve9FfH TpDXu5K9c1m+XOGvUX5BRprhKdGM7B0= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=EesjQ1CwpnFXfNGbq1/L/h6YQv0U8+XJ4R+B/3hRf58=; b=b9KvWHJryQHvFPg9e871YaYOGm mOHNYZR1oSDs4lZ0b6yeUJAn5qeh4RixIgKOSGIVwzGOcVc1XFqLywfdJ0+GBr7X0ivN+NNYeW+ql i9qYgXsyy2/b4QRf/c6W5Nw5VyoVqrntD0jLwB7lsm9CBQtazTshb9SwcE8cbeF4z11ieWi8aFxS4 EUyoaSTcBrlaNjeVYuio8vOURpSeH2X24hvzCkMRxSo3UEQOxc2UFkRnRiwvnAOxrRRw+4ACnByTj kmZ4/iyB90ugEP2lMVb3KHICvfHY4wTTiWulaL1VCGvSkb/kha9hSdF73dDRXoR7KfnWWlqFlzLcb 7PqLDyPQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qEf6l-004L0A-Tr; Thu, 29 Jun 2023 00:01:59 +0000 Date: Thu, 29 Jun 2023 01:01:59 +0100 From: Matthew Wilcox To: Dave Chinner Cc: Andrew Morton , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jan Kara , Christoph Hellwig Subject: Re: [PATCH] writeback: Account the number of pages written back Message-ID: References: <20230628185548.981888-1-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 0779C120024 X-Stat-Signature: x5o39nspgfrhh1c6heq1o1dxt5685jzb X-HE-Tag: 1687996923-191016 X-HE-Meta: U2FsdGVkX1+Pxnpdy1W6cyGgwxhn8A6heuyha9tSqC2fleTqVYYEgx2GMB7dlvVWpTNXfke8OJje08KU6FJvPjJKzr9KHRoBrDRyOaWH/KosfhS3jpd+E+sNujQ6H5n8hMov0RZiSZwALwveXVgY+jWyWfmshLmwq3cuERBY5fj15H7MpQ6Wv13Zp8ui40Ez0zbnC0E3n7sGcnzixT+J06yW8cQQpitFPRdn4bbqGJ9ifEZx1VIKPhHPk3Pa8OoXGT9l80COV6XivlT7Iyds0ulTN2Ih0PAc9/5jyH9OtB8SAGvOQ1nnUj/TsJxbJlAdU5je8shpaHu4n8I91luaDLhJWPuvTSu5ZMy8NAiVmJGTkgVJUjqFdFpdcNjLmcqBZS9GzJSSGugxF6ZQbAnee/RrTo7hAxK8dAhvFi6facKEoTH+epoFwgXaJYdYTPg9pYPSMtfvnFzyes/2ICLVh6o1FT/ST8RnvQnfiQROKvsdkWLjrf6ZNTPL7dQPrn++F87LjE+ViA6LJGevS2ppytuPvbeoTH3TRgmGcnuy10Bc3LvKe5qj/w7IXQbsqBie51ldlKTu2C/IZloJ98CoxCi9MTz/fCw0tm3pWnhttC0RS24KX7rIHx2qDaXweKqMEB+T+9DXUYPWoDN0FHhcov2vwaa4b9k+5pYHI02rYAq2MfrB+TJWH/pBvpGyDFEYszA4cwXp0a7ijxYnK7TLkJgRrvkszmEVapsm9j9m6E/MMewsRfqUHJgIzIZGwD2kec93dCXYT5QraDI5pHmf+xJXwFVw1T0kwBSFjUXSenqtL8zhD4X3ti9WyPlSOlR7wXAeEZG1MFi2u7+KdjJ74DH8N+z2w8MEXZv6POg5pYi9lAaQ5gaVoYDVXVQcmz2agT7dCxTm6oq79sfzjqbsM1Qhuc/rCn5/dHZiHh1SZ3dlutLTDNvYjNzJ+skLA5qtzcQ6P6xiphJYbKGT5VG ry5P8A13 OG69DbDqpm8YfC8igWPONWvMMRNgLn1FdbHGcDybyVmIcGPb2vLsUSwO5Li6nAxWbOFJGutG2Fhy3pnMxNH4Y4LQm/JoEJSGdSQZXCj1bYcGyEz8LuQfPD0jjHPL7aaPB9jT+BPO++U7rKtlL2b6MadhVcUEb6QcrkD91CzukQ9B6MPdPHRD9X5p5n6JOfIxMLe76 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, Jun 29, 2023 at 07:53:44AM +1000, Dave Chinner wrote: > On Wed, Jun 28, 2023 at 07:55:48PM +0100, Matthew Wilcox (Oracle) wrote: > > nr_to_write is a count of pages, so we need to decrease it by the number > > of pages in the folio we just wrote, not by 1. Most callers specify > > either LONG_MAX or 1, so are unaffected, but writeback_sb_inodes() > > might end up writing 512x as many pages as it asked for. > > > > Fixes: 793917d997df ("mm/readahead: Add large folio readahead") > > Signed-off-by: Matthew Wilcox (Oracle) > > --- > > mm/page-writeback.c | 8 +++++--- > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > > diff --git a/mm/page-writeback.c b/mm/page-writeback.c > > index 1d17fb1ec863..d3f42009bb70 100644 > > --- a/mm/page-writeback.c > > +++ b/mm/page-writeback.c > > @@ -2434,6 +2434,7 @@ int write_cache_pages(struct address_space *mapping, > > > > for (i = 0; i < nr_folios; i++) { > > struct folio *folio = fbatch.folios[i]; > > + unsigned long nr; > > > > done_index = folio->index; > > > > @@ -2471,6 +2472,7 @@ int write_cache_pages(struct address_space *mapping, > > > > trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); > > error = writepage(folio, wbc, data); > > + nr = folio_nr_pages(folio); > > This should really be done before writepage() is called, right? By > the time the writepage() returns, the folio can be unlocked, the > entire write completed and the folio partially invalidated which may > try to split the folio... > > Even if this can't happen (folio refcount is elevated, right?), it > makes much more sense to me to sample the size of the folio while it > is obviously locked and not going to change... It can't change because of the refcount we hold (that's put in the call to folio_batch_release()). I didn't want to call it before the call to writepage() because that makes the compiler stick it on the stack instead of a local variable. Also, when we transform this into an iterator (see patches posted yesterday), we'd have to stash it away in the iterator.