From patchwork Mon Jun 26 17:35:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113082 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7665600vqr; Mon, 26 Jun 2023 11:12:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6uFJXqY+3Q6e2WSn4S0KmDeyrz27l621wFKGhfmTbKXCQhl4JbnVCN/ug2NduMVTsCVYbJ X-Received: by 2002:a05:6a00:2d04:b0:672:264c:e8cf with SMTP id fa4-20020a056a002d0400b00672264ce8cfmr5203855pfb.7.1687803132261; Mon, 26 Jun 2023 11:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687803132; cv=none; d=google.com; s=arc-20160816; b=NGGpzuAn4LHw1/M6kTaqhRFDZEk1juSzz9VZAKM8nZyLl2ipCT3P2uQrLIAUWewFyy lG5ogxNOcKnG6N6xtdnsKCpcR3/WV7FWP/QfjG87H79XRuaDMfrWZoy9PeyFtohGOBoN CnamBw19OvMo3aXrDn8zN4msvZ8jbjyicilHmNifFmjO1ooMTf+WDwTDJTcUKmmwBJT3 nxEXrScPa2P21YuSBp0EVCkXu5Lj+Eu4sgDAhgkaQgDLASMA6twTrmSUxayaoDalvGBK Gjx1AgyqNlaWwIxQQQvPpT171ip/7mQB9wQhbcoPumsH/TwwApEmECnL3QkKZ07w1aWW dtwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Rl4mK631QVfMYqrn657sw5cU2nYiKao9j/G8hhMJYQc=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=sKvg7Om6/RTagsJq1QES1i9EnhljfZYRc815wpvnfxO6LZQPqV+rC9qhoWakqgXqmQ i0Qsa+RPTaPRIts5TLOSXjFVzBGQeEYErfa/7KOxQXSiEHZRgDfAJgTuaRg8E58eBGRV MN1ABnlj5XKWr89/TJUax0VX7QekKL1ihsDPMdODc3QMnChuxzDfJPQUNsBq5wQ+U28U +9oPAY5CIQioghTzgpOBJcfPkWEAFLDhgECB/ihJUfTzbrxCa4JnntZ42qfUGcGnBJrZ Eogww1nzjj6ORZMZDxKjO/K8ENo4cyjaLWFdcB+yBfyc9n3GX2P9I612BJr8JPQvVvs4 rxow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=nbsu3asm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cp27-20020a056a00349b00b00675807330bfsi3003999pfb.194.2023.06.26.11.11.58; Mon, 26 Jun 2023 11:12:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=nbsu3asm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230087AbjFZRiD (ORCPT + 99 others); Mon, 26 Jun 2023 13:38:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbjFZRhD (ORCPT ); Mon, 26 Jun 2023 13:37:03 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 757FB19A4; Mon, 26 Jun 2023 10:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=Rl4mK631QVfMYqrn657sw5cU2nYiKao9j/G8hhMJYQc=; b=nbsu3asmGLUEUJkp+PGufwS657 4CnYI/PCw6l8Xww27U0CYRwuyhdw3qbIis63qGdeGzCtVLsJOFwYt3NxR09Tdc5xZeJfOY8HBxSpD ML123J3s2go0dLVKtO7JpczdsBdChbc2qdUxfvc7R/nlZz9ke8A7G0kVR8Pe3BeM8cYwULIOBI4va QsVz+e8awbc3irLZPqIwC6yclmfeLbv2Eyi3WV9YAYsgEKeC1gNGPKT8+flhqRnRCmJZMdmeKgqPH POUXY9Q1cVqApg0noTgC9DVH6ZMLKwAsYN6jYt4BOAsygoP/Us8PMzM8KNlDC/dCF+nMklunLylR/ u0gT4KlA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vVB-PR; Mon, 26 Jun 2023 17:35:23 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 07/12] writeback: Factor writeback_iter_init() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:16 +0100 Message-Id: <20230626173521.459345-8-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230626173521.459345-1-willy@infradead.org> References: <20230626173521.459345-1-willy@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769789857195471785?= X-GMAIL-MSGID: =?utf-8?q?1769789857195471785?= Make it return the first folio in the batch so that we can use it in a typical for() pattern. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 48 ++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index f782b48c5b0c..18f332611a52 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2430,6 +2430,28 @@ static bool should_writeback_folio(struct address_space *mapping, return true; } +static struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc) +{ + if (wbc->range_cyclic) { + wbc->index = mapping->writeback_index; /* prev offset */ + wbc->end = -1; + } else { + wbc->index = wbc->range_start >> PAGE_SHIFT; + wbc->end = wbc->range_end >> PAGE_SHIFT; + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) + wbc->range_whole = 1; + } + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc->end); + + wbc->done_index = wbc->index; + folio_batch_init(&wbc->fbatch); + wbc->err = 0; + + return writeback_get_next(mapping, wbc); +} + /** * 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 @@ -2465,30 +2487,12 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { + struct folio *folio; int error; - if (wbc->range_cyclic) { - wbc->index = mapping->writeback_index; /* prev offset */ - wbc->end = -1; - } else { - wbc->index = wbc->range_start >> PAGE_SHIFT; - wbc->end = wbc->range_end >> PAGE_SHIFT; - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) - wbc->range_whole = 1; - } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, wbc->end); - - wbc->done_index = wbc->index; - folio_batch_init(&wbc->fbatch); - wbc->err = 0; - - for (;;) { - struct folio *folio = writeback_get_next(mapping, wbc); - - if (!folio) - break; - + for (folio = writeback_iter_init(mapping, wbc); + folio; + folio = writeback_get_next(mapping, wbc)) { wbc->done_index = folio->index; folio_lock(folio);