From patchwork Mon Feb 13 13:46:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13138462 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 DB439C636CC for ; Mon, 13 Feb 2023 13:46:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 765406B007E; Mon, 13 Feb 2023 08:46:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EF0B6B0080; Mon, 13 Feb 2023 08:46:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 567F96B0081; Mon, 13 Feb 2023 08:46:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 453A56B007E for ; Mon, 13 Feb 2023 08:46:33 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1ECCD140837 for ; Mon, 13 Feb 2023 13:46:33 +0000 (UTC) X-FDA: 80462393466.12.1A483C4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 4EEC7180014 for ; Mon, 13 Feb 2023 13:46:31 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DzyYmZM7; spf=pass (imf16.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1676295991; 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=Nvl8+FROX68UViRruMCdGgXgWsaTBkOPXdZwOet0pQY=; b=b8pm9J94qdOaIZHs4/DcCV+IjgbLg+1Fvq6SB5oLOIP3AQPojJUat844mEz6CDQwfRRzek R4VQozBtQ8EK1fLlUlKp11TvQvrGTb1L1MpBkj44rrbT2Qbqcm3prWhG7Vrb8037rpFDLH MdhzDeegE1qbvbJN6lJAynegoH38oYE= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DzyYmZM7; spf=pass (imf16.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1676295991; a=rsa-sha256; cv=none; b=Ec20/pwPL5g9aM+nTHMKHBFxAZw9QWLH6RYaxPhwqrdDjIgarawqlf+3krCs9N43p7Mk08 Vyrjdwrko4kUkdMvawTAhBEyhuZyPHMoTGI9MgwhUH88pqj/Vw794HdzHgYV4Vl3cVGXTj 2pFGeEVP9k9hEZ9jvCMT8Rzv7IrX16o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676295990; 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=Nvl8+FROX68UViRruMCdGgXgWsaTBkOPXdZwOet0pQY=; b=DzyYmZM74Xa7+yN8FBQiq5tm800tOPBn57rI2/ZwVm+tcnFORAKodLzTBih2HDjoV8fX/P OgkoZpN3oAokXigNOQ6LtUYwMi8xHIVCVCk3wAJN9+6v2LGvLXj/GUTKCKxZSoo5Hc+cu1 ZK3D5agMqwKDU7e5KUdhT4OVFsYdkXE= 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-447-Qzx4kRCYOYyoMJ2DNcD_ow-1; Mon, 13 Feb 2023 08:46:29 -0500 X-MC-Unique: Qzx4kRCYOYyoMJ2DNcD_ow-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A0EAF857AA4; Mon, 13 Feb 2023 13:46:28 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5926C16022; Mon, 13 Feb 2023 13:46:26 +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 2/4] splice: Provide pipe_head_buf() helper Date: Mon, 13 Feb 2023 13:46:17 +0000 Message-Id: <20230213134619.2198965-3-dhowells@redhat.com> In-Reply-To: <20230213134619.2198965-1-dhowells@redhat.com> References: <20230213134619.2198965-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4EEC7180014 X-Stat-Signature: s3p4yfrdbw6owdaxk98wcirbrqqsxkpe X-HE-Tag: 1676295991-466627 X-HE-Meta: U2FsdGVkX19nkLAg+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RTYrR3SP9FCBCW31BjIj1z29J+1cZtHIPBY+wA2Np6ZTLi9kQNw28CXnGfxx4fJrYFcvTJK/CN3QR+JGj5MwZSH4hu6R9IzG9o1dqOcO3QBq7mODLOdT6nWuF+xCV5FkfHL+TQIWdhUvH2vpU8KGKJnX5zkDCdbxTTI6qwpj/OZSwrWR2wvJuAi6RRAEvHAsPYtag6XBNeWgT+Xh+IaKDWI/ub7y37xFXGkFhzDUitGlV/d5adksI9i+xkL9fG/mS824vcnEhsqF9JbVaXJnoj3NKaGBK0o4hqF+ktA7qLU0jNqKlovaKw6wPBe8X84DcHlXP0n/24Teud3qyAAB3P2qJv1xlDH+HeKy2Dca2x3F1zqdJinTxS4931E3tBB1s0z97XoCT6yxeUTpmIjW32w== 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 cc: 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: Christoph Hellwig --- 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