Patchwork [v2] fs/ext4: increase parallelism in updating ext4 orphan list

login
register
mail settings
Submitter Thavatchai Makphaibulchoke
Date April 15, 2014, 8:22 p.m.
Message ID <534D9517.9080701@hp.com>
Download mbox | patch
Permalink /patch/339366/
State Superseded
Headers show

Comments

Thavatchai Makphaibulchoke - April 15, 2014, 8:22 p.m.
On 04/15/2014 11:25 AM, Jan Kara wrote:
>   I have checked the source and I didn't find many places where i_mutex was
> not held. But maybe I'm wrong. That's why I wanted to see the patch where
> you are using i_mutex instead of hashed mutexes and which didn't perform
> good enough.
> 

I've attached two patches.  The first one, 0001-Orphan-patch-using-i_mutex-and-removing-s_orphan_loc.patch, is the one you requested, using i_mutex and removing the s_orphan_lock.  The second one, 0001-Adding-code-to-collect-i_mutex-usage-during-orphan.patch, with the code to collect statistics on the number of orphan operations with and without holding i_mutex, in case you are also interested, can be applied on top of the first patch.

Please note that these two patches is meant for data collection only, as the code is quite of submittal quality.

Please also let me know if you have any further comments or suggestion.  I'll hold submitting for a couple more days.


> 
> 								Honza
>

Thanks,
Mak.

Patch

From a656649fcf6fa5a17697ec55b2bd2ebd77eceac0 Mon Sep 17 00:00:00 2001
From: T Makphaibulchoke <tmac@hp.com>
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 <tmac@hp.com>
---
 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