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 21365C433E1 for ; Wed, 10 Jun 2020 20:39:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C8037206A4 for ; Wed, 10 Jun 2020 20:39:20 +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="abB0wGDo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8037206A4 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 87E5A8D0021; Wed, 10 Jun 2020 16:39:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 80A1D8D000E; Wed, 10 Jun 2020 16:39:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 680748D0021; Wed, 10 Jun 2020 16:39:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0106.hostedemail.com [216.40.44.106]) by kanga.kvack.org (Postfix) with ESMTP id 50C958D000E for ; Wed, 10 Jun 2020 16:39:17 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 18C62146F59 for ; Wed, 10 Jun 2020 20:39:17 +0000 (UTC) X-FDA: 76914467154.13.war20_060dd9f26dce Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id E06231813F3F1 for ; Wed, 10 Jun 2020 20:39:16 +0000 (UTC) X-HE-Tag: war20_060dd9f26dce X-Filterd-Recvd-Size: 7864 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Wed, 10 Jun 2020 20:39:16 +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=X3jPEAbYsbcdPk9lVXyvLsl+/O0MuFQGp8os2fJmDlE=; b=abB0wGDoYqPJf3a0kTiTdIqZhw O8Z2N2CbGR7yjgwE6PI/y1fk4DQuQ93VOyG1Cl++6rTIE8YVeRKpDQUq6BZnZ3ngX1lNMXCQ39pX5 htRAiPu9klOmqT/TyhlPSdfPHOvQ0gSaAC+MVfdzn207YMHp7m8D0Ij0qSYbxIr6tt+AUO9HNm46G a/VgbkdZ43HCD8fDGJeGLj4unnZFe0N4fMzMzHxrx5yunT2P+IAhsNf+qKdMwqiJl9Dic1sFL4hF+ n6H2DOGftvQjd7p8lippSF18uqHWUZAF+n/iiasPoIrTkfuI3uZ1eXFuiO4dbFoyi2i+OT7+wxz/H yHMBC1Dg==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jj76a-0003W2-Dl; 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 29/51] iomap: Support THPs in write paths Date: Wed, 10 Jun 2020 13:13:23 -0700 Message-Id: <20200610201345.13273-30-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: E06231813F3F1 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)" Use thp_size() instead of PAGE_SIZE and offset_in_thp() instead of offset_in_page(). Also simplify the logic in iomap_do_writepage() for determining end of file. Signed-off-by: Matthew Wilcox (Oracle) --- fs/iomap/buffered-io.c | 44 +++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index e445ee5f0521..9275268ea97e 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -460,7 +460,7 @@ iomap_is_partially_uptodate(struct page *page, unsign= ed long from, unsigned i; =20 /* Limit range to one page */ - len =3D min_t(unsigned, PAGE_SIZE - from, count); + len =3D min_t(unsigned, thp_size(page) - from, count); =20 /* First and last blocks in range within page */ first =3D from >> inode->i_blkbits; @@ -654,8 +654,8 @@ static ssize_t iomap_write_begin(struct inode *inode,= loff_t pos, loff_t len, else if (iomap->flags & IOMAP_F_BUFFER_HEAD) status =3D __block_write_begin_int(page, pos, len, NULL, srcmap); else - status =3D __iomap_write_begin(inode, pos, len, flags, page, - srcmap); + status =3D __iomap_write_begin(inode, pos, len, flags, + thp_head(page), srcmap); =20 if (status < 0) goto out_unlock; @@ -717,7 +717,7 @@ static size_t __iomap_write_end(struct inode *inode, = loff_t pos, size_t len, */ if (unlikely(copied < len && !PageUptodate(page))) return 0; - iomap_set_range_uptodate(page, offset_in_page(pos), len); + iomap_set_range_uptodate(page, offset_in_thp(page, pos), len); iomap_set_page_dirty(page); return copied; } @@ -753,7 +753,8 @@ static size_t iomap_write_end(struct inode *inode, lo= ff_t pos, size_t len, ret =3D block_write_end(NULL, inode->i_mapping, pos, len, copied, page, NULL); } else { - ret =3D __iomap_write_end(inode, pos, len, copied, page); + ret =3D __iomap_write_end(inode, pos, len, copied, + thp_head(page)); } =20 /* @@ -792,6 +793,10 @@ iomap_write_actor(struct inode *inode, loff_t pos, l= off_t length, void *data, unsigned long bytes; /* Bytes to write to page */ size_t copied; /* Bytes copied from user */ =20 + /* + * XXX: We don't know what size page we'll find in the + * page cache, so only copy up to a regular page boundary. + */ offset =3D offset_in_page(pos); bytes =3D min_t(unsigned long, PAGE_SIZE - offset, iov_iter_count(i)); @@ -1116,7 +1121,7 @@ iomap_finish_ioend(struct iomap_ioend *ioend, int e= rror) next =3D bio->bi_private; =20 /* walk each page on bio, ending page IO on them */ - bio_for_each_segment_all(bv, bio, iter_all) + bio_for_each_thp_segment_all(bv, bio, iter_all) iomap_finish_page_writeback(inode, bv->bv_page, error); bio_put(bio); } @@ -1322,7 +1327,7 @@ iomap_add_to_ioend(struct inode *inode, loff_t offs= et, struct page *page, { sector_t sector =3D iomap_sector(&wpc->iomap, offset); unsigned len =3D i_blocksize(inode); - unsigned poff =3D offset & (PAGE_SIZE - 1); + unsigned poff =3D offset & (thp_size(page) - 1); bool merged, same_page =3D false; =20 if (!wpc->ioend || !iomap_can_add_to_ioend(wpc, offset, sector)) { @@ -1372,8 +1377,9 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc= , struct iomap_page *iop =3D iomap_page_create(inode, page); struct iomap_ioend *ioend, *next; unsigned len =3D i_blocksize(inode); - u64 file_offset; /* file offset of page */ + loff_t pos; int error =3D 0, count =3D 0, i; + int nr_blocks =3D i_blocks_per_page(inode, page); LIST_HEAD(submit_list); =20 WARN_ON_ONCE(iop && atomic_read(&iop->write_count) !=3D 0); @@ -1383,20 +1389,20 @@ iomap_writepage_map(struct iomap_writepage_ctx *w= pc, * end of the current map or find the current map invalid, grab a new * one. */ - for (i =3D 0, file_offset =3D page_offset(page); - i < (PAGE_SIZE >> inode->i_blkbits) && file_offset < end_offset; - i++, file_offset +=3D len) { + for (i =3D 0, pos =3D page_offset(page); + i < nr_blocks && pos < end_offset; + i++, pos +=3D len) { if (iop && !test_bit(i, iop->uptodate)) continue; =20 - error =3D wpc->ops->map_blocks(wpc, inode, file_offset); + error =3D wpc->ops->map_blocks(wpc, inode, pos); if (error) break; if (WARN_ON_ONCE(wpc->iomap.type =3D=3D IOMAP_INLINE)) continue; if (wpc->iomap.type =3D=3D IOMAP_HOLE) continue; - iomap_add_to_ioend(inode, file_offset, page, iop, wpc, wbc, + iomap_add_to_ioend(inode, pos, page, iop, wpc, wbc, &submit_list); count++; } @@ -1478,7 +1484,6 @@ iomap_do_writepage(struct page *page, struct writeb= ack_control *wbc, void *data) { struct iomap_writepage_ctx *wpc =3D data; struct inode *inode =3D page->mapping->host; - pgoff_t end_index; u64 end_offset; loff_t offset; =20 @@ -1519,10 +1524,8 @@ iomap_do_writepage(struct page *page, struct write= back_control *wbc, void *data) * ---------------------------------^------------------| */ offset =3D i_size_read(inode); - end_index =3D offset >> PAGE_SHIFT; - if (page->index < end_index) - end_offset =3D (loff_t)(page->index + 1) << PAGE_SHIFT; - else { + end_offset =3D page_offset(page) + thp_size(page); + if (end_offset > offset) { /* * Check whether the page to write out is beyond or straddles * i_size or not. @@ -1534,7 +1537,8 @@ iomap_do_writepage(struct page *page, struct writeb= ack_control *wbc, void *data) * | | Straddles | * ---------------------------------^-----------|--------| */ - unsigned offset_into_page =3D offset & (PAGE_SIZE - 1); + unsigned offset_into_page =3D offset_in_thp(page, offset); + pgoff_t end_index =3D offset >> PAGE_SHIFT; =20 /* * Skip the page if it is fully outside i_size, e.g. due to a @@ -1565,7 +1569,7 @@ iomap_do_writepage(struct page *page, struct writeb= ack_control *wbc, void *data) * memory is zeroed when mapped, and writes to that region are * not written out to the file." */ - zero_user_segment(page, offset_into_page, PAGE_SIZE); + zero_user_segment(page, offset_into_page, thp_size(page)); =20 /* Adjust the end_offset to the end of file */ end_offset =3D offset; --=20 2.26.2