Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1560892ybg; Wed, 29 Jul 2020 18:19:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwA8zCqAFQK6/3kTBtx9/jLz5sGUwcGooilffBp1N71fxvcyoSHpyCDNzYIRmsVFW4Oi9Mw X-Received: by 2002:aa7:c6ce:: with SMTP id b14mr498210eds.208.1596071965713; Wed, 29 Jul 2020 18:19:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596071965; cv=none; d=google.com; s=arc-20160816; b=uTFhvGG6sSzbwxh40xfB41PuOWynpWDQdnThL02h6oErYt9ULxrMrg0TM2gFMTLObF 4tWGhW5ObxrVN4/qjtJt130ljgqxWgXpfqx6coxCGmfNPVXIS5zDt1SKYl4Jp/M+c40U O88HF3GsEMip/QwpXcvZHxBlNZJMEs/3Ky9++CQYfVQoihDiktLxp+APFnxIVwpg2Fgw 5aWX62drVd88BmWEHMjqn+g25HKhhLvPEEZ6CEleibfxgbxkZC66dJkQlLosyynBcwjZ dn3sk7fdydBq7yVASEmAzsoaSz6g2ROLTIe+iTc9LHpyIX4kVYUzPZNYbULOaHYH+9gx fV7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=sEWd/zFGMBSIbqSHVguuAsJbs7cr+7ByMe0c05CMseY=; b=JpjdPdPj11V/rlqbruTVFI1wNSyNrGInLrnBzRdH6HhN6eDpTkuACHu0DMEasTscFH /IpUZHcOnqhb9956BxuDBZn/WPL4SvINjnKCOzijzlxCU/bJu9NEXCkSTo2Eg6t/8vte f9VcjN8nsWVmt8i6Behjv4yBjdT7Rj+QqH6af6Kuzjk/nzy1TmwAovY9rGZ9zGngnLI4 geCgjiIpaQ0BfC9Xw8b91/8YT7OGK36WuydiNQwEKwJpJhzzCz5OIxMwq3yKYWc7OCWb CG/rLVTksQAg5+vB1nWVQ6/3E8/OXAAsnjuzHc739jpWzCSTdH3bwev4DteEsE6HxqNK k6xA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jz19si2302850ejb.133.2020.07.29.18.19.02; Wed, 29 Jul 2020 18:19:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726509AbgG3BS5 (ORCPT + 99 others); Wed, 29 Jul 2020 21:18:57 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:39260 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725851AbgG3BS5 (ORCPT ); Wed, 29 Jul 2020 21:18:57 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 4CD56A7A3968656C05A9; Thu, 30 Jul 2020 09:18:54 +0800 (CST) Received: from huawei.com (10.175.127.227) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Thu, 30 Jul 2020 09:18:45 +0800 From: Yu Kuai To: , CC: , , , , Subject: [RFC PATCH] iomap: add support to track dirty state of sub pages Date: Thu, 30 Jul 2020 09:19:01 +0800 Message-ID: <20200730011901.2840886-1-yukuai3@huawei.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit 9dc55f1389f9 ("iomap: add support for sub-pagesize buffered I/O without buffer heads") replace the per-block structure buffer_head with the per-page structure iomap_page. However, iomap_page can't track the dirty state of sub pages, which will cause performance issue since sub pages will be writeback even if they are not dirty. For example, if block size is 4k and page size is 64k: dd if=/dev/zero of=testfile bs=4k count=16 oflag=sync With buffer_head implementation, the above dd cmd will writeback 4k in each round. However, with iomap_page implementation, the range of writeback in each round is from the start of the page to the end offset we just wrote. Thus add support to track dirty state for sub pages in iomap_page. Signed-off-by: Yu Kuai --- fs/iomap/buffered-io.c | 51 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index bcfc288dba3f..ac2676146b98 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -29,7 +29,9 @@ struct iomap_page { atomic_t read_count; atomic_t write_count; spinlock_t uptodate_lock; + spinlock_t dirty_lock; DECLARE_BITMAP(uptodate, PAGE_SIZE / 512); + DECLARE_BITMAP(dirty, PAGE_SIZE / 512); }; static inline struct iomap_page *to_iomap_page(struct page *page) @@ -53,7 +55,9 @@ iomap_page_create(struct inode *inode, struct page *page) atomic_set(&iop->read_count, 0); atomic_set(&iop->write_count, 0); spin_lock_init(&iop->uptodate_lock); + spin_lock_init(&iop->dirty_lock); bitmap_zero(iop->uptodate, PAGE_SIZE / SECTOR_SIZE); + bitmap_zero(iop->dirty, PAGE_SIZE / SECTOR_SIZE); /* * migrate_page_move_mapping() assumes that pages with private data have @@ -135,6 +139,44 @@ iomap_adjust_read_range(struct inode *inode, struct iomap_page *iop, *lenp = plen; } +static void +iomap_iop_set_or_clear_range_dirty( + struct page *page, + unsigned int off, + unsigned int len, + bool is_set) +{ + struct iomap_page *iop = to_iomap_page(page); + struct inode *inode = page->mapping->host; + unsigned int first = off >> inode->i_blkbits; + unsigned int last = (off + len - 1) >> inode->i_blkbits; + unsigned long flags; + unsigned int i; + + spin_lock_irqsave(&iop->dirty_lock, flags); + for (i = first; i <= last; i++) + if (is_set) + set_bit(i, iop->dirty); + else + clear_bit(i, iop->dirty); + spin_unlock_irqrestore(&iop->dirty_lock, flags); +} + +static void +iomap_set_or_clear_range_dirty( + struct page *page, + unsigned int off, + unsigned int len, + bool is_set) +{ + if (PageError(page)) + return; + + if (page_has_private(page)) + iomap_iop_set_or_clear_range_dirty( + page, off, len, is_set); +} + static void iomap_iop_set_range_uptodate(struct page *page, unsigned off, unsigned len) { @@ -705,6 +747,8 @@ __iomap_write_end(struct inode *inode, loff_t pos, unsigned len, if (unlikely(copied < len && !PageUptodate(page))) return 0; iomap_set_range_uptodate(page, offset_in_page(pos), len); + iomap_set_or_clear_range_dirty( + page, offset_in_page(pos), len, true); iomap_set_page_dirty(page); return copied; } @@ -1030,6 +1074,8 @@ iomap_page_mkwrite_actor(struct inode *inode, loff_t pos, loff_t length, WARN_ON_ONCE(!PageUptodate(page)); iomap_page_create(inode, page); set_page_dirty(page); + iomap_set_or_clear_range_dirty( + page, offset_in_page(pos), length, true); } return length; @@ -1386,7 +1432,8 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc, for (i = 0, file_offset = page_offset(page); i < (PAGE_SIZE >> inode->i_blkbits) && file_offset < end_offset; i++, file_offset += len) { - if (iop && !test_bit(i, iop->uptodate)) + if (iop && (!test_bit(i, iop->uptodate) || + !test_bit(i, iop->dirty))) continue; error = wpc->ops->map_blocks(wpc, inode, file_offset); @@ -1435,6 +1482,8 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc, */ set_page_writeback_keepwrite(page); } else { + iomap_set_or_clear_range_dirty( + page, 0, end_offset - page_offset(page) + 1, false); clear_page_dirty_for_io(page); set_page_writeback(page); } -- 2.25.4