From patchwork Wed Mar 8 16:52:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13166143 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 1BD68C64EC4 for ; Wed, 8 Mar 2023 16:53:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AF976B007B; Wed, 8 Mar 2023 11:53:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 838A36B007D; Wed, 8 Mar 2023 11:53:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B17D6B007E; Wed, 8 Mar 2023 11:53:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 51EE06B007B for ; Wed, 8 Mar 2023 11:53:10 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E51EC1C6760 for ; Wed, 8 Mar 2023 16:53:09 +0000 (UTC) X-FDA: 80546326098.25.9964823 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 323F640019 for ; Wed, 8 Mar 2023 16:53:07 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="hTMhpU9/"; spf=pass (imf12.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=1678294387; 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=dL8s47Tp1nK8GIg8PijNkCrDLEgPha2fkCIMRUXm1zk=; b=R+GE1yrrN4aiIr/aRSKZZ77uul/BndOYqgtvNQpMza+vmXmiO+YZ3ha3E6JvSRWzeuxpnj p1MOBrL/IGeMuGV0ALTGM7Tp0rKTBn7+Zycu+v2tzwXs+2slggz52koT0R1VHFJxZo8lbc xp+hCzOUuaEZbTCPtZbXtrq3/PzTvFY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="hTMhpU9/"; spf=pass (imf12.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=1678294387; a=rsa-sha256; cv=none; b=RrYZtv9GsoXfggzgcOB2QZSYPAnSzGEbabSSsbzSGi/DGowpAmPQgEIFcUQbxcRBNyb3JF dyDBZ52CR2aWKgBLDXbf7kArq+926OyNY/M2rgnvJu9hPeFl8O0RbePtYKIvQV52mds7sE 4azAcG6B8SjY9nWhnz1QgeZCGxw2vT4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678294386; 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=dL8s47Tp1nK8GIg8PijNkCrDLEgPha2fkCIMRUXm1zk=; b=hTMhpU9/JD0HBvjCuHgXAMJK4XcAjZlC0neCx+1s1T5MwxKOIPRPPYSiXLp/1H1PiQcILL l1m9VsdA7zRHIC/0cQP6dtoQiD4WNJgFSnM6JlzHmtbrzNVpL03clSunYlN0Yjez/mWbqm WWWaMMxAI+323FuVCX9yooZ54WMChb4= 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-609-Q9XiGVkBM5CVEEGBMEseQA-1; Wed, 08 Mar 2023 11:53:02 -0500 X-MC-Unique: Q9XiGVkBM5CVEEGBMEseQA-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 0ADFE2810C15; Wed, 8 Mar 2023 16:53:01 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08E1F492B04; Wed, 8 Mar 2023 16:52:58 +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 , 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 v17 01/14] splice: Clean up direct_splice_read() a bit Date: Wed, 8 Mar 2023 16:52:38 +0000 Message-Id: <20230308165251.2078898-2-dhowells@redhat.com> In-Reply-To: <20230308165251.2078898-1-dhowells@redhat.com> References: <20230308165251.2078898-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Stat-Signature: ukqr9huwygpb81a88cf96mhw7m3hmx6r X-Rspam-User: X-Rspamd-Queue-Id: 323F640019 X-Rspamd-Server: rspam06 X-HE-Tag: 1678294386-812316 X-HE-Meta: U2FsdGV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ERfpFam9OSf/ygdBRbs1PzXD+L55iry8lxUAOfxTbHoE8eKG4bmXknTahRsLNRE39GBtxctD9ppEqv7qEsOPnUKtAR8wmEAtpJoc74/bQmSklho8wcHS7c7441/RhoNLezrLjxp4gB8elDXSaCL3tuYeMPTsrkQjfyW+LF7TvypkcCeMnzv8mDzaswdZey/Rp/mtiZayTir+AkCFSNrUY1UtcgXJRlky/GOAv7HV8zjOjQZIMnVjjnQRRIv38n7fqaR3j+y7+qC1CeafjnMYWst18j/TE4xUPE1Sc8MTiJ1BSCskP6h2LQ86MkELM73p7+MaZx1OihHSTSh9Mw6Uj5smPv8PsKVcnYPUe+/pc3iATE/CtJM9b5/ya4CQsbw4du+OHdwVA== 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 direct_splice_read(): (1) Cast to struct page **, not void *. (2) Simplify the calculation of the number of pages to keep/reclaim in direct_splice_read(). Suggested-by: Christoph Hellwig Signed-off-by: David Howells cc: Jens Axboe cc: Christoph Hellwig 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: Christoph Hellwig --- fs/splice.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 2e76dbb81a8f..abd21a455a2b 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -295,7 +295,7 @@ ssize_t direct_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 */ @@ -309,7 +309,7 @@ ssize_t direct_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); @@ -332,11 +332,8 @@ ssize_t direct_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) { @@ -349,14 +346,12 @@ ssize_t direct_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);