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: 13158027 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 18E31C6FA8E for ; Thu, 2 Mar 2023 23:16:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 809666B0073; Thu, 2 Mar 2023 18:16:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B8F76B0074; Thu, 2 Mar 2023 18:16:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60BDB6B0075; Thu, 2 Mar 2023 18:16:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 54FEC6B0073 for ; Thu, 2 Mar 2023 18:16:57 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2B770A072E for ; Thu, 2 Mar 2023 23:16:57 +0000 (UTC) X-FDA: 80525520474.10.F3A2B7B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 74FC5C0002 for ; Thu, 2 Mar 2023 23:16:54 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="WzM+D/cd"; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@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=1677799014; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ix2GZROjqu1lNaAS5h0hXsC2zG3GiI8z8sp15KcpJfk=; b=I477rjmbcXlTSEqcZjw86wSKHyhG+KPITzrU6wGA9gKCCSAil7xq0NOVYN/Zca+geQx2Ul fcPVkYEXJhxolUGRBFXdW6wZ81yNQsppjFT7+aH3T28X4ZKz4XP1Eb52VZnUE2apPnKMIe oL/lQzQizmX3sSfbbESLZt/uUEDzKtY= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="WzM+D/cd"; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677799014; a=rsa-sha256; cv=none; b=LszAn+5NXNLPXxLqr4IKpN5XFy76GvrAjhjEf5SfGI8mwzeqP4oqANv2oBt3jlgTbwL4y2 UznmtTgEkb77oe7V1fRGvFetFQl67I4IaMZoEIrW/A0V8DAuK8GzKca2xD0dWZUwZU0tP4 lPCQ2HK+mrUfeDcgiE2tt59sDNRLhBE= 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=ix2GZROjqu1lNaAS5h0hXsC2zG3GiI8z8sp15KcpJfk=; b=WzM+D/cdM0VPTcRGwtqBvId1u+uvFto+MLPyDBkPB3LLCnXdhotpiqfboZb7MnuewgOqWW EXqTyuqDD4EXenIMxX78JqIgl4cqce86OanCSeGB5cVEn9Y9giUHkclLSQE3a6Vsb3O04v EX1uAXtvdfTCDSjw8HRh02shVamgHu4= 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 74FC5C0002 X-Rspam-User: X-Stat-Signature: nezu5zwnogoiro94ddqbwdts9ji6qehh X-HE-Tag: 1677799014-312782 X-HE-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PgKjaH3T6VtYSSeaCOF2BLpDZgiI5iXULtIVgTSCClkxzB3VfVPDeKHwnLO3XXRDMY+i4V94aw5uHjRc5cmA8cfhVv0t36K7pR6hzlOu/e5IjyAk+wlyVgoFPo8Js7OLqRd2wQivtsVtMhU8NekNYZtbvyomqiqSek0vAfoblaJKvtJKvgsHWZo8JiwF09QuPqrt36IFlVhoQyBX/EGQWFsnKCwiI6FmNzLD9nvOcKcoSd3KiL0lxI/gb3MCarRLc/qHGAkMBpyEqj79mAv1c/S4XyE+iLDbMDp3T1iAIkUnEcflcib2McCl+IDieWq1PPgTALpdNHxpJYFpMB1oavXuddsvbCTHtiUVFZUfAzy91HAcENcajlLDOrORoELKiTSsru8/4itgvPVwLfDllvcsLhUJnO2SZiBgZMnx5LrTcQw53rBPdcR2yeDuf+19E3kWfXEgA8wqlAwh0IO7IGKvfK5ouLeFdIAJuK9DxrYiZ0b4ETCFW+gmI90V9BLOSmv2YjUf22BxsYEyQC14jKhdtlrmbgNyC7tWhuzKXYoiHl46+HfPKagTiOwSF5l4U4zg1awWqy03q6yw6cU7Stg== 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: 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);