logger: replace spinlock by rwsem

This commit is contained in:
Thomas Schoebel-Theuer 2017-12-10 22:43:28 +01:00 committed by Thomas Schoebel-Theuer
parent d2786079f6
commit e5bb5ade55
2 changed files with 8 additions and 13 deletions

View File

@ -2708,7 +2708,6 @@ void replay_endio(struct generic_callback *cb)
struct trans_logger_mref_aspect *mref_a = cb->cb_private;
struct trans_logger_brick *brick;
bool ok;
unsigned long flags;
_crashme(22, false);
@ -2722,10 +2721,10 @@ void replay_endio(struct generic_callback *cb)
MARS_ERR("IO error = %d\n", cb->cb_error);
}
traced_lock(&brick->replay_lock, flags);
down_write(&brick->replay_mutex);
ok = !list_empty(&mref_a->replay_head);
list_del_init(&mref_a->replay_head);
traced_unlock(&brick->replay_lock, flags);
up_write(&brick->replay_mutex);
if (likely(ok)) {
atomic_dec(&brick->replay_count);
@ -2745,11 +2744,8 @@ bool _has_conflict(struct trans_logger_brick *brick, struct trans_logger_mref_as
struct mref_object *mref = mref_a->object;
struct list_head *tmp;
bool res = false;
unsigned long flags;
// NOTE: replacing this by rwlock_t will not gain anything, because there exists at most 1 reader at any time
traced_lock(&brick->replay_lock, flags);
down_read(&brick->replay_mutex);
for (tmp = brick->replay_list.next; tmp != &brick->replay_list; tmp = tmp->next) {
struct trans_logger_mref_aspect *tmp_a;
@ -2763,7 +2759,7 @@ bool _has_conflict(struct trans_logger_brick *brick, struct trans_logger_mref_as
}
}
traced_unlock(&brick->replay_lock, flags);
up_read(&brick->replay_mutex);
return res;
}
@ -2774,7 +2770,6 @@ void wait_replay(struct trans_logger_brick *brick, struct trans_logger_mref_aspe
int conflicts = 0;
bool ok = false;
bool was_empty;
unsigned long flags;
wait_event_interruptible_timeout(brick->worker_event,
atomic_read(&brick->replay_count) < max
@ -2785,7 +2780,7 @@ void wait_replay(struct trans_logger_brick *brick, struct trans_logger_mref_aspe
if (conflicts)
atomic_inc(&brick->total_replay_conflict_count);
traced_lock(&brick->replay_lock, flags);
down_write(&brick->replay_mutex);
was_empty = !!list_empty(&mref_a->replay_head);
if (likely(was_empty)) {
atomic_inc(&brick->replay_count);
@ -2793,7 +2788,7 @@ void wait_replay(struct trans_logger_brick *brick, struct trans_logger_mref_aspe
list_del(&mref_a->replay_head);
}
list_add(&mref_a->replay_head, &brick->replay_list);
traced_unlock(&brick->replay_lock, flags);
up_write(&brick->replay_mutex);
if (unlikely(!was_empty)) {
MARS_ERR("replay_head was already used (ok=%d, conflicts=%d, replay_count=%d)\n", ok, conflicts, atomic_read(&brick->replay_count));
@ -3391,7 +3386,7 @@ int trans_logger_brick_construct(struct trans_logger_brick *brick)
}
atomic_set(&brick->hash_count, 0);
spin_lock_init(&brick->replay_lock);
init_rwsem(&brick->replay_mutex);
INIT_LIST_HEAD(&brick->replay_list);
INIT_LIST_HEAD(&brick->group_head);
init_waitqueue_head(&brick->worker_event);

View File

@ -187,7 +187,7 @@ struct trans_logger_brick {
struct trans_logger_hash_anchor **hash_table;
struct list_head group_head;
loff_t old_margin;
spinlock_t replay_lock;
struct rw_semaphore replay_mutex;
struct list_head replay_list;
struct task_struct *thread;
wait_queue_head_t worker_event;