Skip to contentSkip to conversation

[PATCH]

PATCH New Rafael J. Wysocki 4 participants 12 messages Aug 11, 2011 – Aug 25, 2011 1 message not in the archive VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 [PATCH]

From: Rafael J. Wysocki <[email protected]>
Subject: fs / ext3: Always unlock updates in ext3_freeze()

In analogy with ext4 make ext3_freeze() always call journal_unlock_updates() to prevent it from leaving a locked mutex behind. Accordingly, modify ext3_unfreeze() so that it doesn't call journal_unlock_updates() any more.

---
 fs/ext3/super.c |   39 ++++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 21 deletions(-)
fs/ext3/super.c +18 -21
Index: linux/fs/ext3/super.c
===================================================================
@@ -2535,30 +2535,28 @@ static int ext3_sync_fs(struct super_blo
  */
 static int ext3_freeze(struct super_block *sb)
 {
-	int error = 0;
+	int error;
 	journal_t *journal;
 
-	if (!(sb->s_flags & MS_RDONLY)) {
-		journal = EXT3_SB(sb)->s_journal;
+	if (sb->s_flags & MS_RDONLY)
+		return 0;
 
-		/* Now we set up the journal barrier. */
-		journal_lock_updates(journal);
+	journal = EXT3_SB(sb)->s_journal;
 
-		/*
-		 * We don't want to clear needs_recovery flag when we failed
-		 * to flush the journal.
-		 */
-		error = journal_flush(journal);
-		if (error < 0)
-			goto out;
-
-		/* Journal blocked and flushed, clear needs_recovery flag. */
-		EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
-		error = ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
-		if (error)
-			goto out;
-	}
-	return 0;
+	/* Now we set up the journal barrier. */
+	journal_lock_updates(journal);
+
+	/*
+	 * We don't want to clear needs_recovery flag when we failed
+	 * to flush the journal.
+	 */
+	error = journal_flush(journal);
+	if (error < 0)
+		goto out;
+
+	/* Journal blocked and flushed, clear needs_recovery flag. */
+	EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
+	error = ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
 
 out:
 	journal_unlock_updates(journal);
@@ -2577,7 +2575,6 @@ static int ext3_unfreeze(struct super_bl
 		EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
 		ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
 		unlock_super(sb);
-		journal_unlock_updates(EXT3_SB(sb)->s_journal);
 	}
 	return 0;
 }
#1 lore raw

PATCH 1/1 fs / ext3: Always unlock updates in ext3_freeze()

From: Rafael J. Wysocki <[email protected]>

In analogy with ext4 make ext3_freeze() always call journal_unlock_updates() to prevent it from leaving a locked mutex behind. Accordingly, modify ext3_unfreeze() so that it doesn't call journal_unlock_updates() any more.

---

Sorry for the duplicate, the previous one was sent too early.

---
 fs/ext3/super.c |   39 ++++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 21 deletions(-)
fs/ext3/super.c +18 -21
Index: linux/fs/ext3/super.c
===================================================================
@@ -2535,30 +2535,28 @@ static int ext3_sync_fs(struct super_blo
  */
 static int ext3_freeze(struct super_block *sb)
 {
-	int error = 0;
+	int error;
 	journal_t *journal;
 
-	if (!(sb->s_flags & MS_RDONLY)) {
-		journal = EXT3_SB(sb)->s_journal;
+	if (sb->s_flags & MS_RDONLY)
+		return 0;
 
-		/* Now we set up the journal barrier. */
-		journal_lock_updates(journal);
+	journal = EXT3_SB(sb)->s_journal;
 
-		/*
-		 * We don't want to clear needs_recovery flag when we failed
-		 * to flush the journal.
-		 */
-		error = journal_flush(journal);
-		if (error < 0)
-			goto out;
-
-		/* Journal blocked and flushed, clear needs_recovery flag. */
-		EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
-		error = ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
-		if (error)
-			goto out;
-	}
-	return 0;
+	/* Now we set up the journal barrier. */
+	journal_lock_updates(journal);
+
+	/*
+	 * We don't want to clear needs_recovery flag when we failed
+	 * to flush the journal.
+	 */
+	error = journal_flush(journal);
+	if (error < 0)
+		goto out;
+
+	/* Journal blocked and flushed, clear needs_recovery flag. */
+	EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
+	error = ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
 
 out:
 	journal_unlock_updates(journal);
@@ -2577,7 +2575,6 @@ static int ext3_unfreeze(struct super_bl
 		EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
 		ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
 		unlock_super(sb);
-		journal_unlock_updates(EXT3_SB(sb)->s_journal);
 	}
 	return 0;
 }
reviewer
#2 lore raw

Re: [PATCH] fs / ext3: Always unlock updates in ext3_freeze()

Hi,

Quoted 70 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

In analogy with ext4 make ext3_freeze() always call journal_unlock_updates() to prevent it from leaving a locked mutex behind. Accordingly, modify ext3_unfreeze() so that it doesn't call journal_unlock_updates() any more.

---

Sorry for the duplicate, the previous one was sent too early.

---
 fs/ext3/super.c |   39 ++++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 21 deletions(-)

Index: linux/fs/ext3/super.c
===================================================================

fs/ext3/super.c +18 -20
@@ -2535,30 +2535,28 @@ static int ext3_sync_fs(struct super_blo
  */
 static int ext3_freeze(struct super_block *sb)
 {
-	int error = 0;
+	int error;
 	journal_t *journal;
 
-	if (!(sb->s_flags & MS_RDONLY)) {
-		journal = EXT3_SB(sb)->s_journal;
+	if (sb->s_flags & MS_RDONLY)
+		return 0;
 
-		/* Now we set up the journal barrier. */
-		journal_lock_updates(journal);
+	journal = EXT3_SB(sb)->s_journal;
 
-		/*
-		 * We don't want to clear needs_recovery flag when we failed
-		 * to flush the journal.
-		 */
-		error = journal_flush(journal);
-		if (error < 0)
-			goto out;
-
-		/* Journal blocked and flushed, clear needs_recovery flag. */
-		EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
-		error = ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
-		if (error)
-			goto out;
-	}
-	return 0;
+	/* Now we set up the journal barrier. */
+	journal_lock_updates(journal);
+
+	/*
+	 * We don't want to clear needs_recovery flag when we failed
+	 * to flush the journal.
+	 */
+	error = journal_flush(journal);
+	if (error < 0)
+		goto out;
+
+	/* Journal blocked and flushed, clear needs_recovery flag. */
+	EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
+	error = ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
 
 out:
 	journal_unlock_updates(journal);

fs/ext3/super.c static int ext3_unfreeze(struct super_bl · line 2580

Quoted 7 lines
fs/ext3/super.c +0 -1
@@ -2577,7 +2575,6 @@ static int ext3_unfreeze(struct super_bl
 		EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
 		ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
 		unlock_super(sb);
-		journal_unlock_updates(EXT3_SB(sb)->s_journal);
 	}
 	return 0;
 }

It's not so simple as this. Ext3 relies on the mutex (the one hidden in
journal_lock_updates()) to make sure that new transaction cannot be started while the filesystem is frozen - that's essentially what makes the filesystem frozen. So if we want to get rid of the mutex we have to achieve blocking by something else - ext4 uses vfs_check_frozen() in ext4_journal_start().
BTW, filesystem freezing never really worked for mmaped writes under
ext3 - ext3 would have to implement page_mkwrite() callback for that - so if you want to rely on it for suspending, this will be non-trivial.

Honza

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

Re: [PATCH] fs / ext3: Always unlock updates in ext3_freeze()

Hi,

Quoted 69 lines · Jan Kara

Hi,

Quoted 67 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

In analogy with ext4 make ext3_freeze() always call journal_unlock_updates() to prevent it from leaving a locked mutex behind. Accordingly, modify ext3_unfreeze() so that it doesn't call journal_unlock_updates() any more.

---

Sorry for the duplicate, the previous one was sent too early.

---
 fs/ext3/super.c |   39 ++++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 21 deletions(-)

Index: linux/fs/ext3/super.c
===================================================================

fs/ext3/super.c +18 -20
@@ -2535,30 +2535,28 @@ static int ext3_sync_fs(struct super_blo
  */
 static int ext3_freeze(struct super_block *sb)
 {
-	int error = 0;
+	int error;
 	journal_t *journal;
 
-	if (!(sb->s_flags & MS_RDONLY)) {
-		journal = EXT3_SB(sb)->s_journal;
+	if (sb->s_flags & MS_RDONLY)
+		return 0;
 
-		/* Now we set up the journal barrier. */
-		journal_lock_updates(journal);
+	journal = EXT3_SB(sb)->s_journal;
 
-		/*
-		 * We don't want to clear needs_recovery flag when we failed
-		 * to flush the journal.
-		 */
-		error = journal_flush(journal);
-		if (error < 0)
-			goto out;
-
-		/* Journal blocked and flushed, clear needs_recovery flag. */
-		EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
-		error = ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
-		if (error)
-			goto out;
-	}
-	return 0;
+	/* Now we set up the journal barrier. */
+	journal_lock_updates(journal);
+
+	/*
+	 * We don't want to clear needs_recovery flag when we failed
+	 * to flush the journal.
+	 */
+	error = journal_flush(journal);
+	if (error < 0)
+		goto out;
+
+	/* Journal blocked and flushed, clear needs_recovery flag. */
+	EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
+	error = ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
 
Quoted 16 lines

fs/ext3/super.c static int ext3_unfreeze(struct super_bl · line 2580

Quoted 10 lines
fs/ext3/super.c +0 -1
 out:
 	journal_unlock_updates(journal);
@@ -2577,7 +2575,6 @@ static int ext3_unfreeze(struct super_bl
 		EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
 		ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
 		unlock_super(sb);
-		journal_unlock_updates(EXT3_SB(sb)->s_journal);
 	}
 	return 0;
 }

It's not so simple as this. Ext3 relies on the mutex (the one hidden in
journal_lock_updates()) to make sure that new transaction cannot be started while the filesystem is frozen - that's essentially what makes the filesystem frozen. So if we want to get rid of the mutex we have to achieve blocking by something else - ext4 uses vfs_check_frozen() in ext4_journal_start().

I see. Still, freeze_bdev() may be called by user space through a syscall, as far as I can say, so it shouldn't leave the mutex locked.

Quoted 3 lines

BTW, filesystem freezing never really worked for mmaped writes under
ext3 - ext3 would have to implement page_mkwrite() callback for that - so if you want to rely on it for suspending, this will be non-trivial.

At this point the purpose of freezing filesystems is basically to prevent XFS from deadlocking with hibernation's memory preallocation. For other filesystems it may or may not make a difference depending on their implementation of freeze/unfreeze_super().

Thanks,
Rafael

reviewer
#4 lore raw

Re: [PATCH] fs / ext3: Always unlock updates in ext3_freeze()

Hello,

Quoted 87 lines · Rafael J. Wysocki
Quoted 69 lines · Jan Kara

Hi,

Quoted 67 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

In analogy with ext4 make ext3_freeze() always call journal_unlock_updates() to prevent it from leaving a locked mutex behind. Accordingly, modify ext3_unfreeze() so that it doesn't call journal_unlock_updates() any more.

---

Sorry for the duplicate, the previous one was sent too early.

---
 fs/ext3/super.c |   39 ++++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 21 deletions(-)

Index: linux/fs/ext3/super.c
===================================================================

fs/ext3/super.c +18 -20
@@ -2535,30 +2535,28 @@ static int ext3_sync_fs(struct super_blo
  */
 static int ext3_freeze(struct super_block *sb)
 {
-	int error = 0;
+	int error;
 	journal_t *journal;
 
-	if (!(sb->s_flags & MS_RDONLY)) {
-		journal = EXT3_SB(sb)->s_journal;
+	if (sb->s_flags & MS_RDONLY)
+		return 0;
 
-		/* Now we set up the journal barrier. */
-		journal_lock_updates(journal);
+	journal = EXT3_SB(sb)->s_journal;
 
-		/*
-		 * We don't want to clear needs_recovery flag when we failed
-		 * to flush the journal.
-		 */
-		error = journal_flush(journal);
-		if (error < 0)
-			goto out;
-
-		/* Journal blocked and flushed, clear needs_recovery flag. */
-		EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
-		error = ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
-		if (error)
-			goto out;
-	}
-	return 0;
+	/* Now we set up the journal barrier. */
+	journal_lock_updates(journal);
+
+	/*
+	 * We don't want to clear needs_recovery flag when we failed
+	 * to flush the journal.
+	 */
+	error = journal_flush(journal);
+	if (error < 0)
+		goto out;
+
+	/* Journal blocked and flushed, clear needs_recovery flag. */
+	EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
+	error = ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
 
Quoted 16 lines

fs/ext3/super.c static int ext3_unfreeze(struct super_bl · line 2580

Quoted 10 lines
fs/ext3/super.c +0 -1
 out:
 	journal_unlock_updates(journal);
@@ -2577,7 +2575,6 @@ static int ext3_unfreeze(struct super_bl
 		EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
 		ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1);
 		unlock_super(sb);
-		journal_unlock_updates(EXT3_SB(sb)->s_journal);
 	}
 	return 0;
 }

It's not so simple as this. Ext3 relies on the mutex (the one hidden in
journal_lock_updates()) to make sure that new transaction cannot be started while the filesystem is frozen - that's essentially what makes the filesystem frozen. So if we want to get rid of the mutex we have to achieve blocking by something else - ext4 uses vfs_check_frozen() in ext4_journal_start().

Quoted 2 lines

I see. Still, freeze_bdev() may be called by user space through a syscall, as far as I can say, so it shouldn't leave the mutex locked.

Yes, I agree with you. That's an ugliness left over from a long time ago.
I'll have a look at fixing this...

Quoted 8 lines
Quoted 3 lines

BTW, filesystem freezing never really worked for mmaped writes under
ext3 - ext3 would have to implement page_mkwrite() callback for that - so if you want to rely on it for suspending, this will be non-trivial.

At this point the purpose of freezing filesystems is basically to prevent XFS from deadlocking with hibernation's memory preallocation. For other filesystems it may or may not make a difference depending on their implementation of freeze/unfreeze_super().

What's exactly the problem? Memory preallocation enters direct reclaim
and that deadlocks in the filesystem?

Honza

#5 lore raw

Re: [PATCH] fs / ext3: Always unlock updates in ext3_freeze()

Hi,

Quoted 4 lines · Jan Kara

Hello,

Quoted 1 line · Rafael J. Wysocki

On Monday, August 15, 2011, Jan Kara wrote:

...

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines

It's not so simple as this. Ext3 relies on the mutex (the one hidden in
journal_lock_updates()) to make sure that new transaction cannot be started while the filesystem is frozen - that's essentially what makes the filesystem frozen. So if we want to get rid of the mutex we have to achieve blocking by something else - ext4 uses vfs_check_frozen() in ext4_journal_start().

I see. Still, freeze_bdev() may be called by user space through a syscall, as far as I can say, so it shouldn't leave the mutex locked.

Yes, I agree with you. That's an ugliness left over from a long time ago.
I'll have a look at fixing this...

Thanks!

Quoted 10 lines
Quoted 8 lines
Quoted 3 lines

BTW, filesystem freezing never really worked for mmaped writes under
ext3 - ext3 would have to implement page_mkwrite() callback for that - so if you want to rely on it for suspending, this will be non-trivial.

At this point the purpose of freezing filesystems is basically to prevent XFS from deadlocking with hibernation's memory preallocation. For other filesystems it may or may not make a difference depending on their implementation of freeze/unfreeze_super().

What's exactly the problem? Memory preallocation enters direct reclaim
and that deadlocks in the filesystem?

Yes, that seems to be the case.

Thanks,
Rafael

#6 lore raw

Re: [PATCH] fs / ext3: Always unlock updates in ext3_freeze()

In reply to Jan Kara
Quoted 8 lines · Jan Kara

Hello,

Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Jan Kara

BTW, filesystem freezing never really worked for mmaped writes under
ext3 - ext3 would have to implement page_mkwrite() callback for that - so if you want to rely on it for suspending, this will be non-trivial.

Quoted 6 lines
Quoted 4 lines

At this point the purpose of freezing filesystems is basically to prevent XFS from deadlocking with hibernation's memory preallocation. For other filesystems it may or may not make a difference depending on their implementation of freeze/unfreeze_super().

What's exactly the problem? Memory preallocation enters direct reclaim
and that deadlocks in the filesystem?

Well, that's one possible manifestation. The problem is that the current hibernate code still assumes that sys_sync() results in an idle filesystem that will not change after the call if nothing is dirty.

The result is that when the large memory allocation occurs for the hibernate image (after the sys_sync() call) then the shrink_slab() tends to be called. The XFS shrinkers are capable of dirtying inodes and the backing buffers of inodes that are in the reclaimable state. But those buffers cannot be flushed to disk because hibernate has already frozen the xfsbufd threads, so the shrinker doing inode reclaim hangs up on locks waiting for the buffers to be written. This either leads to deadlock or hibernate image allocation failure.

Far worse, IMO, is the case where is -doesn't- deadlock, because the filesystem state can still changing after the allocation has finished due to async metadata IO completions. That has the potential to cause filesystem corruption as after resume the on-disk state may not match what is written from memory to the hibernate image.

The problem really isn't XFS specific, nor is it new - the fact is that any filesystem that has registered a shrinker or can do async work in the background post-sync is vulnerable to this problem. It's just that XFS is the filesystem that usually exposes such issues, so it gets blamed for causing the problem....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#7 lore raw

Re: [PATCH] fs / ext3: Always unlock updates in ext3_freeze()

Quoted 37 lines · Dave Chinner
Quoted 8 lines · Jan Kara

Hello,

Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Jan Kara

BTW, filesystem freezing never really worked for mmaped writes under
ext3 - ext3 would have to implement page_mkwrite() callback for that - so if you want to rely on it for suspending, this will be non-trivial.

Quoted 6 lines
Quoted 4 lines

At this point the purpose of freezing filesystems is basically to prevent XFS from deadlocking with hibernation's memory preallocation. For other filesystems it may or may not make a difference depending on their implementation of freeze/unfreeze_super().

What's exactly the problem? Memory preallocation enters direct reclaim
and that deadlocks in the filesystem?

Well, that's one possible manifestation. The problem is that the current hibernate code still assumes that sys_sync() results in an idle filesystem that will not change after the call if nothing is dirty.

The result is that when the large memory allocation occurs for the hibernate image (after the sys_sync() call) then the shrink_slab() tends to be called. The XFS shrinkers are capable of dirtying inodes and the backing buffers of inodes that are in the reclaimable state. But those buffers cannot be flushed to disk because hibernate has already frozen the xfsbufd threads, so the shrinker doing inode reclaim hangs up on locks waiting for the buffers to be written. This either leads to deadlock or hibernate image allocation failure.

Far worse, IMO, is the case where is -doesn't- deadlock, because the filesystem state can still changing after the allocation has finished due to async metadata IO completions. That has the potential to cause filesystem corruption as after resume the on-disk state may not match what is written from memory to the hibernate image.

Quoted 5 lines

The problem really isn't XFS specific, nor is it new - the fact is that any filesystem that has registered a shrinker or can do async work in the background post-sync is vulnerable to this problem. It's just that XFS is the filesystem that usually exposes such issues, so it gets blamed for causing the problem....

I'm not saying it's XFS' fault. It's just that XFS tends to do things that other filesystems don't do and that expose the problem in the hibernate code.

Thanks,
Rafael

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

Re: [PATCH] fs / ext3: Always unlock updates in ext3_freeze()

Quoted 26 lines · Pavel Machek

Hi!

Quoted 24 lines
Quoted 2 lines

What's exactly the problem? Memory preallocation enters direct reclaim
and that deadlocks in the filesystem?

Well, that's one possible manifestation. The problem is that the current hibernate code still assumes that sys_sync() results in an idle filesystem that will not change after the call if nothing is dirty.

The result is that when the large memory allocation occurs for the hibernate image (after the sys_sync() call) then the shrink_slab() tends to be called. The XFS shrinkers are capable of dirtying inodes and the backing buffers of inodes that are in the reclaimable state. But those buffers cannot be flushed to disk because hibernate has already frozen the xfsbufd threads, so the shrinker doing inode reclaim hangs up on locks waiting for the buffers to be written. This either leads to deadlock or hibernate image allocation failure.

Far worse, IMO, is the case where is -doesn't- deadlock, because the filesystem state can still changing after the allocation has finished due to async metadata IO completions. That has the potential to cause filesystem corruption as after resume the on-disk state may not match what is written from memory to the hibernate image.

Quoted 5 lines
Quoted 3 lines

The problem really isn't XFS specific, nor is it new - the fact is that any filesystem that has registered a shrinker or can do async work in the background post-sync is vulnerable to this problem. It's

Should we avoid calling shrinkers while hibernating?

If you like getting random OOM problems when hibernating, then go for it. Besides, shrinkers are used for more than just filesystems, so you might find you screw entire classes of users by doing this (eg everyone using intel graphics and 3D).

Quoted 2 lines

Or put BUG_ON()s into filesystem shrinkers so that this can not happen?

Definitely not. If your concern is filesystem shrinkers and you want a large hammer to hit the problem with then do your hibernate image allocation wih GFP_NOFS and the filesystem shrinkers will abort without doing anything.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#10 lore raw

Re: [PATCH] fs / ext3: Always unlock updates in ext3_freeze()

Quoted 38 lines · Dave Chinner
Quoted 26 lines · Pavel Machek

Hi!

Quoted 24 lines
Quoted 2 lines

What's exactly the problem? Memory preallocation enters direct reclaim
and that deadlocks in the filesystem?

Well, that's one possible manifestation. The problem is that the current hibernate code still assumes that sys_sync() results in an idle filesystem that will not change after the call if nothing is dirty.

The result is that when the large memory allocation occurs for the hibernate image (after the sys_sync() call) then the shrink_slab() tends to be called. The XFS shrinkers are capable of dirtying inodes and the backing buffers of inodes that are in the reclaimable state. But those buffers cannot be flushed to disk because hibernate has already frozen the xfsbufd threads, so the shrinker doing inode reclaim hangs up on locks waiting for the buffers to be written. This either leads to deadlock or hibernate image allocation failure.

Far worse, IMO, is the case where is -doesn't- deadlock, because the filesystem state can still changing after the allocation has finished due to async metadata IO completions. That has the potential to cause filesystem corruption as after resume the on-disk state may not match what is written from memory to the hibernate image.

Quoted 5 lines
Quoted 3 lines

The problem really isn't XFS specific, nor is it new - the fact is that any filesystem that has registered a shrinker or can do async work in the background post-sync is vulnerable to this problem. It's

Should we avoid calling shrinkers while hibernating?

If you like getting random OOM problems when hibernating, then go for it. Besides, shrinkers are used for more than just filesystems, so you might find you screw entire classes of users by doing this (eg everyone using intel graphics and 3D).

Quoted 7 lines
Quoted 2 lines

Or put BUG_ON()s into filesystem shrinkers so that this can not happen?

Definitely not. If your concern is filesystem shrinkers and you want a large hammer to hit the problem with then do your hibernate image allocation wih GFP_NOFS and the filesystem shrinkers will abort without doing anything.

I think we can do that, actually.

Thanks,
Rafael

#11 lore raw

Re: [PATCH] fs / ext3: Always unlock updates in ext3_freeze()

Hi!

Quoted 14 lines
Quoted 14 lines
Quoted 5 lines
Quoted 3 lines

The problem really isn't XFS specific, nor is it new - the fact is that any filesystem that has registered a shrinker or can do async work in the background post-sync is vulnerable to this problem. It's

Should we avoid calling shrinkers while hibernating?

If you like getting random OOM problems when hibernating, then go for it. Besides, shrinkers are used for more than just filesystems, so you might find you screw entire classes of users by doing this (eg everyone using intel graphics and 3D).

Quoted 2 lines

Or put BUG_ON()s into filesystem shrinkers so that this can not happen?

Quoted 6 lines
Quoted 4 lines

Definitely not. If your concern is filesystem shrinkers and you want a large hammer to hit the problem with then do your hibernate image allocation wih GFP_NOFS and the filesystem shrinkers will abort without doing anything.

I think we can do that, actually.

I believe we should, yes. Question is if it helps much, because various drivers (and userspace in case uswsusp?) will still trigger GFP_KERNEL allocations.

Something like this?

snapshot.c renamed from snapshot.c.ofic +1 -1
@@ -1107,7 +1107,7 @@
 
 /* Helper functions used for the shrinking of memory. */
 
-#define GFP_IMAGE	(GFP_KERNEL | __GFP_NOWARN)
+#define GFP_IMAGE	(GFP_NODS | __GFP_NOWARN)
 
 /**
  * preallocate_image_pages - Allocate a number of pages for hibernation image
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#12 lore raw

Re: [PATCH] fs / ext3: Always unlock updates in ext3_freeze()

Quoted 32 lines · Pavel Machek

Hi!

Quoted 14 lines
Quoted 14 lines
Quoted 5 lines
Quoted 3 lines

The problem really isn't XFS specific, nor is it new - the fact is that any filesystem that has registered a shrinker or can do async work in the background post-sync is vulnerable to this problem. It's

Should we avoid calling shrinkers while hibernating?

If you like getting random OOM problems when hibernating, then go for it. Besides, shrinkers are used for more than just filesystems, so you might find you screw entire classes of users by doing this (eg everyone using intel graphics and 3D).

Quoted 2 lines

Or put BUG_ON()s into filesystem shrinkers so that this can not happen?

Quoted 6 lines
Quoted 4 lines

Definitely not. If your concern is filesystem shrinkers and you want a large hammer to hit the problem with then do your hibernate image allocation wih GFP_NOFS and the filesystem shrinkers will abort without doing anything.

I think we can do that, actually.

I believe we should, yes. Question is if it helps much, because various drivers (and userspace in case uswsusp?) will still trigger GFP_KERNEL allocations.

Something like this?

snapshot.c line 1110

Quoted 5 lines
snapshot.c renamed from snapshot.c.ofic +1 -1
@@ -1107,7 +1107,7 @@
 
 /* Helper functions used for the shrinking of memory. */
 
-#define GFP_IMAGE	(GFP_KERNEL | __GFP_NOWARN)
+#define GFP_IMAGE	(GFP_NODS | __GFP_NOWARN)

Surely GFP_NOFS?

Quoted 6 lines
snapshot.c renamed from snapshot.c.ofic +0 -0
 /**
  * preallocate_image_pages - Allocate a number of pages for hibernation image