OSDN Git Service

dm snapshot: Replace mutex with rw semaphore
authorNikos Tsironis <ntsironis@arrikto.com>
Sun, 17 Mar 2019 12:22:56 +0000 (14:22 +0200)
committerMike Snitzer <snitzer@redhat.com>
Thu, 18 Apr 2019 20:18:28 +0000 (16:18 -0400)
commit4ad8d880b6c4497e365fb6fd16bab52e9974a3f6
treea99defd7c4628295894f37b6af5f1e5a2386883e
parent65fc7c37047797a0a7b80d0ad2c063deda569337
dm snapshot: Replace mutex with rw semaphore

dm-snapshot uses a single mutex to serialize every access to the
snapshot state. This includes all accesses to the complete and pending
exception tables, which occur at every origin write, every snapshot
read/write and every exception completion.

The lock statistics indicate that this mutex is a bottleneck (average
wait time ~480 usecs for 8 processes doing random 4K writes to the
origin device) preventing dm-snapshot to scale as the number of threads
doing IO increases.

The major contention points are __origin_write()/snapshot_map() and
pending_complete(), i.e., the submission and completion of pending
exceptions.

Replace this mutex with a rw semaphore.

We essentially revert commit ae1093be5a0ef9 ("dm snapshot: use mutex
instead of rw_semaphore") and together with the next two patches we
substitute the single mutex with a fine-grained locking scheme, where we
use a read-write semaphore to protect the mostly read fields of the
snapshot structure, e.g., valid, active, etc., and per-bucket bit
spinlocks to protect accesses to the complete and pending exception
tables.

Co-developed-by: Ilias Tsitsimpis <iliastsi@arrikto.com>
Signed-off-by: Nikos Tsironis <ntsironis@arrikto.com>
Acked-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-snap.c