From: Zheng Liu <gnehzuil.liu@gmail.com>
To: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: Zheng Liu <wenqing.lz@taobao.com>, Jens Axboe <axboe@kernel.dk>,
Steven Whitehouse <swhiteho@redhat.com>,
Aditya Kali <adityakali@google.com>,
Wang Shaoyan <wangshaoyan.pt@taobao.com>
Subject: [PATCH v4 1/8] ext4: add percpu counters and related functions to account io types.
Date: Tue, 24 Jan 2012 00:50:21 +0800 [thread overview]
Message-ID: <1327337428-8266-2-git-send-email-wenqing.lz@taobao.com> (raw)
In-Reply-To: <1327337428-8266-1-git-send-email-wenqing.lz@taobao.com>
Add percpu counters in ext4_sb_info and related functions to save the result of
io types. IO types in ext4 are splitted as follows:
* Metadata:
- super block
- group descriptor
- inode bitmap
- block bitmap
- inode table
- extent block
- indirect block
- dir index and entry
- extended attribute
* Data:
- regular data block
CC: Jens Axboe <axboe@kernel.dk>
CC: Steven Whitehouse <swhiteho@redhat.com>
CC: Aditya Kali <adityakali@google.com>
Signed-off-by: Wang Shaoyan <wangshaoyan.pt@taobao.com>
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
---
fs/ext4/ext4.h | 37 +++++++++++++++++++++++++++++++++
fs/ext4/super.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 97 insertions(+), 0 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 513004f..7ec0596 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1118,6 +1118,23 @@ struct ext4_super_block {
#define EXT4_MF_FS_ABORTED 0x0002 /* Fatal error detected */
/*
+ * ext4 io types
+ */
+enum {
+ EXT4_IOS_SUPER_BLOCK = 0,
+ EXT4_IOS_GROUP_DESC,
+ EXT4_IOS_INODE_BITMAP,
+ EXT4_IOS_BLOCK_BITMAP,
+ EXT4_IOS_INODE_TABLE,
+ EXT4_IOS_EXTENT_BLOCK,
+ EXT4_IOS_INDIRECT_BLOCK,
+ EXT4_IOS_DIR_ENTRY,
+ EXT4_IOS_EXTENDED_ATTR,
+ EXT4_IOS_REGULAR_DATA,
+ EXT4_IOS_TYPE_END,
+};
+
+/*
* fourth extended-fs super-block data in memory
*/
struct ext4_sb_info {
@@ -1259,6 +1276,9 @@ struct ext4_sb_info {
/* record the last minlen when FITRIM is called. */
atomic_t s_last_trim_minblks;
+
+ /* for io type accouting */
+ struct percpu_counter s_ios_counters[EXT4_IOS_TYPE_END][2];
};
static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
@@ -1294,6 +1314,11 @@ static inline void ext4_set_io_unwritten_flag(struct inode *inode,
}
}
+static inline unsigned int ext4_blocks_per_page(struct inode *inode)
+{
+ return PAGE_CACHE_SIZE >> inode->i_blkbits;
+}
+
/*
* Inode dynamic state flags
*/
@@ -1931,6 +1956,18 @@ extern int ext4_group_extend(struct super_block *sb,
extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count);
/* super.c */
+extern void __ext4_io_stat(struct super_block *sb, int rw,
+ int type, unsigned long count);
+extern void ext4_ios_write(struct super_block *sb, handle_t *handle,
+ struct buffer_head *bh, int type,
+ unsigned long count);
+
+static inline void ext4_ios_read(struct super_block *sb, int type,
+ unsigned long count)
+{
+ __ext4_io_stat(sb, READ, type, count);
+}
+
extern void *ext4_kvmalloc(size_t size, gfp_t flags);
extern void *ext4_kvzalloc(size_t size, gfp_t flags);
extern void ext4_kvfree(void *ptr);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 502c61f..f3a5cab 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -842,6 +842,10 @@ static void ext4_put_super(struct super_block *sb)
percpu_counter_destroy(&sbi->s_freeinodes_counter);
percpu_counter_destroy(&sbi->s_dirs_counter);
percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
+ for (i = 0; i < EXT4_IOS_TYPE_END; i++) {
+ percpu_counter_destroy(&sbi->s_ios_counters[i][READ]);
+ percpu_counter_destroy(&sbi->s_ios_counters[i][WRITE]);
+ }
brelse(sbi->s_sbh);
#ifdef CONFIG_QUOTA
for (i = 0; i < MAXQUOTAS; i++)
@@ -3153,6 +3157,16 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
}
/*
+ * Note: s_ios_counters must be initialized as soon as possible becuase
+ * ext4 io type accouting depends on it
+ */
+ for (i = 0; i < EXT4_IOS_TYPE_END; i++) {
+ if (percpu_counter_init(&sbi->s_ios_counters[i][READ], 0))
+ goto out_init_ios;
+ if (percpu_counter_init(&sbi->s_ios_counters[i][WRITE], 0))
+ goto out_init_ios;
+ }
+ /*
* The ext4 superblock will not be buffer aligned for other than 1kB
* block sizes. We need to calculate the offset from buffer start.
*/
@@ -3874,6 +3888,11 @@ out_fail:
sb->s_fs_info = NULL;
kfree(sbi->s_blockgroup_lock);
kfree(sbi);
+out_init_ios:
+ for (i = 0; i < EXT4_IOS_TYPE_END; i++) {
+ percpu_counter_destroy(&sbi->s_ios_counters[i][READ]);
+ percpu_counter_destroy(&sbi->s_ios_counters[i][WRITE]);
+ }
out_free_orig:
kfree(orig_data);
return ret;
@@ -4939,6 +4958,47 @@ out:
#endif
+static inline u64 ext4_get_ios_counter(struct ext4_sb_info *sbi,
+ int rw, int type)
+{
+ return percpu_counter_sum(&sbi->s_ios_counters[type][rw]);
+}
+
+static inline void ext4_reset_ios_counter(struct ext4_sb_info *sbi)
+{
+ int i;
+
+ for (i = 0; i < EXT4_IOS_TYPE_END; i++) {
+ percpu_counter_set(&sbi->s_ios_counters[i][READ], 0);
+ percpu_counter_set(&sbi->s_ios_counters[i][WRITE], 0);
+ }
+}
+
+void __ext4_io_stat(struct super_block *sb, int rw,
+ int type, unsigned long count)
+{
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+
+ BUG_ON(type < 0 || type >= EXT4_IOS_TYPE_END);
+ percpu_counter_add(&sbi->s_ios_counters[type][rw], count);
+}
+
+void ext4_ios_write(struct super_block *sb, handle_t *handle,
+ struct buffer_head *bh, int type, unsigned long count)
+{
+ if (!bh)
+ goto count;
+ if (!handle || !ext4_handle_valid(handle)) {
+ if (buffer_dirty(bh))
+ return;
+ } else {
+ if (buffer_jbddirty(bh))
+ return;
+ }
+count:
+ __ext4_io_stat(sb, WRITE, type, count);
+}
+
static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags,
const char *dev_name, void *data)
{
--
1.7.4.1
next prev parent reply other threads:[~2012-01-23 16:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-23 16:50 [PATCH v4 0/8] ext4: io type accouting Zheng Liu
2012-01-23 16:50 ` Zheng Liu [this message]
2012-01-23 16:50 ` [PATCH v4 2/8] ext4: add wrapper functions for buffer layer Zheng Liu
2012-01-23 16:50 ` [PATCH v4 3/8] ext4: account the metadata request of read operations in buffered io Zheng Liu
2012-01-23 16:50 ` [PATCH v4 4/8] ext4: account the data " Zheng Liu
2012-01-23 16:50 ` [PATCH v4 5/8] ext4: account the metadata request of write " Zheng Liu
2012-01-23 16:50 ` [PATCH v4 6/8] ext4: account the data " Zheng Liu
2012-01-23 16:50 ` [PATCH v4 7/8] ext4: request accouting in direct io Zheng Liu
2012-01-23 16:50 ` [PATCH v4 8/8] ext4: show the result of io types accouting Zheng Liu
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=1327337428-8266-2-git-send-email-wenqing.lz@taobao.com \
--to=gnehzuil.liu@gmail.com \
--cc=adityakali@google.com \
--cc=axboe@kernel.dk \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=swhiteho@redhat.com \
--cc=wangshaoyan.pt@taobao.com \
--cc=wenqing.lz@taobao.com \
/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).