From patchwork Thu Dec 21 13:23:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 182230 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp412452dyi; Thu, 21 Dec 2023 05:34:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8CcLbhljYUEyczpy5FwKO0kld/xbXnG9J8kQ7dOKyLSFxIi8OO10b9nnNU6Sb1NLm4ldj X-Received: by 2002:a05:6808:398e:b0:3bb:72f9:86d6 with SMTP id gq14-20020a056808398e00b003bb72f986d6mr3518565oib.106.1703165688649; Thu, 21 Dec 2023 05:34:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703165688; cv=none; d=google.com; s=arc-20160816; b=c8YYCxnTvTgEd6LTHARXIs+PZpIetiWJBLOZC8faeu87CYk220Z5detJm7xCYfrnsC 5Gn9COl7jjgnGn4dXeeL7qzNPj8Bs5ey+DfexLghiZOXkX1545khgWd1Yv5TGLXYYWVL ziOhKpVKDkUwCY95xnVgF8Qzmg/opsVdyRxlYeMXXwnxS6OoCh4ZuOJDvW96QyIBBYsX EL1ZgbQPvtLH3FPDTe7dCQkG+1dh3ovtsa4BGvgGD4KY8T3Oj5sRRK1PlDG9AUJV+Rf4 aMq4aQv4K/MLJC0NB7SrzHsThdGZQpolnxZ2FG1cVKkITxXbT+3oGnVKzVWIMQRSa600 8kDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gAK2p2qAWIcg9pxgbQQ97/VBoelCZmAI70KqBDTKmoo=; fh=ib4gl95HfLmZdfX9QIMf3rTepWCH9JlNymcDKJTPhJg=; b=nwJxUJt6dpzLfetd+4Hy9UIH3bdhR3oEaky9dv/TfnUhgN3Y1cPkgS6RB7+eWIDHFY 8iOk3W6W7rjqaqmcrxjAxdtBFv4vTopxBX4tPYJnjpMc1d/HussZS+EMntn5OBYPylQt tfUsN9sZPQPY0gU6NZ6QJz2mM1x5I9A9sHijHVvIvQx95ObjTOs67j+yhcsAAm/cWSI6 7KC8jWcZ4eQ9Dcul/ZaTNmKxPwU13IjTY0E4P9LQOGC/JtJnD3/WZ2ljoyYxpfVxdeye wjqQBDIkb0pLcJPaArRNBDQYj0pnOJ8wTwXR3KJi28OsjwCfPRvuEOWddY5+LV4XOWZH /Nwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NGJxW77L; spf=pass (google.com: domain of linux-kernel+bounces-8463-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8463-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id r16-20020a0cb290000000b0067f27bdede5si2052932qve.87.2023.12.21.05.34.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 05:34:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8463-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NGJxW77L; spf=pass (google.com: domain of linux-kernel+bounces-8463-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8463-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4888A1C21A86 for ; Thu, 21 Dec 2023 13:34:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71FBD76DB0; Thu, 21 Dec 2023 13:25:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NGJxW77L" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6078C7E78D for ; Thu, 21 Dec 2023 13:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703165117; 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=gAK2p2qAWIcg9pxgbQQ97/VBoelCZmAI70KqBDTKmoo=; b=NGJxW77L/MsYNpQIUEx5y1JG4z8fOVfxhkRAR2QuZK0TUY1+ovl0XwNH1sg0kDx/kL8UQa PeUOdZuhjyQwh9u1Fw15M54QSlUnzg9F9EGomFi7C0d/kiMwYW1u7hDurHdIT/fvhnlDLD dquRO+3NDlVP8POfIiyqS/gccPO50ZI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-139-gV0Lbc_QMBi7LTGmGAIj8w-1; Thu, 21 Dec 2023 08:25:15 -0500 X-MC-Unique: gV0Lbc_QMBi7LTGmGAIj8w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 3FBCF280D471; Thu, 21 Dec 2023 13:25:14 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.39.195.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 585BD2166B31; Thu, 21 Dec 2023 13:25:11 +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 v5 18/40] netfs: Limit subrequest by size or number of segments Date: Thu, 21 Dec 2023 13:23:13 +0000 Message-ID: <20231221132400.1601991-19-dhowells@redhat.com> In-Reply-To: <20231221132400.1601991-1-dhowells@redhat.com> References: <20231221132400.1601991-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785898664951112922 X-GMAIL-MSGID: 1785898664951112922 Limit a subrequest to a maximum size and/or a maximum number of contiguous physical regions. This permits, for instance, an subreq's iterator to be limited to the number of DMA'able segments that a large RDMA request can handle. Signed-off-by: David Howells Reviewed-by: Jeff Layton cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/netfs/io.c | 18 ++++++++++++++++++ include/linux/netfs.h | 1 + include/trace/events/netfs.h | 1 + 3 files changed, 20 insertions(+) diff --git a/fs/netfs/io.c b/fs/netfs/io.c index e9d408e211b8..e228bfb530ea 100644 --- a/fs/netfs/io.c +++ b/fs/netfs/io.c @@ -525,6 +525,7 @@ netfs_rreq_prepare_read(struct netfs_io_request *rreq, struct iov_iter *io_iter) { enum netfs_io_source source; + size_t lsize; _enter("%llx-%llx,%llx", subreq->start, subreq->start + subreq->len, rreq->i_size); @@ -547,13 +548,30 @@ netfs_rreq_prepare_read(struct netfs_io_request *rreq, source = NETFS_INVALID_READ; goto out; } + + if (subreq->max_nr_segs) { + lsize = netfs_limit_iter(io_iter, 0, subreq->len, + subreq->max_nr_segs); + if (subreq->len > lsize) { + subreq->len = lsize; + trace_netfs_sreq(subreq, netfs_sreq_trace_limited); + } + } } + if (subreq->len > rreq->len) + pr_warn("R=%08x[%u] SREQ>RREQ %zx > %zx\n", + rreq->debug_id, subreq->debug_index, + subreq->len, rreq->len); + if (WARN_ON(subreq->len == 0)) { source = NETFS_INVALID_READ; goto out; } + subreq->source = source; + trace_netfs_sreq(subreq, netfs_sreq_trace_prepare); + subreq->io_iter = *io_iter; iov_iter_truncate(&subreq->io_iter, subreq->len); iov_iter_advance(io_iter, subreq->len); diff --git a/include/linux/netfs.h b/include/linux/netfs.h index 41d438e5d6db..2ece21fccb02 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -161,6 +161,7 @@ struct netfs_io_subrequest { refcount_t ref; short error; /* 0 or error that occurred */ unsigned short debug_index; /* Index in list (for debugging output) */ + unsigned int max_nr_segs; /* 0 or max number of segments in an iterator */ enum netfs_io_source source; /* Where to read from/write to */ unsigned long flags; #define NETFS_SREQ_COPY_TO_CACHE 0 /* Set if should copy the data to the cache */ diff --git a/include/trace/events/netfs.h b/include/trace/events/netfs.h index beec534cbaab..fce6d0bc78e5 100644 --- a/include/trace/events/netfs.h +++ b/include/trace/events/netfs.h @@ -44,6 +44,7 @@ #define netfs_sreq_traces \ EM(netfs_sreq_trace_download_instead, "RDOWN") \ EM(netfs_sreq_trace_free, "FREE ") \ + EM(netfs_sreq_trace_limited, "LIMIT") \ EM(netfs_sreq_trace_prepare, "PREP ") \ EM(netfs_sreq_trace_resubmit_short, "SHORT") \ EM(netfs_sreq_trace_submit, "SUBMT") \