On 11/19/19 3:37 AM, Jan Kara wrote:
> On Tue 19-11-19 00:16:36, John Hubbard wrote:
>> @@ -2025,6 +2149,20 @@ static int __record_subpages(struct page *page, 
>> unsigned long addr,
>>      return nr;
>>  }
>>  
>> +static bool __pin_compound_head(struct page *head, int refs, unsigned int 
>> flags)
>> +{
> 
> I don't quite like the proliferation of names starting with __. I don't
> think there's a good reason for that, particularly in this case. Also 'pin'
> here is somewhat misleading as we already use term "pin" for the particular
> way of pinning the page. We could have grab_compound_head() or maybe
> nail_compound_head() :), but you're native speaker so you may come up with
> better word.


Yes, it is ugly naming, I'll change these as follows:

    __pin_compound_head() --> grab_compound_head()    
    __record_subpages()   --> record_subpages()

I loved the "nail_compound_head()" suggestion, it just seems very vivid, but
in the end, I figured I'd better keep it relatively drab and colorless. :)

> 
>> +    if (flags & FOLL_PIN) {
>> +            if (unlikely(!try_pin_compound_head(head, refs)))
>> +                    return false;
>> +    } else {
>> +            head = try_get_compound_head(head, refs);
>> +            if (!head)
>> +                    return false;
>> +    }
>> +
>> +    return true;
>> +}
>> +
>>  static void put_compound_head(struct page *page, int refs)
>>  {
>>      /* Do a get_page() first, in case refs == page->_refcount */
> 
> put_compound_head() needs similar treatment as undo_dev_pagemap(), doesn't
> it?
> 

Yes, will fix that up.


>> @@ -968,7 +973,18 @@ struct page *follow_devmap_pmd(struct vm_area_struct 
>> *vma, unsigned long addr,
>>      if (!*pgmap)
>>              return ERR_PTR(-EFAULT);
>>      page = pfn_to_page(pfn);
>> -    get_page(page);
>> +
>> +    if (flags & FOLL_GET)
>> +            get_page(page);
>> +    else if (flags & FOLL_PIN) {
>> +            /*
>> +             * try_pin_page() is not actually expected to fail here because
>> +             * we hold the pmd lock so no one can unmap the pmd and free the
>> +             * page that it points to.
>> +             */
>> +            if (unlikely(!try_pin_page(page)))
>> +                    page = ERR_PTR(-EFAULT);
>> +    }
> 
> This pattern is rather common. So maybe I'd add a helper grab_page(page,
> flags) doing
> 
>       if (flags & FOLL_GET)
>               get_page(page);
>       else if (flags & FOLL_PIN)
>               return try_pin_page(page);
>       return true;
> 

OK.

> Otherwise the patch looks good to me now.
> 
>                                                               Honza

Great! I thought I'd have a v7 out today, but fate decided to have me repair
my test machine instead. So, soon. ha. :)

thanks,
-- 
John Hubbard
NVIDIA

Reply via email to