Skip to content

Commit b98dba2

Browse files
zhangyi089tytso
authored andcommitted
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>
1 parent be22255 commit b98dba2

File tree

2 files changed

+21
-66
lines changed

2 files changed

+21
-66
lines changed

fs/jbd2/checkpoint.c

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -347,75 +347,34 @@ int jbd2_cleanup_journal_tail(journal_t *journal)
347347

348348
/* Checkpoint list management */
349349

350-
/*
351-
* journal_clean_one_cp_list
352-
*
353-
* Find all the written-back checkpoint buffers in the given list and
354-
* release them. If 'destroy' is set, clean all buffers unconditionally.
355-
*
356-
* Called with j_list_lock held.
357-
* Returns 1 if we freed the transaction, 0 otherwise.
358-
*/
359-
static int journal_clean_one_cp_list(struct journal_head *jh, bool destroy)
360-
{
361-
struct journal_head *last_jh;
362-
struct journal_head *next_jh = jh;
363-
364-
if (!jh)
365-
return 0;
366-
367-
last_jh = jh->b_cpprev;
368-
do {
369-
jh = next_jh;
370-
next_jh = jh->b_cpnext;
371-
372-
if (!destroy && __cp_buffer_busy(jh))
373-
return 0;
374-
375-
if (__jbd2_journal_remove_checkpoint(jh))
376-
return 1;
377-
/*
378-
* This function only frees up some memory
379-
* if possible so we dont have an obligation
380-
* to finish processing. Bail out if preemption
381-
* requested:
382-
*/
383-
if (need_resched())
384-
return 0;
385-
} while (jh != last_jh);
386-
387-
return 0;
388-
}
389-
390350
/*
391351
* journal_shrink_one_cp_list
392352
*
393-
* Find 'nr_to_scan' written-back checkpoint buffers in the given list
353+
* Find all the written-back checkpoint buffers in the given list
394354
* and try to release them. If the whole transaction is released, set
395355
* the 'released' parameter. Return the number of released checkpointed
396356
* buffers.
397357
*
398358
* Called with j_list_lock held.
399359
*/
400360
static unsigned long journal_shrink_one_cp_list(struct journal_head *jh,
401-
unsigned long *nr_to_scan,
402-
bool *released)
361+
bool destroy, bool *released)
403362
{
404363
struct journal_head *last_jh;
405364
struct journal_head *next_jh = jh;
406365
unsigned long nr_freed = 0;
407366
int ret;
408367

409-
if (!jh || *nr_to_scan == 0)
368+
*released = false;
369+
if (!jh)
410370
return 0;
411371

412372
last_jh = jh->b_cpprev;
413373
do {
414374
jh = next_jh;
415375
next_jh = jh->b_cpnext;
416376

417-
(*nr_to_scan)--;
418-
if (__cp_buffer_busy(jh))
377+
if (!destroy && __cp_buffer_busy(jh))
419378
continue;
420379

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

428387
if (need_resched())
429388
break;
430-
} while (jh != last_jh && *nr_to_scan);
389+
} while (jh != last_jh);
431390

432391
return nr_freed;
433392
}
@@ -445,11 +404,11 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
445404
unsigned long *nr_to_scan)
446405
{
447406
transaction_t *transaction, *last_transaction, *next_transaction;
448-
bool released;
407+
bool __maybe_unused released;
449408
tid_t first_tid = 0, last_tid = 0, next_tid = 0;
450409
tid_t tid = 0;
451410
unsigned long nr_freed = 0;
452-
unsigned long nr_scanned = *nr_to_scan;
411+
unsigned long freed;
453412

454413
again:
455414
spin_lock(&journal->j_list_lock);
@@ -478,10 +437,11 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
478437
transaction = next_transaction;
479438
next_transaction = transaction->t_cpnext;
480439
tid = transaction->t_tid;
481-
released = false;
482440

483-
nr_freed += journal_shrink_one_cp_list(transaction->t_checkpoint_list,
484-
nr_to_scan, &released);
441+
freed = journal_shrink_one_cp_list(transaction->t_checkpoint_list,
442+
false, &released);
443+
nr_freed += freed;
444+
(*nr_to_scan) -= min(*nr_to_scan, freed);
485445
if (*nr_to_scan == 0)
486446
break;
487447
if (need_resched() || spin_needbreak(&journal->j_list_lock))
@@ -502,9 +462,8 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
502462
if (*nr_to_scan && next_tid)
503463
goto again;
504464
out:
505-
nr_scanned -= *nr_to_scan;
506465
trace_jbd2_shrink_checkpoint_list(journal, first_tid, tid, last_tid,
507-
nr_freed, nr_scanned, next_tid);
466+
nr_freed, next_tid);
508467

509468
return nr_freed;
510469
}
@@ -520,7 +479,7 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
520479
void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
521480
{
522481
transaction_t *transaction, *last_transaction, *next_transaction;
523-
int ret;
482+
bool released;
524483

525484
transaction = journal->j_checkpoint_transactions;
526485
if (!transaction)
@@ -531,8 +490,8 @@ void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
531490
do {
532491
transaction = next_transaction;
533492
next_transaction = transaction->t_cpnext;
534-
ret = journal_clean_one_cp_list(transaction->t_checkpoint_list,
535-
destroy);
493+
journal_shrink_one_cp_list(transaction->t_checkpoint_list,
494+
destroy, &released);
536495
/*
537496
* This function only frees up some memory if possible so we
538497
* 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)
545504
* avoids pointless scanning of transactions which still
546505
* weren't checkpointed.
547506
*/
548-
if (!ret)
507+
if (!released)
549508
return;
550509
} while (transaction != last_transaction);
551510
}

include/trace/events/jbd2.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,19 +462,16 @@ TRACE_EVENT(jbd2_shrink_scan_exit,
462462
TRACE_EVENT(jbd2_shrink_checkpoint_list,
463463

464464
TP_PROTO(journal_t *journal, tid_t first_tid, tid_t tid, tid_t last_tid,
465-
unsigned long nr_freed, unsigned long nr_scanned,
466-
tid_t next_tid),
465+
unsigned long nr_freed, tid_t next_tid),
467466

468-
TP_ARGS(journal, first_tid, tid, last_tid, nr_freed,
469-
nr_scanned, next_tid),
467+
TP_ARGS(journal, first_tid, tid, last_tid, nr_freed, next_tid),
470468

471469
TP_STRUCT__entry(
472470
__field(dev_t, dev)
473471
__field(tid_t, first_tid)
474472
__field(tid_t, tid)
475473
__field(tid_t, last_tid)
476474
__field(unsigned long, nr_freed)
477-
__field(unsigned long, nr_scanned)
478475
__field(tid_t, next_tid)
479476
),
480477

@@ -484,15 +481,14 @@ TRACE_EVENT(jbd2_shrink_checkpoint_list,
484481
__entry->tid = tid;
485482
__entry->last_tid = last_tid;
486483
__entry->nr_freed = nr_freed;
487-
__entry->nr_scanned = nr_scanned;
488484
__entry->next_tid = next_tid;
489485
),
490486

491487
TP_printk("dev %d,%d shrink transaction %u-%u(%u) freed %lu "
492-
"scanned %lu next transaction %u",
488+
"next transaction %u",
493489
MAJOR(__entry->dev), MINOR(__entry->dev),
494490
__entry->first_tid, __entry->tid, __entry->last_tid,
495-
__entry->nr_freed, __entry->nr_scanned, __entry->next_tid)
491+
__entry->nr_freed, __entry->next_tid)
496492
);
497493

498494
#endif /* _TRACE_JBD2_H */

0 commit comments

Comments
 (0)