Re: [Phishing Risk] [External] [PATCH 2/3] mm/zsmalloc.c: combine two atomic ops in zs_pool_dec_isolated()

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

 



On 2021/6/25 13:01, Muchun Song wrote:
> On Thu, Jun 24, 2021 at 8:40 PM Miaohe Lin <linmiaohe@xxxxxxxxxx> wrote:
>>
>> atomic_long_dec_and_test() is equivalent to atomic_long_dec() and
>> atomic_long_read() == 0. Use it to make code more succinct.
> 
> Actually, they are not equal. atomic_long_dec_and_test implies a
> full memory barrier around it but atomic_long_dec and atomic_long_read
> don't.
> 

Many thanks for comment. They are indeed not completely equal as you said.
What I mean is they can do the same things we want in this specified context.
Thanks again.

> That RMW operations that have a return value is equal to the following.
> 
> smp_mb__before_atomic()
> non-RMW operations or RMW operations that have no return value
> smp_mb__after_atomic()
> 
> Thanks.
> 
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@xxxxxxxxxx>
>> ---
>>  mm/zsmalloc.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
>> index 1476289b619f..0b4b23740d78 100644
>> --- a/mm/zsmalloc.c
>> +++ b/mm/zsmalloc.c
>> @@ -1828,13 +1828,12 @@ static void putback_zspage_deferred(struct zs_pool *pool,
>>  static inline void zs_pool_dec_isolated(struct zs_pool *pool)
>>  {
>>         VM_BUG_ON(atomic_long_read(&pool->isolated_pages) <= 0);
>> -       atomic_long_dec(&pool->isolated_pages);
>>         /*
>>          * There's no possibility of racing, since wait_for_isolated_drain()
>>          * checks the isolated count under &class->lock after enqueuing
>>          * on migration_wait.
>>          */
>> -       if (atomic_long_read(&pool->isolated_pages) == 0 && pool->destroying)
>> +       if (atomic_long_dec_and_test(&pool->isolated_pages) && pool->destroying)
>>                 wake_up_all(&pool->migration_wait);
>>  }
>>
>> --
>> 2.23.0
>>
> .
> 





[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