From patchwork Thu Mar 2 23:41:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 63664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp128914wrd; Thu, 2 Mar 2023 15:50:39 -0800 (PST) X-Google-Smtp-Source: AK7set/WkDqJI0jqH627bLXoFHfYTP2GpJTqOCQLRklemW+pshF7GEk5z0UtDEKM60jgD/dOeJc1 X-Received: by 2002:a17:902:d502:b0:19a:96ea:3850 with SMTP id b2-20020a170902d50200b0019a96ea3850mr3739967plg.17.1677801038761; Thu, 02 Mar 2023 15:50:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677801038; cv=none; d=google.com; s=arc-20160816; b=ntDKHENAJE84AzQWr9Wa29Rl+eqpugUvkukprXV21UW3SXzVYvK+5LHCGAd1WEtKmf 8VwWHasTQLZQTmr3s9mNDZB+xx8w5p9Rj9YLWlk8Pir5dPNppUCX3Mjks1stp4Hnh/A/ ERMd4bFU8gmndCpRM2JMDdtTtNhaiGvZWuo5ePHHhgtOWpBfBJWCoxlNbPErHRKq0o3v XhAyi8qLKNAjOUWspLaStp8htdoucYkc7zzkq+pyfdM8WKvImBwVuYOhzQ4/pcUURxKu kS9brLZv/rEqQUa5NqZph9gBFSQOv+8rhl8P3/stFv4BUeIwVQHSWwnmOcBP0qSwAmDb oNBA== 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=PlH4fJFKppxY+A07JXfq9y7Xnf4IHpCsyJL9AJzCkgg=; b=dAoH7HsqztbtyrMcz3yq1Gc+43QHAsXD24tWEu1HMF1T9PBc5lqSkRO0A/6l7Vdi0y aYi16/p5YTuQyK/wR9RJFVktJ06oBafL8sxIySlU35IwLwIGWn1ZQfWGylE/+RYg8p9Y IwvxmRQSjuGtT4i7/QzfPQLoVPQ1fw+JqnRmw1emMLK3qiUyw+KVl7KOxClvhLkGvuw/ uIbQTHKkEX5n/ODLbRfTaJ/b6XhgAQmOfhht1DTQcBNXW4ehX1UzVIm/SpNVX2tqrJtT XuymwAowI9Yv/AojGodXC2ndQkvUc5LZEmbD2U/VOhAv05Bpa1eBSMWjOSKcuHflr6tE lP7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YfaOPaqp; 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 f6-20020a17090274c600b001931fce6511si570500plt.374.2023.03.02.15.50.25; Thu, 02 Mar 2023 15:50:38 -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=YfaOPaqp; 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 S229961AbjCBXmh (ORCPT + 99 others); Thu, 2 Mar 2023 18:42:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229486AbjCBXmf (ORCPT ); Thu, 2 Mar 2023 18:42:35 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D001B4617F for ; Thu, 2 Mar 2023 15:41:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677800508; 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=PlH4fJFKppxY+A07JXfq9y7Xnf4IHpCsyJL9AJzCkgg=; b=YfaOPaqpXvFM/fmKL26sYDIiTuZaB1ZBfVkZZX+iQmQUCyRuP1cUh5QRjdcxUCcMpWTnYa LlINPZAFYu3ZfbGxQ7tqfbf3bsl296g2ugPCicAGwzuAijOaUvHG0BAzqAMIEy+zPq/uOd cSvc5XDFOk4j22AT8ewF3AbTJ8NYZEM= 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-175-AwPjlJZLO6-m9tqSQdYfyw-1; Thu, 02 Mar 2023 18:41:42 -0500 X-MC-Unique: AwPjlJZLO6-m9tqSQdYfyw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B90D31C05AEE; Thu, 2 Mar 2023 23:41:41 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id F275F440D9; Thu, 2 Mar 2023 23:41:39 +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: <522331.1677800209@warthog.procyon.org.uk> References: <522331.1677800209@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: cifs test patch to make cifs use its own version of write_cache_pages() MIME-Version: 1.0 Content-ID: <522531.1677800499.1@warthog.procyon.org.uk> Date: Thu, 02 Mar 2023 23:41:39 +0000 Message-ID: <522532.1677800499@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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?1759301901735637210?= X-GMAIL-MSGID: =?utf-8?q?1759301901735637210?= David Howells wrote: > And then CIFS. ... > > Base + Own write_cache_pages(): > WRITE: bw=451MiB/s (473MB/s), 113MiB/s-113MiB/s (118MB/s-118MB/s) > WRITE: bw=455MiB/s (478MB/s), 114MiB/s-114MiB/s (119MB/s-120MB/s) > WRITE: bw=453MiB/s (475MB/s), 113MiB/s-113MiB/s (119MB/s-119MB/s) > WRITE: bw=459MiB/s (481MB/s), 115MiB/s-115MiB/s (120MB/s-120MB/s) Here's my patch to give cifs its own copy of write_cache_pages() so that the function pointer can be eliminated in case some sort of spectre thing is causing a slowdown. This goes on top of "cifs test patch to convert to using write_cache_pages()". David --- fs/cifs/file.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 1 deletion(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 04e2466609d9..c33c7db729c7 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2802,6 +2802,141 @@ static int cifs_writepages_add_folio(struct folio *folio, return 0; } +static int cifs_write_cache_pages(struct address_space *mapping, + struct writeback_control *wbc, + struct cifs_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; + + error = cifs_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 */ @@ -2816,7 +2951,7 @@ static int cifs_writepages(struct address_space *mapping, * to prevent it. */ - ret = write_cache_pages(mapping, wbc, cifs_writepages_add_folio, &ctx); + ret = cifs_write_cache_pages(mapping, wbc, &ctx); if (ret >= 0 && ctx.begun) { ret = cifs_writepages_submit(mapping, wbc, &ctx); if (ret < 0)