Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp804973rdb; Fri, 17 Nov 2023 13:19:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbFlhBIAFHsdyX5Y7kGT27vyjXBIVYQu3md/Qcxjid+d6URHwNqHZHpBtEf9+ytUqjOmP4 X-Received: by 2002:a05:6a21:3603:b0:189:b1aa:a283 with SMTP id yg3-20020a056a21360300b00189b1aaa283mr330948pzb.3.1700255978476; Fri, 17 Nov 2023 13:19:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700255978; cv=none; d=google.com; s=arc-20160816; b=xv7ElqFoOxCKLGkgh0U680rBucvay6xKFNXo18AAM0i6swvigNX76ySb4o9VKyjoCs mKxB5w+m2JyTCiEQs/qVfqjDyz98ccfq05YbvDqUf9js1kSVN/v5QpDS2nMu9rjSM6xT dIONCG42iSu+pLH8GBAPbFrPfILBZSURXYwoGrG3ZYtkNdtgBLm0UaiB1/GblBdBHEC5 K1QBDeJkTHiLKvVcRjKzYe6HJZAmcOQYPAAP0VNUVTffCF5tP8cImx8jyR3zwrQY3PKa aQSULf5Jy4BMDASLVCnIPz6xPJJV9UAoWsCIKMQkjFptbjW9QMJ+T10PtCN55sjpClSO wnGw== 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=ablsJdTiyO2NAigj2ijcrkqA9EUIfyGm7/v4HJQaeAo=; fh=lVY/c7gYUTDnyYYKKvGQU3Q29dA69hck6eN/HP5dBQ0=; b=BjhUsAGjugZIWbb+3cC/te3VjG7SRY5/9xOpVhqZHL/1TybKDHDhUCZ80yPg5NTgNw HLpppTYnoNT2T6fTXM1HmgobmaekAAiHEFsRrv0mev9yfSgeJDkKHaXwXjIQfTpt2L6z NGWvIMFAsrM7mQeQ+EfsyTcxTwCDExd34+uI/Vu6fvWZU4hXQevqdM3fjN9fh75Iyp1k uUztmHditVhllCpae1/BP0MFeiBnaQewemhxf7s7P21XM2OWVzwKbUj6kie8leetSM6X kbfGC8vbqiqWMf0Z0gf2rRzj6+dRmJ03RoovS7r42JR9vRZ+nqR+9C/BoOg7VgxtNWR/ qWYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IajUhQQn; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id ix3-20020a170902f80300b001c589ba4a04si2394513plb.24.2023.11.17.13.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 13:19:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IajUhQQn; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8329182C92DF; Fri, 17 Nov 2023 13:19:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235859AbjKQVTh (ORCPT + 99 others); Fri, 17 Nov 2023 16:19:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346253AbjKQVTT (ORCPT ); Fri, 17 Nov 2023 16:19:19 -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 C1697173A for ; Fri, 17 Nov 2023 13:18:02 -0800 (PST) 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=ablsJdTiyO2NAigj2ijcrkqA9EUIfyGm7/v4HJQaeAo=; b=IajUhQQnLL+B/7O9sbM0nwpZZ2clFWdAA6SeqxE3pLO2xc1fI9fzppz9xY1/DKQ4FJ5rV1 wmHZOkJBDoMpotAdVtNVgDkOpo355pfAqIBgPnOn+NlEauImbbrXxwgXdJUHCbZeDwGQ1N ergrtEuOTWL2h6Q8JXFd6i1wKEIw1jQ= 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-588-pglnLLpXNf-TX_OTm7-ryQ-1; Fri, 17 Nov 2023 16:17:54 -0500 X-MC-Unique: pglnLLpXNf-TX_OTm7-ryQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 582C1185A78E; Fri, 17 Nov 2023 21:17:53 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id B99B6492BFD; Fri, 17 Nov 2023 21:17:50 +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 31/51] netfs: Provide minimum blocksize parameter Date: Fri, 17 Nov 2023 21:15:23 +0000 Message-ID: <20231117211544.1740466-32-dhowells@redhat.com> In-Reply-To: <20231117211544.1740466-1-dhowells@redhat.com> References: <20231117211544.1740466-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 17 Nov 2023 13:19:37 -0800 (PST) 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 097086d75d1c..4f0feedb357a 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 02a8ddddc8cd..cb80de66d165 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 */ }; /* @@ -463,6 +464,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