Thread (5 messages) 5 messages, 5 authors, 2020-08-19

Re: [PATCH] btrfs: switch btrfs_buffered_write() to page-by-page pace

From: kernel test robot <hidden>
Date: 2020-08-19 08:52:27
Also in: oe-kbuild-all

Hi Qu,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on v5.9-rc1 next-20200819]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Qu-Wenruo/btrfs-switch-btrfs_buffered_write-to-page-by-page-pace/20200819-135541
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
config: arm-randconfig-r022-20200818 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project b34b1e38381fa4d1b1d9751a6b5233b68e734cfe)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <redacted>

All warnings (new ones prefixed by >>):

   In file included from fs/btrfs/file.c:19:
   fs/btrfs/ctree.h:2265:8: warning: 'const' type qualifier on return type has no effect [-Wignored-qualifiers]
   size_t __const btrfs_get_num_csums(void);
          ^~~~~~~~
quoted
fs/btrfs/file.c:1570:24: warning: comparison of distinct pointer types ('typeof (iov_iter_count(i)) *' (aka 'unsigned int *') and 'typeof (((1UL) << 12) - offset) *' (aka 'unsigned long *')) [-Wcompare-distinct-pointer-types]
                   size_t write_bytes = min(iov_iter_count(i),
                                        ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:884:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(x, y, <)
                           ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:875:24: note: expanded from macro '__careful_cmp'
           __builtin_choose_expr(__safe_cmp(x, y), \
                                 ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:865:4: note: expanded from macro '__safe_cmp'
                   (__typecheck(x, y) && __no_side_effects(x, y))
                    ^~~~~~~~~~~~~~~~~
   include/linux/kernel.h:851:29: note: expanded from macro '__typecheck'
                   (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                              ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
   2 warnings generated.

# https://github.com/0day-ci/linux/commit/89f414f96d87eab3a1c3a3afc5283f80154e7a8b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Qu-Wenruo/btrfs-switch-btrfs_buffered_write-to-page-by-page-pace/20200819-135541
git checkout 89f414f96d87eab3a1c3a3afc5283f80154e7a8b
vim +1570 fs/btrfs/file.c

89f414f96d87ea Qu Wenruo          2020-08-19  1550  
e4af400a9c5081 Goldwyn Rodrigues  2018-06-17  1551  static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
e4af400a9c5081 Goldwyn Rodrigues  2018-06-17  1552  					       struct iov_iter *i)
39279cc3d2704c Chris Mason        2007-06-12  1553  {
e4af400a9c5081 Goldwyn Rodrigues  2018-06-17  1554  	struct file *file = iocb->ki_filp;
e4af400a9c5081 Goldwyn Rodrigues  2018-06-17  1555  	loff_t pos = iocb->ki_pos;
496ad9aa8ef448 Al Viro            2013-01-23  1556  	struct inode *inode = file_inode(file);
0b246afa62b0cf Jeff Mahoney       2016-06-22  1557  	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
89f414f96d87ea Qu Wenruo          2020-08-19  1558  	struct page *page = NULL;
364ecf3651e086 Qu Wenruo          2017-02-27  1559  	struct extent_changeset *data_reserved = NULL;
376cc685cb3b43 Miao Xie           2013-12-10  1560  	u64 lockstart;
376cc685cb3b43 Miao Xie           2013-12-10  1561  	u64 lockend;
d0215f3e5ebb58 Josef Bacik        2011-01-25  1562  	size_t num_written = 0;
c9149235a42ab9 Tsutomu Itoh       2011-03-30  1563  	int ret = 0;
7ee9e4405f264e Josef Bacik        2013-06-21  1564  	bool only_release_metadata = false;
b6316429af7f36 Josef Bacik        2011-09-30  1565  	bool force_page_uptodate = false;
4b46fce23349bf Josef Bacik        2010-05-23  1566  
d0215f3e5ebb58 Josef Bacik        2011-01-25  1567  	while (iov_iter_count(i) > 0) {
c67d970f0ea8dc Filipe Manana      2019-09-30  1568  		struct extent_state *cached_state = NULL;
7073017aeb98db Johannes Thumshirn 2018-12-05  1569  		size_t offset = offset_in_page(pos);
d0215f3e5ebb58 Josef Bacik        2011-01-25 @1570  		size_t write_bytes = min(iov_iter_count(i),
89f414f96d87ea Qu Wenruo          2020-08-19  1571  					 PAGE_SIZE - offset);
89f414f96d87ea Qu Wenruo          2020-08-19  1572  		size_t reserve_bytes = PAGE_SIZE;
d0215f3e5ebb58 Josef Bacik        2011-01-25  1573  		size_t copied;
79f015f216539d Goldwyn Rodrigues  2017-10-16  1574  		int extents_locked;
39279cc3d2704c Chris Mason        2007-06-12  1575  
914ee295af418e Xin Zhong          2010-12-09  1576  		/*
89f414f96d87ea Qu Wenruo          2020-08-19  1577  		 * Fault pages before locking them in prepare_page()
914ee295af418e Xin Zhong          2010-12-09  1578  		 * to avoid recursive lock
914ee295af418e Xin Zhong          2010-12-09  1579  		 */
d0215f3e5ebb58 Josef Bacik        2011-01-25  1580  		if (unlikely(iov_iter_fault_in_readable(i, write_bytes))) {
914ee295af418e Xin Zhong          2010-12-09  1581  			ret = -EFAULT;
d0215f3e5ebb58 Josef Bacik        2011-01-25  1582  			break;
914ee295af418e Xin Zhong          2010-12-09  1583  		}
914ee295af418e Xin Zhong          2010-12-09  1584  
a0e248bb502d51 Filipe Manana      2019-10-11  1585  		only_release_metadata = false;
d9d8b2a51a404c Qu Wenruo          2015-09-08  1586  
364ecf3651e086 Qu Wenruo          2017-02-27  1587  		extent_changeset_release(data_reserved);
36ea6f3e931391 Nikolay Borisov    2020-06-03  1588  		ret = btrfs_check_data_free_space(BTRFS_I(inode),
36ea6f3e931391 Nikolay Borisov    2020-06-03  1589  						  &data_reserved, pos,
364ecf3651e086 Qu Wenruo          2017-02-27  1590  						  write_bytes);
c6887cd11149d7 Josef Bacik        2016-03-25  1591  		if (ret < 0) {
89f414f96d87ea Qu Wenruo          2020-08-19  1592  			size_t tmp = write_bytes;
38d37aa9c32938 Qu Wenruo          2020-06-24  1593  			if (btrfs_check_nocow_lock(BTRFS_I(inode), pos,
89f414f96d87ea Qu Wenruo          2020-08-19  1594  						   &tmp) > 0) {
89f414f96d87ea Qu Wenruo          2020-08-19  1595  				ASSERT(tmp == write_bytes);
d9d8b2a51a404c Qu Wenruo          2015-09-08  1596  				/*
d9d8b2a51a404c Qu Wenruo          2015-09-08  1597  				 * For nodata cow case, no need to reserve
d9d8b2a51a404c Qu Wenruo          2015-09-08  1598  				 * data space.
d9d8b2a51a404c Qu Wenruo          2015-09-08  1599  				 */
7ee9e4405f264e Josef Bacik        2013-06-21  1600  				only_release_metadata = true;
89f414f96d87ea Qu Wenruo          2020-08-19  1601  				reserve_bytes = 0;
c6887cd11149d7 Josef Bacik        2016-03-25  1602  			} else {
d0215f3e5ebb58 Josef Bacik        2011-01-25  1603  				break;
c6887cd11149d7 Josef Bacik        2016-03-25  1604  			}
c6887cd11149d7 Josef Bacik        2016-03-25  1605  		}
1832a6d5ee3b1a Chris Mason        2007-12-21  1606  
9f3db423f98c5c Nikolay Borisov    2017-02-20  1607  		ret = btrfs_delalloc_reserve_metadata(BTRFS_I(inode),
9f3db423f98c5c Nikolay Borisov    2017-02-20  1608  				reserve_bytes);
7ee9e4405f264e Josef Bacik        2013-06-21  1609  		if (ret) {
7ee9e4405f264e Josef Bacik        2013-06-21  1610  			if (!only_release_metadata)
25ce28caaa1ddc Nikolay Borisov    2020-06-03  1611  				btrfs_free_reserved_data_space(BTRFS_I(inode),
bc42bda22345ef Qu Wenruo          2017-02-27  1612  						data_reserved, pos,
d9d8b2a51a404c Qu Wenruo          2015-09-08  1613  						write_bytes);
8257b2dc3c1a10 Miao Xie           2014-03-06  1614  			else
38d37aa9c32938 Qu Wenruo          2020-06-24  1615  				btrfs_check_nocow_unlock(BTRFS_I(inode));
7ee9e4405f264e Josef Bacik        2013-06-21  1616  			break;
7ee9e4405f264e Josef Bacik        2013-06-21  1617  		}
7ee9e4405f264e Josef Bacik        2013-06-21  1618  
376cc685cb3b43 Miao Xie           2013-12-10  1619  again:
89f414f96d87ea Qu Wenruo          2020-08-19  1620  		ret = prepare_one_page(inode, &page, pos, write_bytes,
b6316429af7f36 Josef Bacik        2011-09-30  1621  				       force_page_uptodate);
8b62f87bad9cf0 Josef Bacik        2017-10-19  1622  		if (ret) {
8b62f87bad9cf0 Josef Bacik        2017-10-19  1623  			btrfs_delalloc_release_extents(BTRFS_I(inode),
8702ba9396bf7b Qu Wenruo          2019-10-14  1624  						       reserve_bytes);
d0215f3e5ebb58 Josef Bacik        2011-01-25  1625  			break;
8b62f87bad9cf0 Josef Bacik        2017-10-19  1626  		}
39279cc3d2704c Chris Mason        2007-06-12  1627  
79f015f216539d Goldwyn Rodrigues  2017-10-16  1628  		extents_locked = lock_and_cleanup_extent_if_need(
89f414f96d87ea Qu Wenruo          2020-08-19  1629  				BTRFS_I(inode), &page, 1, pos, write_bytes,
89f414f96d87ea Qu Wenruo          2020-08-19  1630  				&lockstart, &lockend, &cached_state);
79f015f216539d Goldwyn Rodrigues  2017-10-16  1631  		if (extents_locked < 0) {
79f015f216539d Goldwyn Rodrigues  2017-10-16  1632  			if (extents_locked == -EAGAIN)
376cc685cb3b43 Miao Xie           2013-12-10  1633  				goto again;
8b62f87bad9cf0 Josef Bacik        2017-10-19  1634  			btrfs_delalloc_release_extents(BTRFS_I(inode),
8702ba9396bf7b Qu Wenruo          2019-10-14  1635  						       reserve_bytes);
79f015f216539d Goldwyn Rodrigues  2017-10-16  1636  			ret = extents_locked;
376cc685cb3b43 Miao Xie           2013-12-10  1637  			break;
376cc685cb3b43 Miao Xie           2013-12-10  1638  		}
376cc685cb3b43 Miao Xie           2013-12-10  1639  
89f414f96d87ea Qu Wenruo          2020-08-19  1640  		copied = iov_iter_copy_from_user_atomic(page, i, offset,
89f414f96d87ea Qu Wenruo          2020-08-19  1641  							write_bytes);
89f414f96d87ea Qu Wenruo          2020-08-19  1642  		flush_dcache_page(page);
56244ef151c3cd Chris Mason        2016-05-16  1643  
89f414f96d87ea Qu Wenruo          2020-08-19  1644  		if (!PageUptodate(page) && copied < write_bytes) {
b1bf862e9dad43 Chris Mason        2011-02-28  1645  			/*
89f414f96d87ea Qu Wenruo          2020-08-19  1646  			 * Short write on non-uptodate page, we must retry and
89f414f96d87ea Qu Wenruo          2020-08-19  1647  			 * force the page uptodate in next run.
b1bf862e9dad43 Chris Mason        2011-02-28  1648  			 */
89f414f96d87ea Qu Wenruo          2020-08-19  1649  			copied = 0;
b6316429af7f36 Josef Bacik        2011-09-30  1650  			force_page_uptodate = true;
b6316429af7f36 Josef Bacik        2011-09-30  1651  		} else {
89f414f96d87ea Qu Wenruo          2020-08-19  1652  			/* Next run doesn't need forced uptodate */
b6316429af7f36 Josef Bacik        2011-09-30  1653  			force_page_uptodate = false;
b6316429af7f36 Josef Bacik        2011-09-30  1654  		}
914ee295af418e Xin Zhong          2010-12-09  1655  
89f414f96d87ea Qu Wenruo          2020-08-19  1656  		iov_iter_advance(i, copied);
485290a734f142 Qu Wenruo          2015-10-29  1657  
89f414f96d87ea Qu Wenruo          2020-08-19  1658  		if (copied > 0) {
89f414f96d87ea Qu Wenruo          2020-08-19  1659  			ret = btrfs_dirty_pages(BTRFS_I(inode), &page, 1, pos,
89f414f96d87ea Qu Wenruo          2020-08-19  1660  						copied, &cached_state);
89f414f96d87ea Qu Wenruo          2020-08-19  1661  		} else {
89f414f96d87ea Qu Wenruo          2020-08-19  1662  			/* No bytes copied, need to free reserved space */
89f414f96d87ea Qu Wenruo          2020-08-19  1663  			if (only_release_metadata)
89f414f96d87ea Qu Wenruo          2020-08-19  1664  				btrfs_delalloc_release_metadata(BTRFS_I(inode),
89f414f96d87ea Qu Wenruo          2020-08-19  1665  						reserve_bytes, true);
89f414f96d87ea Qu Wenruo          2020-08-19  1666  			else
86d52921a2ba51 Nikolay Borisov    2020-06-03  1667  				btrfs_delalloc_release_space(BTRFS_I(inode),
89f414f96d87ea Qu Wenruo          2020-08-19  1668  						data_reserved, pos, write_bytes,
89f414f96d87ea Qu Wenruo          2020-08-19  1669  						true);
485290a734f142 Qu Wenruo          2015-10-29  1670  		}
914ee295af418e Xin Zhong          2010-12-09  1671  
c67d970f0ea8dc Filipe Manana      2019-09-30  1672  		/*
c67d970f0ea8dc Filipe Manana      2019-09-30  1673  		 * If we have not locked the extent range, because the range's
c67d970f0ea8dc Filipe Manana      2019-09-30  1674  		 * start offset is >= i_size, we might still have a non-NULL
c67d970f0ea8dc Filipe Manana      2019-09-30  1675  		 * cached extent state, acquired while marking the extent range
c67d970f0ea8dc Filipe Manana      2019-09-30  1676  		 * as delalloc through btrfs_dirty_pages(). Therefore free any
c67d970f0ea8dc Filipe Manana      2019-09-30  1677  		 * possible cached extent state to avoid a memory leak.
c67d970f0ea8dc Filipe Manana      2019-09-30  1678  		 */
79f015f216539d Goldwyn Rodrigues  2017-10-16  1679  		if (extents_locked)
376cc685cb3b43 Miao Xie           2013-12-10  1680  			unlock_extent_cached(&BTRFS_I(inode)->io_tree,
e43bbe5e16d87b David Sterba       2017-12-12  1681  					     lockstart, lockend, &cached_state);
c67d970f0ea8dc Filipe Manana      2019-09-30  1682  		else
c67d970f0ea8dc Filipe Manana      2019-09-30  1683  			free_extent_state(cached_state);
c67d970f0ea8dc Filipe Manana      2019-09-30  1684  
8702ba9396bf7b Qu Wenruo          2019-10-14  1685  		btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes);
f1de968376340c Miao Xie           2014-01-09  1686  		if (ret) {
89f414f96d87ea Qu Wenruo          2020-08-19  1687  			btrfs_drop_pages(&page, 1);
d0215f3e5ebb58 Josef Bacik        2011-01-25  1688  			break;
f1de968376340c Miao Xie           2014-01-09  1689  		}
39279cc3d2704c Chris Mason        2007-06-12  1690  
89f414f96d87ea Qu Wenruo          2020-08-19  1691  		if (only_release_metadata) {
38d37aa9c32938 Qu Wenruo          2020-06-24  1692  			btrfs_check_nocow_unlock(BTRFS_I(inode));
da17066c40472c Jeff Mahoney       2016-06-15  1693  			lockstart = round_down(pos,
0b246afa62b0cf Jeff Mahoney       2016-06-22  1694  					       fs_info->sectorsize);
89f414f96d87ea Qu Wenruo          2020-08-19  1695  			lockend = lockstart + PAGE_SIZE - 1;
7ee9e4405f264e Josef Bacik        2013-06-21  1696  
7ee9e4405f264e Josef Bacik        2013-06-21  1697  			set_extent_bit(&BTRFS_I(inode)->io_tree, lockstart,
7ee9e4405f264e Josef Bacik        2013-06-21  1698  				       lockend, EXTENT_NORESERVE, NULL,
7ee9e4405f264e Josef Bacik        2013-06-21  1699  				       NULL, GFP_NOFS);
7ee9e4405f264e Josef Bacik        2013-06-21  1700  		}
7ee9e4405f264e Josef Bacik        2013-06-21  1701  
89f414f96d87ea Qu Wenruo          2020-08-19  1702  		btrfs_drop_pages(&page, 1);
f1de968376340c Miao Xie           2014-01-09  1703  
d0215f3e5ebb58 Josef Bacik        2011-01-25  1704  		cond_resched();
d0215f3e5ebb58 Josef Bacik        2011-01-25  1705  
d0e1d66b5aa1ec Namjae Jeon        2012-12-11  1706  		balance_dirty_pages_ratelimited(inode->i_mapping);
cb843a6f513a1a Chris Mason        2008-10-03  1707  
914ee295af418e Xin Zhong          2010-12-09  1708  		pos += copied;
914ee295af418e Xin Zhong          2010-12-09  1709  		num_written += copied;
d0215f3e5ebb58 Josef Bacik        2011-01-25  1710  	}
39279cc3d2704c Chris Mason        2007-06-12  1711  
364ecf3651e086 Qu Wenruo          2017-02-27  1712  	extent_changeset_free(data_reserved);
d0215f3e5ebb58 Josef Bacik        2011-01-25  1713  	return num_written ? num_written : ret;
39279cc3d2704c Chris Mason        2007-06-12  1714  }
d0215f3e5ebb58 Josef Bacik        2011-01-25  1715  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help