From patchwork Fri Oct 13 15:56:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13421066 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 18492C41513 for ; Fri, 13 Oct 2023 15:57:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A9138D0165; Fri, 13 Oct 2023 11:57:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70B848D0015; Fri, 13 Oct 2023 11:57:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55DD58D0165; Fri, 13 Oct 2023 11:57:48 -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 402D58D0015 for ; Fri, 13 Oct 2023 11:57:48 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E5DB61202E5 for ; Fri, 13 Oct 2023 15:57:47 +0000 (UTC) X-FDA: 81340893774.09.96DEBDC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 3EBAB180022 for ; Fri, 13 Oct 2023 15:57:46 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LX5qOz7s; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.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=1697212666; 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=ybL5Z84E2MKfw9/KPwUGR/SMS/5stuqwlJ261jfXYyg=; b=JYH774hZkIAwnHhuMctrlnAO7o33PJ7BRn5NALsmIVvUEzBLLxH+qnpDtBEqDCYqdBWqrI S4YoJPvYKzPuOCkwP1uBLHByOAFD+W2s5xSn8Qv8fya0biH4b7E6mPEBVxGbgF8gZoR1sy gx/0NPC7e2LV8Xx8RkqWdwh5yekJp0U= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LX5qOz7s; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.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=1697212666; a=rsa-sha256; cv=none; b=Xja4zSZlIc/LzdUY4KVPVDSCjXvdmcbfk3+jBdUPJNHQFmos6MFBEhyD0x9PmDpHBMjJwa jzBgk9sPrfdjm077nG80rrMkCcz2DhZ4OgvbkcBCjRDUgcr+q6p/QWwOZf4Bav5/W/v9/o A/lAhpskL++a/gFq96eJNJs4eM6mevA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697212665; 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=ybL5Z84E2MKfw9/KPwUGR/SMS/5stuqwlJ261jfXYyg=; b=LX5qOz7sWtaDh5wudt+NVUMQjlseMWJbXX/mS/BuH6m9fU0/ZT50KCvnm+8XoFPCNtdEDf SBraSJAmCPFA+3sdniRFiyeryeWnsC6+L66a6byktrVX4bj0rcOCcDU4wsBKhtEkr30A6m wu55lQdo2tquHMlExdOCOYdMrfJ07Sw= 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-216-M9f1MTH9Nyy4xEZUXNXggw-1; Fri, 13 Oct 2023 11:57:40 -0400 X-MC-Unique: M9f1MTH9Nyy4xEZUXNXggw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 EFB55862DFD; Fri, 13 Oct 2023 15:57:38 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4664425C0; Fri, 13 Oct 2023 15:57:36 +0000 (UTC) From: David Howells To: Jeff Layton , Steve French Cc: David Howells , Matthew Wilcox , Marc Dionne , Paulo Alcantara , Ronnie Sahlberg , 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 02/53] netfs: Track the fpos above which the server has no data Date: Fri, 13 Oct 2023 16:56:35 +0100 Message-ID: <20231013155727.2217781-3-dhowells@redhat.com> In-Reply-To: <20231013155727.2217781-1-dhowells@redhat.com> References: <20231013155727.2217781-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Rspamd-Queue-Id: 3EBAB180022 X-Rspam-User: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exePs7+Lg1FoYrRaRKBIIXgXuuhfTcs5nw8nAtCrHtwp9X32IsnXmsL3MHzCIfld4tRK8owBdhhUvbhfzipa811INMYMqAHPduFrZkYpIcty1NYyrvUIrFPM+gojCFKZOFrC1DUBsPL3ZQj0yQJNB7lpULMCVXhEOTeTUQNp0BPSNVtexT1FYWM+j4x8GmjDnvr9toGVIOKCkqEYWeimfAFt4Ck5jgvrGjcHonelNlZLgSnyfMZYCM76RHmOlK6vB6fRWD3tBqm+NjmVvgNmeflNMKS5DoA= 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: Track the file position above which the server is not expected to have any data and preemptively assume that we can simply fill blocks with zeroes locally rather than attempting to download them - even if we've written data back to the server. Assume that any data that was written back above that position is held in the local cache. Call this the "zero point". Make use of this to optimise away some reads from the server. We need to set the zero point in the following circumstances: (1) When we see an extant remote inode and have no cache for it, we set the zero_point to i_size. (2) On local inode creation, we set zero_point to 0. (3) On local truncation down, we reduce zero_point to the new i_size if the new i_size is lower. (4) On local truncation up, we don't change zero_point. (5) On local modification, we don't change zero_point. (6) On remote invalidation, we set zero_point to the new i_size. (7) If stored data is culled from the local cache, we must set zero_point above that if the data also got written to the server. (8) If dirty data is written back to the server, but not the local cache, we must set zero_point above that. Assuming the above, any read from the server at or above the zero_point position will return all zeroes. The zero_point value can be stored in the cache, provided the above rules are applied to it by any code that culls part of the local cache. 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/afs/inode.c | 13 +++++++------ fs/netfs/buffered_read.c | 40 +++++++++++++++++++++++++--------------- include/linux/netfs.h | 5 +++++ 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/fs/afs/inode.c b/fs/afs/inode.c index 1c794a1896aa..46bc5574d6f5 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -252,6 +252,7 @@ static void afs_apply_status(struct afs_operation *op, vnode->netfs.remote_i_size = status->size; if (change_size) { afs_set_i_size(vnode, status->size); + vnode->netfs.zero_point = status->size; inode_set_ctime_to_ts(inode, t); inode->i_atime = t; } @@ -865,17 +866,17 @@ static void afs_setattr_success(struct afs_operation *op) static void afs_setattr_edit_file(struct afs_operation *op) { struct afs_vnode_param *vp = &op->file[0]; - struct inode *inode = &vp->vnode->netfs.inode; + struct afs_vnode *vnode = vp->vnode; if (op->setattr.attr->ia_valid & ATTR_SIZE) { loff_t size = op->setattr.attr->ia_size; loff_t i_size = op->setattr.old_i_size; - if (size < i_size) - truncate_pagecache(inode, size); - if (size != i_size) - fscache_resize_cookie(afs_vnode_cache(vp->vnode), - vp->scb.status.size); + if (size != i_size) { + truncate_pagecache(&vnode->netfs.inode, size); + netfs_resize_file(&vnode->netfs, size); + fscache_resize_cookie(afs_vnode_cache(vnode), size); + } } } diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c index 2cd3ccf4c439..a2852fa64ad0 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -147,6 +147,22 @@ static void netfs_rreq_expand(struct netfs_io_request *rreq, } } +/* + * Begin an operation, and fetch the stored zero point value from the cookie if + * available. + */ +static int netfs_begin_cache_operation(struct netfs_io_request *rreq, + struct netfs_inode *ctx) +{ + int ret = -ENOBUFS; + + if (ctx->ops->begin_cache_operation) { + ret = ctx->ops->begin_cache_operation(rreq); + /* TODO: Get the zero point value from the cache */ + } + return ret; +} + /** * netfs_readahead - Helper to manage a read request * @ractl: The description of the readahead request @@ -180,11 +196,9 @@ void netfs_readahead(struct readahead_control *ractl) if (IS_ERR(rreq)) return; - if (ctx->ops->begin_cache_operation) { - ret = ctx->ops->begin_cache_operation(rreq); - if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS) - goto cleanup_free; - } + ret = netfs_begin_cache_operation(rreq, ctx); + if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS) + goto cleanup_free; netfs_stat(&netfs_n_rh_readahead); trace_netfs_read(rreq, readahead_pos(ractl), readahead_length(ractl), @@ -238,11 +252,9 @@ int netfs_read_folio(struct file *file, struct folio *folio) goto alloc_error; } - if (ctx->ops->begin_cache_operation) { - ret = ctx->ops->begin_cache_operation(rreq); - if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS) - goto discard; - } + ret = netfs_begin_cache_operation(rreq, ctx); + if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS) + goto discard; netfs_stat(&netfs_n_rh_readpage); trace_netfs_read(rreq, rreq->start, rreq->len, netfs_read_trace_readpage); @@ -390,11 +402,9 @@ int netfs_write_begin(struct netfs_inode *ctx, rreq->no_unlock_folio = folio_index(folio); __set_bit(NETFS_RREQ_NO_UNLOCK_FOLIO, &rreq->flags); - if (ctx->ops->begin_cache_operation) { - ret = ctx->ops->begin_cache_operation(rreq); - if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS) - goto error_put; - } + ret = netfs_begin_cache_operation(rreq, ctx); + if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS) + goto error_put; netfs_stat(&netfs_n_rh_write_begin); trace_netfs_read(rreq, pos, len, netfs_read_trace_write_begin); diff --git a/include/linux/netfs.h b/include/linux/netfs.h index b447cb67f599..282511090ead 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -129,6 +129,8 @@ struct netfs_inode { struct fscache_cookie *cache; #endif loff_t remote_i_size; /* Size of the remote file */ + loff_t zero_point; /* Size after which we assume there's no data + * on the server */ }; /* @@ -330,6 +332,7 @@ static inline void netfs_inode_init(struct netfs_inode *ctx, { ctx->ops = ops; ctx->remote_i_size = i_size_read(&ctx->inode); + ctx->zero_point = ctx->remote_i_size; #if IS_ENABLED(CONFIG_FSCACHE) ctx->cache = NULL; #endif @@ -345,6 +348,8 @@ static inline void netfs_inode_init(struct netfs_inode *ctx, static inline void netfs_resize_file(struct netfs_inode *ctx, loff_t new_i_size) { ctx->remote_i_size = new_i_size; + if (new_i_size < ctx->zero_point) + ctx->zero_point = new_i_size; } /**