All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: reset retry counter when ext4_alloc_file_blocks() makes progress
@ 2021-01-13 22:14 Eric Whitney
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Whitney @ 2021-01-13 22:14 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, Eric Whitney

Change the retry policy in ext4_alloc_file_blocks() to allow for a full
retry cycle whenever a portion of an allocation request has been
fulfilled.  A large allocation request often results in multiple calls
to ext4_map_blocks(), each of which is potentially subject to a
temporary ENOSPC condition and retry cycle.  The current code only
allows for a single retry cycle.

This patch does not address a known bug or reported complaint.
However, it should make block allocation for fallocate and zero range
more robust.

In addition, simplify the conditional controlling the allocation while
loop, where testing len alone is sufficient.  Remove the assignment to
ret2 in the error path after the call to ext4_map_blocks() since its
value isn't subsequently used.

Signed-off-by: Eric Whitney <enwlinux@gmail.com>
---
 fs/ext4/extents.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 3960b7ec3ab7..77c7c8a54da7 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -4382,8 +4382,7 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
 {
 	struct inode *inode = file_inode(file);
 	handle_t *handle;
-	int ret = 0;
-	int ret2 = 0, ret3 = 0;
+	int ret, ret2 = 0, ret3 = 0;
 	int retries = 0;
 	int depth = 0;
 	struct ext4_map_blocks map;
@@ -4408,7 +4407,7 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
 	depth = ext_depth(inode);
 
 retry:
-	while (ret >= 0 && len) {
+	while (len) {
 		/*
 		 * Recalculate credits when extent tree depth changes.
 		 */
@@ -4430,9 +4429,13 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
 				   inode->i_ino, map.m_lblk,
 				   map.m_len, ret);
 			ext4_mark_inode_dirty(handle, inode);
-			ret2 = ext4_journal_stop(handle);
+			ext4_journal_stop(handle);
 			break;
 		}
+		/*
+		 * allow a full retry cycle for any remaining allocations
+		 */
+		retries = 0;
 		map.m_lblk += ret;
 		map.m_len = len = len - ret;
 		epos = (loff_t)map.m_lblk << inode->i_blkbits;
@@ -4450,11 +4453,8 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
 		if (unlikely(ret2))
 			break;
 	}
-	if (ret == -ENOSPC &&
-			ext4_should_retry_alloc(inode->i_sb, &retries)) {
-		ret = 0;
+	if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
 		goto retry;
-	}
 
 	return ret > 0 ? ret2 : ret;
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext4: reset retry counter when ext4_alloc_file_blocks() makes progress
@ 2021-01-14  4:49 kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2021-01-14  4:49 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 8613 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210113221403.18258-1-enwlinux@gmail.com>
References: <20210113221403.18258-1-enwlinux@gmail.com>
TO: Eric Whitney <enwlinux@gmail.com>
TO: linux-ext4(a)vger.kernel.org
CC: tytso(a)mit.edu
CC: Eric Whitney <enwlinux@gmail.com>

Hi Eric,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on ext4/dev]
[also build test WARNING on v5.11-rc3 next-20210113]
[cannot apply to tytso-fscrypt/master]
[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/Eric-Whitney/ext4-reset-retry-counter-when-ext4_alloc_file_blocks-makes-progress/20210114-101236
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
:::::: branch date: 3 hours ago
:::::: commit date: 3 hours ago
config: m68k-randconfig-m031-20210114 (attached as .config)
compiler: m68k-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/ext4/extents.c:4456 ext4_alloc_file_blocks() error: uninitialized symbol 'ret'.

Old smatch warnings:
fs/ext4/extents.c:2396 ext4_rereserve_cluster() warn: should '(1) << sbi->s_cluster_bits' be a 64 bit type?
fs/ext4/extents.c:5760 ext4_clu_mapped() warn: should 'lclu << sbi->s_cluster_bits' be a 64 bit type?
fs/ext4/extents.c:6009 ext4_ext_replay_set_iblocks() warn: should 'numblks << (inode->i_sb->s_blocksize_bits - 9)' be a 64 bit type?

vim +/ret +4456 fs/ext4/extents.c

a86c61812637c7dd Alex Tomas         2006-10-11  4378  
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4379  static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
c174e6d6979a04b7 Dmitry Monakhov    2014-08-27  4380  				  ext4_lblk_t len, loff_t new_size,
77a2e84d51729da7 Tahsin Erdogan     2017-08-05  4381  				  int flags)
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4382  {
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4383  	struct inode *inode = file_inode(file);
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4384  	handle_t *handle;
fb3666c305fccbd1 Eric Whitney       2021-01-13  4385  	int ret, ret2 = 0, ret3 = 0;
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4386  	int retries = 0;
4134f5c88dcd5b00 Lukas Czerner      2015-06-15  4387  	int depth = 0;
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4388  	struct ext4_map_blocks map;
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4389  	unsigned int credits;
c174e6d6979a04b7 Dmitry Monakhov    2014-08-27  4390  	loff_t epos;
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4391  
c3fe493ccdb1f443 Fabian Frederick   2016-09-15  4392  	BUG_ON(!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS));
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4393  	map.m_lblk = offset;
c174e6d6979a04b7 Dmitry Monakhov    2014-08-27  4394  	map.m_len = len;
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4395  	/*
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4396  	 * Don't normalize the request if it can fit in one extent so
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4397  	 * that it doesn't get unnecessarily split into multiple
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4398  	 * extents.
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4399  	 */
556615dcbf38b0a9 Lukas Czerner      2014-04-20  4400  	if (len <= EXT_UNWRITTEN_MAX_LEN)
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4401  		flags |= EXT4_GET_BLOCKS_NO_NORMALIZE;
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4402  
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4403  	/*
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4404  	 * credits to insert 1 extent into extent tree
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4405  	 */
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4406  	credits = ext4_chunk_trans_blocks(inode, len);
4134f5c88dcd5b00 Lukas Czerner      2015-06-15  4407  	depth = ext_depth(inode);
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4408  
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4409  retry:
fb3666c305fccbd1 Eric Whitney       2021-01-13  4410  	while (len) {
4134f5c88dcd5b00 Lukas Czerner      2015-06-15  4411  		/*
4134f5c88dcd5b00 Lukas Czerner      2015-06-15  4412  		 * Recalculate credits when extent tree depth changes.
4134f5c88dcd5b00 Lukas Czerner      2015-06-15  4413  		 */
011c88e36c26a085 Dan Carpenter      2016-12-03  4414  		if (depth != ext_depth(inode)) {
4134f5c88dcd5b00 Lukas Czerner      2015-06-15  4415  			credits = ext4_chunk_trans_blocks(inode, len);
4134f5c88dcd5b00 Lukas Czerner      2015-06-15  4416  			depth = ext_depth(inode);
4134f5c88dcd5b00 Lukas Czerner      2015-06-15  4417  		}
4134f5c88dcd5b00 Lukas Czerner      2015-06-15  4418  
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4419  		handle = ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS,
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4420  					    credits);
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4421  		if (IS_ERR(handle)) {
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4422  			ret = PTR_ERR(handle);
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4423  			break;
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4424  		}
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4425  		ret = ext4_map_blocks(handle, inode, &map, flags);
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4426  		if (ret <= 0) {
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4427  			ext4_debug("inode #%lu: block %u: len %u: "
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4428  				   "ext4_ext_map_blocks returned %d",
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4429  				   inode->i_ino, map.m_lblk,
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4430  				   map.m_len, ret);
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4431  			ext4_mark_inode_dirty(handle, inode);
fb3666c305fccbd1 Eric Whitney       2021-01-13  4432  			ext4_journal_stop(handle);
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4433  			break;
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4434  		}
fb3666c305fccbd1 Eric Whitney       2021-01-13  4435  		/*
fb3666c305fccbd1 Eric Whitney       2021-01-13  4436  		 * allow a full retry cycle for any remaining allocations
fb3666c305fccbd1 Eric Whitney       2021-01-13  4437  		 */
fb3666c305fccbd1 Eric Whitney       2021-01-13  4438  		retries = 0;
c174e6d6979a04b7 Dmitry Monakhov    2014-08-27  4439  		map.m_lblk += ret;
c174e6d6979a04b7 Dmitry Monakhov    2014-08-27  4440  		map.m_len = len = len - ret;
c174e6d6979a04b7 Dmitry Monakhov    2014-08-27  4441  		epos = (loff_t)map.m_lblk << inode->i_blkbits;
eeca7ea1baa939c9 Deepa Dinamani     2016-11-14  4442  		inode->i_ctime = current_time(inode);
c174e6d6979a04b7 Dmitry Monakhov    2014-08-27  4443  		if (new_size) {
c174e6d6979a04b7 Dmitry Monakhov    2014-08-27  4444  			if (epos > new_size)
c174e6d6979a04b7 Dmitry Monakhov    2014-08-27  4445  				epos = new_size;
c174e6d6979a04b7 Dmitry Monakhov    2014-08-27  4446  			if (ext4_update_inode_size(inode, epos) & 0x1)
c174e6d6979a04b7 Dmitry Monakhov    2014-08-27  4447  				inode->i_mtime = inode->i_ctime;
c174e6d6979a04b7 Dmitry Monakhov    2014-08-27  4448  		}
4209ae12b12265d4 Harshad Shirwadkar 2020-04-26  4449  		ret2 = ext4_mark_inode_dirty(handle, inode);
c894aa97577e47d3 Eryu Guan          2017-12-03  4450  		ext4_update_inode_fsync_trans(handle, inode, 1);
4209ae12b12265d4 Harshad Shirwadkar 2020-04-26  4451  		ret3 = ext4_journal_stop(handle);
4209ae12b12265d4 Harshad Shirwadkar 2020-04-26  4452  		ret2 = ret3 ? ret3 : ret2;
4209ae12b12265d4 Harshad Shirwadkar 2020-04-26  4453  		if (unlikely(ret2))
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4454  			break;
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4455  	}
fb3666c305fccbd1 Eric Whitney       2021-01-13 @4456  	if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4457  		goto retry;
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4458  
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4459  	return ret > 0 ? ret2 : ret;
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4460  }
0e8b6879f3c23403 Lukas Czerner      2014-03-18  4461  

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

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 18876 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-14  4:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13 22:14 [PATCH] ext4: reset retry counter when ext4_alloc_file_blocks() makes progress Eric Whitney
2021-01-14  4:49 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.