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: 56304 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2372313wrn; Mon, 13 Feb 2023 06:22:29 -0800 (PST) X-Google-Smtp-Source: AK7set/1PQJnX67aT9wAAQqFEQaK9G5gL3rm8S7ZGum9E5e2A3lhpC6zlUxz3VXDtgIh+kLT9XvV X-Received: by 2002:a50:d085:0:b0:4ab:1681:b99e with SMTP id v5-20020a50d085000000b004ab1681b99emr7122451edd.4.1676298149671; Mon, 13 Feb 2023 06:22:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676298149; cv=none; d=google.com; s=arc-20160816; b=hBrkd9nj23pKekN9pBbsHxjZZkYsR2rFXZBERQVXe9nZwHdMCkmeQlH0ic3Uv8GoGj 1M+zGot2O05ZExtjfXrSa+hgCjbIYUZ5ePWTSHVc92zE1icz9vPNc6qnfuynqM/U5uCm DyA/7Kbne8UXIJijNxMlcsZEDbmTvUPuLnV/vsspo49MgpSsigOabxJDPo7U1apdg4dG JqQPEBgqF88mmn8Gef8qL4VC1Ly1ZMd4QT/0NLgHfM4hY6mUNHCArKiNJwAHO3lgLxtg b8PFyAScWsH7s5mpBQPvoWbGCFbZ7vH783/9veNgcUfqB091gB+vRd/Fp1pFsyf6Kav2 vh5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Nvl8+FROX68UViRruMCdGgXgWsaTBkOPXdZwOet0pQY=; b=KNFvuKshCGdvm/GVuzkFr4qkSl1MNYSod76Pu/ICI8Dj6P2epNbtNaji/rUzbrpwrH wQ600uH1DSvFzWdXOjyFCkNZgwwssapC9zE/zCFTAxpsZ00bjASrx5KlhdDBVjzPKYHG HEuem4Y0sw6eF25EYcRh+Ix0UfPGQxxKPV647M1xyPWSlvaPtd04s7ZRi2G5cfhTxUwK joH01IvtekKOckQXrxmEYVma4C1QNY6nh4Z3xhuvWR05IUsE64PDFIPZdI7cEg0vYQ4a xjnosQLR8/PExkBCdBEtR/LdiyJDRiQiJPenM31ZQ1rZ+sbTsnLj5JkQZyMEpP4Gw6Xz AHHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aCgPqUc8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a056402128400b004acc613462asi4283381edv.78.2023.02.13.06.22.06; Mon, 13 Feb 2023 06:22:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aCgPqUc8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230374AbjBMNsK (ORCPT + 99 others); Mon, 13 Feb 2023 08:48:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230285AbjBMNsB (ORCPT ); Mon, 13 Feb 2023 08:48:01 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50B051ADE7 for ; Mon, 13 Feb 2023 05:46:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676295992; 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=aCgPqUc8cO2iel1mn9sznB0epdXZxv6FMa98KT7yVPkmqEDDe2aBIuUQnKbVww6BhDjI2Y mx7vO4MBdyUnveiI6XoMTPjtgLlr/rywivoYFNiGGfF4tlZ6IJJ1IAGk1mAkqPSOyW5LaQ jGOzT98gJbXwuqZ5s8BMpad4MsFeoEc= 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757726008763793317?= X-GMAIL-MSGID: =?utf-8?q?1757726008763793317?= 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