From patchwork Fri Nov 17 21:15:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13459589 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 3205BC072A2 for ; Fri, 17 Nov 2023 21:18:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC5A98D0057; Fri, 17 Nov 2023 16:18:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B75278D001C; Fri, 17 Nov 2023 16:18:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F2188D0057; Fri, 17 Nov 2023 16:18:04 -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 8A26C8D001C for ; Fri, 17 Nov 2023 16:18:04 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 64A0D1CBBF0 for ; Fri, 17 Nov 2023 21:18:04 +0000 (UTC) X-FDA: 81468708888.12.EA0E31B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id B27451C0003 for ; Fri, 17 Nov 2023 21:18:02 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="eRO/NpYF"; spf=pass (imf21.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=1700255882; 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=yJ0EH3j50U389igBFANhTwAFPV4cR9SbiJMpaWBP0sQ=; b=5AKe0bLF6Bx+pIlYMjCgVGZepTsZyreMPECdicXESWA8BJv84dl0fT5u9Kufc3cptgV2Sd NT23ATQpA4ryqa9LZ3wJ2XK/3QuPE9Y4RmrGjEbskW1C/kTiMnJydRV7BObHBc4Oclrwzl XnDbMR+ERj+vhFRS29EswJPLejpqNX4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700255882; a=rsa-sha256; cv=none; b=oYA2bQZxP3QX3SQbirQ0LX97CGcE3uQDsUTywm9XML4xvkIpLfWJ84FQB5nzYHGCq2/4gk Xap5gYJx08cCgcbJS7jEYOuKrminH70qJc5vYfFPR1npNyH2WaJmqsqmqIz6EJu9VEALJL 6cAa7yQ/RtpKLhpoufadMraVrdKB2t8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="eRO/NpYF"; spf=pass (imf21.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700255882; 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=yJ0EH3j50U389igBFANhTwAFPV4cR9SbiJMpaWBP0sQ=; b=eRO/NpYFc0N+xEjGqw7IvMpEKnP4WK1r3TqV3herJSE6xeQlMGyq4WeZJXriGOoLDwyIrd acUL2Y8Onpt6QRoOfMzGF2w+edb1W9oaHbS7MQo/X/qTc011OMHc+nIgTJvnTIHRM+yWff Ue0D8cDpyeszUSN+zjsB2JhWKUJH4Mk= 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-124-2tVkcOLeNIK64W8EMhC0KA-1; Fri, 17 Nov 2023 16:17:57 -0500 X-MC-Unique: 2tVkcOLeNIK64W8EMhC0KA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 BC7B8101B045; Fri, 17 Nov 2023 21:17:56 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B871C15882; Fri, 17 Nov 2023 21:17:54 +0000 (UTC) From: David Howells To: Jeff Layton , Steve French Cc: David Howells , Matthew Wilcox , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Dominique Martinet , Ilya Dryomov , Christian Brauner , linux-cachefs@redhat.com, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 32/51] netfs: Make netfs_skip_folio_read() take account of blocksize Date: Fri, 17 Nov 2023 21:15:24 +0000 Message-ID: <20231117211544.1740466-33-dhowells@redhat.com> In-Reply-To: <20231117211544.1740466-1-dhowells@redhat.com> References: <20231117211544.1740466-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Rspamd-Queue-Id: B27451C0003 X-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Ep 3KdGPcW2lu+rRV2aCaa6fM6+Hparo4KPnyyqkDHDP/1l9/dP77ryTJKJcv4u2E7i98oMfAY8ku9bsgBI2ihcIMdC8sYyviGegk8TRj4Y1xrLd78HE2hiuAqGEOa5skzf9rm8fWBEeR4qpGsIVms7T3juRMHfXVVvKQ72fW9GzwMYVv6PcDPN3AdE+4uUaDYm6culJdsLB0YF1dEsiSoyfElqmuirWbdnCMG2HvFm0GpdKwwqSSoorSUs/fIhbFq2IJzhUjTjEqVlmpFpbwRO0cgsn80Xu1cP2R7Xu2JV5jaBGI5Q3jlZ2/vrJZo7WU81pAaOYHDjaJnIEd26jxbMwWgVYZA== 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: Make netfs_skip_folio_read() take account of blocksize such as crypto blocksize. Signed-off-by: David Howells cc: Jeff Layton cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/netfs/buffered_read.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c index e06461ef0bfa..de696aaaefbd 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -337,6 +337,7 @@ EXPORT_SYMBOL(netfs_read_folio); /* * Prepare a folio for writing without reading first + * @ctx: File context * @folio: The folio being prepared * @pos: starting position for the write * @len: length of write @@ -350,32 +351,41 @@ EXPORT_SYMBOL(netfs_read_folio); * If any of these criteria are met, then zero out the unwritten parts * of the folio and return true. Otherwise, return false. */ -static bool netfs_skip_folio_read(struct folio *folio, loff_t pos, size_t len, - bool always_fill) +static bool netfs_skip_folio_read(struct netfs_inode *ctx, struct folio *folio, + loff_t pos, size_t len, bool always_fill) { struct inode *inode = folio_inode(folio); - loff_t i_size = i_size_read(inode); + loff_t i_size = i_size_read(inode), low, high; size_t offset = offset_in_folio(folio, pos); size_t plen = folio_size(folio); + size_t min_bsize = 1UL << ctx->min_bshift; + + if (likely(min_bsize == 1)) { + low = folio_file_pos(folio); + high = low + plen; + } else { + low = round_down(pos, min_bsize); + high = round_up(pos + len, min_bsize); + } if (unlikely(always_fill)) { - if (pos - offset + len <= i_size) - return false; /* Page entirely before EOF */ + if (low < i_size) + return false; /* Some part of the block before EOF */ zero_user_segment(&folio->page, 0, plen); folio_mark_uptodate(folio); return true; } - /* Full folio write */ - if (offset == 0 && len >= plen) + /* Full page write */ + if (pos == low && high == pos + len) return true; - /* Page entirely beyond the end of the file */ - if (pos - offset >= i_size) + /* pos beyond last page in the file */ + if (low >= i_size) goto zero_out; /* Write that covers from the start of the folio to EOF or beyond */ - if (offset == 0 && (pos + len) >= i_size) + if (pos == low && (pos + len) >= i_size) goto zero_out; return false; @@ -454,7 +464,7 @@ int netfs_write_begin(struct netfs_inode *ctx, * to preload the granule. */ if (!netfs_is_cache_enabled(ctx) && - netfs_skip_folio_read(folio, pos, len, false)) { + netfs_skip_folio_read(ctx, folio, pos, len, false)) { netfs_stat(&netfs_n_rh_write_zskip); goto have_folio_no_wait; }