Re: Question about lock ordering.

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

 



On Wed, Aug 12, 2009 at 11:15 AM, shailesh
jain<coolworldofshail@xxxxxxxxx> wrote:
> I haven't looked the code but ...
> You can unlock in any order, right ? .... because whatever happens you will
> always be able to unlock and it the locks are acquired in the same order
> throughout  the system, then your system is guaranteed to make forward
> progress.

Hmmm ok ... "same order throughout" is the key.

Thanks -
Manish

>
> As an exercise try coming up with an example that leads to you deadlock when
> you unlock in incorrect order.
>
>
> Shailesh Jain
>
>
> On Wed, Aug 12, 2009 at 12:32 AM, Manish Katiyar <mkatiyar@xxxxxxxxx> wrote:
>>
>> Hi,
>>
>> I was going through this code below and was confused why do we need
>> lock ordering here. What is the problem that it is trying to prevent
>> given that the corresponding unlocking doesn't care for the order. I
>> assume lock orders are primarily needed to avoid deadlocks, and if
>> they are then they need to be unlocked in the same order too.
>>
>> File : fs/ext4/move_extent.c
>>
>> /**
>>  * mext_double_down_write - Acquire two inodes' write semaphore
>>  *
>>  * @orig_inode:         original inode structure
>>  * @donor_inode:        donor inode structure
>>  * Acquire write semaphore of the two inodes (orig and donor) by i_ino
>> order.
>>  */
>> static void
>> mext_double_down_write(struct inode *orig_inode, struct inode
>> *donor_inode)
>> {
>>        struct inode *first = orig_inode, *second = donor_inode;
>>
>>        BUG_ON(orig_inode == NULL || donor_inode == NULL);
>>
>>        /*
>>         * Use the inode number to provide the stable locking order instead
>>         * of its address, because the C language doesn't guarantee you can
>>         * compare pointers that don't come from the same array.
>>         */
>>        if (donor_inode->i_ino < orig_inode->i_ino) {
>>                first = donor_inode;
>>                second = orig_inode;
>>        }
>>
>>        down_write(&EXT4_I(first)->i_data_sem);
>>        down_write(&EXT4_I(second)->i_data_sem);
>> }
>>
>> /**
>>  * mext_double_up_read - Release two inodes' read semaphore
>>  *
>>  * @orig_inode:         original inode structure to be released its lock
>> first
>>  * @donor_inode:        donor inode structure to be released its lock
>> second
>>  * Release read semaphore of two inodes (orig and donor).
>>  */
>> static void
>> mext_double_up_read(struct inode *orig_inode, struct inode *donor_inode)
>> {
>>        BUG_ON(orig_inode == NULL || donor_inode == NULL);
>>
>>        up_read(&EXT4_I(orig_inode)->i_data_sem);
>>        up_read(&EXT4_I(donor_inode)->i_data_sem);
>> }
>>
>>
>> --
>> Thanks -
>> Manish
>>
>> --
>> To unsubscribe from this list: send an email with
>> "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
>> Please read the FAQ at http://kernelnewbies.org/FAQ
>>
>
>



-- 
Thanks -
Manish

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux