Re: [PATCH 1/2] btrfs: Implement DRW lock
From: Andrea Parri
Date: Sat Jun 08 2019 - 12:37:58 EST
On Thu, Jun 06, 2019 at 04:52:18PM +0300, Nikolay Borisov wrote:
> A (D)ouble (R)eader (W)riter lock is a locking primitive that allows
> to have multiple readers or multiple writers but not multiple readers
> and writers holding it concurrently. The code is factored out from
> the existing open-coded locking scheme used to exclude pending
> snapshots from nocow writers and vice-versa. Current implementation
> actually favors Readers (that is snapshot creaters) to writers (nocow
> writers of the filesystem).
>
> Signed-off-by: Nikolay Borisov <nborisov@xxxxxxxx>
Interesting! Thank you for sending this over, Nikolay.
I only have a couple of nits (below) to add:
[...]
> +
> +void btrfs_drw_read_unlock(struct btrfs_drw_lock *lock)
> +{
> + /*
> + * Atomic RMW operations imply full barrier, so woken up writers
> + * are guaranteed to see the decrement
> + */
Not every atomic RMW operations imply a full barrier (as exemplified,
e.g., by the atomic_inc() in btrfs_drw_read_lock()); maybe simply
s/Atomic RMW operations imply/atomic_dec_and_test() implies/
FYI, checkpatch.pl issues a few warnings on this patch (you may want
to address some of them in the next version).
Thanks,
Andrea
> + if (atomic_dec_and_test(&lock->readers))
> + wake_up(&lock->pending_writers);
> +}
> +
> +