linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu, bzzz@whamcloud.com, artem.blagodarenko@gmail.com,
	sihara@ddn.com, adilger@dilger.ca,
	Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Subject: [PATCH v2 1/5] ext4: drop s_mb_bal_lock and convert protected fields to atomic
Date: Tue,  9 Feb 2021 12:28:53 -0800	[thread overview]
Message-ID: <20210209202857.4185846-2-harshadshirwadkar@gmail.com> (raw)
In-Reply-To: <20210209202857.4185846-1-harshadshirwadkar@gmail.com>

s_mb_buddies_generated gets used later in this patch series to
determine if the cr 0 and cr 1 optimziations should be performed or
not. Currently, s_mb_buddies_generated is protected under a
spin_lock. In the allocation path, it is better if we don't depend on
the lock and instead read the value atomically. In order to do that,
we drop s_bal_lock altogether and we convert the only two protected
fields by it s_mb_buddies_generated and s_mb_generation_time to atomic
type.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
---
 fs/ext4/ext4.h    |  5 ++---
 fs/ext4/mballoc.c | 13 +++++--------
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 64f25ea2fa7a..6dd127942208 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1552,9 +1552,8 @@ struct ext4_sb_info {
 	atomic_t s_bal_goals;	/* goal hits */
 	atomic_t s_bal_breaks;	/* too long searches */
 	atomic_t s_bal_2orders;	/* 2^order hits */
-	spinlock_t s_bal_lock;
-	unsigned long s_mb_buddies_generated;
-	unsigned long long s_mb_generation_time;
+	atomic_t s_mb_buddies_generated;	/* number of buddies generated */
+	atomic64_t s_mb_generation_time;
 	atomic_t s_mb_lost_chunks;
 	atomic_t s_mb_preallocated;
 	atomic_t s_mb_discarded;
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 99bf091fee10..07b78a3cc421 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -816,10 +816,8 @@ void ext4_mb_generate_buddy(struct super_block *sb,
 	clear_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &(grp->bb_state));
 
 	period = get_cycles() - period;
-	spin_lock(&sbi->s_bal_lock);
-	sbi->s_mb_buddies_generated++;
-	sbi->s_mb_generation_time += period;
-	spin_unlock(&sbi->s_bal_lock);
+	atomic_inc(&sbi->s_mb_buddies_generated);
+	atomic64_add(period, &sbi->s_mb_generation_time);
 }
 
 /* The buddy information is attached the buddy cache inode
@@ -2843,7 +2841,6 @@ int ext4_mb_init(struct super_block *sb)
 	} while (i <= sb->s_blocksize_bits + 1);
 
 	spin_lock_init(&sbi->s_md_lock);
-	spin_lock_init(&sbi->s_bal_lock);
 	sbi->s_mb_free_pending = 0;
 	INIT_LIST_HEAD(&sbi->s_freed_data_list);
 
@@ -2979,9 +2976,9 @@ int ext4_mb_release(struct super_block *sb)
 				atomic_read(&sbi->s_bal_breaks),
 				atomic_read(&sbi->s_mb_lost_chunks));
 		ext4_msg(sb, KERN_INFO,
-		       "mballoc: %lu generated and it took %Lu",
-				sbi->s_mb_buddies_generated,
-				sbi->s_mb_generation_time);
+		       "mballoc: %u generated and it took %llu",
+				atomic_read(&sbi->s_mb_buddies_generated),
+				atomic64_read(&sbi->s_mb_generation_time));
 		ext4_msg(sb, KERN_INFO,
 		       "mballoc: %u preallocated, %u discarded",
 				atomic_read(&sbi->s_mb_preallocated),
-- 
2.30.0.478.g8a0d178c01-goog


  reply	other threads:[~2021-02-09 20: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 ` Harshad Shirwadkar [this message]
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   ` Благодаренко Артём
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=20210209202857.4185846-2-harshadshirwadkar@gmail.com \
    --to=harshadshirwadkar@gmail.com \
    --cc=adilger@dilger.ca \
    --cc=artem.blagodarenko@gmail.com \
    --cc=bzzz@whamcloud.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).