Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp860619rdb; Fri, 22 Dec 2023 07:12:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqJIpu8JIDHoKD7GpY1VwoQlhHu/1dIxv9QgfMt8kV379hgixRS7x5AIlfmQRjI0CJ4ZR6 X-Received: by 2002:a2e:8445:0:b0:2cc:6f7f:6ba4 with SMTP id u5-20020a2e8445000000b002cc6f7f6ba4mr398581ljh.199.1703257967854; Fri, 22 Dec 2023 07:12:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703257967; cv=none; d=google.com; s=arc-20160816; b=OjuAGLhCbhaoekA6Qh+mDKYnOsUN+hmaXjx8tSJQffbJ5YY+1+c5b3Yv9RfK91DjLT +Xpfi9+FrgVoP/kmwntECy9laJuCrO4uJEKKzJ8HMbMvhakD6zMvkgKX0lBhVKAm0dgu hdcV8V9TJ93icJp4aJPQNCG/WBKZEW+e/N6jLDCepz9yvdTPRp3Zu3u5u/9MgvStZLk4 DtwF5zq7odVQMnDO5JHVeSa0EFT+6OK0mBoAG5iXaiOnXLqPcGPvNOfVlrgYzFeE/yDH E0ec3zA2Yzt0gLeY9FmFU/QhylNlyPE3GOLmBBF/wGei7s9G4NScmTCVdn5pqc3gG1BG Kjyw== ARC-Message-Signature: i=1; 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=BwSwsSrvBcosA4alobfWiefPc9fIbR5mK3Ls0770Y3s=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=bvMTHz1s9sU/0rZSHQOT8c5IbsgN7nlhaSvVeSQkzFFKailoU64nb7/Ics2thLNGp8 Rl46HxiUHO3qTkAkbJ/LV2vAJ5WaSCSbgSVujB+1+x2KC/3p2vya9z4ybMFVpKKfXYwN pw7tAHvY3esIVp0b7/zfAdkymAM1+rDF3IRPmPTbAkTSHCBkRMZB5jk8XXNMdNO7W5ZH sWFheST5jkJqVQI2Zt/H1tP3471XhdS54pUmcAl7lXUkhoAncrgjupROEOc503/jSae0 tet4bu7P6tl3Dm4k1b8FjMgTQNJaLVEIsqT5+2ugHMa9lKD858Hzp5KuPsgrYdbU43Dt oItA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=wfmB6gnW; spf=pass (google.com: domain of linux-kernel+bounces-9819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9819-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l2-20020a50d6c2000000b0055293673a8asi1897409edj.360.2023.12.22.07.12.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:12:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9819-linux.lists.archive=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=wfmB6gnW; spf=pass (google.com: domain of linux-kernel+bounces-9819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9819-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 240C31F22665 for ; Fri, 22 Dec 2023 15:11:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 043C92C1BB; Fri, 22 Dec 2023 15:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="wfmB6gnW" X-Original-To: linux-kernel@vger.kernel.org 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 0F69B2C19F; Fri, 22 Dec 2023 15:08:50 +0000 (UTC) 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=BwSwsSrvBcosA4alobfWiefPc9fIbR5mK3Ls0770Y3s=; b=wfmB6gnWpnCr0AsGy1pjmk2FRv 9RZSI3vxFS6RBs4R1tZQlsDjGMbS5AgfaIQyY8ZfRUa4Z0Obe+NYQYoO8e7R/4Gt2MiyF4eHZhRpa 04GcAhvmm7iS/h1QLGYOxhyxxFto7ZTNAYSq8hoonSrTIW3QjmzBVy9hvaw9kQzam+c+YWh/OsC7/ vN8H5b3iW7d1DEOYaDwwWMp75w/Qoi7X7UiegVtM3tVbW7TPNFsyHfpA2nIdBmnDd7s88Npe2D92p 0alD3lK0uoAVqQynOao5x+eGhNarLIbFcKcxno0TpTXOOEO9PCYfs8kBEYY8lzUkrY//dXLo6d4qB F8spWMTw==; 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.96 #2 (Red Hat Linux)) id 1rGh8p-006BRN-0o; Fri, 22 Dec 2023 15:08:47 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 08/17] writeback: Factor folio_prepare_writeback() out of write_cache_pages() Date: Fri, 22 Dec 2023 16:08:18 +0100 Message-Id: <20231222150827.1329938-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-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)" Reduce write_cache_pages() by about 30 lines; much of it is commentary, but it all bundles nicely into an obvious function. Signed-off-by: Matthew Wilcox (Oracle) [hch: rename should_writeback_folio to folio_prepare_writeback based on a comment from Jan Kara] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 61 +++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 798e5264dc0353..fe508548482217 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2397,6 +2397,38 @@ static pgoff_t wbc_end(struct writeback_control *wbc) return wbc->range_end >> PAGE_SHIFT; } +static bool folio_prepare_writeback(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio) +{ + /* + * Folio truncated or invalidated. We can freely skip it then, + * even for data integrity operations: the folio has disappeared + * concurrently, so there could be no real expectation of this + * data integrity operation even if there is now a new, dirty + * folio at the same pagecache index. + */ + if (unlikely(folio->mapping != mapping)) + return false; + + /* + * Did somebody else write it for us? + */ + if (!folio_test_dirty(folio)) + return false; + + if (folio_test_writeback(folio)) { + if (wbc->sync_mode == WB_SYNC_NONE) + return false; + folio_wait_writeback(folio); + } + BUG_ON(folio_test_writeback(folio)); + + if (!folio_clear_dirty_for_io(folio)) + return false; + + return true; +} + static void writeback_get_batch(struct address_space *mapping, struct writeback_control *wbc) { @@ -2470,38 +2502,13 @@ int write_cache_pages(struct address_space *mapping, unsigned long nr; folio_lock(folio); - - /* - * Page truncated or invalidated. We can freely skip it - * then, even for data integrity operations: the page - * has disappeared concurrently, so there could be no - * real expectation of this data integrity operation - * even if there is now a new, dirty page at the same - * pagecache address. - */ - if (unlikely(folio->mapping != mapping)) { -continue_unlock: + if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio); continue; } - if (!folio_test_dirty(folio)) { - /* someone wrote it for us */ - goto continue_unlock; - } - - if (folio_test_writeback(folio)) { - if (wbc->sync_mode != WB_SYNC_NONE) - folio_wait_writeback(folio); - else - goto continue_unlock; - } - - BUG_ON(folio_test_writeback(folio)); - if (!folio_clear_dirty_for_io(folio)) - goto continue_unlock; - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + error = writepage(folio, wbc, data); nr = folio_nr_pages(folio); wbc->nr_to_write -= nr; -- 2.39.2