From mboxrd@z Thu Jan 1 00:00:00 1970 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 AEAE3C636D4 for ; Wed, 15 Feb 2023 13:47:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EF1B6B0074; Wed, 15 Feb 2023 08:47:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 29D976B0075; Wed, 15 Feb 2023 08:47:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 166266B0078; Wed, 15 Feb 2023 08:47:42 -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 090086B0074 for ; Wed, 15 Feb 2023 08:47:42 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D97B0140A2A for ; Wed, 15 Feb 2023 13:47:41 +0000 (UTC) X-FDA: 80469653922.18.179604D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id F2EF31A0024 for ; Wed, 15 Feb 2023 13:47:39 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LaS7j33C; spf=pass (imf19.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=1676468860; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=99QOKMb+AOrpDYfFG2DfoxFW2c4EvPytRBO6/OA6ny4=; b=X9gxOfc60+rC/6/dj1i0IcQwjcHLqCFOYljTb9yEngN1KkJ6R3IvYYY79t5jPz+yuOw1s1 Yui1LRDou8UFp8ky3l6CtdKSAKP3IE/4eQE5R3pcYnO7o8EAd9mLS2I/mvNyJUmSdCC26f JjcPZHeJ43gdDYhZMjTBrREfMSBEx8s= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LaS7j33C; spf=pass (imf19.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=1676468860; a=rsa-sha256; cv=none; b=G0DnqzcpGRfb8riwl0s+/Z4i2l8Z3piH8eBW8vrXO0x58tYdQdG7qGx+Ju0C5ZDnqBMLNf ILORJxM73NhnDdBfRyMrQdZm87yrhf84whgwxnnlzQd3fTdQwvRd9i3+pO8yNakDI2dost gNkf5YLnXXYOvqeLk7BPqJ3SOR5zLOU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676468859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=99QOKMb+AOrpDYfFG2DfoxFW2c4EvPytRBO6/OA6ny4=; b=LaS7j33CiWDJdjRRuQYaCCLkeFs3pD+OF9NWaP3op71eQzttbLLIB30isFuZfFaJXHKUpw 5glZm4pXmn0tq7Ro1MetgCoM3Lt0gTGOolZts3Ce3oXFVKqahFIah3SKfC90xZd3VWy2JQ 6yQY9USlZVa6n6Ad67dvLgKcOJZxlwE= 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-375-9aaqLuwxPfmRX3fDSqVpVw-1; Wed, 15 Feb 2023 08:47:36 -0500 X-MC-Unique: 9aaqLuwxPfmRX3fDSqVpVw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E4E8118A64E0; Wed, 15 Feb 2023 13:47:34 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A22040B40E4; Wed, 15 Feb 2023 13:47:32 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <3113838.1676468540@warthog.procyon.org.uk> References: <3113838.1676468540@warthog.procyon.org.uk> <20230209102954.528942-1-dhowells@redhat.com> <20230209102954.528942-2-dhowells@redhat.com> <909202.1675959337@warthog.procyon.org.uk> To: Christoph Hellwig Cc: dhowells@redhat.com, Matthew Wilcox , Jens Axboe , Al Viro , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzbot+a440341a59e3b7142895@syzkaller.appspotmail.com, Christoph Hellwig , John Hubbard Subject: Re: [PATCH] splice: Clean up direct_splice_read() a bit MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3114483.1676468851.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Wed, 15 Feb 2023 13:47:31 +0000 Message-ID: <3114484.1676468851@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Stat-Signature: djzagks3u54j7i5m1f1u15pdcxs6qzd4 X-Rspam-User: X-Rspamd-Queue-Id: F2EF31A0024 X-Rspamd-Server: rspam06 X-HE-Tag: 1676468859-379504 X-HE-Meta: U2FsdGVkX18hGNofKw1LU1t8qeAe6IMsj2mwaF+QniFGIeFnAaDPIyv01ZvwzscPfUTKJMv8V8CUItyS/wktK+FrKz/1KbvLtBUaRViUcjixA8o842y2AEXMhWYXBRG+Vhd3fKhOiVNXW44fW7e9J7vV7sbvzWLmemn+j0C7Y8DnkSvhwMyYMRdPQ5GlBqo+akAJp/PLiE3ugeKDhShTxZaNXyAPh8BSdQYRuD55lZeKsQpn/59KxQgT2FvNEBvZekIbvstNK4i6Zp7pXor8C0Q4F14AufVFA23RG5I9COr/cS13yPjGKrfU/LIGGMFbIhZ83GKiqRRHUNBd8mO3Y6Lj/L5CzZ+wj1liey2Yg0XoKKdTpNh4hVJWdIy5iNQ0ztMX+YobYqSR3J6sdK7KOziCAWHdlUEmbIGki0cKvbk06Vqizn43acsF0BApfF0Ipm9CNTEvjcbZ3mmeQnaV267j39N5CVyXjLQfNyuIhqbNOFyQUBcSrms/3PZ/Ee5LWYe2lHWZwKR/HvibhahbyXlfJYHrwA/LtWZiJOPbIDmXF0TT9if1SuNfolC8fawlWMZk/TKHUUe9T69i65qnKMk2gteDWFJK77UJBuurs/y2+a95nDRAYbGswExXeGTFsZlh1uIgnlDY07uYDEnIGkUgReC8Wi+qgcI/j+PVDvN/6ZJ488vQXjJPVLuHKyCiu+4y6t+MbdwKLE2TDd9cKVDq5Grawvt2gWL8Nznb++1w76MXWlwCjd0pcEwllamjbUAg2lohN4og5m/5MM9o96CGBMOMqIfgUd6OYw02EsTJxinkRPBHo18+GH8b/QE1T3cG3gzzD0h0vBvst5O6GO0iSazCp3VrxrLpzrAyCOooT7YDbbwKp6b1ri+4MAy35w+tJkxWkswdCP9UwyWVmknvOk7B3dKbPMcYqF98PqG84ogCbu3++aJuHvcITMnQve21wNqymwojo40+Zmx gC2rf6dc xoIiEBYCudcExvdPE8GddUDiCyU5JTfQNZSjzlQ9Y4o49yODwiwKCe9eGrV87hJlqbmyiFKIWdpKmoYggraz2/iqrPmt30m/OnjV0J5dcR6klNloiN2IOnxZ4yxV3ICPy8csZq2cs3yOY2WaRG6h8+N5XZ6a86sSqD1h/VGMRTD4qAtyIK9qik7jBeP1rp9qACPbxcSCfOtlxsOYsNWVeJs7XHQtAqPbtencddyhJQUFb++lMAPZzXkcTV1b3hATfWu0vnWEL2q72ff19w5yJjziZO58cZwGgqf68BCD51ooiajh+K9CplrpT6q67MG5sVCp7PCW1e6/7ns2caVq5Q1OtPZnGVjz+USPd+Q6XPvl+ge5TBNIZ2bMQUH8rXo3vXTOz0PBtx/cu4m3ITEk5zI7ug716SsCqhc5jAiIGplNbPom2zLQtznPIkV8wTvF1sB6j/9E+7KBI7FUpXAUT8XcAYpNyG9a6Xyv7R8Xk78UblLlPZOlmrhQUVeCKdcq3p8vTTetmAuIPzR/j/lP/0gO9V+zwpqz2IOeREFomReM6LYqYF/wdHHN4TNpk4dt3BjdWfIO9jNAjnKMrvNVbUkZKAXBrDSpMZZCW 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: I forgot to commit the cast change too. Try the attached instead. David --- splice: Clean up direct_splice_read() a bit 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 --- diff --git a/fs/splice.c b/fs/splice.c index 9e798c901087..e97f9aa30717 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -295,7 +295,7 @@ ssize_t direct_splice_read(struct file *in, loff_t *pp= os, struct kiocb kiocb; struct page **pages; ssize_t ret; - size_t used, npages, chunk, remain, reclaim; + size_t used, npages, chunk, remain, keep =3D 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 *pp= os, if (!bv) return -ENOMEM; = - pages =3D (void *)(bv + npages); + pages =3D (struct page **)(bv + npages); npages =3D 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 *p= pos, kiocb.ki_pos =3D *ppos; ret =3D call_read_iter(in, &kiocb, &to); = - reclaim =3D npages * PAGE_SIZE; - remain =3D 0; if (ret > 0) { - reclaim -=3D ret; - remain =3D ret; + keep =3D DIV_ROUND_UP(ret, PAGE_SIZE); *ppos =3D 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 /=3D PAGE_SIZE; - if (reclaim) { - npages -=3D reclaim; - release_pages(pages + npages, reclaim); - } + if (keep < npages) + release_pages(pages + keep, npages - keep); = /* Push the remaining pages into the pipe. */ - for (i =3D 0; i < npages; i++) { + remain =3D ret; + for (i =3D 0; i < keep; i++) { struct pipe_buffer *buf =3D pipe_head_buf(pipe); = chunk =3D min_t(size_t, remain, PAGE_SIZE);