linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Благодаренко Артём" <artem.blagodarenko@gmail.com>
To: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Cc: linux-ext4@vger.kernel.org, "Theodore Y. Ts'o" <tytso@mit.edu>,
	bzzz@whamcloud.com, sihara@ddn.com,
	Andreas Dilger <adilger@dilger.ca>
Subject: Re: [PATCH v2 3/5] ext4: add MB_NUM_ORDERS macro
Date: Tue, 16 Feb 2021 13:45:26 +0300	[thread overview]
Message-ID: <1029810C-1D3F-45ED-9EF3-EF85C31AE81B@gmail.com> (raw)
In-Reply-To: <20210209202857.4185846-4-harshadshirwadkar@gmail.com>

Hello Harshad,

I believe there are two places yet there number could be changed to the macros

fs/ext4/mballoc.c <<ext4_mb_init_cache>>
             (sb->s_blocksize_bits+2));

fs/ext4/mballoc.c <<ext4_mb_good_group>>
if (ac->ac_2order > ac->ac_sb->s_blocksize_bits+1)

Best regards,
Artem Blagodarenko

> On 9 Feb 2021, at 23:28, Harshad Shirwadkar <harshadshirwadkar@gmail.com> wrote:
> 
> A few arrays in mballoc.c use the total number of valid orders as
> their size. Currently, this value is set as "sb->s_blocksize_bits +
> 2". This makes code harder to read. So, instead add a new macro
> MB_NUM_ORDERS(sb) to make the code more readable.
> 
> Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
> ---
> fs/ext4/mballoc.c | 15 ++++++++-------
> fs/ext4/mballoc.h |  5 +++++
> 2 files changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index fffd0770e930..b7f25120547d 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -756,7 +756,7 @@ mb_set_largest_free_order(struct super_block *sb, struct ext4_group_info *grp)
> 
> 	grp->bb_largest_free_order = -1; /* uninit */
> 
> -	bits = sb->s_blocksize_bits + 1;
> +	bits = MB_NUM_ORDERS(sb) - 1;
> 	for (i = bits; i >= 0; i--) {
> 		if (grp->bb_counters[i] > 0) {
> 			grp->bb_largest_free_order = i;
> @@ -1928,7 +1928,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
> 	int max;
> 
> 	BUG_ON(ac->ac_2order <= 0);
> -	for (i = ac->ac_2order; i <= sb->s_blocksize_bits + 1; i++) {
> +	for (i = ac->ac_2order; i < MB_NUM_ORDERS(sb); i++) {
> 		if (grp->bb_counters[i] == 0)
> 			continue;
> 
> @@ -2314,13 +2314,13 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
> 	 * We also support searching for power-of-two requests only for
> 	 * requests upto maximum buddy size we have constructed.
> 	 */
> -	if (i >= sbi->s_mb_order2_reqs && i <= sb->s_blocksize_bits + 2) {
> +	if (i >= sbi->s_mb_order2_reqs && i <= MB_NUM_ORDERS(sb)) {
> 		/*
> 		 * This should tell if fe_len is exactly power of 2
> 		 */
> 		if ((ac->ac_g_ex.fe_len & (~(1 << (i - 1)))) == 0)
> 			ac->ac_2order = array_index_nospec(i - 1,
> -							   sb->s_blocksize_bits + 2);
> +							   MB_NUM_ORDERS(sb));
> 	}
> 
> 	/* if stream allocation is enabled, use global goal */
> @@ -2850,7 +2850,7 @@ int ext4_mb_init(struct super_block *sb)
> 	unsigned max;
> 	int ret;
> 
> -	i = (sb->s_blocksize_bits + 2) * sizeof(*sbi->s_mb_offsets);
> +	i = MB_NUM_ORDERS(sb) * sizeof(*sbi->s_mb_offsets);
> 
> 	sbi->s_mb_offsets = kmalloc(i, GFP_KERNEL);
> 	if (sbi->s_mb_offsets == NULL) {
> @@ -2858,7 +2858,7 @@ int ext4_mb_init(struct super_block *sb)
> 		goto out;
> 	}
> 
> -	i = (sb->s_blocksize_bits + 2) * sizeof(*sbi->s_mb_maxs);
> +	i = MB_NUM_ORDERS(sb) * sizeof(*sbi->s_mb_maxs);
> 	sbi->s_mb_maxs = kmalloc(i, GFP_KERNEL);
> 	if (sbi->s_mb_maxs == NULL) {
> 		ret = -ENOMEM;
> @@ -2884,7 +2884,8 @@ int ext4_mb_init(struct super_block *sb)
> 		offset_incr = offset_incr >> 1;
> 		max = max >> 1;
> 		i++;
> -	} while (i <= sb->s_blocksize_bits + 1);
> +	} while (i < MB_NUM_ORDERS(sb));
> +
> 
> 	spin_lock_init(&sbi->s_md_lock);
> 	sbi->s_mb_free_pending = 0;
> diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h
> index 7597330dbdf8..02861406932f 100644
> --- a/fs/ext4/mballoc.h
> +++ b/fs/ext4/mballoc.h
> @@ -78,6 +78,11 @@
>  */
> #define MB_DEFAULT_MAX_INODE_PREALLOC	512
> 
> +/*
> + * Number of valid buddy orders
> + */
> +#define MB_NUM_ORDERS(sb)		((sb)->s_blocksize_bits + 2)
> +
> struct ext4_free_data {
> 	/* this links the free block information from sb_info */
> 	struct list_head		efd_list;
> -- 
> 2.30.0.478.g8a0d178c01-goog
> 


  reply	other threads:[~2021-02-16 10:46 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 20:28 Improve group scanning in mballoc Harshad Shirwadkar
2021-02-09 20:28 ` [PATCH v2 1/5] ext4: drop s_mb_bal_lock and convert protected fields to atomic Harshad Shirwadkar
2021-02-09 20:28 ` [PATCH v2 2/5] ext4: add mballoc stats proc file Harshad Shirwadkar
2021-02-11 23:49   ` Andreas Dilger
2021-02-12 16:52   ` Благодаренко Артём
2021-02-12 17:15     ` harshad shirwadkar
2021-02-09 20:28 ` [PATCH v2 3/5] ext4: add MB_NUM_ORDERS macro Harshad Shirwadkar
2021-02-16 10:45   ` Благодаренко Артём [this message]
2021-02-26  2:36     ` 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   ` [kbuild] " 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-14 14:09   ` [ext4] ef4eebad9c: fxmark.hdd_ext4_no_jnl_MWCL_1_bufferedio.works/sec -9.8% regression kernel test robot
2021-02-26  3:22     ` Andreas Dilger
2021-03-03  2:56       ` Oliver Sang
2021-02-16 19:39   ` [PATCH v2 4/5] ext4: improve cr 0 / cr 1 group scanning Благодаренко Артём
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   ` Благодаренко Артём
2021-02-09 20:28 ` [PATCH v2 5/5] ext4: add proc files to monitor new structures Harshad Shirwadkar
2021-02-12 22:36   ` Andreas Dilger
2021-02-16 16:55     ` harshad shirwadkar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1029810C-1D3F-45ED-9EF3-EF85C31AE81B@gmail.com \
    --to=artem.blagodarenko@gmail.com \
    --cc=adilger@dilger.ca \
    --cc=bzzz@whamcloud.com \
    --cc=harshadshirwadkar@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sihara@ddn.com \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).