jbd2: remove journal_clean_one_cp_list()
journal_clean_one_cp_list() and journal_shrink_one_cp_list() are almost the same, so merge them into journal_shrink_one_cp_list(), remove the nr_to_scan parameter, always scan and try to free the whole checkpoint list. Signed-off-by: Zhang Yi <yi.zhang@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20230606135928.434610-4-yi.zhang@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
parent
be22255360
commit
b98dba273a
2 changed files with 26 additions and 71 deletions
|
@ -348,19 +348,24 @@ int jbd2_cleanup_journal_tail(journal_t *journal)
|
||||||
/* Checkpoint list management */
|
/* Checkpoint list management */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* journal_clean_one_cp_list
|
* journal_shrink_one_cp_list
|
||||||
*
|
*
|
||||||
* Find all the written-back checkpoint buffers in the given list and
|
* Find all the written-back checkpoint buffers in the given list
|
||||||
* release them. If 'destroy' is set, clean all buffers unconditionally.
|
* and try to release them. If the whole transaction is released, set
|
||||||
|
* the 'released' parameter. Return the number of released checkpointed
|
||||||
|
* buffers.
|
||||||
*
|
*
|
||||||
* Called with j_list_lock held.
|
* Called with j_list_lock held.
|
||||||
* Returns 1 if we freed the transaction, 0 otherwise.
|
|
||||||
*/
|
*/
|
||||||
static int journal_clean_one_cp_list(struct journal_head *jh, bool destroy)
|
static unsigned long journal_shrink_one_cp_list(struct journal_head *jh,
|
||||||
|
bool destroy, bool *released)
|
||||||
{
|
{
|
||||||
struct journal_head *last_jh;
|
struct journal_head *last_jh;
|
||||||
struct journal_head *next_jh = jh;
|
struct journal_head *next_jh = jh;
|
||||||
|
unsigned long nr_freed = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
*released = false;
|
||||||
if (!jh)
|
if (!jh)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -370,52 +375,6 @@ static int journal_clean_one_cp_list(struct journal_head *jh, bool destroy)
|
||||||
next_jh = jh->b_cpnext;
|
next_jh = jh->b_cpnext;
|
||||||
|
|
||||||
if (!destroy && __cp_buffer_busy(jh))
|
if (!destroy && __cp_buffer_busy(jh))
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (__jbd2_journal_remove_checkpoint(jh))
|
|
||||||
return 1;
|
|
||||||
/*
|
|
||||||
* This function only frees up some memory
|
|
||||||
* if possible so we dont have an obligation
|
|
||||||
* to finish processing. Bail out if preemption
|
|
||||||
* requested:
|
|
||||||
*/
|
|
||||||
if (need_resched())
|
|
||||||
return 0;
|
|
||||||
} while (jh != last_jh);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* journal_shrink_one_cp_list
|
|
||||||
*
|
|
||||||
* Find 'nr_to_scan' written-back checkpoint buffers in the given list
|
|
||||||
* and try to release them. If the whole transaction is released, set
|
|
||||||
* the 'released' parameter. Return the number of released checkpointed
|
|
||||||
* buffers.
|
|
||||||
*
|
|
||||||
* Called with j_list_lock held.
|
|
||||||
*/
|
|
||||||
static unsigned long journal_shrink_one_cp_list(struct journal_head *jh,
|
|
||||||
unsigned long *nr_to_scan,
|
|
||||||
bool *released)
|
|
||||||
{
|
|
||||||
struct journal_head *last_jh;
|
|
||||||
struct journal_head *next_jh = jh;
|
|
||||||
unsigned long nr_freed = 0;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!jh || *nr_to_scan == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
last_jh = jh->b_cpprev;
|
|
||||||
do {
|
|
||||||
jh = next_jh;
|
|
||||||
next_jh = jh->b_cpnext;
|
|
||||||
|
|
||||||
(*nr_to_scan)--;
|
|
||||||
if (__cp_buffer_busy(jh))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
nr_freed++;
|
nr_freed++;
|
||||||
|
@ -427,7 +386,7 @@ static unsigned long journal_shrink_one_cp_list(struct journal_head *jh,
|
||||||
|
|
||||||
if (need_resched())
|
if (need_resched())
|
||||||
break;
|
break;
|
||||||
} while (jh != last_jh && *nr_to_scan);
|
} while (jh != last_jh);
|
||||||
|
|
||||||
return nr_freed;
|
return nr_freed;
|
||||||
}
|
}
|
||||||
|
@ -445,11 +404,11 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
|
||||||
unsigned long *nr_to_scan)
|
unsigned long *nr_to_scan)
|
||||||
{
|
{
|
||||||
transaction_t *transaction, *last_transaction, *next_transaction;
|
transaction_t *transaction, *last_transaction, *next_transaction;
|
||||||
bool released;
|
bool __maybe_unused released;
|
||||||
tid_t first_tid = 0, last_tid = 0, next_tid = 0;
|
tid_t first_tid = 0, last_tid = 0, next_tid = 0;
|
||||||
tid_t tid = 0;
|
tid_t tid = 0;
|
||||||
unsigned long nr_freed = 0;
|
unsigned long nr_freed = 0;
|
||||||
unsigned long nr_scanned = *nr_to_scan;
|
unsigned long freed;
|
||||||
|
|
||||||
again:
|
again:
|
||||||
spin_lock(&journal->j_list_lock);
|
spin_lock(&journal->j_list_lock);
|
||||||
|
@ -478,10 +437,11 @@ again:
|
||||||
transaction = next_transaction;
|
transaction = next_transaction;
|
||||||
next_transaction = transaction->t_cpnext;
|
next_transaction = transaction->t_cpnext;
|
||||||
tid = transaction->t_tid;
|
tid = transaction->t_tid;
|
||||||
released = false;
|
|
||||||
|
|
||||||
nr_freed += journal_shrink_one_cp_list(transaction->t_checkpoint_list,
|
freed = journal_shrink_one_cp_list(transaction->t_checkpoint_list,
|
||||||
nr_to_scan, &released);
|
false, &released);
|
||||||
|
nr_freed += freed;
|
||||||
|
(*nr_to_scan) -= min(*nr_to_scan, freed);
|
||||||
if (*nr_to_scan == 0)
|
if (*nr_to_scan == 0)
|
||||||
break;
|
break;
|
||||||
if (need_resched() || spin_needbreak(&journal->j_list_lock))
|
if (need_resched() || spin_needbreak(&journal->j_list_lock))
|
||||||
|
@ -502,9 +462,8 @@ again:
|
||||||
if (*nr_to_scan && next_tid)
|
if (*nr_to_scan && next_tid)
|
||||||
goto again;
|
goto again;
|
||||||
out:
|
out:
|
||||||
nr_scanned -= *nr_to_scan;
|
|
||||||
trace_jbd2_shrink_checkpoint_list(journal, first_tid, tid, last_tid,
|
trace_jbd2_shrink_checkpoint_list(journal, first_tid, tid, last_tid,
|
||||||
nr_freed, nr_scanned, next_tid);
|
nr_freed, next_tid);
|
||||||
|
|
||||||
return nr_freed;
|
return nr_freed;
|
||||||
}
|
}
|
||||||
|
@ -520,7 +479,7 @@ out:
|
||||||
void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
|
void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
|
||||||
{
|
{
|
||||||
transaction_t *transaction, *last_transaction, *next_transaction;
|
transaction_t *transaction, *last_transaction, *next_transaction;
|
||||||
int ret;
|
bool released;
|
||||||
|
|
||||||
transaction = journal->j_checkpoint_transactions;
|
transaction = journal->j_checkpoint_transactions;
|
||||||
if (!transaction)
|
if (!transaction)
|
||||||
|
@ -531,8 +490,8 @@ void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
|
||||||
do {
|
do {
|
||||||
transaction = next_transaction;
|
transaction = next_transaction;
|
||||||
next_transaction = transaction->t_cpnext;
|
next_transaction = transaction->t_cpnext;
|
||||||
ret = journal_clean_one_cp_list(transaction->t_checkpoint_list,
|
journal_shrink_one_cp_list(transaction->t_checkpoint_list,
|
||||||
destroy);
|
destroy, &released);
|
||||||
/*
|
/*
|
||||||
* This function only frees up some memory if possible so we
|
* This function only frees up some memory if possible so we
|
||||||
* dont have an obligation to finish processing. Bail out if
|
* dont have an obligation to finish processing. Bail out if
|
||||||
|
@ -545,7 +504,7 @@ void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
|
||||||
* avoids pointless scanning of transactions which still
|
* avoids pointless scanning of transactions which still
|
||||||
* weren't checkpointed.
|
* weren't checkpointed.
|
||||||
*/
|
*/
|
||||||
if (!ret)
|
if (!released)
|
||||||
return;
|
return;
|
||||||
} while (transaction != last_transaction);
|
} while (transaction != last_transaction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -462,11 +462,9 @@ TRACE_EVENT(jbd2_shrink_scan_exit,
|
||||||
TRACE_EVENT(jbd2_shrink_checkpoint_list,
|
TRACE_EVENT(jbd2_shrink_checkpoint_list,
|
||||||
|
|
||||||
TP_PROTO(journal_t *journal, tid_t first_tid, tid_t tid, tid_t last_tid,
|
TP_PROTO(journal_t *journal, tid_t first_tid, tid_t tid, tid_t last_tid,
|
||||||
unsigned long nr_freed, unsigned long nr_scanned,
|
unsigned long nr_freed, tid_t next_tid),
|
||||||
tid_t next_tid),
|
|
||||||
|
|
||||||
TP_ARGS(journal, first_tid, tid, last_tid, nr_freed,
|
TP_ARGS(journal, first_tid, tid, last_tid, nr_freed, next_tid),
|
||||||
nr_scanned, next_tid),
|
|
||||||
|
|
||||||
TP_STRUCT__entry(
|
TP_STRUCT__entry(
|
||||||
__field(dev_t, dev)
|
__field(dev_t, dev)
|
||||||
|
@ -474,7 +472,6 @@ TRACE_EVENT(jbd2_shrink_checkpoint_list,
|
||||||
__field(tid_t, tid)
|
__field(tid_t, tid)
|
||||||
__field(tid_t, last_tid)
|
__field(tid_t, last_tid)
|
||||||
__field(unsigned long, nr_freed)
|
__field(unsigned long, nr_freed)
|
||||||
__field(unsigned long, nr_scanned)
|
|
||||||
__field(tid_t, next_tid)
|
__field(tid_t, next_tid)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -484,15 +481,14 @@ TRACE_EVENT(jbd2_shrink_checkpoint_list,
|
||||||
__entry->tid = tid;
|
__entry->tid = tid;
|
||||||
__entry->last_tid = last_tid;
|
__entry->last_tid = last_tid;
|
||||||
__entry->nr_freed = nr_freed;
|
__entry->nr_freed = nr_freed;
|
||||||
__entry->nr_scanned = nr_scanned;
|
|
||||||
__entry->next_tid = next_tid;
|
__entry->next_tid = next_tid;
|
||||||
),
|
),
|
||||||
|
|
||||||
TP_printk("dev %d,%d shrink transaction %u-%u(%u) freed %lu "
|
TP_printk("dev %d,%d shrink transaction %u-%u(%u) freed %lu "
|
||||||
"scanned %lu next transaction %u",
|
"next transaction %u",
|
||||||
MAJOR(__entry->dev), MINOR(__entry->dev),
|
MAJOR(__entry->dev), MINOR(__entry->dev),
|
||||||
__entry->first_tid, __entry->tid, __entry->last_tid,
|
__entry->first_tid, __entry->tid, __entry->last_tid,
|
||||||
__entry->nr_freed, __entry->nr_scanned, __entry->next_tid)
|
__entry->nr_freed, __entry->next_tid)
|
||||||
);
|
);
|
||||||
|
|
||||||
#endif /* _TRACE_JBD2_H */
|
#endif /* _TRACE_JBD2_H */
|
||||||
|
|
Loading…
Add table
Reference in a new issue