Skip to content

Commit d94d23f

Browse files
axboeakpm00
authored andcommitted
mm: add FGP_DONTCACHE folio creation flag
Callers can pass this in for uncached folio creation, in which case if a folio is newly created it gets marked as uncached. If a folio exists for this index and lookup succeeds, then it will not get marked as uncached. If an !uncached lookup finds a cached folio, clear the flag. For that case, there are competeting uncached and cached users of the folio, and it should not get pruned. Link: https://lkml.kernel.org/r/20241220154831.1086649-13-axboe@kernel.dk Signed-off-by: Jens Axboe <axboe@kernel.dk> Cc: Brian Foster <bfoster@redhat.com> Cc: Chris Mason <clm@meta.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 1d44575 commit d94d23f

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

include/linux/pagemap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping,
710710
* * %FGP_NOFS - __GFP_FS will get cleared in gfp.
711711
* * %FGP_NOWAIT - Don't block on the folio lock.
712712
* * %FGP_STABLE - Wait for the folio to be stable (finished writeback)
713+
* * %FGP_DONTCACHE - Uncached buffered IO
713714
* * %FGP_WRITEBEGIN - The flags to use in a filesystem write_begin()
714715
* implementation.
715716
*/
@@ -723,6 +724,7 @@ typedef unsigned int __bitwise fgf_t;
723724
#define FGP_NOWAIT ((__force fgf_t)0x00000020)
724725
#define FGP_FOR_MMAP ((__force fgf_t)0x00000040)
725726
#define FGP_STABLE ((__force fgf_t)0x00000080)
727+
#define FGP_DONTCACHE ((__force fgf_t)0x00000100)
726728
#define FGF_GET_ORDER(fgf) (((__force unsigned)fgf) >> 26) /* top 6 bits */
727729

728730
#define FGP_WRITEBEGIN (FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE)

mm/filemap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,8 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
19731973
/* Init accessed so avoid atomic mark_page_accessed later */
19741974
if (fgp_flags & FGP_ACCESSED)
19751975
__folio_set_referenced(folio);
1976+
if (fgp_flags & FGP_DONTCACHE)
1977+
__folio_set_dropbehind(folio);
19761978

19771979
err = filemap_add_folio(mapping, folio, index, gfp);
19781980
if (!err)
@@ -1995,6 +1997,9 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
19951997

19961998
if (!folio)
19971999
return ERR_PTR(-ENOENT);
2000+
/* not an uncached lookup, clear uncached if set */
2001+
if (folio_test_dropbehind(folio) && !(fgp_flags & FGP_DONTCACHE))
2002+
folio_clear_dropbehind(folio);
19982003
return folio;
19992004
}
20002005
EXPORT_SYMBOL(__filemap_get_folio);

0 commit comments

Comments
 (0)