From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: "Yin, Fengwei" <fengwei.yin@intel.com>,
"Huang, Ying" <ying.huang@intel.com>, Zi Yan <ziy@nvidia.com>
Cc: akpm@linux-foundation.org, mgorman@techsingularity.net,
hughd@google.com, vbabka@suse.cz, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: migrate: record the mlocked page status to remove unnecessary lru drain
Date: Fri, 20 Oct 2023 10:09:35 +0800 [thread overview]
Message-ID: <05d596f3-c59c-76c3-495e-09f8573cf438@linux.alibaba.com> (raw)
In-Reply-To: <fd389af5-d949-43dc-9a35-d53112fe4a60@intel.com>
On 10/19/2023 8:07 PM, Yin, Fengwei wrote:
>
>
> On 10/19/2023 4:51 PM, Baolin Wang wrote:
>>
>>
>> On 10/19/2023 4:22 PM, Yin Fengwei wrote:
>>> Hi Baolin,
>>>
>>> On 10/19/23 15:25, Baolin Wang wrote:
>>>>
>>>>
>>>> On 10/19/2023 2:09 PM, Huang, Ying wrote:
>>>>> Zi Yan <ziy@nvidia.com> writes:
>>>>>
>>>>>> On 18 Oct 2023, at 9:04, Baolin Wang wrote:
>>>>>>
>>>>>>> When doing compaction, I found the lru_add_drain() is an obvious hotspot
>>>>>>> when migrating pages. The distribution of this hotspot is as follows:
>>>>>>> - 18.75% compact_zone
>>>>>>> - 17.39% migrate_pages
>>>>>>> - 13.79% migrate_pages_batch
>>>>>>> - 11.66% migrate_folio_move
>>>>>>> - 7.02% lru_add_drain
>>>>>>> + 7.02% lru_add_drain_cpu
>>>>>>> + 3.00% move_to_new_folio
>>>>>>> 1.23% rmap_walk
>>>>>>> + 1.92% migrate_folio_unmap
>>>>>>> + 3.20% migrate_pages_sync
>>>>>>> + 0.90% isolate_migratepages
>>>>>>>
>>>>>>> The lru_add_drain() was added by commit c3096e6782b7 ("mm/migrate:
>>>>>>> __unmap_and_move() push good newpage to LRU") to drain the newpage to LRU
>>>>>>> immediately, to help to build up the correct newpage->mlock_count in
>>>>>>> remove_migration_ptes() for mlocked pages. However, if there are no mlocked
>>>>>>> pages are migrating, then we can avoid this lru drain operation, especailly
>>>>>>> for the heavy concurrent scenarios.
>>>>>>
>>>>>> lru_add_drain() is also used to drain pages out of folio_batch. Pages in folio_batch
>>>>>> have an additional pin to prevent migration. See folio_get(folio); in folio_add_lru().
>>>>>
>>>>> lru_add_drain() is called after the page reference count checking in
>>>>> move_to_new_folio(). So, I don't this is an issue.
>>>>
>>>> Agree. The purpose of adding lru_add_drain() is to address the 'mlock_count' issue for mlocked pages. Please see commit c3096e6782b7 and related comments. Moreover I haven't seen an increase in the number of page migration failures due to page reference count checking after this patch.
>>>
>>> I agree with your. My understanding also is that the lru_add_drain() is only needed
>>> for mlocked folio to correct mlock_count. Like to hear the confirmation from Huge.
>>>
>>>
>>> But I have question: why do we need use page_was_mlocked instead of check
>>> folio_test_mlocked(src)? Does page migration clear the mlock flag? Thanks.
>>
>> Yes, please see the call trace: try_to_migrate_one() ---> page_remove_rmap() ---> munlock_vma_folio().
>
> Yes. This will clear mlock bit.
>
> What about set dst folio mlocked if source is before try_to_migrate_one()? And
> then check whether dst folio is mlocked after? And need clear mlocked if migration
> fails. I suppose the change is minor. Just a thought. Thanks.
IMO, this will break the mlock related statistics in mlock_folio() when
the remove_migration_pte() rebuilds the mlock status and mlock count.
Another concern I can see is that, during the page migration, a
concurrent munlock() can be called to clean the VM_LOCKED flags for the
VMAs, so the remove_migration_pte() should not rebuild the mlock status
and mlock count. But the dst folio's mlcoked status is still remained,
which is wrong.
So your suggested apporach seems not easy, and I think my patch is
simple with re-using existing __migrate_folio_record() and
__migrate_folio_extract() :)
next prev parent reply other threads:[~2023-10-20 2:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-18 13:04 Baolin Wang
2023-10-18 14:00 ` Zi Yan
2023-10-19 6:09 ` Huang, Ying
2023-10-19 7:25 ` Baolin Wang
2023-10-19 8:22 ` Yin Fengwei
2023-10-19 8:51 ` Baolin Wang
2023-10-19 12:07 ` Yin, Fengwei
2023-10-20 2:09 ` Baolin Wang [this message]
2023-10-20 2:30 ` Yin, Fengwei
2023-10-20 2:45 ` Baolin Wang
2023-10-20 2:47 ` Yin, Fengwei
2023-10-20 2:54 ` Yin, Fengwei
2023-10-20 3:27 ` Baolin Wang
2023-10-20 3:45 ` Yosry Ahmed
2023-10-20 3:52 ` Yin, Fengwei
2023-10-20 4:02 ` Yosry Ahmed
2023-10-20 4:04 ` Yin, Fengwei
2023-10-19 13:23 ` Zi Yan
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=05d596f3-c59c-76c3-495e-09f8573cf438@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=fengwei.yin@intel.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=vbabka@suse.cz \
--cc=ying.huang@intel.com \
--cc=ziy@nvidia.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