From patchwork Thu Mar 2 23:32:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 63665 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp128944wrd; Thu, 2 Mar 2023 15:50:44 -0800 (PST) X-Google-Smtp-Source: AK7set+K3rY2hIZjVHvr7cRRiWmYUYUogKGWj4C0skBAc8R1H2w379GgvwtGyee+PL8QTo1Vyosq X-Received: by 2002:a05:6a20:3c94:b0:cb:692e:63d3 with SMTP id b20-20020a056a203c9400b000cb692e63d3mr248597pzj.38.1677801044476; Thu, 02 Mar 2023 15:50:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677801044; cv=none; d=google.com; s=arc-20160816; b=OUREHTjTWSezP/s3zZmDSpCAVcN0PqlOG0VWTsPgd4vK6P+YVuhb3bzX7LNKNFIyJ8 4SzTD6I3k6R2DjXrGf1Og3+Sp+7MCjTf7P1kXetY08yIXMpuqtTu3Kvo0PQm1NEkJL1A krFs2grfc7MXWWEGXSNWPnpHXKbSBmlrCTQVMJZwCq700biR59IEEsLH+n62952vz0Fd anofMv55bcbH4DH9idLZ5rfaj98Xiv1gi71lh91tyYB+3NZ/2IA1wHsEZVHaNAoF5m9X CXMa8pIf2BfNuQ88oXH3vLQEWm3cHeyAcqTC3euRMaIRN6E89rHfm00mRi4myE5jG6rg Jj+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-transfer-encoding :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization:dkim-signature; bh=5AKnwm11CuV/ZxP8F1kL9kNO/YucYb6B9hOTf3x61Ss=; b=majV2lpulTYX2BQoYKggQKfXG5XfEHEnTphsF1UeQE6h188zt5OGLkZiaJjOYH2d3b iPFFF7v1fLttlwxFCrvv4FcdJFOexe3DTWDk9TbZtZhDnvPNQLmejbDi3sicAyHYFIGX hZZUk3HkeevUEniRAuhHYZSN26ONjJ3VezuQsqDjAWp2hHnY/s03kYuXbCAHzISjtnLu 6wxRRRFa8QlBnLwOblSXtC/DYR4ych9PjcnChlzL9p/pxkYTsinv++JMmPpxOCgOwp9J BddfKW8QKAqwCdH6oonwZt8oE5jI2zgjngf6QDaztZfJeoj+V1+/rk9d4UB98BQ/JHnD hBGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WKPWDaQX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y5-20020a63e245000000b00502d65e848asi592848pgj.466.2023.03.02.15.50.31; Thu, 02 Mar 2023 15:50:44 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=WKPWDaQX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229787AbjCBXdy (ORCPT + 99 others); Thu, 2 Mar 2023 18:33:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjCBXdt (ORCPT ); Thu, 2 Mar 2023 18:33:49 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F200AEF8B for ; Thu, 2 Mar 2023 15:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677799985; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5AKnwm11CuV/ZxP8F1kL9kNO/YucYb6B9hOTf3x61Ss=; b=WKPWDaQXJaje6ej1B8yf3GCv00uC4P0zeAaiXFbMsqoveOrsDVDZ+hRCqg7g/rQxIjgx0F pv+3XdChG4zNiRgHhDGjYH3gY7/0XBN7TjQyFkjtH3UoDhDoLCDH1bb2oIgUmvx5W62/GG vNnJ5knREnzBc4lc0ZH1vWQWpAYGbFs= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-50-E7TjwiinNbuZZv7n31dibw-1; Thu, 02 Mar 2023 18:32:59 -0500 X-MC-Unique: E7TjwiinNbuZZv7n31dibw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E640380450A; Thu, 2 Mar 2023 23:32:58 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6C12492C3E; Thu, 2 Mar 2023 23:32:56 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <521914.1677799750@warthog.procyon.org.uk> References: <521914.1677799750@warthog.procyon.org.uk> <521671.1677799421@warthog.procyon.org.uk> <20230302231638.521280-1-dhowells@redhat.com> To: Linus Torvalds , Steve French Cc: dhowells@redhat.com, Vishal Moola , Shyam Prasad N , Rohith Surabattula , Tom Talpey , Stefan Metzmacher , Paulo Alcantara , Jeff Layton , Matthew Wilcox , Marc Dionne , linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Test patch to make afs use its own version of write_cache_pages() MIME-Version: 1.0 Content-ID: <522121.1677799976.1@warthog.procyon.org.uk> Date: Thu, 02 Mar 2023 23:32:56 +0000 Message-ID: <522122.1677799976@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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?1759301907535361043?= X-GMAIL-MSGID: =?utf-8?q?1759301907535361043?= David Howells wrote: > AFS firstly. ... > > Base + Page-dirty-region tracking removed + Own write_cache_pages() > WRITE: bw=302MiB/s (316MB/s), 75.1MiB/s-76.1MiB/s (78.7MB/s-79.8MB/s) > WRITE: bw=302MiB/s (316MB/s), 74.5MiB/s-76.1MiB/s (78.1MB/s-79.8MB/s) > WRITE: bw=301MiB/s (316MB/s), 75.2MiB/s-75.5MiB/s (78.9MB/s-79.1MB/s) This goes on top of "Test patch to remove per-page dirty region tracking from afs" and "Test patch to make afs use write_cache_pages()" David --- write.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 138 insertions(+), 3 deletions(-) diff --git a/fs/afs/write.c b/fs/afs/write.c index 86b6e7cbe17c..d66c05acda8c 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -463,9 +463,9 @@ static int afs_writepages_submit(struct address_space *mapping, * Add a page to the set and flush when large enough. */ static int afs_writepages_add_folio(struct folio *folio, - struct writeback_control *wbc, void *data) + struct writeback_control *wbc, + struct afs_writepages_context *ctx) { - struct afs_writepages_context *ctx = data; struct afs_vnode *vnode = AFS_FS_I(folio->mapping->host); int ret; @@ -499,6 +499,141 @@ static int afs_writepages_add_folio(struct folio *folio, } return 0; } +static int afs_write_cache_pages(struct address_space *mapping, + struct writeback_control *wbc, + struct afs_writepages_context *ctx) +{ + int ret = 0; + int done = 0; + int error; + struct folio_batch fbatch; + int nr_folios; + pgoff_t index; + pgoff_t end; /* Inclusive */ + pgoff_t done_index; + int range_whole = 0; + xa_mark_t tag; + + folio_batch_init(&fbatch); + if (wbc->range_cyclic) { + index = mapping->writeback_index; /* prev offset */ + end = -1; + } else { + index = wbc->range_start >> PAGE_SHIFT; + end = wbc->range_end >> PAGE_SHIFT; + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) + range_whole = 1; + } + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) { + tag_pages_for_writeback(mapping, index, end); + tag = PAGECACHE_TAG_TOWRITE; + } else { + tag = PAGECACHE_TAG_DIRTY; + } + done_index = index; + while (!done && (index <= end)) { + int i; + + nr_folios = filemap_get_folios_tag(mapping, &index, end, + tag, &fbatch); + + if (nr_folios == 0) + break; + + for (i = 0; i < nr_folios; i++) { + struct folio *folio = fbatch.folios[i]; + + done_index = folio->index; + + 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: + 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 = afs_writepages_add_folio(folio, wbc, ctx); + if (unlikely(error)) { + /* + * Handle errors according to the type of + * writeback. There's no need to continue for + * background writeback. Just push done_index + * past this page so media errors won't choke + * writeout for the entire file. For integrity + * writeback, we must process the entire dirty + * set regardless of errors because the fs may + * still have state to clear for each page. In + * that case we continue processing and return + * the first error. + */ + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } else if (wbc->sync_mode != WB_SYNC_ALL) { + ret = error; + done_index = folio->index + + folio_nr_pages(folio); + done = 1; + break; + } + if (!ret) + ret = error; + } + + /* + * We stop writing back only if we are not doing + * integrity sync. In case of integrity sync we have to + * keep going until we have written all the pages + * we tagged for writeback prior to entering this loop. + */ + if (--wbc->nr_to_write <= 0 && + wbc->sync_mode == WB_SYNC_NONE) { + done = 1; + break; + } + } + folio_batch_release(&fbatch); + cond_resched(); + } + + /* + * If we hit the last page and there is more work to be done: wrap + * back the index back to the start of the file for the next + * time we are called. + */ + if (wbc->range_cyclic && !done) + done_index = 0; + if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) + mapping->writeback_index = done_index; + + return ret; +} /* * write some of the pending data back to the server @@ -523,7 +658,7 @@ int afs_writepages(struct address_space *mapping, else if (!down_read_trylock(&vnode->validate_lock)) return 0; - ret = write_cache_pages(mapping, wbc, afs_writepages_add_folio, &ctx); + ret = afs_write_cache_pages(mapping, wbc, &ctx); if (ret >= 0 && ctx.begun) ret = afs_writepages_submit(mapping, wbc, &ctx);