From patchwork Tue Mar 14 22:07:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13175044 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 5BE73C6FD1F for ; Tue, 14 Mar 2023 22:08:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFE2D8E0002; Tue, 14 Mar 2023 18:08:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AAE918E0003; Tue, 14 Mar 2023 18:08:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 927B08E0002; Tue, 14 Mar 2023 18:08:17 -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 82E476B0071 for ; Tue, 14 Mar 2023 18:08:17 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 56187A42B3 for ; Tue, 14 Mar 2023 22:08:17 +0000 (UTC) X-FDA: 80568893034.26.A083815 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 8737D140008 for ; Tue, 14 Mar 2023 22:08:14 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GiNbBaSg; spf=pass (imf23.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=1678831694; 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=fEHZtUBR4B7sSEpj4V24Co6bhAobBEWGUt1eQB77Iqg=; b=ic1+BPyUOtQ8yaTiYOoqjTBqrVBjWr4M+jQMTWsfAxBqJlNiS4k+Bd9ukmxrARXXJkmMAl CbB3foo4rmlhbimij44pDZpIDFkcy8+xeuS/tF+px1PyjRdzjk/if9pFpi1NMnAFJmBkPr 8t1oXBCsfBB3s6SMkUmMmbJT2TzDTzk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GiNbBaSg; spf=pass (imf23.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=1678831694; a=rsa-sha256; cv=none; b=zPU/pk1xMARoXTDfI1OBxShhJF0H9cyt+0TjhpTFRouC5u/8gcZyExQw6Q6wxikulFDHCE vEhCaEJ/g9tPF3TedrTaYVh0KosjeQOCGmZ0YuOSPAR/d7RARiZIafmhDIKihUvxc/FXFH hZ1G7eHwqwfezzA8wJeBhLmKbR7Tcmo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831693; 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=fEHZtUBR4B7sSEpj4V24Co6bhAobBEWGUt1eQB77Iqg=; b=GiNbBaSghhcxzvdmL6iS8IcJZavYOXc/NxCR8hc7CocyipG82TM/pAbORFaQ/vpBu5+Nne yp07J2E1QydctJL83U5l5xuE3aUpPCKZKSFTi5CnA5/qcqEyfeTcOMw9P7/ywS9Yiwf8Rj 67MkCWP/+sIOKn8HdSar9DsWOIAUZ9g= 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-412-DdUmrbONMJOLxGdg1BeEdA-1; Tue, 14 Mar 2023 18:08:10 -0400 X-MC-Unique: DdUmrbONMJOLxGdg1BeEdA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D1B623806702; Tue, 14 Mar 2023 22:08:09 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6B8840C6E67; Tue, 14 Mar 2023 22:08:07 +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 v18 01/15] splice: Clean up direct_splice_read() a bit Date: Tue, 14 Mar 2023 22:07:43 +0000 Message-Id: <20230314220757.3827941-2-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8737D140008 X-Stat-Signature: 9jfe934xxgptudupkf6sqgot8n1eyb3s X-Rspam-User: X-HE-Tag: 1678831694-833384 X-HE-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UHTpNN83YueKrFe7pmTLjLGMuCSCljfIWUD8q2QCjqgymii7NdDs5QjAMnjQ9YpI/AneAfDi0agHHXrJH2sjEJliDF58XCx0+WEBB4/98qjw0syMceMIeFik/bzAYCV4fQJuZThAxSNXcGsN+WycUwD0MuDqeREBKypyx2EyHPcKhNZGKANEbfOTl3k/44gLMPf6gS898Ql+iLpNKy/nmfo4gWroYsUG6DYR80vXYrruwFdQSVwiKUwN4Pbks6ZMdszafFHCaUKtjV00D0sDYWp+pKDRPwUr9rLd5yF4oz4LGwDAahgnbBfzIqCE018C3PCn8JLwjtXRUBgPLW2iKTejmqxUqCFMS1wRaNV91GWG9LhCPHVZpqXL+WtAmjGqNDZGQN9X0FYTqyD1JvmjaQddQtd3fXrikfw== 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 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 --- 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);