From patchwork Mon Nov 28 12:20:21 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 127970 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 5BF7EB6F94 for ; Mon, 28 Nov 2011 23:18:25 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752619Ab1K1MSW (ORCPT ); Mon, 28 Nov 2011 07:18:22 -0500 Received: from mail-iy0-f174.google.com ([209.85.210.174]:53709 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752455Ab1K1MSV (ORCPT ); Mon, 28 Nov 2011 07:18:21 -0500 Received: by iage36 with SMTP id e36so8873378iag.19 for ; Mon, 28 Nov 2011 04:18:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=WdsxAhWvbHnpLT6EoeAqGdeHTQuVr67XHft3H1Z+ydQ=; b=syViB2mvpFkAmvU1nnBL+EGRkvu/MKbZYAqtvYD/ZYIyh4JLEHLthL3fDfRoEvALm8 KlV2PFLBCCkcCbZ8tGeY5W0ghGo2VslgN1a5P4Mv0TPg6uMR18cdTlzSRBtswf758mub 5ssCYosH7suW7oYn6CFM1kiYiDa0UVhPMrgSs= Received: by 10.50.217.195 with SMTP id pa3mr49817778igc.12.1322482701209; Mon, 28 Nov 2011 04:18:21 -0800 (PST) Received: from localhost.localdomain ([182.92.247.2]) by mx.google.com with ESMTPS id cb15sm40036924ibb.4.2011.11.28.04.18.15 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 28 Nov 2011 04:18:19 -0800 (PST) From: Zheng Liu To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Jens Axboe , Steven Whitehouse , Aditya Kali , Wang Shaoyan , Zheng Liu Subject: [PATCH v3 1/8] ext4: add percpu counters and related functions to account io types. Date: Mon, 28 Nov 2011 20:20:21 +0800 Message-Id: <1322482828-5529-1-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1322482392-5346-1-git-send-email-wenqing.lz@taobao.com> References: <1322482392-5346-1-git-send-email-wenqing.lz@taobao.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zheng Liu 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 CC: Steven Whitehouse CC: Aditya Kali Signed-off-by: Wang Shaoyan Signed-off-by: Zheng Liu --- 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 5b0e26a..cd9c7f9 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1108,6 +1108,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 { @@ -1249,6 +1266,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) @@ -1284,6 +1304,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 */ @@ -1926,6 +1951,18 @@ extern int ext4_group_extend(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 3858767..3ef3e03b 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++) @@ -3157,6 +3161,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. */ @@ -3875,6 +3889,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; @@ -4940,6 +4959,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) {