mm/vmscan: remove redundant folio_test_swapbacked()
Subsystems (3)
PATCH RESEND 1/1 mm/vmscan: remove redundant folio_test_swapbacked()
When !folio_is_file_lru(folio) is false, it implies that !folio_test_swapbacked(folio) must be true. Therefore, the additional check for !folio_test_swapbacked(folio) is redundant and can be safely removed.
This cleanup simplifies the code without changing any functionality.
--- mm/vmscan.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/vmscan.c +1 -2
@@ -985,8 +985,7 @@ static void folio_check_dirty_writeback(struct folio *folio,* They could be mistakenly treated as file lru. So further anon * test is needed. */ -if (!folio_is_file_lru (folio) || - (folio_test_anon (folio) && !folio_test_swapbacked (folio))) { +if (!folio_is_file_lru (folio) ||folio_test_anon (folio)) { *dirty = false; *writeback = false;return ;
Signature · 1 line
2.50.0
Harry Yoo
Acked-by Minchan Kim Acked-by Michal Hocko Acked-by Johannes Weiner Acked-by Hillf Danton on v1 1/1This is marked as RESEND, but which patch is it a resend of? I can’t find the original one.
Quoted 2 lines · Jialin Wang
When !folio_is_file_lru(folio) is false, it implies that !folio_test_swapbacked(folio) must be true.
That is not true.
MADV_FREE pages are anonymous pages that are not swapbacked (and thus can be reclaimed without pageout if they are clean).
See below commit that added the condition and the patch series that introduced it:
https://lore.kernel.org/all/[email protected]/
commit 802a3a92ad7ac0b9be9df229dee530a1f0a8039b
Author: Shaohua Li <[email protected]> Date: Wed May 3 14:52:32 2017 -0700
mm: reclaim MADV_FREE pages
When memory pressure is high, we free MADV_FREE pages. If the pages are not dirty in pte, the pages could be freed immediately. Otherwise we can't reclaim them. We put the pages back to anonumous LRU list (by setting SwapBacked flag) and the pages will be reclaimed in normal swapout way.
We use normal page reclaim policy. Since MADV_FREE pages are put into inactive file list, such pages and inactive file pages are reclaimed according to their age. This is expected, because we don't want to reclaim too many MADV_FREE pages before used once pages.
Based on Minchan's original patch
Signature · 2 lines
Cheers, Harry / Hyeonggon
Quoted 29 lines
Therefore, the additional
check for !folio_test_swapbacked(folio) is redundant and can be safely removed.This cleanup simplifies the code without changing any functionality.
Signed-off-by Jialin Wang <[email protected]>--- mm/vmscan.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/vmscan.c +1
-2@@ -985,8 +985,7 @@ static void folio_check_dirty_writeback(struct folio *folio,* They could be mistakenly treated as file lru. So further anon * test is needed. */ -if (!folio_is_file_lru (folio) || - (folio_test_anon (folio) && !folio_test_swapbacked (folio))) { +if (!folio_is_file_lru (folio) ||folio_test_anon (folio)) { *dirty = false; *writeback = false;return ;Signature · 1 line
2.50.0
Quoted 4 lines · Harry Yoo
This is marked as RESEND, but which patch is it a resend of? I can’t find the original one.
I sent the original one to the wrong mailing list and missed proper cc's, sorry.
https://lore.kernel.org/lkml/[email protected]/
Quoted 6 lines · Jialin Wang
Quoted 2 lines
When !folio_is_file_lru(folio) is false, it implies that !folio_test_swapbacked(folio) must be true.
That is not true.
This is the definition of folio_is_file_lru() in include/linux/mm_inline.h line 28:
static inline int folio_is_file_lru(struct folio *folio) {
return !folio_test_swapbacked(folio);
}
Quoted 3 lines
MADV_FREEpages are anonymous pages that are not swapbacked (and thus can be reclaimed without pageout if they are clean).
Thanks for the explanation! I'm new to memory management, so this is really helpful for me to learn.
Best regards,
Jialin Wang
Quoted 7 lines · Jialin Wang
Quoted 4 lines · Harry Yoo
This is marked as RESEND, but which patch is it a resend of? I can’t find the original one.
I sent the original one to the wrong mailing list and missed proper cc's, sorry.
https://lore.kernel.org/lkml/[email protected]/
Ahh I see. I couldn't find it because it was not sent to linux-mm. I assumed you sent it a while ago but didn't get any feedback.
Quoted 5 lines
Quoted 5 lines · Jialin Wang
Quoted 2 lines
When !folio_is_file_lru(folio) is false, it implies that !folio_test_swapbacked(folio) must be true.
That is not true.
Oops, I completely misread the message and really sorry for that.
I thought you're saying "anonymous pages are always swapbacked", (without considering ! in the expression), but you weren't saying that. Probably I shouldn't have read it so late at night ;)
Quoted 6 lines
This is the definition of
folio_is_file_lru()ininclude/linux/mm_inline.hline 28:
static inline intfolio_is_file_lru(struct folio *folio){
return !folio_test_swapbacked(folio);
}
You're right that technically this can be simplified, but I see Miaohe tried this exactly same simplication a few years ago and it got some negative feedbacks from people as it makes it harder to read the code.
https://lore.kernel.org/linux-mm/[email protected]
So maybe not worth it?
Quoted 5 lines
Quoted 3 lines
MADV_FREEpages are anonymous pages that are not swapbacked (and thus can be reclaimed without pageout if they are clean).Thanks for the explanation! I'm new to memory management, so this is really helpful for me to learn.
You're welcome!
Quoted 2 lines
Best regards,
Jialin Wang
Signature · 2 lines
Cheers, Harry / Hyeonggon