Re: [PATCH 4/7] khugepaged: Allow to callapse a page shared across fork

Zi Yan
2020-03-27T21:45:03Z

[-- Attachment #1: Type: text/plain, Size: 1508 bytes --]

<snip>
>>> /*
>>> * Drain pagevec and retry just in case we can get rid
>>> * of the extra pin, like in swapin case.
>>> */
>>> lru_add_drain();
>>> }
>>> - if (page_count(page) != 1 + PageSwapCache(page)) {
>>> + if (total_mapcount(page) + PageSwapCache(page) !=
>>> + page_count(page)) {
>>> unlock_page(page);
>>> result = SCAN_PAGE_COUNT;
>>> goto out;
>>> @@ -680,7 +688,6 @@ static void __collapse_huge_page_copy(pte_t *pte, struct page *page,
>>> } else {
>>> src_page = pte_page(pteval);
>>> copy_user_highpage(page, src_page, address, vma);
>>> - VM_BUG_ON_PAGE(page_mapcount(src_page) != 1, src_page);
>>
>> Maybe replace it with this?
>>
>> VM_BUG_ON_PAGE(page_mapcount(src_page) + PageSwapCache(src_page) != page_count(src_page), src_page);
>
> I don't think this is correct either. If a THP is PTE mapped its
> refcount would be bumped by the number of PTE mapped subpages. But
> page_mapcount() would just return the mapcount of that specific
> subpage. So, total_mapcount() should be used, but the same check has
> been done before reaching here.

Yes, you are right. Thanks.

Please disregard this comment.

—
Best Regards,
Yan Zi

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 854 bytes --]