From: Jan Kara <jack@suse.cz>
To: <linux-ext4@vger.kernel.org>
Cc: Ted Tso <tytso@mit.edu>, Jan Kara <jack@suse.cz>
Subject: [PATCH 14/19] jbd2: Account descriptor blocks into t_outstanding_credits
Date: Mon, 30 Sep 2019 12:43:32 +0200 [thread overview]
Message-ID: <20190930104339.24919-14-jack@suse.cz> (raw)
In-Reply-To: <20190930103544.11479-1-jack@suse.cz>
Currently, journal descriptor blocks were not accounted in
transaction->t_outstanding_credits and we were just leaving some slack
space in the journal for them (in jbd2_log_space_left() and
jbd2_space_needed()). This is making proper accounting (and reservation
we want to add) of descriptor blocks difficult so switch to accounting
descriptor blocks in transaction->t_outstanding_credits and just reserve
the same amount of credits in t_outstanding credits for journal
descriptor blocks when creating transaction.
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/jbd2/commit.c | 3 +++
fs/jbd2/journal.c | 1 +
fs/jbd2/transaction.c | 20 ++++++++++++--------
include/linux/jbd2.h | 16 +++-------------
4 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index b67e2d0cff88..43f2dde5bb47 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -889,6 +889,9 @@ void jbd2_journal_commit_transaction(journal_t *journal)
if (err)
jbd2_journal_abort(journal, err);
+ WARN_ON_ONCE(
+ atomic_read(&commit_transaction->t_outstanding_credits) < 0);
+
/*
* Now disk caches for filesystem device are flushed so we are safe to
* erase checkpointed transactions from the log by updating journal
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 953990eb70a9..810363443df4 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -842,6 +842,7 @@ jbd2_journal_get_descriptor_buffer(transaction_t *transaction, int type)
bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
if (!bh)
return NULL;
+ atomic_dec(&transaction->t_outstanding_credits);
lock_buffer(bh);
memset(bh->b_data, 0, journal->j_blocksize);
header = (journal_header_t *)bh->b_data;
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 8a42c717e260..d580a9ce9ec7 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -62,6 +62,17 @@ void jbd2_journal_free_transaction(transaction_t *transaction)
kmem_cache_free(transaction_cache, transaction);
}
+/*
+ * We reserve t_outstanding_credits >> JBD2_CONTROL_BLOCKS_SHIFT for
+ * transaction descriptor blocks.
+ */
+#define JBD2_CONTROL_BLOCKS_SHIFT 5
+
+static int jbd2_descriptor_blocks_per_trans(journal_t *journal)
+{
+ return journal->j_max_transaction_buffers >> JBD2_CONTROL_BLOCKS_SHIFT;
+}
+
/*
* jbd2_get_transaction: obtain a new transaction_t object.
*
@@ -88,6 +99,7 @@ static void jbd2_get_transaction(journal_t *journal,
spin_lock_init(&transaction->t_handle_lock);
atomic_set(&transaction->t_updates, 0);
atomic_set(&transaction->t_outstanding_credits,
+ jbd2_descriptor_blocks_per_trans(journal) +
atomic_read(&journal->j_reserved_credits));
atomic_set(&transaction->t_handle_count, 0);
INIT_LIST_HEAD(&transaction->t_inode_list);
@@ -631,14 +643,6 @@ int jbd2_journal_extend(handle_t *handle, int nblocks)
goto unlock;
}
- if (wanted + (wanted >> JBD2_CONTROL_BLOCKS_SHIFT) >
- jbd2_log_space_left(journal)) {
- jbd_debug(3, "denied handle %p %d blocks: "
- "insufficient log space\n", handle, nblocks);
- atomic_sub(nblocks, &transaction->t_outstanding_credits);
- goto unlock;
- }
-
trace_jbd2_handle_extend(journal->j_fs_dev->bd_dev,
transaction->t_tid,
handle->h_type, handle->h_line_no,
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index c2ad74ea6015..dd9541a9d3c4 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -1562,20 +1562,13 @@ static inline int jbd2_journal_has_csum_v2or3(journal_t *journal)
return journal->j_chksum_driver != NULL;
}
-/*
- * We reserve t_outstanding_credits >> JBD2_CONTROL_BLOCKS_SHIFT for
- * transaction control blocks.
- */
-#define JBD2_CONTROL_BLOCKS_SHIFT 5
-
/*
* Return the minimum number of blocks which must be free in the journal
* before a new transaction may be started. Must be called under j_state_lock.
*/
static inline int jbd2_space_needed(journal_t *journal)
{
- int nblocks = journal->j_max_transaction_buffers;
- return nblocks + (nblocks >> JBD2_CONTROL_BLOCKS_SHIFT);
+ return journal->j_max_transaction_buffers;
}
/*
@@ -1587,11 +1580,8 @@ static inline unsigned long jbd2_log_space_left(journal_t *journal)
long free = journal->j_free - 32;
if (journal->j_committing_transaction) {
- unsigned long committing = atomic_read(&journal->
- j_committing_transaction->t_outstanding_credits);
-
- /* Transaction + control blocks */
- free -= committing + (committing >> JBD2_CONTROL_BLOCKS_SHIFT);
+ free -= atomic_read(&journal->
+ j_committing_transaction->t_outstanding_credits);
}
return max_t(long, free, 0);
}
--
2.16.4
next prev parent reply other threads:[~2019-09-30 10:43 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-30 10:43 [PATCH 0/19 v2] ext4: Fix transaction overflow due to revoke descriptors Jan Kara
2019-09-30 10:43 ` [PATCH 01/19] jbd2: Fix possible overflow in jbd2_log_space_left() Jan Kara
2019-09-30 10:43 ` [PATCH 02/19] jbd2: Fixup stale comment in commit code Jan Kara
2019-09-30 10:43 ` [PATCH 03/19] ext4: Do not iput inode under running transaction in ext4_mkdir() Jan Kara
2019-09-30 10:43 ` [PATCH 04/19] ext4: Use ext4_journal_extend() instead of jbd2_journal_extend() Jan Kara
2019-09-30 10:43 ` [PATCH 05/19] ext4: Avoid unnecessary revokes in ext4_alloc_branch() Jan Kara
2019-09-30 10:43 ` [PATCH 06/19] ext4: Provide function to handle transaction restarts Jan Kara
2019-09-30 10:43 ` [PATCH 07/19] ext4, jbd2: Provide accessor function for handle credits Jan Kara
2019-09-30 10:43 ` [PATCH 08/19] ocfs2: Use accessor function for h_buffer_credits Jan Kara
2019-09-30 10:43 ` [PATCH 09/19] jbd2: Fix statistics for the number of logged blocks Jan Kara
2019-09-30 10:43 ` [PATCH 10/19] jbd2: Reorganize jbd2_journal_stop() Jan Kara
2019-09-30 10:43 ` [PATCH 11/19] jbd2: Drop pointless check from jbd2_journal_stop() Jan Kara
2019-09-30 10:43 ` [PATCH 12/19] jbd2: Drop pointless wakeup " Jan Kara
2019-09-30 10:43 ` [PATCH 13/19] jbd2: Factor out common parts of stopping and restarting a handle Jan Kara
2019-09-30 10:43 ` Jan Kara [this message]
2019-09-30 10:43 ` [PATCH 15/19] jbd2: Drop jbd2_space_needed() Jan Kara
2019-09-30 10:43 ` [PATCH 16/19] jbd2: Reserve space for revoke descriptor blocks Jan Kara
2019-09-30 12:24 ` kbuild test robot
2019-09-30 10:43 ` [PATCH 17/19] jbd2: Rename h_buffer_credits to h_total_credits Jan Kara
2019-09-30 11:27 ` kbuild test robot
2019-09-30 12:26 ` kbuild test robot
2019-09-30 15:05 ` Theodore Y. Ts'o
2019-09-30 16:25 ` Jan Kara
2019-09-30 21:21 ` Theodore Y. Ts'o
2019-10-01 7:59 ` Jan Kara
2019-10-03 8:33 ` Jan Kara
2019-10-03 13:29 ` Theodore Y. Ts'o
2019-10-03 21:50 ` Jan Kara
2019-09-30 10:43 ` [PATCH 18/19] jbd2: Make credit checking more strict Jan Kara
2019-09-30 10:43 ` [PATCH 19/19] ext4: Reserve revoke credits for freed blocks Jan Kara
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=20190930104339.24919-14-jack@suse.cz \
--to=jack@suse.cz \
--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).