All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v2 4/5] ext4: improve cr 0 / cr 1 group scanning
@ 2021-02-10  8:55 kernel test robot
  0 siblings, 0 replies; 17+ messages in thread
From: kernel test robot @ 2021-02-10  8:55 UTC (permalink / raw)
  To: kbuild

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

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210209202857.4185846-5-harshadshirwadkar@gmail.com>
References: <20210209202857.4185846-5-harshadshirwadkar@gmail.com>
TO: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
TO: linux-ext4(a)vger.kernel.org
CC: tytso(a)mit.edu
CC: bzzz(a)whamcloud.com
CC: artem.blagodarenko(a)gmail.com
CC: sihara(a)ddn.com
CC: adilger(a)dilger.ca
CC: Harshad Shirwadkar <harshadshirwadkar@gmail.com>

Hi Harshad,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on ext4/dev]
[also build test WARNING on v5.11-rc7 next-20210125]
[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/Harshad-Shirwadkar/ext4-drop-s_mb_bal_lock-and-convert-protected-fields-to-atomic/20210210-054647
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
:::::: branch date: 11 hours ago
:::::: commit date: 11 hours ago
config: s390-randconfig-m031-20210209 (attached as .config)
compiler: s390-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/mballoc.c:930 ext4_mb_choose_next_group_cr1() error: uninitialized symbol 'avg_fragment_size'.

Old smatch warnings:
fs/ext4/mballoc.c:1745 mb_free_blocks() warn: should 'block << sbi->s_cluster_bits' be a 64 bit type?
fs/ext4/mballoc.c:5139 ext4_mb_release_context() warn: should '(ac->ac_b_ex.fe_len) << sbi->s_cluster_bits' be a 64 bit type?
fs/ext4/mballoc.c:5273 ext4_mb_new_blocks() warn: should '(ar->len) << sbi->s_cluster_bits' be a 64 bit type?
fs/ext4/mballoc.c:5277 ext4_mb_new_blocks() warn: should '(ar->len) << sbi->s_cluster_bits' be a 64 bit type?
fs/ext4/mballoc.c:5277 ext4_mb_new_blocks() warn: should '(ar->len) << sbi->s_cluster_bits' be a 64 bit type?
fs/ext4/mballoc.c:5362 ext4_mb_new_blocks() warn: should '(inquota - ar->len) << sbi->s_cluster_bits' be a 64 bit type?
fs/ext4/mballoc.c:5811 ext4_free_blocks() warn: should 'count_clusters << sbi->s_cluster_bits' be a 64 bit type?

vim +/avg_fragment_size +930 fs/ext4/mballoc.c

ef4eebad9c018a Harshad Shirwadkar 2021-02-09  871  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  872  /*
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  873   * Choose next group by traversing average fragment size tree. Return 0 if next
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  874   * group was selected optimally. Return 1 if next group could not selected
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  875   * optimally (due to lock contention). Updates *new_cr if cr lvel needs an
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  876   * update.
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  877   */
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  878  static int ext4_mb_choose_next_group_cr1(struct ext4_allocation_context *ac,
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  879  		int *new_cr, ext4_group_t *group, ext4_group_t ngroups)
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  880  {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  881  	struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  882  	int avg_fragment_size, best_so_far;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  883  	struct rb_node *node, *found;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  884  	struct ext4_group_info *grp;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  885  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  886  	/*
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  887  	 * If there is contention on the lock, instead of waiting for the lock
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  888  	 * to become available, just continue searching lineraly. We'll resume
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  889  	 * our rb tree search later starting at ac->ac_last_optimal_group.
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  890  	 */
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  891  	if (!read_trylock(&sbi->s_mb_rb_lock))
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  892  		return 1;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  893  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  894  	if (ac->ac_flags & EXT4_MB_CR1_OPTIMIZED) {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  895  		/* We have found something at CR 1 in the past */
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  896  		grp = ext4_get_group_info(ac->ac_sb, ac->ac_last_optimal_group);
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  897  		for (found = rb_next(&grp->bb_avg_fragment_size_rb); found != NULL;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  898  		     found = rb_next(found)) {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  899  			grp = rb_entry(found, struct ext4_group_info,
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  900  				       bb_avg_fragment_size_rb);
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  901  			/*
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  902  			 * Perform this check without locking, we'll lock later
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  903  			 * to confirm.
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  904  			 */
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  905  			if (likely(ext4_mb_good_group(ac, grp->bb_group, 1)))
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  906  				break;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  907  		}
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  908  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  909  		goto done;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  910  	}
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  911  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  912  	node = sbi->s_mb_avg_fragment_size_root.rb_node;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  913  	best_so_far = 0;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  914  	found = NULL;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  915  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  916  	while (node) {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  917  		grp = rb_entry(node, struct ext4_group_info,
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  918  			       bb_avg_fragment_size_rb);
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  919  		/*
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  920  		 * Perform this check without locking, we'll lock later to confirm.
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  921  		 */
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  922  		if (ext4_mb_good_group(ac, grp->bb_group, 1)) {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  923  			avg_fragment_size = grp->bb_fragments ?
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  924  				grp->bb_free / grp->bb_fragments : 0;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  925  			if (!best_so_far || avg_fragment_size < best_so_far) {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  926  				best_so_far = avg_fragment_size;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  927  				found = node;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  928  			}
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  929  		}
ef4eebad9c018a Harshad Shirwadkar 2021-02-09 @930  		if (avg_fragment_size > ac->ac_g_ex.fe_len)
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  931  			node = node->rb_right;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  932  		else
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  933  			node = node->rb_left;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  934  	}
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  935  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  936  done:
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  937  	if (found) {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  938  		grp = rb_entry(found, struct ext4_group_info,
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  939  			       bb_avg_fragment_size_rb);
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  940  		*group = grp->bb_group;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  941  		ac->ac_flags |= EXT4_MB_CR1_OPTIMIZED;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  942  	} else {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  943  		*new_cr = 2;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  944  	}
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  945  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  946  	read_unlock(&sbi->s_mb_rb_lock);
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  947  	ac->ac_last_optimal_group = *group;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  948  	return 0;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  949  }
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  950  

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

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: [PATCH v2 4/5] ext4: improve cr 0 / cr 1 group scanning
@ 2021-02-10  7:04 kernel test robot
  0 siblings, 0 replies; 17+ messages in thread
From: kernel test robot @ 2021-02-10  7:04 UTC (permalink / raw)
  To: kbuild

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

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210209202857.4185846-5-harshadshirwadkar@gmail.com>
References: <20210209202857.4185846-5-harshadshirwadkar@gmail.com>
TO: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
TO: linux-ext4(a)vger.kernel.org
CC: tytso(a)mit.edu
CC: bzzz(a)whamcloud.com
CC: artem.blagodarenko(a)gmail.com
CC: sihara(a)ddn.com
CC: adilger(a)dilger.ca
CC: Harshad Shirwadkar <harshadshirwadkar@gmail.com>

Hi Harshad,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on ext4/dev]
[also build test WARNING on v5.11-rc7 next-20210125]
[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/Harshad-Shirwadkar/ext4-drop-s_mb_bal_lock-and-convert-protected-fields-to-atomic/20210210-054647
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
:::::: branch date: 9 hours ago
:::::: commit date: 9 hours ago
config: h8300-randconfig-s031-20210209 (attached as .config)
compiler: h8300-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-215-g0fb77bb6-dirty
        # https://github.com/0day-ci/linux/commit/ef4eebad9c018a972a470b7b41e68bc981b31d00
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Harshad-Shirwadkar/ext4-drop-s_mb_bal_lock-and-convert-protected-fields-to-atomic/20210210-054647
        git checkout ef4eebad9c018a972a470b7b41e68bc981b31d00
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=h8300 

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


"sparse warnings: (new ones prefixed by >>)"
>> fs/ext4/mballoc.c:946:9: sparse: sparse: context imbalance in 'ext4_mb_choose_next_group_cr1' - wrong count at exit
   fs/ext4/mballoc.c:1188:9: sparse: sparse: context imbalance in 'ext4_mb_init_cache' - different lock contexts for basic block
   fs/ext4/mballoc.c:2091:5: sparse: sparse: context imbalance in 'ext4_mb_try_best_found' - different lock contexts for basic block
   fs/ext4/mballoc.c:2119:5: sparse: sparse: context imbalance in 'ext4_mb_find_by_goal' - different lock contexts for basic block
   fs/ext4/mballoc.c:2407:12: sparse: sparse: context imbalance in 'ext4_mb_good_group_nolock' - wrong count at exit
   fs/ext4/mballoc.c:2619:43: sparse: sparse: context imbalance in 'ext4_mb_regular_allocator' - different lock contexts for basic block
   fs/ext4/mballoc.c:3277:17: sparse: sparse: context imbalance in 'ext4_mb_release' - different lock contexts for basic block
   fs/ext4/mballoc.c:3396:26: sparse: sparse: context imbalance in 'ext4_free_data_in_buddy' - wrong count at exit
   fs/ext4/mballoc.c:3612:15: sparse: sparse: context imbalance in 'ext4_mb_mark_diskspace_used' - different lock contexts for basic block
   fs/ext4/mballoc.c:3620:6: sparse: sparse: context imbalance in 'ext4_mb_mark_bb' - different lock contexts for basic block
   fs/ext4/mballoc.c:3943:13: sparse: sparse: context imbalance in 'ext4_discard_allocated_blocks' - different lock contexts for basic block
   fs/ext4/mballoc.c:4245:13: sparse: sparse: context imbalance in 'ext4_mb_put_pa' - different lock contexts for basic block
   fs/ext4/mballoc.c:4582:9: sparse: sparse: context imbalance in 'ext4_mb_discard_group_preallocations' - different lock contexts for basic block
   fs/ext4/mballoc.c:4735:9: sparse: sparse: context imbalance in 'ext4_discard_preallocations' - different lock contexts for basic block
   fs/ext4/mballoc.c:5030:9: sparse: sparse: context imbalance in 'ext4_mb_discard_lg_preallocations' - different lock contexts for basic block
   fs/ext4/mballoc.c:5675:9: sparse: sparse: context imbalance in 'ext4_free_blocks' - different lock contexts for basic block
   fs/ext4/mballoc.c:5975:15: sparse: sparse: context imbalance in 'ext4_group_add_blocks' - different lock contexts for basic block
   fs/ext4/mballoc.c: note: in included file (through include/linux/atomic.h, include/asm-generic/bitops/lock.h, arch/h8300/include/asm/bitops.h, ...):
   arch/h8300/include/asm/atomic.h:92:31: sparse: sparse: context imbalance in 'ext4_trim_extent' - wrong count at exit
   fs/ext4/mballoc.c:6039:1: sparse: sparse: context imbalance in 'ext4_trim_all_free' - different lock contexts for basic block
   fs/ext4/mballoc.c:6205:1: sparse: sparse: context imbalance in 'ext4_mballoc_query_range' - different lock contexts for basic block

vim +/ext4_mb_choose_next_group_cr1 +946 fs/ext4/mballoc.c

ef4eebad9c018a Harshad Shirwadkar 2021-02-09  871  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  872  /*
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  873   * Choose next group by traversing average fragment size tree. Return 0 if next
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  874   * group was selected optimally. Return 1 if next group could not selected
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  875   * optimally (due to lock contention). Updates *new_cr if cr lvel needs an
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  876   * update.
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  877   */
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  878  static int ext4_mb_choose_next_group_cr1(struct ext4_allocation_context *ac,
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  879  		int *new_cr, ext4_group_t *group, ext4_group_t ngroups)
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  880  {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  881  	struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  882  	int avg_fragment_size, best_so_far;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  883  	struct rb_node *node, *found;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  884  	struct ext4_group_info *grp;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  885  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  886  	/*
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  887  	 * If there is contention on the lock, instead of waiting for the lock
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  888  	 * to become available, just continue searching lineraly. We'll resume
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  889  	 * our rb tree search later starting at ac->ac_last_optimal_group.
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  890  	 */
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  891  	if (!read_trylock(&sbi->s_mb_rb_lock))
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  892  		return 1;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  893  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  894  	if (ac->ac_flags & EXT4_MB_CR1_OPTIMIZED) {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  895  		/* We have found something at CR 1 in the past */
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  896  		grp = ext4_get_group_info(ac->ac_sb, ac->ac_last_optimal_group);
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  897  		for (found = rb_next(&grp->bb_avg_fragment_size_rb); found != NULL;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  898  		     found = rb_next(found)) {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  899  			grp = rb_entry(found, struct ext4_group_info,
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  900  				       bb_avg_fragment_size_rb);
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  901  			/*
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  902  			 * Perform this check without locking, we'll lock later
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  903  			 * to confirm.
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  904  			 */
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  905  			if (likely(ext4_mb_good_group(ac, grp->bb_group, 1)))
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  906  				break;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  907  		}
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  908  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  909  		goto done;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  910  	}
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  911  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  912  	node = sbi->s_mb_avg_fragment_size_root.rb_node;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  913  	best_so_far = 0;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  914  	found = NULL;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  915  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  916  	while (node) {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  917  		grp = rb_entry(node, struct ext4_group_info,
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  918  			       bb_avg_fragment_size_rb);
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  919  		/*
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  920  		 * Perform this check without locking, we'll lock later to confirm.
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  921  		 */
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  922  		if (ext4_mb_good_group(ac, grp->bb_group, 1)) {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  923  			avg_fragment_size = grp->bb_fragments ?
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  924  				grp->bb_free / grp->bb_fragments : 0;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  925  			if (!best_so_far || avg_fragment_size < best_so_far) {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  926  				best_so_far = avg_fragment_size;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  927  				found = node;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  928  			}
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  929  		}
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  930  		if (avg_fragment_size > ac->ac_g_ex.fe_len)
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  931  			node = node->rb_right;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  932  		else
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  933  			node = node->rb_left;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  934  	}
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  935  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  936  done:
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  937  	if (found) {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  938  		grp = rb_entry(found, struct ext4_group_info,
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  939  			       bb_avg_fragment_size_rb);
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  940  		*group = grp->bb_group;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  941  		ac->ac_flags |= EXT4_MB_CR1_OPTIMIZED;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  942  	} else {
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  943  		*new_cr = 2;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  944  	}
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  945  
ef4eebad9c018a Harshad Shirwadkar 2021-02-09 @946  	read_unlock(&sbi->s_mb_rb_lock);
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  947  	ac->ac_last_optimal_group = *group;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  948  	return 0;
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  949  }
ef4eebad9c018a Harshad Shirwadkar 2021-02-09  950  

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

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Improve group scanning in mballoc
@ 2021-02-09 20:28 Harshad Shirwadkar
  2021-02-09 20:28 ` [PATCH v2 4/5] ext4: improve cr 0 / cr 1 group scanning Harshad Shirwadkar
  0 siblings, 1 reply; 17+ messages in thread
From: Harshad Shirwadkar @ 2021-02-09 20:28 UTC (permalink / raw)
  To: linux-ext4
  Cc: tytso, bzzz, artem.blagodarenko, sihara, adilger,
	Harshad Shirwadkar

This patch series improves cr 0 and cr 1 passes of the allocator
signficantly. Currently, at cr 0 and 1, we perform linear lookups to
find the matching groups. That's very inefficient for large file
systems where there are millions of block groups. At cr 0, we only
care about the groups that have the largest free order >= the
request's order and at cr 1 we only care about groups where average
fragment size > the request size. so, this patchset introduces new
data structures that allow us to perform cr 0 lookup in constant time
and cr 1 lookup in log (number of groups) time instead of linear.

For cr 0, we add a list for each order and all the groups are enqueued
to the appropriate list based on the largest free order in its buddy
bitmap. This allows us to lookup a match at cr 0 in constant time.

For cr 1, we add a new rb tree of groups sorted by largest fragment
size. This allows us to lookup a match for cr 1 in log (num groups)
time.

These optimizations can be enabled by passing "mb_optimize_scan" mount
option.

These changes may result in allocations to be spread across the block
device. While that would not matter some block devices (such as flash)
it may be a cause of concern for other block devices that benefit from
storing related content togetther such as disk. However, it can be
argued that in high fragmentation scenrio, especially for large disks,
it's still worth optimizing the scanning since in such cases, we get
cpu bound on group scanning instead of getting IO bound. Perhaps, in
future, we could dynamically turn this new optimization on based on
fragmentation levels for such devices.

Verified that there are no regressions in smoke tests (-g quick -c 4k).

Also, to demonstrate the effectiveness for the patch series, following
experiment was performed:

Created a highly fragmented disk of size 65TB. The disk had no
contiguous 2M regions. Following command was run consecutively for 3
times:

time dd if=/dev/urandom of=file bs=2M count=10

Here are the results with and without cr 0/1 optimizations:

|---------+------------------------------+---------------------------|
|         | Without CR 0/1 Optimizations | With CR 0/1 Optimizations |
|---------+------------------------------+---------------------------|
| 1st run | 5m1.871s                     | 2m47.642s                 |
| 2nd run | 2m28.390s                    | 0m0.611s                  |
| 3rd run | 2m26.530s                    | 0m1.255s                  |
|---------+------------------------------+---------------------------|

The patch [2/5] "ext4: add mballoc stats proc file" is a modified
version of the patch originally written by Artem Blagodarenko
(artem.blagodarenko@gmail.com). With that patch, I ran following
command with and without optimizations.

dd if=/dev/zero of=/mnt/file bs=2M count=2 conv=fsync

Without optimizations:
mballoc:
        reqs: 41
        success: 1
        groups_scanned: 63
        groups_considered: 20643620
        extents_scanned: 7851
                goal_hits: 0
                2^n_hits: 1
                breaks: 39
                lost: 0
        useless_c0_loops: 3
        useless_c1_loops: 39
        useless_c2_loops: 0
        useless_c3_loops: 0
        buddies_generated: 491561/491520
        buddies_time_used: 13078539152
        preallocated: 0
        discarded: 0

With optimizations:
mballoc:
        reqs: 42
        success: 1
        groups_scanned: 62
        groups_considered: 1011
        extents_scanned: 8062
                goal_hits: 0
                2^n_hits: 0
                breaks: 40
                lost: 0
        useless_c0_loops: 0
        useless_c1_loops: 0
        useless_c2_loops: 0
        useless_c3_loops: 0
        buddies_generated: 491561/491520
        buddies_time_used: 13165943648
        preallocated: 0
        discarded: 0

This shows that CR0 and CR1 optimizations get rid of useless CR0 and
CR1 loops altogether thereby significantly reducing the number of
groups that get considered.

Changes from V1:
---------------
- Incorporated Artem's patch that adds a few useful statistics for
  mballoc performace
- Added more fine grained locking for CR0 lists and CR1 tree
- Broke up ext4_mb_choose_next_group function to make code more
  readable
- Added a new mount option to provide a switch for these changes

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>

Harshad Shirwadkar (5):
  ext4: drop s_mb_bal_lock and convert protected fields to atomic
  ext4: add mballoc stats proc file
  ext4: add MB_NUM_ORDERS macro
  ext4: improve cr 0 / cr 1 group scanning
  ext4: add proc files to monitor new structures

 fs/ext4/ext4.h    |  23 ++-
 fs/ext4/mballoc.c | 477 +++++++++++++++++++++++++++++++++++++++++++---
 fs/ext4/mballoc.h |   7 +
 fs/ext4/super.c   |   6 +-
 fs/ext4/sysfs.c   |   4 +
 5 files changed, 485 insertions(+), 32 deletions(-)

-- 
2.30.0.478.g8a0d178c01-goog


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

end of thread, other threads:[~2021-02-26  4:43 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-10  8:55 [PATCH v2 4/5] ext4: improve cr 0 / cr 1 group scanning kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2021-02-10  7:04 kernel test robot
2021-02-09 20:28 Improve group scanning in mballoc Harshad Shirwadkar
2021-02-09 20:28 ` [PATCH v2 4/5] ext4: improve cr 0 / cr 1 group scanning Harshad Shirwadkar
2021-02-10  9:00   ` Dan Carpenter
2021-02-11  7:43   ` Alexey Lyashkov
2021-02-11  7:53     ` Alex Zhuravlev
2021-02-11 10:13       ` Alexey Lyashkov
2021-02-11 10:30   ` Andreas Dilger
2021-02-12 22:46   ` Andreas Dilger
2021-02-16 19:39   ` Благодаренко Артём
2021-02-16 22:36     ` Andreas Dilger
2021-02-22  3:59       ` harshad shirwadkar
2021-02-23 18:39         ` harshad shirwadkar
2021-02-26  3:43         ` Andreas Dilger
2021-02-26  4:06           ` harshad shirwadkar
2021-02-26  4:42             ` Andreas Dilger
2021-02-17 19:41   ` Благодаренко Артём

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.