From: David Hildenbrand <david@redhat.com>
To: Barry Song <21cnbao@gmail.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org, chrisl@kernel.org,
linux-kernel@vger.kernel.org, mhocko@suse.com,
ryan.roberts@arm.com, baolin.wang@linux.alibaba.com,
yosryahmed@google.com, shy828301@gmail.com, surenb@google.com,
v-songbaohua@oppo.com, willy@infradead.org, ying.huang@intel.com,
yuzhao@google.com
Subject: Re: [PATCH RFC 3/3] mm: remove folio_test_anon(folio)==false path in __folio_add_anon_rmap()
Date: Fri, 14 Jun 2024 13:10:01 +0200 [thread overview]
Message-ID: <c50287f2-1c83-438b-ba4a-c08ef91b5ba9@redhat.com> (raw)
In-Reply-To: <CAGsJ_4wJjp5kTRt=MAQ7umS-uSw9uyUthj1z5urmo5t084aUwQ@mail.gmail.com>
>> I don't think that is required? We are only working with anon folios. Or
>> were you able to trigger this? (which would be weird)
>
> I didn't trigger this. but I am not sure if kfifo is always anon based on
> the code context.
>
> for page, it is 100% anon(otherwise "goto out"), but I am not quite
> sure about kpage
> by the code context.
>
> static int try_to_merge_one_page(struct vm_area_struct *vma,
> struct page *page, struct page *kpage)
> {
> pte_t orig_pte = __pte(0);
> int err = -EFAULT;
>
> if (page == kpage) /* ksm page forked */
> return 0;
>
> if (!PageAnon(page))
> goto out;
> ....
> }
>
> Then I saw this
>
> static int replace_page(struct vm_area_struct *vma, struct page *page,
> struct page *kpage, pte_t orig_pte)
> {
> ...
> VM_BUG_ON_PAGE(PageAnonExclusive(page), page);
> VM_BUG_ON_FOLIO(folio_test_anon(kfolio) && PageAnonExclusive(kpage),
> kfolio);
> }
>
> If kfolio is always anon, we should have used
> VM_BUG_ON_FOLIO(PageAnonExclusive(kpage), folio)
> just like
> VM_BUG_ON_PAGE(PageAnonExclusive(page), page);
> without "folio_test_anon(kfolio)".
>
> So I lost my way.
try_to_merge_one_page() is either called with a KSM page (anon) from
try_to_merge_with_ksm_page() or with the shared zeropage (!anon and must
never become anon) from cmp_and_merge_page().
So in replace_page(), we either have an ksm/anon page or the shared
zeropage.
We never updated the documentation of replace_page() to spell out that
"kpage" can also be the shared zeropage.
Note how replace_page() calls folio_add_anon_rmap_pte() not for the
shared zeropage.
If we would have to craft a new anon page things would be going terribly
wrong.
So not, this (!anon -> anon) must not happen and if it were to happen,
it would be a real bug and your check in folio_add_anon_rmap_pte()
would catch it.
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2024-06-14 11:14 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-13 0:07 [PATCH RFC 0/3] mm: clarify folio_add_new_anon_rmap() and __folio_add_anon_rmap() Barry Song
2024-06-13 0:07 ` [PATCH RFC 1/3] mm: extend rmap flags arguments for folio_add_new_anon_rmap Barry Song
2024-06-13 8:39 ` Barry Song
2024-06-13 0:07 ` [PATCH RFC 2/3] mm: do_swap_page: use folio_add_new_anon_rmap() if folio_test_anon(folio)==false Barry Song
2024-06-13 9:23 ` David Hildenbrand
2024-06-13 9:58 ` Barry Song
2024-06-13 10:37 ` David Hildenbrand
2024-06-13 10:55 ` Barry Song
2024-06-13 0:07 ` [PATCH RFC 3/3] mm: remove folio_test_anon(folio)==false path in __folio_add_anon_rmap() Barry Song
2024-06-13 8:46 ` Barry Song
2024-06-13 8:49 ` David Hildenbrand
2024-06-13 9:06 ` Barry Song
2024-06-13 9:12 ` David Hildenbrand
2024-06-14 7:56 ` Barry Song
2024-06-14 8:51 ` David Hildenbrand
2024-06-14 8:56 ` Barry Song
2024-06-14 8:58 ` Barry Song
2024-06-14 9:04 ` David Hildenbrand
2024-06-14 9:33 ` Barry Song
2024-06-14 11:10 ` David Hildenbrand [this message]
2024-06-14 22:24 ` Barry Song
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=c50287f2-1c83-438b-ba4a-c08ef91b5ba9@redhat.com \
--to=david@redhat.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=chrisl@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=ryan.roberts@arm.com \
--cc=shy828301@gmail.com \
--cc=surenb@google.com \
--cc=v-songbaohua@oppo.com \
--cc=willy@infradead.org \
--cc=ying.huang@intel.com \
--cc=yosryahmed@google.com \
--cc=yuzhao@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox