All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: Fix dead loop in ext4_mb_new_blocks
@ 2020-09-09  6:40 Ye Bin
  2020-09-09  9:34 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Ye Bin @ 2020-09-09  6:40 UTC (permalink / raw)
  To: tytso, adilger.kernel, linux-ext4; +Cc: Ye Bin

As we test disk offline/online with running fsstress, we find fsstress
process is keeping running state.
kworker/u32:3-262   [004] ...1   140.787471: ext4_mb_discard_preallocations: dev 8,32 needed 114
....
kworker/u32:3-262   [004] ...1   140.787471: ext4_mb_discard_preallocations: dev 8,32 needed 114

Test step:
1. sysctl kernel.panic_on_oops=1
2. mkfs.ext4 -O^has_journal /dev/sdc
3. mount /dev/sdc -o errors=continue test
4. ./fsstress -d ./test/ -l 1000 -n 1000000 -p 1 &
5. run test script:
while true; do
        echo offline > /sys/block/sda/device/state
        sleep 0.05
        echo running > /sys/block/sda/device/state
done

ext4_mb_new_blocks
repeat:
	ext4_mb_discard_preallocations_should_retry(sb, ac, &seq)
		freed = ext4_mb_discard_preallocations
			ext4_mb_discard_group_preallocations
				this_cpu_inc(discard_pa_seq);
		---> freed == 0
		seq_retry = ext4_get_discard_pa_seq_sum
			for_each_possible_cpu(__cpu)
				__seq += per_cpu(discard_pa_seq, __cpu);
		if (seq_retry != *seq) {
			*seq = seq_retry;
			ret = true;
		}

As we see seq_retry is sum of discard_pa_seq every cpu, if
ext4_mb_discard_group_preallocations return zero discard_pa_seq in this
cpu maybe increase one, so condition "seq_retry != *seq" have always
been met.
To Fix this problem, ext4_get_discard_pa_seq_sum function couldn't add
own's cpu "discard_pa_seq" value.

Fixes: 07b5b8e1ac40 ("ext4: mballoc: introduce pcpu seqcnt for freeing PA to improve ENOSPC handling")
Signed-off-by: Ye Bin <yebin10@huawei.com>
---
 fs/ext4/mballoc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 132c118d12e1..168ea3e65da2 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -373,10 +373,12 @@ static DEFINE_PER_CPU(u64, discard_pa_seq);
 static inline u64 ext4_get_discard_pa_seq_sum(void)
 {
 	int __cpu;
+	int this_cpu = smp_processor_id();;
 	u64 __seq = 0;
 
 	for_each_possible_cpu(__cpu)
-		__seq += per_cpu(discard_pa_seq, __cpu);
+		if (this_cpu != __cpu)
+			__seq += per_cpu(discard_pa_seq, __cpu);
 	return __seq;
 }
 
-- 
2.25.4


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

* Re: [PATCH] ext4: Fix dead loop in ext4_mb_new_blocks
  2020-09-09  6:40 [PATCH] ext4: Fix dead loop in ext4_mb_new_blocks Ye Bin
@ 2020-09-09  9:34 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2020-09-09  9:34 UTC (permalink / raw)
  To: kbuild-all

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

Hi Ye,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on ext4/dev]
[also build test WARNING on linus/master v5.9-rc4 next-20200908]
[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/Ye-Bin/ext4-Fix-dead-loop-in-ext4_mb_new_blocks/20200909-144157
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: openrisc-randconfig-r016-20200909 (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.3.0
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
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=openrisc 

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

All warnings (new ones prefixed by >>):

   fs/ext4/mballoc.c: In function 'ext4_get_discard_pa_seq_sum':
>> fs/ext4/mballoc.c:377:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     377 |  u64 __seq = 0;
         |  ^~~

# https://github.com/0day-ci/linux/commit/8e252818fb9a7e69802f6927e5e2461b163f1d52
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ye-Bin/ext4-Fix-dead-loop-in-ext4_mb_new_blocks/20200909-144157
git checkout 8e252818fb9a7e69802f6927e5e2461b163f1d52
vim +377 fs/ext4/mballoc.c

c3a326a657562da Aneesh Kumar K.V 2008-11-25  353  
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  354  /*
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  355   * The algorithm using this percpu seq counter goes below:
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  356   * 1. We sample the percpu discard_pa_seq counter before trying for block
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  357   *    allocation in ext4_mb_new_blocks().
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  358   * 2. We increment this percpu discard_pa_seq counter when we either allocate
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  359   *    or free these blocks i.e. while marking those blocks as used/free in
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  360   *    mb_mark_used()/mb_free_blocks().
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  361   * 3. We also increment this percpu seq counter when we successfully identify
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  362   *    that the bb_prealloc_list is not empty and hence proceed for discarding
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  363   *    of those PAs inside ext4_mb_discard_group_preallocations().
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  364   *
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  365   * Now to make sure that the regular fast path of block allocation is not
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  366   * affected, as a small optimization we only sample the percpu seq counter
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  367   * on that cpu. Only when the block allocation fails and when freed blocks
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  368   * found were 0, that is when we sample percpu seq counter for all cpus using
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  369   * below function ext4_get_discard_pa_seq_sum(). This happens after making
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  370   * sure that all the PAs on grp->bb_prealloc_list got freed or if it's empty.
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  371   */
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  372  static DEFINE_PER_CPU(u64, discard_pa_seq);
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  373  static inline u64 ext4_get_discard_pa_seq_sum(void)
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  374  {
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  375  	int __cpu;
8e252818fb9a7e6 Ye Bin           2020-09-09  376  	int this_cpu = smp_processor_id();;
07b5b8e1ac4004b Ritesh Harjani   2020-05-20 @377  	u64 __seq = 0;
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  378  
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  379  	for_each_possible_cpu(__cpu)
8e252818fb9a7e6 Ye Bin           2020-09-09  380  		if (this_cpu != __cpu)
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  381  			__seq += per_cpu(discard_pa_seq, __cpu);
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  382  	return __seq;
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  383  }
07b5b8e1ac4004b Ritesh Harjani   2020-05-20  384  

---
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: 21199 bytes --]

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

end of thread, other threads:[~2020-09-09  9:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-09  6:40 [PATCH] ext4: Fix dead loop in ext4_mb_new_blocks Ye Bin
2020-09-09  9:34 ` 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.