[Gluster-devel] Improvement of eager locking

Xavier Hernandez xhernandez at datalab.es
Fri Jan 16 12:10:07 UTC 2015


On 01/16/2015 04:58 AM, Pranith Kumar Karampuri wrote:
>
> On 01/15/2015 10:53 PM, Xavier Hernandez wrote:
>> Hi,
>>
>> currently eager locking is implemented by checking the open-fd-count
>> special xattr for each write. If there's more than one open on the
>> same file, eager locking is disabled to avoid starvation.
>>
>> This works quite well for file writes, but makes eager locking
>> unusable for other request types that do not involve an open fd (in
>> fact, this method is only for writes on regular files, not reads or
>> directories). This may cause a performance problem for other
>> operations, like metadata.
>>
>> To be able to use eager locking for other purposes, what do you think
>> about this proposal:
>>
>> Instead of implementing open-fd-count on posix xlator, do something
>> similar but in locks xlator. The difference will be that locks xlator
>> can use the pending locking information to determine if there are
>> other processes waiting for a resource. If so, set a flag in the cbk
>> xdata to let high level xlators know that they should not use eager
>> locking (this can be done only upon request by xdata).
>>
>> I think this way provides a more precise way to avoid starvation and
>> maximize performance at the same time, and it can be used for any
>> request even if it doesn't depend on an fd.
>>
>> Another advantage is that if one file has been opened multiple times
>> but all of them from the same glusterfs client, that client could use
>> a single inodelk to manage all the accesses, not needing to release
>> the lock. Current implementation in posix xlator cannot differentiate
>> from opens from the same client or different clients.
>>
>> What do you think ?
> I like the idea. So basically we can propagate list_empty information of
> 'blocking_locks' list. And for sending locks, we need to use lk-owner
> based on gfid so that locks from same client i.e. lkowner+transport are
> granted irrespective of conflicting locks. The respective xls need to
> make sure to order the fops so that they don't step on each other in a
> single process. This can be used for entry-locks also.

I don't understand what are the benefits of checking for 
lkowner+transport to grant a lock bypassing conflicts. It seems 
dangerous and I don't see exactly how this can help the upper xlator. If 
this xlator already needs to take care of fop ordering for each inode, 
it can share the same lock. It seems there's no need to do additional 
locking calls. I may be missing some detail though.

Thinking a litle more about the way to detect multiple accesses to the 
same inode using the list of pending locks, there's a case where some 
more logic must be added to avoid unnecessary delays.

Suppose you receive a request for an inode from one client. If there 
isn't anyone else waiting, a flag is set into the answer indicating that 
there's no conflict. After that the caller begins an eager lock timer 
because there isn't anyone else waiting. During that timeout, another 
client tries to access the same inode. It will block until the eager 
lock timer expires (at this time it will release the inode lock) or 
another request from the first client arrives (in this case the request 
is served and the result will indicate that it should release the lock 
since there are other clients waiting). When the lock is released, it 
will be granted to the other client. It's possible that this client 
completes the request before the first one tries to acquire the lock 
again (because it had more requests pending), causing that the second 
client initiates another eager lock timer because there were no other 
client waiting at the moment of executing the request. This is an 
unnecessary delay.

To avoid this problem, we could add a flag in the inodelk/entrylk calls 
to indicate that the lock is released to let other clients to proceed, 
but we will want the lock again as soon as possible. It would be as a 
combined unlock and lock on the same inode sent in a single request. 
This way we avoid one round trip and locks xlator has more up to date 
information to decide if there are concurrent accesses or not.

Xavi


More information about the Gluster-devel mailing list