lkml.org 
[lkml]   [2024]   [Apr]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v7 1/3] mm/madvise: introduce clear_young_dirty_ptes() batch helper
From
On 17/04/2024 10:01, Lance Yang wrote:
> On Wed, Apr 17, 2024 at 4:19 PM David Hildenbrand <david@redhat.com> wrote:
>>
>> On 17.04.24 07:04, Lance Yang wrote:
>>> Hey David, Ryan,
>>>
>>> How about this change?
>>>
>>> static inline void clear_young_dirty_ptes(struct vm_area_struct *vma,
>>> unsigned long addr, pte_t *ptep,
>>> unsigned int nr, cydp_t flags)
>>> {
>>> if (flags == CYDP_CLEAR_YOUNG) {
>>> for (;;) {
>>> ptep_test_and_clear_young(vma, addr, ptep);
>>> if (--nr == 0)
>>> break;
>>> ptep++;
>>> addr += PAGE_SIZE;
>>> }
>>> return;
>>> }
>>>
>>> pte_t pte;
>>>
>>> for (;;) {
>>> pte = ptep_get_and_clear(vma->vm_mm, addr, ptep);
>>>
>>> if (flags & CYDP_CLEAR_YOUNG)
>>> pte = pte_mkold(pte);
>>> if (flags & CYDP_CLEAR_DIRTY)
>>> pte = pte_mkclean(pte);
>>>
>>> if (--nr == 0)
>>> break;
>>> ptep++;
>>> addr += PAGE_SIZE;
>>> }
>>> }
>>
>> Likely it might be best to just KIS for now and leave it as is. The
>> compiler should optimize out based on flags already, that's what I ignored.
>
> Got it. Let's keep it as is for now :)

Yep agreed; you're passing the flags as constants so the compiler should be
completely removing one half of the conditional. And if the input isn't a
constant, I'd still expect the compiler to hoist the conditional out of the loop.

>
> Thanks,
> Lance
>
>>
>> --
>> Cheers,
>>
>> David / dhildenb
>>


\
 
 \ /
  Last update: 2024-04-17 12:53    [W:0.054 / U:0.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site