From patchwork Thu Mar 2 23:16:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 63651 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp119790wrd; Thu, 2 Mar 2023 15:22:16 -0800 (PST) X-Google-Smtp-Source: AK7set+Reu7T7ZszFS8c/8ylAIHb5qf4Ki7Z1OELGgSKDDC+VKVxLI8HPksFXszDBOhN8YRj+Wjc X-Received: by 2002:a17:906:26d7:b0:8e6:1726:df82 with SMTP id u23-20020a17090626d700b008e61726df82mr3122705ejc.30.1677799336460; Thu, 02 Mar 2023 15:22:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677799336; cv=none; d=google.com; s=arc-20160816; b=zBuQ0uDUEk/UNO9NgnoRVaqJ+O3T8brRQCDYppOeU90lCaSeD8+WYK7lV01tNCZHJW Qjp6F3ptoXlfFphdm21+Lw8IeQqnW9N5+jVOXjKnvpBkLWn3LpE0imyng9QPYO1K8NQK s2HdXUrcB7xpWUa+44uEz/sNg+JY+uCc3pXP0Qzwj0Gk0FdtXI+2MEACGqm8vMK8+ybS r37YMuqAcqHAXzZaKF8vKTdzgPHmOJxm838jEc831oxdNHgOO3yW9rOpyyEEIujWEuNa KSLSBlOJ39CHmoNMQ+sMhmfmmJnwTuU2VE7P3uRhfi10ikqyCu7GjhE4Is+AbnfWW98a +2sA== 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=1eE9Pafa530L5JjpUU74EsDdw6S9K1gsLvm9PBz92W8=; b=twfa0agBREMhe3LOhmzGRp+WDlLtGt2a+zeye9FUtTrCBnIxC1EP4t+MGC8i6kr0RN 0kzCM0QrW7+KHc8UkQD/Lda9CLpcMcjyaIDzJXIE1s24BUB64z1Y+xqWQAJPVOASAGAt FC7CqMNOYawNUg+pZR+oEdq8TlVmJBS7k3/t8HlQ4slHyyYNVeroyjomArlreMgOlQY4 pnCNKYAeh3RKIO8izPFEw0fG9wfbXPx9O2xiEVPTtcWXYRHiM6EGmvLecqCIdIncvYKe fHLRPYlLoA3pyAZZ9wtQkKf/Qkb8N4CJjl/UNpAyh+mKO2Y95Iu/AWGN9CwHR3Y0r37+ N6ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e5UibSOr; 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 gz2-20020a170906f2c200b008cbae8a510bsi574927ejb.652.2023.03.02.15.21.53; Thu, 02 Mar 2023 15:22:16 -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=e5UibSOr; 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 S229840AbjCBXSW (ORCPT + 99 others); Thu, 2 Mar 2023 18:18:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbjCBXSP (ORCPT ); Thu, 2 Mar 2023 18:18:15 -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 86D47580F6 for ; Thu, 2 Mar 2023 15:17:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677799012; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1eE9Pafa530L5JjpUU74EsDdw6S9K1gsLvm9PBz92W8=; b=e5UibSOrWGxcxGg2l4E3lQMiSC1vlGR9bBNe4k4Xs0e4w/tEBHZWvaouNgCKh5KXj4bFMG 8Ys+EikQqRfQrcspmFb2sOoqBxSsAyqf0Poi0BA0SIjFAOdw7ZtJGPv/6kveQcpYEK8z1O vUeSrDSMlaDIn9EU6KQSSsgLkSZVI1E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-622-zwFLchJEPOeBqPxHgNImPw-1; Thu, 02 Mar 2023 18:16:47 -0500 X-MC-Unique: zwFLchJEPOeBqPxHgNImPw-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 630DB800B23; Thu, 2 Mar 2023 23:16:46 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54038440D9; Thu, 2 Mar 2023 23:16:44 +0000 (UTC) From: David Howells To: Linus Torvalds , Steve French Cc: David Howells , 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, Steve French , Andrew Morton , linux-mm@kvack.org Subject: [PATCH 1/3] mm: Add a function to get a single tagged folio from a file Date: Thu, 2 Mar 2023 23:16:36 +0000 Message-Id: <20230302231638.521280-2-dhowells@redhat.com> In-Reply-To: <20230302231638.521280-1-dhowells@redhat.com> References: <20230302231638.521280-1-dhowells@redhat.com> MIME-Version: 1.0 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?1759300116892108710?= X-GMAIL-MSGID: =?utf-8?q?1759300116892108710?= Add a function to get a single tagged folio from a file rather than a batch for use in afs and cifs where, in the common case, the batch is likely to be rendered irrelevant by the {afs,cifs}_extend_writeback() function. For filemap_get_folios_tag() to be of use, the batch has to be passed down, and if it contains scattered, non-contiguous folios, these are likely to end up being pinned by the batch for significant periods of time whilst I/O is undertaken on earlier pages. Further, for write_cache_pages() to be useful, it would need to wait for PG_fscache which is used to indicate that I/O is in progress from a folio to the cache - but it can't do this unconditionally as some filesystems, such as btrfs, use PG_private_2 for other purposes. Signed-off-by: David Howells cc: Steve French cc: Linus Torvalds cc: "Vishal Moola (Oracle)" cc: "Matthew Wilcox (Oracle)" cc: Andrew Morton cc: linux-afs@lists.infradead.org cc: linux-cifs@vger.kernel.org cc: linux-mm@kvack.org Link: https://lore.kernel.org/r/2214157.1677250083@warthog.procyon.org.uk/ --- include/linux/pagemap.h | 2 ++ mm/filemap.c | 58 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 0acb8e1fb7af..577535633006 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -741,6 +741,8 @@ unsigned filemap_get_folios_contig(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch); unsigned filemap_get_folios_tag(struct address_space *mapping, pgoff_t *start, pgoff_t end, xa_mark_t tag, struct folio_batch *fbatch); +struct folio *filemap_get_folio_tag(struct address_space *mapping, pgoff_t *start, + pgoff_t end, xa_mark_t tag); struct page *grab_cache_page_write_begin(struct address_space *mapping, pgoff_t index); diff --git a/mm/filemap.c b/mm/filemap.c index 2723104cc06a..1b1e9c661018 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2339,6 +2339,64 @@ unsigned filemap_get_folios_tag(struct address_space *mapping, pgoff_t *start, } EXPORT_SYMBOL(filemap_get_folios_tag); +/** + * filemap_get_folio_tag - Get the first folio matching @tag + * @mapping: The address_space to search + * @start: The starting page index + * @end: The final page index (inclusive) + * @tag: The tag index + * + * Search for and return the first folios in the mapping starting at index + * @start and up to index @end (inclusive). The folio is returned with an + * elevated reference count. + * + * If a folio is returned, it may start before @start; if it does, it will + * contain @start. The folio may also extend beyond @end; if it does, it will + * contain @end. If folios are added to or removed from the page cache while + * this is running, they may or may not be found by this call. + * + * Return: The folio that was found or NULL. @start is also updated to index + * the next folio for the traversal or will be left pointing after @end. + */ +struct folio *filemap_get_folio_tag(struct address_space *mapping, pgoff_t *start, + pgoff_t end, xa_mark_t tag) +{ + XA_STATE(xas, &mapping->i_pages, *start); + struct folio *folio; + + rcu_read_lock(); + while ((folio = find_get_entry(&xas, end, tag)) != NULL) { + /* + * Shadow entries should never be tagged, but this iteration + * is lockless so there is a window for page reclaim to evict + * a page we saw tagged. Skip over it. + */ + if (xa_is_value(folio)) + continue; + + if (folio_test_hugetlb(folio)) + *start = folio->index + 1; + else + *start = folio_next_index(folio); + goto out; + } + + /* + * We come here when there is no page beyond @end. We take care to not + * overflow the index @start as it confuses some of the callers. This + * breaks the iteration when there is a page at index -1 but that is + * already broke anyway. + */ + if (end == (pgoff_t)-1) + *start = (pgoff_t)-1; + else + *start = end + 1; +out: + rcu_read_unlock(); + return folio; +} +EXPORT_SYMBOL(filemap_get_folio_tag); + /* * CD/DVDs are error prone. When a medium error occurs, the driver may fail * a _large_ part of the i/o request. Imagine the worst scenario: From patchwork Thu Mar 2 23:16:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 63652 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp119802wrd; Thu, 2 Mar 2023 15:22:18 -0800 (PST) X-Google-Smtp-Source: AK7set8z7dFyh/6+8j/kyda2ZHbdr66OhL3hDNIwPfzirAjSI37qArPIGFC3sCqLNkwOXqPZuD16 X-Received: by 2002:a50:ef18:0:b0:4ab:4b85:a69f with SMTP id m24-20020a50ef18000000b004ab4b85a69fmr68956eds.1.1677799338368; Thu, 02 Mar 2023 15:22:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677799338; cv=none; d=google.com; s=arc-20160816; b=LmL4UweRUrv5rGX5MxFjGhCwffyTnEoACxrcfsSRBR5QbNTd+y/WssVQyCeT16zuRu jzb3ocOFjnrJ586/lQGylH3N/ueB3+hQr6Mtrr9njujbeqs9KkXl0IbuYPfjEsA38Ec9 uQdxcWkehuj9pwoV/yR0ArQRG5nB1BY6UEz/xr5YBCJ6wsVAhKQaSVbk4l2L4aka68Fp tyztnQQL08B5STWcI6p0zKZYy0GH9HM6tPF17Z9qCIKCTsBAStlTtSavLPejhmBo8j0N DNx55sgOhKm0FFsbECmFe3uz0HusZSWKOCVkQ4PYsRb4gGVYMOcFpnN/axz6tpsK74tO 8oeQ== 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=nNYSQ/Y9B3aZRJt+LYUgV6EcG7vLla4aEHu0riyXHik=; b=LAsGScYIHeiHdnN3bQlkhL/GCt/RnspqdFoGAIbRwgqk/4TaSDY+s0p774lPxFf68/ orHsZss1GFaf0QCNYOvm8dridDSC8EC+dijEs/ZDcJQMkYymTIvBO3bR1jhCMCUkdFUr rA3AfwSl5pGO+UUJe5j1xmh4G+mLJgcxRAvQ+HBASLDJ0HthukYrGNPw9sMBypXeDImX cQ9yE1sFKjGVLhv5u9ajDGQ1aoB5KDpc5kWdsyO4lMjw8Jgj66Cg52AvjiE/oMO/F3Yj oVkjSYF6+Ahm39m+tipkrp2UdAL0BTeJhVgWI0BbPwsmHny4cibbOv29SCG1UC6VMCDl SIKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ccQsJISb; 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 c2-20020aa7c982000000b004aad0c7e385si896453edt.270.2023.03.02.15.21.55; Thu, 02 Mar 2023 15:22:18 -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=ccQsJISb; 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 S229849AbjCBXSY (ORCPT + 99 others); Thu, 2 Mar 2023 18:18:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjCBXSP (ORCPT ); Thu, 2 Mar 2023 18:18:15 -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 2C6FE5943D for ; Thu, 2 Mar 2023 15:17:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677799013; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nNYSQ/Y9B3aZRJt+LYUgV6EcG7vLla4aEHu0riyXHik=; b=ccQsJISbti997Ttdl2XBgh7bmwyhSQlSx3C9X5OHPsJbOIUfNYa1Yukvqv4NKoFngAu8op Bz2eL/FA15HwjbpruglQIHmYkTcjfHCvx/zLY35rXjJCDeuLyJxk4BH27S7w8UJfS3P+h0 3mbAYQoQlJbNC9w14z0LbgUZ5QaLBZI= 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-640-Ema7s1klNeSsDP6d3fPMHw-1; Thu, 02 Mar 2023 18:16:50 -0500 X-MC-Unique: Ema7s1klNeSsDP6d3fPMHw-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 2767F1C05AC1; Thu, 2 Mar 2023 23:16:49 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15443492C3E; Thu, 2 Mar 2023 23:16:46 +0000 (UTC) From: David Howells To: Linus Torvalds , Steve French Cc: David Howells , 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, Steve French , Andrew Morton , linux-mm@kvack.org Subject: [PATCH 2/3] afs: Partially revert and use filemap_get_folio_tag() Date: Thu, 2 Mar 2023 23:16:37 +0000 Message-Id: <20230302231638.521280-3-dhowells@redhat.com> In-Reply-To: <20230302231638.521280-1-dhowells@redhat.com> References: <20230302231638.521280-1-dhowells@redhat.com> MIME-Version: 1.0 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=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?1759300118961485533?= X-GMAIL-MSGID: =?utf-8?q?1759300118961485533?= Partially revert the changes made by: acc8d8588cb7e3e64b0d2fa611dad06574cd67b1. afs: convert afs_writepages_region() to use filemap_get_folios_tag() The issue is that filemap_get_folios_tag() gets a batch of pages at a time, and then afs_writepages_region() goes through them one at a time, extends each into an operation with as many pages as will fit using the loop in afs_extend_writeback() and submits it - but, in the common case, this means that the other pages in the batch already got annexed and processed in afs_extend_writeback() and we end up doing duplicate processing. Switching to write_cache_pages() isn't an immediate substitute as that doesn't take account of PG_fscache (and this bit is used in other ways by other filesystems). So go back to finding the next folio from the VM one at a time and then extending the op onwards. Fixes: acc8d8588cb7 ("afs: convert afs_writepages_region() to use filemap_get_folios_tag()") Signed-off-by: David Howells cc: Linus Torvalds cc: Marc Dionne cc: Steve French cc: "Vishal Moola (Oracle)" cc: "Matthew Wilcox (Oracle)" cc: Andrew Morton cc: linux-afs@lists.infradead.org cc: linux-mm@kvack.org Link: https://lore.kernel.org/r/2214157.1677250083@warthog.procyon.org.uk/ --- fs/afs/write.c | 118 ++++++++++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 61 deletions(-) diff --git a/fs/afs/write.c b/fs/afs/write.c index 571f3b9a417e..2ed76697be96 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -704,87 +704,83 @@ static int afs_writepages_region(struct address_space *mapping, bool max_one_loop) { struct folio *folio; - struct folio_batch fbatch; ssize_t ret; - unsigned int i; - int n, skips = 0; + int skips = 0; _enter("%llx,%llx,", start, end); - folio_batch_init(&fbatch); do { pgoff_t index = start / PAGE_SIZE; - n = filemap_get_folios_tag(mapping, &index, end / PAGE_SIZE, - PAGECACHE_TAG_DIRTY, &fbatch); - - if (!n) + folio = filemap_get_folio_tag(mapping, &index, end / PAGE_SIZE, + PAGECACHE_TAG_DIRTY); + if (!folio) break; - for (i = 0; i < n; i++) { - folio = fbatch.folios[i]; - start = folio_pos(folio); /* May regress with THPs */ - _debug("wback %lx", folio_index(folio)); + start = folio_pos(folio); /* May regress with THPs */ - /* At this point we hold neither the i_pages lock nor the - * page lock: the page may be truncated or invalidated - * (changing page->mapping to NULL), or even swizzled - * back from swapper_space to tmpfs file mapping - */ - if (wbc->sync_mode != WB_SYNC_NONE) { - ret = folio_lock_killable(folio); - if (ret < 0) { - folio_batch_release(&fbatch); - return ret; - } - } else { - if (!folio_trylock(folio)) - continue; - } + _debug("wback %lx", folio_index(folio)); - if (folio->mapping != mapping || - !folio_test_dirty(folio)) { - start += folio_size(folio); - folio_unlock(folio); - continue; + /* At this point we hold neither the i_pages lock nor the + * page lock: the page may be truncated or invalidated + * (changing page->mapping to NULL), or even swizzled + * back from swapper_space to tmpfs file mapping + */ + if (wbc->sync_mode != WB_SYNC_NONE) { + ret = folio_lock_killable(folio); + if (ret < 0) { + folio_put(folio); + return ret; + } + } else { + if (!folio_trylock(folio)) { + folio_put(folio); + return 0; } + } - if (folio_test_writeback(folio) || - folio_test_fscache(folio)) { - folio_unlock(folio); - if (wbc->sync_mode != WB_SYNC_NONE) { - folio_wait_writeback(folio); + if (folio_mapping(folio) != mapping || + !folio_test_dirty(folio)) { + start += folio_size(folio); + folio_unlock(folio); + folio_put(folio); + continue; + } + + if (folio_test_writeback(folio) || + folio_test_fscache(folio)) { + folio_unlock(folio); + if (wbc->sync_mode != WB_SYNC_NONE) { + folio_wait_writeback(folio); #ifdef CONFIG_AFS_FSCACHE - folio_wait_fscache(folio); + folio_wait_fscache(folio); #endif - } else { - start += folio_size(folio); - } - if (wbc->sync_mode == WB_SYNC_NONE) { - if (skips >= 5 || need_resched()) { - *_next = start; - _leave(" = 0 [%llx]", *_next); - return 0; - } - skips++; - } - continue; + } else { + start += folio_size(folio); } - - if (!folio_clear_dirty_for_io(folio)) - BUG(); - ret = afs_write_back_from_locked_folio(mapping, wbc, - folio, start, end); - if (ret < 0) { - _leave(" = %zd", ret); - folio_batch_release(&fbatch); - return ret; + folio_put(folio); + if (wbc->sync_mode == WB_SYNC_NONE) { + if (skips >= 5 || need_resched()) + break; + skips++; } + continue; + } - start += ret; + if (!folio_clear_dirty_for_io(folio)) + BUG(); + ret = afs_write_back_from_locked_folio(mapping, wbc, folio, start, end); + folio_put(folio); + if (ret < 0) { + _leave(" = %zd", ret); + return ret; } - folio_batch_release(&fbatch); + start += ret; + + if (max_one_loop) + break; + cond_resched(); } while (wbc->nr_to_write > 0); From patchwork Thu Mar 2 23:16:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 63653 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp119914wrd; Thu, 2 Mar 2023 15:22:39 -0800 (PST) X-Google-Smtp-Source: AK7set+h3jDr2ySrsH4wkGk/7WxYhAwvoSR6Z8P0U6BAiJr1SyGS/pI2ndvGpmZncS+DIDSGiE5F X-Received: by 2002:aa7:cfcf:0:b0:4ab:1d33:69ba with SMTP id r15-20020aa7cfcf000000b004ab1d3369bamr22188edy.16.1677799358924; Thu, 02 Mar 2023 15:22:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677799358; cv=none; d=google.com; s=arc-20160816; b=AuFDlvU0G6ispflEu1NsR7XNohDIq3bT1f4ijok930NRsPizL6hrJm0Fpba4gncm/e BkvUckJ+zAVTqgWepE+rrIliS78+RqLJM2CSPaihRq7IJqddy8tpTL/71KmHTd8CspuH PzhGvPxSh+Xkyy84NvQO6H1zSUWDsHeRVSTbrwd0hF5RZa3pXK4NTT4VtbBK8zZ/pgF5 FTcFSHgZ4heKV2RFUJtTPtAos+GaXRLCu5M8K1v++Ecc5U2sHt0Uj99g0yvkY0RG0Ns6 gVsPnNUhvGUGhki09NZ3ukMr1v64KJ9odmDIX3CERwujYZXcSsDaMIqNvEBuxFHgqlQB PLGw== 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=ix2GZROjqu1lNaAS5h0hXsC2zG3GiI8z8sp15KcpJfk=; b=jauG0VxpDkuChR4Z3o5mWGeuqo5a8QYzclkvdpDjRiiniU0JgmQzLCWc8M5lzVvf3I pRnsffDTJUDunn+tnIG2AEXx9PwD4/A61uUNB+VneDQEuk1Q6Zf6PEW90apPw3EbdZ/m uh+M7boKm70+gfXtDQ+/LouV6eF28awKsueY3JuGWpbCcy7/8lCb/QHLKvdhEj295mWy 9OfBUPQGAc9WlMHHjhfCc3H6QAWz3kKbkBPGJ97Ntu843/KNzRyM8fOT20uW6okzG9tC v7Yh0QTWtlEmFflBPoHZPbmnqpreZAjZ8BL7qYWvGB7f2La8e/oTCnCgpwCD4xsSVyOm 6f5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LcvyD3ux; 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 k21-20020a05640212d500b004bdcff27f88si890494edx.123.2023.03.02.15.22.16; Thu, 02 Mar 2023 15:22: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=LcvyD3ux; 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 S229674AbjCBXSk (ORCPT + 99 others); Thu, 2 Mar 2023 18:18:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbjCBXSW (ORCPT ); Thu, 2 Mar 2023 18:18:22 -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 0EAFB59E47 for ; Thu, 2 Mar 2023 15:17:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677799014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ix2GZROjqu1lNaAS5h0hXsC2zG3GiI8z8sp15KcpJfk=; b=LcvyD3ux3Y1/612Hm7SmO8jncvmUm10zvKPjdqMOQEdly2yg3E58rGsiP/9bYHXVNrF2X3 9HzILPVWJLDS64eA7BFCynWYb6eOdZ/OgBrAuaHsu/1UEmZr8feYK4ItmPoj7fIfs6zP8N n8ypbm9iBM9838fPlSFajkyIntRLcBc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-190-zQT8bSDzMRqgB_Iir98xAw-1; Thu, 02 Mar 2023 18:16:52 -0500 X-MC-Unique: zQT8bSDzMRqgB_Iir98xAw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C4BAA85A5A3; Thu, 2 Mar 2023 23:16:51 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6EE72166B26; Thu, 2 Mar 2023 23:16:49 +0000 (UTC) From: David Howells To: Linus Torvalds , Steve French Cc: David Howells , 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, Steve French , Andrew Morton , linux-mm@kvack.org Subject: [PATCH 3/3] cifs: Partially revert and use filemap_get_folio_tag() Date: Thu, 2 Mar 2023 23:16:38 +0000 Message-Id: <20230302231638.521280-4-dhowells@redhat.com> In-Reply-To: <20230302231638.521280-1-dhowells@redhat.com> References: <20230302231638.521280-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=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?1759300140195109725?= X-GMAIL-MSGID: =?utf-8?q?1759300140195109725?= Mirror the changes made to afs to partially revert the changes made by: acc8d8588cb7e3e64b0d2fa611dad06574cd67b1. "afs: convert afs_writepages_region() to use filemap_get_folios_tag()" that were then mirrored into cifs. The issue is that filemap_get_folios_tag() gets a batch of pages at a time, and then cifs_writepages_region() goes through them one at a time, extends each into an operation with as many pages as will fit using the loop in cifs_extend_writeback() and submits it - but, in the common case, this means that the other pages in the batch already got annexed and processed in cifs_extend_writeback() and we end up doing duplicate processing. Switching to write_cache_pages() isn't an immediate substitute as that doesn't take account of PG_fscache (and this bit is used in other ways by other filesystems). So go back to finding the next folio from the VM one at a time and then extending the op onwards. Fixes: 3822a7c40997 ("Merge tag 'mm-stable-2023-02-20-13-37' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm") Signed-off-by: David Howells cc: Steve French cc: Linus Torvalds cc: Shyam Prasad N cc: Rohith Surabattula cc: Jeff Layton cc: Paulo Alcantara cc: "Vishal Moola (Oracle)" cc: "Matthew Wilcox (Oracle)" cc: Andrew Morton cc: linux-cifs@vger.kernel.org cc: linux-mm@kvack.org Link: https://lore.kernel.org/r/2214157.1677250083@warthog.procyon.org.uk/ --- fs/cifs/file.c | 115 +++++++++++++++++++++---------------------------- 1 file changed, 49 insertions(+), 66 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 4d4a2d82636d..a3e89e741b42 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2864,93 +2864,76 @@ static int cifs_writepages_region(struct address_space *mapping, struct writeback_control *wbc, loff_t start, loff_t end, loff_t *_next) { - struct folio_batch fbatch; + struct folio *folio; + ssize_t ret; int skips = 0; - folio_batch_init(&fbatch); do { - int nr; pgoff_t index = start / PAGE_SIZE; - nr = filemap_get_folios_tag(mapping, &index, end / PAGE_SIZE, - PAGECACHE_TAG_DIRTY, &fbatch); - if (!nr) + folio = filemap_get_folio_tag(mapping, &index, end / PAGE_SIZE, + PAGECACHE_TAG_DIRTY); + if (!folio) break; - for (int i = 0; i < nr; i++) { - ssize_t ret; - struct folio *folio = fbatch.folios[i]; - -redo_folio: - start = folio_pos(folio); /* May regress with THPs */ + start = folio_pos(folio); /* May regress with THPs */ - /* At this point we hold neither the i_pages lock nor the - * page lock: the page may be truncated or invalidated - * (changing page->mapping to NULL), or even swizzled - * back from swapper_space to tmpfs file mapping - */ - if (wbc->sync_mode != WB_SYNC_NONE) { - ret = folio_lock_killable(folio); - if (ret < 0) - goto write_error; - } else { - if (!folio_trylock(folio)) - goto skip_write; + /* At this point we hold neither the i_pages lock nor the + * page lock: the page may be truncated or invalidated + * (changing page->mapping to NULL), or even swizzled + * back from swapper_space to tmpfs file mapping + */ + if (wbc->sync_mode != WB_SYNC_NONE) { + ret = folio_lock_killable(folio); + if (ret < 0) { + folio_put(folio); + return ret; } - - if (folio_mapping(folio) != mapping || - !folio_test_dirty(folio)) { - start += folio_size(folio); - folio_unlock(folio); - continue; + } else { + if (!folio_trylock(folio)) { + folio_put(folio); + return 0; } + } - if (folio_test_writeback(folio) || - folio_test_fscache(folio)) { - folio_unlock(folio); - if (wbc->sync_mode == WB_SYNC_NONE) - goto skip_write; + if (folio_mapping(folio) != mapping || + !folio_test_dirty(folio)) { + start += folio_size(folio); + folio_unlock(folio); + folio_put(folio); + continue; + } + if (folio_test_writeback(folio) || + folio_test_fscache(folio)) { + folio_unlock(folio); + if (wbc->sync_mode != WB_SYNC_NONE) { folio_wait_writeback(folio); #ifdef CONFIG_CIFS_FSCACHE folio_wait_fscache(folio); #endif - goto redo_folio; + } else { + start += folio_size(folio); } - - if (!folio_clear_dirty_for_io(folio)) - /* We hold the page lock - it should've been dirty. */ - WARN_ON(1); - - ret = cifs_write_back_from_locked_folio(mapping, wbc, folio, start, end); - if (ret < 0) - goto write_error; - - start += ret; - continue; - -write_error: - folio_batch_release(&fbatch); - *_next = start; - return ret; - -skip_write: - /* - * Too many skipped writes, or need to reschedule? - * Treat it as a write error without an error code. - */ - if (skips >= 5 || need_resched()) { - ret = 0; - goto write_error; + folio_put(folio); + if (wbc->sync_mode == WB_SYNC_NONE) { + if (skips >= 5 || need_resched()) + break; + skips++; } - - /* Otherwise, just skip that folio and go on to the next */ - skips++; - start += folio_size(folio); continue; } - folio_batch_release(&fbatch); + if (!folio_clear_dirty_for_io(folio)) + /* We hold the page lock - it should've been dirty. */ + WARN_ON(1); + + ret = cifs_write_back_from_locked_folio(mapping, wbc, folio, start, end); + folio_put(folio); + if (ret < 0) + return ret; + + start += ret; cond_resched(); } while (wbc->nr_to_write > 0);