[PATCH 04/11] mm: add PG_dropbehind folio flag

Jens Axboe posted 11 patches 1 year, 1 month ago
There is a newer version of this series
[PATCH 04/11] mm: add PG_dropbehind folio flag
Posted by Jens Axboe 1 year, 1 month ago
Add a folio flag that file IO can use to indicate that the cached IO
being done should be dropped from the page cache upon completion.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 include/linux/page-flags.h     | 5 +++++
 include/trace/events/mmflags.h | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index cf46ac720802..16607f02abd0 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -110,6 +110,7 @@ enum pageflags {
 	PG_reclaim,		/* To be reclaimed asap */
 	PG_swapbacked,		/* Page is backed by RAM/swap */
 	PG_unevictable,		/* Page is "unevictable"  */
+	PG_dropbehind,		/* drop pages on IO completion */
 #ifdef CONFIG_MMU
 	PG_mlocked,		/* Page is vma mlocked */
 #endif
@@ -562,6 +563,10 @@ PAGEFLAG(Reclaim, reclaim, PF_NO_TAIL)
 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)
+
 #ifdef CONFIG_HIGHMEM
 /*
  * Must use a macro here due to header dependency issues. page_zone() is not
diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h
index bb8a59c6caa2..3bc8656c8359 100644
--- a/include/trace/events/mmflags.h
+++ b/include/trace/events/mmflags.h
@@ -116,7 +116,8 @@
 	DEF_PAGEFLAG_NAME(head),					\
 	DEF_PAGEFLAG_NAME(reclaim),					\
 	DEF_PAGEFLAG_NAME(swapbacked),					\
-	DEF_PAGEFLAG_NAME(unevictable)					\
+	DEF_PAGEFLAG_NAME(unevictable),					\
+	DEF_PAGEFLAG_NAME(dropbehind)					\
 IF_HAVE_PG_MLOCK(mlocked)						\
 IF_HAVE_PG_HWPOISON(hwpoison)						\
 IF_HAVE_PG_IDLE(idle)							\
-- 
2.45.2
Re: [PATCH 04/11] mm: add PG_dropbehind folio flag
Posted by Kirill A. Shutemov 1 year, 1 month ago
On Fri, Dec 13, 2024 at 08:55:18AM -0700, Jens Axboe wrote:
> Add a folio flag that file IO can use to indicate that the cached IO
> being done should be dropped from the page cache upon completion.
> 
> Signed-off-by: Jens Axboe <axboe@kernel.dk>

Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

+ David, Vlastimil.

I think we should consider converting existing folio_set_reclaim() /
SetPageReclaim() users to the new flag. From a quick scan, all of them
would benefit from dropping the page after writeback is complete instead
of leaving the folio on the LRU.

-- 
  Kiryl Shutsemau / Kirill A. Shutemov
Re: [PATCH 04/11] mm: add PG_dropbehind folio flag
Posted by David Hildenbrand 1 year, 1 month ago
On 20.12.24 12:08, Kirill A. Shutemov wrote:
> On Fri, Dec 13, 2024 at 08:55:18AM -0700, Jens Axboe wrote:
>> Add a folio flag that file IO can use to indicate that the cached IO
>> being done should be dropped from the page cache upon completion.
>>
>> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> 
> Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> 
> + David, Vlastimil.
> 
> I think we should consider converting existing folio_set_reclaim() /
> SetPageReclaim() users to the new flag. From a quick scan, all of them
> would benefit from dropping the page after writeback is complete instead
> of leaving the folio on the LRU.

I wonder of there are some use cases where we write a lot of data to 
then only consume it read-only from that point on (databases? fancy AI 
stuff? no idea :) ).

-- 
Cheers,

David / dhildenb
Re: [PATCH 04/11] mm: add PG_dropbehind folio flag
Posted by Kirill A. Shutemov 1 year, 1 month ago
On Fri, Dec 20, 2024 at 04:03:44PM +0100, David Hildenbrand wrote:
> On 20.12.24 12:08, Kirill A. Shutemov wrote:
> > On Fri, Dec 13, 2024 at 08:55:18AM -0700, Jens Axboe wrote:
> > > Add a folio flag that file IO can use to indicate that the cached IO
> > > being done should be dropped from the page cache upon completion.
> > > 
> > > Signed-off-by: Jens Axboe <axboe@kernel.dk>
> > 
> > Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > 
> > + David, Vlastimil.
> > 
> > I think we should consider converting existing folio_set_reclaim() /
> > SetPageReclaim() users to the new flag. From a quick scan, all of them
> > would benefit from dropping the page after writeback is complete instead
> > of leaving the folio on the LRU.
> 
> I wonder of there are some use cases where we write a lot of data to then
> only consume it read-only from that point on (databases? fancy AI stuff? no
> idea :) ).

Do we use PG_reclaim for such cases?

-- 
  Kiryl Shutsemau / Kirill A. Shutemov
Re: [PATCH 04/11] mm: add PG_dropbehind folio flag
Posted by David Hildenbrand 1 year, 1 month ago
On 20.12.24 16:12, Kirill A. Shutemov wrote:
> On Fri, Dec 20, 2024 at 04:03:44PM +0100, David Hildenbrand wrote:
>> On 20.12.24 12:08, Kirill A. Shutemov wrote:
>>> On Fri, Dec 13, 2024 at 08:55:18AM -0700, Jens Axboe wrote:
>>>> Add a folio flag that file IO can use to indicate that the cached IO
>>>> being done should be dropped from the page cache upon completion.
>>>>
>>>> Signed-off-by: Jens Axboe <axboe@kernel.dk>
>>>
>>> Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
>>>
>>> + David, Vlastimil.
>>>
>>> I think we should consider converting existing folio_set_reclaim() /
>>> SetPageReclaim() users to the new flag. From a quick scan, all of them
>>> would benefit from dropping the page after writeback is complete instead
>>> of leaving the folio on the LRU.
>>
>> I wonder of there are some use cases where we write a lot of data to then
>> only consume it read-only from that point on (databases? fancy AI stuff? no
>> idea :) ).
> 
> Do we use PG_reclaim for such cases?

Good point, I looked at the pageout() case, but there we really want to 
pageout that thing and not just write it back, so makes sense to me.

-- 
Cheers,

David / dhildenb
Re: [PATCH 04/11] mm: add PG_dropbehind folio flag
Posted by Matthew Wilcox 1 year, 1 month ago
On Fri, Dec 20, 2024 at 01:08:39PM +0200, Kirill A. Shutemov wrote:
> On Fri, Dec 13, 2024 at 08:55:18AM -0700, Jens Axboe wrote:
> > Add a folio flag that file IO can use to indicate that the cached IO
> > being done should be dropped from the page cache upon completion.
> > 
> > Signed-off-by: Jens Axboe <axboe@kernel.dk>
> 
> Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> 
> + David, Vlastimil.
> 
> I think we should consider converting existing folio_set_reclaim() /
> SetPageReclaim() users to the new flag. From a quick scan, all of them
> would benefit from dropping the page after writeback is complete instead
> of leaving the folio on the LRU.

Ooh, that would be nice.  Removes the overloading of PG_reclaim with
PG_readahead, right?
Re: [PATCH 04/11] mm: add PG_dropbehind folio flag
Posted by Kirill A. Shutemov 1 year, 1 month ago
On Fri, Dec 20, 2024 at 02:38:09PM +0000, Matthew Wilcox wrote:
> On Fri, Dec 20, 2024 at 01:08:39PM +0200, Kirill A. Shutemov wrote:
> > On Fri, Dec 13, 2024 at 08:55:18AM -0700, Jens Axboe wrote:
> > > Add a folio flag that file IO can use to indicate that the cached IO
> > > being done should be dropped from the page cache upon completion.
> > > 
> > > Signed-off-by: Jens Axboe <axboe@kernel.dk>
> > 
> > Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > 
> > + David, Vlastimil.
> > 
> > I think we should consider converting existing folio_set_reclaim() /
> > SetPageReclaim() users to the new flag. From a quick scan, all of them
> > would benefit from dropping the page after writeback is complete instead
> > of leaving the folio on the LRU.
> 
> Ooh, that would be nice.  Removes the overloading of PG_reclaim with
> PG_readahead, right?

Yep.

-- 
  Kiryl Shutsemau / Kirill A. Shutemov
Re: [PATCH 04/11] mm: add PG_dropbehind folio flag
Posted by Matthew Wilcox 1 year, 1 month ago
On Fri, Dec 20, 2024 at 05:11:52PM +0200, Kirill A. Shutemov wrote:
> On Fri, Dec 20, 2024 at 02:38:09PM +0000, Matthew Wilcox wrote:
> > On Fri, Dec 20, 2024 at 01:08:39PM +0200, Kirill A. Shutemov wrote:
> > > On Fri, Dec 13, 2024 at 08:55:18AM -0700, Jens Axboe wrote:
> > > > Add a folio flag that file IO can use to indicate that the cached IO
> > > > being done should be dropped from the page cache upon completion.
> > > > 
> > > > Signed-off-by: Jens Axboe <axboe@kernel.dk>
> > > 
> > > Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > > 
> > > + David, Vlastimil.
> > > 
> > > I think we should consider converting existing folio_set_reclaim() /
> > > SetPageReclaim() users to the new flag. From a quick scan, all of them
> > > would benefit from dropping the page after writeback is complete instead
> > > of leaving the folio on the LRU.
> > 
> > Ooh, that would be nice.  Removes the overloading of PG_reclaim with
> > PG_readahead, right?
> 
> Yep.

Then ... maybe this series should just coopt the PG_reclaim flag for its
purposes?

Going through the users:

lru_deactivate_file()
---------------------

Called due to mapping_try_invalidate() failing to invalidate.
Absolutely, get rid of this folio as quickly as possible.

pageout()
---------

Again, we're trying to get rid of this folio.  This time due to memory
pressure / reaching the end of the LRU list.  Yup, we want it gone.

shrink_folio_list()
-------------------

Again, end of the LRU (both cases in this function)

zswap_writeback_entry()
-----------------------

This is exactly the same case that Jens is adding.  The swapcache is
being used as a staging location, and we want the folio gone as soon as
writeback completes.