Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Zhang Yi and committed by
Theodore Ts'o
b98dba27 be222553

+26 -71
+22 -63
fs/jbd2/checkpoint.c
··· 348 348 /* Checkpoint list management */ 349 349 350 350 /* 351 - * journal_clean_one_cp_list 351 + * journal_shrink_one_cp_list 352 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. 353 + * Find all the written-back checkpoint buffers in the given list 354 + * and try to release them. If the whole transaction is released, set 355 + * the 'released' parameter. Return the number of released checkpointed 356 + * buffers. 355 357 * 356 358 * Called with j_list_lock held. 357 - * Returns 1 if we freed the transaction, 0 otherwise. 358 359 */ 359 - static int journal_clean_one_cp_list(struct journal_head *jh, bool destroy) 360 + static unsigned long journal_shrink_one_cp_list(struct journal_head *jh, 361 + bool destroy, bool *released) 360 362 { 361 363 struct journal_head *last_jh; 362 364 struct journal_head *next_jh = jh; 365 + unsigned long nr_freed = 0; 366 + int ret; 363 367 368 + *released = false; 364 369 if (!jh) 365 370 return 0; 366 371 ··· 375 370 next_jh = jh->b_cpnext; 376 371 377 372 if (!destroy && __cp_buffer_busy(jh)) 378 - return 0; 379 - 380 - if (__jbd2_journal_remove_checkpoint(jh)) 381 - return 1; 382 - /* 383 - * This function only frees up some memory 384 - * if possible so we dont have an obligation 385 - * to finish processing. Bail out if preemption 386 - * requested: 387 - */ 388 - if (need_resched()) 389 - return 0; 390 - } while (jh != last_jh); 391 - 392 - return 0; 393 - } 394 - 395 - /* 396 - * journal_shrink_one_cp_list 397 - * 398 - * Find 'nr_to_scan' written-back checkpoint buffers in the given list 399 - * and try to release them. If the whole transaction is released, set 400 - * the 'released' parameter. Return the number of released checkpointed 401 - * buffers. 402 - * 403 - * Called with j_list_lock held. 404 - */ 405 - static unsigned long journal_shrink_one_cp_list(struct journal_head *jh, 406 - unsigned long *nr_to_scan, 407 - bool *released) 408 - { 409 - struct journal_head *last_jh; 410 - struct journal_head *next_jh = jh; 411 - unsigned long nr_freed = 0; 412 - int ret; 413 - 414 - if (!jh || *nr_to_scan == 0) 415 - return 0; 416 - 417 - last_jh = jh->b_cpprev; 418 - do { 419 - jh = next_jh; 420 - next_jh = jh->b_cpnext; 421 - 422 - (*nr_to_scan)--; 423 - if (__cp_buffer_busy(jh)) 424 373 continue; 425 374 426 375 nr_freed++; ··· 386 427 387 428 if (need_resched()) 388 429 break; 389 - } while (jh != last_jh && *nr_to_scan); 430 + } while (jh != last_jh); 390 431 391 432 return nr_freed; 392 433 } ··· 404 445 unsigned long *nr_to_scan) 405 446 { 406 447 transaction_t *transaction, *last_transaction, *next_transaction; 407 - bool released; 448 + bool __maybe_unused released; 408 449 tid_t first_tid = 0, last_tid = 0, next_tid = 0; 409 450 tid_t tid = 0; 410 451 unsigned long nr_freed = 0; 411 - unsigned long nr_scanned = *nr_to_scan; 452 + unsigned long freed; 412 453 413 454 again: 414 455 spin_lock(&journal->j_list_lock); ··· 437 478 transaction = next_transaction; 438 479 next_transaction = transaction->t_cpnext; 439 480 tid = transaction->t_tid; 440 - released = false; 441 481 442 - nr_freed += journal_shrink_one_cp_list(transaction->t_checkpoint_list, 443 - nr_to_scan, &released); 482 + freed = journal_shrink_one_cp_list(transaction->t_checkpoint_list, 483 + false, &released); 484 + nr_freed += freed; 485 + (*nr_to_scan) -= min(*nr_to_scan, freed); 444 486 if (*nr_to_scan == 0) 445 487 break; 446 488 if (need_resched() || spin_needbreak(&journal->j_list_lock)) ··· 462 502 if (*nr_to_scan && next_tid) 463 503 goto again; 464 504 out: 465 - nr_scanned -= *nr_to_scan; 466 505 trace_jbd2_shrink_checkpoint_list(journal, first_tid, tid, last_tid, 467 - nr_freed, nr_scanned, next_tid); 506 + nr_freed, next_tid); 468 507 469 508 return nr_freed; 470 509 } ··· 479 520 void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy) 480 521 { 481 522 transaction_t *transaction, *last_transaction, *next_transaction; 482 - int ret; 523 + bool released; 483 524 484 525 transaction = journal->j_checkpoint_transactions; 485 526 if (!transaction) ··· 490 531 do { 491 532 transaction = next_transaction; 492 533 next_transaction = transaction->t_cpnext; 493 - ret = journal_clean_one_cp_list(transaction->t_checkpoint_list, 494 - destroy); 534 + journal_shrink_one_cp_list(transaction->t_checkpoint_list, 535 + destroy, &released); 495 536 /* 496 537 * This function only frees up some memory if possible so we 497 538 * dont have an obligation to finish processing. Bail out if ··· 504 545 * avoids pointless scanning of transactions which still 505 546 * weren't checkpointed. 506 547 */ 507 - if (!ret) 548 + if (!released) 508 549 return; 509 550 } while (transaction != last_transaction); 510 551 }
+4 -8
include/trace/events/jbd2.h
··· 462 462 TRACE_EVENT(jbd2_shrink_checkpoint_list, 463 463 464 464 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), 467 466 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), 470 468 471 469 TP_STRUCT__entry( 472 470 __field(dev_t, dev) ··· 472 474 __field(tid_t, tid) 473 475 __field(tid_t, last_tid) 474 476 __field(unsigned long, nr_freed) 475 - __field(unsigned long, nr_scanned) 476 477 __field(tid_t, next_tid) 477 478 ), 478 479 ··· 481 484 __entry->tid = tid; 482 485 __entry->last_tid = last_tid; 483 486 __entry->nr_freed = nr_freed; 484 - __entry->nr_scanned = nr_scanned; 485 487 __entry->next_tid = next_tid; 486 488 ), 487 489 488 490 TP_printk("dev %d,%d shrink transaction %u-%u(%u) freed %lu " 489 - "scanned %lu next transaction %u", 491 + "next transaction %u", 490 492 MAJOR(__entry->dev), MINOR(__entry->dev), 491 493 __entry->first_tid, __entry->tid, __entry->last_tid, 492 - __entry->nr_freed, __entry->nr_scanned, __entry->next_tid) 494 + __entry->nr_freed, __entry->next_tid) 493 495 ); 494 496 495 497 #endif /* _TRACE_JBD2_H */