From: Matthew Wilcox <willy@infradead.org>
To: "黄朝阳 (Zhaoyang Huang)" <zhaoyang.huang@unisoc.com>
Cc: "Zhaoyang Huang" <huangzhaoyang@gmail.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"康纪滨 (Steve Kang)" <Steve.Kang@unisoc.com>
Subject: Re: summarize all information again at bottom//reply: reply: [PATCH] mm: fix a race scenario in folio_isolate_lru
Date: Mon, 18 Mar 2024 12:32:24 +0000 [thread overview]
Message-ID: <Zfg0WLrcOmCtdn_M@casper.infradead.org> (raw)
In-Reply-To: <be75859d7e4245939d825da5e881902c@BJMBX01.spreadtrum.com>
Stop creating new threads. You're really annoying.
On Mon, Mar 18, 2024 at 09:32:32AM +0000, 黄朝阳 (Zhaoyang Huang) wrote:
> Summarize all information below to make it more clear(remove thread2 which is not mandatory and make the scenario complex)
You've gone back to over-indenting. STOP IT.
> #thread 0(madivise_cold_and_pageout) #thread1(truncate_inode_pages_range)
This is still an impossible race, and it's the third time I've told you
this. And madivise_cold_and_pageout does not exist, it's
madvise_cold_or_pageout_pte_range(). I'm going to stop responding to
your emails if you keep on uselessly repeating the same mistakes.
So, once again,
For madvise_cold_or_pageout_pte_range() to find a page, it must have
a PTE pointing to the page. That means there's a mapcount on the page.
That means there's a refcount on the page.
truncate_inode_pages_range() will indeed attempt to remove a page from
the page cache. BUT before it does that, it has to shoot down TLB
entries that refer to the affected folios. That happens like this:
for (i = 0; i < folio_batch_count(&fbatch); i++)
truncate_cleanup_folio(fbatch.folios[i]);
truncate_cleanup_folio() -> unmap_mapping_folio ->
unmap_mapping_range_tree() -> unmap_mapping_range_vma() ->
zap_page_range_single() -> unmap_single_vma -> unmap_page_range ->
zap_p4d_range -> zap_pud_range -> zap_pmd_range -> zap_pte_range ->
pte_offset_map_lock()
> pte_offset_map_lock takes NO lock
> truncate_inode_folio(refcnt == 2)
> <decrease the refcnt of page cache>
> folio_isolate_lru(refcnt == 1)
> release_pages(refcnt == 1)
> folio_test_clear_lru
> <remove folio's PG_lru>
> folio_put_testzero == true
> folio_get(refer to isolation)
> folio_test_lru == false
> <No lruvec_del_folio>
> list_add(folio->lru, pages_to_free)
> ****current folio will break LRU's integrity since it has not been deleted****
>
> 0. Folio's refcnt decrease from 2 to 1 by filemap_remove_folio
> 1. thread 0 calls folio_isolate_lru with refcnt == 1. Folio comes from vm's pte
> 2. thread 1 calls release_pages with refcnt == 1. Folio comes from address_space
> (refcnt == 1 make sense for both of folio_isolate_lru and release_pages)
> 3. thread0 clear folio's PG_lru by folio_test_clear_lru
> 4. thread1 decrease folio's refcnt from 1 to 0 and get permission to proceed
> 5. thread1 failed in folio_test_lru and do no list_del(folio)
> 6. thread1 add folio to pages_to_free wrongly which break the LRU's->list
> 7. next folio after current one within thread1 experiences list_del_invalid when calling lruvec_del_folio
next prev parent reply other threads:[~2024-03-18 12:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-18 9:32 summarize all information again at bottom//reply: reply: [PATCH] mm: fix a race scenario in folio_isolate_lru 黄朝阳 (Zhaoyang Huang)
2024-03-18 12:32 ` Matthew Wilcox [this message]
2024-03-19 0:48 ` Zhaoyang Huang
2024-03-19 3:01 ` Matthew Wilcox
2024-03-21 8:25 ` Zhaoyang Huang
2024-03-21 12:36 ` Matthew Wilcox
2024-03-22 1:52 ` Zhaoyang Huang
2024-03-22 3:20 ` Matthew Wilcox
2024-03-24 11:14 ` Zhaoyang Huang
2024-03-25 3:22 ` Matthew Wilcox
2024-03-26 9:06 ` Zhaoyang Huang
2024-03-26 12:21 ` Matthew Wilcox
2024-03-27 1:25 ` Zhaoyang Huang
2024-03-27 12:31 ` Matthew Wilcox
2024-03-28 1:27 ` Zhaoyang Huang
2024-03-28 3:18 ` Matthew Wilcox
2024-03-28 4:03 ` Zhaoyang Huang
2024-03-28 14:12 ` Matthew Wilcox
2024-03-29 5:49 ` Zhaoyang Huang
2024-03-29 12:19 ` Matthew Wilcox
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=Zfg0WLrcOmCtdn_M@casper.infradead.org \
--to=willy@infradead.org \
--cc=Steve.Kang@unisoc.com \
--cc=akpm@linux-foundation.org \
--cc=huangzhaoyang@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=zhaoyang.huang@unisoc.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).