From patchwork Sat May 20 00:00:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13248985 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 5A26CC77B7A for ; Sat, 20 May 2023 00:01:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E338F280002; Fri, 19 May 2023 20:01:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBAF5280001; Fri, 19 May 2023 20:01:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C347D280002; Fri, 19 May 2023 20:01:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B31AE280001 for ; Fri, 19 May 2023 20:01:14 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 803F280B7E for ; Sat, 20 May 2023 00:01:14 +0000 (UTC) X-FDA: 80808678468.28.C401FC6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id CACD9C0024 for ; Sat, 20 May 2023 00:01:12 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gVNek1Sc; spf=pass (imf10.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=1684540872; 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=PT+Bun0dIbxZdwJScwf3VqpEC9/8xV7aRQjBWH3biT0=; b=4Smdnls3tLip57Zm2s4iDx6aijPgVCxu2wqGzPTGtSseyUQAaapECdv8gfZY1AhIZXS7R4 vfQ4+fwZYhnEXmn557pCtY3PdUJXufjjoxyoE3CsY91q6ASTIwpdINUoHRZ6xIGjw6y7LV vo6HOUATJcEVbjFRz1JqRXzZRFY4RSw= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gVNek1Sc; spf=pass (imf10.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=1684540872; a=rsa-sha256; cv=none; b=mKWiCwWAu8Z0cqQqfKOvUgM2YlIY9kS/TEDfHwRGAGJW76WhK7LVBF9sjmWs/FcQepvSrO tgMHAcNrCnM9VCShBia/WZ9aBx6YN3kwTXh3iJbvv26d7a6rDt5TMeyGNqI6UljitmEQ6w nr4OYjx67V1YShClajG+fJJKiPE8wq0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684540872; 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=PT+Bun0dIbxZdwJScwf3VqpEC9/8xV7aRQjBWH3biT0=; b=gVNek1ScxdDpT0J0Yzf87Q2FONTwF/M347lP2HXsLGcj8utXvAbVM0F0rqPEry4vbDJcuv +UVnD6vCSGhx/M+yGSEx9nFRZv+NpYkPSxwOZLzKn4v33AoVRG/CnKhQ1/c7opU3QVDJeU vgOtu+9xIbeFd419fir61Hd0PsJCJzI= 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-624-hfhZbVVlMdejFFXt6z0GIA-1; Fri, 19 May 2023 20:01:06 -0400 X-MC-Unique: hfhZbVVlMdejFFXt6z0GIA-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 ABCF7101A53A; Sat, 20 May 2023 00:01:05 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 721554F2DE0; Sat, 20 May 2023 00:01:03 +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 , Christian Brauner , Linus Torvalds , 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 v21 04/30] splice: Clean up copy_splice_read() a bit Date: Sat, 20 May 2023 01:00:23 +0100 Message-Id: <20230520000049.2226926-5-dhowells@redhat.com> In-Reply-To: <20230520000049.2226926-1-dhowells@redhat.com> References: <20230520000049.2226926-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Queue-Id: CACD9C0024 X-Rspam-User: X-Stat-Signature: 7jy4j5d1af1889qpg9bq1n7xu8ih1igu X-Rspamd-Server: rspam01 X-HE-Tag: 1684540872-168436 X-HE-Meta: U2FsdGVkX18ITyYSrg/uegvERH0sYHAXT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Zj3aKhv6dBU008RT8RHyONJHQScYQ4xfWyK06TE2y7orHRbceCDqXrF0uUs4t2CnrrMiwtBeQ1Ko0fJ8hUoje+mXmG2Yda67y00DyU2PySa5seYL+hPnmKSyx9OiMe/zjPv6xN8vqrjI3Rbz6PkOl/lzzpbA0GD3xWs+hLJM/jwNIKwWc9urhQRecBsEfcPoCbwh5POrRMcBydWJV3MUsGuERE7f0JquNml5V9xeh1ZB5b5Wkna9XTv815atv9Vjf98Gwx0QXJWdaSw6YbgFUKvxn7/YNmlC8dUV8KEvDsYWumGOSFAK8B7n490d4aoXFAz1zoVwFpw+bU 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: Do a couple of cleanups to copy_splice_read(): (1) Cast to struct page **, not void *. (2) Simplify the calculation of the number of pages to keep/reclaim in copy_splice_read(). Suggested-by: Christoph Hellwig Signed-off-by: David Howells Reviewed-by: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: linux-mm@kvack.org cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org Reviewed-by: Christian Brauner --- Notes: ver #21) - direct_splice_read() got renamed to copy_splice_read(). fs/splice.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 2478e065bc53..f9a9be797b0c 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -311,7 +311,7 @@ ssize_t copy_splice_read(struct file *in, loff_t *ppos, struct kiocb kiocb; struct page **pages; ssize_t ret; - size_t used, npages, chunk, remain, reclaim; + size_t used, npages, chunk, remain, keep = 0; int i; /* Work out how much data we can actually add into the pipe */ @@ -325,7 +325,7 @@ ssize_t copy_splice_read(struct file *in, loff_t *ppos, if (!bv) return -ENOMEM; - pages = (void *)(bv + npages); + pages = (struct page **)(bv + npages); npages = alloc_pages_bulk_array(GFP_USER, npages, pages); if (!npages) { kfree(bv); @@ -348,11 +348,8 @@ ssize_t copy_splice_read(struct file *in, loff_t *ppos, kiocb.ki_pos = *ppos; ret = call_read_iter(in, &kiocb, &to); - reclaim = npages * PAGE_SIZE; - remain = 0; if (ret > 0) { - reclaim -= ret; - remain = ret; + keep = DIV_ROUND_UP(ret, PAGE_SIZE); *ppos = kiocb.ki_pos; file_accessed(in); } else if (ret < 0) { @@ -365,14 +362,12 @@ ssize_t copy_splice_read(struct file *in, loff_t *ppos, } /* Free any pages that didn't get touched at all. */ - reclaim /= PAGE_SIZE; - if (reclaim) { - npages -= reclaim; - release_pages(pages + npages, reclaim); - } + if (keep < npages) + release_pages(pages + keep, npages - keep); /* Push the remaining pages into the pipe. */ - for (i = 0; i < npages; i++) { + remain = ret; + for (i = 0; i < keep; i++) { struct pipe_buffer *buf = pipe_head_buf(pipe); chunk = min_t(size_t, remain, PAGE_SIZE);