From patchwork Thu Dec 7 21:21:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13484055 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 A05E7C46CA3 for ; Thu, 7 Dec 2023 21:24:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9157C6B00C2; Thu, 7 Dec 2023 16:24:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B8786B00C3; Thu, 7 Dec 2023 16:24:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 708606B00C5; Thu, 7 Dec 2023 16:24:19 -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 5D2696B00C3 for ; Thu, 7 Dec 2023 16:24:19 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3FA0C4026C for ; Thu, 7 Dec 2023 21:24:19 +0000 (UTC) X-FDA: 81541300638.05.FCA6801 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 944BAC0014 for ; Thu, 7 Dec 2023 21:24:17 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ehdgBajI; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.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=1701984257; 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=gDEVNBWkDC1KjDnrtBrbZBZNboYk+5MLxRm91IWt834=; b=sKjgnh7F+IFyMpVykPw/Nf6ezbxSqhdxKalYs+0LzAEv1SFotfLgPzXNAuug7lmUevu3ll 2m7tOLIz0r80TyE6sLD2CqRhc+ieC13qaN7D9vk+Tc89dwomKRe65J7PUyfw97CnXwYT8s YOTPxfaZZJHIz/GukKbawLYD6HT0cXo= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ehdgBajI; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.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=1701984257; a=rsa-sha256; cv=none; b=UsY8MoqSqktHJ3okxCKY2suaO53meRgOvpGSz+iylZ8ollyl3lg4lNEEQoWyLfNGFO5q1q xcW3R6cD4QwWWad8qwjJj7BRej0rfy8bEOd7VgNuGlizxiVM75KsRzQTwhsktaaU/TQSlJ xi+V/rlZ6482s3y6fzbSW70Ow+Q4O8k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701984256; 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=gDEVNBWkDC1KjDnrtBrbZBZNboYk+5MLxRm91IWt834=; b=ehdgBajIWh9/3TQ8nTl0IMVR5BMncqNfXWruWMCqZJMBI5YNq2TgEM8TMQdJjefUCB3H7q tiAcov6TTMDYB1aOLybHAOaU20T0x1r8kDJSX3SwykOfTme+UqN4RE3mVjStFL02jlrBIN l0f+ppNj61oP0hDUB0c6850h9WLQ0fM= 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-258-xjZJHMPbPOmQdOv-d-4Uow-1; Thu, 07 Dec 2023 16:24:13 -0500 X-MC-Unique: xjZJHMPbPOmQdOv-d-4Uow-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 44867101A52A; Thu, 7 Dec 2023 21:24:12 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C42B1C060AF; Thu, 7 Dec 2023 21:24:09 +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 , Eric Van Hensbergen , 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 v3 35/59] netfs: Provide minimum blocksize parameter Date: Thu, 7 Dec 2023 21:21:42 +0000 Message-ID: <20231207212206.1379128-36-dhowells@redhat.com> In-Reply-To: <20231207212206.1379128-1-dhowells@redhat.com> References: <20231207212206.1379128-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Rspamd-Queue-Id: 944BAC0014 X-R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XZWP6uuk6GPiyUdaMfMeSYl8JjVsrhRvGmPBhXch1lmGdJtKdkIIieN/v7GykyDPgTwJ6runR6Wgt+MsDVHnFOB//NFbu4qBpT/vUnUnwfPGMguPv9Na0NBUk0uQYvcG42OJvXlJ6Hvh57VciaP09r2LV2JDSuiK1R4L5RP/EYZTq7kVkrXNfWBgH25ELPDFG1uDdO37DgM0S8PLkwWzB/S6PIu6TOv6wkYPrU9Bei5NspjNjfUuRD9nkqbdW57586/jz50ULtfxjBEmsQqVdA88X0dxZ71x3A4GxJNU= 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: 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 a59e7b2edaac..0d47e5ea6870 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -521,14 +521,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); @@ -542,7 +554,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 42f89f8ea8af..8339e3f753af 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 ef17d94a2fbd..69ff5d652931 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -139,6 +139,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->ops = ops; ctx->remote_i_size = i_size_read(&ctx->inode); ctx->flags = 0; + ctx->min_bshift = 0; #if IS_ENABLED(CONFIG_FSCACHE) ctx->cache = NULL; #endif