>From a656649fcf6fa5a17697ec55b2bd2ebd77eceac0 Mon Sep 17 00:00:00 2001 From: T Makphaibulchoke Date: Tue, 15 Apr 2014 14:19:44 -0600 Subject: [PATCH] Adding code to collect i_mutex usage during orphan Signed-off-by: T. Makphaibulchoke --- fs/ext4/namei.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 4a1a6a0..e747e43 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -48,6 +48,46 @@ #define NAMEI_RA_BLOCKS 4 #define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS) +static unsigned long num_add_call; +static unsigned long num_del_call; +static unsigned long num_add_mutex_lock; +static unsigned long num_del_mutex_lock; +static unsigned long num_add_error; +static unsigned long num_del_error; + +static struct kobject *ext4_orphan_kobj; + +static ssize_t ext4_print_count(struct kobject *kobj, struct kobj_attribute + *attr, char *buff) +{ + return sprintf(buff, "Add_mutex_lock %ld(%ld), Del_mutex_lock %ld(%ld).\n", + num_add_mutex_lock, num_add_call, + num_del_mutex_lock, num_del_call); +} + +static ssize_t ext4_print_error(struct kobject *kobj, struct kobj_attribute + *attr, char *buff) +{ + return sprintf(buff, "Add_mutex_lock %ld(%ld), Del_mutex_lock %ld(%ld).\n", + num_add_error, num_add_call, num_del_error, num_del_call); +} + +static struct kobj_attribute ext4_show_count = + __ATTR(ext4_mutex_lock, 0444, ext4_print_count, NULL); + +static struct kobj_attribute ext4_show_error = + __ATTR(ext4_mutex_error, 0444, ext4_print_error, NULL); + +static struct attribute * attrs[] = { + &ext4_show_count.attr, + &ext4_show_error.attr, + NULL +}; + +static struct attribute_group attr_group = { + .attrs = attrs +}; + static struct buffer_head *ext4_append(handle_t *handle, struct inode *inode, ext4_lblk_t *block) @@ -2557,9 +2597,21 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode) if (!EXT4_SB(sb)->s_journal) return 0; + if (!ext4_orphan_kobj) { + ext4_orphan_kobj = kobject_create_and_add("ext4_orphan", NULL); + if (ext4_orphan_kobj) { + int ret = sysfs_create_group(ext4_orphan_kobj, + &attr_group); + pr_warning("%s: sys_create_group ret %d.\n", + __func__, ret); + } + } + + ++num_add_call; if (!mutex_is_locked(&inode->i_mutex)) { lock_mutex = 1; mutex_lock(&inode->i_mutex); + ++num_add_mutex_lock; } if (!list_empty(&EXT4_I(inode)->i_orphan)) @@ -2588,6 +2640,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode) */ if (NEXT_ORPHAN(inode) && NEXT_ORPHAN(inode) <= (le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count))) { + ++num_add_error; brelse(iloc.bh); mutex_lock(&EXT4_SB(sb)->s_ondisk_orphan_lock); ////spin_lock(&EXT4_SB(sb)->s_orphan_lock); @@ -2655,9 +2708,11 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode) !(sbi->s_mount_state & EXT4_ORPHAN_FS)) return 0; + ++num_del_call; if (!mutex_is_locked(&inode->i_mutex)) { lock_mutex = 1; mutex_lock(&inode->i_mutex); + ++num_del_mutex_lock; } if (list_empty(&ei->i_orphan)) { @@ -2679,6 +2734,7 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode) list_del_init(&ei->i_orphan); mutex_unlock(&sbi->s_ondisk_orphan_lock); ////spin_unlock(&sbi->s_orphan_lock); + ++num_del_error; } else err = ext4_reserve_inode_write(handle, inode, &iloc); -- 1.7.11.3