Skip to content

Commit

Permalink
jbd2: remove journal_clean_one_cp_list()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
zhangyi089 authored and tytso committed Jul 11, 2023
1 parent be22255 commit b98dba2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 66 deletions.
75 changes: 17 additions & 58 deletions fs/jbd2/checkpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,75 +347,34 @@ int jbd2_cleanup_journal_tail(journal_t *journal)

/* Checkpoint list management */

/*
* journal_clean_one_cp_list
*
* Find all the written-back checkpoint buffers in the given list and
* release them. If 'destroy' is set, clean all buffers unconditionally.
*
* 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)
{
struct journal_head *last_jh;
struct journal_head *next_jh = jh;

if (!jh)
return 0;

last_jh = jh->b_cpprev;
do {
jh = next_jh;
next_jh = jh->b_cpnext;

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
* Find all the 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)
bool destroy, 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)
*released = false;
if (!jh)
return 0;

last_jh = jh->b_cpprev;
do {
jh = next_jh;
next_jh = jh->b_cpnext;

(*nr_to_scan)--;
if (__cp_buffer_busy(jh))
if (!destroy && __cp_buffer_busy(jh))
continue;

nr_freed++;
Expand All @@ -427,7 +386,7 @@ static unsigned long journal_shrink_one_cp_list(struct journal_head *jh,

if (need_resched())
break;
} while (jh != last_jh && *nr_to_scan);
} while (jh != last_jh);

return nr_freed;
}
Expand All @@ -445,11 +404,11 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
unsigned long *nr_to_scan)
{
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 tid = 0;
unsigned long nr_freed = 0;
unsigned long nr_scanned = *nr_to_scan;
unsigned long freed;

again:
spin_lock(&journal->j_list_lock);
Expand Down Expand Up @@ -478,10 +437,11 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
transaction = next_transaction;
next_transaction = transaction->t_cpnext;
tid = transaction->t_tid;
released = false;

nr_freed += journal_shrink_one_cp_list(transaction->t_checkpoint_list,
nr_to_scan, &released);
freed = journal_shrink_one_cp_list(transaction->t_checkpoint_list,
false, &released);
nr_freed += freed;
(*nr_to_scan) -= min(*nr_to_scan, freed);
if (*nr_to_scan == 0)
break;
if (need_resched() || spin_needbreak(&journal->j_list_lock))
Expand All @@ -502,9 +462,8 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
if (*nr_to_scan && next_tid)
goto again;
out:
nr_scanned -= *nr_to_scan;
trace_jbd2_shrink_checkpoint_list(journal, first_tid, tid, last_tid,
nr_freed, nr_scanned, next_tid);
nr_freed, next_tid);

return nr_freed;
}
Expand All @@ -520,7 +479,7 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
{
transaction_t *transaction, *last_transaction, *next_transaction;
int ret;
bool released;

transaction = journal->j_checkpoint_transactions;
if (!transaction)
Expand All @@ -531,8 +490,8 @@ void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
do {
transaction = next_transaction;
next_transaction = transaction->t_cpnext;
ret = journal_clean_one_cp_list(transaction->t_checkpoint_list,
destroy);
journal_shrink_one_cp_list(transaction->t_checkpoint_list,
destroy, &released);
/*
* This function only frees up some memory if possible so we
* dont have an obligation to finish processing. Bail out if
Expand All @@ -545,7 +504,7 @@ void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
* avoids pointless scanning of transactions which still
* weren't checkpointed.
*/
if (!ret)
if (!released)
return;
} while (transaction != last_transaction);
}
Expand Down
12 changes: 4 additions & 8 deletions include/trace/events/jbd2.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,19 +462,16 @@ TRACE_EVENT(jbd2_shrink_scan_exit,
TRACE_EVENT(jbd2_shrink_checkpoint_list,

TP_PROTO(journal_t *journal, tid_t first_tid, tid_t tid, tid_t last_tid,
unsigned long nr_freed, unsigned long nr_scanned,
tid_t next_tid),
unsigned long nr_freed, tid_t next_tid),

TP_ARGS(journal, first_tid, tid, last_tid, nr_freed,
nr_scanned, next_tid),
TP_ARGS(journal, first_tid, tid, last_tid, nr_freed, next_tid),

TP_STRUCT__entry(
__field(dev_t, dev)
__field(tid_t, first_tid)
__field(tid_t, tid)
__field(tid_t, last_tid)
__field(unsigned long, nr_freed)
__field(unsigned long, nr_scanned)
__field(tid_t, next_tid)
),

Expand All @@ -484,15 +481,14 @@ TRACE_EVENT(jbd2_shrink_checkpoint_list,
__entry->tid = tid;
__entry->last_tid = last_tid;
__entry->nr_freed = nr_freed;
__entry->nr_scanned = nr_scanned;
__entry->next_tid = next_tid;
),

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),
__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 */
Expand Down

0 comments on commit b98dba2

Please sign in to comment.