Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp429859rdb; Thu, 15 Feb 2024 04:51:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUVW3tiBIBl7mFiLUQdUf12NS32SyziEvsMv8VfM5pa1IqRKJdT+nmN7nEsgooiLklL2x1S6Mxw4jfx6bBu8JvAVeDLW/zHID/Rq0DXlQ== X-Google-Smtp-Source: AGHT+IFPL9wqLwhLlPIU57r1XhgEVl1td+8Hsk1pFg+h1zZFSwDsMq1jlYM37IkpcX3xEMwIiyHN X-Received: by 2002:a17:90b:1081:b0:299:1d1a:5b4d with SMTP id gj1-20020a17090b108100b002991d1a5b4dmr525435pjb.13.1708001508994; Thu, 15 Feb 2024 04:51:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708001508; cv=pass; d=google.com; s=arc-20160816; b=Tjo8Q1rMmki5JaZeH5nlFwu1SnsD4CZ/mbwWV58tMgLOkG7fkMfwfEeRlEMIfkJWWo 0aevxIEmfskWDSuX99zu2+LBbnf7hkpX1m49TL0FIZuhaAxRo0ibC5nypE11GoGg1GQN aZpPBK+tyIIG5qVH26zAQ7G3g4eCbMzUfOyJc6v66tHupxF6luocl+BrHXuikZMrRIE3 P6Ecvg7KNpD8I63Y3iU3gcFfwTxDmFVbRqddQlBvLRuzu31uATk8OxMrroWO95WVENtx vLXJks1P5uZRk2yMtrVHGQhEhK/jFWmGH1JI114ptXUvKZjxYNmz8xZq0SzEEldr5f58 I3XA== 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=j7oK7/19ACOHFK7IfrqUkUYg5wgn+UHWF7oPozt79Xs=; fh=fHt1epEEG4CBzP1AZFY/UQTnQHCnTLYuOY60rKPEgb0=; b=JWqm91q0UZA/Mz6VG52E4YlIpYby6GyhzonYnN2A5yuj+Rf46j1Gsj5CaVJ/RswOVf FsNCuAUQMoHnavJMuuxITzf5xvFDx7ztS9grLRx0Gqmb2giTtlgGEMYj4BqLYdy6rPPC GTOU2U2xj52e7hn7HgOiaViMWSGT7WGnEYjGwTHMCPYJrs8T9kV7f9FGae+gRH9G4yWr Qv7G3pI3Bmda+FLICs9fmoEzEOTIeCPjbK3mYLQZgxmciEHxAA37ztbMaqXa+BYlNfx2 Q9h5uAogWAXvK9u/CsFcEYZGQntiy41lHtHmc6qgDWjlTeTJfv3w9bcoLtCs5ufmnRIh 9GTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=Sq+z8AZs; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-66330-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66330-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z8-20020a17090a8b8800b0028e79d4c104si3005677pjn.131.2024.02.15.04.51.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 04:51:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66330-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=Sq+z8AZs; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-66330-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66330-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8901D291F7B for ; Thu, 15 Feb 2024 06:39:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51FB918038; Thu, 15 Feb 2024 06:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Sq+z8AZs" 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 1B5E9C15B; Thu, 15 Feb 2024 06:37:18 +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=1707979040; cv=none; b=ODzbZZuztTVaAx65LUv6Up5DiiMFtzwRIV8LO8B7Dd5/Avr3fIVxbAEmry0v/OP8EirBWmPobh5vo1q9iV9oOSP+KDolnlUhY6zxXg27sMs8mO6qMm06xVX0X9ELWyJY8hjJsMWmBTKAKx9HIx0m9LtsIz1NX/lEIFLRNmOFDQg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707979040; c=relaxed/simple; bh=Ov4CQxEf3ENyWeW/t0O/ov+Q1GH4rrRIa+NgOqzCg4o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tvnZ++JOMiUdPDvFWzIR4tz70SCE1nRTsgsQqBn3wTQEzwUSKxA2/Qpb37HGXGZwcspsdXT142Uyh9MkQkRInWMQzXz8oqdOW1m7/x9p3cTpI8/PRoMCwm6/wDifxnELDJNly7H+qX0uooreLpnvcx9ohTIJawd0z1mP/tTq7uM= 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=Sq+z8AZs; 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=j7oK7/19ACOHFK7IfrqUkUYg5wgn+UHWF7oPozt79Xs=; b=Sq+z8AZsN0OQbwPCVzc+xwQZGf fm7ViVlN00hHrVnU8bKUDWgWsINORFCOeB+0xJoU8o4n9XW0DUTNhYVyHCWo2D9EAbYlSs+mH2Zi3 cpFB3g/my0T6zfQauarrKIvaavz8csDa0WZzcqjrtb46C+vOL7IhnqPIra1qjqOttDVVXV53wU0kx dOUAlCiVv+TEA9PIDtoJZSnY8o+DS3Fln0eJY88JIE/JF/a8psprUrXFNayGPEzIQfuLeMwDKSV7y ukZ6Q+vsJSn6lKCKVRjJtjtBjaraFHqZiwoUa3zHZQcOnCDCId4RHZYS8dh0gHaO5Do9icAR8Jgfd DIfn1KdA==; 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 1raVMx-0000000F6uZ-36cp; Thu, 15 Feb 2024 06:37:16 +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 07/14] writeback: Factor folio_prepare_writeback() out of write_cache_pages() Date: Thu, 15 Feb 2024 07:36:42 +0100 Message-Id: <20240215063649.2164017-8-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)" 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: Brian Foster 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 3a1e23bed4052c..4bc55ce9597d13 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2360,6 +2360,38 @@ void tag_pages_for_writeback(struct address_space *mapping, } EXPORT_SYMBOL(tag_pages_for_writeback); +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; +} + /** * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. * @mapping: address space structure to write @@ -2430,38 +2462,13 @@ int write_cache_pages(struct address_space *mapping, for (i = 0; i < nr_folios; i++) { folio = fbatch.folios[i]; 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); wbc->nr_to_write -= folio_nr_pages(folio); -- 2.39.2