From patchwork Wed Mar 15 16:35:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176333 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 88125C61DA4 for ; Wed, 15 Mar 2023 16:36:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CA466B0075; Wed, 15 Mar 2023 12:36:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17AF56B0078; Wed, 15 Mar 2023 12:36:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01B986B007B; Wed, 15 Mar 2023 12:36:04 -0400 (EDT) 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 E5D9E6B0075 for ; Wed, 15 Mar 2023 12:36:04 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A953DAB8B6 for ; Wed, 15 Mar 2023 16:36:04 +0000 (UTC) X-FDA: 80571684648.19.E92BE6F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 4D95914000F for ; Wed, 15 Mar 2023 16:36:02 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HSUrVCYu; spf=pass (imf26.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=1678898162; a=rsa-sha256; cv=none; b=esDLIYnwLH5mCmeONi3zILW5iHn39Ri3k5ITBT5rNqEIXKQ3U00JsyRs9yyNoXCpctPaWc y0CW7iFo5Y4+t+X0zO6b8o/1mpGtPBkOobMmyOdYrRt2VarsB61d1VleT/TiVcJgurL8ZB 8TLN7nl5q9zgAWt0dS08GOw8sfXGGFo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HSUrVCYu; spf=pass (imf26.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=1678898162; 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=VJzWDb/n/pMjELeQcZdjZNoFG9mKWRVEo4/2zQqbBeSsgMegNvbI6EG2qRrLjGtWZ2jJ4R d6pwe9dsqWD48odCh2VCHfLnHZq72YSfIcpHsyd/hJgBctTpJ6oBXcpsfiFP8bLq3YVAz2 7Mm+tu3UME6h/jaQS6wEhzf6/fjkPwQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898161; 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=HSUrVCYuVWzQ94ISqK4yiL55PIFlorse0niiDDscGX50Rh43co4F+XEsMWTzio9KUdSAfk ZeUkFLHjYFybeSXTJqOJagqP/h59VlDVs5W2mfY1/Lo5fjbi1RqWgADUJjzxuowu8sGw2q tI5oeHmBeb5e+AU9gMiXXsGcxqwS+cY= 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-202-Kzhf41MDNSGA4ALqB2MQAQ-1; Wed, 15 Mar 2023 12:35:57 -0400 X-MC-Unique: Kzhf41MDNSGA4ALqB2MQAQ-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 E32C2857F81; Wed, 15 Mar 2023 16:35:55 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id C33412166B26; Wed, 15 Mar 2023 16:35:53 +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 v19 01/15] splice: Clean up direct_splice_read() a bit Date: Wed, 15 Mar 2023 16:35:35 +0000 Message-Id: <20230315163549.295454-2-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Rspamd-Queue-Id: 4D95914000F X-Rspamd-Server: rspam01 X-Stat-Signature: dst7dw4ku9m3zwbej345tmdp3g61o1og X-HE-Tag: 1678898162-269358 X-HE-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5iT9WR4xVdQ4BxdGGuJ5EiqsBsx+e5hVok3fnQIpObP5TH6YAQRRBgbTMwdZszP6wwm7+a/n2SMqXr7h2dvmDK8fJkJyK1sZPHt+ycs1OpHV+BbYwj0kUTOEkLdRDYHC1incCk6XTDwUSWIli7tPwH52lffhBkpMV3Vlic+v5zCn5zCfQDfg5p5F/sUX3XLShkjb4G2YEw3+e1uiIJE0xBB5E3O2iWltRIYE9HEUFkZlKRePr/C8GbDQgJC5qaslVr8JoksfYh6pSObjrWVgzeXAhzph5ahT3ex8SN79selCcnRl7S5GZN5C+KlHxOuqMQ1c6+6f3piql09Ha+LUBIqwoGlLLbTRhKB1XT4C+BZ+AhaOy4SPBVddN5kJmDiHuma/qX275lSpVkbi2CPEXHMzMugTMODhP83qETpV7w== 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 Reviewed-by: David Hildenbrand --- 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);