mm: Remove PG_reclaim
Subsystems (14)
cover mm: Remove PG_reclaim
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.
Kirill A. Shutemov (8):
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/swap: Use PG_dropbehind instead of PG_reclaim 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_dropcache instead of PG_reclaim in
lru_gen_folio_seq()
mm: Remove 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 | 4 +- 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 | 24 +----------- mm/vmscan.c | 46 ++++++----------------- mm/zswap.c | 4 +- tools/mm/page-types.c | 8 +--- 15 files changed, 41 insertions(+), 139 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/8 drm/i915/gem: Convert __shmem_writeback() to folios
Use 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.45.2
Re: [PATCH 1/8] drm/i915/gem: Convert __shmem_writeback() to folios
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]>---
Signature · 3 lines
Cheers, David / dhildenb
PATCH 2/8 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.45.2
Re: [PATCH 2/8] drm/i915/gem: 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()in__shmem_writeback()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.
I think this is correct
Signature · 3 lines
Cheers, David / dhildenb
PATCH 3/8 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
@@ -1096,8 +1096,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.45.2
Re: [PATCH 3/8] mm/zswap: Use PG_dropbehind instead of PG_reclaim
Quoted 17 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()inzswap_writeback_entry().Signed-off-by Kirill A. Shutemov <[email protected]>--- mm/zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/zswap.c +0
-0
mm/zswap.c static int zswap_writeback_entry(struct zswap_entry *entry, · line 1100
Quoted 7 lines
mm/zswap.c +2
-2@@ -1096,8 +1096,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);
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 3/8] mm/zswap: Use PG_dropbehind instead of PG_reclaim
In reply to Kirill A. ShutemovQuoted 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.Instead of using
folio_set_reclaim(), usefolio_set_dropbehind()inzswap_writeback_entry().Signed-off-by Kirill A. Shutemov <[email protected]>
Quoted 22 lines
--- mm/zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/zswap.c +2
-3@@ -1096,8 +1096,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); --2.45.2
PATCH 4/8 mm/swap: 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 lru_deactivate_file().
--- mm/swap.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
mm/swap.c +1 -7
@@ -562,14 +562,8 @@ static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio)folio_clear_referenced (folio);if (folio_test_writeback (folio) ||folio_test_dirty (folio)) { -/* -* Setting the reclaim flag could race with -* folio_end_writeback() and confuse readahead. But the -* race window is _really_ small and it's not a critical -* problem. -*/ lruvec_add_folio (lruvec, folio); -folio_set_reclaim (folio); +folio_set_dropbehind (folio); }else {/* * The folio's writeback ended while it was in the batch.
Signature · 1 line
2.45.2
Re: [PATCH 4/8] mm/swap: Use PG_dropbehind instead of PG_reclaim
Quoted 22 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()inlru_deactivate_file().Signed-off-by Kirill A. Shutemov <[email protected]>--- mm/swap.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)mm/swap.c +0
-2@@ -562,14 +562,8 @@ static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio)folio_clear_referenced (folio);if (folio_test_writeback (folio) ||folio_test_dirty (folio)) { -/* -* Setting the reclaim flag could race with
mm/swap.c static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio) · line 569
Quoted 10 lines
mm/swap.c +1
-5-* folio_end_writeback() and confuse readahead. But the -* race window is _really_ small and it's not a critical -* problem. -*/ lruvec_add_folio (lruvec, folio); -folio_set_reclaim (folio); +folio_set_dropbehind (folio); }else {/* * The folio's writeback ended while it was in the batch.
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 4/8] mm/swap: Use PG_dropbehind instead of PG_reclaim
In reply to Kirill A. ShutemovQuoted 23 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()inlru_deactivate_file().Signed-off-by Kirill A. Shutemov <[email protected]>--- mm/swap.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)mm/swap.c +0
-2@@ -562,14 +562,8 @@ static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio)folio_clear_referenced (folio);if (folio_test_writeback (folio) ||folio_test_dirty (folio)) { -/* -* Setting the reclaim flag could race with
mm/swap.c static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio) · line 569
Quoted 10 lines
mm/swap.c +1
-5-* folio_end_writeback() and confuse readahead. But the -* race window is _really_ small and it's not a critical -* problem. -*/ lruvec_add_folio (lruvec, folio); -folio_set_reclaim (folio); +folio_set_dropbehind (folio); }else {/* * The folio's writeback ended while it was in the batch.
Now there's a difference in behavior here depending on whether or not the folio is under writeback (or will be written back soon). If it is, we set PG_dropbehind to get it freed right after, but if writeback has already ended we put it on the tail of the LRU to be freed later.
It's a bit counterintuitive to me that folios with pending writeback get freed faster than folios that completed their writeback already. Am I missing something?
Re: [PATCH 4/8] mm/swap: Use PG_dropbehind instead of PG_reclaim
Quoted 41 lines · Yosry Ahmed
Quoted 23 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()inlru_deactivate_file().Signed-off-by Kirill A. Shutemov <[email protected]>--- mm/swap.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)mm/swap.c +0
-2@@ -562,14 +562,8 @@ static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio)folio_clear_referenced (folio);if (folio_test_writeback (folio) ||folio_test_dirty (folio)) { -/* -* Setting the reclaim flag could race with mm/swap.c static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio) · line 569
Quoted 10 lines
mm/swap.c +1
-5-* folio_end_writeback() and confuse readahead. But the -* race window is _really_ small and it's not a critical -* problem. -*/ lruvec_add_folio (lruvec, folio); -folio_set_reclaim (folio); +folio_set_dropbehind (folio); }else {/* * The folio's writeback ended while it was in the batch. Now there's a difference in behavior here depending on whether or not the folio is under writeback (or will be written back soon). If it is, we set
PG_dropbehindto get it freed right after, but if writeback has already ended we put it on the tail of the LRU to be freed later.
Quoted 3 lines
It's a bit counterintuitive to me that folios with pending writeback get freed faster than folios that completed their writeback already. Am I missing something?
Yeah, it is strange.
I think we can drop the writeback/dirty check. Set PG_dropbehind and put the page on the tail of LRU unconditionally. The check was required to avoid confusion with PG_readahead.
Comment above the function is not valid anymore.
But the folio that is still dirty under writeback will be freed faster as we get rid of the folio just after writeback is done while clean page can dangle on LRU for a while.
I don't think we have any convenient place to free clean dropbehind page other than shrink_folio_list(). Or do we?
Looking at shrink_folio_list(), I think we need to bypass page demotion for PG_dropbehind pages.
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov
Re: [PATCH 4/8] mm/swap: Use PG_dropbehind instead of PG_reclaim
Quoted 47 lines · Kirill A. Shutemov
Quoted 41 lines · Yosry Ahmed
Quoted 23 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()inlru_deactivate_file().Signed-off-by Kirill A. Shutemov <[email protected]>--- mm/swap.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)mm/swap.c +0
-2@@ -562,14 +562,8 @@ static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio)folio_clear_referenced (folio);if (folio_test_writeback (folio) ||folio_test_dirty (folio)) { -/* -* Setting the reclaim flag could race with mm/swap.c static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio) · line 569
Quoted 10 lines
mm/swap.c +1
-5-* folio_end_writeback() and confuse readahead. But the -* race window is _really_ small and it's not a critical -* problem. -*/ lruvec_add_folio (lruvec, folio); -folio_set_reclaim (folio); +folio_set_dropbehind (folio); }else {/* * The folio's writeback ended while it was in the batch. Now there's a difference in behavior here depending on whether or not the folio is under writeback (or will be written back soon). If it is, we set
PG_dropbehindto get it freed right after, but if writeback has already ended we put it on the tail of the LRU to be freed later.Quoted 3 lines
It's a bit counterintuitive to me that folios with pending writeback get freed faster than folios that completed their writeback already. Am I missing something?
Quoted 7 lines
Yeah, it is strange.
I think we can drop the writeback/dirty check. Set
PG_dropbehindand put the page on the tail of LRU unconditionally. The check was required to avoid confusion withPG_readahead.Comment above the function is not valid anymore.
My read is that we don't put dirty/writeback folios at the tail of the LRU because they cannot be freed immediately and we want to give them time to be written back before reclaim reaches them. So I don't think we want to change that and always put the pages at the tail.
Quoted 4 lines
But the folio that is still dirty under writeback will be freed faster as we get rid of the folio just after writeback is done while clean page can dangle on LRU for a while.
Yeah if we reuse PG_dropbehind then we cannot avoid folio_end_writeback() freeing the folio faster than clean ones.
Quoted 3 lines
I don't think we have any convenient place to free clean dropbehind page other than
shrink_folio_list(). Or do we?
Not sure tbh. FWIW I am not saying it's necessarily a bad thing to free dirty/writeback folios before clean ones when deactivated, it's just strange and a behavioral change from today that I wanted to point out. Perhaps that's the best we can do for now.
Quoted 6 lines
Looking at
shrink_folio_list(), I think we need to bypass page demotion forPG_dropbehindpages.--
Kiryl Shutsemau / Kirill A. Shutemov
Re: [PATCH 4/8] mm/swap: Use PG_dropbehind instead of PG_reclaim
Quoted 72 lines · Yosry Ahmed
Quoted 47 lines · Kirill A. Shutemov
Quoted 41 lines · Yosry Ahmed
Quoted 23 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()inlru_deactivate_file().Signed-off-by Kirill A. Shutemov <[email protected]>--- mm/swap.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)mm/swap.c +0
-2@@ -562,14 +562,8 @@ static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio)folio_clear_referenced (folio);if (folio_test_writeback (folio) ||folio_test_dirty (folio)) { -/* -* Setting the reclaim flag could race with mm/swap.c static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio) · line 569
Quoted 10 lines
mm/swap.c +1
-5-* folio_end_writeback() and confuse readahead. But the -* race window is _really_ small and it's not a critical -* problem. -*/ lruvec_add_folio (lruvec, folio); -folio_set_reclaim (folio); +folio_set_dropbehind (folio); }else {/* * The folio's writeback ended while it was in the batch. Now there's a difference in behavior here depending on whether or not the folio is under writeback (or will be written back soon). If it is, we set
PG_dropbehindto get it freed right after, but if writeback has already ended we put it on the tail of the LRU to be freed later.Quoted 3 lines
It's a bit counterintuitive to me that folios with pending writeback get freed faster than folios that completed their writeback already. Am I missing something?
Quoted 7 lines
Yeah, it is strange.
I think we can drop the writeback/dirty check. Set
PG_dropbehindand put the page on the tail of LRU unconditionally. The check was required to avoid confusion withPG_readahead.Comment above the function is not valid anymore.
My read is that we don't put dirty/writeback folios at the tail of the LRU because they cannot be freed immediately and we want to give them time to be written back before reclaim reaches them. So I don't think we want to change that and always put the pages at the tail.
Quoted 4 lines
But the folio that is still dirty under writeback will be freed faster as we get rid of the folio just after writeback is done while clean page can dangle on LRU for a while.
Yeah if we reuse
PG_dropbehindthen we cannot avoidfolio_end_writeback()freeing the folio faster than clean ones.Quoted 1 line
Quoted 11 lines
Quoted 2 lines
I don't think we have any convenient place to free clean dropbehind page other than
shrink_folio_list(). Or do we?Not sure tbh. FWIW I am not saying it's necessarily a bad thing to free dirty/writeback folios before clean ones when deactivated, it's just strange and a behavioral change from today that I wanted to point out. Perhaps that's the best we can do for now.
Quoted 3 lines
Looking at
shrink_folio_list(), I think we need to bypass page demotion forPG_dropbehindpages.
I agree with Yosry. I don't think lru_deactivate_file() is still needed -- it was needed only because when truncation fails to free a dirty/writeback folio, page reclaim can do that quickly. For other conditions that mapping_evict_folio() returns 0, there isn't much page reclaim can do, and those conditions are not deactivate_file_folio() and lru_deactivate_file()'s intentions. So the following should be enough, and it's a lot cleaner :
mm/truncate.c +0 -0
@@ -486,7 +486,7 @@ unsigned long mapping_try_invalidate(struct
address_space *mapping,
* of interest and try to speed up its reclaim.
*/
if (!ret) {
- deactivate_file_folio(folio);
+ folio_set_dropbehind(folio)
/* Likely in the lru cache of a remote CPU */
if (nr_failed)
(*nr_failed)++;Then we can drop deactivate_file_folio() and lru_deactivate_file().
Re: [PATCH 4/8] mm/swap: Use PG_dropbehind instead of PG_reclaim
Quoted 109 lines · Yu Zhao
Quoted 72 lines · Yosry Ahmed
Quoted 47 lines · Kirill A. Shutemov
Quoted 41 lines · Yosry Ahmed
Quoted 23 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()inlru_deactivate_file().Signed-off-by Kirill A. Shutemov <[email protected]>--- mm/swap.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)mm/swap.c +0
-2@@ -562,14 +562,8 @@ static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio)folio_clear_referenced (folio);if (folio_test_writeback (folio) ||folio_test_dirty (folio)) { -/* -* Setting the reclaim flag could race with mm/swap.c static void lru_deactivate_file(struct lruvec *lruvec, struct folio *folio) · line 569
Quoted 10 lines
mm/swap.c +1
-5-* folio_end_writeback() and confuse readahead. But the -* race window is _really_ small and it's not a critical -* problem. -*/ lruvec_add_folio (lruvec, folio); -folio_set_reclaim (folio); +folio_set_dropbehind (folio); }else {/* * The folio's writeback ended while it was in the batch. Now there's a difference in behavior here depending on whether or not the folio is under writeback (or will be written back soon). If it is, we set
PG_dropbehindto get it freed right after, but if writeback has already ended we put it on the tail of the LRU to be freed later.Quoted 3 lines
It's a bit counterintuitive to me that folios with pending writeback get freed faster than folios that completed their writeback already. Am I missing something?
Quoted 7 lines
Yeah, it is strange.
I think we can drop the writeback/dirty check. Set
PG_dropbehindand put the page on the tail of LRU unconditionally. The check was required to avoid confusion withPG_readahead.Comment above the function is not valid anymore.
My read is that we don't put dirty/writeback folios at the tail of the LRU because they cannot be freed immediately and we want to give them time to be written back before reclaim reaches them. So I don't think we want to change that and always put the pages at the tail.
Quoted 4 lines
But the folio that is still dirty under writeback will be freed faster as we get rid of the folio just after writeback is done while clean page can dangle on LRU for a while.
Yeah if we reuse
PG_dropbehindthen we cannot avoidfolio_end_writeback()freeing the folio faster than clean ones.Quoted 1 line
Quoted 11 lines
Quoted 2 lines
I don't think we have any convenient place to free clean dropbehind page other than
shrink_folio_list(). Or do we?Not sure tbh. FWIW I am not saying it's necessarily a bad thing to free dirty/writeback folios before clean ones when deactivated, it's just strange and a behavioral change from today that I wanted to point out. Perhaps that's the best we can do for now.
Quoted 3 lines
Looking at
shrink_folio_list(), I think we need to bypass page demotion forPG_dropbehindpages.I agree with Yosry. I don't think
lru_deactivate_file()is still needed -- it was needed only because when truncation fails to free a dirty/writeback folio, page reclaim can do that quickly. For other conditions thatmapping_evict_folio()returns 0, there isn't much page reclaim can do, and those conditions are notdeactivate_file_folio()and lru_deactivate_file()'s intentions. So the following should be enough, and it's a lot cleaner :mm/truncate.c +1
-1@@ -486,7 +486,7 @@ unsigned long mapping_try_invalidate(structaddress_space *mapping, * of interest and try to speed up its reclaim. */ if (!ret) { -deactivate_file_folio (folio); +folio_set_dropbehind (folio)/* Likely in the lru cache of a remote CPU */ if (nr_failed)(*nr_failed)++;
Quoted 1 line
Then we can drop
deactivate_file_folio()andlru_deactivate_file().
And with the above and list_move_tail() removed, we can also remove lruvec_add_folio_tail().
PATCH 5/8 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.45.2
Re: [PATCH 5/8] mm/vmscan: Use PG_dropbehind instead of PG_reclaim
Quoted 34 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
-2@@ -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);
mm/vmscan.c static pageout_t pageout(struct folio *folio, struct address_space *mapping, · line 707
Quoted 10 lines
mm/vmscan.c +0
-4return 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 · 3 lines
Cheers, David / dhildenb
PATCH 6/8 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
@@ -1174,7 +1174,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.
@@ -1193,31 +1193,17 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,/* 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) || (mapping &&mapping_writeback_indeterminate (mapping))) { -/* -* 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;
@@ -1372,7 +1358,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.
@@ -1382,7 +1368,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.45.2
Re: [PATCH 6/8] mm/vmscan: Use PG_dropbehind instead of PG_reclaim in shrink_folio_list()
Quoted 12 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()inshrink_folio_list().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.
Quoted 4 lines
Also use
PG_dropbehindinsteadPG_reclaimto detect I/O congestion.Signed-off-by Kirill A. Shutemov <[email protected]>---
Signature · 3 lines
Cheers, David / dhildenb
PATCH 7/8 mm/mglru: Check PG_dropcache 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.45.2
Re: [PATCH 7/8] mm/mglru: Check PG_dropcache instead of PG_reclaim in lru_gen_folio_seq()
Quoted 2 lines · Kirill A. Shutemov
Kernel sets
PG_dropcacheinstead ofPG_reclaimeverywhere. CheckPG_dropcacheinlru_gen_folio_seq().
Subject and description PG_dropcache->PG_dropbehind
Apart from that LGTM
Signature · 3 lines
Cheers, David / dhildenb
PATCH 8/8 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 | 1 - 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 | 16 ---------------- mm/vmscan.c | 7 ------- tools/mm/page-types.c | 8 +------- 13 files changed, 18 insertions(+), 90 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 -1
@@ -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
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
@@ -114,7 +114,7 @@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
@@ -1624,18 +1624,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
@@ -686,6 +686,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);/*
@@ -728,14 +730,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 +0 -16
@@ -221,22 +221,6 @@ static void lru_move_tail(struct lruvec *lruvec, struct folio *folio)__count_vm_events (PGROTATED ,folio_nr_pages (folio)); } -/* -* Writeback is about to end against a folio which has been marked for -* immediate reclaim. If it still appears to be reclaimable, move it -* to the tail of the inactive list. -* -* folio_rotate_reclaimable() must disable IRQs, to prevent nasty races. -*/ -void folio_rotate_reclaimable (struct folio *folio) -{ -if (folio_test_locked (folio) ||folio_test_dirty (folio) || -folio_test_unevictable (folio)) -return ; - -folio_batch_add_and_move (folio, lru_move_tail, true); -} -void lru_note_cost (struct lruvec *lruvec,bool file,unsigned int nr_io,unsigned int nr_rotated) {
mm/vmscan.c +0 -7
@@ -3216,9 +3216,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);
@@ -4460,9 +4457,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);
@@ -4659,7 +4653,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.45.2
Quoted 5 lines · Kirill A. Shutemov
Nobody sets the flag anymore.
Remove the
PG_reclaim, makingPG_readheadexclusive user of the page flag bit.
Signature · 3 lines
Cheers, David / dhildenb
Matthew Wilcox
maintainermm/migrate.c void folio_migrate_flags(struct folio *newfolio, struct folio *folio) · line 693
Quoted 13 lines · Kirill A. Shutemov
mm/migrate.c +2
-0@@ -686,6 +686,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);/*
Not a problem with this patch ... but aren't we missing a test_dropbehind / set_dropbehind pair in this function? Or are we prohibited from migrating a folio with the dropbehind flag set somewhere?
Quoted 10 lines
+++
b/mm/swap.cmm/migrate.c +0
-5@@ -221,22 +221,6 @@ static void lru_move_tail(struct lruvec *lruvec, struct folio *folio)__count_vm_events (PGROTATED ,folio_nr_pages (folio)); } -/* -* Writeback is about to end against a folio which has been marked for -* immediate reclaim. If it still appears to be reclaimable, move it -* to the tail of the inactive list. -*
mm/migrate.c static void lru_move_tail(struct lruvec *lruvec, struct folio *folio) · line 238
Quoted 10 lines
mm/migrate.c +0
-10-* folio_rotate_reclaimable() must disable IRQs, to prevent nasty races. -*/ -void folio_rotate_reclaimable (struct folio *folio) -{ -if (folio_test_locked (folio) ||folio_test_dirty (folio) || -folio_test_unevictable (folio)) -return ; - -folio_batch_add_and_move (folio, lru_move_tail, true); -}
I think this is the last caller of lru_move_tail(), which means we can get rid of fbatches->lru_move_tail and the local_lock that protects it. Or did I miss something?
Quoted 12 lines · Matthew Wilcox
Quoted 11 lines · Kirill A. Shutemov
mm/migrate.c +2
-0@@ -686,6 +686,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);
Quoted 7 lines
mm/migrate.c void folio_migrate_flags(struct folio *newfolio, struct folio *folio) · line 693
Quoted 2 lines
mm/migrate.c +0
-0folio_migrate_refs (newfolio, folio);/* Not a problem with this patch ... but aren't we missing a
test_dropbehind/set_dropbehindpair in this function? Or are we prohibited from migrating a folio with the dropbehind flag set somewhere?
Hm. Good catch.
We might want to drop clean dropbehind pages instead migrating them.
But I am not sure about dirty ones. With slow backing storage it might be better for the system to migrate them instead of keeping them in the old place for potentially long time.
Any opinions?
Quoted 16 lines
Quoted 16 lines
+++
b/mm/swap.cmm/migrate.c +0
-11@@ -221,22 +221,6 @@ static void lru_move_tail(struct lruvec *lruvec, struct folio *folio)__count_vm_events (PGROTATED ,folio_nr_pages (folio)); } -/* -* Writeback is about to end against a folio which has been marked for -* immediate reclaim. If it still appears to be reclaimable, move it -* to the tail of the inactive list. -* -* folio_rotate_reclaimable() must disable IRQs, to prevent nasty races. -*/ -void folio_rotate_reclaimable (struct folio *folio) -{ -if (folio_test_locked (folio) ||folio_test_dirty (folio) || -folio_test_unevictable (folio))
Quoted 8 lines
mm/migrate.c static void lru_move_tail(struct lruvec *lruvec, struct folio *folio) · line 238
Quoted 4 lines
mm/migrate.c +0
-4-return ; - -folio_batch_add_and_move (folio, lru_move_tail, true); -}I think this is the last caller of
lru_move_tail(), which means we can get rid offbatches->lru_move_tailand thelocal_lockthat protects it. Or did I miss something?
I see lru_move_tail() being used by lru_add_drain_cpu().
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov
Quoted 57 lines · Kirill A. Shutemov
Quoted 12 lines · Matthew Wilcox
Quoted 11 lines · Kirill A. Shutemov
mm/migrate.c +2
-0@@ -686,6 +686,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);Quoted 7 lines
mm/migrate.c void folio_migrate_flags(struct folio *newfolio, struct folio *folio) · line 693
Quoted 2 lines
mm/migrate.c +0
-0folio_migrate_refs (newfolio, folio);/* Not a problem with this patch ... but aren't we missing a
test_dropbehind/set_dropbehindpair in this function? Or are we prohibited from migrating a folio with the dropbehind flag set somewhere?Hm. Good catch.
We might want to drop clean dropbehind pages instead migrating them.
But I am not sure about dirty ones. With slow backing storage it might be better for the system to migrate them instead of keeping them in the old place for potentially long time.
Any opinions?
Quoted 16 lines
Quoted 16 lines
+++
b/mm/swap.cmm/migrate.c +0
-11@@ -221,22 +221,6 @@ static void lru_move_tail(struct lruvec *lruvec, struct folio *folio)__count_vm_events (PGROTATED ,folio_nr_pages (folio)); } -/* -* Writeback is about to end against a folio which has been marked for -* immediate reclaim. If it still appears to be reclaimable, move it -* to the tail of the inactive list. -* -* folio_rotate_reclaimable() must disable IRQs, to prevent nasty races. -*/ -void folio_rotate_reclaimable (struct folio *folio) -{ -if (folio_test_locked (folio) ||folio_test_dirty (folio) || -folio_test_unevictable (folio))Quoted 8 lines
mm/migrate.c static void lru_move_tail(struct lruvec *lruvec, struct folio *folio) · line 238
Quoted 4 lines
mm/migrate.c +0
-4-return ; - -folio_batch_add_and_move (folio, lru_move_tail, true); -}I think this is the last caller of
lru_move_tail(), which means we can get rid offbatches->lru_move_tailand thelocal_lockthat protects it. Or did I miss something?
Quoted 1 line
I see
lru_move_tail()being used bylru_add_drain_cpu().
That can be deleted too, since you've already removed the producer to fbatches->lru_move_tail.
Matthew Wilcox
maintainerQuoted 1 line · Kirill A. Shutemov
Use
PG_dropbehindinstead ofPG_reclaimand removePG_reclaim.
I was hoping we'd end up with the name PG_reclaim instead of the name PG_dropbehind. PG_reclaim is a better name for this functionality.
Quoted 5 lines · Matthew Wilcox
Quoted 1 line · Kirill A. Shutemov
Use
PG_dropbehindinstead ofPG_reclaimand removePG_reclaim.I was hoping we'd end up with the name
PG_reclaiminstead of the namePG_dropbehind.PG_reclaimis a better name for this functionality.
I got burned by re-using the name with MAX_ORDER redefinition. I guess it is less risky as it is less used, but still...
Anyway, it can be done with a patch on top of the patchset. We must get rid of current PG_reclaim first.
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov