Message ID | 20210622121551.3398730-25-willy@infradead.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Folio-enabling the page cache | expand |
On Tue, Jun 22, 2021 at 01:15:29PM +0100, Matthew Wilcox (Oracle) wrote: > test_clear_page_writeback() is actually an mm-internal function, although > it's named as if it's a pagecache function. Move it to mm/internal.h, > rename it to __folio_end_writeback() and change the return type to bool. > > The conversion from page to folio is mostly about accounting the number > of pages being written back, although it does eliminate a couple of > calls to compound_head(). While this looks good, I think the whole abstraction is wrong. I think test_clear_page_writeback should just be merged into it's only caller. But if that is somehow not on the table this change looks ok: Reviewed-by: Christoph Hellwig <hch@lst.de>
On Wed, Jun 23, 2021 at 11:15:55AM +0200, Christoph Hellwig wrote: > On Tue, Jun 22, 2021 at 01:15:29PM +0100, Matthew Wilcox (Oracle) wrote: > > test_clear_page_writeback() is actually an mm-internal function, although > > it's named as if it's a pagecache function. Move it to mm/internal.h, > > rename it to __folio_end_writeback() and change the return type to bool. > > > > The conversion from page to folio is mostly about accounting the number > > of pages being written back, although it does eliminate a couple of > > calls to compound_head(). > > While this looks good, I think the whole abstraction is wrong. I think > test_clear_page_writeback should just be merged into it's only caller. I'm not opposed to doing that, but something else has to get un-static'ed in order to make that happen. folio_end_writeback (exported, filemap.c) -> folio_wake (static, filemap.c) -> folio_wake_bit (static, filemap.c) -> __folio_end_writeback (non-static, page-writeback.c) -> __wb_writeout_add (static, page-writeback.c) I'm not sure there's an obviously better split than where it is right now. > But if that is somehow not on the table this change looks ok: > > Reviewed-by: Christoph Hellwig <hch@lst.de>
On Thu, Jun 24, 2021 at 07:20:12PM +0100, Matthew Wilcox wrote: > > While this looks good, I think the whole abstraction is wrong. I think > > test_clear_page_writeback should just be merged into it's only caller. > > I'm not opposed to doing that, but something else has to get > un-static'ed in order to make that happen. > > folio_end_writeback (exported, filemap.c) > -> folio_wake (static, filemap.c) > -> folio_wake_bit (static, filemap.c) > -> __folio_end_writeback (non-static, page-writeback.c) > -> __wb_writeout_add (static, page-writeback.c) > > I'm not sure there's an obviously better split than where it is right > now. Ok, let's ignore that whole mess for now. There is plenty bigger fish to fry.
diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 50df34886537..bdf807c98736 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -646,7 +646,6 @@ static __always_inline void SetPageUptodate(struct page *page) CLEARPAGEFLAG(Uptodate, uptodate, PF_NO_TAIL) -int test_clear_page_writeback(struct page *page); int __test_set_page_writeback(struct page *page, bool keep_write); #define test_set_page_writeback(page) \ diff --git a/mm/filemap.c b/mm/filemap.c index 4b2698e5e8e2..dd360721c72b 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1535,7 +1535,7 @@ void folio_end_writeback(struct folio *folio) * reused before the folio_wake(). */ folio_get(folio); - if (!test_clear_page_writeback(&folio->page)) + if (!__folio_end_writeback(folio)) BUG(); smp_mb__after_atomic(); diff --git a/mm/internal.h b/mm/internal.h index 3e70121c71c7..d7013df5d1f0 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -43,6 +43,7 @@ static inline void *folio_rmapping(struct folio *folio) vm_fault_t do_swap_page(struct vm_fault *vmf); void folio_rotate_reclaimable(struct folio *folio); +bool __folio_end_writeback(struct folio *folio); void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma, unsigned long floor, unsigned long ceiling); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index dc66ff78f033..9213b8b6d50b 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -588,7 +588,7 @@ static void wb_domain_writeout_add(struct wb_domain *dom, /* * Increment @wb's writeout completion count and the global writeout - * completion count. Called from test_clear_page_writeback(). + * completion count. Called from __folio_end_writeback(). */ static inline void __wb_writeout_add(struct bdi_writeback *wb, long nr) { @@ -2727,27 +2727,28 @@ int clear_page_dirty_for_io(struct page *page) } EXPORT_SYMBOL(clear_page_dirty_for_io); -int test_clear_page_writeback(struct page *page) +bool __folio_end_writeback(struct folio *folio) { - struct address_space *mapping = page_mapping(page); - int ret; + long nr = folio_nr_pages(folio); + struct address_space *mapping = folio_mapping(folio); + bool ret; - lock_page_memcg(page); + lock_folio_memcg(folio); if (mapping && mapping_use_writeback_tags(mapping)) { struct inode *inode = mapping->host; struct backing_dev_info *bdi = inode_to_bdi(inode); unsigned long flags; xa_lock_irqsave(&mapping->i_pages, flags); - ret = TestClearPageWriteback(page); + ret = folio_test_clear_writeback_flag(folio); if (ret) { - __xa_clear_mark(&mapping->i_pages, page_index(page), + __xa_clear_mark(&mapping->i_pages, folio_index(folio), PAGECACHE_TAG_WRITEBACK); if (bdi->capabilities & BDI_CAP_WRITEBACK_ACCT) { struct bdi_writeback *wb = inode_to_wb(inode); - dec_wb_stat(wb, WB_WRITEBACK); - __wb_writeout_add(wb, 1); + wb_stat_mod(wb, WB_WRITEBACK, -nr); + __wb_writeout_add(wb, nr); } } @@ -2757,14 +2758,14 @@ int test_clear_page_writeback(struct page *page) xa_unlock_irqrestore(&mapping->i_pages, flags); } else { - ret = TestClearPageWriteback(page); + ret = folio_test_clear_writeback_flag(folio); } if (ret) { - dec_lruvec_page_state(page, NR_WRITEBACK); - dec_zone_page_state(page, NR_ZONE_WRITE_PENDING); - inc_node_page_state(page, NR_WRITTEN); + lruvec_stat_mod_folio(folio, NR_WRITEBACK, -nr); + zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr); + node_stat_mod_folio(folio, NR_WRITTEN, nr); } - unlock_page_memcg(page); + unlock_folio_memcg(folio); return ret; }
test_clear_page_writeback() is actually an mm-internal function, although it's named as if it's a pagecache function. Move it to mm/internal.h, rename it to __folio_end_writeback() and change the return type to bool. The conversion from page to folio is mostly about accounting the number of pages being written back, although it does eliminate a couple of calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> --- include/linux/page-flags.h | 1 - mm/filemap.c | 2 +- mm/internal.h | 1 + mm/page-writeback.c | 29 +++++++++++++++-------------- 4 files changed, 17 insertions(+), 16 deletions(-)