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

ext4: use writeback_iter in ext4_journalled_submit_inode_data_buffers

Use writeback_iter directly instead of write_cache_pages for a nicer
code structure and less indirect calls.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
Link: https://patch.msgid.link/20250505091604.3449879-1-hch@lst.de
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

authored by

Christoph Hellwig and committed by
Theodore Ts'o
e80325ef 32a93f5b

+22 -24
+22 -24
fs/ext4/super.c
··· 508 508 ext4_maybe_update_superblock(sb); 509 509 } 510 510 511 - /* 512 - * This writepage callback for write_cache_pages() 513 - * takes care of a few cases after page cleaning. 514 - * 515 - * write_cache_pages() already checks for dirty pages 516 - * and calls clear_page_dirty_for_io(), which we want, 517 - * to write protect the pages. 518 - * 519 - * However, we may have to redirty a page (see below.) 520 - */ 521 - static int ext4_journalled_writepage_callback(struct folio *folio, 522 - struct writeback_control *wbc, 523 - void *data) 511 + static bool ext4_journalled_writepage_needs_redirty(struct jbd2_inode *jinode, 512 + struct folio *folio) 524 513 { 525 - transaction_t *transaction = (transaction_t *) data; 526 514 struct buffer_head *bh, *head; 527 515 struct journal_head *jh; 528 516 ··· 531 543 */ 532 544 jh = bh2jh(bh); 533 545 if (buffer_dirty(bh) || 534 - (jh && (jh->b_transaction != transaction || 535 - jh->b_next_transaction))) { 536 - folio_redirty_for_writepage(wbc, folio); 537 - goto out; 538 - } 546 + (jh && (jh->b_transaction != jinode->i_transaction || 547 + jh->b_next_transaction))) 548 + return true; 539 549 } while ((bh = bh->b_this_page) != head); 540 550 541 - out: 542 - return AOP_WRITEPAGE_ACTIVATE; 551 + return false; 543 552 } 544 553 545 554 static int ext4_journalled_submit_inode_data_buffers(struct jbd2_inode *jinode) ··· 548 563 .range_start = jinode->i_dirty_start, 549 564 .range_end = jinode->i_dirty_end, 550 565 }; 566 + struct folio *folio = NULL; 567 + int error; 551 568 552 - return write_cache_pages(mapping, &wbc, 553 - ext4_journalled_writepage_callback, 554 - jinode->i_transaction); 569 + /* 570 + * writeback_iter() already checks for dirty pages and calls 571 + * folio_clear_dirty_for_io(), which we want to write protect the 572 + * folios. 573 + * 574 + * However, we may have to redirty a folio sometimes. 575 + */ 576 + while ((folio = writeback_iter(mapping, &wbc, folio, &error))) { 577 + if (ext4_journalled_writepage_needs_redirty(jinode, folio)) 578 + folio_redirty_for_writepage(&wbc, folio); 579 + folio_unlock(folio); 580 + } 581 + 582 + return error; 555 583 } 556 584 557 585 static int ext4_journal_submit_inode_data_buffers(struct jbd2_inode *jinode)