From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89567C48297 for ; Tue, 6 Feb 2024 14:52:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07BAE6B0078; Tue, 6 Feb 2024 09:52:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 02AE86B007B; Tue, 6 Feb 2024 09:52:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E36BC6B007D; Tue, 6 Feb 2024 09:52:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CF9636B0078 for ; Tue, 6 Feb 2024 09:52:55 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7CB01120C31 for ; Tue, 6 Feb 2024 14:52:55 +0000 (UTC) X-FDA: 81761671110.21.E61503D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 87F984001C for ; Tue, 6 Feb 2024 14:52:53 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NhBfo7sQ; spf=pass (imf07.hostedemail.com: domain of bfoster@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bfoster@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707231173; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ICNu3j0RxsXSNnJAkw6sqT5jyTGFKxvpyFp2l0saKd0=; b=kCyluz7QsymnKi7HzQX2nDEienW+zZUTxmNKZmcWxBYIUXSJ2vwC4P5XsEWIeZTiUDhXBB E+N9PLTSaXsmgvzmF7oMYlCdbzya5fWdP4GW9Nx14srA0X8GG6srLA6iWKtyt/fBC4MBbL Owut3fVFPiSOLUpNE1BaSAivtX8H1zY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707231173; a=rsa-sha256; cv=none; b=KPG0RxWoap6RdlYJIpO9PuoGmvo3Lw5aCAd8C4/24YLksEmci++ZwZbLYfNhjNRLAlDrxa PZEPzq1LRzlrDtrTM9HuzQPUIUmjDgEFicMFQX7iiKL/eEcD1tT41mj/Wo+zllq9Ee5wf+ aHll8ZY0zyA8HtA3/kCRiWWP/ZLqLlw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NhBfo7sQ; spf=pass (imf07.hostedemail.com: domain of bfoster@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bfoster@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707231172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ICNu3j0RxsXSNnJAkw6sqT5jyTGFKxvpyFp2l0saKd0=; b=NhBfo7sQuddndDNw9MOALgr2/hyZoQJlo+9J3aeZseVV/9MX3yvaP9TnCGLF+vMjtlIBy0 R0II9dC9rwVupZFnYaInAAbNnpvS1lOyolW6X9T39Zd4NucTLw2++o87bVgLEOw7tCTg0g wEWW2E+AiqPw5bWFqlp8U7tDj5LxQAk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-167-zB82_cyAMDOOlBX9rRInSA-1; Tue, 06 Feb 2024 09:52:44 -0500 X-MC-Unique: zB82_cyAMDOOlBX9rRInSA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D5715185A782; Tue, 6 Feb 2024 14:52:43 +0000 (UTC) Received: from bfoster (unknown [10.22.32.186]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A5E51C060B3; Tue, 6 Feb 2024 14:52:43 +0000 (UTC) Date: Tue, 6 Feb 2024 09:54:01 -0500 From: Brian Foster To: Christoph Hellwig Cc: linux-mm@kvack.org, Matthew Wilcox , Jan Kara , David Howells , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 12/13] writeback: add a writeback iterator Message-ID: References: <20240203071147.862076-1-hch@lst.de> <20240203071147.862076-13-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Rspamd-Queue-Id: 87F984001C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: mdqt4m4xhph9mfc7hjkpot4yot9fxcjp X-HE-Tag: 1707231173-825256 X-HE-Meta: U2FsdGVkX1/m8O6DSOvMdM7quXDowNjAQCaZAbmknIhgsI8uc6NzK+cN1LqS90bq/ibayKUi/gXRJKQ/GZEwBLH3573OAigCPGxVMIKajtzFt5wSggM5SVNcB9mrg3X5vZGsCAA299YVdKXlf2rSSGi7QqcvQTsfZGeq9JTPR1vovc/hh19EQ9GBcKKsPjvjXbuMQ7QipgpYMxD6VvXYbptYp1f7a1LFK9hD485bvLli0HTvjZV/bYX0OeZXPe26NN0M0Y3OHNorQVrqEiBMwn57BlPWeQ5+g61cE9nL6YIiFP+7oLHIoqcsLCvmD+G73rY8n+HxSmhwcPjMnIoh+dW0d7BkI/10lmrtfJnic8OPXxr3ohdfmBFa+sPvgHINVsKzq1QIA44IoofIQCUAXbVE0aMs+8aTXw1yHZoXRbVHL9CckQSBEQYwdQqDxWriC4HoQ6X8/8WBetlt25Kl0fUwFKQqksxTYTmfQT8CZU8UVdW+euGCSD90N4hF/uSDmPXeifmTKGwWb4z0lOy4l2xIy2T8MYcAJsowI6VuqLzVy6QUTuyNZEtycLwLEMO63vLkS9pXSm3uHFyPQm15zpeddBoizcP51Mpl2/Pws6RrIFsoBI2mj8s3TgBGTbhaSjycCxmsOfzgRjIG0ZB2NJO4hh9bGTif1jF7hnkNZdSD+Mlgy54/1hW3/v2SZ+S/JkAv+aukf2ycbqMj/6crRhc/PqTkVGSYKoklrUdNOb9fa6meakqPUaN0oW0ilXfSPPABBXUPBsyv1hILpbAoRGgEk3+nbOTP2vXXqRzyb6+82GOLmiVhzbVq1OVN6AuOL/REn6uqmL8/ABv8d/ajfhUkyXjyLDotQz5NOl0BCTos3eud0VWGuNNUQkRpAdyFbvEquBhUSFlwc3iF5I/CPxpDsbhdAfs0nK6VH5n97jESIcPOR0zvn5PET5ruh9zREJ2fvnIzn4nNujujrTd faA0XQGk SSX/veJlY7/tB4xRNgVW7YeeR3Y8BNPfCfZSA0Gtwmi2hKDoky1/mn4Aqc0aUKoj+vyRMWJjgpXO9wCkQKiq7T5GkfsEt3FP0mDv6vgTA5R8rElVd+oipRj/4e3c55Lz9WfSDruRdMGhiUwZEd72FQVjMRNoZJ4KJRcgTPzrcB6l1P034FczI1DAj5A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Feb 05, 2024 at 10:33:52AM -0500, Brian Foster wrote: > On Sat, Feb 03, 2024 at 08:11:46AM +0100, Christoph Hellwig wrote: > > Refactor the code left in write_cache_pages into an iterator that the > > file system can call to get the next folio for a writeback operation: > > > > struct folio *folio = NULL; > > > > while ((folio = writeback_iter(mapping, wbc, folio, &error))) { > > error = ; > > } > > > > The twist here is that the error value is passed by reference, so that > > the iterator can restore it when breaking out of the loop. > > > > Handling of the magic AOP_WRITEPAGE_ACTIVATE value stays outside the > > iterator and needs is just kept in the write_cache_pages legacy wrapper. > > in preparation for eventually killing it off. > > > > Heavily based on a for_each* based iterator from Matthew Wilcox. > > > > Signed-off-by: Christoph Hellwig > > --- > > include/linux/writeback.h | 4 + > > mm/page-writeback.c | 192 ++++++++++++++++++++++---------------- > > 2 files changed, 118 insertions(+), 78 deletions(-) > > > ... > > diff --git a/mm/page-writeback.c b/mm/page-writeback.c > > index 3abb053e70580e..5fe4cdb7dbd61a 100644 > > --- a/mm/page-writeback.c > > +++ b/mm/page-writeback.c > ... > > @@ -2434,69 +2434,68 @@ static struct folio *writeback_get_folio(struct address_space *mapping, > > } > > > > /** > ... > > */ > > -int write_cache_pages(struct address_space *mapping, > > - struct writeback_control *wbc, writepage_t writepage, > > - void *data) > > +struct folio *writeback_iter(struct address_space *mapping, > > + struct writeback_control *wbc, struct folio *folio, int *error) > > { > ... > > + } else { > > wbc->nr_to_write -= folio_nr_pages(folio); > > > > - if (error == AOP_WRITEPAGE_ACTIVATE) { > > - folio_unlock(folio); > > - error = 0; > > - } > > + WARN_ON_ONCE(*error > 0); > > Why the warning on writeback error here? It looks like new behavior, but > maybe I missed something. Otherwise the factoring LGTM. Err, sorry.. I glossed over the > 0 check and read it as < 0. Disregard, this seems reasonable to me as long as we no longer expect those AOP returns (which I'm not really clear on either, but anyways..): Reviewed-by: Brian Foster > > Brian > > > > > /* > > * For integrity writeback we have to keep going until we have > > @@ -2510,33 +2509,70 @@ int write_cache_pages(struct address_space *mapping, > > * wbc->nr_to_write or encounter the first error. > > */ > > if (wbc->sync_mode == WB_SYNC_ALL) { > > - if (error && !ret) > > - ret = error; > > + if (*error && !wbc->saved_err) > > + wbc->saved_err = *error; > > } else { > > - if (error || wbc->nr_to_write <= 0) > > + if (*error || wbc->nr_to_write <= 0) > > goto done; > > } > > } > > > > - /* > > - * For range cyclic writeback we need to remember where we stopped so > > - * that we can continue there next time we are called. If we hit the > > - * last page and there is more work to be done, wrap back to the start > > - * of the file. > > - * > > - * For non-cyclic writeback we always start looking up at the beginning > > - * of the file if we are called again, which can only happen due to > > - * -ENOMEM from the file system. > > - */ > > - folio_batch_release(&wbc->fbatch); > > - if (wbc->range_cyclic) > > - mapping->writeback_index = 0; > > - return ret; > > + folio = writeback_get_folio(mapping, wbc); > > + if (!folio) { > > + /* > > + * To avoid deadlocks between range_cyclic writeback and callers > > + * that hold pages in PageWriteback to aggregate I/O until > > + * the writeback iteration finishes, we do not loop back to the > > + * start of the file. Doing so causes a page lock/page > > + * writeback access order inversion - we should only ever lock > > + * multiple pages in ascending page->index order, and looping > > + * back to the start of the file violates that rule and causes > > + * deadlocks. > > + */ > > + if (wbc->range_cyclic) > > + mapping->writeback_index = 0; > > + > > + /* > > + * Return the first error we encountered (if there was any) to > > + * the caller. > > + */ > > + *error = wbc->saved_err; > > + } > > + return folio; > > > > done: > > folio_batch_release(&wbc->fbatch); > > if (wbc->range_cyclic) > > mapping->writeback_index = folio->index + folio_nr_pages(folio); > > + return NULL; > > +} > > + > > +/** > > + * 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 > > + * @wbc: subtract the number of written pages from *@wbc->nr_to_write > > + * @writepage: function called for each page > > + * @data: data passed to writepage function > > + * > > + * Return: %0 on success, negative error code otherwise > > + * > > + * Note: please use writeback_iter() instead. > > + */ > > +int write_cache_pages(struct address_space *mapping, > > + struct writeback_control *wbc, writepage_t writepage, > > + void *data) > > +{ > > + struct folio *folio = NULL; > > + int error; > > + > > + while ((folio = writeback_iter(mapping, wbc, folio, &error))) { > > + error = writepage(folio, wbc, data); > > + if (error == AOP_WRITEPAGE_ACTIVATE) { > > + folio_unlock(folio); > > + error = 0; > > + } > > + } > > + > > return error; > > } > > EXPORT_SYMBOL(write_cache_pages); > > -- > > 2.39.2 > > > > > >