From: Ridong Chen <ridong.chen@linux.dev>
To: Barry Song <baohua@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Johannes Weiner <hannes@cmpxchg.org>,
David Hildenbrand <david@kernel.org>,
Michal Hocko <mhocko@kernel.org>, Qi Zheng <qi.zheng@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Lorenzo Stoakes <ljs@kernel.org>,
Kairui Song <kasong@tencent.com>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
Baoquan He <baoquan.he@linux.dev>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Ridong Chen <chenridong@xiaomi.com>
Subject: Re: [PATCH mm-new v2] mm: vmscan: put rotation-missed folios at the LRU tail
Date: Mon, 21 Sep 2026 14:04:54 +0800 [thread overview]
Message-ID: <2e878fe2-473e-4dc1-a669-7e2e37894d6e@linux.dev> (raw)
In-Reply-To: <CAGsJ_4zCADpQDqVj=BFipOztctBMBhw9Wcj+FLVcj-d8e=0bow@mail.gmail.com>
On 9/21/2026 5:31 AM, Barry Song wrote:
> On Sun, Sep 20, 2026 at 9:25 PM Ridong Chen <ridong.chen@linux.dev> wrote:
>>
> [...]
>>
>> mm/vmscan.c | 24 ++++++++++++++++++------
>> 1 file changed, 18 insertions(+), 6 deletions(-)
>>
>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>> index e200ce3eb056..91295070ca33 100644
>> --- a/mm/vmscan.c
>> +++ b/mm/vmscan.c
>> @@ -1971,7 +1971,7 @@ static bool too_many_isolated(struct pglist_data *pgdat, int file,
>> *
>> * Note: The caller must not hold any lruvec lock.
>> */
>> -static unsigned int move_folios_to_lru(struct list_head *list)
>> +static unsigned int move_folios_to_lru(struct list_head *list, bool do_rotate)
>> {
>> int nr_pages, nr_moved = 0;
>> struct lruvec *lruvec = NULL;
>> @@ -2018,7 +2018,19 @@ static unsigned int move_folios_to_lru(struct list_head *list)
>> continue;
>> }
>>
>> - lruvec_add_folio(lruvec, folio);
>> + /*
>> + * Put clean, unreferenced and unpinned folios that may have
>> + * missed folio_rotate_reclaimable() at the tail to avoid
>> + * cold/hot inversion.
>> + */
>> + if (do_rotate && !folio_test_active(folio) && !folio_mapped(folio) &&
>> + !folio_test_dirty(folio) && !folio_test_writeback(folio) &&
>> + !folio_test_referenced(folio) &&
>> + folio_ref_count(folio) == folio_expected_ref_count(folio))
>
>
> I guess this is wrong. We hold an extra reference while isolating
> the folio, so I think this should be:
>
> `folio_ref_count(folio) == folio_expected_ref_count(folio) + 1`
>
> Am I missing something here?
>
Hi Barry,
Thank you for your review.
The folios we want to check have the following lifecycle:
1. In isolate_lru_folios, we take an extra reference (i.e., +1).
2. In __remove_mapping, the folio can only be frozen successfully when refcount
== 1 + folio_nr_pages(folio). We need to exclude folios whose refcount is not 1
+ folio_nr_pages(folio) (e.g., those pinned by GUP), as reported by Sashiko.
```
...
refcount = 1 + folio_nr_pages(folio);
if (!folio_ref_freeze(folio, refcount))
goto cannot_free;
...
```
3. In move_folios_to_lru, we drop the extra reference and move the folio back to
the lruvec.
```
...
if (unlikely(folio_put_testzero(folio))) {
__folio_clear_lru_flags(folio);
...
}
if (do_rotate && !folio_test_active(folio) && !folio_mapped(folio) &&
!folio_test_dirty(folio) && !folio_test_writeback(folio) &&
!folio_test_referenced(folio) &&
folio_ref_count(folio) == folio_expected_ref_count(folio))
lruvec_add_folio_tail(lruvec, folio);
else
lruvec_add_folio(lruvec, folio);
```
The refcount check is added after the extra reference has been dropped.
Therefore, I believe it should be 'folio_ref_count(folio) ==
folio_expected_ref_count(folio)', not 'folio_ref_count(folio) ==
folio_expected_ref_count(folio) + 1'.
--
Best regards
Ridong
next prev parent reply other threads:[~2026-09-21 6:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 13:25 [PATCH mm-new v2] mm: vmscan: put rotation-missed folios at the LRU tail Ridong Chen
2026-09-20 21:31 ` Barry Song
2026-09-21 6:04 ` Ridong Chen [this message]
2026-09-21 7:00 ` Barry Song
2026-09-21 7:00 ` Barry Song
2026-09-23 2:58 ` Baolin Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2e878fe2-473e-4dc1-a669-7e2e37894d6e@linux.dev \
--to=ridong.chen@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=chenridong@xiaomi.com \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=qi.zheng@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.