linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* potential memory leak on transaction commit
@ 2011-03-08 11:40 Zhang Huan
  2011-03-08 13:16 ` Lukas Czerner
  2011-03-15  6:39 ` Zhang Huan
  0 siblings, 2 replies; 8+ messages in thread
From: Zhang Huan @ 2011-03-08 11:40 UTC (permalink / raw)
  To: linux-ext4

Hi all,

There is potential memory leak of journal head in function
jbd2_journal_commit_transaction. The problem is that JBD2 will not
reclaim the journal head of commit record if error occurs or journal is
abotred.

I use the following script to reproduce this issue, on a RHEL6 system. I
found it very easy to reproduce with async commit enabled.

mount /dev/sdb /mnt -o journal_checksum,journal_async_commit
touch /mnt/xxx
echo offline > /sys/block/sdb/device/state
sync
umount /mnt
rmmod ext4
rmmod jbd2

Removal of the jbd2 module will make slab complaining that
"cache `jbd2_journal_head': can't free all objects".


Here is my fix for this issue. The commit record should be reclaimed no
matter error occurs or not.

diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index f3ad159..37a973a 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -105,6 +105,8 @@ static int journal_submit_commit_record(journal_t *journal,
 	int ret;
 	struct timespec now = current_kernel_time();
 
+	*cbh = NULL;
+
 	if (is_journal_aborted(journal))
 		return 0;
 
@@ -808,7 +810,7 @@ wait_for_iobuf:
 		if (err)
 			__jbd2_journal_abort_hard(journal);
 	}
-	if (!err && !is_journal_aborted(journal))
+	if (cbh)
 		err = journal_wait_on_commit_record(journal, cbh);
 	if (JBD2_HAS_INCOMPAT_FEATURE(journal,
 				      JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) &&



PS: Just out of curiosity, why would journal_submit_commit_record return a
value of 1 instead of an error number if get descriptor buffer is failed.


Zhang Huan

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-04-05 23:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-08 11:40 potential memory leak on transaction commit Zhang Huan
2011-03-08 13:16 ` Lukas Czerner
2011-03-08 14:43   ` Zhang Huan
2011-03-08 16:13     ` Lukas Czerner
2011-03-15  6:39 ` Zhang Huan
2011-04-04 22:10   ` Ted Ts'o
2011-04-05 12:35     ` Zhang Huan
2011-04-05 23:27       ` Ted Ts'o

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).