Get rid of PG_reclaim and rename PG_dropbehind
Subsystems (14)
v3 cover Get rid of PG_reclaim and rename PG_dropbehind
Use PG_dropbehind instead of PG_reclaim and remove PG_reclaim.
After removing PG_relcaim, PG_readahead is exclusive user of the page flag bit.
Once PG_reclaim is gone, we can rename PG_dropbehind to PG_reclaim.
v3:
- Condition folio_set_dropbehind() call in mapping_try_invalidate() on
!unevictable and !mapped;
- Add Reviewed-by tag by Yu Zhao;
Kirill A. Shutemov (11):
mm/migrate: Transfer PG_dropbehind to the new folio drm/i915/gem: Convert __shmem_writeback() to folios drm/i915/gem: Use PG_dropbehind instead of PG_reclaim mm/zswap: Use PG_dropbehind instead of PG_reclaim mm/truncate: Use folio_set_dropbehind() instead of
deactivate_file_folio()
mm/vmscan: Use PG_dropbehind instead of PG_reclaim mm/vmscan: Use PG_dropbehind instead of PG_reclaim in
shrink_folio_list()
mm/mglru: Check PG_dropbehind instead of PG_reclaim in
lru_gen_folio_seq()
mm: Remove PG_reclaim
mm/vmscan: Do not demote PG_dropbehind folios
mm: Rename PG_dropbehind to PG_reclaim
drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 18 ++- fs/fuse/dev.c | 2 +- fs/proc/page.c | 2 +- include/linux/mm_inline.h | 18 +-- include/linux/page-flags.h | 23 ++-- include/linux/pagemap.h | 2 +- include/trace/events/mmflags.h | 4 +- include/uapi/linux/kernel-page-flags.h | 2 +- mm/filemap.c | 46 +++---- mm/internal.h | 1 - mm/migrate.c | 14 +- mm/page-writeback.c | 16 +-- mm/page_io.c | 15 +-- mm/readahead.c | 4 +- mm/swap.c | 153 +--------------------- mm/truncate.c | 5 +- mm/vmscan.c | 28 +--- mm/zswap.c | 2 +- tools/mm/page-types.c | 8 +- 19 files changed, 68 insertions(+), 295 deletions(-)
Signature · 1 line
2.47.2
PATCH v3 1/11 mm/migrate: Transfer PG_dropbehind to the new folio
Do not lose the flag on page migration.
Ideally, these folios should be freed instead of migration. But it requires to find right spot do this and proper testing.
Transfer the flag for now.
--- mm/migrate.c | 4 ++++ 1 file changed, 4 insertions(+)
mm/migrate.c +4 -0
@@ -682,6 +682,10 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio)if (folio_test_dirty (folio))folio_set_dirty (newfolio); +/* TODO: free the folio on migration? */ +if (folio_test_dropbehind (folio)) +folio_set_dropbehind (newfolio); +if (folio_test_young (folio))folio_set_young (newfolio);if (folio_test_idle (folio))
Signature · 1 line
2.47.2
Re: [PATCHv3 01/11] mm/migrate: Transfer PG_dropbehind to the new folio
Quoted 9 lines · Kirill A. Shutemov
Do not lose the flag on page migration.
Ideally, these folios should be freed instead of migration. But it requires to find right spot do this and proper testing.
Transfer the flag for now.
Signed-off-by Kirill A. Shutemov <[email protected]>
PATCH v3 2/11 drm/i915/gem: Convert __shmem_writeback() to folios
In reply to Kirill A. ShutemovUse folios instead of pages.
This is preparation for removing PG_reclaim.
--- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +9 -9
@@ -320,25 +320,25 @@ void __shmem_writeback(size_t size, struct address_space *mapping)/* Begin writeback on each dirty page */ for (i =0 ; i < size >>PAGE_SHIFT ; i++) { -struct page *page; +struct folio *folio; - page =find_lock_page (mapping, i); -if (!page) + folio =filemap_lock_folio (mapping, i); +if (!folio)continue ; -if (!page_mapped (page) &&clear_page_dirty_for_io (page)) { +if (!folio_mapped (folio) &&folio_clear_dirty_for_io (folio)) {int ret; -SetPageReclaim (page); - ret = mapping->a_ops->writepage (page, &wbc); +folio_set_reclaim (folio); + ret = mapping->a_ops->writepage (&folio->page, &wbc);if (!PageWriteback (page)) -ClearPageReclaim (page); +folio_clear_reclaim (folio);if (!ret) goto put; } -unlock_page (page); +folio_unlock (folio); put: -put_page (page); +folio_put (folio); } }
Signature · 1 line
2.47.2
Re: [PATCHv3 02/11] drm/i915/gem: Convert __shmem_writeback() to folios
Hi Kirill,
Quoted 6 lines · Kirill A. Shutemov
Use folios instead of pages.
This is preparation for removing
PG_reclaim.Signed-off-by Kirill A. Shutemov <[email protected]>
looks good:
Thanks,
Andi
Matthew Wilcox
maintainerRe: [PATCHv3 02/11] drm/i915/gem: Convert __shmem_writeback() to folios
In reply to Kirill A. ShutemovQuoted 3 lines · Kirill A. Shutemov
Use folios instead of pages.
This is preparation for removing
PG_reclaim.
Well, this is a horrid little function. Rather than iterating just the dirty folios, it iterates all folios, then locks them before checking whether they're dirty.
I don't know whether the comments are correct or the code is correct. This comment doesn't match with setting PageReclaim:
* Leave mmapings intact (GTT will have been revoked on unbinding,
* leaving only CPU mmapings around) and add those pages to the LRU
* instead of invoking writeback so they are aged and paged out
* as normal.
so I wonder if Chris was confused about what PageReclaim actually does. Let's find out if he still remembers what he thought it did!
Shakeel Butt
reviewerRe: [PATCHv3 02/11] drm/i915/gem: Convert __shmem_writeback() to folios
In reply to Kirill A. ShutemovQuoted 15 lines · Kirill A. Shutemov
Use folios instead of pages.
This is preparation for removing
PG_reclaim.Signed-off-by Kirill A. Shutemov <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-0
drivers/gpu/drm/i915/gem/i915_gem_shmem.c void __shmem_writeback(size_t size, struct address_space *mapping) · line 322
Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-0@@ -320,25 +320,25 @@ void __shmem_writeback(size_t size, struct address_space *mapping)/* Begin writeback on each dirty page */ for (i =0 ; i < size >>PAGE_SHIFT ; i++) {
With folio conversion, should the iteration step be folio_nr_pages() instead of 1?
Quoted 34 lines
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +9
-9-struct page *page; +struct folio *folio; - page =find_lock_page (mapping, i); -if (!page) + folio =filemap_lock_folio (mapping, i); +if (!folio)continue ; -if (!page_mapped (page) &&clear_page_dirty_for_io (page)) { +if (!folio_mapped (folio) &&folio_clear_dirty_for_io (folio)) {int ret; -SetPageReclaim (page); - ret = mapping->a_ops->writepage (page, &wbc); +folio_set_reclaim (folio); + ret = mapping->a_ops->writepage (&folio->page, &wbc);if (!PageWriteback (page)) -ClearPageReclaim (page); +folio_clear_reclaim (folio);if (!ret) goto put; } -unlock_page (page); +folio_unlock (folio); put: -put_page (page); +folio_put (folio); } }Signature · 1 line
2.47.2
PATCH v3 3/11 drm/i915/gem: Use PG_dropbehind instead of PG_reclaim
In reply to Kirill A. ShutemovThe recently introduced PG_dropbehind allows for freeing folios immediately after writeback. Unlike PG_reclaim, it does not need vmscan to be involved to get the folio freed.
Instead of using folio_set_reclaim(), use folio_set_dropbehind() in __shmem_writeback()
It is safe to leave PG_dropbehind on the folio if, for some reason (bug?), the folio is not in a writeback state after ->writepage(). In these cases, the kernel had to clear PG_reclaim as it shared a page flag bit with PG_readahead.
--- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +1 -3
@@ -329,10 +329,8 @@ void __shmem_writeback(size_t size, struct address_space *mapping)if (!folio_mapped (folio) &&folio_clear_dirty_for_io (folio)) {int ret; -folio_set_reclaim (folio); +folio_set_dropbehind (folio); ret = mapping->a_ops->writepage (&folio->page, &wbc); -if (!PageWriteback (page)) -folio_clear_reclaim (folio);if (!ret) goto put; }
Signature · 1 line
2.47.2
Re: [PATCHv3 03/11] drm/i915/gem: Use PG_dropbehind instead of PG_reclaim
Hi Kirill,
Quoted 7 lines · Kirill A. Shutemov
The recently introduced
PG_dropbehindallows for freeing folios immediately after writeback. UnlikePG_reclaim, it does not need vmscan to be involved to get the folio freed.Instead of using
folio_set_reclaim(), usefolio_set_dropbehind()in__shmem_writeback()
Quoted 7 lines
It is safe to leave
PG_dropbehindon the folio if, for some reason (bug?), the folio is not in a writeback state after ->writepage(). In these cases, the kernel had to clearPG_reclaimas it shared a page flag bit withPG_readahead.Signed-off-by Kirill A. Shutemov <[email protected]>
Thanks,
Andi
PATCH v3 4/11 mm/zswap: Use PG_dropbehind instead of PG_reclaim
In reply to Kirill A. ShutemovThe recently introduced PG_dropbehind allows for freeing folios immediately after writeback. Unlike PG_reclaim, it does not need vmscan to be involved to get the folio freed.
Instead of using folio_set_reclaim(), use folio_set_dropbehind() in zswap_writeback_entry().
--- mm/zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/zswap.c +2 -2
@@ -1102,8 +1102,8 @@ static int zswap_writeback_entry(struct zswap_entry *entry,/* folio is up to date */ folio_mark_uptodate (folio); -/* move it to the tail of the inactive list after end_writeback */ -folio_set_reclaim (folio); +/* free the folio after writeback */ +folio_set_dropbehind (folio);/* start writeback */ __swap_writepage (folio, &wbc);
Signature · 1 line
2.47.2
Re: [PATCHv3 04/11] mm/zswap: Use PG_dropbehind instead of PG_reclaim
Quoted 4 lines · Kirill A. Shutemov
The recently introduced
PG_dropbehindallows for freeing folios immediately after writeback. UnlikePG_reclaim, it does not need vmscan to be involved to get the folio freed.
Neat!
Quoted 7 lines
Instead of using
folio_set_reclaim(), usefolio_set_dropbehind()inzswap_writeback_entry().Signed-off-by Kirill A. Shutemov <[email protected]>Acked-by Yosry Ahmed <[email protected]>
PATCH v3 5/11 mm/truncate: Use folio_set_dropbehind() instead of deactivate_file_folio()
In reply to Kirill A. ShutemovThe recently introduced PG_dropbehind allows for freeing folios immediately after writeback. Unlike PG_reclaim, it does not need vmscan to be involved to get the folio freed.
The new flag allows to replace whole deactivate_file_folio() machinery with simple folio_set_dropbehind().
--- mm/internal.h | 1 - mm/swap.c | 90 --------------------------------------------------- mm/truncate.c | 5 ++- 3 files changed, 4 insertions(+), 92 deletions(-)
mm/internal.h +0 -1
@@ -379,7 +379,6 @@ static inline vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)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 deactivate_file_folio (struct folio *folio);void folio_activate (struct folio *folio); void free_pgtables(struct mmu_gather *tlb, struct ma_state *mas,
mm/swap.c +0 -90
120 lines not on this page · raw message
mm/truncate.c +4 -1
@@ -486,7 +486,10 @@ unsigned long mapping_try_invalidate(struct address_space *mapping,* of interest and try to speed up its reclaim. */ if (!ret) { -deactivate_file_folio (folio); +if (!folio_test_unevictable (folio) && + !folio_mapped (folio)) +folio_set_dropbehind (folio); +/* Likely in the lru cache of a remote CPU */ if (nr_failed) (*nr_failed)++;
Signature · 1 line
2.47.2
Re: [PATCHv3 05/11] mm/truncate: Use folio_set_dropbehind() instead of deactivate_file_folio()
Quoted 9 lines · Kirill A. Shutemov
The recently introduced
PG_dropbehindallows for freeing folios immediately after writeback. UnlikePG_reclaim, it does not need vmscan to be involved to get the folio freed.The new flag allows to replace whole
deactivate_file_folio()machinery with simplefolio_set_dropbehind().Signed-off-by Kirill A. Shutemov <[email protected]>
PATCH v3 6/11 mm/vmscan: Use PG_dropbehind instead of PG_reclaim
In reply to Kirill A. ShutemovThe recently introduced PG_dropbehind allows for freeing folios immediately after writeback. Unlike PG_reclaim, it does not need vmscan to be involved to get the folio freed.
Instead of using folio_set_reclaim(), use folio_set_dropbehind() in pageout().
It is safe to leave PG_dropbehind on the folio if, for some reason (bug?), the folio is not in a writeback state after ->writepage(). In these cases, the kernel had to clear PG_reclaim as it shared a page flag bit with PG_readahead.
--- mm/vmscan.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
mm/vmscan.c +3 -6
@@ -692,19 +692,16 @@ static pageout_t pageout(struct folio *folio, struct address_space *mapping,if (shmem_mapping (mapping) &&folio_test_large (folio)) wbc.list = folio_list; -folio_set_reclaim (folio); +folio_set_dropbehind (folio); + res = mapping->a_ops->writepage (&folio->page, &wbc);if (res <0 )handle_write_error (mapping, folio, res);if (res ==AOP_WRITEPAGE_ACTIVATE ) { -folio_clear_reclaim (folio); +folio_clear_dropbehind (folio);return PAGE_ACTIVATE ; } -if (!folio_test_writeback (folio)) { -/* synchronous write or broken a_ops? */ -folio_clear_reclaim (folio); - }trace_mm_vmscan_write_folio (folio);node_stat_add_folio (folio,NR_VMSCAN_WRITE );return PAGE_SUCCESS ;
Signature · 1 line
2.47.2
Shakeel Butt
reviewerRe: [PATCHv3 06/11] mm/vmscan: Use PG_dropbehind instead of PG_reclaim
Quoted 11 lines · Kirill A. Shutemov
The recently introduced
PG_dropbehindallows for freeing folios immediately after writeback. UnlikePG_reclaim, it does not need vmscan to be involved to get the folio freed.Instead of using
folio_set_reclaim(), usefolio_set_dropbehind()inpageout().It is safe to leave
PG_dropbehindon the folio if, for some reason (bug?), the folio is not in a writeback state after ->writepage(). In these cases, the kernel had to clearPG_reclaimas it shared a page flag bit withPG_readahead.
Is it correct to say that leaving PG_dropbehind on folios which doesn't have writeback state after ->writepage() (i.e. store to zswap) is fine because PG_dropbehind is not in PAGE_FLAGS_CHECK_AT_FREE?
Quoted 37 lines
Signed-off-by Kirill A. Shutemov <[email protected]>--- mm/vmscan.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)mm/vmscan.c +3
-6@@ -692,19 +692,16 @@ static pageout_t pageout(struct folio *folio, struct address_space *mapping,if (shmem_mapping (mapping) &&folio_test_large (folio)) wbc.list = folio_list; -folio_set_reclaim (folio); +folio_set_dropbehind (folio); + res = mapping->a_ops->writepage (&folio->page, &wbc);if (res <0 )handle_write_error (mapping, folio, res);if (res ==AOP_WRITEPAGE_ACTIVATE ) { -folio_clear_reclaim (folio); +folio_clear_dropbehind (folio);return PAGE_ACTIVATE ; } -if (!folio_test_writeback (folio)) { -/* synchronous write or broken a_ops? */ -folio_clear_reclaim (folio); - }trace_mm_vmscan_write_folio (folio);node_stat_add_folio (folio,NR_VMSCAN_WRITE );return PAGE_SUCCESS ;Signature · 1 line
2.47.2
Re: [PATCHv3 06/11] mm/vmscan: Use PG_dropbehind instead of PG_reclaim
In reply to Kirill A. ShutemovQuoted 47 lines · Kirill A. Shutemov
The recently introduced
PG_dropbehindallows for freeing folios immediately after writeback. UnlikePG_reclaim, it does not need vmscan to be involved to get the folio freed.Instead of using
folio_set_reclaim(), usefolio_set_dropbehind()inpageout().It is safe to leave
PG_dropbehindon the folio if, for some reason (bug?), the folio is not in a writeback state after ->writepage(). In these cases, the kernel had to clearPG_reclaimas it shared a page flag bit withPG_readahead.Signed-off-by Kirill A. Shutemov <[email protected]>--- mm/vmscan.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)mm/vmscan.c +3
-7@@ -692,19 +692,16 @@ static pageout_t pageout(struct folio *folio, struct address_space *mapping,if (shmem_mapping (mapping) &&folio_test_large (folio)) wbc.list = folio_list; -folio_set_reclaim (folio); +folio_set_dropbehind (folio); + res = mapping->a_ops->writepage (&folio->page, &wbc);if (res <0 )handle_write_error (mapping, folio, res);if (res ==AOP_WRITEPAGE_ACTIVATE ) { -folio_clear_reclaim (folio); +folio_clear_dropbehind (folio);return PAGE_ACTIVATE ; } -if (!folio_test_writeback (folio)) { -/* synchronous write or broken a_ops? */ -folio_clear_reclaim (folio); - }trace_mm_vmscan_write_folio (folio);node_stat_add_folio (folio,NR_VMSCAN_WRITE );return PAGE_SUCCESS ; --
Quoted 2 lines
2.47.2
Hi, I'm seeing following panic with SWAP after this commit:
[ 29.672319] Oops: general protection fault, probably for non-canonical address 0xffff88909a3be3: 0000 [#1] PREEMPT SMP NOPTI [ 29.675503] CPU: 82 UID: 0 PID: 5145 Comm: tar Kdump: loaded Not tainted 6.13.0.ptch-g1fe9ea48ec98 #917 [ 29.677508] Hardware name: Red Hat KVM/RHEL-AV, BIOS 0.0.0 02/06/2015 [ 29.678886] RIP: 0010:__lock_acquire+0x20/0x15d0 [ 29.679891] Code: 90 90 90 90 90 90 90 90 90 90 41 57 41 56 41 55 41 54 55 53 48 83 ec 30 8b 2d 10 ac f3 01 44 8b ac 24 88 00 00 00 85 ed 74 64 <48> 8b 07 49 89 ff 48 3d 20 1d bf 83 74 56 8b 1d 8c f5 b1 01 41 89 [ 29.683852] RSP: 0018:ffffc9000bea3148 EFLAGS: 00010002 [ 29.684980] RAX: ffff8890874b2940 RBX: 0000000000000200 RCX: 0000000000000000 [ 29.686510] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00ffff88909a3be3 [ 29.688031] RBP: 0000000000000001 R08: 0000000000000001 R09: 0000000000000000 [ 29.689561] R10: 0000000000000000 R11: 0000000000000020 R12: 00ffff88909a3be3 [ 29.691087] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 29.692613] FS: 00007fa05c2824c0(0000) GS:ffff88a03fa80000(0000) knlGS:0000000000000000 [ 29.694339] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 29.695581] CR2: 000055f9abb7fc7d CR3: 00000010932f2002 CR4: 0000000000770eb0 [ 29.697109] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 29.698637] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 29.700161] PKRU: 55555554 [ 29.700759] Call Trace: [ 29.701296] <TASK> [ 29.701770] ? __die_body+0x1e/0x60 [ 29.702540] ? die_addr+0x3c/0x60 [ 29.703267] ? exc_general_protection+0x18f/0x3c0 [ 29.704290] ? asm_exc_general_protection+0x26/0x30 [ 29.705345] ? __lock_acquire+0x20/0x15d0 [ 29.706215] ? lockdep_hardirqs_on_prepare+0xda/0x190 [ 29.707304] ? asm_sysvec_apic_timer_interrupt+0x1a/0x20 [ 29.708452] lock_acquire+0xbf/0x2e0 [ 29.709229] ? folio_unmap_invalidate+0x12f/0x220 [ 29.710257] ? __folio_end_writeback+0x15d/0x430 [ 29.711260] ? __folio_end_writeback+0x116/0x430 [ 29.712261] _raw_spin_lock+0x30/0x40 [ 29.713064] ? folio_unmap_invalidate+0x12f/0x220 [ 29.714076] folio_unmap_invalidate+0x12f/0x220 [ 29.715058] folio_end_writeback+0xdf/0x190 [ 29.715967] swap_writepage_bdev_sync+0x1e0/0x450 [ 29.716994] ? __pfx_submit_bio_wait_endio+0x10/0x10 [ 29.718074] swap_writepage+0x46b/0x6b0 [ 29.718917] pageout+0x14b/0x360 [ 29.719628] shrink_folio_list+0x67d/0xec0 [ 29.720519] ? mark_held_locks+0x48/0x80 [ 29.721375] evict_folios+0x2a7/0x9e0 [ 29.722179] try_to_shrink_lruvec+0x19a/0x270 [ 29.723130] lru_gen_shrink_lruvec+0x70/0xc0 [ 29.724060] ? __lock_acquire+0x558/0x15d0 [ 29.724954] shrink_lruvec+0x57/0x780 [ 29.725754] ? find_held_lock+0x2d/0xa0 [ 29.726588] ? rcu_read_unlock+0x17/0x60 [ 29.727449] shrink_node+0x2ad/0x930 [ 29.728229] do_try_to_free_pages+0xbd/0x4e0 [ 29.729160] try_to_free_mem_cgroup_pages+0x123/0x2c0 [ 29.730252] try_charge_memcg+0x222/0x660 [ 29.731128] charge_memcg+0x3c/0x80 [ 29.731888] __mem_cgroup_charge+0x30/0x70 [ 29.732776] shmem_alloc_and_add_folio+0x1a5/0x480 [ 29.733818] ? filemap_get_entry+0x155/0x390 [ 29.734748] shmem_get_folio_gfp+0x28c/0x6c0 [ 29.735680] shmem_write_begin+0x5a/0xc0 [ 29.736535] generic_perform_write+0x12a/0x2e0 [ 29.737503] shmem_file_write_iter+0x86/0x90 [ 29.738428] vfs_write+0x364/0x530 [ 29.739180] ksys_write+0x6c/0xe0 [ 29.739906] do_syscall_64+0x66/0x140 [ 29.740713] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 29.741800] RIP: 0033:0x7fa05c439984 [ 29.742584] Code: c7 00 16 00 00 00 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 80 3d c5 06 0e 00 00 74 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 c3 0f 1f 00 55 48 89 e5 48 83 ec 20 48 89 [ 29.746542] RSP: 002b:00007ffece7720f8 EFLAGS: 00000202 ORIG_RAX: 0000000000000001 [ 29.748157] RAX: ffffffffffffffda RBX: 0000000000002800 RCX: 00007fa05c439984 [ 29.749682] RDX: 0000000000002800 RSI: 000055f9cfa08000 RDI: 0000000000000004 [ 29.751216] RBP: 00007ffece772140 R08: 0000000000002800 R09: 0000000000000007 [ 29.752743] R10: 0000000000000180 R11: 0000000000000202 R12: 000055f9cfa08000 [ 29.754262] R13: 0000000000000004 R14: 0000000000002800 R15: 00000000000009af [ 29.755797] </TASK> [ 29.756285] Modules linked in: zram virtiofs
I'm testing with PROVE_LOCKING on. It seems folio_unmap_invalidate is called for swapcache folio and it doesn't work well, following PATCH on top of mm-unstable seems fix it well:
mm/filemap.c +3 -2
@@ -1605,8 +1605,9 @@ static void folio_end_reclaim_write(struct folio *folio)* invalidation in that case. */ if (in_task () &&folio_trylock (folio)) { -if (folio->mapping) -folio_unmap_invalidate (folio->mapping, folio,0 ); +struct address_space *mapping =folio_mapping (folio); +if (mapping) +folio_unmap_invalidate (mapping, folio,0 );folio_unlock (folio); } }
mm/truncate.c +0 -0
@@ -565,23 +565,29 @@ int folio_unmap_invalidate(struct address_space
*mapping, struct folio *folio,
if (!filemap_release_folio(folio, gfp))
return -EBUSY;
- spin_lock(&mapping->host->i_lock);
+ if (!folio_test_swapcache(folio)) {
+ spin_lock(&mapping->host->i_lock);
+ BUG_ON(folio_has_private(folio));
+ }
+
xa_lock_irq(&mapping->i_pages);
if (folio_test_dirty(folio))
goto failed;- BUG_ON(folio_has_private(folio));
__filemap_remove_folio(folio, NULL);
xa_unlock_irq(&mapping->i_pages);
if (mapping_shrinkable(mapping))
inode_add_lru(mapping->host);- spin_unlock(&mapping->host->i_lock);
+
+ if (!folio_test_swapcache(folio))
+ spin_unlock(&mapping->host->i_lock);
filemap_free_folio(mapping, folio);
return 1;
failed:
xa_unlock_irq(&mapping->i_pages);
- spin_unlock(&mapping->host->i_lock);
+ if (!folio_test_swapcache(folio))
+ spin_unlock(&mapping->host->i_lock);
return -EBUSY;}
Re: [PATCHv3 06/11] mm/vmscan: Use PG_dropbehind instead of PG_reclaim
Quoted 139 lines · Kairui Song
Quoted 47 lines · Kirill A. Shutemov
The recently introduced
PG_dropbehindallows for freeing folios immediately after writeback. UnlikePG_reclaim, it does not need vmscan to be involved to get the folio freed.Instead of using
folio_set_reclaim(), usefolio_set_dropbehind()inpageout().It is safe to leave
PG_dropbehindon the folio if, for some reason (bug?), the folio is not in a writeback state after ->writepage(). In these cases, the kernel had to clearPG_reclaimas it shared a page flag bit withPG_readahead.Signed-off-by Kirill A. Shutemov <[email protected]>--- mm/vmscan.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)mm/vmscan.c +3
-7@@ -692,19 +692,16 @@ static pageout_t pageout(struct folio *folio, struct address_space *mapping,if (shmem_mapping (mapping) &&folio_test_large (folio)) wbc.list = folio_list; -folio_set_reclaim (folio); +folio_set_dropbehind (folio); + res = mapping->a_ops->writepage (&folio->page, &wbc);if (res <0 )handle_write_error (mapping, folio, res);if (res ==AOP_WRITEPAGE_ACTIVATE ) { -folio_clear_reclaim (folio); +folio_clear_dropbehind (folio);return PAGE_ACTIVATE ; } -if (!folio_test_writeback (folio)) { -/* synchronous write or broken a_ops? */ -folio_clear_reclaim (folio); - }trace_mm_vmscan_write_folio (folio);node_stat_add_folio (folio,NR_VMSCAN_WRITE );return PAGE_SUCCESS ; --Quoted 2 lines
2.47.2
Hi, I'm seeing following panic with SWAP after this commit:
[ 29.672319] Oops: general protection fault, probably for non-canonical address 0xffff88909a3be3: 0000 [#1] PREEMPT SMP NOPTI [ 29.675503] CPU: 82 UID: 0 PID: 5145 Comm: tar Kdump: loaded Not tainted 6.13.0.ptch-g1fe9ea48ec98 #917 [ 29.677508] Hardware name: Red Hat KVM/RHEL-AV, BIOS 0.0.0 02/06/2015 [ 29.678886] RIP: 0010:__lock_acquire+0x20/0x15d0 [ 29.679891] Code: 90 90 90 90 90 90 90 90 90 90 41 57 41 56 41 55 41 54 55 53 48 83 ec 30 8b 2d 10 ac f3 01 44 8b ac 24 88 00 00 00 85 ed 74 64 <48> 8b 07 49 89 ff 48 3d 20 1d bf 83 74 56 8b 1d 8c f5 b1 01 41 89 [ 29.683852] RSP: 0018:ffffc9000bea3148 EFLAGS: 00010002 [ 29.684980] RAX: ffff8890874b2940 RBX: 0000000000000200 RCX: 0000000000000000 [ 29.686510] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00ffff88909a3be3 [ 29.688031] RBP: 0000000000000001 R08: 0000000000000001 R09: 0000000000000000 [ 29.689561] R10: 0000000000000000 R11: 0000000000000020 R12: 00ffff88909a3be3 [ 29.691087] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 29.692613] FS: 00007fa05c2824c0(0000) GS:ffff88a03fa80000(0000) knlGS:0000000000000000 [ 29.694339] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 29.695581] CR2: 000055f9abb7fc7d CR3: 00000010932f2002 CR4: 0000000000770eb0 [ 29.697109] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 29.698637] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 29.700161] PKRU: 55555554 [ 29.700759] Call Trace: [ 29.701296] <TASK> [ 29.701770] ? __die_body+0x1e/0x60 [ 29.702540] ? die_addr+0x3c/0x60 [ 29.703267] ? exc_general_protection+0x18f/0x3c0 [ 29.704290] ? asm_exc_general_protection+0x26/0x30 [ 29.705345] ? __lock_acquire+0x20/0x15d0 [ 29.706215] ? lockdep_hardirqs_on_prepare+0xda/0x190 [ 29.707304] ? asm_sysvec_apic_timer_interrupt+0x1a/0x20 [ 29.708452] lock_acquire+0xbf/0x2e0 [ 29.709229] ? folio_unmap_invalidate+0x12f/0x220 [ 29.710257] ? __folio_end_writeback+0x15d/0x430 [ 29.711260] ? __folio_end_writeback+0x116/0x430 [ 29.712261] _raw_spin_lock+0x30/0x40 [ 29.713064] ? folio_unmap_invalidate+0x12f/0x220 [ 29.714076] folio_unmap_invalidate+0x12f/0x220 [ 29.715058] folio_end_writeback+0xdf/0x190 [ 29.715967] swap_writepage_bdev_sync+0x1e0/0x450 [ 29.716994] ? __pfx_submit_bio_wait_endio+0x10/0x10 [ 29.718074] swap_writepage+0x46b/0x6b0 [ 29.718917] pageout+0x14b/0x360 [ 29.719628] shrink_folio_list+0x67d/0xec0 [ 29.720519] ? mark_held_locks+0x48/0x80 [ 29.721375] evict_folios+0x2a7/0x9e0 [ 29.722179] try_to_shrink_lruvec+0x19a/0x270 [ 29.723130] lru_gen_shrink_lruvec+0x70/0xc0 [ 29.724060] ? __lock_acquire+0x558/0x15d0 [ 29.724954] shrink_lruvec+0x57/0x780 [ 29.725754] ? find_held_lock+0x2d/0xa0 [ 29.726588] ? rcu_read_unlock+0x17/0x60 [ 29.727449] shrink_node+0x2ad/0x930 [ 29.728229] do_try_to_free_pages+0xbd/0x4e0 [ 29.729160] try_to_free_mem_cgroup_pages+0x123/0x2c0 [ 29.730252] try_charge_memcg+0x222/0x660 [ 29.731128] charge_memcg+0x3c/0x80 [ 29.731888] __mem_cgroup_charge+0x30/0x70 [ 29.732776] shmem_alloc_and_add_folio+0x1a5/0x480 [ 29.733818] ? filemap_get_entry+0x155/0x390 [ 29.734748] shmem_get_folio_gfp+0x28c/0x6c0 [ 29.735680] shmem_write_begin+0x5a/0xc0 [ 29.736535] generic_perform_write+0x12a/0x2e0 [ 29.737503] shmem_file_write_iter+0x86/0x90 [ 29.738428] vfs_write+0x364/0x530 [ 29.739180] ksys_write+0x6c/0xe0 [ 29.739906] do_syscall_64+0x66/0x140 [ 29.740713] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 29.741800] RIP: 0033:0x7fa05c439984 [ 29.742584] Code: c7 00 16 00 00 00 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 80 3d c5 06 0e 00 00 74 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 c3 0f 1f 00 55 48 89 e5 48 83 ec 20 48 89 [ 29.746542] RSP: 002b:00007ffece7720f8 EFLAGS: 00000202 ORIG_RAX: 0000000000000001 [ 29.748157] RAX: ffffffffffffffda RBX: 0000000000002800 RCX: 00007fa05c439984 [ 29.749682] RDX: 0000000000002800 RSI: 000055f9cfa08000 RDI: 0000000000000004 [ 29.751216] RBP: 00007ffece772140 R08: 0000000000002800 R09: 0000000000000007 [ 29.752743] R10: 0000000000000180 R11: 0000000000000202 R12: 000055f9cfa08000 [ 29.754262] R13: 0000000000000004 R14: 0000000000002800 R15: 00000000000009af [ 29.755797] </TASK> [ 29.756285] Modules linked in: zram virtiofs
Quoted 3 lines
I'm testing with
PROVE_LOCKINGon. It seemsfolio_unmap_invalidateis called for swapcache folio and it doesn't work well, following PATCH on top of mm-unstable seems fix it well:
I think there is a bigger problem here. folio_end_reclaim_write() currently calls folio_unmap_invalidate() to remove the mapping, and that's very different from what __remove_mapping() does in the reclaim
path: not only it breaks the swapcache case, the shadow entry is also lost.
Re: [PATCHv3 06/11] mm/vmscan: Use PG_dropbehind instead of PG_reclaim
In reply to Kairui SongQuoted 54 lines · Kairui Song
Quoted 47 lines · Kirill A. Shutemov
The recently introduced
PG_dropbehindallows for freeing folios immediately after writeback. UnlikePG_reclaim, it does not need vmscan to be involved to get the folio freed.Instead of using
folio_set_reclaim(), usefolio_set_dropbehind()inpageout().It is safe to leave
PG_dropbehindon the folio if, for some reason (bug?), the folio is not in a writeback state after ->writepage(). In these cases, the kernel had to clearPG_reclaimas it shared a page flag bit withPG_readahead.Signed-off-by Kirill A. Shutemov <[email protected]>--- mm/vmscan.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)mm/vmscan.c +3
-7@@ -692,19 +692,16 @@ static pageout_t pageout(struct folio *folio, struct address_space *mapping,if (shmem_mapping (mapping) &&folio_test_large (folio)) wbc.list = folio_list; -folio_set_reclaim (folio); +folio_set_dropbehind (folio); + res = mapping->a_ops->writepage (&folio->page, &wbc);if (res <0 )handle_write_error (mapping, folio, res);if (res ==AOP_WRITEPAGE_ACTIVATE ) { -folio_clear_reclaim (folio); +folio_clear_dropbehind (folio);return PAGE_ACTIVATE ; } -if (!folio_test_writeback (folio)) { -/* synchronous write or broken a_ops? */ -folio_clear_reclaim (folio); - }trace_mm_vmscan_write_folio (folio);node_stat_add_folio (folio,NR_VMSCAN_WRITE );return PAGE_SUCCESS ; --Quoted 2 lines
2.47.2
Hi, I'm seeing following panic with SWAP after this commit:
Quoted 6 lines
[ 29.672319] Oops: general protection fault, probably for non-canonical address 0xffff88909a3be3: 0000 [#1] PREEMPT SMP NOPTI [ 29.675503] CPU: 82 UID: 0 PID: 5145 Comm: tar Kdump: loaded Not tainted 6.13.0.ptch-g1fe9ea48ec98 #917 [ 29.677508] Hardware name: Red Hat KVM/RHEL-AV, BIOS 0.0.0 02/06/2015 [ 29.678886] RIP: 0010:__lock_acquire+0x20/0x15d0
Ouch.
I failed to trigger it my setup. Could you share your reproducer?
Quoted 3 lines
I'm testing with
PROVE_LOCKINGon. It seemsfolio_unmap_invalidateis called for swapcache folio and it doesn't work well, following PATCH on top of mm-unstable seems fix it well:
Right. I don't understand swapping good enough. I missed this.
Quoted 6 lines
mm/filemap.c +0
-0@@ -1605,8 +1605,9 @@ static void folio_end_reclaim_write(struct folio *folio)* invalidation in that case.
mm/filemap.c static void folio_end_reclaim_write(struct folio *folio) · line 1613
Quoted 10 lines
mm/filemap.c +3
-2*/ if (in_task () &&folio_trylock (folio)) { -if (folio->mapping) -folio_unmap_invalidate (folio->mapping, folio,0 ); +struct address_space *mapping =folio_mapping (folio); +if (mapping) +folio_unmap_invalidate (mapping, folio,0 );folio_unlock (folio); } }
Once you do this, folio_unmap_invalidate() will never succeed for swapcache as folio->mapping != mapping check will always be true and it will fail with -EBUSY.
I guess we need to do something similar to what __remove_mapping() does for swapcache folios.
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov
Andrew Morton
maintainerRe: [PATCHv3 06/11] mm/vmscan: Use PG_dropbehind instead of PG_reclaim
Quoted 21 lines · On Mon, 3 Feb 2025 10:39:58 +0200 "Kirill A. Shutemov"…
Quoted 6 lines
mm/filemap.c +0
-0@@ -1605,8 +1605,9 @@ static void folio_end_reclaim_write(struct folio *folio)* invalidation in that case. mm/filemap.c static void folio_end_reclaim_write(struct folio *folio) · line 1613
Quoted 10 lines
mm/filemap.c +3
-2*/ if (in_task () &&folio_trylock (folio)) { -if (folio->mapping) -folio_unmap_invalidate (folio->mapping, folio,0 ); +struct address_space *mapping =folio_mapping (folio); +if (mapping) +folio_unmap_invalidate (mapping, folio,0 );folio_unlock (folio); } }Once you do this,
folio_unmap_invalidate()will never succeed for swapcache asfolio->mapping!= mapping check will always be true and it will fail with-EBUSY.
Quoted 2 lines
I guess we need to do something similar to what
__remove_mapping()does for swapcache folios.
Thanks, I'll drop the v3 series from mm.git.
Re: [PATCHv3 06/11] mm/vmscan: Use PG_dropbehind instead of PG_reclaim
In reply to Kirill A. ShutemovQuoted 9 lines · Kirill A. Shutemov
Quoted 8 lines
Hi, I'm seeing following panic with SWAP after this commit:
[ 29.672319] Oops: general protection fault, probably for non-canonical address 0xffff88909a3be3: 0000 [#1] PREEMPT SMP NOPTI [ 29.675503] CPU: 82 UID: 0 PID: 5145 Comm: tar Kdump: loaded Not tainted 6.13.0.ptch-g1fe9ea48ec98 #917 [ 29.677508] Hardware name: Red Hat KVM/RHEL-AV, BIOS 0.0.0 02/06/2015 [ 29.678886] RIP: 0010:__lock_acquire+0x20/0x15d0
Quoted 3 lines
Ouch.
I failed to trigger it my setup. Could you share your reproducer?
I'm seeing this as well (backtraces below).
My repro is:
- 4GB VM with 2 zram devices
- one is setup as swap
- the other one has ext4 fs on it
- I dd large files to it
---
xa_lock_irq(&mapping->i_pages):
[ 94.609589][ T157] Oops: general protection fault, probably for non-canonical address 0xe01ffbf11020301a: 0000 [#1] PREEMPT SMP KASAN PTI [ 94.611881][ T157] KASAN: maybe wild-memory-access in range [0x00ffff88810180d0-0x00ffff88810180d7] [ 94.613567][ T157] CPU: 1 UID: 0 PID: 157 Comm: kswapd0 Not tainted 6.13.0+ #927 [ 94.614947][ T157] RIP: 0010:__lock_acquire+0x6a/0x1ef0 [ 94.615942][ T157] Code: 08 84 d2 0f 85 ed 13 00 00 44 8b 05 24 30 d5 02 45 85 c0 0f 84 bc 07 00 00 48 b8 00 00 00 00 00 fc ff df 4c 89 e2 48 c1 ea 03 <80> 3c 02 00 0f 85 eb 18 00 00 49 8b 04 24 48 3d a0 8b ac 84 0f 84 [ 94.619668][ T157] RSP: 0018:ffff88810510eec0 EFLAGS: 00010002 [ 94.620835][ T157] RAX: dffffc0000000000 RBX: 1ffff11020a21df5 RCX: 1ffffffff084c092 [ 94.622329][ T157] RDX: 001ffff11020301a RSI: 0000000000000000 RDI: 00ffff88810180d1 [ 94.623779][ T157] RBP: 00ffff88810180d1 R08: 0000000000000001 R09: 0000000000000000 [ 94.625213][ T157] R10: ffffffff8425d0d7 R11: 0000000000000000 R12: 00ffff88810180d1 [ 94.626656][ T157] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000001 [ 94.628086][ T157] FS: 0000000000000000(0000) GS:ffff88815aa80000(0000) knlGS:0000000000000000 [ 94.629700][ T157] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 94.630894][ T157] CR2: 00007f757719c2b0 CR3: 0000000003c82005 CR4: 0000000000770ef0 [ 94.632333][ T157] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 94.633796][ T157] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 94.635265][ T157] PKRU: 55555554 [ 94.635909][ T157] Call Trace: [ 94.636512][ T157] <TASK> [ 94.637052][ T157] ? show_trace_log_lvl+0x1a7/0x2e0 [ 94.638005][ T157] ? show_trace_log_lvl+0x1a7/0x2e0 [ 94.638960][ T157] ? lock_acquire.part.0+0xfa/0x310 [ 94.639909][ T157] ? __die_body.cold+0x8/0x12 [ 94.640765][ T157] ? die_addr+0x42/0x70 [ 94.641530][ T157] ? exc_general_protection+0x12e/0x210 [ 94.642558][ T157] ? asm_exc_general_protection+0x22/0x30 [ 94.643610][ T157] ? __lock_acquire+0x6a/0x1ef0 [ 94.644506][ T157] ? _raw_spin_unlock_irq+0x24/0x40 [ 94.645468][ T157] ? __wait_for_common+0x2f2/0x610 [ 94.646412][ T157] ? pci_mmcfg_reserved+0x120/0x120 [ 94.647364][ T157] ? submit_bio_noacct_nocheck+0x32e/0x3e0 [ 94.648448][ T157] ? lock_is_held_type+0x81/0xe0 [ 94.649360][ T157] lock_acquire.part.0+0xfa/0x310 [ 94.650288][ T157] ? folio_unmap_invalidate+0x286/0x550 [ 94.651324][ T157] ? __lock_acquire+0x1ef0/0x1ef0 [ 94.652250][ T157] ? submit_bio_wait+0x17c/0x200 [ 94.653166][ T157] ? submit_bio_wait_endio+0x40/0x40 [ 94.654140][ T157] ? lock_acquire+0x18a/0x1f0 [ 94.655008][ T157] _raw_spin_lock+0x2c/0x40 [ 94.655853][ T157] ? folio_unmap_invalidate+0x286/0x550 [ 94.656879][ T157] folio_unmap_invalidate+0x286/0x550 [ 94.657866][ T157] folio_end_writeback+0x146/0x190 [ 94.658815][ T157] swap_writepage_bdev_sync+0x312/0x410 [ 94.659840][ T157] ? swap_read_folio_bdev_sync+0x3c0/0x3c0 [ 94.660917][ T157] ? do_raw_spin_lock+0x12a/0x260 [ 94.661845][ T157] ? __rwlock_init+0x150/0x150 [ 94.662726][ T157] ? bio_kmalloc+0x20/0x20 [ 94.663548][ T157] ? swapcache_clear+0xd0/0xd0 [ 94.664431][ T157] swap_writepage+0x2a5/0x720 [ 94.665298][ T157] pageout+0x304/0x6a0 [ 94.666052][ T157] ? get_pte_pfn.isra.0+0x4d0/0x4d0 [ 94.667025][ T157] ? find_held_lock+0x2d/0x110 [ 94.667912][ T157] ? enable_swap_slots_cache+0x90/0x90 [ 94.668925][ T157] ? arch_tlbbatch_flush+0x1f6/0x370 [ 94.669903][ T157] shrink_folio_list+0x19b5/0x2600 [ 94.670856][ T157] ? pageout+0x6a0/0x6a0 [ 94.671649][ T157] ? isolate_folios+0x156/0x320 [ 94.672544][ T157] ? find_held_lock+0x2d/0x110 [ 94.673428][ T157] ? mark_lock+0xcc/0x12c0 [ 94.674258][ T157] ? mark_lock_irq+0x1cd0/0x1cd0 [ 94.675174][ T157] ? reacquire_held_locks+0x4d0/0x4d0 [ 94.676166][ T157] ? mark_held_locks+0x94/0xe0 [ 94.677045][ T157] evict_folios+0x4bb/0x1580 [ 94.677890][ T157] ? isolate_folios+0x320/0x320 [ 94.678787][ T157] ? __lock_acquire+0xc4c/0x1ef0 [ 94.679695][ T157] ? lock_is_held_type+0x81/0xe0 [ 94.680607][ T157] try_to_shrink_lruvec+0x41e/0x9e0 [ 94.681564][ T157] ? __lock_acquire+0xc4c/0x1ef0 [ 94.682482][ T157] ? evict_folios+0x1580/0x1580 [ 94.683390][ T157] ? lock_release+0x105/0x260 [ 94.684255][ T157] lru_gen_shrink_node+0x25d/0x660 [ 94.685202][ T157] ? balance_pgdat+0x5b5/0xf00 [ 94.686083][ T157] ? try_to_shrink_lruvec+0x9e0/0x9e0 [ 94.687076][ T157] ? pgdat_balanced+0xb8/0x110 [ 94.687957][ T157] balance_pgdat+0x532/0xf00 [ 94.688803][ T157] ? shrink_node.part.0+0xc30/0xc30 [ 94.689758][ T157] ? io_schedule_timeout+0x110/0x110 [ 94.690741][ T157] ? reacquire_held_locks+0x4d0/0x4d0 [ 94.691723][ T157] ? __lock_acquire+0x1ef0/0x1ef0 [ 94.692643][ T157] ? zone_watermark_ok_safe+0x32/0x290 [ 94.693650][ T157] ? inactive_is_low.isra.0+0xe0/0xe0 [ 94.694639][ T157] ? do_raw_spin_lock+0x12a/0x260 [ 94.695567][ T157] kswapd+0x2ef/0x4e0 [ 94.696297][ T157] ? balance_pgdat+0xf00/0xf00 [ 94.697176][ T157] ? __kthread_parkme+0xb1/0x1c0 [ 94.698087][ T157] ? balance_pgdat+0xf00/0xf00 [ 94.698971][ T157] kthread+0x38b/0x700 [ 94.699721][ T157] ? kthread_is_per_cpu+0xb0/0xb0 [ 94.700648][ T157] ? lock_acquire+0x18a/0x1f0 [ 94.701516][ T157] ? kthread_is_per_cpu+0xb0/0xb0 [ 94.702438][ T157] ret_from_fork+0x2d/0x70 [ 94.703267][ T157] ? kthread_is_per_cpu+0xb0/0xb0 [ 94.704193][ T157] ret_from_fork_asm+0x11/0x20 [ 94.705074][ T157] </TASK>
Also UAF in compactd
[ 95.249096][ T146] ================================================================== [ 95.254091][ T146] BUG: KASAN: slab-use-after-free in kcompactd+0x9cd/0xa60 [ 95.257959][ T146] Read of size 4 at addr ffff888105100018 by task kcompactd0/146 [ 95.262100][ T146] [ 95.263347][ T146] CPU: 11 UID: 0 PID: 146 Comm: kcompactd0 Tainted: G D W 6.13.0+ #927 [ 95.263363][ T146] Tainted: [D]=DIE, [W]=WARN [ 95.263367][ T146] Call Trace: [ 95.263379][ T146] <TASK> [ 95.263386][ T146] dump_stack_lvl+0x57/0x80 [ 95.263403][ T146] print_address_description.constprop.0+0x88/0x330 [ 95.263416][ T146] ? kcompactd+0x9cd/0xa60 [ 95.263425][ T146] print_report+0xe2/0x1cc [ 95.263433][ T146] ? __virt_addr_valid+0x1d1/0x3b0 [ 95.263442][ T146] ? kcompactd+0x9cd/0xa60 [ 95.263449][ T146] ? kcompactd+0x9cd/0xa60 [ 95.263456][ T146] kasan_report+0xb9/0x180 [ 95.263466][ T146] ? kcompactd+0x9cd/0xa60 [ 95.263476][ T146] kcompactd+0x9cd/0xa60 [ 95.263487][ T146] ? kcompactd_do_work+0x710/0x710 [ 95.263495][ T146] ? prepare_to_swait_exclusive+0x260/0x260 [ 95.263506][ T146] ? __kthread_parkme+0xb1/0x1c0 [ 95.263520][ T146] ? kcompactd_do_work+0x710/0x710 [ 95.263527][ T146] kthread+0x38b/0x700 [ 95.263535][ T146] ? kthread_is_per_cpu+0xb0/0xb0 [ 95.263542][ T146] ? lock_acquire+0x18a/0x1f0 [ 95.263552][ T146] ? kthread_is_per_cpu+0xb0/0xb0 [ 95.263559][ T146] ret_from_fork+0x2d/0x70 [ 95.263569][ T146] ? kthread_is_per_cpu+0xb0/0xb0 [ 95.263576][ T146] ret_from_fork_asm+0x11/0x20 [ 95.263589][ T146] </TASK> [ 95.263592][ T146] [ 95.293474][ T146] Allocated by task 2: [ 95.294209][ T146] kasan_save_stack+0x1e/0x40 [ 95.295111][ T146] kasan_save_track+0x10/0x30 [ 95.295978][ T146] __kasan_slab_alloc+0x62/0x70 [ 95.296860][ T146] kmem_cache_alloc_node_noprof+0xdb/0x2a0 [ 95.297915][ T146] dup_task_struct+0x32/0x550 [ 95.298797][ T146] copy_process+0x309/0x45d0 [ 95.299656][ T146] kernel_clone+0xb7/0x600 [ 95.300451][ T146] kernel_thread+0xb0/0xe0 [ 95.301253][ T146] kthreadd+0x3b5/0x620 [ 95.302019][ T146] ret_from_fork+0x2d/0x70 [ 95.302865][ T146] ret_from_fork_asm+0x11/0x20 [ 95.303724][ T146] [ 95.304146][ T146] Freed by task 0: [ 95.304836][ T146] kasan_save_stack+0x1e/0x40 [ 95.305708][ T146] kasan_save_track+0x10/0x30 [ 95.306569][ T146] kasan_save_free_info+0x37/0x50 [ 95.307515][ T146] __kasan_slab_free+0x33/0x40 [ 95.308402][ T146] kmem_cache_free+0xff/0x480 [ 95.309256][ T146] delayed_put_task_struct+0x15a/0x1d0 [ 95.310258][ T146] rcu_do_batch+0x2ee/0xb70 [ 95.311113][ T146] rcu_core+0x4a6/0xa10 [ 95.311868][ T146] handle_softirqs+0x191/0x650 [ 95.312747][ T146] __irq_exit_rcu+0xaf/0xe0 [ 95.313643][ T146] irq_exit_rcu+0xa/0x20 [ 95.314536][ T146] sysvec_apic_timer_interrupt+0x65/0x80 [ 95.315616][ T146] asm_sysvec_apic_timer_interrupt+0x16/0x20 [ 95.316702][ T146] [ 95.317127][ T146] Last potentially related work creation: [ 95.318155][ T146] kasan_save_stack+0x1e/0x40 [ 95.319006][ T146] kasan_record_aux_stack+0x97/0xa0 [ 95.319947][ T146] __call_rcu_common.constprop.0+0x70/0x7b0 [ 95.321014][ T146] __schedule+0x75d/0x1720 [ 95.321817][ T146] schedule_idle+0x55/0x80 [ 95.322624][ T146] cpu_startup_entry+0x50/0x60 [ 95.323490][ T146] start_secondary+0x1b6/0x210 [ 95.324354][ T146] common_startup_64+0x12c/0x138 [ 95.325248][ T146] [ 95.325669][ T146] The buggy address belongs to the object at ffff888105100000 [ 95.325669][ T146] which belongs to the cache task_struct of size 8200 [ 95.328215][ T146] The buggy address is located 24 bytes inside of [ 95.328215][ T146] freed 8200-byte region [ffff888105100000, ffff888105102008) [ 95.330692][ T146] [ 95.331116][ T146] The buggy address belongs to the physical page: [ 95.332275][ T146] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x105100 [ 95.333862][ T146] head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 [ 95.335399][ T146] flags: 0x8000000000000040(head|zone=2) [ 95.336425][ T146] page_type: f5(slab) [ 95.337155][ T146] raw: 8000000000000040 ffff888100a80c80 dead000000000122 0000000000000000 [ 95.338716][ T146] raw: 0000000000000000 0000000000030003 00000000f5000000 0000000000000000 [ 95.340273][ T146] head: 8000000000000040 ffff888100a80c80 dead000000000122 0000000000000000 [ 95.341844][ T146] head: 0000000000000000 0000000000030003 00000000f5000000 0000000000000000 [ 95.343418][ T146] head: 8000000000000003 ffffea0004144001 ffffffffffffffff 0000000000000000 [ 95.344977][ T146] head: 0000000000000008 0000000000000000 00000000ffffffff 0000000000000000 [ 95.346540][ T146] page dumped because: kasan: bad access detected [ 95.347701][ T146] [ 95.348123][ T146] Memory state around the buggy address: [ 95.349139][ T146] ffff8881050fff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 95.350598][ T146] ffff8881050fff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 95.352054][ T146] >ffff888105100000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 95.353510][ T146] ^ [ 95.354389][ T146] ffff888105100080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 95.355856][ T146] ffff888105100100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 95.357315][ T146] ==================================================================
PATCH v3 7/11 mm/vmscan: Use PG_dropbehind instead of PG_reclaim in shrink_folio_list()
In reply to Kirill A. ShutemovThe recently introduced PG_dropbehind allows for freeing folios immediately after writeback. Unlike PG_reclaim, it does not need vmscan to be involved to get the folio freed.
Instead of using folio_set_reclaim(), use folio_set_dropbehind() in shrink_folio_list().
It is safe to leave PG_dropbehind on the folio if, for some reason (bug?), the folio is not in a writeback state after ->writepage(). In these cases, the kernel had to clear PG_reclaim as it shared a page flag bit with PG_readahead.
Also use PG_dropbehind instead PG_reclaim to detect I/O congestion.
--- mm/vmscan.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-)
mm/vmscan.c +8 -22
@@ -1140,7 +1140,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,* for immediate reclaim are making it to the end of * the LRU a second time. */ -if (writeback &&folio_test_reclaim (folio)) +if (writeback &&folio_test_dropbehind (folio)) stat->nr_congested += nr_pages;/*
@@ -1149,7 +1149,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,* * 1) If reclaim is encountering an excessive number * of folios under writeback and this folio has both -* the writeback and reclaim flags set, then it +* the writeback and dropbehind flags set, then it * indicates that folios are being queued for I/O but * are being recycled through the LRU before the I/O * can complete. Waiting on the folio itself risks an
@@ -1173,7 +1173,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,* would probably show more reasons. * * 3) Legacy memcg encounters a folio that already has the -* reclaim flag set. memcg does not have any dirty folio +* dropbehind flag set. memcg does not have any dirty folio * throttling so we could easily OOM just because too many * folios are in writeback and there is nothing else to * reclaim. Wait for the writeback to complete.
@@ -1190,30 +1190,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,if (folio_test_writeback (folio)) {/* Case 1 above */ if (current_is_kswapd () && -folio_test_reclaim (folio) && +folio_test_dropbehind (folio) &&test_bit (PGDAT_WRITEBACK , &pgdat->flags)) { stat->nr_immediate += nr_pages; goto activate_locked;/* Case 2 above */ }else if (writeback_throttling_sane (sc) || - !folio_test_reclaim (folio) || + !folio_test_dropbehind (folio) || !may_enter_fs (folio, sc->gfp_mask)) { -/* -* This is slightly racy - -* folio_end_writeback() might have -* just cleared the reclaim flag, then -* setting the reclaim flag here ends up -* interpreted as the readahead flag - but -* that does not matter enough to care. -* What we do want is for this folio to -* have the reclaim flag set next time -* memcg reclaim reaches the tests above, -* so it will then wait for writeback to -* avoid OOM; and it's also appropriate -* in global reclaim. -*/ -folio_set_reclaim (folio); +folio_set_dropbehind (folio); stat->nr_writeback += nr_pages; goto activate_locked;
@@ -1368,7 +1354,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,*/ if (folio_is_file_lru (folio) && (!current_is_kswapd () || - !folio_test_reclaim (folio) || + !folio_test_dropbehind (folio) || !test_bit (PGDAT_DIRTY , &pgdat->flags))) {/* * Immediately reclaim when written back.
@@ -1378,7 +1364,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,*/ node_stat_mod_folio (folio,NR_VMSCAN_IMMEDIATE , nr_pages); -folio_set_reclaim (folio); +folio_set_dropbehind (folio); goto activate_locked; }
Signature · 1 line
2.47.2
PATCH v3 8/11 mm/mglru: Check PG_dropbehind instead of PG_reclaim in lru_gen_folio_seq()
In reply to Kirill A. ShutemovKernel sets PG_dropcache instead of PG_reclaim everywhere. Check PG_dropcache in lru_gen_folio_seq().
No need to check for dirty and writeback as there's no conflict with PG_readahead anymore.
--- include/linux/mm_inline.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/mm_inline.h +1 -2
@@ -241,8 +241,7 @@ static inline unsigned long lru_gen_folio_seq(struct lruvec *lruvec, struct folielse if (reclaiming) gen =MAX_NR_GENS ;else if ((!folio_is_file_lru (folio) && !folio_test_swapcache (folio)) || - (folio_test_reclaim (folio) && - (folio_test_dirty (folio) ||folio_test_writeback (folio)))) +folio_test_dropbehind (folio)) gen =MIN_NR_GENS ;else gen =MAX_NR_GENS -folio_test_workingset (folio);
Signature · 1 line
2.47.2
PATCH v3 9/11 mm: Remove PG_reclaim
In reply to Kirill A. ShutemovNobody sets the flag anymore.
Remove the PG_reclaim, making PG_readhead exclusive user of the page flag bit.
--- fs/fuse/dev.c | 2 +- fs/proc/page.c | 2 +- include/linux/mm_inline.h | 15 ------- include/linux/page-flags.h | 15 +++---- include/trace/events/mmflags.h | 2 +- include/uapi/linux/kernel-page-flags.h | 2 +- mm/filemap.c | 12 ----- mm/migrate.c | 10 +---- mm/page-writeback.c | 16 +------ mm/page_io.c | 15 +++---- mm/swap.c | 61 ++------------------------ mm/vmscan.c | 7 --- tools/mm/page-types.c | 8 +--- 13 files changed, 22 insertions(+), 145 deletions(-)
fs/fuse/dev.c +1 -1
@@ -827,7 +827,7 @@ static int fuse_check_folio(struct folio *folio) 1 << PG_lru | 1 << PG_active | 1 << PG_workingset | - 1 << PG_reclaim | + 1 << PG_readahead | 1 << PG_waiters | LRU_GEN_MASK | LRU_REFS_MASK))) {dump_page (&folio->page,"fuse: trying to steal weird page" );
fs/proc/page.c +1 -1
@@ -189,7 +189,7 @@ u64 stable_page_flags(const struct page *page) u |=kpf_copy_bit (k,KPF_LRU , PG_lru); u |=kpf_copy_bit (k,KPF_REFERENCED , PG_referenced); u |=kpf_copy_bit (k,KPF_ACTIVE , PG_active); - u |=kpf_copy_bit (k,KPF_RECLAIM , PG_reclaim); + u |=kpf_copy_bit (k,KPF_READAHEAD , PG_readahead);#define SWAPCACHE ((1 << PG_swapbacked) | (1 << PG_swapcache))if ((k &SWAPCACHE ) ==SWAPCACHE )
include/linux/mm_inline.h +0 -15
@@ -270,7 +270,6 @@ static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio,set_mask_bits (&folio->flags,LRU_GEN_MASK |BIT (PG_active), flags);lru_gen_update_size (lruvec, folio,-1 , gen); -/* for folio_rotate_reclaimable() */ if (reclaiming)list_add_tail (&folio->lru, &lrugen->folios[gen][type][zone]);else
@@ -349,20 +348,6 @@ void lruvec_add_folio(struct lruvec *lruvec, struct folio *folio)list_add (&folio->lru, &lruvec->lists[lru]); } -static __always_inline -void lruvec_add_folio_tail(struct lruvec *lruvec, struct folio *folio) -{ -enum lru_list lru =folio_lru_list (folio); - -if (lru_gen_add_folio (lruvec, folio, true)) -return ; - -update_lru_size (lruvec, lru,folio_zonenum (folio), -folio_nr_pages (folio)); -/* This is not expected to be used on LRU_UNEVICTABLE */ -list_add_tail (&folio->lru, &lruvec->lists[lru]); -} -static __always_inline void lruvec_del_folio(struct lruvec *lruvec, struct folio *folio) {
include/linux/page-flags.h +5 -10
@@ -63,8 +63,8 @@* might lose their PG_swapbacked flag when they simply can be dropped (e.g. as * a result of MADV_FREE). * -* PG_referenced, PG_reclaim are used for page reclaim for anonymous and -* file-backed pagecache (see mm/vmscan.c). +* PG_referenced is used for page reclaim for anonymous and file-backed +* pagecache (see mm/vmscan.c). * * PG_arch_1 is an architecture specific page state bit. The generic code * guarantees that this bit is cleared for a page when it first is entered into
@@ -107,7 +107,7 @@ enum pageflags { PG_reserved, PG_private,/* If pagecache, has fs-private data */ PG_private_2,/* If pagecache, has fs aux data */ - PG_reclaim,/* To be reclaimed asap */ + PG_readahead, PG_swapbacked,/* Page is backed by RAM/swap */ PG_unevictable,/* Page is "unevictable" */ PG_dropbehind, /* drop pages on IO completion */
@@ -129,8 +129,6 @@ enum pageflags {#endif __NR_PAGEFLAGS, - PG_readahead = PG_reclaim, -/* Anonymous memory (and shmem) */ PG_swapcache = PG_owner_priv_1, /* Swap page: swp_entry_t in private *//* Some filesystems */
@@ -168,7 +166,7 @@ enum pageflags { PG_xen_remapped = PG_owner_priv_1,/* non-lru isolated movable page */ - PG_isolated = PG_reclaim, + PG_isolated = PG_readahead,/* Only valid for buddy pages. Used to track pages that are reported */ PG_reported = PG_uptodate,
@@ -187,7 +185,7 @@ enum pageflags {/* At least one page in this folio has the hwpoison flag set */ PG_has_hwpoisoned = PG_active, PG_large_rmappable = PG_workingset,/* anon or file-backed */ - PG_partially_mapped = PG_reclaim, /* was identified to be partially mapped */ + PG_partially_mapped = PG_readahead, /* was identified to be partially mapped */ };#define PAGEFLAGS_MASK ((1UL << NR_PAGEFLAGS) - 1)
@@ -594,9 +592,6 @@ TESTPAGEFLAG(Writeback, writeback, PF_NO_TAIL) TESTSCFLAG(Writeback, writeback, PF_NO_TAIL) FOLIO_FLAG(mappedtodisk, FOLIO_HEAD_PAGE) -/* PG_readahead is only used for reads; PG_reclaim is only for writes */ -PAGEFLAG(Reclaim, reclaim, PF_NO_TAIL) - TESTCLEARFLAG(Reclaim, reclaim, PF_NO_TAIL) FOLIO_FLAG(readahead, FOLIO_HEAD_PAGE)FOLIO_TEST_CLEAR_FLAG (readahead,FOLIO_HEAD_PAGE )
include/trace/events/mmflags.h +1 -1
@@ -177,7 +177,7 @@ TRACE_DEFINE_ENUM(___GFP_LAST_BIT);DEF_PAGEFLAG_NAME (private_2), \DEF_PAGEFLAG_NAME (writeback), \DEF_PAGEFLAG_NAME (head), \ -DEF_PAGEFLAG_NAME (reclaim), \ +DEF_PAGEFLAG_NAME (readahead), \DEF_PAGEFLAG_NAME (swapbacked), \DEF_PAGEFLAG_NAME (unevictable), \DEF_PAGEFLAG_NAME (dropbehind) \
include/uapi/linux/kernel-page-flags.h +1 -1
@@ -15,7 +15,7 @@#define KPF_ACTIVE 6#define KPF_SLAB 7#define KPF_WRITEBACK 8 -#define KPF_RECLAIM 9 +#define KPF_READAHEAD 9#define KPF_BUDDY 10/* 11-20: new additions in 2.6.31 */
mm/filemap.c +0 -12
@@ -1625,18 +1625,6 @@ void folio_end_writeback(struct folio *folio)VM_BUG_ON_FOLIO (!folio_test_writeback (folio), folio); -/* -* folio_test_clear_reclaim() could be used here but it is an -* atomic operation and overkill in this particular case. Failing -* to shuffle a folio marked for immediate reclaim is too mild -* a gain to justify taking an atomic operation penalty at the -* end of every folio writeback. -*/ -if (folio_test_reclaim (folio)) { -folio_clear_reclaim (folio); -folio_rotate_reclaimable (folio); - } -/* * Writeback does not hold a folio reference of its own, relying * on truncation to wait for the clearing of PG_writeback.
mm/migrate.c +2 -8
@@ -690,6 +690,8 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio)folio_set_young (newfolio);if (folio_test_idle (folio))folio_set_idle (newfolio); +if (folio_test_readahead (folio)) +folio_set_readahead (newfolio);folio_migrate_refs (newfolio, folio);/*
@@ -732,14 +734,6 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio)if (folio_test_writeback (newfolio))folio_end_writeback (newfolio); -/* -* PG_readahead shares the same bit with PG_reclaim. The above -* end_page_writeback() may clear PG_readahead mistakenly, so set the -* bit after that. -*/ -if (folio_test_readahead (folio)) -folio_set_readahead (newfolio); -folio_copy_owner (newfolio, folio);pgalloc_tag_swap (newfolio, folio);
mm/page-writeback.c +1 -15
@@ -2888,22 +2888,8 @@ bool folio_mark_dirty(struct folio *folio) {struct address_space *mapping =folio_mapping (folio); -if (likely (mapping)) { -/* -* readahead/folio_deactivate could remain -* PG_readahead/PG_reclaim due to race with folio_end_writeback -* About readahead, if the folio is written, the flags would be -* reset. So no problem. -* About folio_deactivate, if the folio is redirtied, -* the flag will be reset. So no problem. but if the -* folio is used by readahead it will confuse readahead -* and make it restart the size rampup process. But it's -* a trivial problem. -*/ -if (folio_test_reclaim (folio)) -folio_clear_reclaim (folio); +if (likely (mapping))return mapping->a_ops->dirty_folio (mapping, folio); - }return noop_dirty_folio (mapping, folio); }
mm/page_io.c +5 -10
@@ -37,14 +37,11 @@ static void __end_swap_bio_write(struct bio *bio)* Re-dirty the page in order to avoid it being reclaimed. * Also print a dire warning that things will go BAD (tm) * very quickly. -* -* Also clear PG_reclaim to avoid folio_rotate_reclaimable() */ folio_mark_dirty (folio);pr_alert_ratelimited ("Write-error on swap-device (%u:%u:%llu)\n" ,MAJOR (bio_dev (bio)),MINOR (bio_dev (bio)), (unsigned long long )bio->bi_iter.bi_sector); -folio_clear_reclaim (folio); }folio_end_writeback (folio); }
@@ -350,19 +347,17 @@ static void sio_write_complete(struct kiocb *iocb, long ret)if (ret != sio->len) {/* -* In the case of swap-over-nfs, this can be a -* temporary failure if the system has limited -* memory for allocating transmit buffers. -* Mark the page dirty and avoid -* folio_rotate_reclaimable but rate-limit the -* messages. +* In the case of swap-over-nfs, this can be a temporary failure +* if the system has limited memory for allocating transmit +* buffers. +* +* Mark the page dirty but rate-limit the messages. */ pr_err_ratelimited ("Write error %ld on dio swapfile (%llu)\n" , ret,swap_dev_pos (page_swap_entry (page)));for (p =0 ; p < sio->pages; p++) { page = sio->bvec[p].bv_page;set_page_dirty (page); -ClearPageReclaim (page); } }
mm/swap.c +4 -57
108 lines not on this page · raw message
mm/vmscan.c +0 -7
@@ -3221,9 +3221,6 @@ static int folio_inc_gen(struct lruvec *lruvec, struct folio *folio, bool reclai new_flags = old_flags & ~(LRU_GEN_MASK |LRU_REFS_FLAGS ); new_flags |= (new_gen +1UL ) <<LRU_GEN_PGOFF ; -/* for folio_end_writeback() */ -if (reclaiming) - new_flags |=BIT (PG_reclaim); }while (!try_cmpxchg (&folio->flags, &old_flags, new_flags));lru_gen_update_size (lruvec, folio, old_gen, new_gen);
@@ -4465,9 +4462,6 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct scaif (!folio_test_referenced (folio))set_mask_bits (&folio->flags,LRU_REFS_MASK ,0 ); -/* for shrink_folio_list() */ -folio_clear_reclaim (folio); - success =lru_gen_del_folio (lruvec, folio, true);VM_WARN_ON_ONCE_FOLIO (!success, folio);
@@ -4664,7 +4658,6 @@ static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swapcontinue ; } -/* retry folios that may have missed folio_rotate_reclaimable() */ if (!skip_retry && !folio_test_active (folio) && !folio_mapped (folio) && !folio_test_dirty (folio) && !folio_test_writeback (folio)) {list_move (&folio->lru, &clean);
tools/mm/page-types.c +1 -7
@@ -85,7 +85,6 @@* not part of kernel API */ #define KPF_ANON_EXCLUSIVE 47 -#define KPF_READAHEAD 48#define KPF_SLUB_FROZEN 50#define KPF_SLUB_DEBUG 51#define KPF_FILE 61
@@ -108,7 +107,7 @@ static const char * const page_flag_names[] = { [KPF_ACTIVE] = "A:active", [KPF_SLAB] = "S:slab", [KPF_WRITEBACK] = "W:writeback", - [KPF_RECLAIM] = "I:reclaim", + [KPF_READAHEAD] = "I:readahead", [KPF_BUDDY] = "B:buddy", [KPF_MMAP] = "M:mmap",
@@ -139,7 +138,6 @@ static const char * const page_flag_names[] = { [KPF_ARCH_2] = "H:arch_2", [KPF_ANON_EXCLUSIVE] = "d:anon_exclusive", - [KPF_READAHEAD] = "I:readahead", [KPF_SLUB_FROZEN] = "A:slub_frozen", [KPF_SLUB_DEBUG] = "E:slub_debug",
@@ -484,10 +482,6 @@ static uint64_t expand_overloaded_flags(uint64_t flags, uint64_t pme) flags ^=BIT (ERROR ) |BIT (SLUB_DEBUG ); } -/* PG_reclaim is overloaded as PG_readahead in the read path */ -if ((flags & (BIT (RECLAIM ) |BIT (WRITEBACK ))) ==BIT (RECLAIM )) - flags ^=BIT (RECLAIM ) |BIT (READAHEAD ); -if (pme &PM_SOFT_DIRTY ) flags |=BIT (SOFTDIRTY );if (pme &PM_FILE )
Signature · 1 line
2.47.2
PATCH v3 10/11 mm/vmscan: Do not demote PG_dropbehind folios
In reply to Kirill A. ShutemovPG_dropbehind flag indicates that the folio need to be freed immediately. No point in demoting it.
--- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmscan.c +1 -1
@@ -1231,7 +1231,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,* Before reclaiming the folio, try to relocate * its contents to another node. */ -if (do_demote_pass && +if (do_demote_pass && !folio_test_dropbehind (folio) && (thp_migration_supported () || !folio_test_large (folio))) {list_add (&folio->lru, &demote_folios);folio_unlock (folio);
Signature · 1 line
2.47.2
PATCH v3 11/11 mm: Rename PG_dropbehind to PG_reclaim
In reply to Kirill A. ShutemovNow as PG_reclaim is gone, its name can be reclaimed for better use :)
Rename PG_dropbehind to PG_reclaim and rename all helpers around it.
--- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 2 +- include/linux/mm_inline.h | 2 +- include/linux/page-flags.h | 8 +++--- include/linux/pagemap.h | 2 +- include/trace/events/mmflags.h | 2 +- mm/filemap.c | 34 +++++++++++------------ mm/migrate.c | 4 +-- mm/readahead.c | 4 +-- mm/swap.c | 2 +- mm/truncate.c | 2 +- mm/vmscan.c | 22 +++++++-------- mm/zswap.c | 2 +- 12 files changed, 43 insertions(+), 43 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +1 -1
@@ -329,7 +329,7 @@ void __shmem_writeback(size_t size, struct address_space *mapping)if (!folio_mapped (folio) &&folio_clear_dirty_for_io (folio)) {int ret; -folio_set_dropbehind (folio); +folio_set_reclaim (folio); ret = mapping->a_ops->writepage (&folio->page, &wbc);if (!ret) goto put;
include/linux/mm_inline.h +1 -1
@@ -241,7 +241,7 @@ static inline unsigned long lru_gen_folio_seq(struct lruvec *lruvec, struct folielse if (reclaiming) gen =MAX_NR_GENS ;else if ((!folio_is_file_lru (folio) && !folio_test_swapcache (folio)) || -folio_test_dropbehind (folio)) +folio_test_reclaim (folio)) gen =MIN_NR_GENS ;else gen =MAX_NR_GENS -folio_test_workingset (folio);
include/linux/page-flags.h +4 -4
@@ -110,7 +110,7 @@ enum pageflags { PG_readahead, PG_swapbacked,/* Page is backed by RAM/swap */ PG_unevictable,/* Page is "unevictable" */ - PG_dropbehind,/* drop pages on IO completion */ + PG_reclaim,/* drop pages on IO completion */ #ifdef CONFIG_MMU PG_mlocked, /* Page is vma mlocked */ #endif
@@ -595,9 +595,9 @@ FOLIO_FLAG(mappedtodisk, FOLIO_HEAD_PAGE) FOLIO_FLAG(readahead, FOLIO_HEAD_PAGE) FOLIO_TEST_CLEAR_FLAG(readahead, FOLIO_HEAD_PAGE) -FOLIO_FLAG(dropbehind, FOLIO_HEAD_PAGE) - FOLIO_TEST_CLEAR_FLAG(dropbehind, FOLIO_HEAD_PAGE) - __FOLIO_SET_FLAG(dropbehind, FOLIO_HEAD_PAGE) +FOLIO_FLAG(reclaim, FOLIO_HEAD_PAGE) + FOLIO_TEST_CLEAR_FLAG(reclaim, FOLIO_HEAD_PAGE) + __FOLIO_SET_FLAG(reclaim, FOLIO_HEAD_PAGE)#ifdef CONFIG_HIGHMEM /*
include/linux/pagemap.h +1 -1
@@ -1360,7 +1360,7 @@ struct readahead_control {pgoff_t _index;unsigned int _nr_pages;unsigned int _batch_count; -bool dropbehind; +bool reclaim;bool _workingset;unsigned long _pflags; };
include/trace/events/mmflags.h +1 -1
@@ -180,7 +180,7 @@ TRACE_DEFINE_ENUM(___GFP_LAST_BIT);DEF_PAGEFLAG_NAME (readahead), \DEF_PAGEFLAG_NAME (swapbacked ), \ DEF_PAGEFLAG_NAME(unevictable), \ - DEF_PAGEFLAG_NAME(dropbehind) \ + DEF_PAGEFLAG_NAME(reclaim) \ IF_HAVE_PG_MLOCK(mlocked) \ IF_HAVE_PG_HWPOISON(hwpoison) \ IF_HAVE_PG_IDLE(idle) \
mm/filemap.c +17 -17
@@ -1591,11 +1591,11 @@ int folio_wait_private_2_killable(struct folio *folio)EXPORT_SYMBOL (folio_wait_private_2_killable);/* -* If folio was marked as dropbehind, then pages should be dropped when writeback +* If folio was marked as reclaim, then pages should be dropped when writeback * completes. Do that now. If we fail, it's likely because of a big folio - -* just reset dropbehind for that case and latter completions should invalidate. +* just reset reclaim for that case and latter completions should invalidate. */ -static void folio_end_dropbehind_write (struct folio *folio) +static void folio_end_reclaim_write (struct folio *folio) {/* * Hitting !in_task() should not happen off RWF_DONTCACHE writeback,
@@ -1621,7 +1621,7 @@ static void folio_end_dropbehind_write(struct folio *folio)*/ void folio_end_writeback (struct folio *folio) { -bool folio_dropbehind = false; +bool folio_reclaim = false;VM_BUG_ON_FOLIO (!folio_test_writeback (folio), folio);
@@ -1633,13 +1633,13 @@ void folio_end_writeback(struct folio *folio)*/ folio_get (folio);if (!folio_test_dirty (folio)) - folio_dropbehind =folio_test_clear_dropbehind (folio); + folio_reclaim =folio_test_clear_reclaim (folio);if (__folio_end_writeback (folio))folio_wake_bit (folio, PG_writeback);acct_reclaim_writeback (folio); -if (folio_dropbehind) -folio_end_dropbehind_write (folio); +if (folio_reclaim) +folio_end_reclaim_write (folio);folio_put (folio); }EXPORT_SYMBOL (folio_end_writeback);
@@ -1963,7 +1963,7 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,if (fgp_flags &FGP_ACCESSED )__folio_set_referenced (folio);if (fgp_flags &FGP_DONTCACHE ) -__folio_set_dropbehind (folio); +__folio_set_reclaim (folio); err =filemap_add_folio (mapping, folio, index, gfp);if (!err)
@@ -1987,8 +1987,8 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,if (!folio)return ERR_PTR (-ENOENT );/* not an uncached lookup, clear uncached if set */ -if (folio_test_dropbehind (folio) && !(fgp_flags &FGP_DONTCACHE )) -folio_clear_dropbehind (folio); +if (folio_test_reclaim (folio) && !(fgp_flags &FGP_DONTCACHE )) +folio_clear_reclaim (folio);return folio; }EXPORT_SYMBOL (__filemap_get_folio);
@@ -2486,7 +2486,7 @@ static int filemap_create_folio(struct kiocb *iocb, struct folio_batch *fbatch)if (!folio)return -ENOMEM ;if (iocb->ki_flags &IOCB_DONTCACHE ) -__folio_set_dropbehind (folio); +__folio_set_reclaim (folio);/* * Protect against truncate / hole punch. Grabbing invalidate_lock
@@ -2533,7 +2533,7 @@ static int filemap_readahead(struct kiocb *iocb, struct file *file,if (iocb->ki_flags &IOCB_NOIO )return -EAGAIN ;if (iocb->ki_flags &IOCB_DONTCACHE ) - ractl.dropbehind =1 ; + ractl.reclaim =1 ;page_cache_async_ra (&ractl, folio, last_index - folio->index);return 0 ; }
@@ -2564,7 +2564,7 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count,if (iocb->ki_flags &IOCB_NOWAIT ) flags =memalloc_noio_save ();if (iocb->ki_flags &IOCB_DONTCACHE ) - ractl.dropbehind =1 ; + ractl.reclaim =1 ;page_cache_sync_ra (&ractl, last_index - index);if (iocb->ki_flags &IOCB_NOWAIT )memalloc_noio_restore (flags);
@@ -2612,15 +2612,15 @@ static inline bool pos_same_folio(loff_t pos1, loff_t pos2, struct folio *folio)return (pos1 >> shift == pos2 >> shift); } -static void filemap_end_dropbehind_read (struct address_space *mapping, +static void filemap_end_reclaim_read (struct address_space *mapping,struct folio *folio) { -if (!folio_test_dropbehind (folio)) +if (!folio_test_reclaim (folio))return ;if (folio_test_writeback (folio) ||folio_test_dirty (folio))return ;if (folio_trylock (folio)) { -if (folio_test_clear_dropbehind (folio)) +if (folio_test_clear_reclaim (folio))folio_unmap_invalidate (mapping, folio,0 );folio_unlock (folio); }
@@ -2742,7 +2742,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,for (i =0 ; i <folio_batch_count (&fbatch); i++) {struct folio *folio = fbatch.folios[i]; -filemap_end_dropbehind_read (mapping, folio); +filemap_end_reclaim_read (mapping, folio);folio_put (folio); }folio_batch_init (&fbatch);
mm/migrate.c +2 -2
@@ -683,8 +683,8 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio)folio_set_dirty (newfolio);/* TODO: free the folio on migration? */ -if (folio_test_dropbehind (folio)) -folio_set_dropbehind (newfolio); +if (folio_test_reclaim (folio)) +folio_set_reclaim (newfolio);if (folio_test_young (folio))folio_set_young (newfolio);
mm/readahead.c +2 -2
@@ -185,8 +185,8 @@ static struct folio *ractl_alloc_folio(struct readahead_control *ractl,struct folio *folio; folio =filemap_alloc_folio (gfp_mask, order); -if (folio && ractl->dropbehind) -__folio_set_dropbehind (folio); +if (folio && ractl->reclaim) +__folio_set_reclaim (folio);return folio; }
mm/swap.c +1 -1
@@ -406,7 +406,7 @@ static bool lru_gen_clear_refs(struct folio *folio)*/ void folio_mark_accessed (struct folio *folio) { -if (folio_test_dropbehind (folio)) +if (folio_test_reclaim (folio))return ;if (lru_gen_enabled ()) {lru_gen_inc_refs (folio);
mm/truncate.c +1 -1
@@ -488,7 +488,7 @@ unsigned long mapping_try_invalidate(struct address_space *mapping,if (!ret) {if (!folio_test_unevictable (folio) && !folio_mapped (folio)) -folio_set_dropbehind (folio); +folio_set_reclaim (folio);/* Likely in the lru cache of a remote CPU */ if (nr_failed)
mm/vmscan.c +11 -11
@@ -692,13 +692,13 @@ static pageout_t pageout(struct folio *folio, struct address_space *mapping,if (shmem_mapping (mapping) &&folio_test_large (folio)) wbc.list = folio_list; -folio_set_dropbehind (folio); +folio_set_reclaim (folio); res = mapping->a_ops->writepage (&folio->page, &wbc);if (res <0 )handle_write_error (mapping, folio, res);if (res ==AOP_WRITEPAGE_ACTIVATE ) { -folio_clear_dropbehind (folio); +folio_clear_reclaim (folio);return PAGE_ACTIVATE ; }
@@ -1140,7 +1140,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,* for immediate reclaim are making it to the end of * the LRU a second time. */ -if (writeback &&folio_test_dropbehind (folio)) +if (writeback &&folio_test_reclaim (folio)) stat->nr_congested += nr_pages;/*
@@ -1149,7 +1149,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,* * 1) If reclaim is encountering an excessive number * of folios under writeback and this folio has both -* the writeback and dropbehind flags set, then it +* the writeback and reclaim flags set, then it * indicates that folios are being queued for I/O but * are being recycled through the LRU before the I/O * can complete. Waiting on the folio itself risks an
@@ -1173,7 +1173,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,* would probably show more reasons. * * 3) Legacy memcg encounters a folio that already has the -* dropbehind flag set. memcg does not have any dirty folio +* reclaim flag set. memcg does not have any dirty folio * throttling so we could easily OOM just because too many * folios are in writeback and there is nothing else to * reclaim. Wait for the writeback to complete.
@@ -1190,16 +1190,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,if (folio_test_writeback (folio)) {/* Case 1 above */ if (current_is_kswapd () && -folio_test_dropbehind (folio) && +folio_test_reclaim (folio) &&test_bit (PGDAT_WRITEBACK , &pgdat->flags)) { stat->nr_immediate += nr_pages; goto activate_locked;/* Case 2 above */ }else if (writeback_throttling_sane (sc) || - !folio_test_dropbehind (folio) || + !folio_test_reclaim (folio) || !may_enter_fs (folio, sc->gfp_mask)) { -folio_set_dropbehind (folio); +folio_set_reclaim (folio); stat->nr_writeback += nr_pages; goto activate_locked;
@@ -1231,7 +1231,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,* Before reclaiming the folio, try to relocate * its contents to another node. */ -if (do_demote_pass && !folio_test_dropbehind (folio) && +if (do_demote_pass && !folio_test_reclaim (folio) && (thp_migration_supported () || !folio_test_large (folio))) {list_add (&folio->lru, &demote_folios);folio_unlock (folio);
@@ -1354,7 +1354,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,*/ if (folio_is_file_lru (folio) && (!current_is_kswapd () || - !folio_test_dropbehind (folio) || + !folio_test_reclaim (folio) || !test_bit (PGDAT_DIRTY , &pgdat->flags))) {/* * Immediately reclaim when written back.
@@ -1364,7 +1364,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,*/ node_stat_mod_folio (folio,NR_VMSCAN_IMMEDIATE , nr_pages); -folio_set_dropbehind (folio); +folio_set_reclaim (folio); goto activate_locked; }
mm/zswap.c +1 -1
@@ -1103,7 +1103,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry,folio_mark_uptodate (folio);/* free the folio after writeback */ -folio_set_dropbehind (folio); +folio_set_reclaim (folio);/* start writeback */ __swap_writepage (folio, &wbc);
Signature · 1 line
2.47.2
Re: [PATCHv3 11/11] mm: Rename PG_dropbehind to PG_reclaim
Quoted 7 lines · Kirill A. Shutemov
Now as
PG_reclaimis gone, its name can be reclaimed for better use :)Rename
PG_dropbehindtoPG_reclaimand rename all helpers around it.Signed-off-by Kirill A. Shutemov <[email protected]>