On Sat, Feb 01, 2025 at 04:01:43PM +0800, Kairui Song wrote: > On Thu, Jan 30, 2025 at 6:02 PM Kirill A. Shutemov > <kirill.shutemov@xxxxxxxxxxxxxxx> wrote: > > > > The 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. > > > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> > > Acked-by: David Hildenbrand <david@xxxxxxxxxx> > > --- > > mm/vmscan.c | 9 +++------ > > 1 file changed, 3 insertions(+), 6 deletions(-) > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > index bc1826020159..c97adb0fdaa4 100644 > > --- a/mm/vmscan.c > > +++ b/mm/vmscan.c > > @@ -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; > > -- > > 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 Ouch. I failed to trigger it my setup. Could you share your reproducer? > 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: Right. I don't understand swapping good enough. I missed this. > diff --git a/mm/filemap.c b/mm/filemap.c > index 4fe551037bf7..98493443d120 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -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); > } > } 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. -- Kiryl Shutsemau / Kirill A. Shutemov