lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1327337428-8266-2-git-send-email-wenqing.lz@taobao.com>
Date:	Tue, 24 Jan 2012 00:50:21 +0800
From:	Zheng Liu <gnehzuil.liu@...il.com>
To:	linux-ext4@...r.kernel.org, linux-fsdevel@...r.kernel.org
Cc:	Zheng Liu <wenqing.lz@...bao.com>, Jens Axboe <axboe@...nel.dk>,
	Steven Whitehouse <swhiteho@...hat.com>,
	Aditya Kali <adityakali@...gle.com>,
	Wang Shaoyan <wangshaoyan.pt@...bao.com>
Subject: [PATCH v4 1/8] ext4: add percpu counters and related functions to account io types.

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@...nel.dk>
CC: Steven Whitehouse <swhiteho@...hat.com>
CC: Aditya Kali <adityakali@...gle.com>
Signed-off-by: Wang Shaoyan <wangshaoyan.pt@...bao.com>
Signed-off-by: Zheng Liu <wenqing.lz@...bao.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

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ