From nobody Thu Sep 19 21:57:52 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D96E8C05027 for ; Thu, 9 Feb 2023 10:32:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229487AbjBIKcZ (ORCPT ); Thu, 9 Feb 2023 05:32:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbjBIKbg (ORCPT ); Thu, 9 Feb 2023 05:31:36 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8869F19F24 for ; Thu, 9 Feb 2023 02:30:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675938623; 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=PwfaTp9eGrV7iL5hQ8gz8NVeVdzWatLunSphj9wOeU8=; b=TI+11T13Udj6hWFtIDMuwypib0toO226oCxLnpKPA3CEfFOMbmF1K27GzD0SnaHHN18HZl +3AhDcavAaLh1FH+fZHx+0jalIqW3NMrxWk5cHZXnS0NpRaUl88TJcML34N7Cz3G7cu+iH skx/5VcEyD4TyUfdLKJOLUY1Y+ctwn4= 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-159-9nBR7GipO8SN11GsW6sDPQ-1; Thu, 09 Feb 2023 05:30:20 -0500 X-MC-Unique: 9nBR7GipO8SN11GsW6sDPQ-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 3C19E1871D9B; Thu, 9 Feb 2023 10:30:04 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D5E640C83B6; Thu, 9 Feb 2023 10:30:02 +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 , 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 v13 02/12] mm: Pass info, not iter, into filemap_get_pages() and unstatic it Date: Thu, 9 Feb 2023 10:29:44 +0000 Message-Id: <20230209102954.528942-3-dhowells@redhat.com> In-Reply-To: <20230209102954.528942-1-dhowells@redhat.com> References: <20230209102954.528942-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" filemap_get_pages() and a number of functions that it calls take an iterator to provide two things: the number of bytes to be got from the file specified and whether partially uptodate pages are allowed. Change these functions so that this information is passed in directly. This allows it to be called without having an iterator to hand. Also make filemap_get_pages() available so that it can be used by a later patch to fix splicing from a buffered file. Signed-off-by: David Howells cc: Jens Axboe cc: Christoph Hellwig cc: Matthew Wilcox 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 --- include/linux/pagemap.h | 2 ++ mm/filemap.c | 31 ++++++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 29e1f9e76eb6..3a7bdb35acff 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -748,6 +748,8 @@ struct page *read_cache_page(struct address_space *, pg= off_t index, filler_t *filler, struct file *file); extern struct page * read_cache_page_gfp(struct address_space *mapping, pgoff_t index, gfp_t gfp_mask); +int filemap_get_pages(struct kiocb *iocb, size_t count, + struct folio_batch *fbatch, bool need_uptodate); =20 static inline struct page *read_mapping_page(struct address_space *mapping, pgoff_t index, struct file *file) diff --git a/mm/filemap.c b/mm/filemap.c index c4d4ace9cc70..b31168a9bafd 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2440,21 +2440,19 @@ static int filemap_read_folio(struct file *file, fi= ller_t filler, } =20 static bool filemap_range_uptodate(struct address_space *mapping, - loff_t pos, struct iov_iter *iter, struct folio *folio) + loff_t pos, size_t count, struct folio *folio, + bool need_uptodate) { - int count; - if (folio_test_uptodate(folio)) return true; /* pipes can't handle partially uptodate pages */ - if (iov_iter_is_pipe(iter)) + if (need_uptodate) return false; if (!mapping->a_ops->is_partially_uptodate) return false; if (mapping->host->i_blkbits >=3D folio_shift(folio)) return false; =20 - count =3D iter->count; if (folio_pos(folio) > pos) { count -=3D folio_pos(folio) - pos; pos =3D 0; @@ -2466,8 +2464,8 @@ static bool filemap_range_uptodate(struct address_spa= ce *mapping, } =20 static int filemap_update_page(struct kiocb *iocb, - struct address_space *mapping, struct iov_iter *iter, - struct folio *folio) + struct address_space *mapping, size_t count, + struct folio *folio, bool need_uptodate) { int error; =20 @@ -2501,7 +2499,8 @@ static int filemap_update_page(struct kiocb *iocb, goto unlock; =20 error =3D 0; - if (filemap_range_uptodate(mapping, iocb->ki_pos, iter, folio)) + if (filemap_range_uptodate(mapping, iocb->ki_pos, count, folio, + need_uptodate)) goto unlock; =20 error =3D -EAGAIN; @@ -2577,8 +2576,12 @@ static int filemap_readahead(struct kiocb *iocb, str= uct file *file, return 0; } =20 -static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter, - struct folio_batch *fbatch) +/* + * Extract some folios from the pagecache of a file, reading those pages f= rom + * the backing store if necessary and waiting for them. + */ +int filemap_get_pages(struct kiocb *iocb, size_t count, + struct folio_batch *fbatch, bool need_uptodate) { struct file *filp =3D iocb->ki_filp; struct address_space *mapping =3D filp->f_mapping; @@ -2588,7 +2591,7 @@ static int filemap_get_pages(struct kiocb *iocb, stru= ct iov_iter *iter, struct folio *folio; int err =3D 0; =20 - last_index =3D DIV_ROUND_UP(iocb->ki_pos + iter->count, PAGE_SIZE); + last_index =3D DIV_ROUND_UP(iocb->ki_pos + count, PAGE_SIZE); retry: if (fatal_signal_pending(current)) return -EINTR; @@ -2621,7 +2624,8 @@ static int filemap_get_pages(struct kiocb *iocb, stru= ct iov_iter *iter, if ((iocb->ki_flags & IOCB_WAITQ) && folio_batch_count(fbatch) > 1) iocb->ki_flags |=3D IOCB_NOWAIT; - err =3D filemap_update_page(iocb, mapping, iter, folio); + err =3D filemap_update_page(iocb, mapping, count, folio, + need_uptodate); if (err) goto err; } @@ -2691,7 +2695,8 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_i= ter *iter, if (unlikely(iocb->ki_pos >=3D i_size_read(inode))) break; =20 - error =3D filemap_get_pages(iocb, iter, &fbatch); + error =3D filemap_get_pages(iocb, iter->count, &fbatch, + iov_iter_is_pipe(iter)); if (error < 0) break;