From patchwork Fri Oct 13 16:04:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13421176 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 742F1CDB47E for ; Fri, 13 Oct 2023 16:07:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E65A280048; Fri, 13 Oct 2023 12:06:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E188780022; Fri, 13 Oct 2023 12:06:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1A0F80048; Fri, 13 Oct 2023 12:06:39 -0400 (EDT) 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 B1D2980022 for ; Fri, 13 Oct 2023 12:06:39 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8075514032C for ; Fri, 13 Oct 2023 16:06:39 +0000 (UTC) X-FDA: 81340916118.29.1A7E68F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 96C9E2001D for ; Fri, 13 Oct 2023 16:06:37 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hm3ItpE7; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697213197; 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=uT/Mhdx8sQf5PESeJ8Rr2IswwVlQVrc+dpLVfyRgQ2c=; b=Mp/vCTQi37cV+Fia9DIjDcyBCSK53ppLER684AAMwkEAMVTwVRuco7g21/vkpzzf2G66AZ F9zJ7cp8XNsaBsAQWl+3HkDoNJjlIPqFjuobC3JJf0Ap4/hM2hbMoQKrR4iidvjy2C2Tal EfFd/TmzoCdjJclIQHscpt36YySXS7Y= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hm3ItpE7; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697213197; a=rsa-sha256; cv=none; b=aFwstMnLOigOUBNcyuiXAuerjDfWQU3sV2NduzX4waFxcktuoB5ZpPwpko1hA2QxJIAjR6 PeKgAVo9TdaASuOvMUd85WW4Loj2ijA/HqqNqMK//+4ihVn1RFh/QRNh2ov3qino9JCvE9 vQKWvMv/pTcMejAmjnzvn0Hfh+Oi2ds= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697213196; 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=uT/Mhdx8sQf5PESeJ8Rr2IswwVlQVrc+dpLVfyRgQ2c=; b=hm3ItpE7s02pJPova3XIqdDimlvRJtQ8owbEk0Qrv3E9k9X6byocuHTJICUpmENFSPsOt7 GownP5JWiDDw9k76/vxUMRJy1Sbifh/Qio8qom8YgPZCxQTX94gVLjqpZc0rK0BtkeJ8Zs J0nYFYeAGF0MZewdx+cLMvcX0aDqazg= 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-640-oOqr7qHpOt-wp8G5blDJHw-1; Fri, 13 Oct 2023 12:06:23 -0400 X-MC-Unique: oOqr7qHpOt-wp8G5blDJHw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 259D588B7B8; Fri, 13 Oct 2023 16:06:22 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61A841C060DF; Fri, 13 Oct 2023 16:06:19 +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-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, linux-cachefs@redhat.com Subject: [RFC PATCH 33/53] netfs: Provide minimum blocksize parameter Date: Fri, 13 Oct 2023 17:04:02 +0100 Message-ID: <20231013160423.2218093-34-dhowells@redhat.com> In-Reply-To: <20231013160423.2218093-1-dhowells@redhat.com> References: <20231013160423.2218093-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 96C9E2001D X-Stat-Signature: 856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7XJjWQGBWXSEzA9Cjon7XFb7vfsDQMSoTJdYNTgqdiHzddEPz0ZUE+/rwPMfCQrtOUN2N11exkTfWpV1fKaLWrbVYtx7L6dNb9G07ftuqlSoFt310I+vtW+aG9QdkQ6R7qBvWyKhdYThrs+iS5LA3Ssz0wBttm92y7jOtAbpkDXhM+BKIPTwCPLvY+5ZdD8y7cPNvMWsG16f4+hFQl3A5a2TlX4KfIExkO9zFLVOPbSFIXIuv1J91AM1aMUGQVpv+Bm+ONg= 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: Add a parameter for minimum blocksize in the netfs_i_context struct. This can be used, for instance, to force I/O alignment for content encryption. It also requires the use of an RMW cycle if a write we want to do doesn't meet the block alignment requirements. 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 | 26 ++++++++++++++++++++++---- fs/netfs/buffered_write.c | 3 ++- fs/netfs/direct_read.c | 3 ++- include/linux/netfs.h | 2 ++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c index ab9f8e123245..e06461ef0bfa 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -527,14 +527,26 @@ int netfs_prefetch_for_write(struct file *file, struct folio *folio, struct address_space *mapping = folio_file_mapping(folio); struct netfs_inode *ctx = netfs_inode(mapping->host); unsigned long long start = folio_pos(folio); - size_t flen = folio_size(folio); + unsigned long long i_size, rstart, end; + size_t rlen; int ret; - _enter("%zx @%llx", flen, start); + DEFINE_READAHEAD(ractl, file, NULL, mapping, folio_index(folio)); + + _enter("%zx @%llx", len, start); ret = -ENOMEM; - rreq = netfs_alloc_request(mapping, file, start, flen, + i_size = i_size_read(mapping->host); + end = round_up(start + len, 1U << ctx->min_bshift); + if (end > i_size) { + unsigned long long limit = round_up(start + len, PAGE_SIZE); + end = max(limit, round_up(i_size, PAGE_SIZE)); + } + rstart = round_down(start, 1U << ctx->min_bshift); + rlen = end - rstart; + + rreq = netfs_alloc_request(mapping, file, rstart, rlen, NETFS_READ_FOR_WRITE); if (IS_ERR(rreq)) { ret = PTR_ERR(rreq); @@ -548,7 +560,13 @@ int netfs_prefetch_for_write(struct file *file, struct folio *folio, goto error_put; netfs_stat(&netfs_n_rh_write_begin); - trace_netfs_read(rreq, start, flen, netfs_read_trace_prefetch_for_write); + trace_netfs_read(rreq, rstart, rlen, netfs_read_trace_prefetch_for_write); + + /* Expand the request to meet caching requirements and download + * preferences. + */ + ractl._nr_pages = folio_nr_pages(folio); + netfs_rreq_expand(rreq, &ractl); /* Set up the output buffer */ iov_iter_xarray(&rreq->iter, ITER_DEST, &mapping->i_pages, diff --git a/fs/netfs/buffered_write.c b/fs/netfs/buffered_write.c index d5a5a315fbd3..7163fcc05206 100644 --- a/fs/netfs/buffered_write.c +++ b/fs/netfs/buffered_write.c @@ -80,7 +80,8 @@ static enum netfs_how_to_modify netfs_how_to_modify(struct netfs_inode *ctx, if (file->f_mode & FMODE_READ) return NETFS_JUST_PREFETCH; - if (netfs_is_cache_enabled(ctx)) + if (netfs_is_cache_enabled(ctx) || + ctx->min_bshift > 0) return NETFS_JUST_PREFETCH; if (!finfo) diff --git a/fs/netfs/direct_read.c b/fs/netfs/direct_read.c index 1d26468aafd9..52ad8fa66dd5 100644 --- a/fs/netfs/direct_read.c +++ b/fs/netfs/direct_read.c @@ -185,7 +185,8 @@ static ssize_t netfs_unbuffered_read_iter_locked(struct kiocb *iocb, struct iov_ * will then need to pad the request out to the minimum block size. */ if (test_bit(NETFS_RREQ_USE_BOUNCE_BUFFER, &rreq->flags)) { - start = rreq->start; + min_bsize = 1ULL << ctx->min_bshift; + start = round_down(rreq->start, min_bsize); end = min_t(unsigned long long, round_up(rreq->start + rreq->len, min_bsize), ctx->remote_i_size); diff --git a/include/linux/netfs.h b/include/linux/netfs.h index fb4f4f826b93..6244f7a9a44a 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -141,6 +141,7 @@ struct netfs_inode { unsigned long flags; #define NETFS_ICTX_ODIRECT 0 /* The file has DIO in progress */ #define NETFS_ICTX_UNBUFFERED 1 /* I/O should not use the pagecache */ + unsigned char min_bshift; /* log2 min block size for bounding box or 0 */ }; /* @@ -462,6 +463,7 @@ static inline void netfs_inode_init(struct netfs_inode *ctx, ctx->remote_i_size = i_size_read(&ctx->inode); ctx->zero_point = ctx->remote_i_size; ctx->flags = 0; + ctx->min_bshift = 0; #if IS_ENABLED(CONFIG_FSCACHE) ctx->cache = NULL; #endif