From patchwork Wed Mar 8 14:37:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13165936 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 350F0C64EC4 for ; Wed, 8 Mar 2023 14:38:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEC416B0074; Wed, 8 Mar 2023 09:38:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A9BEB6B0075; Wed, 8 Mar 2023 09:38:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93D246B0078; Wed, 8 Mar 2023 09:38:10 -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 85F5C6B0074 for ; Wed, 8 Mar 2023 09:38:10 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 60328A099F for ; Wed, 8 Mar 2023 14:38:10 +0000 (UTC) X-FDA: 80545985940.14.76706BB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 87AE4C0004 for ; Wed, 8 Mar 2023 14:38:07 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VvFHQb8p; spf=pass (imf22.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=1678286287; 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=lcI06Xw6coR/lrbTRKJZc2negLC1UBMM2xk91FfNd1sjT3S5X4JA28fi3R67zmVedtGNpX 3s7gXd9lGaYy26onuPsTO88fOVt4+pCiKzbNj24ELOOk+WUpFb7M+RPtuctobfJ9GBpNMo Ori6pHTOHvS0RLSmVtUokp13pEaeUvc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VvFHQb8p; spf=pass (imf22.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=1678286287; a=rsa-sha256; cv=none; b=N40dkKqfJ2n4GWouoo+KCAdQxrZdo3QCXJlRrztWxZaTbTKrXS5uDo8J3Osa4BwjNVtDCd l8m1/6UMkgxZBFfO5L0LeBGAagKtFicFpPSsJm721r//QEbvyRxe8nP6EMzGGIsFWM9nD0 0idbrnSK+hfS4LNjbswelBUBC7jNOPI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678286286; 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=VvFHQb8pdLfOvLL/lLP95S3DGaPgh++BEBAhDpKKJRCgMtQl45foWnFo4gGF7ms6b961rK zG4YYgTRq3croVPkEg2juxQCcyEKqKsGAcq3CEgbMRr8KJDymwaqoNoHA4/ragilrOQrgl nTSASzRs6+0j85ujsqb1YW6xVQaFN1o= 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-20-WwOWsJk3MvajoYgGpEO4_w-1; Wed, 08 Mar 2023 09:38:02 -0500 X-MC-Unique: WwOWsJk3MvajoYgGpEO4_w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B1438857A84; Wed, 8 Mar 2023 14:38:01 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACA4114171B6; Wed, 8 Mar 2023 14:37:59 +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 v16 01/13] splice: Clean up direct_splice_read() a bit Date: Wed, 8 Mar 2023 14:37:42 +0000 Message-Id: <20230308143754.1976726-2-dhowells@redhat.com> In-Reply-To: <20230308143754.1976726-1-dhowells@redhat.com> References: <20230308143754.1976726-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 87AE4C0004 X-Rspam-User: X-Stat-Signature: p7bbrodyim3zygwpbbryzo4xr9d1z5do X-HE-Tag: 1678286287-559509 X-HE-Meta: U2FsdGVkX1+GzcJBf2Sonm5LU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dDAia80s+OkGba/oG+KI/nNtbVvWr4myttFnDVMv18lGvElJfhCGEWCfmDEU/V2f38fNzDmlWVj+Q0+O8+W4wuZtPiOxRONvNks1uo+PxvSpdUpxCVRJn7fg4wqi7WBtSlX7HrL1BBcUoSC4abHg4wfB9pTLo8gX/OPGGHSApzDPxnhwhpXNROfYItYlnIrYSXPlh0hTbHzr+gmsddXiFDkJYSuOO5RHt1NqKb/x0IpRyOzTWQwN51WDPd8d3JKsFojvS79ctKM/SkiAR862xF8Pch9ZhIjx9neRh6qhf12Ur11uOKb49mzz6NKqEEokCn+FL61CLrTlXSHB3jWHSjh68/CFFtcEIwTwrNVSC0pEdlPJmCVB6cEMpvgK/GeOufPJ7dw/TyCc7Azgs/Q== 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 --- 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);