From: Tao Ma <tm@tao.ma>
To: linux-ext4@vger.kernel.org
Cc: "Theodore Ts'o" <tytso@mit.edu>
Subject: [PATCH] ext4: Check io list state and avoid an unnecessary mutex_lock in ext4_end_io_work.
Date: Wed, 14 Sep 2011 16:33:02 +0800 [thread overview]
Message-ID: <1315989182-6170-1-git-send-email-tm@tao.ma> (raw)
From: Tao Ma <boyu.mt@taobao.com>
When we finish the end io work in ext4_flush_completed_IO, we take
the io work away from the list, but don't free it. Then in the workqueue,
we can check the list state and then avoid the extra work if it is also
done. It is good, but we check list state in ext4_end_io_nolock with i_mutex held
instead of the spin_lock in other places. This is wrong.
So check the state within spin_lock and another side effect is that the heavy extra
mutex_lock can be avoided.
Cc: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Tao Ma <boyu.mt@taobao.com>
---
fs/ext4/page-io.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 92f38ee..f6b40f1 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -100,9 +100,6 @@ int ext4_end_io_nolock(ext4_io_end_t *io)
"list->prev 0x%p\n",
io, inode->i_ino, io->list.next, io->list.prev);
- if (list_empty(&io->list))
- return ret;
-
if (!(io->flag & EXT4_IO_END_UNWRITTEN))
return ret;
@@ -142,6 +139,13 @@ static void ext4_end_io_work(struct work_struct *work)
unsigned long flags;
int ret;
+ spin_lock_irqsave(&ei->i_completed_io_lock, flags);
+ if (list_empty(&io->list)) {
+ spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
+ goto free;
+ }
+ spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
+
if (!mutex_trylock(&inode->i_mutex)) {
/*
* Requeue the work instead of waiting so that the work
@@ -170,6 +174,7 @@ static void ext4_end_io_work(struct work_struct *work)
list_del_init(&io->list);
spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
mutex_unlock(&inode->i_mutex);
+free:
ext4_free_io_end(io);
}
--
1.7.0.4
next reply other threads:[~2011-09-14 8:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-14 8:33 Tao Ma [this message]
2011-10-29 20:57 ` [PATCH] ext4: Check io list state and avoid an unnecessary mutex_lock in ext4_end_io_work Ted Ts'o
2011-10-30 7:50 ` Tao Ma
2011-10-31 15:02 ` Ted Ts'o
2011-10-31 15:02 ` [PATCH 1/3] ext4: Use correct locking for ext4_end_io_nolock() Theodore Ts'o
2011-10-31 15:02 ` [PATCH 2/3] ext4: remove unnecessary call to waitqueue_active() Theodore Ts'o
2011-10-31 15:02 ` [PATCH 3/3] ext4: optimize locking for end_io extent conversion Theodore Ts'o
2011-11-01 2:51 ` Tao Ma
2011-11-01 10:30 ` Theodore Tso
2011-10-31 15:28 ` [PATCH 1/3] ext4: Use correct locking for ext4_end_io_nolock() Tao Ma
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=1315989182-6170-1-git-send-email-tm@tao.ma \
--to=tm@tao.ma \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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).