From patchwork Mon May 22 13:49:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13250584 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 98597C7EE29 for ; Mon, 22 May 2023 13:50:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4809900002; Mon, 22 May 2023 09:50:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF6EF280002; Mon, 22 May 2023 09:50:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A9755900006; Mon, 22 May 2023 09:50:49 -0400 (EDT) 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 9BC9D900002 for ; Mon, 22 May 2023 09:50:49 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 64842C019E for ; Mon, 22 May 2023 13:50:49 +0000 (UTC) X-FDA: 80818026618.23.0CC0C6D 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 8B8D840014 for ; Mon, 22 May 2023 13:50:47 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=irRwId0b; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.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=1684763447; a=rsa-sha256; cv=none; b=oy2iyWfRBLkMRefn+BpxNQbf+pcNJqGDY/XlpavhnGWa2ZQcxP+bVBks48KdWw28C4RnRq DrZX7HLuPlcCiY8Lp2bNNsptUQnvzJTdg+87eMhsRLDv4PL9cxCuIeXhGe/VGr5HnPea+o Ier2+D6VnnbYC2AsnHm6/g7GXhU3usM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=irRwId0b; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.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=1684763447; 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=+QycUCk1EhV64OEFYi0Ywr/xSgjmAM7Sud1UY4yTKxE=; b=1OQaYmt6tMmfg4o1IJAWfHYr9GrRoA5kOpGWgfDns2Wlf3lGZYpkaBkMbMTEyEhlUsZimc dlMxpLiHYdsFO6G7Amb3ctU0FwZlqCswbiCQ/WSaWHDx4gfy5nqpQiUIB7wq5v2WIL7hF9 8sW67a5FH+l7lrDZzF0t/BFtdAXFz3Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684763446; 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=+QycUCk1EhV64OEFYi0Ywr/xSgjmAM7Sud1UY4yTKxE=; b=irRwId0b7rmrkvFKJGDi5rMomGoLAcVNHD3gfrMJbmzxHoQFvXLan8va9T53clU+p7RTp+ bCfl/B3nF1FJhEnbooXWxUflQUHFBpDETU7lrOc4icWGlZc/+mrWt9BxfoldR/H4vAsbad w1dGvn6OkRH7Ednh04r+CZOnrWbR7Hw= 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-31-5SDxrfwzNriOr4rM0S6JVg-1; Mon, 22 May 2023 09:50:41 -0400 X-MC-Unique: 5SDxrfwzNriOr4rM0S6JVg-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 C8CC9185A78E; Mon, 22 May 2023 13:50:40 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A3B22166B25; Mon, 22 May 2023 13:50:38 +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 v22 04/31] splice: Clean up copy_splice_read() a bit Date: Mon, 22 May 2023 14:49:51 +0100 Message-Id: <20230522135018.2742245-5-dhowells@redhat.com> In-Reply-To: <20230522135018.2742245-1-dhowells@redhat.com> References: <20230522135018.2742245-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: rspam06 X-Rspamd-Queue-Id: 8B8D840014 X-Stat-Signature: gefage8t446yne1doqedaztxyzqm7pi8 X-HE-Tag: 1684763447-196718 X-HE-Meta: U2FsdGVkX1+XrChWSH2oZgCqbJrp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GIl7yU42edDJ2C+hhd3zFLt4VBjnZKudPap9anxlCcNqbaKwTwSNIpKH+qfeKaKSo31IDw2tORhAFPFBpOubQ7aEaaVjwou2EJ+AYZ10SOcMa5rWk1+NjRvYsu4VI5hwLiepnPokdxEB3FTAVyUHHZnq9jRX560x2DQSvrZ8HFmJFm4pZ1vNPCWkh6CkgBc+m9cN7sSXSAHrl5s6b46Y6OAa/uckcXD8mrntR5qWx5MmSjAjArYIQrbYVkspjTCuCOwlB3hqwl8ouPWMivqDUR/CJYMFQtf9lNgpUqAbx3C/CVzktm7ufnh26oDZhLbW4aHeEZbyrNxVbepBRpmdE2l10mFjiy6eLXHi1QaEpKB/7kEJEI5LlyoE40 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 Reviewed-by: Christian Brauner 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 --- 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);