Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp277064rdb; Wed, 14 Feb 2024 22:40:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXSeIjjAK6314vGMkBM1yr1WwOBWd8Wuy7WfaxPDFp7yDw5iYGBtSLlabb43225nH8RStIG/29M3dO2Du/NgNCk7W1gmmiUxFFkMBWaBQ== X-Google-Smtp-Source: AGHT+IEjTDAEdQh8SCfpQSItha4Pu6buN+rzzjoKGtAZIZ0qpbWWdV1P/8RaaE+1zdRtqoa2BHpC X-Received: by 2002:a05:6512:1024:b0:511:87b7:6d88 with SMTP id r4-20020a056512102400b0051187b76d88mr671531lfr.32.1707979224743; Wed, 14 Feb 2024 22:40:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707979224; cv=pass; d=google.com; s=arc-20160816; b=PhiZp1ob4ytk5F5PmttV9cbrAYqQSMg79QZ+IZv3tpB+yqCWD9VpWvjY0AE/qMdabs 9Av5PLavMyO3/qDwkDF0gQjp+MRLFSskU4C40iuRsz8tjDtR3kimUGDliZhCL6Ig0Yx+ 8CBadn9m05gvs7y0oLJP0XSLNHNhZJUg2OtDmdUo9lmSRrNekMUMnACEa51jxwIMVue4 y7i+HKS3EHCY4U7sSky9OMO1fIVDlaHqDY4uuhuyYerG1jyl6i/cSnDlgbK02J0ctpuU x46DgO6jIpbuFtqNOE26RdwrOo7DvPlQhX4a8X1zrsmE7FJ8XlVX6ssGSeTBdJ2Q+rS6 TPcg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dpEY7SmyA34rLmNMjZVpGv1HVhFTICw5Hhe2kQSv81M=; fh=fHt1epEEG4CBzP1AZFY/UQTnQHCnTLYuOY60rKPEgb0=; b=yJFlkH441Tf9TFLexB5luOUnXCRLZV72qgiNbldtv/2WzW5HIKkYMWW7o3GQPJ7seS zrqsM5523XtldLmxAFG0PjkHYrGlc6QCfJ/o/gBlQ76hLCuzq3liIZFBJBbVzrIvkd/A gDpt7fhC/rfmC9sfIMRFjDAa6YVyrWvfUyMyk9nO8l1qf8Fab3FfTOPznq8USuo9eVls 0y0PT6IA0m9i09qTUsX+IXUjB84Pzjq7XSfDU+kmpu+X++bJhFEsvj4jhRODpYKKH+Md sOhvq1cy9jT/+K5Bxvlf6qYljmTktUeL0kJWzMvOh5+tbcCpeTCEHY/dA75dvIhZrMHL TWqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=IE6GYCQF; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-66335-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66335-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h7-20020aa7c607000000b00561282f16a3si354937edq.244.2024.02.14.22.40.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 22:40:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66335-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=IE6GYCQF; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-66335-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66335-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4DEDD1F2D6AA for ; Thu, 15 Feb 2024 06:40:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D9BBE1BDF8; Thu, 15 Feb 2024 06:37:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="IE6GYCQF" Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0454D53F; Thu, 15 Feb 2024 06:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707979051; cv=none; b=jHz1wNxUbuG+u1zEueyUmabqvYAsdzdWqtmLT2qd3zLKHBDLufxy+Ra9QpB1MjEZVH5L+3SwDs7n4vWPJrtQlxvdYJ5WhejKrb3qwhupr3fwR1SXODXIOWpx9vzBamhVq8otQ+CXyhUH/8XF5HDHgL/uy2VDF82slv+v2afTPig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707979051; c=relaxed/simple; bh=dgRYHU8iCb2WQ2DB6EoGsmva8mLKYz2OoB6UGRBNFgo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EftaCzEQjeIIxXoyJCYCTlXo8N17OVyP7wF/zW7FJ7BuarpfDW4vWV/J/o7NpcYyuRlqPczEveigrzbAUUtAup4j5gTWrnHowP9JOUKt55+vXzuDwQvLkcxLcBiIMoL7yN5MJnC1noSlZHCzegDJTCJYjVgC5E/i755x7dWOrTw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=IE6GYCQF; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=dpEY7SmyA34rLmNMjZVpGv1HVhFTICw5Hhe2kQSv81M=; b=IE6GYCQF3eV3lxuP59icZOXmbS +ZieiZz134xt6WwJJzwEPn739abiFT+QYhRmHkAw32tujHIHQHYaTqWK18UROqd9WFjuRrPe7e2tx gpFYSFBSmWjzvOzbpp4+OvsrWEKz3fKWswV/Zrm4Asux3Z2NCPWYpQ7gOdOlLV0EHf56ssi9QFmsK q7iPT2U8FwRCMtBDr7GcdQx219YFW7DS0GggsGgV2i/XgHXQnLt55fDdUF0bbhStSOweF6LucJ4bh eNFNVP2TLPuzZqh7+r2s7SHtmBzkiSMfVkTncMGSxRQLPZJFmcRiKLXjcQQLItfXLoMJfU/8tkReR qNWH7rHA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1raVN9-0000000F71D-1Lq2; Thu, 15 Feb 2024 06:37:27 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 12/14] writeback: Move the folio_prepare_writeback loop out of write_cache_pages() Date: Thu, 15 Feb 2024 07:36:47 +0100 Message-Id: <20240215063649.2164017-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html From: "Matthew Wilcox (Oracle)" Move the loop for should-we-write-this-folio to writeback_get_folio. Signed-off-by: Matthew Wilcox (Oracle) [hch: folded the loop into the existing helper instead of a separate one as suggested by Jan Kara] Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 3cbe4a7daa357c..fc421402f81881 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2411,6 +2411,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, { struct folio *folio; +retry: folio = folio_batch_next(&wbc->fbatch); if (!folio) { folio_batch_release(&wbc->fbatch); @@ -2418,8 +2419,17 @@ static struct folio *writeback_get_folio(struct address_space *mapping, filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), wbc_to_tag(wbc), &wbc->fbatch); folio = folio_batch_next(&wbc->fbatch); + if (!folio) + return NULL; + } + + folio_lock(folio); + if (unlikely(!folio_prepare_writeback(mapping, wbc, folio))) { + folio_unlock(folio); + goto retry; } + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); return folio; } @@ -2480,14 +2490,6 @@ int write_cache_pages(struct address_space *mapping, if (!folio) break; - folio_lock(folio); - if (!folio_prepare_writeback(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } - - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - error = writepage(folio, wbc, data); wbc->nr_to_write -= folio_nr_pages(folio); -- 2.39.2