From patchwork Fri Oct 13 16:03:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13421157 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 9D46DCDB47E for ; Fri, 13 Oct 2023 16:05:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEFDA6B0185; Fri, 13 Oct 2023 12:05:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA0726B0186; Fri, 13 Oct 2023 12:05:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1A466B0187; Fri, 13 Oct 2023 12:05:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B2EA46B0185 for ; Fri, 13 Oct 2023 12:05:27 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8A087C03D2 for ; Fri, 13 Oct 2023 16:05:27 +0000 (UTC) X-FDA: 81340913094.29.6C49DCE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id A020E1C0002 for ; Fri, 13 Oct 2023 16:05:25 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ex3vNT+U; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1697213125; 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=My5vhPID0cGh8dfo8fU6SjTEUwiUM3vyJnExzTG3s6g=; b=xAXWQ4Y66xAMM6G2obssVJ8SuHtSS83r+LJwKJa7A9UXpqP1iZFD/9elP1onZ2Nnh8p8zB IPOzaxo9+NS+ShqGkJd85THd8/DDs5B95hUhty1lalOZ12ydYcHSdZd89/EYgfRZfOxD7O KnKOybpHHfj4e5fm+aZytY6Zeug/g0g= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ex3vNT+U; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697213125; a=rsa-sha256; cv=none; b=EV5LfcKJgLr63Pe2c7Tfm4q6ifYrLIebN8qmbicpoU/rCsEgq+peRFeB0zoPeLYLUnEB6c Fjdbf3rFswN6h3k3BXQVG4Eveebf09FM0DJ8TJNpuK1nh/RwnfabhmNGYfKWKBB5lzJpfS BGNq506vhWsHp251hiZVXWCagoFDZr8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697213124; 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=My5vhPID0cGh8dfo8fU6SjTEUwiUM3vyJnExzTG3s6g=; b=Ex3vNT+UAeISDW0/sbwQvcT6Sj44AlnwlummkG2/0WvlvQF0BOZ2uOKFIih81M+B3bv8A3 U3PUXgokWbDU54t9cthQBwdLuv9re0quB8Jv0LeCcq0KE6Gxrg4yiEFWJcacrbnoeHaNCe R3teWOLATFxo/0CRWoV9TS3EiJo5mtI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-161-UOB1c2_XOhGlcUUO4m1fqg-1; Fri, 13 Oct 2023 12:05:18 -0400 X-MC-Unique: UOB1c2_XOhGlcUUO4m1fqg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 5743E382333F; Fri, 13 Oct 2023 16:05:17 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAF5040C6CA5; Fri, 13 Oct 2023 16:05:14 +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 15/53] netfs: Limit subrequest by size or number of segments Date: Fri, 13 Oct 2023 17:03:44 +0100 Message-ID: <20231013160423.2218093-16-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.2 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A020E1C0002 X-St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kUYO1YBqMAesCC436uV9QQkDAbuOH48zDiuqz3ILjgWmIbOpahVr7N3vf+1dUtrno1UvH55OJLnOIKL23UwSoxLGqZFxvVi+f3H4GQTEvBLJ5IZsZBbhjSdBpwgtpl3apJu92PcVBA8ogQBRRcnKI7Zy1g9K9yrLndI1uazoJ1+Fs2o7BGhsVJqELfFRRgnZ3B6i5S/ItX6lOQBfjjRIlLNRaw64XS7IvtgGPr2bo400tvCoIUk+os4ohD2yfCbcUU+rOZASWlYxHaI6nObKL5Wj1T9mmkC3k9U+/+ziuVi8= 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: 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 cc: 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 d8e9cd6ce338..c80b8eed1209 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 2b5e04ea4db2..aaf1c1d4de51 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -163,6 +163,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") \