From: David Hildenbrand <david@redhat.com>
To: Baolin Wang <baolin.wang@linux.alibaba.com>,
Barry Song <21cnbao@gmail.com>, Lance Yang <ioworker0@gmail.com>
Cc: akpm@linux-foundation.org, ryan.roberts@arm.com, ziy@nvidia.com,
fengwei.yin@intel.com, ying.huang@intel.com,
libang.li@antgroup.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] mm/mlock: implement folio_mlock_step() using folio_pte_batch()
Date: Mon, 3 Jun 2024 11:03:55 +0200 [thread overview]
Message-ID: <a82a7441-3a70-40b6-a765-c91f47bb728c@redhat.com> (raw)
In-Reply-To: <c925eae9-5c7e-47d2-bab3-708edec88990@linux.alibaba.com>
On 03.06.24 10:58, Baolin Wang wrote:
>
>
> On 2024/6/3 12:14, Barry Song wrote:
>> On Mon, Jun 3, 2024 at 3:31 PM Lance Yang <ioworker0@gmail.com> wrote:
>>>
>>> Let's make folio_mlock_step() simply a wrapper around folio_pte_batch(),
>>> which will greatly reduce the cost of ptep_get() when scanning a range of
>>> contptes.
>>>
>>> Signed-off-by: Lance Yang <ioworker0@gmail.com>
>>> ---
>>> mm/mlock.c | 23 ++++++-----------------
>>> 1 file changed, 6 insertions(+), 17 deletions(-)
>>>
>>> diff --git a/mm/mlock.c b/mm/mlock.c
>>> index 30b51cdea89d..1ae6232d38cf 100644
>>> --- a/mm/mlock.c
>>> +++ b/mm/mlock.c
>>> @@ -307,26 +307,15 @@ void munlock_folio(struct folio *folio)
>>> static inline unsigned int folio_mlock_step(struct folio *folio,
>>> pte_t *pte, unsigned long addr, unsigned long end)
>>> {
>>> - unsigned int count, i, nr = folio_nr_pages(folio);
>>> - unsigned long pfn = folio_pfn(folio);
>>> - pte_t ptent = ptep_get(pte);
>>> -
>>> - if (!folio_test_large(folio))
>>> + if (likely(!folio_test_large(folio)))
>>> return 1;
>>>
>>> - count = pfn + nr - pte_pfn(ptent);
>>> - count = min_t(unsigned int, count, (end - addr) >> PAGE_SHIFT);
>>> -
>>> - for (i = 0; i < count; i++, pte++) {
>>> - pte_t entry = ptep_get(pte);
>>> -
>>> - if (!pte_present(entry))
>>> - break;
>>> - if (pte_pfn(entry) - pfn >= nr)
>>> - break;
>>> - }
>>> + const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY;
>>> + int max_nr = (end - addr) / PAGE_SIZE;
>>> + pte_t ptent = ptep_get(pte);
>>>
>>> - return i;
>>> + return folio_pte_batch(folio, addr, pte, ptent, max_nr, fpb_flags, NULL,
>>> + NULL, NULL);
>>> }
>>
>> what about a minimum change as below?
>> index 30b51cdea89d..e8b98f84fbd2 100644
>> --- a/mm/mlock.c
>> +++ b/mm/mlock.c
>> @@ -307,26 +307,15 @@ void munlock_folio(struct folio *folio)
>> static inline unsigned int folio_mlock_step(struct folio *folio,
>> pte_t *pte, unsigned long addr, unsigned long end)
>> {
>> - unsigned int count, i, nr = folio_nr_pages(folio);
>> - unsigned long pfn = folio_pfn(folio);
>> + unsigned int count = (end - addr) >> PAGE_SHIFT;
>> pte_t ptent = ptep_get(pte);
>> + const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY;
>>
>> if (!folio_test_large(folio))
>> return 1;
>>
>> - count = pfn + nr - pte_pfn(ptent);
>> - count = min_t(unsigned int, count, (end - addr) >> PAGE_SHIFT);
>> -
>> - for (i = 0; i < count; i++, pte++) {
>> - pte_t entry = ptep_get(pte);
>> -
>> - if (!pte_present(entry))
>> - break;
>> - if (pte_pfn(entry) - pfn >= nr)
>> - break;
>> - }
>> -
>> - return i;
>> + return folio_pte_batch(folio, addr, pte, ptent, count, fpb_flags, NULL,
>> + NULL, NULL);
>> }
>
> LGTM.
> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
prev parent reply other threads:[~2024-06-03 9:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-03 3:31 Lance Yang
2024-06-03 3:36 ` Matthew Wilcox
2024-06-03 4:13 ` Lance Yang
2024-06-03 4:14 ` Barry Song
2024-06-03 4:27 ` Lance Yang
2024-06-03 8:58 ` Baolin Wang
2024-06-03 9:03 ` David Hildenbrand [this message]
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=a82a7441-3a70-40b6-a765-c91f47bb728c@redhat.com \
--to=david@redhat.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=fengwei.yin@intel.com \
--cc=ioworker0@gmail.com \
--cc=libang.li@antgroup.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryan.roberts@arm.com \
--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