From patchwork Mon Feb 13 15:32:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13138595 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 4C53EC636CC for ; Mon, 13 Feb 2023 15:33:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 390266B0073; Mon, 13 Feb 2023 10:33:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 318146B0075; Mon, 13 Feb 2023 10:33:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B9106B0078; Mon, 13 Feb 2023 10:33:18 -0500 (EST) 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 DE6DB6B0075 for ; Mon, 13 Feb 2023 10:33:17 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 83ADDAA9F2 for ; Mon, 13 Feb 2023 15:33:17 +0000 (UTC) X-FDA: 80462662434.21.8491549 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id CAB1B40021 for ; Mon, 13 Feb 2023 15:33:14 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="bKkDQG/P"; spf=pass (imf07.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=jiirWQEzjOJm38ClQocxHDg9OYUUCbqX/zh69yaIxOk=; b=wectWNAXvpPn2jHgY+QRhYQLTjYxJ3o7rBWfhNtvTc9YhtVY7rjIGzs/Bf8FsfZ4YVVknj x/seCBt21S2PnJ1MMgahIBX7Puhh1Fv/jzcYIAqYpV6BHbdeZpaRl/POIYVtdQ0SF/i3Xd Z2AVRhGyCQW8+JHJA8beTslDXBPVkkc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="bKkDQG/P"; spf=pass (imf07.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=JdX9q1BL3XMUMnebUC3TO2wju2UhRzQXsML4bfYkol1MZsEBmE3GU7uArXNsN/yiBqXTEx AnpUpiqsGvGWpCuguxIQSfv53PjeY/mpD9mfa75COPXQSTTeoGlGO2+cJbQKrPPvJ+af1A axFyIwo2ieI5JSvdpXsAPZj1weTEM20= 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=jiirWQEzjOJm38ClQocxHDg9OYUUCbqX/zh69yaIxOk=; b=bKkDQG/PzppF28YOL69VGtZgW1XFhs3ZE3fPSbZYqpW+qlCUv+kXTeIe43dOUjKjbgGYRY rKyhyq/5PrRAF7mRhc0CW61O/pOc2ZhjXPDvFcGVQUaERmZogJkRV1Khvd60f5xVVgH7rU 63K3RqGMMCGEz+kq6fte+wHiGPHIrWM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.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-312-m02BLPiNNVOcc7akYvkMdA-1; Mon, 13 Feb 2023 10:33:09 -0500 X-MC-Unique: m02BLPiNNVOcc7akYvkMdA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 104AE1C04339; Mon, 13 Feb 2023 15:33:09 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1907918EC7; Mon, 13 Feb 2023 15:33:07 +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 1/4] splice: Rename new splice functions Date: Mon, 13 Feb 2023 15:32:58 +0000 Message-Id: <20230213153301.2338806-2-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.5 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: CAB1B40021 X-Stat-Signature: 5utyn9djn3s8jkcfyjkn7tw6yu7b6k4g X-HE-Tag: 1676302394-138013 X-HE-Meta: U2FsdGVkX18Jd31R8yQsD4kdHDs1e7UXxo4uLN1TO7YP+nUKulYSElA6o8AlXYqSCjiPBVjbcAqyY1DoL+d6Yy+LL7zO+AEaKC+lo4htt1Yj40IJdK2zj+IXnAr4LjmhdVMwNJl4oy96Dy8cfBDFxf8uEmtJ/HIYpF4jBXBbgnQq796hsKLPYIbmbinVh0p2+x2tlLkVovNZGWe5DEQeDszGKq2I0Qw+z1yRgy4fzCtbIhyU8oDwyZxukce5/09pmIP/jWcwu4lwTlDDQj9RuTaH4kSJZdl52kIqYPNt/gE0CdrImBhDXVG2AYL1pq5ph+wE2iDIWXlKRNTMzRD7SQxRz+077qOYL/fWdlR60DyVG3xfjlD1eVNV94CnViE5gCpwy88UD0tpe0zHrOLXXaKOxTSOzjqzYv2w2YVWZS5S9ewJbSwp1cZdHmFlQUTa442UhwTGvIaBNsGdmhZqF1KuC+zbSfy1wePGlxqyJBwt5G4ylzPB6+Bjk43eXB+wYxgMH6xQoOaIy91aIa70f+kgBFJBm/6xvbeI/XSNMdC/tLglPUaA1egLYwQSFaKA8OrTVeE2hjtWkp6MtaxguzWJf1uy86Qcbfpz8v4BkJAWZ+VnhuqOqr6UGZShyKHbxBql8KaNTdexED66qgUYki3kj96gWfr12TDfyUJ0i7YBW9l4dNf4vLhZ8d5owNapXIZcF+IeK+B8J3LyEtqM26hVRCt1vxzxDmoyLElF1VGHWkePZg79oF7Ym/X98vpiEyiJoMUH8gJX6TatlSabw5Kavhz8pkJAbyZpwiaVxrmhm1pea3GwrX2LCeRFWR7gPWi65fDX1mwMUnFgQF0y3gcc2b23535beGAwL2eL8qhalp8L3VPZ62WaxJeNWKGk04VWA1zo3l0EfEXJstmJ4ov+bhe3RQw3VV90VM2H7WSobUSQzINf4oYnuTzBvXJ7EdRoOc9F9SortuH+vCO HowFbZVa yWdp2e2yuERJf/FLeDMFuBcFI+mgYYW8aQ3XFaQlvgLay6XpsQgWTU6hTqR2eoGYvEhA/TsErDpnIuwmpP3mZTTE4q6SyU8j8ozgkYGMrV6x2NP5UXwpLk7bF7LdAkjoNNLb6Z77toeAoObbN1CZhMDInWDbXTiyrAnfK3j6sSrYXR0DDyWNe7hBqnzWgywzSKNPTcAYYUc0KMbfEJ5i9OayL7gUQ6cAKoV0iDqAtCJduAML5oUSUPOMP+5SYwiVZ8pIp7yXzlN80t8ibGdGhZB9eAsc3e5mHCoZEgbI4PimUk8/O4RTXcCA/C1KGUgVzwdlgc3y6tOyIlPvTWKB6ZcJqvAJRWfiB+STxN5NYCCkKhViH4zXrW31MLruBdC7fq+CrOB5g3ndo6T1oZTRHNdeCSvTsVfU4hHa1v1MJV3BtRAS3eH4rsBcQ8SdTBipTeqrD 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: Rename generic_file_buffered_splice_read() to filemap_splice_read(). Rename generic_file_direct_splice_read() to direct_splice_read(). 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 | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 2717078949a2..91b9e2cb9e03 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -287,9 +287,9 @@ void splice_shrink_spd(struct splice_pipe_desc *spd) * Splice data from an O_DIRECT file into pages and then add them to the output * pipe. */ -static ssize_t generic_file_direct_splice_read(struct file *in, loff_t *ppos, - struct pipe_inode_info *pipe, - size_t len, unsigned int flags) +static ssize_t direct_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) { struct iov_iter to; struct bio_vec *bv; @@ -417,10 +417,9 @@ static size_t splice_folio_into_pipe(struct pipe_inode_info *pipe, * Splice folios from the pagecache of a buffered (ie. non-O_DIRECT) file into * a pipe. */ -static ssize_t generic_file_buffered_splice_read(struct file *in, loff_t *ppos, - struct pipe_inode_info *pipe, - size_t len, - unsigned int flags) +static ssize_t filemap_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) { struct folio_batch fbatch; size_t total_spliced = 0, used, npages; @@ -529,8 +528,8 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos, if (unlikely(!len)) return 0; if (in->f_flags & O_DIRECT) - return generic_file_direct_splice_read(in, ppos, pipe, len, flags); - return generic_file_buffered_splice_read(in, ppos, pipe, len, flags); + return direct_splice_read(in, ppos, pipe, len, flags); + return filemap_splice_read(in, ppos, pipe, len, flags); } EXPORT_SYMBOL(generic_file_splice_read); 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: U2FsdGVkX18m690MCrW5AcbHniJEcH4/BaX4Ei/JszlEXfyQYpEyGiS/eZX+U4Ydp9OB5QMzc/Ka0/VeIM7ndBLWYtH+fPKS/KcHAkddCTYJXePK2Ev6awgjnk6PNRh8UFPoEei2y8vRh9nnYeyGhBXDi5KUwru8urz3lH87X7O54c817b6y+edJWphCIxcR3Di8hi0mLCeoJ0SESxcIhebamflrx0jXiSonIIl2pfmR+efq1disBhkj0c2Lc9RGcV7xEYRTSs4merpN0hTz0tg1eOTBQv063PYJYMKNqdgm+Ry045j8d/gZ9+1/8X+yaRABCPgaCH7ZFmETI02cmoKxsB5p5TjFqrDC6En5hUXdOWgBlgiIPe10+FjoGDegEyew6lXDRwRbcbtoITEbAaLlnyR71c56xpXarsWblTUWJHrcoNAqw0r1e5Z2YHYMArhyPJpE4t8fffgZ43vl27CWCoORiyx3g86hqSL8hfgOquZ8o8SPK0VnXOqZvA9rzZ3SvDUrpSKKyUjGwg+PuG72a7jsM4DFOUdfX01utcn5EohjtmWLVoqecI4beXpKLSGuUYOkz93qng0dKHGvDMViO+N6ciFZDNAq86IXwh9Xj8PCv+Ig+7hU/b9YfzeYwpdDuWPzArTdPNLOSujwAHB2iXYVAuBKL/8QKZhaxhmCzTtB4wOcjfSdcKLkBRfTUJZKE/kbvYtpVfPEPvUOKZpfFoF+3GnWqq+E1AfB+lNnH6GpU0tgod5WdmOBfHBJ7PvRI0H16BdLUf0ZeKLHeDcnF5Idz/H+YYdyWbuvuvWEeuDVQsbfvNNLTinRP5JnNc0ySJ/4h4KC9l+l+ypEc45YC+0mmLBvR9G7RtNBsDZvj1Vep87jToqz9YHZbOdq3pAdjvut7h3K4L89gDFvXjXSBt5ggTzAS8zQz8J0kQzycLgaNecB8qP03bzvZlfyjByQ1mfIMOCwF792cXd n0z04TGz AHjFYN7qI0CZHzPteC9YL1qduhcbdFPrxH2EMCA93oLrOuTNx4Mw2+1d8Z6FGqO/oHUM9u40Oe+8mM/q56Xc9t2cahmoTyWZbL6iwBLgd+k0h+327CXs9IHTfRYN7thaSVZC+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 From patchwork Mon Feb 13 15:33:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13138597 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 D82A4C6379F for ; Mon, 13 Feb 2023 15:33:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 675A36B0078; Mon, 13 Feb 2023 10:33:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 627BE6B007D; Mon, 13 Feb 2023 10:33:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C8466B007E; Mon, 13 Feb 2023 10:33:26 -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 34A436B0078 for ; Mon, 13 Feb 2023 10:33:26 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0714D120532 for ; Mon, 13 Feb 2023 15:33:26 +0000 (UTC) X-FDA: 80462662812.25.2B6D7B1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 5703540022 for ; Mon, 13 Feb 2023 15:33:24 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EoZ4+zo9; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.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=1676302404; 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=xJXt4KNNFIdMvSSPmBpCRCAi8g0JFMLHorMyvAgfics=; b=ca8UTnSiTWSXh2fx1ERwdofqvmrxJyibt1lDFh9GbX/INvv1iXU7UfqaXr7CSqmJK94zcp +YKZ4jHbYMEj8sSkzOS2Ed6GwHUs+qbbaUcYQSdZH8ymxBgh1IBMQLqwZb/Z1AoroPyGfv +IyrY4UnicvjnaTMApGpXSdOlvNaTQw= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EoZ4+zo9; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.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=1676302404; a=rsa-sha256; cv=none; b=XrZNJK3lsT8PCPs9IG21ip+hPoa0utyBvMdr9GTBvybGTLhnHYrJcjKiSrqCVmrw0/E+bw W8tUhT5l7rsJo/1EMA5rCQPudUFghk5NBphi79jM/TI6B+nyg//hA50JZ9acGUBl+3fsZb x2GjAfyy2naXDoc8P4lz5bzFme5LXj8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676302403; 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=xJXt4KNNFIdMvSSPmBpCRCAi8g0JFMLHorMyvAgfics=; b=EoZ4+zo9eJbbHbmh7cOYqBY15uCH//mg80tA1UsDa2VJo76jZvkIjSW/BwT+ZRDgFGK9J+ I3XQoSf0k/NdNaWDKdEMeVz0UEj0sRhji2G+ePR2ksVD5mvntEY8WeLURGMhomuSTtSLpn WUNLalUoiMgJJLreQnvcBZbDJit/yKg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.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-325-ffjTGi4LPyGsidvz5tnMXw-1; Mon, 13 Feb 2023 10:33:15 -0500 X-MC-Unique: ffjTGi4LPyGsidvz5tnMXw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 590D43C14851; Mon, 13 Feb 2023 15:33:14 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 53FA22026D4B; Mon, 13 Feb 2023 15:33:12 +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 3/4] splice: Use init_sync_kiocb() in filemap_splice_read() Date: Mon, 13 Feb 2023 15:33:00 +0000 Message-Id: <20230213153301.2338806-4-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.4 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 5703540022 X-Stat-Signature: 91bt6pq99o1um8otk9z3y8ezsea1ubb9 X-HE-Tag: 1676302404-416203 X-HE-Meta: U2FsdGVkX1+GEfXWqxpTHJrfAlKYZFKfSuExQplejUTcJUBFLUMsh3kQl5jGDoni4JDY5fX/HPigk13G4CrvxZTUgdasDCpbFdPTUfEUDst1Wf5yCgdL2m0vNdjOVfoWFPwt4LzuDKWEB2CAfW/6IkUVJyGDDhVX+3I4/oXuwndYnNimSDhEh7WPZGzX0mqjtXyeaUS4rKpKGawBmseNO55A/2p2h8iKlxneIgp5xqMmU6CMote3fAQ5dJtqaTipzE7vPQs3UB/dnyJaOrUoOcA1fS0xJV4BjZXm/RhR1fQEocsDx6VD/e8zzIbV1K5Ys6tACVpRshCYUrULyNzA1iR6eDfVFsi/1sO5eav7av+FfvEZN+C0/Q8Ucp04StYlwQbr2n206t8u63vGvqUljIcqL4WNg4rFcfatQeVT2hHdzzWbkuBqzFBJJZrG2T+cXJ0A/UG2EWiV3V/V00E1fQU0wVmKoCzWjNSRWfFaEgh88/t3DC8rqfhwiNnT65jVgOf0ootlvMXbYb0EHUG2Lqmpa4uRmL28mY4eJzTwoSg05RYo5aojCP0cwMrKwb74Tlq4RxKA+fFQabyvxiZFZXnz6ijtc9Cm7tDWVSGzzx+UqJjQoQ4QIUWKmIcNiXR8/4PV42GmY9Bs8xQA1xlNxYKhwMcNf5gt6fDNQOePmrNo79UwzeLhCvEIy1FFUb6+zHnzOPOfBpruDiteceUb1Uce+7BINQuSF5a8SJCEsYgbQpK5FeRImFNRl4e2XQjHKUz7mAgeBuZ/noCfZP8Fqfz7jXRs+EfUXP0XAkyfGL+xTpKK8S3kyySD/dkcyokCDkuJElhw0rdl7KNdV+sLrCGTi8sNK/F/x9edYdnmLgA8vLZDOHXJ4QZznAd5EW0Dzyv6BCra+yFo8h5cAbHMATbMrUyg9qiUZy1+xJk6zLJ6keYT65KFX12ByKWB17sEkcD+gha8qK8qMjjNEEe wqfsN8a6 RyNHeIvrnCDNE94ZK8OU9ZfnV91EOuyD13dlV/DsdY2K1OoChZv7d9wb76C2IwwLVTI+O/Vx5BN8dBNyuF2PfkqzCmhf3B+BtN/bTQWKAlVKd+c+hTQg3LSedzPoq1Hn/rA8Yr/HccZiuJ93AkmY7Nj5g8GtrQtmjCKKpko8THDs+YDb2YhEsoh710RZb56gLiNNQ6ou67KYNyaaUkx2Cp0M6zDdv6dYByTVn5VzaLNtsHHwcB3YMkTjcBXYZtCkZqJNv1Gz9BoulamoYQTWFRUc7YXiHmeD88cwmVnOsrsQGuyWk2j0zYmA9BtEkcByqjD/PznHP0yFIvMOGsGgXKNoJ+Yz1VF60z08kv36XLOm65YU12tjTzv7ik46hJT/vIhEAPUAvgg2MVLZUkREMCiMEt/zSXNIKYwD6OBRqFpg2Xhbyibz11BERiDuVbYLUt4IA2J3Lr0VI6XmWnQKx0rFJZjFPHkr6EWH8+7g7XOs+7233aO5WgjnQmg== 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: Use init_sync_kiocb() in filemap_splice_read() rather than open coding it. 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: David Hildenbrand --- Notes: ver #2) - Don't attempt to filter IOCB_* flags. fs/splice.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 7c0ff187f87a..4ea63d6a9040 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -419,15 +419,14 @@ static ssize_t filemap_splice_read(struct file *in, loff_t *ppos, size_t len, unsigned int flags) { struct folio_batch fbatch; + struct kiocb iocb; size_t total_spliced = 0, used, npages; loff_t isize, end_offset; bool writably_mapped; int i, error = 0; - struct kiocb iocb = { - .ki_filp = in, - .ki_pos = *ppos, - }; + init_sync_kiocb(&iocb, in); + iocb.ki_pos = *ppos; /* Work out how much data we can actually add into the pipe */ used = pipe_occupancy(pipe->head, pipe->tail); From patchwork Mon Feb 13 15:33:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13138596 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 BBA0EC636CC for ; Mon, 13 Feb 2023 15:33:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53D706B0075; Mon, 13 Feb 2023 10:33:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4ED1F280001; Mon, 13 Feb 2023 10:33:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 367006B007D; Mon, 13 Feb 2023 10:33:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2696A6B0075 for ; Mon, 13 Feb 2023 10:33:24 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E00E01401C9 for ; Mon, 13 Feb 2023 15:33:23 +0000 (UTC) X-FDA: 80462662686.17.D0257FF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id E0D7440016 for ; Mon, 13 Feb 2023 15:33:21 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DuYxIo6R; spf=pass (imf27.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=1676302401; 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=49IJ7O8KaG9bUjSCVtwVGeadJYJCODKyAnH6L7XF9aY=; b=G5sZfNgjJxjPbdgQWvMnFaPo9B93gBD7ssXi1xqsinUVAFmoxVIdDO1ULs3Bs/SkzDRBom JJ+9NM1iAcJV3HHaU+EtGif2oy3i2dhsFiIRs5o+FverOX1SmRQKYLduqbPZjUwue7tML2 slTJB/TAbqQFVyyRCsh5DJed856+hbM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DuYxIo6R; spf=pass (imf27.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=1676302401; a=rsa-sha256; cv=none; b=NxMAfFu1UXG3rSSw4Ohdjq9nQTOgKlVyYnbC5/eoCOHwR5FCNNNbATI+RlOtiLM8pWVeCP 7zazhfwrSBPGJelv1o/gVLZtmN1yxjrblWOEK0SQh6QDj/j24pMI4hmj3oOY/D9+F5G2AJ XJT6orRINlkpQDItYhGcVEVUNC3YpeE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676302401; 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=49IJ7O8KaG9bUjSCVtwVGeadJYJCODKyAnH6L7XF9aY=; b=DuYxIo6R/2/t+ljWYuwfegE73eHF5TDxIlwApqrLYn9UyolK3D9znLjqytYI1dRDwEcBZu PwE4pQSW9sgWnrWUnREVpj2uqgnbvKsCCOCosqL+l8o7FsRw+nskfUDswYk01axIEsbg29 K7YWiXOXJqEvDXVbBLwEpwQy43CScHQ= 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-443-1yMYszxON0mvnfJn-xDpZA-1; Mon, 13 Feb 2023 10:33:17 -0500 X-MC-Unique: 1yMYszxON0mvnfJn-xDpZA-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 0864D18A6464; Mon, 13 Feb 2023 15:33:17 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1696CC16022; Mon, 13 Feb 2023 15:33:14 +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 4/4] splice: Move filemap_read_splice() to mm/filemap.c Date: Mon, 13 Feb 2023 15:33:01 +0000 Message-Id: <20230213153301.2338806-5-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.8 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 7hoqaq3dunz4nj1j3ieyoz1xqad6h4i6 X-Rspamd-Queue-Id: E0D7440016 X-HE-Tag: 1676302401-599231 X-HE-Meta: U2FsdGVkX19qv1FwPzsvLtunrfniD+pquNqRxKk+IzDPE4ntNYegs2/dEJTSJCdo9u/HmTdhLZ+B7lLtgMJW+LAb47eqY5vb/lwkCvHrvkq+fSd/a+c68IglijjACJoTAqQq4hoduolPFf5cdbRVOMRT507HyxatyAyHptI9gT1lf/Tk5XFmxGm96pFGEvXHDLDVinA9YYUouDdaP0kA/gXMX1yorg0RDNGDPzgunfRvktA3uuGnCoL7fPNJRHkeBH2Fb/jAasAMXWUhZCjoJoUxWGOjh9t/hYe7EV5qgFYfj5Mhu84ejxWagEp/lSJnktqpouYuORO4eggioAMY2q09U6CL9uN6m+UxNJp0e7+eNydZajixoN5CBalXZGOfoyQE4Zp5U3jF4mPdme8vz1vDTJZHN5cu5gEpzSXxpwrtCkUfWl7ig3avMiA/XTn2xkVL08kuKK5/8zJ5U3WY83N74a1+lJmpZrqu8e7KzJ36MMb8+BTU0nL22fZoOCgBrTWzwfenQ1i80zlNMKh/Cr4uSjY0g7jXid4whysmEjSh7mnckxB+x7z71oJXw+l0P2KvQBLDxdmZ0UMjgmnj0YwWKIFcI/N3b9X5AkYs1hx3MOTihC7J52T1RVY03S1n7yv3LWAUGnlSdo9Swq0P7nUtUfgUN/fYKtBOmJn5iJc35Rz4xNTPX7ZeowSNFiCkUMj4r/AKyMcNIsVRw2C0jd1dmYcmYFcgVEE7vOYaMPZwNQiYqj8x8RWFf3iceJreJEseNoRUtY6jI7LXWoXHQxqobTib+R8JL5ocQHV1b4cSRnF7bd/iaVcsCuGfm4IrFVOC/I6/DoldRs/QMAnjUQotmmlPVWzxCZhlZ9siYXpksbNC4N3d1yubUn0mPfkYsbQDZdYibkXzblD3ZOzJzpbpfPgzTB7C/dLLsT7cWOC7ybeZPOixH16e2t6g45Y8fVptOjP7DJBWim0qezd MFstJ10T nOHOP6t9aSwP12yYGrrayviN7d61fj0sqIyrw1ODweuWK8SGFsxtkS4aWy1KA9/Em6wGvsw5YSxjX/oku4fwEdrV++RFUzrBVUBu0TK+r1ieDQecryFfmLIH4q4MJ1mLaRhbVu7gBWQY0kYa3G/2BK79Fx4JiV2DZeS8sQ5EgL3y6vsJMyRPjO1DAsJZ8mTD8Z/Tv1J+9CYR90nawUFEl2U2Sa1hn/A06cN+m20FlT4uEfAv83RHhNT626b2P7Cp0X/WOmc2dB/c980YCqnSUn5s0dF/dUBddwQxQBxgeSHm2tNm+DKR06wqBSCo+6l4iRQZCfbNVYaxvjfCwQaX9UuygUden26z4IBQlhrImytrdUSms+ncihJNyYfeWkBUpXBtMQpm6bhIkvqe9YMahtkfh9oNolOcxjP/ij/YJNxg+Cs1TU56gYyCKoz4S/Chsw8uTzwkkQMdEMUR6V0af7kzJVodxT6lxaYkTjzQ2QHzWaohrKcHgv70b6Q== 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: Move filemap_read_splice() to mm/filemap.c and make filemap_get_pages() static again. 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 | 127 ------------------------------------- include/linux/pagemap.h | 2 - include/linux/splice.h | 4 ++ mm/filemap.c | 137 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 135 insertions(+), 135 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 4ea63d6a9040..341cd8fb47a8 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -375,133 +375,6 @@ static ssize_t direct_splice_read(struct file *in, loff_t *ppos, return ret; } -/* - * Splice subpages from a folio into a pipe. - */ -static size_t splice_folio_into_pipe(struct pipe_inode_info *pipe, - struct folio *folio, - loff_t fpos, size_t size) -{ - struct page *page; - size_t spliced = 0, offset = offset_in_folio(folio, fpos); - - page = folio_page(folio, offset / PAGE_SIZE); - size = min(size, folio_size(folio) - offset); - offset %= PAGE_SIZE; - - while (spliced < size && - !pipe_full(pipe->head, pipe->tail, pipe->max_usage)) { - struct pipe_buffer *buf = pipe_head_buf(pipe); - size_t part = min_t(size_t, PAGE_SIZE - offset, size - spliced); - - *buf = (struct pipe_buffer) { - .ops = &page_cache_pipe_buf_ops, - .page = page, - .offset = offset, - .len = part, - }; - folio_get(folio); - pipe->head++; - page++; - spliced += part; - offset = 0; - } - - return spliced; -} - -/* - * Splice folios from the pagecache of a buffered (ie. non-O_DIRECT) file into - * a pipe. - */ -static ssize_t filemap_splice_read(struct file *in, loff_t *ppos, - struct pipe_inode_info *pipe, - size_t len, unsigned int flags) -{ - struct folio_batch fbatch; - struct kiocb iocb; - size_t total_spliced = 0, used, npages; - loff_t isize, end_offset; - bool writably_mapped; - int i, error = 0; - - init_sync_kiocb(&iocb, in); - iocb.ki_pos = *ppos; - - /* Work out how much data we can actually add into the pipe */ - used = pipe_occupancy(pipe->head, pipe->tail); - npages = max_t(ssize_t, pipe->max_usage - used, 0); - len = min_t(size_t, len, npages * PAGE_SIZE); - - folio_batch_init(&fbatch); - - do { - cond_resched(); - - if (*ppos >= i_size_read(file_inode(in))) - break; - - iocb.ki_pos = *ppos; - error = filemap_get_pages(&iocb, len, &fbatch, true); - if (error < 0) - break; - - /* - * i_size must be checked after we know the pages are Uptodate. - * - * Checking i_size after the check allows us to calculate - * the correct value for "nr", which means the zero-filled - * part of the page is not copied back to userspace (unless - * another truncate extends the file - this is desired though). - */ - isize = i_size_read(file_inode(in)); - if (unlikely(*ppos >= isize)) - break; - end_offset = min_t(loff_t, isize, *ppos + len); - - /* - * Once we start copying data, we don't want to be touching any - * cachelines that might be contended: - */ - writably_mapped = mapping_writably_mapped(in->f_mapping); - - for (i = 0; i < folio_batch_count(&fbatch); i++) { - struct folio *folio = fbatch.folios[i]; - size_t n; - - if (folio_pos(folio) >= end_offset) - goto out; - folio_mark_accessed(folio); - - /* - * If users can be writing to this folio using arbitrary - * virtual addresses, take care of potential aliasing - * before reading the folio on the kernel side. - */ - if (writably_mapped) - flush_dcache_folio(folio); - - n = splice_folio_into_pipe(pipe, folio, *ppos, len); - if (!n) - goto out; - len -= n; - total_spliced += n; - *ppos += n; - in->f_ra.prev_pos = *ppos; - if (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) - goto out; - } - - folio_batch_release(&fbatch); - } while (len); - -out: - folio_batch_release(&fbatch); - file_accessed(in); - - return total_spliced ? total_spliced : error; -} - /** * generic_file_splice_read - splice data from file to a pipe * @in: file to splice from diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 3a7bdb35acff..29e1f9e76eb6 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -748,8 +748,6 @@ struct page *read_cache_page(struct address_space *, pgoff_t index, filler_t *filler, struct file *file); extern struct page * read_cache_page_gfp(struct address_space *mapping, pgoff_t index, gfp_t gfp_mask); -int filemap_get_pages(struct kiocb *iocb, size_t count, - struct folio_batch *fbatch, bool need_uptodate); static inline struct page *read_mapping_page(struct address_space *mapping, pgoff_t index, struct file *file) diff --git a/include/linux/splice.h b/include/linux/splice.h index a55179fd60fc..691c44ef5c0b 100644 --- a/include/linux/splice.h +++ b/include/linux/splice.h @@ -67,6 +67,10 @@ typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *, typedef int (splice_direct_actor)(struct pipe_inode_info *, struct splice_desc *); +ssize_t filemap_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags); + extern ssize_t splice_from_pipe(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int, splice_actor *); diff --git a/mm/filemap.c b/mm/filemap.c index 6970be64a3e0..e1ee267675d2 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -42,6 +42,8 @@ #include #include #include +#include +#include #include #include #include "internal.h" @@ -2576,12 +2578,8 @@ static int filemap_readahead(struct kiocb *iocb, struct file *file, return 0; } -/* - * Extract some folios from the pagecache of a file, reading those pages from - * the backing store if necessary and waiting for them. - */ -int filemap_get_pages(struct kiocb *iocb, size_t count, - struct folio_batch *fbatch, bool need_uptodate) +static int filemap_get_pages(struct kiocb *iocb, size_t count, + struct folio_batch *fbatch, bool need_uptodate) { struct file *filp = iocb->ki_filp; struct address_space *mapping = filp->f_mapping; @@ -2845,6 +2843,133 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) } EXPORT_SYMBOL(generic_file_read_iter); +/* + * Splice subpages from a folio into a pipe. + */ +static size_t splice_folio_into_pipe(struct pipe_inode_info *pipe, + struct folio *folio, + loff_t fpos, size_t size) +{ + struct page *page; + size_t spliced = 0, offset = offset_in_folio(folio, fpos); + + page = folio_page(folio, offset / PAGE_SIZE); + size = min(size, folio_size(folio) - offset); + offset %= PAGE_SIZE; + + while (spliced < size && + !pipe_full(pipe->head, pipe->tail, pipe->max_usage)) { + struct pipe_buffer *buf = pipe_head_buf(pipe); + size_t part = min_t(size_t, PAGE_SIZE - offset, size - spliced); + + *buf = (struct pipe_buffer) { + .ops = &page_cache_pipe_buf_ops, + .page = page, + .offset = offset, + .len = part, + }; + folio_get(folio); + pipe->head++; + page++; + spliced += part; + offset = 0; + } + + return spliced; +} + +/* + * Splice folios from the pagecache of a buffered (ie. non-O_DIRECT) file into + * a pipe. + */ +ssize_t filemap_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + struct folio_batch fbatch; + struct kiocb iocb; + size_t total_spliced = 0, used, npages; + loff_t isize, end_offset; + bool writably_mapped; + int i, error = 0; + + init_sync_kiocb(&iocb, in); + iocb.ki_pos = *ppos; + + /* Work out how much data we can actually add into the pipe */ + used = pipe_occupancy(pipe->head, pipe->tail); + npages = max_t(ssize_t, pipe->max_usage - used, 0); + len = min_t(size_t, len, npages * PAGE_SIZE); + + folio_batch_init(&fbatch); + + do { + cond_resched(); + + if (*ppos >= i_size_read(file_inode(in))) + break; + + iocb.ki_pos = *ppos; + error = filemap_get_pages(&iocb, len, &fbatch, true); + if (error < 0) + break; + + /* + * i_size must be checked after we know the pages are Uptodate. + * + * Checking i_size after the check allows us to calculate + * the correct value for "nr", which means the zero-filled + * part of the page is not copied back to userspace (unless + * another truncate extends the file - this is desired though). + */ + isize = i_size_read(file_inode(in)); + if (unlikely(*ppos >= isize)) + break; + end_offset = min_t(loff_t, isize, *ppos + len); + + /* + * Once we start copying data, we don't want to be touching any + * cachelines that might be contended: + */ + writably_mapped = mapping_writably_mapped(in->f_mapping); + + for (i = 0; i < folio_batch_count(&fbatch); i++) { + struct folio *folio = fbatch.folios[i]; + size_t n; + + if (folio_pos(folio) >= end_offset) + goto out; + folio_mark_accessed(folio); + + /* + * If users can be writing to this folio using arbitrary + * virtual addresses, take care of potential aliasing + * before reading the folio on the kernel side. + */ + if (writably_mapped) + flush_dcache_folio(folio); + + n = splice_folio_into_pipe(pipe, folio, *ppos, len); + if (!n) + goto out; + len -= n; + total_spliced += n; + *ppos += n; + in->f_ra.prev_pos = *ppos; + if (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) + goto out; + } + + folio_batch_release(&fbatch); + } while (len); + +out: + folio_batch_release(&fbatch); + file_accessed(in); + + return total_spliced ? total_spliced : error; +} + static inline loff_t folio_seek_hole_data(struct xa_state *xas, struct address_space *mapping, struct folio *folio, loff_t start, loff_t end, bool seek_data)