@@ -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 */
400360static 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
454413again :
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 ;
504464out :
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,
520479void __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}
0 commit comments