mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
jbd2: cleanup needed free block estimates when starting a transaction
__jbd2_log_space_left() and jbd_space_needed() were kind of odd. jbd_space_needed() accounted also credits needed for currently committing transaction while it didn't account for credits needed for control blocks. __jbd2_log_space_left() then accounted for control blocks as a fraction of free space. Since results of these two functions are always only compared against each other, this works correct but is somewhat strange. Move the estimates so that jbd_space_needed() returns number of blocks needed for a transaction including control blocks and __jbd2_log_space_left() returns free space in the journal (with the committing transaction already subtracted). Rename functions to jbd2_log_space_left() and jbd2_space_needed() while we are changing them. Reviewed-by: Zheng Liu <wenqing.lz@taobao.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
parent
2f387f849b
commit
76c3990456
4 changed files with 35 additions and 43 deletions
|
@ -1220,7 +1220,6 @@ extern void jbd2_clear_buffer_revoked_flags(journal_t *journal);
|
|||
* transitions on demand.
|
||||
*/
|
||||
|
||||
int __jbd2_log_space_left(journal_t *); /* Called with journal locked */
|
||||
int jbd2_log_start_commit(journal_t *journal, tid_t tid);
|
||||
int __jbd2_log_start_commit(journal_t *journal, tid_t tid);
|
||||
int jbd2_journal_start_commit(journal_t *journal, tid_t *tid);
|
||||
|
@ -1290,17 +1289,38 @@ static inline int tid_geq(tid_t x, tid_t y)
|
|||
extern int jbd2_journal_blocks_per_page(struct inode *inode);
|
||||
extern size_t journal_tag_bytes(journal_t *journal);
|
||||
|
||||
/*
|
||||
* 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 jbd_space_needed(journal_t *journal)
|
||||
static inline int jbd2_space_needed(journal_t *journal)
|
||||
{
|
||||
int nblocks = journal->j_max_transaction_buffers;
|
||||
if (journal->j_committing_transaction)
|
||||
nblocks += atomic_read(&journal->j_committing_transaction->
|
||||
t_outstanding_credits);
|
||||
return nblocks;
|
||||
return nblocks + (nblocks >> JBD2_CONTROL_BLOCKS_SHIFT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return number of free blocks in the log. Must be called under j_state_lock.
|
||||
*/
|
||||
static inline unsigned long jbd2_log_space_left(journal_t *journal)
|
||||
{
|
||||
/* Allow for rounding errors */
|
||||
unsigned 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);
|
||||
}
|
||||
return free;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue