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 X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D06B8C433DF for ; Wed, 10 Jun 2020 20:39:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 94E3D206A4 for ; Wed, 10 Jun 2020 20:39:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="OiAighL9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 94E3D206A4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C51318D0023; Wed, 10 Jun 2020 16:39:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B86198D000E; Wed, 10 Jun 2020 16:39:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2C9B8D0023; Wed, 10 Jun 2020 16:39:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0094.hostedemail.com [216.40.44.94]) by kanga.kvack.org (Postfix) with ESMTP id 8BE108D000E for ; Wed, 10 Jun 2020 16:39:21 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4F9B514767B for ; Wed, 10 Jun 2020 20:39:21 +0000 (UTC) X-FDA: 76914467322.02.move16_4f11cd826dce Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 2C59B147677 for ; Wed, 10 Jun 2020 20:39:21 +0000 (UTC) X-HE-Tag: move16_4f11cd826dce X-Filterd-Recvd-Size: 7309 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Wed, 10 Jun 2020 20:39:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=C9KNZLFkt8Tle4VaX/QjFZQwjCdLqmDjaJSbY4g1BBc=; b=OiAighL9mBrPMhnrkS/gqGty1F u+yNVja/T7n3ktY+YB0D0qaJCPfbXCZl+5ippi9ekL75UScg7fDbqZKZZfN8RISA5FApVLRtZbdg5 p0jd/PBsujMOChVBoe5Yno51GObGHDl00288vESYdf5iSJKEiH7iyWk5zCgBFto9+w9teXyQzL6hs eRHuA3fYJSvvczre/GDjn6fTWi0+rF5f1F0zwZFOTJtDR1b3TqOi3Glh1clzvypR6h2AZWUBEmf6J VqYU60h2wqrw0yz/hoFGCNB2yzIv9RcVmZBNol0fiYqT6bP6Vi7e0weWLFJWRUPFOBzhXVQ0OCLel hdP4QG6w==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jj76a-0003Vv-BK; Wed, 10 Jun 2020 20:13:48 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 28/51] iomap: Change iomap_write_begin calling convention Date: Wed, 10 Jun 2020 13:13:22 -0700 Message-Id: <20200610201345.13273-29-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200610201345.13273-1-willy@infradead.org> References: <20200610201345.13273-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2C59B147677 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 Content-Transfer-Encoding: quoted-printable 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: From: "Matthew Wilcox (Oracle)" Pass (up to) the remaining length of the extent to iomap_write_begin() and have it return the number of bytes that will fit in the page. That lets us copy more bytes per call to iomap_write_begin() if the page cache has already allocated a THP (and will in future allow us to pass a hint to the page cache that it should try to allocate a larger page if there are none in the cache). Signed-off-by: Matthew Wilcox (Oracle) --- fs/iomap/buffered-io.c | 63 +++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 8d690ad68657..e445ee5f0521 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -571,14 +571,14 @@ iomap_read_page_sync(loff_t block_start, struct pag= e *page, unsigned poff, return submit_bio_wait(&bio); } =20 -static int -__iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, int f= lags, - struct page *page, struct iomap *srcmap) +static ssize_t __iomap_write_begin(struct inode *inode, loff_t pos, + size_t len, int flags, struct page *page, struct iomap *srcmap) { loff_t block_size =3D i_blocksize(inode); loff_t block_start =3D pos & ~(block_size - 1); loff_t block_end =3D (pos + len + block_size - 1) & ~(block_size - 1); - unsigned from =3D offset_in_page(pos), to =3D from + len; + size_t from =3D offset_in_thp(page, pos); + size_t to =3D from + len; size_t poff, plen; int status; =20 @@ -614,12 +614,13 @@ __iomap_write_begin(struct inode *inode, loff_t pos= , unsigned len, int flags, return 0; } =20 -static int -iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigne= d flags, - struct page **pagep, struct iomap *iomap, struct iomap *srcmap) +static ssize_t iomap_write_begin(struct inode *inode, loff_t pos, loff_t= len, + unsigned flags, struct page **pagep, struct iomap *iomap, + struct iomap *srcmap) { const struct iomap_page_ops *page_ops =3D iomap->page_ops; struct page *page; + size_t offset; int status =3D 0; =20 BUG_ON(pos + len > iomap->offset + iomap->length); @@ -630,6 +631,8 @@ iomap_write_begin(struct inode *inode, loff_t pos, un= signed len, unsigned flags, return -EINTR; =20 if (page_ops && page_ops->page_prepare) { + if (len > UINT_MAX) + len =3D UINT_MAX; status =3D page_ops->page_prepare(inode, pos, len, iomap); if (status) return status; @@ -641,6 +644,10 @@ iomap_write_begin(struct inode *inode, loff_t pos, u= nsigned len, unsigned flags, status =3D -ENOMEM; goto out_no_page; } + page =3D thp_head(page); + offset =3D offset_in_thp(page, pos); + if (len > thp_size(page) - offset) + len =3D thp_size(page) - offset; =20 if (srcmap->type =3D=3D IOMAP_INLINE) iomap_read_inline_data(inode, page, srcmap); @@ -650,11 +657,11 @@ iomap_write_begin(struct inode *inode, loff_t pos, = unsigned len, unsigned flags, status =3D __iomap_write_begin(inode, pos, len, flags, page, srcmap); =20 - if (unlikely(status)) + if (status < 0) goto out_unlock; =20 *pagep =3D page; - return 0; + return len; =20 out_unlock: unlock_page(page); @@ -809,8 +816,10 @@ iomap_write_actor(struct inode *inode, loff_t pos, l= off_t length, void *data, =20 status =3D iomap_write_begin(inode, pos, bytes, 0, &page, iomap, srcmap); - if (unlikely(status)) + if (status < 0) break; + /* We may be partway through a THP */ + offset =3D offset_in_thp(page, pos); =20 if (mapping_writably_mapped(inode->i_mapping)) flush_dcache_page(page); @@ -872,8 +881,7 @@ static loff_t iomap_unshare_actor(struct inode *inode, loff_t pos, loff_t length, void= *data, struct iomap *iomap, struct iomap *srcmap) { - long status =3D 0; - ssize_t written =3D 0; + loff_t written =3D 0; =20 /* don't bother with blocks that are not shared to start with */ if (!(iomap->flags & IOMAP_F_SHARED)) @@ -883,25 +891,24 @@ iomap_unshare_actor(struct inode *inode, loff_t pos= , loff_t length, void *data, return length; =20 do { - unsigned long offset =3D offset_in_page(pos); - unsigned long bytes =3D min_t(loff_t, PAGE_SIZE - offset, length); struct page *page; + ssize_t bytes; =20 - status =3D iomap_write_begin(inode, pos, bytes, + bytes =3D iomap_write_begin(inode, pos, length, IOMAP_WRITE_F_UNSHARE, &page, iomap, srcmap); - if (unlikely(status)) - return status; + if (bytes < 0) + return bytes; =20 - status =3D iomap_write_end(inode, pos, bytes, bytes, page, iomap, + bytes =3D iomap_write_end(inode, pos, bytes, bytes, page, iomap, srcmap); - if (WARN_ON_ONCE(status =3D=3D 0)) + if (WARN_ON_ONCE(bytes =3D=3D 0)) return -EIO; =20 cond_resched(); =20 - pos +=3D status; - written +=3D status; - length -=3D status; + pos +=3D bytes; + written +=3D bytes; + length -=3D bytes; =20 balance_dirty_pages_ratelimited(inode->i_mapping); } while (length); @@ -932,15 +939,13 @@ static ssize_t iomap_zero(struct inode *inode, loff= _t pos, loff_t length, struct iomap *iomap, struct iomap *srcmap) { struct page *page; - int status; - unsigned offset =3D offset_in_page(pos); - unsigned bytes =3D min_t(loff_t, PAGE_SIZE - offset, length); + ssize_t bytes; =20 - status =3D iomap_write_begin(inode, pos, bytes, 0, &page, iomap, srcmap= ); - if (status) - return status; + bytes =3D iomap_write_begin(inode, pos, length, 0, &page, iomap, srcmap= ); + if (bytes < 0) + return bytes; =20 - zero_user(page, offset, bytes); + zero_user(page, offset_in_thp(page, pos), bytes); mark_page_accessed(page); =20 return iomap_write_end(inode, pos, bytes, bytes, page, iomap, srcmap); --=20 2.26.2