From: Miaohe Lin <linmiaohe@huawei.com>
To: David Hildenbrand <david@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Oscar Salvador <osalvador@suse.de>,
Naoya Horiguchi <nao.horiguchi@gmail.com>, <linux-mm@kvack.org>,
<dan.carpenter@linaro.org>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH v3 1/5] mm: memory_hotplug: remove head variable in do_migrate_range()
Date: Sun, 29 Sep 2024 09:16:18 +0800 [thread overview]
Message-ID: <170546a8-e442-91e9-31e8-60a91018172a@huawei.com> (raw)
In-Reply-To: <e2c5063a-045d-4cfa-9127-690244e63453@redhat.com>
On 2024/9/28 16:39, David Hildenbrand wrote:
> On 28.09.24 10:34, David Hildenbrand wrote:
>> On 28.09.24 06:55, Matthew Wilcox wrote:
>>> On Tue, Aug 27, 2024 at 07:47:24PM +0800, Kefeng Wang wrote:
>>>> Directly use a folio for HugeTLB and THP when calculate the next pfn, then
>>>> remove unused head variable.
>>>
>>> I just noticed this got merged. You're going to hit BUG_ON with it.
>>>
>>>> - if (PageHuge(page)) {
>>>> - pfn = page_to_pfn(head) + compound_nr(head) - 1;
>>>> - isolate_hugetlb(folio, &source);
>>>> - continue;
>>>> - } else if (PageTransHuge(page))
>>>> - pfn = page_to_pfn(head) + thp_nr_pages(page) - 1;
>>>> + /*
>>>> + * No reference or lock is held on the folio, so it might
>>>> + * be modified concurrently (e.g. split). As such,
>>>> + * folio_nr_pages() may read garbage. This is fine as the outer
>>>> + * loop will revisit the split folio later.
>>>> + */
>>>> + if (folio_test_large(folio)) {
>>>
>>> But it's not fine. Look at the implementation of folio_test_large():
>>>
>>> static inline bool folio_test_large(const struct folio *folio)
>>> {
>>> return folio_test_head(folio);
>>> }
>>>
>>> That's going to be provided by:
>>>
>>> #define FOLIO_TEST_FLAG(name, page) \
>>> static __always_inline bool folio_test_##name(const struct folio *folio) \
>>> { return test_bit(PG_##name, const_folio_flags(folio, page)); }
>>>
>>> and here's the BUG:
>>>
>>> static const unsigned long *const_folio_flags(const struct folio *folio,
>>> unsigned n)
>>> {
>>> const struct page *page = &folio->page;
>>>
>>> VM_BUG_ON_PGFLAGS(PageTail(page), page);
>>> VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page);
>>> return &page[n].flags;
>>> }
>>>
>>> (this page can be transformed from a head page to a tail page because,
>>> as the comment notes, we don't hold a reference.
>>>
>>> Please back this out.
>>
>> Should we generalize the approach in dump_folio() to locally copy a
>> folio, so we can safely perform checks before deciding whether we want
>> to try grabbing a reference on the real folio (if it's still a folio :) )?
>>
>
> Oh, and I forgot: isn't the existing code already racy?
>
> PageTransHuge() -> VM_BUG_ON_PAGE(PageTail(page), page);
do_migrate_range is called after start_isolate_page_range(). So a page might not be able to
transform from a head page to a tail page as it's isolated?
Thanks.
next prev parent reply other threads:[~2024-09-29 1:16 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-27 11:47 [PATCH v3 0/5] mm: memory_hotplug: improve do_migrate_range() Kefeng Wang
2024-08-27 11:47 ` [PATCH v3 1/5] mm: memory_hotplug: remove head variable in do_migrate_range() Kefeng Wang
2024-09-28 4:55 ` Matthew Wilcox
2024-09-28 8:34 ` David Hildenbrand
2024-09-28 8:39 ` David Hildenbrand
2024-09-29 1:16 ` Miaohe Lin [this message]
2024-09-29 2:04 ` Kefeng Wang
2024-09-29 2:19 ` Miaohe Lin
2024-09-30 9:25 ` David Hildenbrand
2024-10-09 7:27 ` Kefeng Wang
2024-08-27 11:47 ` [PATCH v3 2/5] mm: memory-failure: add unmap_poisoned_folio() Kefeng Wang
2024-08-31 8:16 ` Miaohe Lin
2024-08-27 11:47 ` [PATCH v3 3/5] mm: memory_hotplug: check hwpoisoned page firstly in do_migrate_range() Kefeng Wang
2024-08-31 8:36 ` Miaohe Lin
2024-08-27 11:47 ` [PATCH v3 4/5] mm: migrate: add isolate_folio_to_list() Kefeng Wang
2024-08-27 11:47 ` [PATCH v3 5/5] mm: memory_hotplug: unify Huge/LRU/non-LRU movable folio isolation Kefeng Wang
2024-08-29 15:05 ` [PATCH v3 5-fix/5] mm: memory_hotplug: unify Huge/LRU/non-LRU movable folio isolation fix Kefeng Wang
2024-08-29 15:19 ` David Hildenbrand
2024-08-30 1:23 ` Kefeng Wang
2024-08-31 9:01 ` [PATCH v3 5/5] mm: memory_hotplug: unify Huge/LRU/non-LRU movable folio isolation 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=170546a8-e442-91e9-31e8-60a91018172a@huawei.com \
--to=linmiaohe@huawei.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=dan.carpenter@linaro.org \
--cc=david@redhat.com \
--cc=linux-mm@kvack.org \
--cc=nao.horiguchi@gmail.com \
--cc=osalvador@suse.de \
--cc=wangkefeng.wang@huawei.com \
--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