Re: [RFC v11 08/14] mm: page_frag: some minor refactoring before adding new API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2024/8/1 1:02, Alexander H Duyck wrote:
> On Wed, 2024-07-31 at 20:35 +0800, Yunsheng Lin wrote:
>> On 2024/7/30 23:12, Alexander H Duyck wrote:
>>
>> ...
>>
>>>>         }
>>>>
>>>>         nc->pagecnt_bias--;
>>>>         nc->remaining = remaining - fragsz;
>>>>
>>>>         return encoded_page_address(encoded_va) +
>>>>                 (page_frag_cache_page_size(encoded_va) - remaining);
>>>
>>> Parenthesis here shouldn't be needed, addition and subtractions
>>> operations can happen in any order with the result coming out the same.
>>
>> I am playing safe to avoid overflow here, as I am not sure if the allocator
>> will give us the last page. For example, '0xfffffffffffff000 + 0x1000' will
>> have a overflow.
> 
> So what if it does though? When you subtract remaining it will
> underflow and go back to the correct value shouldn't it?

I guess that it is true that underflow will bring back the correct value.
But I am not sure what does it hurt to have a parenthesis here, doesn't having
a parenthesis make it more obvious that 'size - remaining' indicate the offset
of allocated fragment and not having to scratch my head and wondering if there
is overflow/underflow problem? Or is there any performance trick behind the above
comment?




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux