From patchwork Sat Feb 3 07:11:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 196250 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp979597dyc; Sat, 3 Feb 2024 04:01:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFs3MXkI7gethONExdSHzdmy694eRi2jB4MpYUCGOW9RLj+aFnOfYzdkLP0c94pSNWUtBQX X-Received: by 2002:a17:906:31c3:b0:a36:f480:40e5 with SMTP id f3-20020a17090631c300b00a36f48040e5mr3333227ejf.46.1706961706403; Sat, 03 Feb 2024 04:01:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706961706; cv=pass; d=google.com; s=arc-20160816; b=fe6N7HaaAf/LxXPYeZFYzUkA/nuCxRD7Ip2d3efqrluLKNH7woRysUWcY/Wxb5TqJj 9ZBonBg9hPXCe0dPrc4os+ip+RWasL+jfbP5zZvOnEW2Epma5HQzC5FJvSiodBOHkYUZ Is7N/SYqem62dDfOzfjHJgIrHFLI0Dq3YNfFxiLBqhV6/jiI536W5S8CI3q8uzdCmypH jDp6bfv9S/X7cr0q71J6GbNBDa3y5fLRpbt8KMAVDCCrfRtmZvz8FzP9pjhM4pAmdSjb wUfDMZ9VFhw0W1wvYOM208n71/E08kv+O3HhOiFBBQV2uBsj/Wu3B2jBxX4yW74zSXqC VSEw== 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=AnG5GvoJfhWPvqWiitfZqai2sD2FuEVxQzhAIrm6KaA=; fh=ngOuRDn+1bPTAtNgsxtv1r0sRWlRTsxkU/k4q+ARRKo=; b=IWz4DXYk6FpILb9VVl1j8cePXGGOsRiy6vVkOYeoaW3nlM1tGluB7lqyd5q17HMIVY QiMZmtkUS96LiqUhq0dJJAVDUbyDfk2v1TXLr//xDPIeAKnAc4vOSdFYBLdZ2PY7HT7Y +PGYk8Mv9MEZ3T73eEDQHgEQwToT41UAXguyfUYDUyFXbU7LHn8ifVTUxx6spVLR73pT oBgdW20D3r3JBCDTh1sK+exrfxxnoeuWPLz2JI4xqaiuFNtgvvVAoiSL4GtuUFAzj+mD z/xJMm+8eWjxqay6Wc0lnCLvsZlafv92jEUYN6F81DaJk6uaRA2mkbFC6AIgtI/yzN3d 6VCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=vH0hdIAp; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50960-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50960-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCW1IdFJGfArFNdYP1k0S6wNl+hVYZUeCFSEToi4iG64+xtlxVhbTyTf1p4Eo7L8oDqEXSuWr3+9SI2A1dLolTELI0vXJA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v13-20020a170906564d00b00a372ac5cee5si1112160ejr.850.2024.02.03.04.01.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 04:01:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50960-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=vH0hdIAp; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50960-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50960-ouuuleilei=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 633CD1F2B580 for ; Sat, 3 Feb 2024 07:15:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF36856B6B; Sat, 3 Feb 2024 07:12:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="vH0hdIAp" 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 41C345674D; Sat, 3 Feb 2024 07:12:53 +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=1706944375; cv=none; b=WgDO1cNXuU0mWvLO2zjZ7Y2Nc2abdsCUgXs61hCE0AQBcbSxaSMXOyUnt1G8asDqpSSiZDfJCOLkL6z+ZvXSokbvFc4hJ3EynG1PCiWST9hQnkT3cgkzbPb9rSUzYyCRIe0OwolJy0MXqdlphyRc1EzuC6phxnUXpdoM9FvzacA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706944375; c=relaxed/simple; bh=BEzYiGhNCPidNvLvQLhLK2U2cZcI03nhea82PoTH56s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qwTrdoNCgKMGcfy+qax7TpF0QaTvX8IW9Mm+MuGyEd1oNJAhUJwzyi6UaDOwiMqRYBjr0JZoNBe9QougMhh4v7NJSTGNoW8uLRh0CYDXN5HwOSG3OBzJsERNAJzMsbihP4/oaaVPsZVxZWyBDY4RlSU74ioZzQxFIkaoo0VGTUk= 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=vH0hdIAp; 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=AnG5GvoJfhWPvqWiitfZqai2sD2FuEVxQzhAIrm6KaA=; b=vH0hdIAp6gB22asQhHw8fV4fL7 t7SMPnQ6UOZ06eB6iUc6QRiRN2CHY9Hoa3/Qt6lKZZW+1cVc05CzNKKIfNtKfWXE9n/0DIqp9pM41 tUdkoZyp1A/VSO+XZuNI8/iD1snj2iILh49fiFClyMMSrDYvZwMScjIzwLgLCAtb95yYimLLC6kZs 3uYxfZ9w1waMc6giSV8N33kIOCeAyPZBqp55YBUwZiocSMqmbEkiaPrGEeU7UtVNwsyGwiGTQe5eA t3RXkIGbnjSxOrBklgbZ7FsjwDnYiDV06ODpVc/+M3iEChRzlwXXkIMS44L9k65uCSyfj+bQtgnTP OJ4GTRbA==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACn-0000000FkIF-1VWY; Sat, 03 Feb 2024 07:12:50 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 11/13] writeback: Move the folio_prepare_writeback loop out of write_cache_pages() Date: Sat, 3 Feb 2024 08:11:45 +0100 Message-Id: <20240203071147.862076-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789879078205631833 X-GMAIL-MSGID: 1789879078205631833 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 095ba4db9dcc17..3abb053e70580e 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);