Re: [PATCH 1/1] vmalloc: purge_fragmented_blocks: Acquire spinlock before reading vmap_block

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

 



On Thu, Dec 8, 2011 at 12:37 PM, David Rientjes <rientjes@xxxxxxxxxx> wrote:
> On Thu, 8 Dec 2011, Kautuk Consul wrote:
>
>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
>> index 3231bf3..2228971 100644
>> --- a/mm/vmalloc.c
>> +++ b/mm/vmalloc.c
>> @@ -855,11 +855,14 @@ static void purge_fragmented_blocks(int cpu)
>>
>>       rcu_read_lock();
>>       list_for_each_entry_rcu(vb, &vbq->free, free_list) {
>> +             spin_lock(&vb->lock);
>>
>> -             if (!(vb->free + vb->dirty == VMAP_BBMAP_BITS && vb->dirty != VMAP_BBMAP_BITS))
>> +             if (!(vb->free + vb->dirty == VMAP_BBMAP_BITS &&
>> +                       vb->dirty != VMAP_BBMAP_BITS)) {
>> +                     spin_unlock(&vb->lock);
>>                       continue;
>> +             }
>>
>> -             spin_lock(&vb->lock);
>>               if (vb->free + vb->dirty == VMAP_BBMAP_BITS && vb->dirty != VMAP_BBMAP_BITS) {
>>                       vb->free = 0; /* prevent further allocs after releasing lock */
>>                       vb->dirty = VMAP_BBMAP_BITS; /* prevent purging it again */
>
> Nack, this is wrong because the if-clause you're modifying isn't the
> criteria that is used to determine whether the purge occurs or not.  It's
> merely an optimization to prevent doing exactly what your patch is doing:
> taking vb->lock unnecessarily.

I agree.

>
> In the original code, if the if-clause fails, the lock is only then taken
> and the exact same test occurs again while protected.  If the test now
> fails, the lock is immediately dropped.  A branch here is faster than a
> contented spinlock.

But, if there is some concurrent change happening to vb->free and
vb->dirty, dont you think
that it will continue and then go to the next vmap_block ?

If yes, then it will not be put into the purge list.


So, can we make a change where we simply remove the first check ?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href


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