From patchwork Mon Feb 13 13:46:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13138461 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 C25C4C6379F for ; Mon, 13 Feb 2023 13:46:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3BC426B0073; Mon, 13 Feb 2023 08:46:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A7CF6B007E; Mon, 13 Feb 2023 08:46:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FB156B0080; Mon, 13 Feb 2023 08:46:31 -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 F1C786B0073 for ; Mon, 13 Feb 2023 08:46:30 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B8546160800 for ; Mon, 13 Feb 2023 13:46:30 +0000 (UTC) X-FDA: 80462393340.05.8C43F6F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id EB7EE100006 for ; Mon, 13 Feb 2023 13:46:28 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UcsStgGR; spf=pass (imf05.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=1676295989; 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=cowZ1cmLrnZZxcephacOQa4mjhuuVERSSt8ZL/UsOKw=; b=V7r1m2/wPbLuNqOuprzEeA3KYk8T8FAs0Yhh5dr8zWc95dNzCYzS9RIse3lsEmr5jTiIJ+ IIaaDXJKxMOKLmtf1l6wUcU7IAEUGXNacLbU6bkDj37Hf+8KeGQDsrSphc+rWcETzxoPpR kE9RcZmQSJvXp+Lx57wtl5eZGhzITmQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UcsStgGR; spf=pass (imf05.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=1676295989; a=rsa-sha256; cv=none; b=Ee2+v/3sE72QvAFTq9TqyI/GoXpAMI2NFfobFYse6hvinv9gP5gKruF/VO3ORU6agJWSxZ 7uaseMctbt7gj+aTCV6fLl4bJOX5bC/Bf0xSvcHLiveKmaEmgk+QoPyNVwfHOc3qDyAgAy dpHxcAbiEhy+Kp6HzCGqbgjDYelhf9I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676295988; 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=cowZ1cmLrnZZxcephacOQa4mjhuuVERSSt8ZL/UsOKw=; b=UcsStgGRLEjtmBYHgdZfVeithaEVHoFBX508FSp1gJ+WWhJZu6uI/qWqRcXQWpdN4WyGyL DBxEJup17wXim4VlW1XyGlG+cMvqqlwTuYQtFcB4//Lhb/4L4nR4AAODROWoAVHvrnP+4C nSUOERABPNw5HeADbCYlu9kuJpMAOpw= 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-167-u6s-Mzk-MTWOuQY7_HuoaQ-1; Mon, 13 Feb 2023 08:46:27 -0500 X-MC-Unique: u6s-Mzk-MTWOuQY7_HuoaQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EF5EE971086; Mon, 13 Feb 2023 13:46:25 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AE40492C3C; Mon, 13 Feb 2023 13:46:23 +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 1/4] splice: Rename new splice functions Date: Mon, 13 Feb 2023 13:46:16 +0000 Message-Id: <20230213134619.2198965-2-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.9 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: EB7EE100006 X-Stat-Signature: cco4bo3yerg51e5dy5pbu8wye8ad173n X-Rspam-User: X-HE-Tag: 1676295988-172662 X-HE-Meta: U2FsdGVkX19XRywcqIxQPtkhyvzSqgMGndvorfiAZ72ro9XRHWZ1SRPXv5VSSBX0AKei72/+4cBRaGy7KNSqeLG0QdTfKu82UWTY8g6oM0okbQyGBTJYqhcFyGrY+eOQfSZHylHrtiUj23QhTyUSZxcgebVzDzMFh/5Bjf3Ry8eim64AWPi+entKA6rWMbVxZG7nwiNCPq/e/m5n0MsF7qo41RRNRsQyDttN3iJvbqMZ6Fv/wX4lctzZkQuTNQ0zAJuftey6fETCon1UxMSEV/fEa8SlWZAL/A6lpjgGoUDiutRrf9dabpXZ7fP7WAUU6fgeVKCDKQNq5E36lx7DTaTcWVBDfcnd6m8YZi48xyBX0uBu4ttEhNkA+YC8B5xBsrKsVFJV/ZWMAGUpt0h3IULNqNOLakVI/jIT+ab7x/vuUB7NpktMRIPhxhYJiTY1/OPx37eIu7hFlNI2U1ys3ADMZQ0XXOSXRoZjr6T7RuHRltJdDpimZdOuBinIsdZxRLnKho3iahBbpxmKh315PXbfJ4dNIS8PAJr5ga9J/AbshVBAPVzfMwdmFn7J1MgWJR9gLdFNF1vb9NzBZarpton/7WywViJgymfLc6hg1oP0nooMUdT4ybvZtW2GULPXISnN+JWRV1JRdeqv8ydpiS/aldt4KctT6q/dVxZugfbqaP6aX2IwpWvkDAtGjkZqTq2m4gsJ9yem8QGRmkq0rNPGOk9w20Njr/JNJb4lE2kqFkpjuHlq9mTPlpkavEAJSt0l0KoDXOtcbTUzzcAT8QnHJxREmWjvknFIIS7iQdc7xYMz4gRylvquAkFRX7rUp8iFmq2Fex8+YkvYOZESGFzMVXKX9d/BNzZuI/52aallLnGSYjGdRibYLsa9T98//uAWrbZJcCqDz5LPwcgR197JWsjHKtMPXod95U6sqeXWxivwh75XmSvAVBulJw7aAdotODPCFR8lO6k9q89 SD6c/KLn yH6twM9tC/tGX9jWDTYpxlDC16ZxRCIRjx6ew+hyeV8N+cTHepuGCRXP6771yeeO/2+y9cSM0tVW657ZbVo7W+GoApmvsLIDoWm1flfgYUE4t4bg0plji8Ruy7yzuBSbMTXHJuaLuVyCaLEWHMxeXka2VZe8Qp74FgtA3G+onfw5CbT7gFSsWSufpozys+WPL0I8X/2oI76FOOZbnMkD9dwvROsNd/9DRI+nE08USL0/8uXyuAVhrVX/xbZhRlCRGPtQaInGDu+JRieTDyUKRNvKKPMEpd5533lmZItHcY3T2sdLK2IIRGsH3VlXsr9vWCydI04Z/vIySFGDI3BF4Zi9yE/PF7sIv4d7zKzxdX0FIsgZw6K1lh4RSSPw7NOneoFqPyJWJZQ1h94WZ4USBDiF1HzOybFpiyK1mZYZ6F6R6oFLGBErz+N0oXL18+i9/YI8c 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 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 | 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 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+oX+mrfFebEhxBdpIWNb5TiPQYYLhWhVw5w+nHSDgfkCWx30EU/Nmm86uAzOUFaUBJpDs6BY22+ppk/ZNz2pQaLsWRm0nHvTQ1YvRsW6+AjzKjrQoIyZ21lbl955IBkp35gKXEfHoSF6kNhx/b2ullH1h3x8g48HX6w0Rvp7gnJCTJB3YEuSZVEWCTT3MOj5f4RLLHvfI9DGJnLhbTPIoW7LhxigG9BstL04U3IxREyqYGyNvkWpsDvAYGA9vaJGThvGrT+97ch1OAhlz7QuS2LPduwx0vYoVrWWIugH4Kh1igIhq/PrnA9dTE88emso5/i8WNb7xpiKYQDma9I9sPp/ylKt44He8UHr7CTs37q8CgD3W17OM7SKFe3odrtbOfYLZhAhfGbjZ2RyVJjdE39OfW29fzr6uLFs4bcqD+EcEvnaZOmqbwA0lafGUpJ0cIKNhgbxd/aMrpkCHl5wFh1EKv6lMkmsubMh75XmAvJdD0Vf4timTJmM27BQoEKvIH0Gg3v+ab4xM6icRvutBdt9fHEfwV+XOr2JS5DiPW2OPdUFSG1yca71CmM5CIH08RQeMQbbVCwo6OMrWMEFcShOI07k63Cm5X3HWO0Uy8jlpfYc9owqmhoyaJGk+GIvY9hcqS+dAz+SeyK1AR4Pk6GJ/vbz0Z+quKMnhbidOnw7cIjKHdQmEl/YpRFZiFdRY8a2RjSAgkD/ULpM30/IbuzVyQR29ZS95rT6YcZfgCFNgBhzNw/1nYRzt2Tp6Jaw4K8FyIYjURP/I4cWPTn4MtfxLVZqNfKesOytyei9MOWsATPnxSsK+nq4x7W6CyVAv0MyumIkZ9Hu+SmK/znVHcBwN75L795RIJhLcPktxYN+BkliYMFqjIWdnUUiNKzIBGsYdF+RpCPGw+HNTaN9rmKzU87f+Owft9U7eIXJ5yEsQWOBU3/osBf9iQlAq0ReorX 2IJ+lSZ+ vPBsuj5M23raFLXRWri3QoxGhfkbTCdzT0eSqTTjpM8lS2d9gZXKRCuDvZJJuHJhBcKqTOfwc4wYctDPvIJvrPDn26vmD+S0ppu9RTYrR3SP9FCBCW31BjIj1z29J+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 From patchwork Mon Feb 13 13:46:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13138464 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 16A5FC6379F for ; Mon, 13 Feb 2023 13:46:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A70F76B007E; Mon, 13 Feb 2023 08:46:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A20F36B0080; Mon, 13 Feb 2023 08:46:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E90E6B0082; Mon, 13 Feb 2023 08:46:54 -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 7E4486B007E for ; Mon, 13 Feb 2023 08:46:54 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 537B6AAE1B for ; Mon, 13 Feb 2023 13:46:54 +0000 (UTC) X-FDA: 80462394348.05.845CB81 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 79FCE40028 for ; Mon, 13 Feb 2023 13:46:52 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OoWrCXcH; 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=1676296012; 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=4Gd+AM0ivl8H3lv5f0bcfNcViU9oHee8wwcgLJRIkXo=; b=R0s9P9MNGihsnTB2El16lqlWiPnkQEPy9Qe9P1hZ+oYejHP6pWuNyROtDfsdvbEpsps5X4 NbpCAijUH6kwufkPBJbry9GnI3IHpUum812rawy2xb4v4vk0eJ8VadVyBuvfTs7si3laO8 FjOvpw0u5uAIz6WoyEQwb+zRgN0bNqo= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OoWrCXcH; 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=1676296012; a=rsa-sha256; cv=none; b=30ibOXDpEa8Y/Gq7cGWfDRxnutdYcoLRXp9DMIBZ0glQNx7CQngASKhpkAqflKGJ5G62Jo VvTdpFEYghTkSq+rtzNeHg6WozXMHujKHhVLznCgO5zvFboNJnGoLdStCqJE7sIaFPoTXH 9QdKWi2p0S2PjECZoZzLpeu3nbuX8Ac= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676296011; 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=4Gd+AM0ivl8H3lv5f0bcfNcViU9oHee8wwcgLJRIkXo=; b=OoWrCXcHX+UhmKyFSFcbUoI8crsYy3jZX0FaoN1fYS7CBlTHcX0LGC4Y+ZkhsLqdxL85A9 dzv7XLieiZZmHxX7CcASsAofy85dtXxb7aAvNjIwRpeTCgXIJU4Z6kLXN+NqW9KPRII5eT fjNuH9fj4OnXVwXNG1n8vZRyWfVPLMs= 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-58-5GjRqJH1Nv2E9X1dNEvJAQ-1; Mon, 13 Feb 2023 08:46:47 -0500 X-MC-Unique: 5GjRqJH1Nv2E9X1dNEvJAQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 367EF3C16E82; Mon, 13 Feb 2023 13:46:31 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41D452166B26; Mon, 13 Feb 2023 13:46:29 +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 3/4] splice: Use init_sync_kiocb() in filemap_splice_read() Date: Mon, 13 Feb 2023 13:46:18 +0000 Message-Id: <20230213134619.2198965-4-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.6 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 79FCE40028 X-Stat-Signature: 35tczwngzygwisinpy7cmk4t86wgiei3 X-HE-Tag: 1676296012-832906 X-HE-Meta: U2FsdGVkX1/z8htX6T2FlFn5ZquCxJUL/n1n1Ti5rpppO8g3PEtZr7RVzyH0J6zCdmvsXd6cOs21wKjzAv9VVDfgpSlvTWMxk7OOqKASxY+9uDsxu2DXQQFSluiwkh290uIoVPT4F4QSZiWdemFbdv+VEAuGNoMNHrpucHQd4GHALvJ4BT/zj7LkZqWum9cAiw2p4wpyfkzd55YGTvAzZEKTyciKaLBvM1NZhzlX5YDDZRNYeARW9rpU9ECsnHIU3/xeCsk+Z28MHyDqaiXTUh3cP5cSZKUijeMikjqe4jGrWngKwcayyR4F+IM7yQCkMSBrs/DUFCpMK4tGmYko4w975StrbTUgRz2nSdHjZ17ITvm5sO/R08XQWW+2krvmjAfGITgruXMOfeLtQic9SrbcYDGA8tgFqyumnQr1IBTRhiFX3onjs1cULwjs7Gf6Hf5IlrP/esFrkaN9JkB/5aV8NYGkOy/0nYTNeDlqJTcTu073zcVvqwwIoCho7y1s6psVPlzuKKUkVWoroC5qp0IrVxzU9hPx9mzC/nzNAqBgGL/ijIUrODEUF/tTl9uxRuyC3h35uKw4aUTBlrkLXoso3nlGNXgmp4YCJfpvbqiJ9F+7swHQKZjof3OFx1pGwV9mUfjjKM3x73zPbA5flOKn9HcQq4XmH0zX/juRv+AbYk7XIWqgm2WFqwJnGwrolEP+BTJhApkuITfHChfo3jStGgTla8mgF9uFDn5WftT1ceIM0nMu9rAySJnrOdx9vwn3suIv3U4kCaLSL4ebYHTHZF5kx1318+OgaaLj6lW5aRxhivmem5LHUJzpwUkvhh5lu6NwJ+huyjM6mrIUZPZMdPdNdfu3e/3tz2Bn3BgIE576/K+aHRdaQE6W6LzzkvJj9pern4dnHcdMKIaoRYuAJukrlevNyZvNiW668wgU0ShlQavllGq/rEq9HOPpgqLDqPRzc7HQ/8Pa1Mk 7UdUOGnP Znl2ZxavdoNMkEO0I4VPFEzGIUGcGx3wtKZ3mD4pfri4GTQaTb/61xfXH1vwfLogOA/9nMu92JYbaF8ej4YZeBrfIZUnGsNRSPACvzSZCX6aTAiW+Y4w3/kExCLbUMBStfVUiYG9d63y9K0X8jvGsBCbjG2XOgzv3VXLHUvvw4QKZUsDp4xRhzQc9kDtxuQlAratN+J7m56vdE4SsGLsD0ntJ/xFfsXuw03RBiLMiQlSjXIncR66PlwR1Q+GjPDsICndH0AK/8oJ1/1Ie5BrYHXBkorlqBOFrP+BglPCJU/K4pZ/nSHD2PslOqnSsRIXnLtyqQOxmIlJ9/Q91WO7DQr4/K2xHqq7KjTcfQPhlgkMItS1VuJk498qk/k61LjjrqH5Eu1bUABCNxMf5lKqdAkn+65/X/x3VtQXmRH8NHFb6mijCUq/cNcDXj8H9tpcKpRVY/7OM9y6YhHys6bboNWWXZtVgUVs3SMmr2ApmsLwm7T6RJuhtmcTp0A== 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 and filter out IOCB_NOWAIT since the splice is synchronous. 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 --- fs/splice.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 7c0ff187f87a..8b2a9d963bc4 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -419,15 +419,15 @@ 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; + iocb.ki_flags &= IOCB_NOWAIT; /* Work out how much data we can actually add into the pipe */ used = pipe_occupancy(pipe->head, pipe->tail); From patchwork Mon Feb 13 13:46:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13138463 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 66797C636D4 for ; Mon, 13 Feb 2023 13:46:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 037EA6B0080; Mon, 13 Feb 2023 08:46:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F2A976B0081; Mon, 13 Feb 2023 08:46:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DCB686B0082; Mon, 13 Feb 2023 08:46:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CEC7E6B0080 for ; Mon, 13 Feb 2023 08:46:41 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2CFC8C07DC for ; Mon, 13 Feb 2023 13:46:41 +0000 (UTC) X-FDA: 80462393802.03.2A33922 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 5C6E61C0022 for ; Mon, 13 Feb 2023 13:46:39 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=b0nhL30m; spf=pass (imf18.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=1676295999; 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=v3dWdulFMkC02AM2jYIVI6FYFE9HkcrX92HlV1c4tO4=; b=YmzMVZQ6ZHRe1wlgkb49kRA8svCTih4DYQSR5v+c/KYpvF1A0VVnM73CLlD9PyZ4aWH30W aWMoeHEhyWj0vKppu1ApuZuxf0P5xrxEaMG7kBkjvqU/eFERkcufMnVeaUrmO4elkoPplM 1jQMxsMtiTWbHLWGegzgHEtcfr4jHJQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=b0nhL30m; spf=pass (imf18.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=1676295999; a=rsa-sha256; cv=none; b=bjUWMLOSYyriiB5+yZWo2ysAuQBbzYh3yXs2W5uf8KdX30oRc7HYnq+xZZBTFogSoimuL3 e4c9lE+u9VtuuapRYBY7zE2/arM92jrHttKn6+t9jn1wJX0y7mWRoSiJxSaYj7tokiLaxM xFGvLHwI12IQ716nyVWYAXEwSJ3kFBs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676295998; 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=v3dWdulFMkC02AM2jYIVI6FYFE9HkcrX92HlV1c4tO4=; b=b0nhL30m9I9SuQFIty+2FFnChJVdzw+WVl7Z/+r9BZpUsPc4hVNyYURjBHsa59VjFHFk6C hpoeptCi2XHgea6423j+TlHGCPpVPNhGEDdjbiokWvi0YatIt0HqmJqJ4zDvcjVOsKoi9A vaX82iJYwcn6QhaEZ8rUh+dCJM+9NR0= 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-510-H46sO8NjN5-GuV9-iHBZng-1; Mon, 13 Feb 2023 08:46:34 -0500 X-MC-Unique: H46sO8NjN5-GuV9-iHBZng-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 D32F1885620; Mon, 13 Feb 2023 13:46:33 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0CB7C16022; Mon, 13 Feb 2023 13:46:31 +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 4/4] splice: Move filemap_read_splice() to mm/filemap.c Date: Mon, 13 Feb 2023 13:46:19 +0000 Message-Id: <20230213134619.2198965-5-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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5C6E61C0022 X-Rspam-User: X-Stat-Signature: h9xi7juutpryf3ak1e44pn467ku7tsju X-HE-Tag: 1676295999-883642 X-HE-Meta: U2FsdGVkX1/fofbL7YL0ZIRwSfBggL1Y/bpNFO6A07K6IxvEFVRyBiQ5lV2DINDUkYDxWR676YKuysUuIpNs6l/44cn+farL/26cnUmEpQOiG1muLypHTxUghUKBhoCo7xcBgd10IvX8pXWL0nPG7kZbomb1qZ+1iemyB8oiaTuWpH24t4gogkE0TqVf1MpqhFQfs2qBTwnF/LxUu/0RnM8KyLk4G8R9mMG8Gee6j4bl/PZco8jT1rMfEXFv7OwYTiufMGnd74kI3SlpHID3slaXk3fOU84y2SdZ6DZ3NeoTN2SVN8OMofjwsWYJOwn4KBR0Eo+/h8RevWQqXAoE8f6lHlkIH7uTle9shHXJTWLBm97C9UCBdp6nnppQSV5wTflI4xrRBNV4jFRQqJHbL2r+zplT8BDpwH1tkz1azZl1Yw8tNCtQu7roM1PruUz4G/qcBOR386QuSkBSU5GtV39uKd+OeWsRpyLvMm+4UlRgoieyKSHuJNMZ33X2v9KVz0li4aGhGag70YsAZ1iqAsr6CtLsaAdntw/7i2SwFuW97yNRsCFZpqS9+CRuh+GXRB1HWnmcWVPi/wDektanaJjksAqlbxZ0i7CXDBCqa+VZ/vFGZ98ZqMNO7dQ9V3z0bOPIOmRt18vIiREPyE9Yjzgt9ram92jokqhvlqSXqFjUruqm6pWss2EZrwkfclGLOMhjgLLl1SYKP6UOfVSbRW0vAx6h3uqid/fjOWEH2NlRm9MqnhmzAHQfx98+HEJPiKikbe/YidI5vL2mZa5hs47Tw9btJNcEP9wqzEun8cmPI6AwI+TGw2LVswNzRr/1IJM5HlL2+zMuvFoc7m10JwcfUUPKGF0tsQRDDwWOqdjQnbcFfqANoKiRU0XLtfKAURCBxzSQ/Lj6PmxEp5w8zFBj0PK36aiZ98eumvwtlm0XUuEkmmjILHop2OXmo6zD37Cjl4b2s8Sp2uUeeZq Sk02wnZv dPCc0m4v/3DSPb2whf3lN5EFYb0WOK0F0XGSMkC/pa5wXCWwJ7QEqVUWEGmvY22czNg+XPudc1OEgFGSMJ8EsTMvzLZJvxhSFwA/RWVSeLA3n+q3T7jPssWuqso5RTgNBMHrueJjp6+VRXOVfwSRS1jUgj9JqlFLcfHGZycwuMvKBmCzscol51c44I4O32VUUyafCXkM5LQbd5upHXkfs8qfg5ChITgRnzU9eCF5FhaTVFWujYynWGwdSJKoVv149J9T3YV80qCOFWNCR821gaAwDtjP00CqMPHMmT45NKFWHlPDHwkrzh5DBhZDTKL1En84WV8wskkMLgRk8NdEd3eAY7krCCNjcVrmXrRNMHQ5TPrmLIDhv+0tn4T9SCVRsfjRF3Kliy8cOBK+16D8aklHmIe0Rf7xIFcu4IPtVI3Idaf6F7kg5qK4EJub8/TGB52ujITvl7WcKsga+4SVoMie1zrCt3x1Mx9paDGfRcw0i45HnWBiQ4VT1cA== 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 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 | 128 ------------------------------------- include/linux/pagemap.h | 2 - include/linux/splice.h | 4 ++ mm/filemap.c | 138 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 136 insertions(+), 136 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 8b2a9d963bc4..341cd8fb47a8 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -375,134 +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; - iocb.ki_flags &= IOCB_NOWAIT; - - /* 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..963602671fee 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,134 @@ 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; + iocb.ki_flags &= IOCB_NOWAIT; + + /* 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)