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

mm/page-writeback: drop usage of folio_index

folio_index is only needed for mixed usage of page cache and swap cache.
The remaining three caller in page-writeback are for page cache tag
marking. Swap cache space doesn't use tag (explicitly sets
mapping_set_no_writeback_tags), so use folio->index here directly.

Link: https://lkml.kernel.org/r/20250825163721.17734-1-ryncsn@gmail.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kairui Song and committed by
Andrew Morton
46afff45 79dfed09

+11 -5
+11 -5
mm/page-writeback.c
··· 38 38 #include <linux/sched/rt.h> 39 39 #include <linux/sched/signal.h> 40 40 #include <linux/mm_inline.h> 41 + #include <linux/shmem_fs.h> 41 42 #include <trace/events/writeback.h> 42 43 43 44 #include "internal.h" 44 - #include "swap.h" 45 45 46 46 /* 47 47 * Sleep at most 200ms at a time in balance_dirty_pages(). ··· 2705 2705 { 2706 2706 unsigned long flags; 2707 2707 2708 + /* 2709 + * Shmem writeback relies on swap, and swap writeback is LRU based, 2710 + * not using the dirty mark. 2711 + */ 2712 + VM_WARN_ON_ONCE(folio_test_swapcache(folio) || shmem_mapping(mapping)); 2713 + 2708 2714 xa_lock_irqsave(&mapping->i_pages, flags); 2709 2715 if (folio->mapping) { /* Race with truncate? */ 2710 2716 WARN_ON_ONCE(warn && !folio_test_uptodate(folio)); 2711 2717 folio_account_dirtied(folio, mapping); 2712 - __xa_set_mark(&mapping->i_pages, folio_index(folio), 2713 - PAGECACHE_TAG_DIRTY); 2718 + __xa_set_mark(&mapping->i_pages, folio->index, 2719 + PAGECACHE_TAG_DIRTY); 2714 2720 } 2715 2721 xa_unlock_irqrestore(&mapping->i_pages, flags); 2716 2722 } ··· 2995 2989 2996 2990 xa_lock_irqsave(&mapping->i_pages, flags); 2997 2991 ret = folio_xor_flags_has_waiters(folio, 1 << PG_writeback); 2998 - __xa_clear_mark(&mapping->i_pages, folio_index(folio), 2992 + __xa_clear_mark(&mapping->i_pages, folio->index, 2999 2993 PAGECACHE_TAG_WRITEBACK); 3000 2994 if (bdi->capabilities & BDI_CAP_WRITEBACK_ACCT) { 3001 2995 struct bdi_writeback *wb = inode_to_wb(inode); ··· 3032 3026 VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); 3033 3027 3034 3028 if (mapping && mapping_use_writeback_tags(mapping)) { 3035 - XA_STATE(xas, &mapping->i_pages, folio_index(folio)); 3029 + XA_STATE(xas, &mapping->i_pages, folio->index); 3036 3030 struct inode *inode = mapping->host; 3037 3031 struct backing_dev_info *bdi = inode_to_bdi(inode); 3038 3032 unsigned long flags;