Skip to content

mm: drop folios under writeback on POSIX_FADV_DONTNEED

Usama Arif linux-fsdevel linux-mm linux-rt-devel lkml stable 1 version Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 18 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/4mm/migrate: preserve PG_dropbehind across folio migrationmm/migrate.c+3 -05 replies
2/4mm/filemap: clear PG_dropbehind on lookup under the folio lockmm/filemap.c+19 -63 replies
3/4mm/filemap: don't drop dropbehind folios with interrupts disabledmm/filemap.c+3 -24 replies
4/4mm/fadvise: drop folios under writeback on POSIX_FADV_DONTNEEDmm/fadvise.c mm/internal.h mm/page-writeback.c+79 -55 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchJan KaraJeff LaytonZi YanDavid Hildenbrand (Arm)
1/4R-b R-b R-b R-b
2/4R-b R-b
3/4R-b R-b
4/4R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v1 thread

Cover letter [PATCH 0/4] mm: drop folios under writeback on POSIX_FADV_DONTNEED

POSIX_FADV_DONTNEED starts writeback on the dirty folios in the range without waiting for it, then invalidates what it can and skips folios under writeback. With small folios most bios complete while DONTNEED is still invalidating. With large folios on XFS a single bio can carry hundreds of megabytes, none of which leaves writeback until all of it completes, so DONTNEED right after writing a new 256 MiB file leaves all of it cached.

This is affecting production workloads after a kernel upgrade that started using large folios on XFS: an application that writes files through a shared mapping, unmaps them and calls DONTNEED without syncing now fills its memory limit with page cache that DONTNEED used to drop.

Patch 4 marks the unmapped dirty folios in the range dropbehind before starting writeback, and the unmapped folios still under writeback after it, so that writeback completion drops them as it does for RWF_DONTCACHE writes. Only regular files on filesystems that support RWF_DONTCACHE are marked, and not the folio extending past EOF, which an appender calling DONTNEED after each write would have to read back.

Patches 1-3 fix dropbehind bugs that patch 4 makes easier to hit:

1. Migration does not copy PG_dropbehind, so WB_DONTCACHE_DIRTY leaks.
2. Lookups clear PG_dropbehind without the folio lock, racing with dirtying and cleaning, so WB_DONTCACHE_DIRTY drifts.
3. folio_end_dropbehind() can invalidate with interrupts disabled in a forced-threaded handler, as ext4 RWF_DONTCACHE overwrites did with threadirqs from v6.17 until commit 7d7c9c83c822.

Patches 1-3 are stable candidates.

With the series, new files and overwrites on XFS and ext4 were dropped within a second of DONTNEED apart from the folio at EOF; without the series most of them stayed cached.

Alternatives considered:
- fdatasync() before DONTNEED works, but blocks the caller and needs every application changed.
- Restoring the PG_reclaim that DONTNEED set on these folios until commit 5c211ba29deb ("mm: add and use find_lock_entries") only moves them to the tail of the inactive list, still cached and charged.
- Calling bio_complete_in_task() for every bio with a dropbehind folio would also catch folios marked after submission, but needs a pass over every write bio's folios before completing it.

Limitations:
- Folios already under writeback that complete in interrupt context stay cached.

base-commit: 872ceec1e3caf227655a58f7407a9c8493dcf56f

Usama Arif (4):
mm/migrate: preserve PG_dropbehind across folio migration mm/filemap: clear PG_dropbehind on lookup under the folio lock mm/filemap: don't drop dropbehind folios with interrupts disabled mm/fadvise: drop folios under writeback on POSIX_FADV_DONTNEED

 mm/fadvise.c        | 60 +++++++++++++++++++++++++++++++++++++++++----
 mm/filemap.c        | 30 +++++++++++++++++------
 mm/internal.h       |  1 +
 mm/migrate.c        |  3 +++
 mm/page-writeback.c | 23 +++++++++++++++++
 5 files changed, 104 insertions(+), 13 deletions(-)
Signature · 1 line
2.53.1-Meta