Skip to contentSkip to conversation

aborted ext4 leads to inifinity loop in balance_dirty_pages

BUG Kazuya Mio 3 participants 14 messages Oct 25, 2011 – Nov 14, 2011

Subsystems (2)
lore
Share & tools
lore

Kazuya Mio

author
#0 lore raw

Write systemcall calls balance_dirty_pages() for direct reclaim. However, if ext4 is aborted because of the journal abort, ext4_da_writepages() cannot reduce the number of dirty pages because EXT4_MF_FS_ABORTED is set to s_mount_flag. banalce_dirty_pages() has a busy loop, and we can pass this loop only if the number of dirty pages is less than the threshold. So this function loops infinity.

When write systemcall and kjournald ran at the same time and the disk corruption happened, the problem occurred. The kernel version was 3.1-rc9. I corrupted the disk on purpose by using dmsetup command.

process1 (write) process2 (kjournald)

generic_perform_write
ext4_da_write_begin
ext4_da_write_end

-------------- detect disk corruption --------------

jbd2_journal_commit_transaction
journal_submit_data_buffers jbd2_journal_abort

balance_dirty_pages
writeback_inodes_wb
...
ext4_da_writepages <- do nothing if EXT4_MF_FS_ABORTED is set
ext4_journal_start
ext4_journal_start_sb <- detect journal abort
ext4_abort <- set EXT4_MF_FS_ABORTED

One possible idea to fix this problem is that ext4_da_writepages() invalidates the dirty pages if the filesystem has been aborted. Do you have any ideas?

Regards,
Kazuya Mio

maintainer
#1 lore raw
Quoted 24 lines · Kazuya Mio

Write systemcall calls balance_dirty_pages() for direct reclaim. However, if ext4 is aborted because of the journal abort, ext4_da_writepages() cannot reduce the number of dirty pages because EXT4_MF_FS_ABORTED is set to s_mount_flag. banalce_dirty_pages() has a busy loop, and we can pass this loop only if the number of dirty pages is less than the threshold. So this function loops infinity.

When write systemcall and kjournald ran at the same time and the disk corruption happened, the problem occurred. The kernel version was 3.1-rc9. I corrupted the disk on purpose by using dmsetup command.

process1 (write) process2 (kjournald)

generic_perform_write
ext4_da_write_begin
ext4_da_write_end

-------------- detect disk corruption --------------

jbd2_journal_commit_transaction
journal_submit_data_buffers jbd2_journal_abort

Quoted 7 lines

balance_dirty_pages
writeback_inodes_wb
...
ext4_da_writepages <- do nothing if EXT4_MF_FS_ABORTED is set
ext4_journal_start
ext4_journal_start_sb <- detect journal abort
ext4_abort <- set EXT4_MF_FS_ABORTED

Thanks for report!

Quoted 2 lines

One possible idea to fix this problem is that ext4_da_writepages() invalidates the dirty pages if the filesystem has been aborted.

Please no. Generally this boils down to what do we do with dirty data
when there's error in writing them out. Currently we just throw them away (e.g. in media error case) but I don't think that's a generally good thing because e.g. admin may want to copy the data to other working storage or so. So I think we should rather keep the data and provide a mechanism for userspace to ask kernel to get rid of the data (so that we don't eventually run OOM).

Quoted 1 line

Do you have any ideas?

So the question is what would you like to achieve. If you just want to
unblock a thread then a solution would be to make a thread at balance_dirty_pages() killable. If generally you want to get rid of dirty memory, then I don't have a really good answer but throwing dirty data away seems like a bad answer to me.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#2 lore raw
Quoted 7 lines · Jan Kara

Please no. Generally this boils down to what do we do with dirty data
when there's error in writing them out. Currently we just throw them away (e.g. in media error case) but I don't think that's a generally good thing because e.g. admin may want to copy the data to other working storage or so. So I think we should rather keep the data and provide a mechanism for userspace to ask kernel to get rid of the data (so that we don't eventually run OOM).

I see. I agree with you.

Quoted 6 lines
Quoted 1 line

Do you have any ideas?

So the question is what would you like to achieve. If you just want to
unblock a thread then a solution would be to make a thread at balance_dirty_pages() killable. If generally you want to get rid of dirty memory, then I don't have a really good answer but throwing dirty data away seems like a bad answer to me.

The problem is that we cannot unmount the corrupted filesystem due to un-killable dd process. We must bring down the system to resume the service with no dirty pages. I think it is important for the service continuity to be able to kill the thread handling in balance_dirty_pages().

Regards,
Kazuya Mio

maintainer
#3 lore raw
Quoted 18 lines · Kazuya Mio
Quoted 7 lines · Jan Kara

Please no. Generally this boils down to what do we do with dirty data
when there's error in writing them out. Currently we just throw them away (e.g. in media error case) but I don't think that's a generally good thing because e.g. admin may want to copy the data to other working storage or so. So I think we should rather keep the data and provide a mechanism for userspace to ask kernel to get rid of the data (so that we don't eventually run OOM).

I see. I agree with you.

Quoted 6 lines
Quoted 1 line

Do you have any ideas?

So the question is what would you like to achieve. If you just want to
unblock a thread then a solution would be to make a thread at balance_dirty_pages() killable. If generally you want to get rid of dirty memory, then I don't have a really good answer but throwing dirty data away seems like a bad answer to me.

Quoted 4 lines

The problem is that we cannot unmount the corrupted filesystem due to un-killable dd process. We must bring down the system to resume the service with no dirty pages. I think it is important for the service continuity to be able to kill the thread handling in balance_dirty_pages().

Sure. Then allowing a process to be killed while waiting in
balance_dirty_pages() would solve your problem. That can be done relatively easily. I can write the patch, just now the code is under rewrite from IO-less dirty throttling patches so I'll wait for a while for it to settle down.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#4 lore raw
Quoted 9 lines · Jan Kara
Quoted 4 lines

The problem is that we cannot unmount the corrupted filesystem due to un-killable dd process. We must bring down the system to resume the service with no dirty pages. I think it is important for the service continuity to be able to kill the thread handling in balance_dirty_pages().

Sure. Then allowing a process to be killed while waiting in
balance_dirty_pages() would solve your problem. That can be done relatively easily. I can write the patch, just now the code is under rewrite from IO-less dirty throttling patches so I'll wait for a while for it to settle down.

Thanks for working this on.

Regards,
Kazuya Mio

#5 lore raw
In reply to Kazuya Mio
Quoted 18 lines · Kazuya Mio
Quoted 7 lines · Jan Kara

Please no. Generally this boils down to what do we do with dirty data
when there's error in writing them out. Currently we just throw them away (e.g. in media error case) but I don't think that's a generally good thing because e.g. admin may want to copy the data to other working storage or so. So I think we should rather keep the data and provide a mechanism for userspace to ask kernel to get rid of the data (so that we don't eventually run OOM).

I see. I agree with you.

Quoted 6 lines
Quoted 1 line

Do you have any ideas?

So the question is what would you like to achieve. If you just want to
unblock a thread then a solution would be to make a thread at balance_dirty_pages() killable. If generally you want to get rid of dirty memory, then I don't have a really good answer but throwing dirty data away seems like a bad answer to me.

Quoted 4 lines

The problem is that we cannot unmount the corrupted filesystem due to un-killable dd process. We must bring down the system to resume the service with no dirty pages. I think it is important for the service continuity to be able to kill the thread handling in balance_dirty_pages().

In fact you are very lucky because dd is just deadlocked, in many cases journal abort result in BUG_ON triggering(if IO load is high enough). This is because transaction abort check is racy. Right now i've no good fix which has reasonable performance. My latest idea is to protect transaction abort check via SRCU.

Quoted 8 lines

Regards,
Kazuya Mio

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

maintainer
#6 lore raw
Quoted 19 lines · Dmitry Monakhov
Quoted 18 lines · Kazuya Mio
Quoted 7 lines · Jan Kara

Please no. Generally this boils down to what do we do with dirty data
when there's error in writing them out. Currently we just throw them away (e.g. in media error case) but I don't think that's a generally good thing because e.g. admin may want to copy the data to other working storage or so. So I think we should rather keep the data and provide a mechanism for userspace to ask kernel to get rid of the data (so that we don't eventually run OOM).

I see. I agree with you.

Quoted 6 lines
Quoted 1 line

Do you have any ideas?

So the question is what would you like to achieve. If you just want to
unblock a thread then a solution would be to make a thread at balance_dirty_pages() killable. If generally you want to get rid of dirty memory, then I don't have a really good answer but throwing dirty data away seems like a bad answer to me.

Quoted 6 lines
Quoted 4 lines

The problem is that we cannot unmount the corrupted filesystem due to un-killable dd process. We must bring down the system to resume the service with no dirty pages. I think it is important for the service continuity to be able to kill the thread handling in balance_dirty_pages().

In fact you are very lucky because dd is just deadlocked, in many cases journal abort result in BUG_ON triggering(if IO load is high enough).

Can you provide the exact kernel message? I'd be interested...

Quoted 3 lines

This is because transaction abort check is racy. Right now i've no good fix which has reasonable performance. My latest idea is to protect transaction abort check via SRCU.

Yeah, the code does not seem to care about races too much but I don't see
which BUG_ON would be triggered...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#7 lore raw
Quoted 20 lines · Jan Kara
Quoted 19 lines · Dmitry Monakhov
Quoted 18 lines · Kazuya Mio
Quoted 7 lines · Jan Kara

Please no. Generally this boils down to what do we do with dirty data
when there's error in writing them out. Currently we just throw them away (e.g. in media error case) but I don't think that's a generally good thing because e.g. admin may want to copy the data to other working storage or so. So I think we should rather keep the data and provide a mechanism for userspace to ask kernel to get rid of the data (so that we don't eventually run OOM).

I see. I agree with you.

Quoted 6 lines
Quoted 1 line

Do you have any ideas?

So the question is what would you like to achieve. If you just want to
unblock a thread then a solution would be to make a thread at balance_dirty_pages() killable. If generally you want to get rid of dirty memory, then I don't have a really good answer but throwing dirty data away seems like a bad answer to me.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

The problem is that we cannot unmount the corrupted filesystem due to un-killable dd process. We must bring down the system to resume the service with no dirty pages. I think it is important for the service continuity to be able to kill the thread handling in balance_dirty_pages().

In fact you are very lucky because dd is just deadlocked, in many cases journal abort result in BUG_ON triggering(if IO load is high enough).

Can you provide the exact kernel message? I'd be interested...

Several times i've failed in journal_stop() here:
int jbd2_journal_stop(handle_t *handle)

{
        transaction_t *transaction = handle->h_transaction;
        journal_t *journal = transaction->t_journal;
        int err, wait_for_commit = 0;
        tid_t tid;
        pid_t pid;

        J_ASSERT(journal_current_handle() == handle);

        if (is_handle_aborted(handle))
                err = -EIO;
        else {
                J_ASSERT(atomic_read(&transaction->t_updates) > 0);
##FAILED HERE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                err = 0;
        }
Quoted 15 lines
Quoted 4 lines

This is because transaction abort check is racy. Right now i've no good fix which has reasonable performance. My latest idea is to protect transaction abort check via SRCU.

Yeah, the code does not seem to care about races too much but I don't see
which BUG_ON would be triggered...

Honza

Signature · 6 lines
Jan Kara <[email protected]>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#8 lore raw
Quoted 30 lines · Dmitry Monakhov
Quoted 20 lines · Jan Kara
Quoted 19 lines · Dmitry Monakhov
Quoted 18 lines · Kazuya Mio
Quoted 7 lines · Jan Kara

Please no. Generally this boils down to what do we do with dirty data
when there's error in writing them out. Currently we just throw them away (e.g. in media error case) but I don't think that's a generally good thing because e.g. admin may want to copy the data to other working storage or so. So I think we should rather keep the data and provide a mechanism for userspace to ask kernel to get rid of the data (so that we don't eventually run OOM).

I see. I agree with you.

Quoted 6 lines
Quoted 1 line

Do you have any ideas?

So the question is what would you like to achieve. If you just want to
unblock a thread then a solution would be to make a thread at balance_dirty_pages() killable. If generally you want to get rid of dirty memory, then I don't have a really good answer but throwing dirty data away seems like a bad answer to me.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

The problem is that we cannot unmount the corrupted filesystem due to un-killable dd process. We must bring down the system to resume the service with no dirty pages. I think it is important for the service continuity to be able to kill the thread handling in balance_dirty_pages().

In fact you are very lucky because dd is just deadlocked, in many cases journal abort result in BUG_ON triggering(if IO load is high enough).

Can you provide the exact kernel message? I'd be interested...

Several times i've failed in journal_stop() here:
int jbd2_journal_stop(handle_t *handle)

Quoted 16 lines
{
        transaction_t *transaction = handle->h_transaction;
        journal_t *journal = transaction->t_journal;
        int err, wait_for_commit = 0;
        tid_t tid;
        pid_t pid;

        J_ASSERT(journal_current_handle() == handle);

        if (is_handle_aborted(handle))
                err = -EIO;
        else {
                J_ASSERT(atomic_read(&transaction->t_updates) > 0);
##FAILED HERE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                err = 0;
        }

Hum, interesting. The logic wrt t_updates looks correct to me. Whenever
we create a new handle in a transaction, we increase t_updates. Whenever we remove the handle, decrease t_updates. Whether the journal / handle is aborted or not does not play any role here. So I fail to see how the assertion can be triggered - only if we tried to release a handle twice or something like that...

Honza

maintainer
#9 lore raw
In reply to Kazuya Mio
Quoted 18 lines · Kazuya Mio
Quoted 7 lines · Jan Kara

Please no. Generally this boils down to what do we do with dirty data
when there's error in writing them out. Currently we just throw them away (e.g. in media error case) but I don't think that's a generally good thing because e.g. admin may want to copy the data to other working storage or so. So I think we should rather keep the data and provide a mechanism for userspace to ask kernel to get rid of the data (so that we don't eventually run OOM).

I see. I agree with you.

Quoted 6 lines
Quoted 1 line

Do you have any ideas?

So the question is what would you like to achieve. If you just want to
unblock a thread then a solution would be to make a thread at balance_dirty_pages() killable. If generally you want to get rid of dirty memory, then I don't have a really good answer but throwing dirty data away seems like a bad answer to me.

Quoted 4 lines

The problem is that we cannot unmount the corrupted filesystem due to un-killable dd process. We must bring down the system to resume the service with no dirty pages. I think it is important for the service continuity to be able to kill the thread handling in balance_dirty_pages().

OK, attached are two patches based on latest Linus's tree that should
make your task killable. Can you test them?

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
Quoted 1 line

From 62d9916059c0441b3f545158f723c7006bcdc1e8 Mon Sep 17 00:00:00 2001

From: Jan Kara <[email protected]>
Date: Mon, 7 Nov 2011 18:41:05 +0100
Subject: [PATCH 1/2] mm: Make task in balance_dirty_pages() killable

There is no reason why task in balance_dirty_pages() shouldn't be killable and it helps in recovering from some error conditions (like when filesystem goes in error state and cannot accept writeback anymore but we still want to kill processes using it to be able to unmount it).

---
 mm/page-writeback.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
mm/page-writeback.c +3 -1
index 0360d1b..e83c286 100644
@@ -1133,8 +1133,10 @@ pause:
 					  pages_dirtied,
 					  pause,
 					  start_time);
-		__set_current_state(TASK_UNINTERRUPTIBLE);
+		__set_current_state(TASK_KILLABLE);
 		io_schedule_timeout(pause);
+		if (fatal_signal_pending(current))
+			break;
 
 		dirty_thresh = hard_dirty_limit(dirty_thresh);
 		/*
Signature · 1 line
1.7.1
Quoted 1 line

From 6eefa10d92cc35b66a8166cc26472d383b572b0d Mon Sep 17 00:00:00 2001

From: Jan Kara <[email protected]>
Date: Mon, 7 Nov 2011 18:46:39 +0100
Subject: [PATCH 2/2] fs: Make write(2) interruptible by a signal

Currently write(2) to a file is not interruptible by a signal. Sometimes this is desirable (e.g. when you want to quickly kill a process hogging your disk or when some process gets blocked in balance_dirty_pages() indefinitely due to a filesystem being in an error condition).

---
 mm/filemap.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
mm/filemap.c +4 -0
index c0018f2..6b01d2f 100644
@@ -2407,6 +2407,10 @@ static ssize_t generic_perform_write(struct file *file,
 						iov_iter_count(i));
 
 again:
+		if (signal_pending(current)) {
+			status = -EINTR;
+			break;
+		}
 
 		/*
 		 * Bring in the user page that we will copy from _first_.
Signature · 1 line
1.7.1
author
#10 lore raw
Quoted 19 lines · Jan Kara
Quoted 18 lines · Kazuya Mio
Quoted 7 lines · Jan Kara

Please no. Generally this boils down to what do we do with dirty data
when there's error in writing them out. Currently we just throw them away (e.g. in media error case) but I don't think that's a generally good thing because e.g. admin may want to copy the data to other working storage or so. So I think we should rather keep the data and provide a mechanism for userspace to ask kernel to get rid of the data (so that we don't eventually run OOM).

I see. I agree with you.

Quoted 6 lines
Quoted 1 line

Do you have any ideas?

So the question is what would you like to achieve. If you just want to
unblock a thread then a solution would be to make a thread at balance_dirty_pages() killable. If generally you want to get rid of dirty memory, then I don't have a really good answer but throwing dirty data away seems like a bad answer to me.

Quoted 6 lines
Quoted 4 lines

The problem is that we cannot unmount the corrupted filesystem due to un-killable dd process. We must bring down the system to resume the service with no dirty pages. I think it is important for the service continuity to be able to kill the thread handling in balance_dirty_pages().

OK, attached are two patches based on latest Linus's tree that should
make your task killable. Can you test them?

I'm trying to reproduce now, but it's hard. Could you wait a few days?

maintainer
#11 lore raw
Quoted 20 lines · Kazuya Mio
Quoted 19 lines · Jan Kara
Quoted 18 lines · Kazuya Mio
Quoted 7 lines · Jan Kara

Please no. Generally this boils down to what do we do with dirty data
when there's error in writing them out. Currently we just throw them away (e.g. in media error case) but I don't think that's a generally good thing because e.g. admin may want to copy the data to other working storage or so. So I think we should rather keep the data and provide a mechanism for userspace to ask kernel to get rid of the data (so that we don't eventually run OOM).

I see. I agree with you.

Quoted 6 lines
Quoted 1 line

Do you have any ideas?

So the question is what would you like to achieve. If you just want to
unblock a thread then a solution would be to make a thread at balance_dirty_pages() killable. If generally you want to get rid of dirty memory, then I don't have a really good answer but throwing dirty data away seems like a bad answer to me.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

The problem is that we cannot unmount the corrupted filesystem due to un-killable dd process. We must bring down the system to resume the service with no dirty pages. I think it is important for the service continuity to be able to kill the thread handling in balance_dirty_pages().

OK, attached are two patches based on latest Linus's tree that should
make your task killable. Can you test them?

I'm trying to reproduce now, but it's hard. Could you wait a few days?

Sure, take as much time as you need.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#12 lore raw
In reply to Jan Kara
Quoted 19 lines · Jan Kara
Quoted 18 lines · Kazuya Mio
Quoted 7 lines · Jan Kara

Please no. Generally this boils down to what do we do with dirty data
when there's error in writing them out. Currently we just throw them away (e.g. in media error case) but I don't think that's a generally good thing because e.g. admin may want to copy the data to other working storage or so. So I think we should rather keep the data and provide a mechanism for userspace to ask kernel to get rid of the data (so that we don't eventually run OOM).

I see. I agree with you.

Quoted 6 lines
Quoted 1 line

Do you have any ideas?

So the question is what would you like to achieve. If you just want to
unblock a thread then a solution would be to make a thread at balance_dirty_pages() killable. If generally you want to get rid of dirty memory, then I don't have a really good answer but throwing dirty data away seems like a bad answer to me.

Quoted 6 lines
Quoted 4 lines

The problem is that we cannot unmount the corrupted filesystem due to un-killable dd process. We must bring down the system to resume the service with no dirty pages. I think it is important for the service continuity to be able to kill the thread handling in balance_dirty_pages().

OK, attached are two patches based on latest Linus's tree that should
make your task killable. Can you test them?

Sorry for the late reply.
I confirmed that these patches fix the problem.

Reported-and-tested-by Kazuya Mio <[email protected]>

Regards,
Kazuya Mio

maintainer
#13 lore raw
Quoted 24 lines · Kazuya Mio
Quoted 23 lines · Jan Kara
Quoted 22 lines · Kazuya Mio
Quoted 7 lines · Jan Kara

Please no. Generally this boils down to what do we do with dirty data
when there's error in writing them out. Currently we just throw them away (e.g. in media error case) but I don't think that's a generally good thing because e.g. admin may want to copy the data to other working storage or so. So I think we should rather keep the data and provide a mechanism for userspace to ask kernel to get rid of the data (so that we don't eventually run OOM).

I see. I agree with you.

Quoted 6 lines
Quoted 1 line

Do you have any ideas?

So the question is what would you like to achieve. If you just want to
unblock a thread then a solution would be to make a thread at balance_dirty_pages() killable. If generally you want to get rid of dirty memory, then I don't have a really good answer but throwing dirty data away seems like a bad answer to me.

The problem is that we cannot unmount the corrupted filesystem due to un-killable dd process. We must bring down the system to resume the service with no dirty pages. I think it is important for the service continuity to be able to kill the thread handling in balance_dirty_pages().

Quoted 7 lines
Quoted 2 lines

OK, attached are two patches based on latest Linus's tree that should
make your task killable. Can you test them?

Sorry for the late reply.
I confirmed that these patches fix the problem.

Reported-and-tested-by Kazuya Mio <[email protected]>

Thanks for testing! I've sent patches for inclusion...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR