From: Miaohe Lin <linmiaohe@huawei.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: <akpm@linux-foundation.org>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mm/vmscan: don't try to reclaim freed folios
Date: Sat, 28 May 2022 14:24:34 +0800 [thread overview]
Message-ID: <354f9b86-44fe-493b-eac4-07c5eeb573cf@huawei.com> (raw)
In-Reply-To: <YpGTaCf+bZGdEdNj@casper.infradead.org>
On 2022/5/28 11:13, Matthew Wilcox wrote:
> On Sat, May 28, 2022 at 10:52:11AM +0800, Miaohe Lin wrote:
>> On 2022/5/27 23:02, Matthew Wilcox wrote:
>>> What? No. This can absolutely happen. We have a refcount on the folio,
>>> which means that any other thread can temporarily raise the refcount,
>>
>> IIUC, the folio is only in the isolated page_list now and it's not in the page cache, swap cache, pagetable or
>> under any use. So there should be no way that any other thread can temporarily raise the refcount when
>> folio_ref_count == 1. Or am I miss something?
>
> Take a look at something like GUP (fast). If this page _was_ mapped to
> userspace, something like this can happen:
>
> Thread A Thread B
> load PTE
> unmap page
> refcount goes to 1
> vmscan sees the page
> try_get_ref
> refcount is now 2. WARN_ON.
>
> Thread A will see that the PTE has changed and will now drop its
> reference, but Thread B already spat out the WARN.
>
> A similar thing can happen with the page cache.
Oh, I see. Many thanks for your patient explanation! :)
>
> If this is a worthwhile optimisation (does it happen often that we find
> a refcount == 1 page?), we could do something like ...
No, It should be rare.
>
> if (folio_ref_freeze(folio, 1)) {
> nr_pages = folio_nr_pages(folio);
> goto free_it;
> }
>
> ... or ...
>
> if (folio_ref_count(folio) == 1 &&
> folio_ref_freeze(folio, 1)) {
>
> ... if we want to test-and-test-and-clear
These proposed code changes look good to me.
>
> But this function is far too complicated already. I really want to
> see numbers that proves the extra complexity is worth it.
This optimization can save lots of cpu cycles and avoid possible disk I/O in
that specified case. But that is a somewhat rare case. So there's no numbers
that proves the extra complexity is worth it.
Should I drop this patch or proceed with the proposed code changes above in
next version? :)
Many thanks!
>
>
> .
>
next prev parent reply other threads:[~2022-05-28 6:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-27 8:04 Miaohe Lin
2022-05-27 15:02 ` Matthew Wilcox
2022-05-28 2:52 ` Miaohe Lin
2022-05-28 3:13 ` Matthew Wilcox
2022-05-28 6:24 ` Miaohe Lin [this message]
2022-06-08 14:09 ` Miaohe Lin
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=354f9b86-44fe-493b-eac4-07c5eeb573cf@huawei.com \
--to=linmiaohe@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox