From patchwork Mon Feb 13 15:32:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13138594 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 6D417C636D4 for ; Mon, 13 Feb 2023 15:33:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E16516B0072; Mon, 13 Feb 2023 10:33:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DC6AD6B0073; Mon, 13 Feb 2023 10:33:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C40AC6B0075; Mon, 13 Feb 2023 10:33:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B6B8A6B0072 for ; Mon, 13 Feb 2023 10:33:17 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7E787140ACD for ; Mon, 13 Feb 2023 15:33:17 +0000 (UTC) X-FDA: 80462662434.23.4928A20 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id B47C640015 for ; Mon, 13 Feb 2023 15:33:14 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bROk5I38; spf=pass (imf17.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676302394; 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=+b2VMeGpZTyrheqYPKTaHyxDIQ3yZeSE4YqjD4ZyLaI=; b=MmO9SsRg74bqQfDTMB1PsjuDm3W4cBGc1pBiuABIC6Fg1BT3ZS1DPvcxXio9EMq2PC5AUj MOJMrUSnMiCXDCwh3wPPs54eNJpWNp+ajHQfWaK0j8somDJabFKcswpCcUvmbFa0xASLWQ 7K9GzSqTJdzajrAFk6T5fIvRAPadJFs= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bROk5I38; spf=pass (imf17.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676302394; a=rsa-sha256; cv=none; b=PQt2FnmRUcMq6/hbOLR4KdH1DenlSmhVcGMyrMSF22Q/8Luxj+Ly3l2q2mRkaTf6nUuZd9 TYXD89D+qzXZwnNxLH8c/Kfe851h6/HNWa5WcC7uazy+/QUdxJEwAzOTeQqAck6KiSkxRW RhLDyeWU3z/hF9YketMF+gQAUx3G/og= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676302394; 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=+b2VMeGpZTyrheqYPKTaHyxDIQ3yZeSE4YqjD4ZyLaI=; b=bROk5I38MxWfcu2/jKSpA5AxcqLhtr81RY8yNdAMryHcu4McOVz+ThxAOpV47Vgjewvc6N BVhPW7DLjWXmLR5s2dRI0Ma4sDirrDvqZGx6dV4LLaU1x3iNF5JtZL8ggxJy0G6gkvxJGz T1F/ghiloFmAVPcK3LULFEJobeVftqQ= 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-256-1ODbYshqMwmxxNEz7syx6g-1; Mon, 13 Feb 2023 10:33:12 -0500 X-MC-Unique: 1ODbYshqMwmxxNEz7syx6g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ACFD985A588; Mon, 13 Feb 2023 15:33:11 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCD6240B40C9; Mon, 13 Feb 2023 15:33:09 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v2 2/4] splice: Provide pipe_head_buf() helper Date: Mon, 13 Feb 2023 15:32:59 +0000 Message-Id: <20230213153301.2338806-3-dhowells@redhat.com> In-Reply-To: <20230213153301.2338806-1-dhowells@redhat.com> References: <20230213153301.2338806-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B47C640015 X-Rspam-User: X-Stat-Signature: ac3mhnqkjq1oifs13hqhnfqs673f4gk3 X-HE-Tag: 1676302394-676713 X-HE-Meta: U2FsdGVkX18m690MCrW5Acb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TfRYN7thaSVZC+kaOKGCtjPb/wNoaSuX92mqP8lVctTWTkMlBPYQvIUgQsGoVMGldVzmjnMr+MevHyTIKKPX4tWmO9IpgihmHOpQRT4xA89pb2XxUlIKMGN82ZNe+QCjYRj9xodQ61glY3sAmw9CoiE3mKeqUpzUfHgwSqWoQSoIked3hvAXTYEMxyTxfJWbOICTiUY0iVqTZG/OL7JBOmU/Gyso5+31DGufQOxWBkVjEFN0QeClwamodY3yS5FBgDEP6VRm99fFFtPTRj+Iydzc8PPEK5DzQxOxc+csKUpKhTxoOhNiox8FklVlvdeG2xAJaJPaibt9KtcPAJ3XaYRQK1FUiqcnG8mtM05gMSBdpSGHIKjBS6egQROiuOoIBMDQ== 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: Provide a helper, pipe_head_buf(), to get the current head buffer from a pipe. Implement this as a wrapper around a more general function, pipe_buf(), that gets a specified buffer. Requested-by: Christoph Hellwig Signed-off-by: David Howells Reviewed-by: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org Reviewed-by: David Hildenbrand --- fs/splice.c | 9 +++------ include/linux/pipe_fs_i.h | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 91b9e2cb9e03..7c0ff187f87a 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -295,7 +295,6 @@ static ssize_t direct_splice_read(struct file *in, loff_t *ppos, struct bio_vec *bv; struct kiocb kiocb; struct page **pages; - unsigned int head; ssize_t ret; size_t used, npages, chunk, remain, reclaim; int i; @@ -358,9 +357,8 @@ static ssize_t direct_splice_read(struct file *in, loff_t *ppos, } /* Push the remaining pages into the pipe. */ - head = pipe->head; for (i = 0; i < npages; i++) { - struct pipe_buffer *buf = &pipe->bufs[head & (pipe->ring_size - 1)]; + struct pipe_buffer *buf = pipe_head_buf(pipe); chunk = min_t(size_t, remain, PAGE_SIZE); *buf = (struct pipe_buffer) { @@ -369,10 +367,9 @@ static ssize_t direct_splice_read(struct file *in, loff_t *ppos, .offset = 0, .len = chunk, }; - head++; + pipe->head++; remain -= chunk; } - pipe->head = head; kfree(bv); return ret; @@ -394,7 +391,7 @@ static size_t splice_folio_into_pipe(struct pipe_inode_info *pipe, while (spliced < size && !pipe_full(pipe->head, pipe->tail, pipe->max_usage)) { - struct pipe_buffer *buf = &pipe->bufs[pipe->head & (pipe->ring_size - 1)]; + struct pipe_buffer *buf = pipe_head_buf(pipe); size_t part = min_t(size_t, PAGE_SIZE - offset, size - spliced); *buf = (struct pipe_buffer) { diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h index 6cb65df3e3ba..d2c3f16cf6b1 100644 --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h @@ -156,6 +156,26 @@ static inline bool pipe_full(unsigned int head, unsigned int tail, return pipe_occupancy(head, tail) >= limit; } +/** + * pipe_buf - Return the pipe buffer for the specified slot in the pipe ring + * @pipe: The pipe to access + * @slot: The slot of interest + */ +static inline struct pipe_buffer *pipe_buf(const struct pipe_inode_info *pipe, + unsigned int slot) +{ + return &pipe->bufs[slot & (pipe->ring_size - 1)]; +} + +/** + * pipe_head_buf - Return the pipe buffer at the head of the pipe ring + * @pipe: The pipe to access + */ +static inline struct pipe_buffer *pipe_head_buf(const struct pipe_inode_info *pipe) +{ + return pipe_buf(pipe, pipe->head); +} + /** * pipe_buf_get - get a reference to a pipe_buffer * @pipe: the pipe that the buffer belongs to